1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2010 VMware, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include "pipe/p_screen.h"
30bf215546Sopenharmony_ci#include "pipe/p_state.h"
31bf215546Sopenharmony_ci#include "util/u_memory.h"
32bf215546Sopenharmony_ci#include "util/u_debug.h"
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#include "rbug_public.h"
35bf215546Sopenharmony_ci#include "rbug_screen.h"
36bf215546Sopenharmony_ci#include "rbug_context.h"
37bf215546Sopenharmony_ci#include "rbug_objects.h"
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ciDEBUG_GET_ONCE_BOOL_OPTION(rbug, "GALLIUM_RBUG", false)
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_cistatic void
42bf215546Sopenharmony_cirbug_screen_destroy(struct pipe_screen *_screen)
43bf215546Sopenharmony_ci{
44bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
45bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_ci   screen->destroy(screen);
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ci   FREE(rb_screen);
50bf215546Sopenharmony_ci}
51bf215546Sopenharmony_ci
52bf215546Sopenharmony_cistatic const char *
53bf215546Sopenharmony_cirbug_screen_get_name(struct pipe_screen *_screen)
54bf215546Sopenharmony_ci{
55bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
56bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_ci   return screen->get_name(screen);
59bf215546Sopenharmony_ci}
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_cistatic const char *
62bf215546Sopenharmony_cirbug_screen_get_vendor(struct pipe_screen *_screen)
63bf215546Sopenharmony_ci{
64bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
65bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_ci   return screen->get_vendor(screen);
68bf215546Sopenharmony_ci}
69bf215546Sopenharmony_ci
70bf215546Sopenharmony_cistatic const char *
71bf215546Sopenharmony_cirbug_screen_get_device_vendor(struct pipe_screen *_screen)
72bf215546Sopenharmony_ci{
73bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
74bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_ci   return screen->get_device_vendor(screen);
77bf215546Sopenharmony_ci}
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_cistatic const void *
80bf215546Sopenharmony_cirbug_screen_get_compiler_options(struct pipe_screen *_screen,
81bf215546Sopenharmony_ci                                 enum pipe_shader_ir ir,
82bf215546Sopenharmony_ci                                 enum pipe_shader_type shader)
83bf215546Sopenharmony_ci{
84bf215546Sopenharmony_ci   struct pipe_screen *screen = rbug_screen(_screen)->screen;
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_ci   return screen->get_compiler_options(screen, ir, shader);
87bf215546Sopenharmony_ci}
88bf215546Sopenharmony_ci
89bf215546Sopenharmony_cistatic struct disk_cache *
90bf215546Sopenharmony_cirbug_screen_get_disk_shader_cache(struct pipe_screen *_screen)
91bf215546Sopenharmony_ci{
92bf215546Sopenharmony_ci   struct pipe_screen *screen = rbug_screen(_screen)->screen;
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_ci   return screen->get_disk_shader_cache(screen);
95bf215546Sopenharmony_ci}
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_cistatic int
98bf215546Sopenharmony_cirbug_screen_get_param(struct pipe_screen *_screen,
99bf215546Sopenharmony_ci                      enum pipe_cap param)
100bf215546Sopenharmony_ci{
101bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
102bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_ci   return screen->get_param(screen,
105bf215546Sopenharmony_ci                            param);
106bf215546Sopenharmony_ci}
107bf215546Sopenharmony_ci
108bf215546Sopenharmony_cistatic int
109bf215546Sopenharmony_cirbug_screen_get_shader_param(struct pipe_screen *_screen,
110bf215546Sopenharmony_ci                             enum pipe_shader_type shader,
111bf215546Sopenharmony_ci                             enum pipe_shader_cap param)
112bf215546Sopenharmony_ci{
113bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
114bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
115bf215546Sopenharmony_ci
116bf215546Sopenharmony_ci   return screen->get_shader_param(screen, shader,
117bf215546Sopenharmony_ci                            param);
118bf215546Sopenharmony_ci}
119bf215546Sopenharmony_ci
120bf215546Sopenharmony_cistatic float
121bf215546Sopenharmony_cirbug_screen_get_paramf(struct pipe_screen *_screen,
122bf215546Sopenharmony_ci                       enum pipe_capf param)
123bf215546Sopenharmony_ci{
124bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
125bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
126bf215546Sopenharmony_ci
127bf215546Sopenharmony_ci   return screen->get_paramf(screen,
128bf215546Sopenharmony_ci                             param);
129bf215546Sopenharmony_ci}
130bf215546Sopenharmony_ci
131bf215546Sopenharmony_cistatic bool
132bf215546Sopenharmony_cirbug_screen_is_format_supported(struct pipe_screen *_screen,
133bf215546Sopenharmony_ci                                enum pipe_format format,
134bf215546Sopenharmony_ci                                enum pipe_texture_target target,
135bf215546Sopenharmony_ci                                unsigned sample_count,
136bf215546Sopenharmony_ci                                unsigned storage_sample_count,
137bf215546Sopenharmony_ci                                unsigned tex_usage)
138bf215546Sopenharmony_ci{
139bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
140bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
141bf215546Sopenharmony_ci
142bf215546Sopenharmony_ci   return screen->is_format_supported(screen,
143bf215546Sopenharmony_ci                                      format,
144bf215546Sopenharmony_ci                                      target,
145bf215546Sopenharmony_ci                                      sample_count,
146bf215546Sopenharmony_ci                                      storage_sample_count,
147bf215546Sopenharmony_ci                                      tex_usage);
148bf215546Sopenharmony_ci}
149bf215546Sopenharmony_ci
150bf215546Sopenharmony_cistatic void
151bf215546Sopenharmony_cirbug_screen_query_dmabuf_modifiers(struct pipe_screen *_screen,
152bf215546Sopenharmony_ci                                   enum pipe_format format, int max,
153bf215546Sopenharmony_ci                                   uint64_t *modifiers,
154bf215546Sopenharmony_ci                                   unsigned int *external_only, int *count)
155bf215546Sopenharmony_ci{
156bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
157bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
158bf215546Sopenharmony_ci
159bf215546Sopenharmony_ci   screen->query_dmabuf_modifiers(screen,
160bf215546Sopenharmony_ci                                  format,
161bf215546Sopenharmony_ci                                  max,
162bf215546Sopenharmony_ci                                  modifiers,
163bf215546Sopenharmony_ci                                  external_only,
164bf215546Sopenharmony_ci                                  count);
165bf215546Sopenharmony_ci}
166bf215546Sopenharmony_ci
167bf215546Sopenharmony_cistatic bool
168bf215546Sopenharmony_cirbug_screen_is_dmabuf_modifier_supported(struct pipe_screen *_screen,
169bf215546Sopenharmony_ci                                         uint64_t modifier,
170bf215546Sopenharmony_ci                                         enum pipe_format format,
171bf215546Sopenharmony_ci                                         bool *external_only)
172bf215546Sopenharmony_ci{
173bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
174bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
175bf215546Sopenharmony_ci
176bf215546Sopenharmony_ci   return screen->is_dmabuf_modifier_supported(screen,
177bf215546Sopenharmony_ci                                               modifier,
178bf215546Sopenharmony_ci                                               format,
179bf215546Sopenharmony_ci                                               external_only);
180bf215546Sopenharmony_ci}
181bf215546Sopenharmony_ci
182bf215546Sopenharmony_cistatic unsigned int
183bf215546Sopenharmony_cirbug_screen_get_dmabuf_modifier_planes(struct pipe_screen *_screen,
184bf215546Sopenharmony_ci                                       uint64_t modifier,
185bf215546Sopenharmony_ci                                       enum pipe_format format)
186bf215546Sopenharmony_ci{
187bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
188bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
189bf215546Sopenharmony_ci
190bf215546Sopenharmony_ci   return screen->get_dmabuf_modifier_planes(screen, modifier, format);
191bf215546Sopenharmony_ci}
192bf215546Sopenharmony_ci
193bf215546Sopenharmony_cistatic int
194bf215546Sopenharmony_cirbug_screen_get_sparse_texture_virtual_page_size(struct pipe_screen *_screen,
195bf215546Sopenharmony_ci                                                 enum pipe_texture_target target,
196bf215546Sopenharmony_ci                                                 bool multi_sample,
197bf215546Sopenharmony_ci                                                 enum pipe_format format,
198bf215546Sopenharmony_ci                                                 unsigned offset, unsigned size,
199bf215546Sopenharmony_ci                                                 int *x, int *y, int *z)
200bf215546Sopenharmony_ci{
201bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
202bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
203bf215546Sopenharmony_ci
204bf215546Sopenharmony_ci   return screen->get_sparse_texture_virtual_page_size(screen, target, multi_sample,
205bf215546Sopenharmony_ci                                                       format, offset, size, x, y, z);
206bf215546Sopenharmony_ci}
207bf215546Sopenharmony_ci
208bf215546Sopenharmony_cistatic struct pipe_context *
209bf215546Sopenharmony_cirbug_screen_context_create(struct pipe_screen *_screen,
210bf215546Sopenharmony_ci                           void *priv, unsigned flags)
211bf215546Sopenharmony_ci{
212bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
213bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
214bf215546Sopenharmony_ci   struct pipe_context *result;
215bf215546Sopenharmony_ci
216bf215546Sopenharmony_ci   result = screen->context_create(screen, priv, flags);
217bf215546Sopenharmony_ci   if (result)
218bf215546Sopenharmony_ci      return rbug_context_create(_screen, result);
219bf215546Sopenharmony_ci   return NULL;
220bf215546Sopenharmony_ci}
221bf215546Sopenharmony_ci
222bf215546Sopenharmony_cistatic bool
223bf215546Sopenharmony_cirbug_screen_can_create_resource(struct pipe_screen *_screen,
224bf215546Sopenharmony_ci                                const struct pipe_resource *templat)
225bf215546Sopenharmony_ci{
226bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
227bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
228bf215546Sopenharmony_ci
229bf215546Sopenharmony_ci   return screen->can_create_resource(screen,
230bf215546Sopenharmony_ci                                      templat);
231bf215546Sopenharmony_ci}
232bf215546Sopenharmony_ci
233bf215546Sopenharmony_cistatic struct pipe_resource *
234bf215546Sopenharmony_cirbug_screen_resource_create(struct pipe_screen *_screen,
235bf215546Sopenharmony_ci                            const struct pipe_resource *templat)
236bf215546Sopenharmony_ci{
237bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
238bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
239bf215546Sopenharmony_ci   struct pipe_resource *result;
240bf215546Sopenharmony_ci
241bf215546Sopenharmony_ci   result = screen->resource_create(screen,
242bf215546Sopenharmony_ci                                    templat);
243bf215546Sopenharmony_ci
244bf215546Sopenharmony_ci   if (result)
245bf215546Sopenharmony_ci      return rbug_resource_create(rb_screen, result);
246bf215546Sopenharmony_ci   return NULL;
247bf215546Sopenharmony_ci}
248bf215546Sopenharmony_ci
249bf215546Sopenharmony_cistatic struct pipe_resource *
250bf215546Sopenharmony_cirbug_screen_resource_create_with_modifiers(struct pipe_screen *_screen,
251bf215546Sopenharmony_ci                                           const struct pipe_resource *templat,
252bf215546Sopenharmony_ci                                           const uint64_t *modifiers, int count)
253bf215546Sopenharmony_ci{
254bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
255bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
256bf215546Sopenharmony_ci   struct pipe_resource *result;
257bf215546Sopenharmony_ci
258bf215546Sopenharmony_ci   result = screen->resource_create_with_modifiers(screen,
259bf215546Sopenharmony_ci                                                   templat,
260bf215546Sopenharmony_ci                                                   modifiers,
261bf215546Sopenharmony_ci                                                   count);
262bf215546Sopenharmony_ci
263bf215546Sopenharmony_ci   if (result)
264bf215546Sopenharmony_ci      return rbug_resource_create(rb_screen, result);
265bf215546Sopenharmony_ci   return NULL;
266bf215546Sopenharmony_ci}
267bf215546Sopenharmony_ci
268bf215546Sopenharmony_cistatic struct pipe_resource *
269bf215546Sopenharmony_cirbug_screen_resource_from_handle(struct pipe_screen *_screen,
270bf215546Sopenharmony_ci                                 const struct pipe_resource *templ,
271bf215546Sopenharmony_ci                                 struct winsys_handle *handle,
272bf215546Sopenharmony_ci                                 unsigned usage)
273bf215546Sopenharmony_ci{
274bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
275bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
276bf215546Sopenharmony_ci   struct pipe_resource *result;
277bf215546Sopenharmony_ci
278bf215546Sopenharmony_ci   result = screen->resource_from_handle(screen, templ, handle, usage);
279bf215546Sopenharmony_ci
280bf215546Sopenharmony_ci   result = rbug_resource_create(rbug_screen(_screen), result);
281bf215546Sopenharmony_ci
282bf215546Sopenharmony_ci   return result;
283bf215546Sopenharmony_ci}
284bf215546Sopenharmony_ci
285bf215546Sopenharmony_cistatic bool
286bf215546Sopenharmony_cirbug_screen_check_resource_capability(struct pipe_screen *_screen,
287bf215546Sopenharmony_ci                                      struct pipe_resource *_resource,
288bf215546Sopenharmony_ci                                      unsigned bind)
289bf215546Sopenharmony_ci{
290bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
291bf215546Sopenharmony_ci   struct rbug_resource *rb_resource = rbug_resource(_resource);
292bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
293bf215546Sopenharmony_ci   struct pipe_resource *resource = rb_resource->resource;
294bf215546Sopenharmony_ci
295bf215546Sopenharmony_ci   return screen->check_resource_capability(screen, resource, bind);
296bf215546Sopenharmony_ci}
297bf215546Sopenharmony_ci
298bf215546Sopenharmony_cistatic bool
299bf215546Sopenharmony_cirbug_screen_resource_get_handle(struct pipe_screen *_screen,
300bf215546Sopenharmony_ci                                struct pipe_context *_pipe,
301bf215546Sopenharmony_ci                                struct pipe_resource *_resource,
302bf215546Sopenharmony_ci                                struct winsys_handle *handle,
303bf215546Sopenharmony_ci                                unsigned usage)
304bf215546Sopenharmony_ci{
305bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
306bf215546Sopenharmony_ci   struct rbug_context *rb_pipe = rbug_context(_pipe);
307bf215546Sopenharmony_ci   struct rbug_resource *rb_resource = rbug_resource(_resource);
308bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
309bf215546Sopenharmony_ci   struct pipe_resource *resource = rb_resource->resource;
310bf215546Sopenharmony_ci
311bf215546Sopenharmony_ci   return screen->resource_get_handle(screen, rb_pipe ? rb_pipe->pipe : NULL,
312bf215546Sopenharmony_ci                                      resource, handle, usage);
313bf215546Sopenharmony_ci}
314bf215546Sopenharmony_ci
315bf215546Sopenharmony_cistatic bool
316bf215546Sopenharmony_cirbug_screen_resource_get_param(struct pipe_screen *_screen,
317bf215546Sopenharmony_ci                               struct pipe_context *_pipe,
318bf215546Sopenharmony_ci                               struct pipe_resource *_resource,
319bf215546Sopenharmony_ci                               unsigned plane,
320bf215546Sopenharmony_ci                               unsigned layer,
321bf215546Sopenharmony_ci                               unsigned level,
322bf215546Sopenharmony_ci                               enum pipe_resource_param param,
323bf215546Sopenharmony_ci                               unsigned handle_usage,
324bf215546Sopenharmony_ci                               uint64_t *value)
325bf215546Sopenharmony_ci{
326bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
327bf215546Sopenharmony_ci   struct rbug_context *rb_pipe = rbug_context(_pipe);
328bf215546Sopenharmony_ci   struct rbug_resource *rb_resource = rbug_resource(_resource);
329bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
330bf215546Sopenharmony_ci   struct pipe_resource *resource = rb_resource->resource;
331bf215546Sopenharmony_ci
332bf215546Sopenharmony_ci   return screen->resource_get_param(screen, rb_pipe ? rb_pipe->pipe : NULL,
333bf215546Sopenharmony_ci                                     resource, plane, layer, level, param,
334bf215546Sopenharmony_ci                                     handle_usage, value);
335bf215546Sopenharmony_ci}
336bf215546Sopenharmony_ci
337bf215546Sopenharmony_ci
338bf215546Sopenharmony_cistatic void
339bf215546Sopenharmony_cirbug_screen_resource_get_info(struct pipe_screen *_screen,
340bf215546Sopenharmony_ci                              struct pipe_resource *_resource,
341bf215546Sopenharmony_ci                              unsigned *stride,
342bf215546Sopenharmony_ci                              unsigned *offset)
343bf215546Sopenharmony_ci{
344bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
345bf215546Sopenharmony_ci   struct rbug_resource *rb_resource = rbug_resource(_resource);
346bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
347bf215546Sopenharmony_ci   struct pipe_resource *resource = rb_resource->resource;
348bf215546Sopenharmony_ci
349bf215546Sopenharmony_ci   screen->resource_get_info(screen, resource, stride, offset);
350bf215546Sopenharmony_ci}
351bf215546Sopenharmony_ci
352bf215546Sopenharmony_cistatic void
353bf215546Sopenharmony_cirbug_screen_resource_changed(struct pipe_screen *_screen,
354bf215546Sopenharmony_ci                             struct pipe_resource *_resource)
355bf215546Sopenharmony_ci{
356bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
357bf215546Sopenharmony_ci   struct rbug_resource *rb_resource = rbug_resource(_resource);
358bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
359bf215546Sopenharmony_ci   struct pipe_resource *resource = rb_resource->resource;
360bf215546Sopenharmony_ci
361bf215546Sopenharmony_ci   screen->resource_changed(screen, resource);
362bf215546Sopenharmony_ci}
363bf215546Sopenharmony_ci
364bf215546Sopenharmony_cistatic void
365bf215546Sopenharmony_cirbug_screen_resource_destroy(struct pipe_screen *screen,
366bf215546Sopenharmony_ci                             struct pipe_resource *_resource)
367bf215546Sopenharmony_ci{
368bf215546Sopenharmony_ci   rbug_resource_destroy(rbug_resource(_resource));
369bf215546Sopenharmony_ci}
370bf215546Sopenharmony_ci
371bf215546Sopenharmony_cistatic void
372bf215546Sopenharmony_cirbug_screen_flush_frontbuffer(struct pipe_screen *_screen,
373bf215546Sopenharmony_ci                              struct pipe_context *_ctx,
374bf215546Sopenharmony_ci                              struct pipe_resource *_resource,
375bf215546Sopenharmony_ci                              unsigned level, unsigned layer,
376bf215546Sopenharmony_ci                              void *context_private, struct pipe_box *sub_box)
377bf215546Sopenharmony_ci{
378bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
379bf215546Sopenharmony_ci   struct rbug_resource *rb_resource = rbug_resource(_resource);
380bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
381bf215546Sopenharmony_ci   struct pipe_resource *resource = rb_resource->resource;
382bf215546Sopenharmony_ci   struct pipe_context *ctx = _ctx ? rbug_context(_ctx)->pipe : NULL;
383bf215546Sopenharmony_ci
384bf215546Sopenharmony_ci   screen->flush_frontbuffer(screen,
385bf215546Sopenharmony_ci                             ctx,
386bf215546Sopenharmony_ci                             resource,
387bf215546Sopenharmony_ci                             level, layer,
388bf215546Sopenharmony_ci                             context_private, sub_box);
389bf215546Sopenharmony_ci}
390bf215546Sopenharmony_ci
391bf215546Sopenharmony_cistatic void
392bf215546Sopenharmony_cirbug_screen_fence_reference(struct pipe_screen *_screen,
393bf215546Sopenharmony_ci                            struct pipe_fence_handle **ptr,
394bf215546Sopenharmony_ci                            struct pipe_fence_handle *fence)
395bf215546Sopenharmony_ci{
396bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
397bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
398bf215546Sopenharmony_ci
399bf215546Sopenharmony_ci   screen->fence_reference(screen,
400bf215546Sopenharmony_ci                           ptr,
401bf215546Sopenharmony_ci                           fence);
402bf215546Sopenharmony_ci}
403bf215546Sopenharmony_ci
404bf215546Sopenharmony_cistatic bool
405bf215546Sopenharmony_cirbug_screen_fence_finish(struct pipe_screen *_screen,
406bf215546Sopenharmony_ci                         struct pipe_context *_ctx,
407bf215546Sopenharmony_ci                         struct pipe_fence_handle *fence,
408bf215546Sopenharmony_ci                         uint64_t timeout)
409bf215546Sopenharmony_ci{
410bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
411bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
412bf215546Sopenharmony_ci   struct pipe_context *ctx = _ctx ? rbug_context(_ctx)->pipe : NULL;
413bf215546Sopenharmony_ci
414bf215546Sopenharmony_ci   return screen->fence_finish(screen, ctx, fence, timeout);
415bf215546Sopenharmony_ci}
416bf215546Sopenharmony_ci
417bf215546Sopenharmony_cistatic int
418bf215546Sopenharmony_cirbug_screen_fence_get_fd(struct pipe_screen *_screen,
419bf215546Sopenharmony_ci                         struct pipe_fence_handle *fence)
420bf215546Sopenharmony_ci{
421bf215546Sopenharmony_ci   struct rbug_screen *rb_screen = rbug_screen(_screen);
422bf215546Sopenharmony_ci   struct pipe_screen *screen = rb_screen->screen;
423bf215546Sopenharmony_ci
424bf215546Sopenharmony_ci   return screen->fence_get_fd(screen, fence);
425bf215546Sopenharmony_ci}
426bf215546Sopenharmony_ci
427bf215546Sopenharmony_cistatic char *
428bf215546Sopenharmony_cirbug_screen_finalize_nir(struct pipe_screen *_screen, void *nir)
429bf215546Sopenharmony_ci{
430bf215546Sopenharmony_ci   struct pipe_screen *screen = rbug_screen(_screen)->screen;
431bf215546Sopenharmony_ci
432bf215546Sopenharmony_ci   return screen->finalize_nir(screen, nir);
433bf215546Sopenharmony_ci}
434bf215546Sopenharmony_ci
435bf215546Sopenharmony_cibool
436bf215546Sopenharmony_cirbug_enabled()
437bf215546Sopenharmony_ci{
438bf215546Sopenharmony_ci   return debug_get_option_rbug();
439bf215546Sopenharmony_ci}
440bf215546Sopenharmony_ci
441bf215546Sopenharmony_cistruct pipe_screen *
442bf215546Sopenharmony_cirbug_screen_create(struct pipe_screen *screen)
443bf215546Sopenharmony_ci{
444bf215546Sopenharmony_ci   struct rbug_screen *rb_screen;
445bf215546Sopenharmony_ci
446bf215546Sopenharmony_ci   if (!debug_get_option_rbug())
447bf215546Sopenharmony_ci      return screen;
448bf215546Sopenharmony_ci
449bf215546Sopenharmony_ci   rb_screen = CALLOC_STRUCT(rbug_screen);
450bf215546Sopenharmony_ci   if (!rb_screen)
451bf215546Sopenharmony_ci      return screen;
452bf215546Sopenharmony_ci
453bf215546Sopenharmony_ci   (void) mtx_init(&rb_screen->list_mutex, mtx_plain);
454bf215546Sopenharmony_ci   list_inithead(&rb_screen->contexts);
455bf215546Sopenharmony_ci   list_inithead(&rb_screen->resources);
456bf215546Sopenharmony_ci   list_inithead(&rb_screen->surfaces);
457bf215546Sopenharmony_ci   list_inithead(&rb_screen->transfers);
458bf215546Sopenharmony_ci
459bf215546Sopenharmony_ci#define SCR_INIT(_member) \
460bf215546Sopenharmony_ci   rb_screen->base._member = screen->_member ? rbug_screen_##_member : NULL
461bf215546Sopenharmony_ci
462bf215546Sopenharmony_ci   rb_screen->base.destroy = rbug_screen_destroy;
463bf215546Sopenharmony_ci   rb_screen->base.get_name = rbug_screen_get_name;
464bf215546Sopenharmony_ci   rb_screen->base.get_vendor = rbug_screen_get_vendor;
465bf215546Sopenharmony_ci   SCR_INIT(get_compiler_options);
466bf215546Sopenharmony_ci   SCR_INIT(get_disk_shader_cache);
467bf215546Sopenharmony_ci   rb_screen->base.get_device_vendor = rbug_screen_get_device_vendor;
468bf215546Sopenharmony_ci   rb_screen->base.get_param = rbug_screen_get_param;
469bf215546Sopenharmony_ci   rb_screen->base.get_shader_param = rbug_screen_get_shader_param;
470bf215546Sopenharmony_ci   rb_screen->base.get_paramf = rbug_screen_get_paramf;
471bf215546Sopenharmony_ci   rb_screen->base.is_format_supported = rbug_screen_is_format_supported;
472bf215546Sopenharmony_ci   SCR_INIT(query_dmabuf_modifiers);
473bf215546Sopenharmony_ci   SCR_INIT(is_dmabuf_modifier_supported);
474bf215546Sopenharmony_ci   SCR_INIT(get_dmabuf_modifier_planes);
475bf215546Sopenharmony_ci   rb_screen->base.context_create = rbug_screen_context_create;
476bf215546Sopenharmony_ci   SCR_INIT(can_create_resource);
477bf215546Sopenharmony_ci   rb_screen->base.resource_create = rbug_screen_resource_create;
478bf215546Sopenharmony_ci   SCR_INIT(resource_create_with_modifiers);
479bf215546Sopenharmony_ci   rb_screen->base.resource_from_handle = rbug_screen_resource_from_handle;
480bf215546Sopenharmony_ci   SCR_INIT(check_resource_capability);
481bf215546Sopenharmony_ci   rb_screen->base.resource_get_handle = rbug_screen_resource_get_handle;
482bf215546Sopenharmony_ci   SCR_INIT(resource_get_param);
483bf215546Sopenharmony_ci   SCR_INIT(resource_get_info);
484bf215546Sopenharmony_ci   SCR_INIT(resource_changed);
485bf215546Sopenharmony_ci   rb_screen->base.resource_destroy = rbug_screen_resource_destroy;
486bf215546Sopenharmony_ci   rb_screen->base.flush_frontbuffer = rbug_screen_flush_frontbuffer;
487bf215546Sopenharmony_ci   rb_screen->base.fence_reference = rbug_screen_fence_reference;
488bf215546Sopenharmony_ci   rb_screen->base.fence_finish = rbug_screen_fence_finish;
489bf215546Sopenharmony_ci   rb_screen->base.fence_get_fd = rbug_screen_fence_get_fd;
490bf215546Sopenharmony_ci   SCR_INIT(finalize_nir);
491bf215546Sopenharmony_ci   SCR_INIT(get_sparse_texture_virtual_page_size);
492bf215546Sopenharmony_ci
493bf215546Sopenharmony_ci   rb_screen->screen = screen;
494bf215546Sopenharmony_ci
495bf215546Sopenharmony_ci   rb_screen->private_context = screen->context_create(screen, NULL, 0);
496bf215546Sopenharmony_ci   if (!rb_screen->private_context)
497bf215546Sopenharmony_ci      goto err_free;
498bf215546Sopenharmony_ci
499bf215546Sopenharmony_ci   rb_screen->rbug = rbug_start(rb_screen);
500bf215546Sopenharmony_ci
501bf215546Sopenharmony_ci   if (!rb_screen->rbug)
502bf215546Sopenharmony_ci      goto err_context;
503bf215546Sopenharmony_ci
504bf215546Sopenharmony_ci   return &rb_screen->base;
505bf215546Sopenharmony_ci
506bf215546Sopenharmony_cierr_context:
507bf215546Sopenharmony_ci   rb_screen->private_context->destroy(rb_screen->private_context);
508bf215546Sopenharmony_cierr_free:
509bf215546Sopenharmony_ci   FREE(rb_screen);
510bf215546Sopenharmony_ci   return screen;
511bf215546Sopenharmony_ci}
512