1 /*
2 * Copyright 2010 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 #include <stdio.h>
24 #include <errno.h>
25 #include "pipe/p_defines.h"
26 #include "pipe/p_state.h"
27 #include "pipe/p_context.h"
28 #include "pipe/p_screen.h"
29 #include "util/u_memory.h"
30 #include "util/u_inlines.h"
31 #include "util/format/u_format.h"
32 #include "util/u_helpers.h"
33 #include "util/u_upload_mgr.h"
34 #include "util/u_threaded_context.h"
35 #include "noop_public.h"
36
37 DEBUG_GET_ONCE_BOOL_OPTION(noop, "GALLIUM_NOOP", false)
38
39 void noop_init_state_functions(struct pipe_context *ctx);
40
41 struct noop_pipe_screen {
42 struct pipe_screen pscreen;
43 struct pipe_screen *oscreen;
44 struct slab_parent_pool pool_transfers;
45 };
46
47 /*
48 * query
49 */
50 struct noop_query {
51 struct threaded_query b;
52 unsigned query;
53 };
noop_create_query(struct pipe_context * ctx,unsigned query_type,unsigned index)54 static struct pipe_query *noop_create_query(struct pipe_context *ctx, unsigned query_type, unsigned index)
55 {
56 struct noop_query *query = CALLOC_STRUCT(noop_query);
57
58 return (struct pipe_query *)query;
59 }
60
noop_destroy_query(struct pipe_context * ctx,struct pipe_query * query)61 static void noop_destroy_query(struct pipe_context *ctx, struct pipe_query *query)
62 {
63 FREE(query);
64 }
65
noop_begin_query(struct pipe_context * ctx,struct pipe_query * query)66 static bool noop_begin_query(struct pipe_context *ctx, struct pipe_query *query)
67 {
68 return true;
69 }
70
noop_end_query(struct pipe_context * ctx,struct pipe_query * query)71 static bool noop_end_query(struct pipe_context *ctx, struct pipe_query *query)
72 {
73 return true;
74 }
75
noop_get_query_result(struct pipe_context * ctx,struct pipe_query * query,bool wait,union pipe_query_result * vresult)76 static bool noop_get_query_result(struct pipe_context *ctx,
77 struct pipe_query *query,
78 bool wait,
79 union pipe_query_result *vresult)
80 {
81 uint64_t *result = (uint64_t*)vresult;
82
83 *result = 0;
84 return true;
85 }
86
87 static void
noop_set_active_query_state(struct pipe_context * pipe,bool enable)88 noop_set_active_query_state(struct pipe_context *pipe, bool enable)
89 {
90 }
91
92
93 /*
94 * resource
95 */
96 struct noop_resource {
97 struct threaded_resource b;
98 unsigned size;
99 char *data;
100 struct sw_displaytarget *dt;
101 };
102
noop_resource_create(struct pipe_screen * screen,const struct pipe_resource * templ)103 static struct pipe_resource *noop_resource_create(struct pipe_screen *screen,
104 const struct pipe_resource *templ)
105 {
106 struct noop_resource *nresource;
107 unsigned stride;
108
109 nresource = CALLOC_STRUCT(noop_resource);
110 if (!nresource)
111 return NULL;
112
113 stride = util_format_get_stride(templ->format, templ->width0);
114 nresource->b.b = *templ;
115 nresource->b.b.screen = screen;
116 nresource->size = stride * templ->height0 * templ->depth0;
117 nresource->data = MALLOC(nresource->size);
118 pipe_reference_init(&nresource->b.b.reference, 1);
119 if (nresource->data == NULL) {
120 FREE(nresource);
121 return NULL;
122 }
123 threaded_resource_init(&nresource->b.b);
124 return &nresource->b.b;
125 }
126
127 static struct pipe_resource *
noop_resource_create_with_modifiers(struct pipe_screen * screen,const struct pipe_resource * templ,const uint64_t * modifiers,int count)128 noop_resource_create_with_modifiers(struct pipe_screen *screen,
129 const struct pipe_resource *templ,
130 const uint64_t *modifiers, int count)
131 {
132 struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)screen;
133 struct pipe_screen *oscreen = noop_screen->oscreen;
134 struct pipe_resource *result;
135 struct pipe_resource *noop_resource;
136
137 result = oscreen->resource_create_with_modifiers(oscreen, templ,
138 modifiers, count);
139 noop_resource = noop_resource_create(screen, result);
140 pipe_resource_reference(&result, NULL);
141 return noop_resource;
142 }
143
noop_resource_from_handle(struct pipe_screen * screen,const struct pipe_resource * templ,struct winsys_handle * handle,unsigned usage)144 static struct pipe_resource *noop_resource_from_handle(struct pipe_screen *screen,
145 const struct pipe_resource *templ,
146 struct winsys_handle *handle,
147 unsigned usage)
148 {
149 struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)screen;
150 struct pipe_screen *oscreen = noop_screen->oscreen;
151 struct pipe_resource *result;
152 struct pipe_resource *noop_resource;
153
154 result = oscreen->resource_from_handle(oscreen, templ, handle, usage);
155 noop_resource = noop_resource_create(screen, result);
156 pipe_resource_reference(&result, NULL);
157 return noop_resource;
158 }
159
noop_resource_get_handle(struct pipe_screen * pscreen,struct pipe_context * ctx,struct pipe_resource * resource,struct winsys_handle * handle,unsigned usage)160 static bool noop_resource_get_handle(struct pipe_screen *pscreen,
161 struct pipe_context *ctx,
162 struct pipe_resource *resource,
163 struct winsys_handle *handle,
164 unsigned usage)
165 {
166 struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)pscreen;
167 struct pipe_screen *screen = noop_screen->oscreen;
168 struct pipe_resource *tex;
169 bool result;
170
171 /* resource_get_handle musn't fail. Just create something and return it. */
172 tex = screen->resource_create(screen, resource);
173 if (!tex)
174 return false;
175
176 result = screen->resource_get_handle(screen, NULL, tex, handle, usage);
177 pipe_resource_reference(&tex, NULL);
178 return result;
179 }
180
noop_resource_get_param(struct pipe_screen * pscreen,struct pipe_context * ctx,struct pipe_resource * resource,unsigned plane,unsigned layer,unsigned level,enum pipe_resource_param param,unsigned handle_usage,uint64_t * value)181 static bool noop_resource_get_param(struct pipe_screen *pscreen,
182 struct pipe_context *ctx,
183 struct pipe_resource *resource,
184 unsigned plane,
185 unsigned layer,
186 unsigned level,
187 enum pipe_resource_param param,
188 unsigned handle_usage,
189 uint64_t *value)
190 {
191 struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)pscreen;
192 struct pipe_screen *screen = noop_screen->oscreen;
193 struct pipe_resource *tex;
194 bool result;
195
196 /* resource_get_param mustn't fail. Just create something and return it. */
197 tex = screen->resource_create(screen, resource);
198 if (!tex)
199 return false;
200
201 result = screen->resource_get_param(screen, NULL, tex, 0, 0, 0, param,
202 handle_usage, value);
203 pipe_resource_reference(&tex, NULL);
204 return result;
205 }
206
noop_resource_destroy(struct pipe_screen * screen,struct pipe_resource * resource)207 static void noop_resource_destroy(struct pipe_screen *screen,
208 struct pipe_resource *resource)
209 {
210 struct noop_resource *nresource = (struct noop_resource *)resource;
211
212 threaded_resource_deinit(resource);
213 FREE(nresource->data);
214 FREE(resource);
215 }
216
217
218 /*
219 * transfer
220 */
noop_transfer_map(struct pipe_context * pipe,struct pipe_resource * resource,unsigned level,unsigned usage,const struct pipe_box * box,struct pipe_transfer ** ptransfer)221 static void *noop_transfer_map(struct pipe_context *pipe,
222 struct pipe_resource *resource,
223 unsigned level,
224 unsigned usage,
225 const struct pipe_box *box,
226 struct pipe_transfer **ptransfer)
227 {
228 struct pipe_transfer *transfer;
229 struct noop_resource *nresource = (struct noop_resource *)resource;
230
231 transfer = (struct pipe_transfer*)CALLOC_STRUCT(threaded_transfer);
232 if (!transfer)
233 return NULL;
234 pipe_resource_reference(&transfer->resource, resource);
235 transfer->level = level;
236 transfer->usage = usage;
237 transfer->box = *box;
238 transfer->stride = 1;
239 transfer->layer_stride = 1;
240 *ptransfer = transfer;
241
242 return nresource->data;
243 }
244
noop_transfer_flush_region(struct pipe_context * pipe,struct pipe_transfer * transfer,const struct pipe_box * box)245 static void noop_transfer_flush_region(struct pipe_context *pipe,
246 struct pipe_transfer *transfer,
247 const struct pipe_box *box)
248 {
249 }
250
noop_transfer_unmap(struct pipe_context * pipe,struct pipe_transfer * transfer)251 static void noop_transfer_unmap(struct pipe_context *pipe,
252 struct pipe_transfer *transfer)
253 {
254 pipe_resource_reference(&transfer->resource, NULL);
255 FREE(transfer);
256 }
257
noop_buffer_subdata(struct pipe_context * pipe,struct pipe_resource * resource,unsigned usage,unsigned offset,unsigned size,const void * data)258 static void noop_buffer_subdata(struct pipe_context *pipe,
259 struct pipe_resource *resource,
260 unsigned usage, unsigned offset,
261 unsigned size, const void *data)
262 {
263 }
264
noop_texture_subdata(struct pipe_context * pipe,struct pipe_resource * resource,unsigned level,unsigned usage,const struct pipe_box * box,const void * data,unsigned stride,unsigned layer_stride)265 static void noop_texture_subdata(struct pipe_context *pipe,
266 struct pipe_resource *resource,
267 unsigned level,
268 unsigned usage,
269 const struct pipe_box *box,
270 const void *data,
271 unsigned stride,
272 unsigned layer_stride)
273 {
274 }
275
276
277 /*
278 * clear/copy
279 */
noop_clear(struct pipe_context * ctx,unsigned buffers,const struct pipe_scissor_state * scissor_state,const union pipe_color_union * color,double depth,unsigned stencil)280 static void noop_clear(struct pipe_context *ctx, unsigned buffers, const struct pipe_scissor_state *scissor_state,
281 const union pipe_color_union *color, double depth, unsigned stencil)
282 {
283 }
284
noop_clear_render_target(struct pipe_context * ctx,struct pipe_surface * dst,const union pipe_color_union * color,unsigned dstx,unsigned dsty,unsigned width,unsigned height,bool render_condition_enabled)285 static void noop_clear_render_target(struct pipe_context *ctx,
286 struct pipe_surface *dst,
287 const union pipe_color_union *color,
288 unsigned dstx, unsigned dsty,
289 unsigned width, unsigned height,
290 bool render_condition_enabled)
291 {
292 }
293
noop_clear_depth_stencil(struct pipe_context * ctx,struct pipe_surface * dst,unsigned clear_flags,double depth,unsigned stencil,unsigned dstx,unsigned dsty,unsigned width,unsigned height,bool render_condition_enabled)294 static void noop_clear_depth_stencil(struct pipe_context *ctx,
295 struct pipe_surface *dst,
296 unsigned clear_flags,
297 double depth,
298 unsigned stencil,
299 unsigned dstx, unsigned dsty,
300 unsigned width, unsigned height,
301 bool render_condition_enabled)
302 {
303 }
304
noop_resource_copy_region(struct pipe_context * ctx,struct pipe_resource * dst,unsigned dst_level,unsigned dstx,unsigned dsty,unsigned dstz,struct pipe_resource * src,unsigned src_level,const struct pipe_box * src_box)305 static void noop_resource_copy_region(struct pipe_context *ctx,
306 struct pipe_resource *dst,
307 unsigned dst_level,
308 unsigned dstx, unsigned dsty, unsigned dstz,
309 struct pipe_resource *src,
310 unsigned src_level,
311 const struct pipe_box *src_box)
312 {
313 }
314
315
noop_blit(struct pipe_context * ctx,const struct pipe_blit_info * info)316 static void noop_blit(struct pipe_context *ctx,
317 const struct pipe_blit_info *info)
318 {
319 }
320
321
322 static void
noop_flush_resource(struct pipe_context * ctx,struct pipe_resource * resource)323 noop_flush_resource(struct pipe_context *ctx,
324 struct pipe_resource *resource)
325 {
326 }
327
328
329 /*
330 * context
331 */
noop_flush(struct pipe_context * ctx,struct pipe_fence_handle ** fence,unsigned flags)332 static void noop_flush(struct pipe_context *ctx,
333 struct pipe_fence_handle **fence,
334 unsigned flags)
335 {
336 if (fence) {
337 struct pipe_reference *f = MALLOC_STRUCT(pipe_reference);
338 f->count = 1;
339
340 ctx->screen->fence_reference(ctx->screen, fence, NULL);
341 *fence = (struct pipe_fence_handle*)f;
342 }
343 }
344
noop_destroy_context(struct pipe_context * ctx)345 static void noop_destroy_context(struct pipe_context *ctx)
346 {
347 if (ctx->stream_uploader)
348 u_upload_destroy(ctx->stream_uploader);
349
350 p_atomic_dec(&ctx->screen->num_contexts);
351 FREE(ctx);
352 }
353
noop_generate_mipmap(struct pipe_context * ctx,struct pipe_resource * resource,enum pipe_format format,unsigned base_level,unsigned last_level,unsigned first_layer,unsigned last_layer)354 static bool noop_generate_mipmap(struct pipe_context *ctx,
355 struct pipe_resource *resource,
356 enum pipe_format format,
357 unsigned base_level,
358 unsigned last_level,
359 unsigned first_layer,
360 unsigned last_layer)
361 {
362 return true;
363 }
364
noop_invalidate_resource(struct pipe_context * ctx,struct pipe_resource * resource)365 static void noop_invalidate_resource(struct pipe_context *ctx,
366 struct pipe_resource *resource)
367 {
368 }
369
noop_set_context_param(struct pipe_context * ctx,enum pipe_context_param param,unsigned value)370 static void noop_set_context_param(struct pipe_context *ctx,
371 enum pipe_context_param param,
372 unsigned value)
373 {
374 }
375
noop_set_frontend_noop(struct pipe_context * ctx,bool enable)376 static void noop_set_frontend_noop(struct pipe_context *ctx, bool enable)
377 {
378 }
379
noop_replace_buffer_storage(struct pipe_context * ctx,struct pipe_resource * dst,struct pipe_resource * src,unsigned num_rebinds,uint32_t rebind_mask,uint32_t delete_buffer_id)380 static void noop_replace_buffer_storage(struct pipe_context *ctx,
381 struct pipe_resource *dst,
382 struct pipe_resource *src,
383 unsigned num_rebinds,
384 uint32_t rebind_mask,
385 uint32_t delete_buffer_id)
386 {
387 }
388
389 static struct pipe_fence_handle *
noop_create_fence(struct pipe_context * ctx,struct tc_unflushed_batch_token * tc_token)390 noop_create_fence(struct pipe_context *ctx,
391 struct tc_unflushed_batch_token *tc_token)
392 {
393 struct pipe_reference *f = MALLOC_STRUCT(pipe_reference);
394
395 f->count = 1;
396 return (struct pipe_fence_handle*)f;
397 }
398
noop_is_resource_busy(struct pipe_screen * screen,struct pipe_resource * resource,unsigned usage)399 static bool noop_is_resource_busy(struct pipe_screen *screen,
400 struct pipe_resource *resource,
401 unsigned usage)
402 {
403 return false;
404 }
405
noop_create_context(struct pipe_screen * screen,void * priv,unsigned flags)406 static struct pipe_context *noop_create_context(struct pipe_screen *screen,
407 void *priv, unsigned flags)
408 {
409 struct pipe_context *ctx = CALLOC_STRUCT(pipe_context);
410
411 if (!ctx)
412 return NULL;
413
414 ctx->screen = screen;
415 ctx->priv = priv;
416
417 ctx->stream_uploader = u_upload_create_default(ctx);
418 if (!ctx->stream_uploader) {
419 FREE(ctx);
420 return NULL;
421 }
422 ctx->const_uploader = ctx->stream_uploader;
423
424 ctx->destroy = noop_destroy_context;
425 ctx->flush = noop_flush;
426 ctx->clear = noop_clear;
427 ctx->clear_render_target = noop_clear_render_target;
428 ctx->clear_depth_stencil = noop_clear_depth_stencil;
429 ctx->resource_copy_region = noop_resource_copy_region;
430 ctx->generate_mipmap = noop_generate_mipmap;
431 ctx->blit = noop_blit;
432 ctx->flush_resource = noop_flush_resource;
433 ctx->create_query = noop_create_query;
434 ctx->destroy_query = noop_destroy_query;
435 ctx->begin_query = noop_begin_query;
436 ctx->end_query = noop_end_query;
437 ctx->get_query_result = noop_get_query_result;
438 ctx->set_active_query_state = noop_set_active_query_state;
439 ctx->buffer_map = noop_transfer_map;
440 ctx->texture_map = noop_transfer_map;
441 ctx->transfer_flush_region = noop_transfer_flush_region;
442 ctx->buffer_unmap = noop_transfer_unmap;
443 ctx->texture_unmap = noop_transfer_unmap;
444 ctx->buffer_subdata = noop_buffer_subdata;
445 ctx->texture_subdata = noop_texture_subdata;
446 ctx->invalidate_resource = noop_invalidate_resource;
447 ctx->set_context_param = noop_set_context_param;
448 ctx->set_frontend_noop = noop_set_frontend_noop;
449 noop_init_state_functions(ctx);
450
451 p_atomic_inc(&screen->num_contexts);
452
453 if (!(flags & PIPE_CONTEXT_PREFER_THREADED))
454 return ctx;
455
456 struct pipe_context *tc =
457 threaded_context_create(ctx,
458 &((struct noop_pipe_screen*)screen)->pool_transfers,
459 noop_replace_buffer_storage,
460 &(struct threaded_context_options) {
461 .create_fence = noop_create_fence,
462 .is_resource_busy = noop_is_resource_busy,
463 },
464 NULL);
465
466 if (tc && tc != ctx)
467 threaded_context_init_bytes_mapped_limit((struct threaded_context *)tc, 4);
468
469 return tc;
470 }
471
472
473 /*
474 * pipe_screen
475 */
noop_flush_frontbuffer(struct pipe_screen * _screen,struct pipe_context * ctx,struct pipe_resource * resource,unsigned level,unsigned layer,void * context_private,struct pipe_box * box)476 static void noop_flush_frontbuffer(struct pipe_screen *_screen,
477 struct pipe_context *ctx,
478 struct pipe_resource *resource,
479 unsigned level, unsigned layer,
480 void *context_private, struct pipe_box *box)
481 {
482 }
483
noop_get_vendor(struct pipe_screen * pscreen)484 static const char *noop_get_vendor(struct pipe_screen* pscreen)
485 {
486 return "X.Org";
487 }
488
noop_get_device_vendor(struct pipe_screen * pscreen)489 static const char *noop_get_device_vendor(struct pipe_screen* pscreen)
490 {
491 return "NONE";
492 }
493
noop_get_name(struct pipe_screen * pscreen)494 static const char *noop_get_name(struct pipe_screen* pscreen)
495 {
496 return "NOOP";
497 }
498
noop_get_param(struct pipe_screen * pscreen,enum pipe_cap param)499 static int noop_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
500 {
501 struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen;
502
503 return screen->get_param(screen, param);
504 }
505
noop_get_paramf(struct pipe_screen * pscreen,enum pipe_capf param)506 static float noop_get_paramf(struct pipe_screen* pscreen,
507 enum pipe_capf param)
508 {
509 struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen;
510
511 return screen->get_paramf(screen, param);
512 }
513
noop_get_shader_param(struct pipe_screen * pscreen,enum pipe_shader_type shader,enum pipe_shader_cap param)514 static int noop_get_shader_param(struct pipe_screen* pscreen,
515 enum pipe_shader_type shader,
516 enum pipe_shader_cap param)
517 {
518 struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen;
519
520 return screen->get_shader_param(screen, shader, param);
521 }
522
noop_get_compute_param(struct pipe_screen * pscreen,enum pipe_shader_ir ir_type,enum pipe_compute_cap param,void * ret)523 static int noop_get_compute_param(struct pipe_screen *pscreen,
524 enum pipe_shader_ir ir_type,
525 enum pipe_compute_cap param,
526 void *ret)
527 {
528 struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen;
529
530 return screen->get_compute_param(screen, ir_type, param, ret);
531 }
532
noop_is_format_supported(struct pipe_screen * pscreen,enum pipe_format format,enum pipe_texture_target target,unsigned sample_count,unsigned storage_sample_count,unsigned usage)533 static bool noop_is_format_supported(struct pipe_screen* pscreen,
534 enum pipe_format format,
535 enum pipe_texture_target target,
536 unsigned sample_count,
537 unsigned storage_sample_count,
538 unsigned usage)
539 {
540 struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen;
541
542 return screen->is_format_supported(screen, format, target, sample_count,
543 storage_sample_count, usage);
544 }
545
noop_get_timestamp(struct pipe_screen * pscreen)546 static uint64_t noop_get_timestamp(struct pipe_screen *pscreen)
547 {
548 return 0;
549 }
550
noop_destroy_screen(struct pipe_screen * screen)551 static void noop_destroy_screen(struct pipe_screen *screen)
552 {
553 struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)screen;
554 struct pipe_screen *oscreen = noop_screen->oscreen;
555
556 oscreen->destroy(oscreen);
557 slab_destroy_parent(&noop_screen->pool_transfers);
558 FREE(screen);
559 }
560
noop_fence_reference(struct pipe_screen * screen,struct pipe_fence_handle ** ptr,struct pipe_fence_handle * fence)561 static void noop_fence_reference(struct pipe_screen *screen,
562 struct pipe_fence_handle **ptr,
563 struct pipe_fence_handle *fence)
564 {
565 if (pipe_reference((struct pipe_reference*)*ptr,
566 (struct pipe_reference*)fence))
567 FREE(*ptr);
568
569 *ptr = fence;
570 }
571
noop_fence_finish(struct pipe_screen * screen,struct pipe_context * ctx,struct pipe_fence_handle * fence,uint64_t timeout)572 static bool noop_fence_finish(struct pipe_screen *screen,
573 struct pipe_context *ctx,
574 struct pipe_fence_handle *fence,
575 uint64_t timeout)
576 {
577 return true;
578 }
579
noop_query_memory_info(struct pipe_screen * pscreen,struct pipe_memory_info * info)580 static void noop_query_memory_info(struct pipe_screen *pscreen,
581 struct pipe_memory_info *info)
582 {
583 struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)pscreen;
584 struct pipe_screen *screen = noop_screen->oscreen;
585
586 screen->query_memory_info(screen, info);
587 }
588
noop_get_disk_shader_cache(struct pipe_screen * pscreen)589 static struct disk_cache *noop_get_disk_shader_cache(struct pipe_screen *pscreen)
590 {
591 struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen;
592
593 return screen->get_disk_shader_cache(screen);
594 }
595
noop_get_compiler_options(struct pipe_screen * pscreen,enum pipe_shader_ir ir,enum pipe_shader_type shader)596 static const void *noop_get_compiler_options(struct pipe_screen *pscreen,
597 enum pipe_shader_ir ir,
598 enum pipe_shader_type shader)
599 {
600 struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen;
601
602 return screen->get_compiler_options(screen, ir, shader);
603 }
604
noop_finalize_nir(struct pipe_screen * pscreen,void * nir)605 static char *noop_finalize_nir(struct pipe_screen *pscreen, void *nir)
606 {
607 struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen;
608
609 return screen->finalize_nir(screen, nir);
610 }
611
noop_check_resource_capability(struct pipe_screen * screen,struct pipe_resource * resource,unsigned bind)612 static bool noop_check_resource_capability(struct pipe_screen *screen,
613 struct pipe_resource *resource,
614 unsigned bind)
615 {
616 return true;
617 }
618
noop_set_max_shader_compiler_threads(struct pipe_screen * screen,unsigned max_threads)619 static void noop_set_max_shader_compiler_threads(struct pipe_screen *screen,
620 unsigned max_threads)
621 {
622 }
623
noop_is_parallel_shader_compilation_finished(struct pipe_screen * screen,void * shader,unsigned shader_type)624 static bool noop_is_parallel_shader_compilation_finished(struct pipe_screen *screen,
625 void *shader,
626 unsigned shader_type)
627 {
628 return true;
629 }
630
noop_is_dmabuf_modifier_supported(struct pipe_screen * screen,uint64_t modifier,enum pipe_format format,bool * external_only)631 static bool noop_is_dmabuf_modifier_supported(struct pipe_screen *screen,
632 uint64_t modifier, enum pipe_format format,
633 bool *external_only)
634 {
635 struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)screen;
636 struct pipe_screen *oscreen = noop_screen->oscreen;
637
638 return oscreen->is_dmabuf_modifier_supported(oscreen, modifier, format, external_only);
639 }
640
noop_get_dmabuf_modifier_planes(struct pipe_screen * screen,uint64_t modifier,enum pipe_format format)641 static unsigned int noop_get_dmabuf_modifier_planes(struct pipe_screen *screen,
642 uint64_t modifier,
643 enum pipe_format format)
644 {
645 struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)screen;
646 struct pipe_screen *oscreen = noop_screen->oscreen;
647
648 return oscreen->get_dmabuf_modifier_planes(oscreen, modifier, format);
649 }
650
noop_get_driver_uuid(struct pipe_screen * screen,char * uuid)651 static void noop_get_driver_uuid(struct pipe_screen *screen, char *uuid)
652 {
653 struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)screen;
654 struct pipe_screen *oscreen = noop_screen->oscreen;
655
656 oscreen->get_driver_uuid(oscreen, uuid);
657 }
658
noop_get_device_uuid(struct pipe_screen * screen,char * uuid)659 static void noop_get_device_uuid(struct pipe_screen *screen, char *uuid)
660 {
661 struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)screen;
662 struct pipe_screen *oscreen = noop_screen->oscreen;
663
664 oscreen->get_device_uuid(oscreen, uuid);
665 }
666
noop_query_dmabuf_modifiers(struct pipe_screen * screen,enum pipe_format format,int max,uint64_t * modifiers,unsigned int * external_only,int * count)667 static void noop_query_dmabuf_modifiers(struct pipe_screen *screen,
668 enum pipe_format format, int max,
669 uint64_t *modifiers,
670 unsigned int *external_only, int *count)
671 {
672 struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)screen;
673 struct pipe_screen *oscreen = noop_screen->oscreen;
674
675 oscreen->query_dmabuf_modifiers(oscreen, format, max, modifiers,
676 external_only, count);
677 }
678
679 static struct pipe_vertex_state *
noop_create_vertex_state(struct pipe_screen * screen,struct pipe_vertex_buffer * buffer,const struct pipe_vertex_element * elements,unsigned num_elements,struct pipe_resource * indexbuf,uint32_t full_velem_mask)680 noop_create_vertex_state(struct pipe_screen *screen,
681 struct pipe_vertex_buffer *buffer,
682 const struct pipe_vertex_element *elements,
683 unsigned num_elements,
684 struct pipe_resource *indexbuf,
685 uint32_t full_velem_mask)
686 {
687 struct pipe_vertex_state *state = CALLOC_STRUCT(pipe_vertex_state);
688
689 if (!state)
690 return NULL;
691
692 util_init_pipe_vertex_state(screen, buffer, elements, num_elements, indexbuf,
693 full_velem_mask, state);
694 return state;
695 }
696
noop_vertex_state_destroy(struct pipe_screen * screen,struct pipe_vertex_state * state)697 static void noop_vertex_state_destroy(struct pipe_screen *screen,
698 struct pipe_vertex_state *state)
699 {
700 pipe_vertex_buffer_unreference(&state->input.vbuffer);
701 pipe_resource_reference(&state->input.indexbuf, NULL);
702 FREE(state);
703 }
704
noop_screen_create(struct pipe_screen * oscreen)705 struct pipe_screen *noop_screen_create(struct pipe_screen *oscreen)
706 {
707 struct noop_pipe_screen *noop_screen;
708 struct pipe_screen *screen;
709
710 if (!debug_get_option_noop()) {
711 return oscreen;
712 }
713
714 noop_screen = CALLOC_STRUCT(noop_pipe_screen);
715 if (!noop_screen) {
716 return NULL;
717 }
718 noop_screen->oscreen = oscreen;
719 screen = &noop_screen->pscreen;
720
721 screen->destroy = noop_destroy_screen;
722 screen->get_name = noop_get_name;
723 screen->get_vendor = noop_get_vendor;
724 screen->get_device_vendor = noop_get_device_vendor;
725 screen->get_param = noop_get_param;
726 screen->get_shader_param = noop_get_shader_param;
727 screen->get_compute_param = noop_get_compute_param;
728 screen->get_paramf = noop_get_paramf;
729 screen->is_format_supported = noop_is_format_supported;
730 screen->context_create = noop_create_context;
731 screen->resource_create = noop_resource_create;
732 screen->resource_from_handle = noop_resource_from_handle;
733 screen->resource_get_handle = noop_resource_get_handle;
734 if (oscreen->resource_get_param)
735 screen->resource_get_param = noop_resource_get_param;
736 screen->resource_destroy = noop_resource_destroy;
737 screen->flush_frontbuffer = noop_flush_frontbuffer;
738 screen->get_timestamp = noop_get_timestamp;
739 screen->fence_reference = noop_fence_reference;
740 screen->fence_finish = noop_fence_finish;
741 screen->query_memory_info = noop_query_memory_info;
742 screen->get_disk_shader_cache = noop_get_disk_shader_cache;
743 screen->get_compiler_options = noop_get_compiler_options;
744 screen->finalize_nir = noop_finalize_nir;
745 screen->check_resource_capability = noop_check_resource_capability;
746 screen->set_max_shader_compiler_threads = noop_set_max_shader_compiler_threads;
747 screen->is_parallel_shader_compilation_finished = noop_is_parallel_shader_compilation_finished;
748 screen->is_dmabuf_modifier_supported = noop_is_dmabuf_modifier_supported;
749 screen->get_dmabuf_modifier_planes = noop_get_dmabuf_modifier_planes;
750 screen->get_driver_uuid = noop_get_driver_uuid;
751 screen->get_device_uuid = noop_get_device_uuid;
752 screen->query_dmabuf_modifiers = noop_query_dmabuf_modifiers;
753 screen->resource_create_with_modifiers = noop_resource_create_with_modifiers;
754 screen->create_vertex_state = noop_create_vertex_state;
755 screen->vertex_state_destroy = noop_vertex_state_destroy;
756
757 slab_create_parent(&noop_screen->pool_transfers,
758 sizeof(struct pipe_transfer), 64);
759
760 return screen;
761 }
762