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/u_format.h>
32 #include "noop_public.h"
34 DEBUG_GET_ONCE_BOOL_OPTION(noop, "GALLIUM_NOOP", FALSE)
36 void noop_init_state_functions(struct pipe_context *ctx);
38 struct noop_pipe_screen {
39 struct pipe_screen pscreen;
40 struct pipe_screen *oscreen;
49 static struct pipe_query *noop_create_query(struct pipe_context *ctx, unsigned query_type)
51 struct noop_query *query = CALLOC_STRUCT(noop_query);
53 return (struct pipe_query *)query;
56 static void noop_destroy_query(struct pipe_context *ctx, struct pipe_query *query)
61 static void noop_begin_query(struct pipe_context *ctx, struct pipe_query *query)
65 static void noop_end_query(struct pipe_context *ctx, struct pipe_query *query)
69 static boolean noop_get_query_result(struct pipe_context *ctx,
70 struct pipe_query *query,
71 boolean wait, void *vresult)
73 uint64_t *result = (uint64_t*)vresult;
83 struct noop_resource {
84 struct pipe_resource base;
87 struct sw_displaytarget *dt;
90 static struct pipe_resource *noop_resource_create(struct pipe_screen *screen,
91 const struct pipe_resource *templ)
93 struct noop_resource *nresource;
96 nresource = CALLOC_STRUCT(noop_resource);
97 if (nresource == NULL)
100 stride = util_format_get_stride(templ->format, templ->width0);
101 nresource->base = *templ;
102 nresource->base.screen = screen;
103 nresource->size = stride * templ->height0 * templ->depth0;
104 nresource->data = malloc(nresource->size);
105 pipe_reference_init(&nresource->base.reference, 1);
106 if (nresource->data == NULL) {
110 return &nresource->base;
113 static struct pipe_resource *noop_resource_from_handle(struct pipe_screen *screen,
114 const struct pipe_resource *templ,
115 struct winsys_handle *handle)
117 struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)screen;
118 struct pipe_screen *oscreen = noop_screen->oscreen;
119 struct pipe_resource *result;
120 struct pipe_resource *noop_resource;
122 result = oscreen->resource_from_handle(oscreen, templ, handle);
123 noop_resource = noop_resource_create(screen, result);
124 pipe_resource_reference(&result, NULL);
125 return noop_resource;
128 static boolean noop_resource_get_handle(struct pipe_screen *screen,
129 struct pipe_resource *resource,
130 struct winsys_handle *handle)
135 static void noop_resource_destroy(struct pipe_screen *screen,
136 struct pipe_resource *resource)
138 struct noop_resource *nresource = (struct noop_resource *)resource;
140 free(nresource->data);
144 static struct pipe_resource *noop_user_buffer_create(struct pipe_screen *screen,
145 void *ptr, unsigned bytes,
148 struct pipe_resource templ;
150 templ.target = PIPE_BUFFER;
151 templ.format = PIPE_FORMAT_R8_UNORM;
152 templ.usage = PIPE_USAGE_IMMUTABLE;
154 templ.width0 = bytes;
158 return noop_resource_create(screen, &templ);
165 static struct pipe_transfer *noop_get_transfer(struct pipe_context *context,
166 struct pipe_resource *resource,
168 enum pipe_transfer_usage usage,
169 const struct pipe_box *box)
171 struct pipe_transfer *transfer;
173 transfer = CALLOC_STRUCT(pipe_transfer);
174 if (transfer == NULL)
176 pipe_resource_reference(&transfer->resource, resource);
177 transfer->level = level;
178 transfer->usage = usage;
179 transfer->box = *box;
180 transfer->stride = 1;
181 transfer->layer_stride = 1;
185 static void *noop_transfer_map(struct pipe_context *pipe,
186 struct pipe_transfer *transfer)
188 struct noop_resource *nresource = (struct noop_resource *)transfer->resource;
190 return nresource->data;
193 static void noop_transfer_flush_region(struct pipe_context *pipe,
194 struct pipe_transfer *transfer,
195 const struct pipe_box *box)
199 static void noop_transfer_unmap(struct pipe_context *pipe,
200 struct pipe_transfer *transfer)
204 static void noop_transfer_destroy(struct pipe_context *pipe,
205 struct pipe_transfer *transfer)
207 pipe_resource_reference(&transfer->resource, NULL);
211 static void noop_transfer_inline_write(struct pipe_context *pipe,
212 struct pipe_resource *resource,
215 const struct pipe_box *box,
218 unsigned layer_stride)
226 static void noop_clear(struct pipe_context *ctx, unsigned buffers,
227 const float *rgba, double depth, unsigned stencil)
231 static void noop_clear_render_target(struct pipe_context *ctx,
232 struct pipe_surface *dst,
234 unsigned dstx, unsigned dsty,
235 unsigned width, unsigned height)
239 static void noop_clear_depth_stencil(struct pipe_context *ctx,
240 struct pipe_surface *dst,
241 unsigned clear_flags,
244 unsigned dstx, unsigned dsty,
245 unsigned width, unsigned height)
249 static void noop_resource_copy_region(struct pipe_context *ctx,
250 struct pipe_resource *dst,
252 unsigned dstx, unsigned dsty, unsigned dstz,
253 struct pipe_resource *src,
255 const struct pipe_box *src_box)
263 static void noop_flush(struct pipe_context *ctx,
264 struct pipe_fence_handle **fence)
268 static void noop_destroy_context(struct pipe_context *ctx)
273 static struct pipe_context *noop_create_context(struct pipe_screen *screen, void *priv)
275 struct pipe_context *ctx = CALLOC_STRUCT(pipe_context);
279 ctx->winsys = screen->winsys;
280 ctx->screen = screen;
282 ctx->destroy = noop_destroy_context;
283 ctx->flush = noop_flush;
284 ctx->clear = noop_clear;
285 ctx->clear_render_target = noop_clear_render_target;
286 ctx->clear_depth_stencil = noop_clear_depth_stencil;
287 ctx->resource_copy_region = noop_resource_copy_region;
288 ctx->create_query = noop_create_query;
289 ctx->destroy_query = noop_destroy_query;
290 ctx->begin_query = noop_begin_query;
291 ctx->end_query = noop_end_query;
292 ctx->get_query_result = noop_get_query_result;
293 ctx->get_transfer = noop_get_transfer;
294 ctx->transfer_map = noop_transfer_map;
295 ctx->transfer_flush_region = noop_transfer_flush_region;
296 ctx->transfer_unmap = noop_transfer_unmap;
297 ctx->transfer_destroy = noop_transfer_destroy;
298 ctx->transfer_inline_write = noop_transfer_inline_write;
299 noop_init_state_functions(ctx);
308 static void noop_flush_frontbuffer(struct pipe_screen *_screen,
309 struct pipe_resource *resource,
310 unsigned level, unsigned layer,
311 void *context_private)
315 static const char *noop_get_vendor(struct pipe_screen* pscreen)
320 static const char *noop_get_name(struct pipe_screen* pscreen)
325 static int noop_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
328 /* Supported features (boolean caps). */
329 case PIPE_CAP_NPOT_TEXTURES:
330 case PIPE_CAP_TWO_SIDED_STENCIL:
332 case PIPE_CAP_OCCLUSION_QUERY:
333 case PIPE_CAP_POINT_SPRITE:
334 case PIPE_CAP_ANISOTROPIC_FILTER:
335 case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
336 case PIPE_CAP_TEXTURE_MIRROR_REPEAT:
337 case PIPE_CAP_TEXTURE_SHADOW_MAP:
338 case PIPE_CAP_TEXTURE_SWIZZLE:
339 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
340 case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
343 case PIPE_CAP_DUAL_SOURCE_BLEND:
346 case PIPE_CAP_INDEP_BLEND_ENABLE:
347 case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE:
348 case PIPE_CAP_DEPTH_CLAMP:
349 case PIPE_CAP_SHADER_STENCIL_EXPORT:
350 case PIPE_CAP_TIMER_QUERY:
351 case PIPE_CAP_STREAM_OUTPUT:
352 case PIPE_CAP_PRIMITIVE_RESTART:
353 case PIPE_CAP_INDEP_BLEND_FUNC:
357 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
358 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
359 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
361 case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS:
363 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
364 case PIPE_CAP_MAX_COMBINED_SAMPLERS:
367 /* Render targets. */
368 case PIPE_CAP_MAX_RENDER_TARGETS:
371 /* Fragment coordinate conventions. */
372 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
373 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
375 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
376 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
384 static float noop_get_paramf(struct pipe_screen* pscreen, enum pipe_cap param)
387 case PIPE_CAP_MAX_LINE_WIDTH:
388 case PIPE_CAP_MAX_LINE_WIDTH_AA:
389 case PIPE_CAP_MAX_POINT_WIDTH:
390 case PIPE_CAP_MAX_POINT_WIDTH_AA:
392 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
394 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
401 static int noop_get_shader_param(struct pipe_screen* pscreen, unsigned shader, enum pipe_shader_cap param)
405 case PIPE_SHADER_FRAGMENT:
406 case PIPE_SHADER_VERTEX:
407 case PIPE_SHADER_GEOMETRY:
414 case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
415 case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
416 case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
417 case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
419 case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
421 case PIPE_SHADER_CAP_MAX_INPUTS:
423 case PIPE_SHADER_CAP_MAX_TEMPS:
425 case PIPE_SHADER_CAP_MAX_ADDRS:
427 case PIPE_SHADER_CAP_MAX_CONSTS:
429 case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
431 case PIPE_SHADER_CAP_MAX_PREDS:
433 case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED:
435 case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
436 case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
437 case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
438 case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
445 static boolean noop_is_format_supported(struct pipe_screen* screen,
446 enum pipe_format format,
447 enum pipe_texture_target target,
448 unsigned sample_count,
454 static void noop_destroy_screen(struct pipe_screen *screen)
456 struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)screen;
457 struct pipe_screen *oscreen = noop_screen->oscreen;
459 oscreen->destroy(oscreen);
463 struct pipe_screen *noop_screen_create(struct pipe_screen *oscreen)
465 struct noop_pipe_screen *noop_screen;
466 struct pipe_screen *screen;
468 if (!debug_get_option_noop()) {
472 noop_screen = CALLOC_STRUCT(noop_pipe_screen);
473 if (noop_screen == NULL) {
476 noop_screen->oscreen = oscreen;
477 screen = &noop_screen->pscreen;
479 screen->winsys = oscreen->winsys;
480 screen->destroy = noop_destroy_screen;
481 screen->get_name = noop_get_name;
482 screen->get_vendor = noop_get_vendor;
483 screen->get_param = noop_get_param;
484 screen->get_shader_param = noop_get_shader_param;
485 screen->get_paramf = noop_get_paramf;
486 screen->is_format_supported = noop_is_format_supported;
487 screen->context_create = noop_create_context;
488 screen->resource_create = noop_resource_create;
489 screen->resource_from_handle = noop_resource_from_handle;
490 screen->resource_get_handle = noop_resource_get_handle;
491 screen->resource_destroy = noop_resource_destroy;
492 screen->user_buffer_create = noop_user_buffer_create;
493 screen->flush_frontbuffer = noop_flush_frontbuffer;