2 * Copyright 2010 Red Hat Inc.
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:
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
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.
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_upload_mgr.h"
33 #include "noop_public.h"
35 DEBUG_GET_ONCE_BOOL_OPTION(noop
, "GALLIUM_NOOP", false)
37 void noop_init_state_functions(struct pipe_context
*ctx
);
39 struct noop_pipe_screen
{
40 struct pipe_screen pscreen
;
41 struct pipe_screen
*oscreen
;
50 static struct pipe_query
*noop_create_query(struct pipe_context
*ctx
, unsigned query_type
, unsigned index
)
52 struct noop_query
*query
= CALLOC_STRUCT(noop_query
);
54 return (struct pipe_query
*)query
;
57 static void noop_destroy_query(struct pipe_context
*ctx
, struct pipe_query
*query
)
62 static bool noop_begin_query(struct pipe_context
*ctx
, struct pipe_query
*query
)
67 static bool noop_end_query(struct pipe_context
*ctx
, struct pipe_query
*query
)
72 static bool noop_get_query_result(struct pipe_context
*ctx
,
73 struct pipe_query
*query
,
75 union pipe_query_result
*vresult
)
77 uint64_t *result
= (uint64_t*)vresult
;
84 noop_set_active_query_state(struct pipe_context
*pipe
, bool enable
)
92 struct noop_resource
{
93 struct pipe_resource base
;
96 struct sw_displaytarget
*dt
;
99 static struct pipe_resource
*noop_resource_create(struct pipe_screen
*screen
,
100 const struct pipe_resource
*templ
)
102 struct noop_resource
*nresource
;
105 nresource
= CALLOC_STRUCT(noop_resource
);
109 stride
= util_format_get_stride(templ
->format
, templ
->width0
);
110 nresource
->base
= *templ
;
111 nresource
->base
.screen
= screen
;
112 nresource
->size
= stride
* templ
->height0
* templ
->depth0
;
113 nresource
->data
= MALLOC(nresource
->size
);
114 pipe_reference_init(&nresource
->base
.reference
, 1);
115 if (nresource
->data
== NULL
) {
119 return &nresource
->base
;
122 static struct pipe_resource
*noop_resource_from_handle(struct pipe_screen
*screen
,
123 const struct pipe_resource
*templ
,
124 struct winsys_handle
*handle
,
127 struct noop_pipe_screen
*noop_screen
= (struct noop_pipe_screen
*)screen
;
128 struct pipe_screen
*oscreen
= noop_screen
->oscreen
;
129 struct pipe_resource
*result
;
130 struct pipe_resource
*noop_resource
;
132 result
= oscreen
->resource_from_handle(oscreen
, templ
, handle
, usage
);
133 noop_resource
= noop_resource_create(screen
, result
);
134 pipe_resource_reference(&result
, NULL
);
135 return noop_resource
;
138 static bool noop_resource_get_handle(struct pipe_screen
*pscreen
,
139 struct pipe_context
*ctx
,
140 struct pipe_resource
*resource
,
141 struct winsys_handle
*handle
,
144 struct noop_pipe_screen
*noop_screen
= (struct noop_pipe_screen
*)pscreen
;
145 struct pipe_screen
*screen
= noop_screen
->oscreen
;
146 struct pipe_resource
*tex
;
149 /* resource_get_handle musn't fail. Just create something and return it. */
150 tex
= screen
->resource_create(screen
, resource
);
154 result
= screen
->resource_get_handle(screen
, NULL
, tex
, handle
, usage
);
155 pipe_resource_reference(&tex
, NULL
);
159 static bool noop_resource_get_param(struct pipe_screen
*pscreen
,
160 struct pipe_context
*ctx
,
161 struct pipe_resource
*resource
,
164 enum pipe_resource_param param
,
165 unsigned handle_usage
,
168 struct noop_pipe_screen
*noop_screen
= (struct noop_pipe_screen
*)pscreen
;
169 struct pipe_screen
*screen
= noop_screen
->oscreen
;
170 struct pipe_resource
*tex
;
173 /* resource_get_param mustn't fail. Just create something and return it. */
174 tex
= screen
->resource_create(screen
, resource
);
178 result
= screen
->resource_get_param(screen
, NULL
, tex
, 0, 0, param
,
179 handle_usage
, value
);
180 pipe_resource_reference(&tex
, NULL
);
184 static void noop_resource_destroy(struct pipe_screen
*screen
,
185 struct pipe_resource
*resource
)
187 struct noop_resource
*nresource
= (struct noop_resource
*)resource
;
189 FREE(nresource
->data
);
197 static void *noop_transfer_map(struct pipe_context
*pipe
,
198 struct pipe_resource
*resource
,
201 const struct pipe_box
*box
,
202 struct pipe_transfer
**ptransfer
)
204 struct pipe_transfer
*transfer
;
205 struct noop_resource
*nresource
= (struct noop_resource
*)resource
;
207 transfer
= CALLOC_STRUCT(pipe_transfer
);
210 pipe_resource_reference(&transfer
->resource
, resource
);
211 transfer
->level
= level
;
212 transfer
->usage
= usage
;
213 transfer
->box
= *box
;
214 transfer
->stride
= 1;
215 transfer
->layer_stride
= 1;
216 *ptransfer
= transfer
;
218 return nresource
->data
;
221 static void noop_transfer_flush_region(struct pipe_context
*pipe
,
222 struct pipe_transfer
*transfer
,
223 const struct pipe_box
*box
)
227 static void noop_transfer_unmap(struct pipe_context
*pipe
,
228 struct pipe_transfer
*transfer
)
230 pipe_resource_reference(&transfer
->resource
, NULL
);
234 static void noop_buffer_subdata(struct pipe_context
*pipe
,
235 struct pipe_resource
*resource
,
236 unsigned usage
, unsigned offset
,
237 unsigned size
, const void *data
)
241 static void noop_texture_subdata(struct pipe_context
*pipe
,
242 struct pipe_resource
*resource
,
245 const struct pipe_box
*box
,
248 unsigned layer_stride
)
256 static void noop_clear(struct pipe_context
*ctx
, unsigned buffers
, const struct pipe_scissor_state
*scissor_state
,
257 const union pipe_color_union
*color
, double depth
, unsigned stencil
)
261 static void noop_clear_render_target(struct pipe_context
*ctx
,
262 struct pipe_surface
*dst
,
263 const union pipe_color_union
*color
,
264 unsigned dstx
, unsigned dsty
,
265 unsigned width
, unsigned height
,
266 bool render_condition_enabled
)
270 static void noop_clear_depth_stencil(struct pipe_context
*ctx
,
271 struct pipe_surface
*dst
,
272 unsigned clear_flags
,
275 unsigned dstx
, unsigned dsty
,
276 unsigned width
, unsigned height
,
277 bool render_condition_enabled
)
281 static void noop_resource_copy_region(struct pipe_context
*ctx
,
282 struct pipe_resource
*dst
,
284 unsigned dstx
, unsigned dsty
, unsigned dstz
,
285 struct pipe_resource
*src
,
287 const struct pipe_box
*src_box
)
292 static void noop_blit(struct pipe_context
*ctx
,
293 const struct pipe_blit_info
*info
)
299 noop_flush_resource(struct pipe_context
*ctx
,
300 struct pipe_resource
*resource
)
308 static void noop_flush(struct pipe_context
*ctx
,
309 struct pipe_fence_handle
**fence
,
316 static void noop_destroy_context(struct pipe_context
*ctx
)
318 if (ctx
->stream_uploader
)
319 u_upload_destroy(ctx
->stream_uploader
);
324 static bool noop_generate_mipmap(struct pipe_context
*ctx
,
325 struct pipe_resource
*resource
,
326 enum pipe_format format
,
329 unsigned first_layer
,
335 static void noop_invalidate_resource(struct pipe_context
*ctx
,
336 struct pipe_resource
*resource
)
340 static void noop_set_context_param(struct pipe_context
*ctx
,
341 enum pipe_context_param param
,
346 static struct pipe_context
*noop_create_context(struct pipe_screen
*screen
,
347 void *priv
, unsigned flags
)
349 struct pipe_context
*ctx
= CALLOC_STRUCT(pipe_context
);
354 ctx
->screen
= screen
;
357 ctx
->stream_uploader
= u_upload_create_default(ctx
);
358 if (!ctx
->stream_uploader
) {
362 ctx
->const_uploader
= ctx
->stream_uploader
;
364 ctx
->destroy
= noop_destroy_context
;
365 ctx
->flush
= noop_flush
;
366 ctx
->clear
= noop_clear
;
367 ctx
->clear_render_target
= noop_clear_render_target
;
368 ctx
->clear_depth_stencil
= noop_clear_depth_stencil
;
369 ctx
->resource_copy_region
= noop_resource_copy_region
;
370 ctx
->generate_mipmap
= noop_generate_mipmap
;
371 ctx
->blit
= noop_blit
;
372 ctx
->flush_resource
= noop_flush_resource
;
373 ctx
->create_query
= noop_create_query
;
374 ctx
->destroy_query
= noop_destroy_query
;
375 ctx
->begin_query
= noop_begin_query
;
376 ctx
->end_query
= noop_end_query
;
377 ctx
->get_query_result
= noop_get_query_result
;
378 ctx
->set_active_query_state
= noop_set_active_query_state
;
379 ctx
->transfer_map
= noop_transfer_map
;
380 ctx
->transfer_flush_region
= noop_transfer_flush_region
;
381 ctx
->transfer_unmap
= noop_transfer_unmap
;
382 ctx
->buffer_subdata
= noop_buffer_subdata
;
383 ctx
->texture_subdata
= noop_texture_subdata
;
384 ctx
->invalidate_resource
= noop_invalidate_resource
;
385 ctx
->set_context_param
= noop_set_context_param
;
386 noop_init_state_functions(ctx
);
395 static void noop_flush_frontbuffer(struct pipe_screen
*_screen
,
396 struct pipe_resource
*resource
,
397 unsigned level
, unsigned layer
,
398 void *context_private
, struct pipe_box
*box
)
402 static const char *noop_get_vendor(struct pipe_screen
* pscreen
)
407 static const char *noop_get_device_vendor(struct pipe_screen
* pscreen
)
412 static const char *noop_get_name(struct pipe_screen
* pscreen
)
417 static int noop_get_param(struct pipe_screen
* pscreen
, enum pipe_cap param
)
419 struct pipe_screen
*screen
= ((struct noop_pipe_screen
*)pscreen
)->oscreen
;
421 return screen
->get_param(screen
, param
);
424 static float noop_get_paramf(struct pipe_screen
* pscreen
,
425 enum pipe_capf param
)
427 struct pipe_screen
*screen
= ((struct noop_pipe_screen
*)pscreen
)->oscreen
;
429 return screen
->get_paramf(screen
, param
);
432 static int noop_get_shader_param(struct pipe_screen
* pscreen
,
433 enum pipe_shader_type shader
,
434 enum pipe_shader_cap param
)
436 struct pipe_screen
*screen
= ((struct noop_pipe_screen
*)pscreen
)->oscreen
;
438 return screen
->get_shader_param(screen
, shader
, param
);
441 static int noop_get_compute_param(struct pipe_screen
*pscreen
,
442 enum pipe_shader_ir ir_type
,
443 enum pipe_compute_cap param
,
446 struct pipe_screen
*screen
= ((struct noop_pipe_screen
*)pscreen
)->oscreen
;
448 return screen
->get_compute_param(screen
, ir_type
, param
, ret
);
451 static bool noop_is_format_supported(struct pipe_screen
* pscreen
,
452 enum pipe_format format
,
453 enum pipe_texture_target target
,
454 unsigned sample_count
,
455 unsigned storage_sample_count
,
458 struct pipe_screen
*screen
= ((struct noop_pipe_screen
*)pscreen
)->oscreen
;
460 return screen
->is_format_supported(screen
, format
, target
, sample_count
,
461 storage_sample_count
, usage
);
464 static uint64_t noop_get_timestamp(struct pipe_screen
*pscreen
)
469 static void noop_destroy_screen(struct pipe_screen
*screen
)
471 struct noop_pipe_screen
*noop_screen
= (struct noop_pipe_screen
*)screen
;
472 struct pipe_screen
*oscreen
= noop_screen
->oscreen
;
474 oscreen
->destroy(oscreen
);
478 static void noop_fence_reference(struct pipe_screen
*screen
,
479 struct pipe_fence_handle
**ptr
,
480 struct pipe_fence_handle
*fence
)
484 static bool noop_fence_finish(struct pipe_screen
*screen
,
485 struct pipe_context
*ctx
,
486 struct pipe_fence_handle
*fence
,
492 static void noop_query_memory_info(struct pipe_screen
*pscreen
,
493 struct pipe_memory_info
*info
)
495 struct noop_pipe_screen
*noop_screen
= (struct noop_pipe_screen
*)pscreen
;
496 struct pipe_screen
*screen
= noop_screen
->oscreen
;
498 screen
->query_memory_info(screen
, info
);
501 static struct disk_cache
*noop_get_disk_shader_cache(struct pipe_screen
*pscreen
)
503 struct pipe_screen
*screen
= ((struct noop_pipe_screen
*)pscreen
)->oscreen
;
505 return screen
->get_disk_shader_cache(screen
);
508 static const void *noop_get_compiler_options(struct pipe_screen
*pscreen
,
509 enum pipe_shader_ir ir
,
510 enum pipe_shader_type shader
)
512 struct pipe_screen
*screen
= ((struct noop_pipe_screen
*)pscreen
)->oscreen
;
514 return screen
->get_compiler_options(screen
, ir
, shader
);
517 static void noop_finalize_nir(struct pipe_screen
*pscreen
, void *nir
, bool optimize
)
519 struct pipe_screen
*screen
= ((struct noop_pipe_screen
*)pscreen
)->oscreen
;
521 screen
->finalize_nir(screen
, nir
, optimize
);
524 struct pipe_screen
*noop_screen_create(struct pipe_screen
*oscreen
)
526 struct noop_pipe_screen
*noop_screen
;
527 struct pipe_screen
*screen
;
529 if (!debug_get_option_noop()) {
533 noop_screen
= CALLOC_STRUCT(noop_pipe_screen
);
537 noop_screen
->oscreen
= oscreen
;
538 screen
= &noop_screen
->pscreen
;
540 screen
->destroy
= noop_destroy_screen
;
541 screen
->get_name
= noop_get_name
;
542 screen
->get_vendor
= noop_get_vendor
;
543 screen
->get_device_vendor
= noop_get_device_vendor
;
544 screen
->get_param
= noop_get_param
;
545 screen
->get_shader_param
= noop_get_shader_param
;
546 screen
->get_compute_param
= noop_get_compute_param
;
547 screen
->get_paramf
= noop_get_paramf
;
548 screen
->is_format_supported
= noop_is_format_supported
;
549 screen
->context_create
= noop_create_context
;
550 screen
->resource_create
= noop_resource_create
;
551 screen
->resource_from_handle
= noop_resource_from_handle
;
552 screen
->resource_get_handle
= noop_resource_get_handle
;
553 if (oscreen
->resource_get_param
)
554 screen
->resource_get_param
= noop_resource_get_param
;
555 screen
->resource_destroy
= noop_resource_destroy
;
556 screen
->flush_frontbuffer
= noop_flush_frontbuffer
;
557 screen
->get_timestamp
= noop_get_timestamp
;
558 screen
->fence_reference
= noop_fence_reference
;
559 screen
->fence_finish
= noop_fence_finish
;
560 screen
->query_memory_info
= noop_query_memory_info
;
561 screen
->get_disk_shader_cache
= noop_get_disk_shader_cache
;
562 screen
->get_compiler_options
= noop_get_compiler_options
;
563 screen
->finalize_nir
= noop_finalize_nir
;