Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5563 | serge | 1 | /************************************************************************** |
2 | * |
||
3 | * Copyright 2010 VMware, Inc. |
||
4 | * All Rights Reserved. |
||
5 | * |
||
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
7 | * copy of this software and associated documentation files (the |
||
8 | * "Software"), to deal in the Software without restriction, including |
||
9 | * without limitation the rights to use, copy, modify, merge, publish, |
||
10 | * distribute, sub license, and/or sell copies of the Software, and to |
||
11 | * permit persons to whom the Software is furnished to do so, subject to |
||
12 | * the following conditions: |
||
13 | * |
||
14 | * The above copyright notice and this permission notice (including the |
||
15 | * next paragraph) shall be included in all copies or substantial portions |
||
16 | * of the Software. |
||
17 | * |
||
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||
19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||
20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
||
21 | * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR |
||
22 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||
23 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||
24 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||
25 | * |
||
26 | **************************************************************************/ |
||
27 | |||
28 | |||
29 | #include "pipe/p_context.h" |
||
30 | #include "util/u_memory.h" |
||
31 | #include "util/u_inlines.h" |
||
32 | #include "util/u_simple_list.h" |
||
33 | |||
34 | #include "rbug/rbug_context.h" |
||
35 | |||
36 | #include "rbug_context.h" |
||
37 | #include "rbug_objects.h" |
||
38 | |||
39 | |||
40 | static void |
||
41 | rbug_destroy(struct pipe_context *_pipe) |
||
42 | { |
||
43 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
44 | struct pipe_context *pipe = rb_pipe->pipe; |
||
45 | |||
46 | remove_from_list(&rb_pipe->list); |
||
47 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
48 | pipe->destroy(pipe); |
||
49 | rb_pipe->pipe = NULL; |
||
50 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
51 | |||
52 | FREE(rb_pipe); |
||
53 | } |
||
54 | |||
55 | static void |
||
56 | rbug_draw_block_locked(struct rbug_context *rb_pipe, int flag) |
||
57 | { |
||
58 | |||
59 | if (rb_pipe->draw_blocker & flag) { |
||
60 | rb_pipe->draw_blocked |= flag; |
||
61 | } else if ((rb_pipe->draw_rule.blocker & flag) && |
||
62 | (rb_pipe->draw_blocker & RBUG_BLOCK_RULE)) { |
||
63 | unsigned k; |
||
64 | boolean block = FALSE; |
||
65 | unsigned sh; |
||
66 | |||
67 | debug_printf("%s (%p %p) (%p %p) (%p %u) (%p %u)\n", __FUNCTION__, |
||
68 | (void *) rb_pipe->draw_rule.shader[PIPE_SHADER_FRAGMENT], |
||
69 | (void *) rb_pipe->curr.shader[PIPE_SHADER_FRAGMENT], |
||
70 | (void *) rb_pipe->draw_rule.shader[PIPE_SHADER_VERTEX], |
||
71 | (void *) rb_pipe->curr.shader[PIPE_SHADER_VERTEX], |
||
72 | (void *) rb_pipe->draw_rule.surf, 0, |
||
73 | (void *) rb_pipe->draw_rule.texture, 0); |
||
74 | for (sh = 0; sh < PIPE_SHADER_TYPES; sh++) { |
||
75 | if (rb_pipe->draw_rule.shader[sh] && |
||
76 | rb_pipe->draw_rule.shader[sh] == rb_pipe->curr.shader[sh]) |
||
77 | block = TRUE; |
||
78 | } |
||
79 | |||
80 | if (rb_pipe->draw_rule.surf && |
||
81 | rb_pipe->draw_rule.surf == rb_pipe->curr.zsbuf) |
||
82 | block = TRUE; |
||
83 | if (rb_pipe->draw_rule.surf) |
||
84 | for (k = 0; k < rb_pipe->curr.nr_cbufs; k++) |
||
85 | if (rb_pipe->draw_rule.surf == rb_pipe->curr.cbufs[k]) |
||
86 | block = TRUE; |
||
87 | if (rb_pipe->draw_rule.texture) { |
||
88 | for (sh = 0; sh < Elements(rb_pipe->curr.num_views); sh++) { |
||
89 | for (k = 0; k < rb_pipe->curr.num_views[sh]; k++) { |
||
90 | if (rb_pipe->draw_rule.texture == rb_pipe->curr.texs[sh][k]) { |
||
91 | block = TRUE; |
||
92 | sh = PIPE_SHADER_TYPES; /* to break out of both loops */ |
||
93 | break; |
||
94 | } |
||
95 | } |
||
96 | } |
||
97 | } |
||
98 | |||
99 | if (block) |
||
100 | rb_pipe->draw_blocked |= (flag | RBUG_BLOCK_RULE); |
||
101 | } |
||
102 | |||
103 | if (rb_pipe->draw_blocked) |
||
104 | rbug_notify_draw_blocked(rb_pipe); |
||
105 | |||
106 | /* wait for rbug to clear the blocked flag */ |
||
107 | while (rb_pipe->draw_blocked & flag) { |
||
108 | rb_pipe->draw_blocked |= flag; |
||
109 | pipe_condvar_wait(rb_pipe->draw_cond, rb_pipe->draw_mutex); |
||
110 | } |
||
111 | |||
112 | } |
||
113 | |||
114 | static void |
||
115 | rbug_draw_vbo(struct pipe_context *_pipe, const struct pipe_draw_info *info) |
||
116 | { |
||
117 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
118 | struct pipe_context *pipe = rb_pipe->pipe; |
||
119 | |||
120 | pipe_mutex_lock(rb_pipe->draw_mutex); |
||
121 | rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_BEFORE); |
||
122 | |||
123 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
124 | /* XXX loop over PIPE_SHADER_x here */ |
||
125 | if (!(rb_pipe->curr.shader[PIPE_SHADER_FRAGMENT] && rb_pipe->curr.shader[PIPE_SHADER_FRAGMENT]->disabled) && |
||
126 | !(rb_pipe->curr.shader[PIPE_SHADER_GEOMETRY] && rb_pipe->curr.shader[PIPE_SHADER_GEOMETRY]->disabled) && |
||
127 | !(rb_pipe->curr.shader[PIPE_SHADER_VERTEX] && rb_pipe->curr.shader[PIPE_SHADER_VERTEX]->disabled)) |
||
128 | pipe->draw_vbo(pipe, info); |
||
129 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
130 | |||
131 | rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_AFTER); |
||
132 | pipe_mutex_unlock(rb_pipe->draw_mutex); |
||
133 | } |
||
134 | |||
135 | static struct pipe_query * |
||
136 | rbug_create_query(struct pipe_context *_pipe, |
||
137 | unsigned query_type) |
||
138 | { |
||
139 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
140 | struct pipe_context *pipe = rb_pipe->pipe; |
||
141 | |||
142 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
143 | return pipe->create_query(pipe, |
||
144 | query_type); |
||
145 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
146 | } |
||
147 | |||
148 | static void |
||
149 | rbug_destroy_query(struct pipe_context *_pipe, |
||
150 | struct pipe_query *query) |
||
151 | { |
||
152 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
153 | struct pipe_context *pipe = rb_pipe->pipe; |
||
154 | |||
155 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
156 | pipe->destroy_query(pipe, |
||
157 | query); |
||
158 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
159 | } |
||
160 | |||
161 | static void |
||
162 | rbug_begin_query(struct pipe_context *_pipe, |
||
163 | struct pipe_query *query) |
||
164 | { |
||
165 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
166 | struct pipe_context *pipe = rb_pipe->pipe; |
||
167 | |||
168 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
169 | pipe->begin_query(pipe, |
||
170 | query); |
||
171 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
172 | } |
||
173 | |||
174 | static void |
||
175 | rbug_end_query(struct pipe_context *_pipe, |
||
176 | struct pipe_query *query) |
||
177 | { |
||
178 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
179 | struct pipe_context *pipe = rb_pipe->pipe; |
||
180 | |||
181 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
182 | pipe->end_query(pipe, |
||
183 | query); |
||
184 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
185 | } |
||
186 | |||
187 | static boolean |
||
188 | rbug_get_query_result(struct pipe_context *_pipe, |
||
189 | struct pipe_query *query, |
||
190 | boolean wait, |
||
191 | union pipe_query_result *result) |
||
192 | { |
||
193 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
194 | struct pipe_context *pipe = rb_pipe->pipe; |
||
195 | boolean ret; |
||
196 | |||
197 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
198 | ret = pipe->get_query_result(pipe, |
||
199 | query, |
||
200 | wait, |
||
201 | result); |
||
202 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
203 | |||
204 | return ret; |
||
205 | } |
||
206 | |||
207 | static void * |
||
208 | rbug_create_blend_state(struct pipe_context *_pipe, |
||
209 | const struct pipe_blend_state *blend) |
||
210 | { |
||
211 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
212 | struct pipe_context *pipe = rb_pipe->pipe; |
||
213 | void *ret; |
||
214 | |||
215 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
216 | ret = pipe->create_blend_state(pipe, |
||
217 | blend); |
||
218 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
219 | |||
220 | return ret; |
||
221 | } |
||
222 | |||
223 | static void |
||
224 | rbug_bind_blend_state(struct pipe_context *_pipe, |
||
225 | void *blend) |
||
226 | { |
||
227 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
228 | struct pipe_context *pipe = rb_pipe->pipe; |
||
229 | |||
230 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
231 | pipe->bind_blend_state(pipe, |
||
232 | blend); |
||
233 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
234 | } |
||
235 | |||
236 | static void |
||
237 | rbug_delete_blend_state(struct pipe_context *_pipe, |
||
238 | void *blend) |
||
239 | { |
||
240 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
241 | struct pipe_context *pipe = rb_pipe->pipe; |
||
242 | |||
243 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
244 | pipe->delete_blend_state(pipe, |
||
245 | blend); |
||
246 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
247 | } |
||
248 | |||
249 | static void * |
||
250 | rbug_create_sampler_state(struct pipe_context *_pipe, |
||
251 | const struct pipe_sampler_state *sampler) |
||
252 | { |
||
253 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
254 | struct pipe_context *pipe = rb_pipe->pipe; |
||
255 | void *ret; |
||
256 | |||
257 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
258 | ret = pipe->create_sampler_state(pipe, |
||
259 | sampler); |
||
260 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
261 | |||
262 | return ret; |
||
263 | } |
||
264 | |||
265 | static void |
||
266 | rbug_bind_fragment_sampler_states(struct pipe_context *_pipe, |
||
267 | unsigned num_samplers, |
||
268 | void **samplers) |
||
269 | { |
||
270 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
271 | struct pipe_context *pipe = rb_pipe->pipe; |
||
272 | |||
273 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
274 | pipe->bind_fragment_sampler_states(pipe, |
||
275 | num_samplers, |
||
276 | samplers); |
||
277 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
278 | } |
||
279 | |||
280 | static void |
||
281 | rbug_bind_vertex_sampler_states(struct pipe_context *_pipe, |
||
282 | unsigned num_samplers, |
||
283 | void **samplers) |
||
284 | { |
||
285 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
286 | struct pipe_context *pipe = rb_pipe->pipe; |
||
287 | |||
288 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
289 | pipe->bind_vertex_sampler_states(pipe, |
||
290 | num_samplers, |
||
291 | samplers); |
||
292 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
293 | } |
||
294 | |||
295 | static void |
||
296 | rbug_delete_sampler_state(struct pipe_context *_pipe, |
||
297 | void *sampler) |
||
298 | { |
||
299 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
300 | struct pipe_context *pipe = rb_pipe->pipe; |
||
301 | |||
302 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
303 | pipe->delete_sampler_state(pipe, |
||
304 | sampler); |
||
305 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
306 | } |
||
307 | |||
308 | static void * |
||
309 | rbug_create_rasterizer_state(struct pipe_context *_pipe, |
||
310 | const struct pipe_rasterizer_state *rasterizer) |
||
311 | { |
||
312 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
313 | struct pipe_context *pipe = rb_pipe->pipe; |
||
314 | void *ret; |
||
315 | |||
316 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
317 | ret = pipe->create_rasterizer_state(pipe, |
||
318 | rasterizer); |
||
319 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
320 | |||
321 | return ret; |
||
322 | } |
||
323 | |||
324 | static void |
||
325 | rbug_bind_rasterizer_state(struct pipe_context *_pipe, |
||
326 | void *rasterizer) |
||
327 | { |
||
328 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
329 | struct pipe_context *pipe = rb_pipe->pipe; |
||
330 | |||
331 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
332 | pipe->bind_rasterizer_state(pipe, |
||
333 | rasterizer); |
||
334 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
335 | } |
||
336 | |||
337 | static void |
||
338 | rbug_delete_rasterizer_state(struct pipe_context *_pipe, |
||
339 | void *rasterizer) |
||
340 | { |
||
341 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
342 | struct pipe_context *pipe = rb_pipe->pipe; |
||
343 | |||
344 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
345 | pipe->delete_rasterizer_state(pipe, |
||
346 | rasterizer); |
||
347 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
348 | } |
||
349 | |||
350 | static void * |
||
351 | rbug_create_depth_stencil_alpha_state(struct pipe_context *_pipe, |
||
352 | const struct pipe_depth_stencil_alpha_state *depth_stencil_alpha) |
||
353 | { |
||
354 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
355 | struct pipe_context *pipe = rb_pipe->pipe; |
||
356 | void *ret; |
||
357 | |||
358 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
359 | ret = pipe->create_depth_stencil_alpha_state(pipe, |
||
360 | depth_stencil_alpha); |
||
361 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
362 | |||
363 | return ret; |
||
364 | } |
||
365 | |||
366 | static void |
||
367 | rbug_bind_depth_stencil_alpha_state(struct pipe_context *_pipe, |
||
368 | void *depth_stencil_alpha) |
||
369 | { |
||
370 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
371 | struct pipe_context *pipe = rb_pipe->pipe; |
||
372 | |||
373 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
374 | pipe->bind_depth_stencil_alpha_state(pipe, |
||
375 | depth_stencil_alpha); |
||
376 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
377 | } |
||
378 | |||
379 | static void |
||
380 | rbug_delete_depth_stencil_alpha_state(struct pipe_context *_pipe, |
||
381 | void *depth_stencil_alpha) |
||
382 | { |
||
383 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
384 | struct pipe_context *pipe = rb_pipe->pipe; |
||
385 | |||
386 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
387 | pipe->delete_depth_stencil_alpha_state(pipe, |
||
388 | depth_stencil_alpha); |
||
389 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
390 | } |
||
391 | |||
392 | static void * |
||
393 | rbug_create_fs_state(struct pipe_context *_pipe, |
||
394 | const struct pipe_shader_state *state) |
||
395 | { |
||
396 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
397 | struct pipe_context *pipe = rb_pipe->pipe; |
||
398 | void *result; |
||
399 | |||
400 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
401 | result = pipe->create_fs_state(pipe, state); |
||
402 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
403 | |||
404 | if (!result) |
||
405 | return NULL; |
||
406 | |||
407 | return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_FRAGMENT); |
||
408 | } |
||
409 | |||
410 | static void |
||
411 | rbug_bind_fs_state(struct pipe_context *_pipe, |
||
412 | void *_fs) |
||
413 | { |
||
414 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
415 | struct pipe_context *pipe = rb_pipe->pipe; |
||
416 | void *fs; |
||
417 | |||
418 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
419 | |||
420 | fs = rbug_shader_unwrap(_fs); |
||
421 | rb_pipe->curr.shader[PIPE_SHADER_FRAGMENT] = rbug_shader(_fs); |
||
422 | pipe->bind_fs_state(pipe, |
||
423 | fs); |
||
424 | |||
425 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
426 | } |
||
427 | |||
428 | static void |
||
429 | rbug_delete_fs_state(struct pipe_context *_pipe, |
||
430 | void *_fs) |
||
431 | { |
||
432 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
433 | struct rbug_shader *rb_shader = rbug_shader(_fs); |
||
434 | |||
435 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
436 | rbug_shader_destroy(rb_pipe, rb_shader); |
||
437 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
438 | } |
||
439 | |||
440 | static void * |
||
441 | rbug_create_vs_state(struct pipe_context *_pipe, |
||
442 | const struct pipe_shader_state *state) |
||
443 | { |
||
444 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
445 | struct pipe_context *pipe = rb_pipe->pipe; |
||
446 | void *result; |
||
447 | |||
448 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
449 | result = pipe->create_vs_state(pipe, state); |
||
450 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
451 | |||
452 | if (!result) |
||
453 | return NULL; |
||
454 | |||
455 | return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_VERTEX); |
||
456 | } |
||
457 | |||
458 | static void |
||
459 | rbug_bind_vs_state(struct pipe_context *_pipe, |
||
460 | void *_vs) |
||
461 | { |
||
462 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
463 | struct pipe_context *pipe = rb_pipe->pipe; |
||
464 | void *vs; |
||
465 | |||
466 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
467 | |||
468 | vs = rbug_shader_unwrap(_vs); |
||
469 | rb_pipe->curr.shader[PIPE_SHADER_VERTEX] = rbug_shader(_vs); |
||
470 | pipe->bind_vs_state(pipe, |
||
471 | vs); |
||
472 | |||
473 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
474 | } |
||
475 | |||
476 | static void |
||
477 | rbug_delete_vs_state(struct pipe_context *_pipe, |
||
478 | void *_vs) |
||
479 | { |
||
480 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
481 | struct rbug_shader *rb_shader = rbug_shader(_vs); |
||
482 | |||
483 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
484 | rbug_shader_destroy(rb_pipe, rb_shader); |
||
485 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
486 | } |
||
487 | |||
488 | static void * |
||
489 | rbug_create_gs_state(struct pipe_context *_pipe, |
||
490 | const struct pipe_shader_state *state) |
||
491 | { |
||
492 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
493 | struct pipe_context *pipe = rb_pipe->pipe; |
||
494 | void *result; |
||
495 | |||
496 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
497 | result = pipe->create_gs_state(pipe, state); |
||
498 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
499 | |||
500 | if (!result) |
||
501 | return NULL; |
||
502 | |||
503 | return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_GEOM); |
||
504 | } |
||
505 | |||
506 | static void |
||
507 | rbug_bind_gs_state(struct pipe_context *_pipe, |
||
508 | void *_gs) |
||
509 | { |
||
510 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
511 | struct pipe_context *pipe = rb_pipe->pipe; |
||
512 | void *gs; |
||
513 | |||
514 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
515 | |||
516 | gs = rbug_shader_unwrap(_gs); |
||
517 | rb_pipe->curr.shader[PIPE_SHADER_GEOMETRY] = rbug_shader(_gs); |
||
518 | pipe->bind_gs_state(pipe, |
||
519 | gs); |
||
520 | |||
521 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
522 | } |
||
523 | |||
524 | static void |
||
525 | rbug_delete_gs_state(struct pipe_context *_pipe, |
||
526 | void *_gs) |
||
527 | { |
||
528 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
529 | struct rbug_shader *rb_shader = rbug_shader(_gs); |
||
530 | |||
531 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
532 | rbug_shader_destroy(rb_pipe, rb_shader); |
||
533 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
534 | } |
||
535 | |||
536 | static void * |
||
537 | rbug_create_vertex_elements_state(struct pipe_context *_pipe, |
||
538 | unsigned num_elements, |
||
539 | const struct pipe_vertex_element *vertex_elements) |
||
540 | { |
||
541 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
542 | struct pipe_context *pipe = rb_pipe->pipe; |
||
543 | void *ret; |
||
544 | |||
545 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
546 | ret = pipe->create_vertex_elements_state(pipe, |
||
547 | num_elements, |
||
548 | vertex_elements); |
||
549 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
550 | |||
551 | return ret; |
||
552 | } |
||
553 | |||
554 | static void |
||
555 | rbug_bind_vertex_elements_state(struct pipe_context *_pipe, |
||
556 | void *velems) |
||
557 | { |
||
558 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
559 | struct pipe_context *pipe = rb_pipe->pipe; |
||
560 | |||
561 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
562 | pipe->bind_vertex_elements_state(pipe, |
||
563 | velems); |
||
564 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
565 | } |
||
566 | |||
567 | static void |
||
568 | rbug_delete_vertex_elements_state(struct pipe_context *_pipe, |
||
569 | void *velems) |
||
570 | { |
||
571 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
572 | struct pipe_context *pipe = rb_pipe->pipe; |
||
573 | |||
574 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
575 | pipe->delete_vertex_elements_state(pipe, |
||
576 | velems); |
||
577 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
578 | } |
||
579 | |||
580 | static void |
||
581 | rbug_set_blend_color(struct pipe_context *_pipe, |
||
582 | const struct pipe_blend_color *blend_color) |
||
583 | { |
||
584 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
585 | struct pipe_context *pipe = rb_pipe->pipe; |
||
586 | |||
587 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
588 | pipe->set_blend_color(pipe, |
||
589 | blend_color); |
||
590 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
591 | } |
||
592 | |||
593 | static void |
||
594 | rbug_set_stencil_ref(struct pipe_context *_pipe, |
||
595 | const struct pipe_stencil_ref *stencil_ref) |
||
596 | { |
||
597 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
598 | struct pipe_context *pipe = rb_pipe->pipe; |
||
599 | |||
600 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
601 | pipe->set_stencil_ref(pipe, |
||
602 | stencil_ref); |
||
603 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
604 | } |
||
605 | |||
606 | static void |
||
607 | rbug_set_clip_state(struct pipe_context *_pipe, |
||
608 | const struct pipe_clip_state *clip) |
||
609 | { |
||
610 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
611 | struct pipe_context *pipe = rb_pipe->pipe; |
||
612 | |||
613 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
614 | pipe->set_clip_state(pipe, |
||
615 | clip); |
||
616 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
617 | } |
||
618 | |||
619 | static void |
||
620 | rbug_set_constant_buffer(struct pipe_context *_pipe, |
||
621 | uint shader, |
||
622 | uint index, |
||
623 | struct pipe_constant_buffer *_cb) |
||
624 | { |
||
625 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
626 | struct pipe_context *pipe = rb_pipe->pipe; |
||
627 | struct pipe_constant_buffer cb; |
||
628 | |||
629 | /* XXX hmm? unwrap the input state */ |
||
630 | if (_cb) { |
||
631 | cb = *_cb; |
||
632 | cb.buffer = rbug_resource_unwrap(_cb->buffer); |
||
633 | } |
||
634 | |||
635 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
636 | pipe->set_constant_buffer(pipe, |
||
637 | shader, |
||
638 | index, |
||
639 | _cb ? &cb : NULL); |
||
640 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
641 | } |
||
642 | |||
643 | static void |
||
644 | rbug_set_framebuffer_state(struct pipe_context *_pipe, |
||
645 | const struct pipe_framebuffer_state *_state) |
||
646 | { |
||
647 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
648 | struct pipe_context *pipe = rb_pipe->pipe; |
||
649 | struct pipe_framebuffer_state unwrapped_state; |
||
650 | struct pipe_framebuffer_state *state = NULL; |
||
651 | unsigned i; |
||
652 | |||
653 | /* must protect curr status */ |
||
654 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
655 | |||
656 | rb_pipe->curr.nr_cbufs = 0; |
||
657 | memset(rb_pipe->curr.cbufs, 0, sizeof(rb_pipe->curr.cbufs)); |
||
658 | rb_pipe->curr.zsbuf = NULL; |
||
659 | |||
660 | /* unwrap the input state */ |
||
661 | if (_state) { |
||
662 | memcpy(&unwrapped_state, _state, sizeof(unwrapped_state)); |
||
663 | |||
664 | rb_pipe->curr.nr_cbufs = _state->nr_cbufs; |
||
665 | for(i = 0; i < _state->nr_cbufs; i++) { |
||
666 | unwrapped_state.cbufs[i] = rbug_surface_unwrap(_state->cbufs[i]); |
||
667 | if (_state->cbufs[i]) |
||
668 | rb_pipe->curr.cbufs[i] = rbug_resource(_state->cbufs[i]->texture); |
||
669 | } |
||
670 | unwrapped_state.zsbuf = rbug_surface_unwrap(_state->zsbuf); |
||
671 | if (_state->zsbuf) |
||
672 | rb_pipe->curr.zsbuf = rbug_resource(_state->zsbuf->texture); |
||
673 | state = &unwrapped_state; |
||
674 | } |
||
675 | |||
676 | pipe->set_framebuffer_state(pipe, |
||
677 | state); |
||
678 | |||
679 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
680 | } |
||
681 | |||
682 | static void |
||
683 | rbug_set_polygon_stipple(struct pipe_context *_pipe, |
||
684 | const struct pipe_poly_stipple *poly_stipple) |
||
685 | { |
||
686 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
687 | struct pipe_context *pipe = rb_pipe->pipe; |
||
688 | |||
689 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
690 | pipe->set_polygon_stipple(pipe, |
||
691 | poly_stipple); |
||
692 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
693 | } |
||
694 | |||
695 | static void |
||
696 | rbug_set_scissor_states(struct pipe_context *_pipe, |
||
697 | unsigned start_slot, |
||
698 | unsigned num_scissors, |
||
699 | const struct pipe_scissor_state *scissor) |
||
700 | { |
||
701 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
702 | struct pipe_context *pipe = rb_pipe->pipe; |
||
703 | |||
704 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
705 | pipe->set_scissor_states(pipe, start_slot, num_scissors, scissor); |
||
706 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
707 | } |
||
708 | |||
709 | static void |
||
710 | rbug_set_viewport_states(struct pipe_context *_pipe, |
||
711 | unsigned start_slot, |
||
712 | unsigned num_viewports, |
||
713 | const struct pipe_viewport_state *viewport) |
||
714 | { |
||
715 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
716 | struct pipe_context *pipe = rb_pipe->pipe; |
||
717 | |||
718 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
719 | pipe->set_viewport_states(pipe, start_slot, num_viewports, viewport); |
||
720 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
721 | } |
||
722 | |||
723 | static void |
||
724 | rbug_set_sampler_views(struct pipe_context *_pipe, |
||
725 | unsigned shader, |
||
726 | unsigned start, |
||
727 | unsigned num, |
||
728 | struct pipe_sampler_view **_views) |
||
729 | { |
||
730 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
731 | struct pipe_context *pipe = rb_pipe->pipe; |
||
732 | struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS]; |
||
733 | struct pipe_sampler_view **views = NULL; |
||
734 | unsigned i; |
||
735 | |||
736 | assert(start == 0); /* XXX fix */ |
||
737 | |||
738 | /* must protect curr status */ |
||
739 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
740 | |||
741 | rb_pipe->curr.num_views[shader] = 0; |
||
742 | memset(rb_pipe->curr.views[shader], 0, sizeof(rb_pipe->curr.views[shader])); |
||
743 | memset(rb_pipe->curr.texs[shader], 0, sizeof(rb_pipe->curr.texs[shader])); |
||
744 | memset(unwrapped_views, 0, sizeof(unwrapped_views)); |
||
745 | |||
746 | if (_views) { |
||
747 | rb_pipe->curr.num_views[shader] = num; |
||
748 | for (i = 0; i < num; i++) { |
||
749 | rb_pipe->curr.views[shader][i] = rbug_sampler_view(_views[i]); |
||
750 | rb_pipe->curr.texs[shader][i] = rbug_resource(_views[i] ? _views[i]->texture : NULL); |
||
751 | unwrapped_views[i] = rbug_sampler_view_unwrap(_views[i]); |
||
752 | } |
||
753 | views = unwrapped_views; |
||
754 | } |
||
755 | |||
756 | switch (shader) { |
||
757 | case PIPE_SHADER_VERTEX: |
||
758 | pipe->set_vertex_sampler_views(pipe, num, views); |
||
759 | break; |
||
760 | case PIPE_SHADER_FRAGMENT: |
||
761 | pipe->set_fragment_sampler_views(pipe, num, views); |
||
762 | break; |
||
763 | default: |
||
764 | assert(0); |
||
765 | } |
||
766 | |||
767 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
768 | } |
||
769 | |||
770 | static void |
||
771 | rbug_set_vertex_sampler_views(struct pipe_context *_pipe, |
||
772 | unsigned num, |
||
773 | struct pipe_sampler_view **_views) |
||
774 | { |
||
775 | rbug_set_sampler_views(_pipe, PIPE_SHADER_VERTEX, 0, num, _views); |
||
776 | } |
||
777 | |||
778 | static void |
||
779 | rbug_set_fragment_sampler_views(struct pipe_context *_pipe, |
||
780 | unsigned num, |
||
781 | struct pipe_sampler_view **_views) |
||
782 | { |
||
783 | rbug_set_sampler_views(_pipe, PIPE_SHADER_FRAGMENT, 0, num, _views); |
||
784 | } |
||
785 | |||
786 | static void |
||
787 | rbug_set_vertex_buffers(struct pipe_context *_pipe, |
||
788 | unsigned start_slot, unsigned num_buffers, |
||
789 | const struct pipe_vertex_buffer *_buffers) |
||
790 | { |
||
791 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
792 | struct pipe_context *pipe = rb_pipe->pipe; |
||
793 | struct pipe_vertex_buffer unwrapped_buffers[PIPE_MAX_SHADER_INPUTS]; |
||
794 | struct pipe_vertex_buffer *buffers = NULL; |
||
795 | unsigned i; |
||
796 | |||
797 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
798 | |||
799 | if (num_buffers) { |
||
800 | memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers)); |
||
801 | for (i = 0; i < num_buffers; i++) |
||
802 | unwrapped_buffers[i].buffer = rbug_resource_unwrap(_buffers[i].buffer); |
||
803 | buffers = unwrapped_buffers; |
||
804 | } |
||
805 | |||
806 | pipe->set_vertex_buffers(pipe, start_slot, |
||
807 | num_buffers, |
||
808 | buffers); |
||
809 | |||
810 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
811 | } |
||
812 | |||
813 | static void |
||
814 | rbug_set_index_buffer(struct pipe_context *_pipe, |
||
815 | const struct pipe_index_buffer *_ib) |
||
816 | { |
||
817 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
818 | struct pipe_context *pipe = rb_pipe->pipe; |
||
819 | struct pipe_index_buffer unwrapped_ib, *ib = NULL; |
||
820 | |||
821 | if (_ib) { |
||
822 | unwrapped_ib = *_ib; |
||
823 | unwrapped_ib.buffer = rbug_resource_unwrap(_ib->buffer); |
||
824 | ib = &unwrapped_ib; |
||
825 | } |
||
826 | |||
827 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
828 | pipe->set_index_buffer(pipe, ib); |
||
829 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
830 | } |
||
831 | |||
832 | static void |
||
833 | rbug_set_sample_mask(struct pipe_context *_pipe, |
||
834 | unsigned sample_mask) |
||
835 | { |
||
836 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
837 | struct pipe_context *pipe = rb_pipe->pipe; |
||
838 | |||
839 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
840 | pipe->set_sample_mask(pipe, sample_mask); |
||
841 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
842 | } |
||
843 | |||
844 | static void |
||
845 | rbug_resource_copy_region(struct pipe_context *_pipe, |
||
846 | struct pipe_resource *_dst, |
||
847 | unsigned dst_level, |
||
848 | unsigned dstx, |
||
849 | unsigned dsty, |
||
850 | unsigned dstz, |
||
851 | struct pipe_resource *_src, |
||
852 | unsigned src_level, |
||
853 | const struct pipe_box *src_box) |
||
854 | { |
||
855 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
856 | struct rbug_resource *rb_resource_dst = rbug_resource(_dst); |
||
857 | struct rbug_resource *rb_resource_src = rbug_resource(_src); |
||
858 | struct pipe_context *pipe = rb_pipe->pipe; |
||
859 | struct pipe_resource *dst = rb_resource_dst->resource; |
||
860 | struct pipe_resource *src = rb_resource_src->resource; |
||
861 | |||
862 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
863 | pipe->resource_copy_region(pipe, |
||
864 | dst, |
||
865 | dst_level, |
||
866 | dstx, |
||
867 | dsty, |
||
868 | dstz, |
||
869 | src, |
||
870 | src_level, |
||
871 | src_box); |
||
872 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
873 | } |
||
874 | |||
875 | static void |
||
876 | rbug_clear(struct pipe_context *_pipe, |
||
877 | unsigned buffers, |
||
878 | const union pipe_color_union *color, |
||
879 | double depth, |
||
880 | unsigned stencil) |
||
881 | { |
||
882 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
883 | struct pipe_context *pipe = rb_pipe->pipe; |
||
884 | |||
885 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
886 | pipe->clear(pipe, |
||
887 | buffers, |
||
888 | color, |
||
889 | depth, |
||
890 | stencil); |
||
891 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
892 | } |
||
893 | |||
894 | static void |
||
895 | rbug_clear_render_target(struct pipe_context *_pipe, |
||
896 | struct pipe_surface *_dst, |
||
897 | const union pipe_color_union *color, |
||
898 | unsigned dstx, unsigned dsty, |
||
899 | unsigned width, unsigned height) |
||
900 | { |
||
901 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
902 | struct rbug_surface *rb_surface_dst = rbug_surface(_dst); |
||
903 | struct pipe_context *pipe = rb_pipe->pipe; |
||
904 | struct pipe_surface *dst = rb_surface_dst->surface; |
||
905 | |||
906 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
907 | pipe->clear_render_target(pipe, |
||
908 | dst, |
||
909 | color, |
||
910 | dstx, |
||
911 | dsty, |
||
912 | width, |
||
913 | height); |
||
914 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
915 | } |
||
916 | |||
917 | static void |
||
918 | rbug_clear_depth_stencil(struct pipe_context *_pipe, |
||
919 | struct pipe_surface *_dst, |
||
920 | unsigned clear_flags, |
||
921 | double depth, |
||
922 | unsigned stencil, |
||
923 | unsigned dstx, unsigned dsty, |
||
924 | unsigned width, unsigned height) |
||
925 | { |
||
926 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
927 | struct rbug_surface *rb_surface_dst = rbug_surface(_dst); |
||
928 | struct pipe_context *pipe = rb_pipe->pipe; |
||
929 | struct pipe_surface *dst = rb_surface_dst->surface; |
||
930 | |||
931 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
932 | pipe->clear_depth_stencil(pipe, |
||
933 | dst, |
||
934 | clear_flags, |
||
935 | depth, |
||
936 | stencil, |
||
937 | dstx, |
||
938 | dsty, |
||
939 | width, |
||
940 | height); |
||
941 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
942 | } |
||
943 | |||
944 | static void |
||
945 | rbug_flush(struct pipe_context *_pipe, |
||
946 | struct pipe_fence_handle **fence, |
||
947 | unsigned flags) |
||
948 | { |
||
949 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
950 | struct pipe_context *pipe = rb_pipe->pipe; |
||
951 | |||
952 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
953 | pipe->flush(pipe, fence, flags); |
||
954 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
955 | } |
||
956 | |||
957 | static struct pipe_sampler_view * |
||
958 | rbug_context_create_sampler_view(struct pipe_context *_pipe, |
||
959 | struct pipe_resource *_resource, |
||
960 | const struct pipe_sampler_view *templ) |
||
961 | { |
||
962 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
963 | struct rbug_resource *rb_resource = rbug_resource(_resource); |
||
964 | struct pipe_context *pipe = rb_pipe->pipe; |
||
965 | struct pipe_resource *resource = rb_resource->resource; |
||
966 | struct pipe_sampler_view *result; |
||
967 | |||
968 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
969 | result = pipe->create_sampler_view(pipe, |
||
970 | resource, |
||
971 | templ); |
||
972 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
973 | |||
974 | if (result) |
||
975 | return rbug_sampler_view_create(rb_pipe, rb_resource, result); |
||
976 | return NULL; |
||
977 | } |
||
978 | |||
979 | static void |
||
980 | rbug_context_sampler_view_destroy(struct pipe_context *_pipe, |
||
981 | struct pipe_sampler_view *_view) |
||
982 | { |
||
983 | rbug_sampler_view_destroy(rbug_context(_pipe), |
||
984 | rbug_sampler_view(_view)); |
||
985 | } |
||
986 | |||
987 | static struct pipe_surface * |
||
988 | rbug_context_create_surface(struct pipe_context *_pipe, |
||
989 | struct pipe_resource *_resource, |
||
990 | const struct pipe_surface *surf_tmpl) |
||
991 | { |
||
992 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
993 | struct rbug_resource *rb_resource = rbug_resource(_resource); |
||
994 | struct pipe_context *pipe = rb_pipe->pipe; |
||
995 | struct pipe_resource *resource = rb_resource->resource; |
||
996 | struct pipe_surface *result; |
||
997 | |||
998 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
999 | result = pipe->create_surface(pipe, |
||
1000 | resource, |
||
1001 | surf_tmpl); |
||
1002 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
1003 | |||
1004 | if (result) |
||
1005 | return rbug_surface_create(rb_pipe, rb_resource, result); |
||
1006 | return NULL; |
||
1007 | } |
||
1008 | |||
1009 | static void |
||
1010 | rbug_context_surface_destroy(struct pipe_context *_pipe, |
||
1011 | struct pipe_surface *_surface) |
||
1012 | { |
||
1013 | struct rbug_context *rb_pipe = rbug_context(_pipe); |
||
1014 | struct rbug_surface *rb_surface = rbug_surface(_surface); |
||
1015 | |||
1016 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
1017 | rbug_surface_destroy(rb_pipe, |
||
1018 | rb_surface); |
||
1019 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
1020 | } |
||
1021 | |||
1022 | |||
1023 | |||
1024 | static void * |
||
1025 | rbug_context_transfer_map(struct pipe_context *_context, |
||
1026 | struct pipe_resource *_resource, |
||
1027 | unsigned level, |
||
1028 | unsigned usage, |
||
1029 | const struct pipe_box *box, |
||
1030 | struct pipe_transfer **transfer) |
||
1031 | { |
||
1032 | struct rbug_context *rb_pipe = rbug_context(_context); |
||
1033 | struct rbug_resource *rb_resource = rbug_resource(_resource); |
||
1034 | struct pipe_context *context = rb_pipe->pipe; |
||
1035 | struct pipe_resource *resource = rb_resource->resource; |
||
1036 | struct pipe_transfer *result; |
||
1037 | void *map; |
||
1038 | |||
1039 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
1040 | map = context->transfer_map(context, |
||
1041 | resource, |
||
1042 | level, |
||
1043 | usage, |
||
1044 | box, &result); |
||
1045 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
1046 | |||
1047 | *transfer = rbug_transfer_create(rb_pipe, rb_resource, result); |
||
1048 | return *transfer ? map : NULL; |
||
1049 | } |
||
1050 | |||
1051 | static void |
||
1052 | rbug_context_transfer_flush_region(struct pipe_context *_context, |
||
1053 | struct pipe_transfer *_transfer, |
||
1054 | const struct pipe_box *box) |
||
1055 | { |
||
1056 | struct rbug_context *rb_pipe = rbug_context(_context); |
||
1057 | struct rbug_transfer *rb_transfer = rbug_transfer(_transfer); |
||
1058 | struct pipe_context *context = rb_pipe->pipe; |
||
1059 | struct pipe_transfer *transfer = rb_transfer->transfer; |
||
1060 | |||
1061 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
1062 | context->transfer_flush_region(context, |
||
1063 | transfer, |
||
1064 | box); |
||
1065 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
1066 | } |
||
1067 | |||
1068 | |||
1069 | static void |
||
1070 | rbug_context_transfer_unmap(struct pipe_context *_context, |
||
1071 | struct pipe_transfer *_transfer) |
||
1072 | { |
||
1073 | struct rbug_context *rb_pipe = rbug_context(_context); |
||
1074 | struct rbug_transfer *rb_transfer = rbug_transfer(_transfer); |
||
1075 | struct pipe_context *context = rb_pipe->pipe; |
||
1076 | struct pipe_transfer *transfer = rb_transfer->transfer; |
||
1077 | |||
1078 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
1079 | context->transfer_unmap(context, |
||
1080 | transfer); |
||
1081 | rbug_transfer_destroy(rb_pipe, |
||
1082 | rb_transfer); |
||
1083 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
1084 | } |
||
1085 | |||
1086 | |||
1087 | static void |
||
1088 | rbug_context_transfer_inline_write(struct pipe_context *_context, |
||
1089 | struct pipe_resource *_resource, |
||
1090 | unsigned level, |
||
1091 | unsigned usage, |
||
1092 | const struct pipe_box *box, |
||
1093 | const void *data, |
||
1094 | unsigned stride, |
||
1095 | unsigned layer_stride) |
||
1096 | { |
||
1097 | struct rbug_context *rb_pipe = rbug_context(_context); |
||
1098 | struct rbug_resource *rb_resource = rbug_resource(_resource); |
||
1099 | struct pipe_context *context = rb_pipe->pipe; |
||
1100 | struct pipe_resource *resource = rb_resource->resource; |
||
1101 | |||
1102 | pipe_mutex_lock(rb_pipe->call_mutex); |
||
1103 | context->transfer_inline_write(context, |
||
1104 | resource, |
||
1105 | level, |
||
1106 | usage, |
||
1107 | box, |
||
1108 | data, |
||
1109 | stride, |
||
1110 | layer_stride); |
||
1111 | pipe_mutex_unlock(rb_pipe->call_mutex); |
||
1112 | } |
||
1113 | |||
1114 | |||
1115 | struct pipe_context * |
||
1116 | rbug_context_create(struct pipe_screen *_screen, struct pipe_context *pipe) |
||
1117 | { |
||
1118 | struct rbug_context *rb_pipe; |
||
1119 | struct rbug_screen *rb_screen = rbug_screen(_screen); |
||
1120 | |||
1121 | if (!rb_screen) |
||
1122 | return NULL; |
||
1123 | |||
1124 | rb_pipe = CALLOC_STRUCT(rbug_context); |
||
1125 | if (!rb_pipe) |
||
1126 | return NULL; |
||
1127 | |||
1128 | pipe_mutex_init(rb_pipe->draw_mutex); |
||
1129 | pipe_condvar_init(rb_pipe->draw_cond); |
||
1130 | pipe_mutex_init(rb_pipe->call_mutex); |
||
1131 | pipe_mutex_init(rb_pipe->list_mutex); |
||
1132 | make_empty_list(&rb_pipe->shaders); |
||
1133 | |||
1134 | rb_pipe->base.screen = _screen; |
||
1135 | rb_pipe->base.priv = pipe->priv; /* expose wrapped data */ |
||
1136 | rb_pipe->base.draw = NULL; |
||
1137 | |||
1138 | rb_pipe->base.destroy = rbug_destroy; |
||
1139 | rb_pipe->base.draw_vbo = rbug_draw_vbo; |
||
1140 | rb_pipe->base.create_query = rbug_create_query; |
||
1141 | rb_pipe->base.destroy_query = rbug_destroy_query; |
||
1142 | rb_pipe->base.begin_query = rbug_begin_query; |
||
1143 | rb_pipe->base.end_query = rbug_end_query; |
||
1144 | rb_pipe->base.get_query_result = rbug_get_query_result; |
||
1145 | rb_pipe->base.create_blend_state = rbug_create_blend_state; |
||
1146 | rb_pipe->base.bind_blend_state = rbug_bind_blend_state; |
||
1147 | rb_pipe->base.delete_blend_state = rbug_delete_blend_state; |
||
1148 | rb_pipe->base.create_sampler_state = rbug_create_sampler_state; |
||
1149 | rb_pipe->base.bind_fragment_sampler_states = rbug_bind_fragment_sampler_states; |
||
1150 | rb_pipe->base.bind_vertex_sampler_states = rbug_bind_vertex_sampler_states; |
||
1151 | rb_pipe->base.delete_sampler_state = rbug_delete_sampler_state; |
||
1152 | rb_pipe->base.create_rasterizer_state = rbug_create_rasterizer_state; |
||
1153 | rb_pipe->base.bind_rasterizer_state = rbug_bind_rasterizer_state; |
||
1154 | rb_pipe->base.delete_rasterizer_state = rbug_delete_rasterizer_state; |
||
1155 | rb_pipe->base.create_depth_stencil_alpha_state = rbug_create_depth_stencil_alpha_state; |
||
1156 | rb_pipe->base.bind_depth_stencil_alpha_state = rbug_bind_depth_stencil_alpha_state; |
||
1157 | rb_pipe->base.delete_depth_stencil_alpha_state = rbug_delete_depth_stencil_alpha_state; |
||
1158 | rb_pipe->base.create_fs_state = rbug_create_fs_state; |
||
1159 | rb_pipe->base.bind_fs_state = rbug_bind_fs_state; |
||
1160 | rb_pipe->base.delete_fs_state = rbug_delete_fs_state; |
||
1161 | rb_pipe->base.create_vs_state = rbug_create_vs_state; |
||
1162 | rb_pipe->base.bind_vs_state = rbug_bind_vs_state; |
||
1163 | rb_pipe->base.delete_vs_state = rbug_delete_vs_state; |
||
1164 | rb_pipe->base.create_gs_state = rbug_create_gs_state; |
||
1165 | rb_pipe->base.bind_gs_state = rbug_bind_gs_state; |
||
1166 | rb_pipe->base.delete_gs_state = rbug_delete_gs_state; |
||
1167 | rb_pipe->base.create_vertex_elements_state = rbug_create_vertex_elements_state; |
||
1168 | rb_pipe->base.bind_vertex_elements_state = rbug_bind_vertex_elements_state; |
||
1169 | rb_pipe->base.delete_vertex_elements_state = rbug_delete_vertex_elements_state; |
||
1170 | rb_pipe->base.set_blend_color = rbug_set_blend_color; |
||
1171 | rb_pipe->base.set_stencil_ref = rbug_set_stencil_ref; |
||
1172 | rb_pipe->base.set_clip_state = rbug_set_clip_state; |
||
1173 | rb_pipe->base.set_constant_buffer = rbug_set_constant_buffer; |
||
1174 | rb_pipe->base.set_framebuffer_state = rbug_set_framebuffer_state; |
||
1175 | rb_pipe->base.set_polygon_stipple = rbug_set_polygon_stipple; |
||
1176 | rb_pipe->base.set_scissor_states = rbug_set_scissor_states; |
||
1177 | rb_pipe->base.set_viewport_states = rbug_set_viewport_states; |
||
1178 | rb_pipe->base.set_fragment_sampler_views = rbug_set_fragment_sampler_views; |
||
1179 | rb_pipe->base.set_vertex_sampler_views = rbug_set_vertex_sampler_views; |
||
1180 | rb_pipe->base.set_vertex_buffers = rbug_set_vertex_buffers; |
||
1181 | rb_pipe->base.set_index_buffer = rbug_set_index_buffer; |
||
1182 | rb_pipe->base.set_sample_mask = rbug_set_sample_mask; |
||
1183 | rb_pipe->base.resource_copy_region = rbug_resource_copy_region; |
||
1184 | rb_pipe->base.clear = rbug_clear; |
||
1185 | rb_pipe->base.clear_render_target = rbug_clear_render_target; |
||
1186 | rb_pipe->base.clear_depth_stencil = rbug_clear_depth_stencil; |
||
1187 | rb_pipe->base.flush = rbug_flush; |
||
1188 | rb_pipe->base.create_sampler_view = rbug_context_create_sampler_view; |
||
1189 | rb_pipe->base.sampler_view_destroy = rbug_context_sampler_view_destroy; |
||
1190 | rb_pipe->base.create_surface = rbug_context_create_surface; |
||
1191 | rb_pipe->base.surface_destroy = rbug_context_surface_destroy; |
||
1192 | rb_pipe->base.transfer_map = rbug_context_transfer_map; |
||
1193 | rb_pipe->base.transfer_unmap = rbug_context_transfer_unmap; |
||
1194 | rb_pipe->base.transfer_flush_region = rbug_context_transfer_flush_region; |
||
1195 | rb_pipe->base.transfer_inline_write = rbug_context_transfer_inline_write; |
||
1196 | |||
1197 | rb_pipe->pipe = pipe; |
||
1198 | |||
1199 | rbug_screen_add_to_list(rb_screen, contexts, rb_pipe); |
||
1200 | |||
1201 | if (debug_get_bool_option("GALLIUM_RBUG_START_BLOCKED", FALSE)) { |
||
1202 | rb_pipe->draw_blocked = RBUG_BLOCK_BEFORE; |
||
1203 | } |
||
1204 | |||
1205 | return &rb_pipe->base; |
||
1206 | }>>>>>>> |