gallium: add render_condition_enable param to clear_render_target/depth_stencil
[mesa.git] / src / gallium / drivers / noop / noop_pipe.c
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/u_format.h"
32 #include "noop_public.h"
33
34 DEBUG_GET_ONCE_BOOL_OPTION(noop, "GALLIUM_NOOP", FALSE)
35
36 void noop_init_state_functions(struct pipe_context *ctx);
37
38 struct noop_pipe_screen {
39 struct pipe_screen pscreen;
40 struct pipe_screen *oscreen;
41 };
42
43 /*
44 * query
45 */
46 struct noop_query {
47 unsigned query;
48 };
49 static struct pipe_query *noop_create_query(struct pipe_context *ctx, unsigned query_type, unsigned index)
50 {
51 struct noop_query *query = CALLOC_STRUCT(noop_query);
52
53 return (struct pipe_query *)query;
54 }
55
56 static void noop_destroy_query(struct pipe_context *ctx, struct pipe_query *query)
57 {
58 FREE(query);
59 }
60
61 static boolean noop_begin_query(struct pipe_context *ctx, struct pipe_query *query)
62 {
63 return true;
64 }
65
66 static bool noop_end_query(struct pipe_context *ctx, struct pipe_query *query)
67 {
68 return true;
69 }
70
71 static boolean noop_get_query_result(struct pipe_context *ctx,
72 struct pipe_query *query,
73 boolean wait,
74 union pipe_query_result *vresult)
75 {
76 uint64_t *result = (uint64_t*)vresult;
77
78 *result = 0;
79 return TRUE;
80 }
81
82 static void
83 noop_set_active_query_state(struct pipe_context *pipe, boolean enable)
84 {
85 }
86
87
88 /*
89 * resource
90 */
91 struct noop_resource {
92 struct pipe_resource base;
93 unsigned size;
94 char *data;
95 struct sw_displaytarget *dt;
96 };
97
98 static struct pipe_resource *noop_resource_create(struct pipe_screen *screen,
99 const struct pipe_resource *templ)
100 {
101 struct noop_resource *nresource;
102 unsigned stride;
103
104 nresource = CALLOC_STRUCT(noop_resource);
105 if (!nresource)
106 return NULL;
107
108 stride = util_format_get_stride(templ->format, templ->width0);
109 nresource->base = *templ;
110 nresource->base.screen = screen;
111 nresource->size = stride * templ->height0 * templ->depth0;
112 nresource->data = MALLOC(nresource->size);
113 pipe_reference_init(&nresource->base.reference, 1);
114 if (nresource->data == NULL) {
115 FREE(nresource);
116 return NULL;
117 }
118 return &nresource->base;
119 }
120
121 static struct pipe_resource *noop_resource_from_handle(struct pipe_screen *screen,
122 const struct pipe_resource *templ,
123 struct winsys_handle *handle,
124 unsigned usage)
125 {
126 struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)screen;
127 struct pipe_screen *oscreen = noop_screen->oscreen;
128 struct pipe_resource *result;
129 struct pipe_resource *noop_resource;
130
131 result = oscreen->resource_from_handle(oscreen, templ, handle, usage);
132 noop_resource = noop_resource_create(screen, result);
133 pipe_resource_reference(&result, NULL);
134 return noop_resource;
135 }
136
137 static boolean noop_resource_get_handle(struct pipe_screen *screen,
138 struct pipe_resource *resource,
139 struct winsys_handle *handle,
140 unsigned usage)
141 {
142 return FALSE;
143 }
144
145 static void noop_resource_destroy(struct pipe_screen *screen,
146 struct pipe_resource *resource)
147 {
148 struct noop_resource *nresource = (struct noop_resource *)resource;
149
150 FREE(nresource->data);
151 FREE(resource);
152 }
153
154
155 /*
156 * transfer
157 */
158 static void *noop_transfer_map(struct pipe_context *pipe,
159 struct pipe_resource *resource,
160 unsigned level,
161 enum pipe_transfer_usage usage,
162 const struct pipe_box *box,
163 struct pipe_transfer **ptransfer)
164 {
165 struct pipe_transfer *transfer;
166 struct noop_resource *nresource = (struct noop_resource *)resource;
167
168 transfer = CALLOC_STRUCT(pipe_transfer);
169 if (!transfer)
170 return NULL;
171 pipe_resource_reference(&transfer->resource, resource);
172 transfer->level = level;
173 transfer->usage = usage;
174 transfer->box = *box;
175 transfer->stride = 1;
176 transfer->layer_stride = 1;
177 *ptransfer = transfer;
178
179 return nresource->data;
180 }
181
182 static void noop_transfer_flush_region(struct pipe_context *pipe,
183 struct pipe_transfer *transfer,
184 const struct pipe_box *box)
185 {
186 }
187
188 static void noop_transfer_unmap(struct pipe_context *pipe,
189 struct pipe_transfer *transfer)
190 {
191 pipe_resource_reference(&transfer->resource, NULL);
192 FREE(transfer);
193 }
194
195 static void noop_buffer_subdata(struct pipe_context *pipe,
196 struct pipe_resource *resource,
197 unsigned usage, unsigned offset,
198 unsigned size, const void *data)
199 {
200 }
201
202 static void noop_texture_subdata(struct pipe_context *pipe,
203 struct pipe_resource *resource,
204 unsigned level,
205 unsigned usage,
206 const struct pipe_box *box,
207 const void *data,
208 unsigned stride,
209 unsigned layer_stride)
210 {
211 }
212
213
214 /*
215 * clear/copy
216 */
217 static void noop_clear(struct pipe_context *ctx, unsigned buffers,
218 const union pipe_color_union *color, double depth, unsigned stencil)
219 {
220 }
221
222 static void noop_clear_render_target(struct pipe_context *ctx,
223 struct pipe_surface *dst,
224 const union pipe_color_union *color,
225 unsigned dstx, unsigned dsty,
226 unsigned width, unsigned height,
227 bool render_condition_enabled)
228 {
229 }
230
231 static void noop_clear_depth_stencil(struct pipe_context *ctx,
232 struct pipe_surface *dst,
233 unsigned clear_flags,
234 double depth,
235 unsigned stencil,
236 unsigned dstx, unsigned dsty,
237 unsigned width, unsigned height,
238 bool render_condition_enabled)
239 {
240 }
241
242 static void noop_resource_copy_region(struct pipe_context *ctx,
243 struct pipe_resource *dst,
244 unsigned dst_level,
245 unsigned dstx, unsigned dsty, unsigned dstz,
246 struct pipe_resource *src,
247 unsigned src_level,
248 const struct pipe_box *src_box)
249 {
250 }
251
252
253 static void noop_blit(struct pipe_context *ctx,
254 const struct pipe_blit_info *info)
255 {
256 }
257
258
259 static void
260 noop_flush_resource(struct pipe_context *ctx,
261 struct pipe_resource *resource)
262 {
263 }
264
265
266 /*
267 * context
268 */
269 static void noop_flush(struct pipe_context *ctx,
270 struct pipe_fence_handle **fence,
271 unsigned flags)
272 {
273 }
274
275 static void noop_destroy_context(struct pipe_context *ctx)
276 {
277 FREE(ctx);
278 }
279
280 static struct pipe_context *noop_create_context(struct pipe_screen *screen,
281 void *priv, unsigned flags)
282 {
283 struct pipe_context *ctx = CALLOC_STRUCT(pipe_context);
284
285 if (!ctx)
286 return NULL;
287 ctx->screen = screen;
288 ctx->priv = priv;
289 ctx->destroy = noop_destroy_context;
290 ctx->flush = noop_flush;
291 ctx->clear = noop_clear;
292 ctx->clear_render_target = noop_clear_render_target;
293 ctx->clear_depth_stencil = noop_clear_depth_stencil;
294 ctx->resource_copy_region = noop_resource_copy_region;
295 ctx->blit = noop_blit;
296 ctx->flush_resource = noop_flush_resource;
297 ctx->create_query = noop_create_query;
298 ctx->destroy_query = noop_destroy_query;
299 ctx->begin_query = noop_begin_query;
300 ctx->end_query = noop_end_query;
301 ctx->get_query_result = noop_get_query_result;
302 ctx->set_active_query_state = noop_set_active_query_state;
303 ctx->transfer_map = noop_transfer_map;
304 ctx->transfer_flush_region = noop_transfer_flush_region;
305 ctx->transfer_unmap = noop_transfer_unmap;
306 ctx->buffer_subdata = noop_buffer_subdata;
307 ctx->texture_subdata = noop_texture_subdata;
308 noop_init_state_functions(ctx);
309
310 return ctx;
311 }
312
313
314 /*
315 * pipe_screen
316 */
317 static void noop_flush_frontbuffer(struct pipe_screen *_screen,
318 struct pipe_resource *resource,
319 unsigned level, unsigned layer,
320 void *context_private, struct pipe_box *box)
321 {
322 }
323
324 static const char *noop_get_vendor(struct pipe_screen* pscreen)
325 {
326 return "X.Org";
327 }
328
329 static const char *noop_get_device_vendor(struct pipe_screen* pscreen)
330 {
331 return "NONE";
332 }
333
334 static const char *noop_get_name(struct pipe_screen* pscreen)
335 {
336 return "NOOP";
337 }
338
339 static int noop_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
340 {
341 struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen;
342
343 return screen->get_param(screen, param);
344 }
345
346 static float noop_get_paramf(struct pipe_screen* pscreen,
347 enum pipe_capf param)
348 {
349 struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen;
350
351 return screen->get_paramf(screen, param);
352 }
353
354 static int noop_get_shader_param(struct pipe_screen* pscreen, unsigned shader, enum pipe_shader_cap param)
355 {
356 struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen;
357
358 return screen->get_shader_param(screen, shader, param);
359 }
360
361 static boolean noop_is_format_supported(struct pipe_screen* pscreen,
362 enum pipe_format format,
363 enum pipe_texture_target target,
364 unsigned sample_count,
365 unsigned usage)
366 {
367 struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen;
368
369 return screen->is_format_supported(screen, format, target, sample_count, usage);
370 }
371
372 static uint64_t noop_get_timestamp(struct pipe_screen *pscreen)
373 {
374 return 0;
375 }
376
377 static void noop_destroy_screen(struct pipe_screen *screen)
378 {
379 struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)screen;
380 struct pipe_screen *oscreen = noop_screen->oscreen;
381
382 oscreen->destroy(oscreen);
383 FREE(screen);
384 }
385
386 struct pipe_screen *noop_screen_create(struct pipe_screen *oscreen)
387 {
388 struct noop_pipe_screen *noop_screen;
389 struct pipe_screen *screen;
390
391 if (!debug_get_option_noop()) {
392 return oscreen;
393 }
394
395 noop_screen = CALLOC_STRUCT(noop_pipe_screen);
396 if (!noop_screen) {
397 return NULL;
398 }
399 noop_screen->oscreen = oscreen;
400 screen = &noop_screen->pscreen;
401
402 screen->destroy = noop_destroy_screen;
403 screen->get_name = noop_get_name;
404 screen->get_vendor = noop_get_vendor;
405 screen->get_device_vendor = noop_get_device_vendor;
406 screen->get_param = noop_get_param;
407 screen->get_shader_param = noop_get_shader_param;
408 screen->get_paramf = noop_get_paramf;
409 screen->is_format_supported = noop_is_format_supported;
410 screen->context_create = noop_create_context;
411 screen->resource_create = noop_resource_create;
412 screen->resource_from_handle = noop_resource_from_handle;
413 screen->resource_get_handle = noop_resource_get_handle;
414 screen->resource_destroy = noop_resource_destroy;
415 screen->flush_frontbuffer = noop_flush_frontbuffer;
416 screen->get_timestamp = noop_get_timestamp;
417
418 return screen;
419 }