1 /**************************************************************************
3 * Copyright 2015 Advanced Micro Devices, Inc.
4 * Copyright 2008 VMware, Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * on the rights to use, copy, modify, merge, publish, distribute, sub
11 * license, and/or sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 #include "tgsi/tgsi_parse.h"
30 #include "util/u_inlines.h"
31 #include "util/u_memory.h"
35 safe_memcpy(void *dst
, const void *src
, size_t size
)
38 memcpy(dst
, src
, size
);
44 /********************************************************************
48 static struct dd_query
*
49 dd_query(struct pipe_query
*query
)
51 return (struct dd_query
*)query
;
54 static struct pipe_query
*
55 dd_query_unwrap(struct pipe_query
*query
)
58 return dd_query(query
)->query
;
64 static struct pipe_query
*
65 dd_context_create_query(struct pipe_context
*_pipe
, unsigned query_type
,
68 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
69 struct pipe_query
*query
;
71 query
= pipe
->create_query(pipe
, query_type
, index
);
73 /* Wrap query object. */
75 struct dd_query
*dd_query
= CALLOC_STRUCT(dd_query
);
77 dd_query
->type
= query_type
;
78 dd_query
->query
= query
;
79 query
= (struct pipe_query
*)dd_query
;
81 pipe
->destroy_query(pipe
, query
);
89 static struct pipe_query
*
90 dd_context_create_batch_query(struct pipe_context
*_pipe
, unsigned num_queries
,
91 unsigned *query_types
)
93 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
94 struct pipe_query
*query
;
96 query
= pipe
->create_batch_query(pipe
, num_queries
, query_types
);
98 /* Wrap query object. */
100 struct dd_query
*dd_query
= CALLOC_STRUCT(dd_query
);
102 /* no special handling for batch queries yet */
103 dd_query
->type
= query_types
[0];
104 dd_query
->query
= query
;
105 query
= (struct pipe_query
*)dd_query
;
107 pipe
->destroy_query(pipe
, query
);
116 dd_context_destroy_query(struct pipe_context
*_pipe
,
117 struct pipe_query
*query
)
119 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
121 pipe
->destroy_query(pipe
, dd_query_unwrap(query
));
126 dd_context_begin_query(struct pipe_context
*_pipe
, struct pipe_query
*query
)
128 struct dd_context
*dctx
= dd_context(_pipe
);
129 struct pipe_context
*pipe
= dctx
->pipe
;
131 return pipe
->begin_query(pipe
, dd_query_unwrap(query
));
135 dd_context_end_query(struct pipe_context
*_pipe
, struct pipe_query
*query
)
137 struct dd_context
*dctx
= dd_context(_pipe
);
138 struct pipe_context
*pipe
= dctx
->pipe
;
140 return pipe
->end_query(pipe
, dd_query_unwrap(query
));
144 dd_context_get_query_result(struct pipe_context
*_pipe
,
145 struct pipe_query
*query
, boolean wait
,
146 union pipe_query_result
*result
)
148 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
150 return pipe
->get_query_result(pipe
, dd_query_unwrap(query
), wait
, result
);
154 dd_context_set_active_query_state(struct pipe_context
*_pipe
, boolean enable
)
156 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
158 pipe
->set_active_query_state(pipe
, enable
);
162 dd_context_render_condition(struct pipe_context
*_pipe
,
163 struct pipe_query
*query
, boolean condition
,
166 struct dd_context
*dctx
= dd_context(_pipe
);
167 struct pipe_context
*pipe
= dctx
->pipe
;
168 struct dd_draw_state
*dstate
= &dctx
->draw_state
;
170 pipe
->render_condition(pipe
, dd_query_unwrap(query
), condition
, mode
);
171 dstate
->render_cond
.query
= dd_query(query
);
172 dstate
->render_cond
.condition
= condition
;
173 dstate
->render_cond
.mode
= mode
;
177 /********************************************************************
178 * constant (immutable) non-shader states
181 #define DD_CSO_CREATE(name, shortname) \
183 dd_context_create_##name##_state(struct pipe_context *_pipe, \
184 const struct pipe_##name##_state *state) \
186 struct pipe_context *pipe = dd_context(_pipe)->pipe; \
187 struct dd_state *hstate = CALLOC_STRUCT(dd_state); \
191 hstate->cso = pipe->create_##name##_state(pipe, state); \
192 hstate->state.shortname = *state; \
196 #define DD_CSO_BIND(name, shortname) \
198 dd_context_bind_##name##_state(struct pipe_context *_pipe, void *state) \
200 struct dd_context *dctx = dd_context(_pipe); \
201 struct pipe_context *pipe = dctx->pipe; \
202 struct dd_state *hstate = state; \
204 dctx->draw_state.shortname = hstate; \
205 pipe->bind_##name##_state(pipe, hstate ? hstate->cso : NULL); \
208 #define DD_CSO_DELETE(name) \
210 dd_context_delete_##name##_state(struct pipe_context *_pipe, void *state) \
212 struct dd_context *dctx = dd_context(_pipe); \
213 struct pipe_context *pipe = dctx->pipe; \
214 struct dd_state *hstate = state; \
216 pipe->delete_##name##_state(pipe, hstate->cso); \
220 #define DD_CSO_WHOLE(name, shortname) \
221 DD_CSO_CREATE(name, shortname) \
222 DD_CSO_BIND(name, shortname) \
225 DD_CSO_WHOLE(blend
, blend
)
226 DD_CSO_WHOLE(rasterizer
, rs
)
227 DD_CSO_WHOLE(depth_stencil_alpha
, dsa
)
229 DD_CSO_CREATE(sampler
, sampler
)
230 DD_CSO_DELETE(sampler
)
233 dd_context_bind_sampler_states(struct pipe_context
*_pipe
,
234 enum pipe_shader_type shader
,
235 unsigned start
, unsigned count
, void **states
)
237 struct dd_context
*dctx
= dd_context(_pipe
);
238 struct pipe_context
*pipe
= dctx
->pipe
;
240 memcpy(&dctx
->draw_state
.sampler_states
[shader
][start
], states
,
241 sizeof(void*) * count
);
244 void *samp
[PIPE_MAX_SAMPLERS
];
247 for (i
= 0; i
< count
; i
++) {
248 struct dd_state
*s
= states
[i
];
249 samp
[i
] = s
? s
->cso
: NULL
;
252 pipe
->bind_sampler_states(pipe
, shader
, start
, count
, samp
);
255 pipe
->bind_sampler_states(pipe
, shader
, start
, count
, NULL
);
259 dd_context_create_vertex_elements_state(struct pipe_context
*_pipe
,
261 const struct pipe_vertex_element
*elems
)
263 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
264 struct dd_state
*hstate
= CALLOC_STRUCT(dd_state
);
268 hstate
->cso
= pipe
->create_vertex_elements_state(pipe
, num_elems
, elems
);
269 memcpy(hstate
->state
.velems
.velems
, elems
, sizeof(elems
[0]) * num_elems
);
270 hstate
->state
.velems
.count
= num_elems
;
274 DD_CSO_BIND(vertex_elements
, velems
)
275 DD_CSO_DELETE(vertex_elements
)
278 /********************************************************************
282 #define DD_SHADER_NOCREATE(NAME, name) \
284 dd_context_bind_##name##_state(struct pipe_context *_pipe, void *state) \
286 struct dd_context *dctx = dd_context(_pipe); \
287 struct pipe_context *pipe = dctx->pipe; \
288 struct dd_state *hstate = state; \
290 dctx->draw_state.shaders[PIPE_SHADER_##NAME] = hstate; \
291 pipe->bind_##name##_state(pipe, hstate ? hstate->cso : NULL); \
295 dd_context_delete_##name##_state(struct pipe_context *_pipe, void *state) \
297 struct dd_context *dctx = dd_context(_pipe); \
298 struct pipe_context *pipe = dctx->pipe; \
299 struct dd_state *hstate = state; \
301 pipe->delete_##name##_state(pipe, hstate->cso); \
302 tgsi_free_tokens(hstate->state.shader.tokens); \
306 #define DD_SHADER(NAME, name) \
308 dd_context_create_##name##_state(struct pipe_context *_pipe, \
309 const struct pipe_shader_state *state) \
311 struct pipe_context *pipe = dd_context(_pipe)->pipe; \
312 struct dd_state *hstate = CALLOC_STRUCT(dd_state); \
316 hstate->cso = pipe->create_##name##_state(pipe, state); \
317 hstate->state.shader = *state; \
318 hstate->state.shader.tokens = tgsi_dup_tokens(state->tokens); \
322 DD_SHADER_NOCREATE(NAME, name)
324 DD_SHADER(FRAGMENT
, fs
)
325 DD_SHADER(VERTEX
, vs
)
326 DD_SHADER(GEOMETRY
, gs
)
327 DD_SHADER(TESS_CTRL
, tcs
)
328 DD_SHADER(TESS_EVAL
, tes
)
331 dd_context_create_compute_state(struct pipe_context
*_pipe
,
332 const struct pipe_compute_state
*state
)
334 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
335 struct dd_state
*hstate
= CALLOC_STRUCT(dd_state
);
339 hstate
->cso
= pipe
->create_compute_state(pipe
, state
);
341 if (state
->ir_type
== PIPE_SHADER_IR_TGSI
)
342 hstate
->state
.shader
.tokens
= tgsi_dup_tokens(state
->prog
);
347 DD_SHADER_NOCREATE(COMPUTE
, compute
)
349 /********************************************************************
353 #define DD_IMM_STATE(name, type, deref, ref) \
355 dd_context_set_##name(struct pipe_context *_pipe, type deref) \
357 struct dd_context *dctx = dd_context(_pipe); \
358 struct pipe_context *pipe = dctx->pipe; \
360 dctx->draw_state.name = deref; \
361 pipe->set_##name(pipe, ref); \
364 DD_IMM_STATE(blend_color
, const struct pipe_blend_color
, *state
, state
)
365 DD_IMM_STATE(stencil_ref
, const struct pipe_stencil_ref
, *state
, state
)
366 DD_IMM_STATE(clip_state
, const struct pipe_clip_state
, *state
, state
)
367 DD_IMM_STATE(sample_mask
, unsigned, sample_mask
, sample_mask
)
368 DD_IMM_STATE(min_samples
, unsigned, min_samples
, min_samples
)
369 DD_IMM_STATE(framebuffer_state
, const struct pipe_framebuffer_state
, *state
, state
)
370 DD_IMM_STATE(polygon_stipple
, const struct pipe_poly_stipple
, *state
, state
)
373 dd_context_set_constant_buffer(struct pipe_context
*_pipe
,
374 uint shader
, uint index
,
375 const struct pipe_constant_buffer
*constant_buffer
)
377 struct dd_context
*dctx
= dd_context(_pipe
);
378 struct pipe_context
*pipe
= dctx
->pipe
;
380 safe_memcpy(&dctx
->draw_state
.constant_buffers
[shader
][index
],
381 constant_buffer
, sizeof(*constant_buffer
));
382 pipe
->set_constant_buffer(pipe
, shader
, index
, constant_buffer
);
386 dd_context_set_scissor_states(struct pipe_context
*_pipe
,
387 unsigned start_slot
, unsigned num_scissors
,
388 const struct pipe_scissor_state
*states
)
390 struct dd_context
*dctx
= dd_context(_pipe
);
391 struct pipe_context
*pipe
= dctx
->pipe
;
393 safe_memcpy(&dctx
->draw_state
.scissors
[start_slot
], states
,
394 sizeof(*states
) * num_scissors
);
395 pipe
->set_scissor_states(pipe
, start_slot
, num_scissors
, states
);
399 dd_context_set_viewport_states(struct pipe_context
*_pipe
,
400 unsigned start_slot
, unsigned num_viewports
,
401 const struct pipe_viewport_state
*states
)
403 struct dd_context
*dctx
= dd_context(_pipe
);
404 struct pipe_context
*pipe
= dctx
->pipe
;
406 safe_memcpy(&dctx
->draw_state
.viewports
[start_slot
], states
,
407 sizeof(*states
) * num_viewports
);
408 pipe
->set_viewport_states(pipe
, start_slot
, num_viewports
, states
);
411 static void dd_context_set_tess_state(struct pipe_context
*_pipe
,
412 const float default_outer_level
[4],
413 const float default_inner_level
[2])
415 struct dd_context
*dctx
= dd_context(_pipe
);
416 struct pipe_context
*pipe
= dctx
->pipe
;
418 memcpy(dctx
->draw_state
.tess_default_levels
, default_outer_level
,
420 memcpy(dctx
->draw_state
.tess_default_levels
+4, default_inner_level
,
422 pipe
->set_tess_state(pipe
, default_outer_level
, default_inner_level
);
426 /********************************************************************
430 static struct pipe_surface
*
431 dd_context_create_surface(struct pipe_context
*_pipe
,
432 struct pipe_resource
*resource
,
433 const struct pipe_surface
*surf_tmpl
)
435 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
436 struct pipe_surface
*view
=
437 pipe
->create_surface(pipe
, resource
, surf_tmpl
);
441 view
->context
= _pipe
;
446 dd_context_surface_destroy(struct pipe_context
*_pipe
,
447 struct pipe_surface
*surf
)
449 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
451 pipe
->surface_destroy(pipe
, surf
);
454 static struct pipe_sampler_view
*
455 dd_context_create_sampler_view(struct pipe_context
*_pipe
,
456 struct pipe_resource
*resource
,
457 const struct pipe_sampler_view
*templ
)
459 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
460 struct pipe_sampler_view
*view
=
461 pipe
->create_sampler_view(pipe
, resource
, templ
);
465 view
->context
= _pipe
;
470 dd_context_sampler_view_destroy(struct pipe_context
*_pipe
,
471 struct pipe_sampler_view
*view
)
473 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
475 pipe
->sampler_view_destroy(pipe
, view
);
478 static struct pipe_stream_output_target
*
479 dd_context_create_stream_output_target(struct pipe_context
*_pipe
,
480 struct pipe_resource
*res
,
481 unsigned buffer_offset
,
482 unsigned buffer_size
)
484 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
485 struct pipe_stream_output_target
*view
=
486 pipe
->create_stream_output_target(pipe
, res
, buffer_offset
,
491 view
->context
= _pipe
;
496 dd_context_stream_output_target_destroy(struct pipe_context
*_pipe
,
497 struct pipe_stream_output_target
*target
)
499 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
501 pipe
->stream_output_target_destroy(pipe
, target
);
505 /********************************************************************
510 dd_context_set_sampler_views(struct pipe_context
*_pipe
,
511 enum pipe_shader_type shader
,
512 unsigned start
, unsigned num
,
513 struct pipe_sampler_view
**views
)
515 struct dd_context
*dctx
= dd_context(_pipe
);
516 struct pipe_context
*pipe
= dctx
->pipe
;
518 safe_memcpy(&dctx
->draw_state
.sampler_views
[shader
][start
], views
,
519 sizeof(views
[0]) * num
);
520 pipe
->set_sampler_views(pipe
, shader
, start
, num
, views
);
524 dd_context_set_shader_images(struct pipe_context
*_pipe
,
525 enum pipe_shader_type shader
,
526 unsigned start
, unsigned num
,
527 const struct pipe_image_view
*views
)
529 struct dd_context
*dctx
= dd_context(_pipe
);
530 struct pipe_context
*pipe
= dctx
->pipe
;
532 safe_memcpy(&dctx
->draw_state
.shader_images
[shader
][start
], views
,
533 sizeof(views
[0]) * num
);
534 pipe
->set_shader_images(pipe
, shader
, start
, num
, views
);
538 dd_context_set_shader_buffers(struct pipe_context
*_pipe
, unsigned shader
,
539 unsigned start
, unsigned num_buffers
,
540 const struct pipe_shader_buffer
*buffers
)
542 struct dd_context
*dctx
= dd_context(_pipe
);
543 struct pipe_context
*pipe
= dctx
->pipe
;
545 safe_memcpy(&dctx
->draw_state
.shader_buffers
[shader
][start
], buffers
,
546 sizeof(buffers
[0]) * num_buffers
);
547 pipe
->set_shader_buffers(pipe
, shader
, start
, num_buffers
, buffers
);
551 dd_context_set_vertex_buffers(struct pipe_context
*_pipe
,
552 unsigned start
, unsigned num_buffers
,
553 const struct pipe_vertex_buffer
*buffers
)
555 struct dd_context
*dctx
= dd_context(_pipe
);
556 struct pipe_context
*pipe
= dctx
->pipe
;
558 safe_memcpy(&dctx
->draw_state
.vertex_buffers
[start
], buffers
,
559 sizeof(buffers
[0]) * num_buffers
);
560 pipe
->set_vertex_buffers(pipe
, start
, num_buffers
, buffers
);
564 dd_context_set_index_buffer(struct pipe_context
*_pipe
,
565 const struct pipe_index_buffer
*ib
)
567 struct dd_context
*dctx
= dd_context(_pipe
);
568 struct pipe_context
*pipe
= dctx
->pipe
;
570 safe_memcpy(&dctx
->draw_state
.index_buffer
, ib
, sizeof(*ib
));
571 pipe
->set_index_buffer(pipe
, ib
);
575 dd_context_set_stream_output_targets(struct pipe_context
*_pipe
,
576 unsigned num_targets
,
577 struct pipe_stream_output_target
**tgs
,
578 const unsigned *offsets
)
580 struct dd_context
*dctx
= dd_context(_pipe
);
581 struct pipe_context
*pipe
= dctx
->pipe
;
582 struct dd_draw_state
*dstate
= &dctx
->draw_state
;
584 dstate
->num_so_targets
= num_targets
;
585 safe_memcpy(dstate
->so_targets
, tgs
, sizeof(*tgs
) * num_targets
);
586 safe_memcpy(dstate
->so_offsets
, offsets
, sizeof(*offsets
) * num_targets
);
587 pipe
->set_stream_output_targets(pipe
, num_targets
, tgs
, offsets
);
591 dd_context_destroy(struct pipe_context
*_pipe
)
593 struct dd_context
*dctx
= dd_context(_pipe
);
594 struct pipe_context
*pipe
= dctx
->pipe
;
597 pipe_mutex_lock(dctx
->mutex
);
598 dctx
->kill_thread
= 1;
599 pipe_mutex_unlock(dctx
->mutex
);
600 pipe_thread_wait(dctx
->thread
);
601 pipe_mutex_destroy(dctx
->mutex
);
602 assert(!dctx
->records
);
606 pipe
->transfer_unmap(pipe
, dctx
->fence_transfer
);
607 pipe_resource_reference(&dctx
->fence
, NULL
);
614 /********************************************************************
619 dd_context_transfer_map(struct pipe_context
*_pipe
,
620 struct pipe_resource
*resource
, unsigned level
,
621 unsigned usage
, const struct pipe_box
*box
,
622 struct pipe_transfer
**transfer
)
624 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
626 return pipe
->transfer_map(pipe
, resource
, level
, usage
, box
, transfer
);
630 dd_context_transfer_flush_region(struct pipe_context
*_pipe
,
631 struct pipe_transfer
*transfer
,
632 const struct pipe_box
*box
)
634 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
636 pipe
->transfer_flush_region(pipe
, transfer
, box
);
640 dd_context_transfer_unmap(struct pipe_context
*_pipe
,
641 struct pipe_transfer
*transfer
)
643 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
645 pipe
->transfer_unmap(pipe
, transfer
);
649 dd_context_buffer_subdata(struct pipe_context
*_pipe
,
650 struct pipe_resource
*resource
,
651 unsigned usage
, unsigned offset
,
652 unsigned size
, const void *data
)
654 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
656 pipe
->buffer_subdata(pipe
, resource
, usage
, offset
, size
, data
);
660 dd_context_texture_subdata(struct pipe_context
*_pipe
,
661 struct pipe_resource
*resource
,
662 unsigned level
, unsigned usage
,
663 const struct pipe_box
*box
,
664 const void *data
, unsigned stride
,
665 unsigned layer_stride
)
667 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
669 pipe
->texture_subdata(pipe
, resource
, level
, usage
, box
, data
,
670 stride
, layer_stride
);
674 /********************************************************************
679 dd_context_texture_barrier(struct pipe_context
*_pipe
, unsigned flags
)
681 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
683 pipe
->texture_barrier(pipe
, flags
);
687 dd_context_memory_barrier(struct pipe_context
*_pipe
, unsigned flags
)
689 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
691 pipe
->memory_barrier(pipe
, flags
);
695 dd_context_get_sample_position(struct pipe_context
*_pipe
,
696 unsigned sample_count
, unsigned sample_index
,
699 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
701 return pipe
->get_sample_position(pipe
, sample_count
, sample_index
,
706 dd_context_invalidate_resource(struct pipe_context
*_pipe
,
707 struct pipe_resource
*resource
)
709 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
711 pipe
->invalidate_resource(pipe
, resource
);
714 static enum pipe_reset_status
715 dd_context_get_device_reset_status(struct pipe_context
*_pipe
)
717 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
719 return pipe
->get_device_reset_status(pipe
);
723 dd_context_set_device_reset_callback(struct pipe_context
*_pipe
,
724 const struct pipe_device_reset_callback
*cb
)
726 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
728 return pipe
->set_device_reset_callback(pipe
, cb
);
732 dd_context_emit_string_marker(struct pipe_context
*_pipe
,
733 const char *string
, int len
)
735 struct dd_context
*dctx
= dd_context(_pipe
);
736 struct pipe_context
*pipe
= dctx
->pipe
;
738 pipe
->emit_string_marker(pipe
, string
, len
);
739 dd_parse_apitrace_marker(string
, len
, &dctx
->draw_state
.apitrace_call_number
);
743 dd_context_dump_debug_state(struct pipe_context
*_pipe
, FILE *stream
,
746 struct pipe_context
*pipe
= dd_context(_pipe
)->pipe
;
748 return pipe
->dump_debug_state(pipe
, stream
, flags
);
751 struct pipe_context
*
752 dd_context_create(struct dd_screen
*dscreen
, struct pipe_context
*pipe
)
754 struct dd_context
*dctx
;
759 dctx
= CALLOC_STRUCT(dd_context
);
764 dctx
->base
.priv
= pipe
->priv
; /* expose wrapped priv data */
765 dctx
->base
.screen
= &dscreen
->base
;
766 dctx
->base
.stream_uploader
= pipe
->stream_uploader
;
767 dctx
->base
.const_uploader
= pipe
->const_uploader
;
769 dctx
->base
.destroy
= dd_context_destroy
;
771 CTX_INIT(render_condition
);
772 CTX_INIT(create_query
);
773 CTX_INIT(create_batch_query
);
774 CTX_INIT(destroy_query
);
775 CTX_INIT(begin_query
);
777 CTX_INIT(get_query_result
);
778 CTX_INIT(set_active_query_state
);
779 CTX_INIT(create_blend_state
);
780 CTX_INIT(bind_blend_state
);
781 CTX_INIT(delete_blend_state
);
782 CTX_INIT(create_sampler_state
);
783 CTX_INIT(bind_sampler_states
);
784 CTX_INIT(delete_sampler_state
);
785 CTX_INIT(create_rasterizer_state
);
786 CTX_INIT(bind_rasterizer_state
);
787 CTX_INIT(delete_rasterizer_state
);
788 CTX_INIT(create_depth_stencil_alpha_state
);
789 CTX_INIT(bind_depth_stencil_alpha_state
);
790 CTX_INIT(delete_depth_stencil_alpha_state
);
791 CTX_INIT(create_fs_state
);
792 CTX_INIT(bind_fs_state
);
793 CTX_INIT(delete_fs_state
);
794 CTX_INIT(create_vs_state
);
795 CTX_INIT(bind_vs_state
);
796 CTX_INIT(delete_vs_state
);
797 CTX_INIT(create_gs_state
);
798 CTX_INIT(bind_gs_state
);
799 CTX_INIT(delete_gs_state
);
800 CTX_INIT(create_tcs_state
);
801 CTX_INIT(bind_tcs_state
);
802 CTX_INIT(delete_tcs_state
);
803 CTX_INIT(create_tes_state
);
804 CTX_INIT(bind_tes_state
);
805 CTX_INIT(delete_tes_state
);
806 CTX_INIT(create_compute_state
);
807 CTX_INIT(bind_compute_state
);
808 CTX_INIT(delete_compute_state
);
809 CTX_INIT(create_vertex_elements_state
);
810 CTX_INIT(bind_vertex_elements_state
);
811 CTX_INIT(delete_vertex_elements_state
);
812 CTX_INIT(set_blend_color
);
813 CTX_INIT(set_stencil_ref
);
814 CTX_INIT(set_sample_mask
);
815 CTX_INIT(set_min_samples
);
816 CTX_INIT(set_clip_state
);
817 CTX_INIT(set_constant_buffer
);
818 CTX_INIT(set_framebuffer_state
);
819 CTX_INIT(set_polygon_stipple
);
820 CTX_INIT(set_scissor_states
);
821 CTX_INIT(set_viewport_states
);
822 CTX_INIT(set_sampler_views
);
823 CTX_INIT(set_tess_state
);
824 CTX_INIT(set_shader_buffers
);
825 CTX_INIT(set_shader_images
);
826 CTX_INIT(set_vertex_buffers
);
827 CTX_INIT(set_index_buffer
);
828 CTX_INIT(create_stream_output_target
);
829 CTX_INIT(stream_output_target_destroy
);
830 CTX_INIT(set_stream_output_targets
);
831 CTX_INIT(create_sampler_view
);
832 CTX_INIT(sampler_view_destroy
);
833 CTX_INIT(create_surface
);
834 CTX_INIT(surface_destroy
);
835 CTX_INIT(transfer_map
);
836 CTX_INIT(transfer_flush_region
);
837 CTX_INIT(transfer_unmap
);
838 CTX_INIT(buffer_subdata
);
839 CTX_INIT(texture_subdata
);
840 CTX_INIT(texture_barrier
);
841 CTX_INIT(memory_barrier
);
842 /* create_video_codec */
843 /* create_video_buffer */
844 /* set_compute_resources */
845 /* set_global_binding */
846 CTX_INIT(get_sample_position
);
847 CTX_INIT(invalidate_resource
);
848 CTX_INIT(get_device_reset_status
);
849 CTX_INIT(set_device_reset_callback
);
850 CTX_INIT(dump_debug_state
);
851 CTX_INIT(emit_string_marker
);
853 dd_init_draw_functions(dctx
);
855 dctx
->draw_state
.sample_mask
= ~0;
857 if (dscreen
->mode
== DD_DETECT_HANGS_PIPELINED
) {
858 dctx
->fence
= pipe_buffer_create(dscreen
->screen
, PIPE_BIND_CUSTOM
,
859 PIPE_USAGE_STAGING
, 4);
863 dctx
->mapped_fence
= pipe_buffer_map(pipe
, dctx
->fence
,
864 PIPE_TRANSFER_READ_WRITE
|
865 PIPE_TRANSFER_PERSISTENT
|
866 PIPE_TRANSFER_COHERENT
,
867 &dctx
->fence_transfer
);
868 if (!dctx
->mapped_fence
)
871 *dctx
->mapped_fence
= 0;
873 (void) mtx_init(&dctx
->mutex
, mtx_plain
);
874 dctx
->thread
= pipe_thread_create(dd_thread_pipelined_hang_detect
, dctx
);
876 pipe_mutex_destroy(dctx
->mutex
);
885 if (dctx
->mapped_fence
)
886 pipe_transfer_unmap(pipe
, dctx
->fence_transfer
);
887 pipe_resource_reference(&dctx
->fence
, NULL
);