1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
29 #include "pipe/p_context.h"
31 #include "util/u_format.h"
32 #include "util/u_memory.h"
33 #include "util/u_inlines.h"
35 #include "glhd_context.h"
36 #include "glhd_objects.h"
40 galahad_context_destroy(struct pipe_context
*_pipe
)
42 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
43 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
51 galahad_context_draw_vbo(struct pipe_context
*_pipe
,
52 const struct pipe_draw_info
*info
)
54 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
55 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
57 /* XXX we should check that all bound resources are unmapped
61 pipe
->draw_vbo(pipe
, info
);
64 static struct pipe_query
*
65 galahad_context_create_query(struct pipe_context
*_pipe
,
68 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
69 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
71 if (query_type
== PIPE_QUERY_OCCLUSION_COUNTER
&&
72 !pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_OCCLUSION_QUERY
)) {
73 glhd_error("Occlusion query requested but not supported");
76 if (query_type
== PIPE_QUERY_TIME_ELAPSED
&&
77 !pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_QUERY_TIME_ELAPSED
)) {
78 glhd_error("Timer query requested but not supported");
81 return pipe
->create_query(pipe
,
86 galahad_context_destroy_query(struct pipe_context
*_pipe
,
87 struct pipe_query
*query
)
89 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
90 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
92 pipe
->destroy_query(pipe
,
97 galahad_context_begin_query(struct pipe_context
*_pipe
,
98 struct pipe_query
*query
)
100 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
101 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
103 pipe
->begin_query(pipe
,
108 galahad_context_end_query(struct pipe_context
*_pipe
,
109 struct pipe_query
*query
)
111 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
112 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
114 pipe
->end_query(pipe
,
119 galahad_context_get_query_result(struct pipe_context
*_pipe
,
120 struct pipe_query
*query
,
122 union pipe_query_result
*result
)
124 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
125 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
127 return pipe
->get_query_result(pipe
,
134 galahad_context_create_blend_state(struct pipe_context
*_pipe
,
135 const struct pipe_blend_state
*blend
)
137 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
138 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
140 if (blend
->logicop_enable
) {
141 if (blend
->rt
[0].blend_enable
) {
142 glhd_warn("Blending enabled for render target 0, but logicops "
147 return pipe
->create_blend_state(pipe
,
152 galahad_context_bind_blend_state(struct pipe_context
*_pipe
,
155 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
156 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
158 pipe
->bind_blend_state(pipe
,
163 galahad_context_delete_blend_state(struct pipe_context
*_pipe
,
166 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
167 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
169 pipe
->delete_blend_state(pipe
,
174 galahad_context_create_sampler_state(struct pipe_context
*_pipe
,
175 const struct pipe_sampler_state
*sampler
)
177 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
178 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
180 return pipe
->create_sampler_state(pipe
,
185 galahad_context_bind_sampler_states(struct pipe_context
*_pipe
,
188 unsigned num_samplers
,
191 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
192 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
194 if (num_samplers
> PIPE_MAX_SAMPLERS
) {
195 glhd_error("%u samplers requested, "
196 "but only %u are permitted by API",
197 num_samplers
, PIPE_MAX_SAMPLERS
);
200 pipe
->bind_sampler_states(pipe
, shader
, start
, num_samplers
, samplers
);
204 galahad_context_delete_sampler_state(struct pipe_context
*_pipe
,
207 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
208 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
210 pipe
->delete_sampler_state(pipe
,
215 galahad_context_create_rasterizer_state(struct pipe_context
*_pipe
,
216 const struct pipe_rasterizer_state
*rasterizer
)
218 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
219 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
221 if (rasterizer
->point_quad_rasterization
) {
222 if (rasterizer
->point_smooth
) {
223 glhd_warn("Point smoothing requested but ignored");
226 if (rasterizer
->sprite_coord_enable
) {
227 glhd_warn("Point sprites requested but ignored");
231 return pipe
->create_rasterizer_state(pipe
,
236 galahad_context_bind_rasterizer_state(struct pipe_context
*_pipe
,
239 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
240 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
242 pipe
->bind_rasterizer_state(pipe
,
247 galahad_context_delete_rasterizer_state(struct pipe_context
*_pipe
,
250 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
251 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
253 pipe
->delete_rasterizer_state(pipe
,
258 galahad_context_create_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
259 const struct pipe_depth_stencil_alpha_state
*depth_stencil_alpha
)
261 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
262 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
264 return pipe
->create_depth_stencil_alpha_state(pipe
,
265 depth_stencil_alpha
);
269 galahad_context_bind_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
270 void *depth_stencil_alpha
)
272 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
273 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
275 pipe
->bind_depth_stencil_alpha_state(pipe
,
276 depth_stencil_alpha
);
280 galahad_context_delete_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
281 void *depth_stencil_alpha
)
283 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
284 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
286 pipe
->delete_depth_stencil_alpha_state(pipe
,
287 depth_stencil_alpha
);
290 #define GLHD_SHADER_STATE(shader_type) \
292 galahad_context_create_##shader_type##_state(struct pipe_context *_pipe, \
293 const struct pipe_shader_state *state) \
295 struct galahad_context *glhd_pipe = galahad_context(_pipe); \
296 struct pipe_context *pipe = glhd_pipe->pipe; \
297 return pipe->create_##shader_type##_state(pipe, state); \
301 galahad_context_bind_##shader_type##_state(struct pipe_context *_pipe, \
304 struct galahad_context *glhd_pipe = galahad_context(_pipe); \
305 struct pipe_context *pipe = glhd_pipe->pipe; \
306 pipe->bind_##shader_type##_state(pipe, state); \
310 galahad_context_delete_##shader_type##_state(struct pipe_context *_pipe, \
313 struct galahad_context *glhd_pipe = galahad_context(_pipe); \
314 struct pipe_context *pipe = glhd_pipe->pipe; \
315 pipe->delete_##shader_type##_state(pipe, state); \
318 GLHD_SHADER_STATE(fs
)
319 GLHD_SHADER_STATE(vs
)
320 GLHD_SHADER_STATE(gs
)
322 #undef GLHD_SHADER_STATE
325 galahad_context_create_vertex_elements_state(struct pipe_context
*_pipe
,
326 unsigned num_elements
,
327 const struct pipe_vertex_element
*vertex_elements
)
329 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
330 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
332 /* XXX check if stride lines up with element size, at least for floats */
334 return pipe
->create_vertex_elements_state(pipe
,
340 galahad_context_bind_vertex_elements_state(struct pipe_context
*_pipe
,
343 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
344 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
346 pipe
->bind_vertex_elements_state(pipe
,
351 galahad_context_delete_vertex_elements_state(struct pipe_context
*_pipe
,
354 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
355 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
357 pipe
->delete_vertex_elements_state(pipe
,
362 galahad_context_set_blend_color(struct pipe_context
*_pipe
,
363 const struct pipe_blend_color
*blend_color
)
365 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
366 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
368 pipe
->set_blend_color(pipe
,
373 galahad_context_set_stencil_ref(struct pipe_context
*_pipe
,
374 const struct pipe_stencil_ref
*stencil_ref
)
376 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
377 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
379 pipe
->set_stencil_ref(pipe
,
384 galahad_context_set_clip_state(struct pipe_context
*_pipe
,
385 const struct pipe_clip_state
*clip
)
387 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
388 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
390 pipe
->set_clip_state(pipe
,
395 galahad_context_set_sample_mask(struct pipe_context
*_pipe
,
396 unsigned sample_mask
)
398 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
399 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
401 pipe
->set_sample_mask(pipe
,
406 galahad_context_set_constant_buffer(struct pipe_context
*_pipe
,
409 struct pipe_constant_buffer
*_cb
)
411 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
412 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
413 struct pipe_constant_buffer cb
;
415 if (shader
>= PIPE_SHADER_TYPES
) {
416 glhd_error("Unknown shader type %u", shader
);
421 pipe
->screen
->get_shader_param(pipe
->screen
, shader
, PIPE_SHADER_CAP_MAX_CONST_BUFFERS
)) {
422 glhd_error("Access to constant buffer %u requested, "
423 "but only %d are supported",
425 pipe
->screen
->get_shader_param(pipe
->screen
, shader
, PIPE_SHADER_CAP_MAX_CONST_BUFFERS
));
428 /* XXX hmm? unwrap the input state */
431 cb
.buffer
= galahad_resource_unwrap(_cb
->buffer
);
434 pipe
->set_constant_buffer(pipe
,
441 galahad_context_set_framebuffer_state(struct pipe_context
*_pipe
,
442 const struct pipe_framebuffer_state
*_state
)
444 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
445 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
446 struct pipe_framebuffer_state unwrapped_state
;
447 struct pipe_framebuffer_state
*state
= NULL
;
450 if (_state
->nr_cbufs
> PIPE_MAX_COLOR_BUFS
) {
451 glhd_error("%d render targets bound, but only %d are permitted by API",
452 _state
->nr_cbufs
, PIPE_MAX_COLOR_BUFS
);
453 } else if (_state
->nr_cbufs
>
454 pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_MAX_RENDER_TARGETS
)) {
455 glhd_warn("%d render targets bound, but only %d are supported",
457 pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_MAX_RENDER_TARGETS
));
460 /* unwrap the input state */
462 memcpy(&unwrapped_state
, _state
, sizeof(unwrapped_state
));
463 for(i
= 0; i
< _state
->nr_cbufs
; i
++)
464 unwrapped_state
.cbufs
[i
] = galahad_surface_unwrap(_state
->cbufs
[i
]);
465 for (; i
< PIPE_MAX_COLOR_BUFS
; i
++)
466 unwrapped_state
.cbufs
[i
] = NULL
;
467 unwrapped_state
.zsbuf
= galahad_surface_unwrap(_state
->zsbuf
);
468 state
= &unwrapped_state
;
471 pipe
->set_framebuffer_state(pipe
,
476 galahad_context_set_polygon_stipple(struct pipe_context
*_pipe
,
477 const struct pipe_poly_stipple
*poly_stipple
)
479 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
480 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
482 pipe
->set_polygon_stipple(pipe
,
487 galahad_context_set_scissor_states(struct pipe_context
*_pipe
,
489 unsigned num_scissors
,
490 const struct pipe_scissor_state
*scissor
)
492 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
493 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
495 pipe
->set_scissor_states(pipe
, start_slot
, num_scissors
,
500 galahad_context_set_viewport_states(struct pipe_context
*_pipe
,
502 unsigned num_viewports
,
503 const struct pipe_viewport_state
*viewport
)
505 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
506 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
508 pipe
->set_viewport_states(pipe
, start_slot
, num_viewports
,
513 galahad_context_set_sampler_views(struct pipe_context
*_pipe
,
517 struct pipe_sampler_view
**_views
)
519 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
520 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
521 struct pipe_sampler_view
*unwrapped_views
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
524 for (i
= 0; i
< num
; i
++)
525 unwrapped_views
[i
] = galahad_sampler_view_unwrap(_views
[i
]);
527 pipe
->set_sampler_views(pipe
, shader
, start
, num
, unwrapped_views
);
531 galahad_context_set_vertex_buffers(struct pipe_context
*_pipe
,
532 unsigned start_slot
, unsigned num_buffers
,
533 const struct pipe_vertex_buffer
*_buffers
)
535 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
536 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
537 struct pipe_vertex_buffer unwrapped_buffers
[PIPE_MAX_SHADER_INPUTS
];
538 struct pipe_vertex_buffer
*buffers
= NULL
;
541 if (num_buffers
&& _buffers
) {
542 memcpy(unwrapped_buffers
, _buffers
, num_buffers
* sizeof(*_buffers
));
543 for (i
= 0; i
< num_buffers
; i
++)
544 unwrapped_buffers
[i
].buffer
= galahad_resource_unwrap(_buffers
[i
].buffer
);
545 buffers
= unwrapped_buffers
;
548 pipe
->set_vertex_buffers(pipe
,
549 start_slot
, num_buffers
,
554 galahad_context_set_index_buffer(struct pipe_context
*_pipe
,
555 const struct pipe_index_buffer
*_ib
)
557 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
558 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
559 struct pipe_index_buffer unwrapped_ib
, *ib
= NULL
;
562 if (_ib
->buffer
|| _ib
->user_buffer
) {
563 switch (_ib
->index_size
) {
569 glhd_warn("unrecognized index size %d", _ib
->index_size
);
573 else if (_ib
->offset
|| _ib
->index_size
) {
574 glhd_warn("non-indexed state with index offset %d and index size %d",
575 _ib
->offset
, _ib
->index_size
);
579 unwrapped_ib
.buffer
= galahad_resource_unwrap(_ib
->buffer
);
583 pipe
->set_index_buffer(pipe
, ib
);
586 static INLINE
struct pipe_stream_output_target
*
587 galahad_context_create_stream_output_target(struct pipe_context
*_pipe
,
588 struct pipe_resource
*_res
,
589 unsigned buffer_offset
,
590 unsigned buffer_size
)
592 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
593 struct galahad_resource
*glhd_resource_res
= galahad_resource(_res
);
594 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
595 struct pipe_resource
*res
= glhd_resource_res
->resource
;
597 return pipe
->create_stream_output_target(pipe
,
598 res
, buffer_offset
, buffer_size
);
602 galahad_context_stream_output_target_destroy(
603 struct pipe_context
*_pipe
,
604 struct pipe_stream_output_target
*target
)
606 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
607 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
609 pipe
->stream_output_target_destroy(pipe
, target
);
613 galahad_context_set_stream_output_targets(struct pipe_context
*_pipe
,
614 unsigned num_targets
,
615 struct pipe_stream_output_target
**tgs
,
616 const unsigned *offsets
)
618 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
619 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
621 pipe
->set_stream_output_targets(pipe
, num_targets
, tgs
, offsets
);
625 galahad_context_resource_copy_region(struct pipe_context
*_pipe
,
626 struct pipe_resource
*_dst
,
631 struct pipe_resource
*_src
,
633 const struct pipe_box
*src_box
)
635 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
636 struct galahad_resource
*glhd_resource_dst
= galahad_resource(_dst
);
637 struct galahad_resource
*glhd_resource_src
= galahad_resource(_src
);
638 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
639 struct pipe_resource
*dst
= glhd_resource_dst
->resource
;
640 struct pipe_resource
*src
= glhd_resource_src
->resource
;
642 if (_dst
->format
!= _src
->format
) {
643 const struct util_format_description
*src_desc
=
644 util_format_description(_src
->format
);
645 const struct util_format_description
*dst_desc
=
646 util_format_description(_dst
->format
);
647 if (!util_is_format_compatible(src_desc
, dst_desc
))
648 glhd_warn("Format mismatch: Source is %s, destination is %s",
649 src_desc
->short_name
,
650 dst_desc
->short_name
);
653 if ((_src
->target
== PIPE_BUFFER
&& _dst
->target
!= PIPE_BUFFER
) ||
654 (_src
->target
!= PIPE_BUFFER
&& _dst
->target
== PIPE_BUFFER
)) {
655 glhd_warn("Resource target mismatch: Source is %i, destination is %i",
656 _src
->target
, _dst
->target
);
659 pipe
->resource_copy_region(pipe
,
671 galahad_context_blit(struct pipe_context
*_pipe
,
672 const struct pipe_blit_info
*_info
)
674 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
675 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
676 struct pipe_blit_info info
= *_info
;
678 info
.dst
.resource
= galahad_resource_unwrap(info
.dst
.resource
);
679 info
.src
.resource
= galahad_resource_unwrap(info
.src
.resource
);
681 if (info
.dst
.box
.width
< 0 ||
682 info
.dst
.box
.height
< 0)
683 glhd_error("Destination dimensions are negative");
685 if (info
.filter
!= PIPE_TEX_FILTER_NEAREST
&&
686 info
.src
.resource
->target
!= PIPE_TEXTURE_3D
&&
687 info
.dst
.box
.depth
!= info
.src
.box
.depth
)
688 glhd_error("Filtering in z-direction on non-3D texture");
690 if (util_format_is_depth_or_stencil(info
.dst
.format
) !=
691 util_format_is_depth_or_stencil(info
.src
.format
))
692 glhd_error("Invalid format conversion: %s <- %s\n",
693 util_format_name(info
.dst
.format
),
694 util_format_name(info
.src
.format
));
696 pipe
->blit(pipe
, &info
);
700 galahad_context_flush_resource(struct pipe_context
*_pipe
,
701 struct pipe_resource
*_res
)
703 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
704 struct galahad_resource
*glhd_resource_res
= galahad_resource(_res
);
705 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
706 struct pipe_resource
*res
= glhd_resource_res
->resource
;
708 pipe
->flush_resource(pipe
, res
);
712 galahad_context_clear(struct pipe_context
*_pipe
,
714 const union pipe_color_union
*color
,
718 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
719 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
729 galahad_context_clear_render_target(struct pipe_context
*_pipe
,
730 struct pipe_surface
*_dst
,
731 const union pipe_color_union
*color
,
732 unsigned dstx
, unsigned dsty
,
733 unsigned width
, unsigned height
)
735 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
736 struct galahad_surface
*glhd_surface_dst
= galahad_surface(_dst
);
737 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
738 struct pipe_surface
*dst
= glhd_surface_dst
->surface
;
740 pipe
->clear_render_target(pipe
,
749 galahad_context_clear_depth_stencil(struct pipe_context
*_pipe
,
750 struct pipe_surface
*_dst
,
751 unsigned clear_flags
,
754 unsigned dstx
, unsigned dsty
,
755 unsigned width
, unsigned height
)
757 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
758 struct galahad_surface
*glhd_surface_dst
= galahad_surface(_dst
);
759 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
760 struct pipe_surface
*dst
= glhd_surface_dst
->surface
;
762 pipe
->clear_depth_stencil(pipe
,
775 galahad_context_flush(struct pipe_context
*_pipe
,
776 struct pipe_fence_handle
**fence
,
779 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
780 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
782 pipe
->flush(pipe
, fence
, flags
);
785 static struct pipe_sampler_view
*
786 galahad_context_create_sampler_view(struct pipe_context
*_pipe
,
787 struct pipe_resource
*_resource
,
788 const struct pipe_sampler_view
*templ
)
790 struct galahad_context
*glhd_context
= galahad_context(_pipe
);
791 struct galahad_resource
*glhd_resource
= galahad_resource(_resource
);
792 struct pipe_context
*pipe
= glhd_context
->pipe
;
793 struct pipe_resource
*resource
= glhd_resource
->resource
;
794 struct pipe_sampler_view
*result
;
796 result
= pipe
->create_sampler_view(pipe
,
801 return galahad_sampler_view_create(glhd_context
, glhd_resource
, result
);
806 galahad_context_sampler_view_destroy(struct pipe_context
*_pipe
,
807 struct pipe_sampler_view
*_view
)
809 galahad_sampler_view_destroy(galahad_context(_pipe
),
810 galahad_sampler_view(_view
));
813 static struct pipe_surface
*
814 galahad_context_create_surface(struct pipe_context
*_pipe
,
815 struct pipe_resource
*_resource
,
816 const struct pipe_surface
*templ
)
818 struct galahad_context
*glhd_context
= galahad_context(_pipe
);
819 struct galahad_resource
*glhd_resource
= galahad_resource(_resource
);
820 struct pipe_context
*pipe
= glhd_context
->pipe
;
821 struct pipe_resource
*resource
= glhd_resource
->resource
;
822 struct pipe_surface
*result
;
824 result
= pipe
->create_surface(pipe
,
829 return galahad_surface_create(glhd_context
, glhd_resource
, result
);
834 galahad_context_surface_destroy(struct pipe_context
*_pipe
,
835 struct pipe_surface
*_surface
)
837 galahad_surface_destroy(galahad_context(_pipe
),
838 galahad_surface(_surface
));
843 galahad_context_transfer_map(struct pipe_context
*_context
,
844 struct pipe_resource
*_resource
,
847 const struct pipe_box
*box
,
848 struct pipe_transfer
**transfer
)
850 struct galahad_context
*glhd_context
= galahad_context(_context
);
851 struct galahad_resource
*glhd_resource
= galahad_resource(_resource
);
852 struct pipe_context
*context
= glhd_context
->pipe
;
853 struct pipe_resource
*resource
= glhd_resource
->resource
;
854 struct pipe_transfer
*result
;
857 map
= context
->transfer_map(context
,
865 glhd_resource
->map_count
++;
867 *transfer
= galahad_transfer_create(glhd_context
, glhd_resource
, result
);
868 return *transfer
? map
: NULL
;
872 galahad_context_transfer_flush_region(struct pipe_context
*_context
,
873 struct pipe_transfer
*_transfer
,
874 const struct pipe_box
*box
)
876 struct galahad_context
*glhd_context
= galahad_context(_context
);
877 struct galahad_transfer
*glhd_transfer
= galahad_transfer(_transfer
);
878 struct pipe_context
*context
= glhd_context
->pipe
;
879 struct pipe_transfer
*transfer
= glhd_transfer
->transfer
;
881 context
->transfer_flush_region(context
,
887 galahad_context_transfer_unmap(struct pipe_context
*_context
,
888 struct pipe_transfer
*_transfer
)
890 struct galahad_context
*glhd_context
= galahad_context(_context
);
891 struct galahad_transfer
*glhd_transfer
= galahad_transfer(_transfer
);
892 struct pipe_context
*context
= glhd_context
->pipe
;
893 struct pipe_transfer
*transfer
= glhd_transfer
->transfer
;
894 struct galahad_resource
*glhd_resource
= galahad_resource(_transfer
->resource
);
896 if (glhd_resource
->map_count
< 1) {
897 glhd_warn("context::transfer_unmap() called too many times"
898 " (count = %d)\n", glhd_resource
->map_count
);
901 glhd_resource
->map_count
--;
903 context
->transfer_unmap(context
,
906 galahad_transfer_destroy(galahad_context(_context
),
907 galahad_transfer(_transfer
));
912 galahad_context_transfer_inline_write(struct pipe_context
*_context
,
913 struct pipe_resource
*_resource
,
916 const struct pipe_box
*box
,
919 unsigned slice_stride
)
921 struct galahad_context
*glhd_context
= galahad_context(_context
);
922 struct galahad_resource
*glhd_resource
= galahad_resource(_resource
);
923 struct pipe_context
*context
= glhd_context
->pipe
;
924 struct pipe_resource
*resource
= glhd_resource
->resource
;
926 context
->transfer_inline_write(context
,
938 galahad_context_render_condition(struct pipe_context
*_context
,
939 struct pipe_query
*query
,
943 struct galahad_context
*glhd_context
= galahad_context(_context
);
944 struct pipe_context
*context
= glhd_context
->pipe
;
946 context
->render_condition(context
, query
, condition
, mode
);
950 struct pipe_context
*
951 galahad_context_create(struct pipe_screen
*_screen
, struct pipe_context
*pipe
)
953 struct galahad_context
*glhd_pipe
;
954 (void)galahad_screen(_screen
);
956 glhd_pipe
= CALLOC_STRUCT(galahad_context
);
961 glhd_pipe
->base
.screen
= _screen
;
962 glhd_pipe
->base
.priv
= pipe
->priv
; /* expose wrapped data */
963 glhd_pipe
->base
.draw
= NULL
;
965 glhd_pipe
->base
.destroy
= galahad_context_destroy
;
967 #define GLHD_PIPE_INIT(_member) \
968 glhd_pipe->base . _member = pipe -> _member ? galahad_context_ ## _member : NULL
970 GLHD_PIPE_INIT(draw_vbo
);
971 GLHD_PIPE_INIT(render_condition
);
972 GLHD_PIPE_INIT(create_query
);
973 GLHD_PIPE_INIT(destroy_query
);
974 GLHD_PIPE_INIT(begin_query
);
975 GLHD_PIPE_INIT(end_query
);
976 GLHD_PIPE_INIT(get_query_result
);
977 GLHD_PIPE_INIT(create_blend_state
);
978 GLHD_PIPE_INIT(bind_blend_state
);
979 GLHD_PIPE_INIT(delete_blend_state
);
980 GLHD_PIPE_INIT(create_sampler_state
);
981 GLHD_PIPE_INIT(bind_sampler_states
);
982 GLHD_PIPE_INIT(delete_sampler_state
);
983 GLHD_PIPE_INIT(create_rasterizer_state
);
984 GLHD_PIPE_INIT(bind_rasterizer_state
);
985 GLHD_PIPE_INIT(delete_rasterizer_state
);
986 GLHD_PIPE_INIT(create_depth_stencil_alpha_state
);
987 GLHD_PIPE_INIT(bind_depth_stencil_alpha_state
);
988 GLHD_PIPE_INIT(delete_depth_stencil_alpha_state
);
989 GLHD_PIPE_INIT(create_fs_state
);
990 GLHD_PIPE_INIT(bind_fs_state
);
991 GLHD_PIPE_INIT(delete_fs_state
);
992 GLHD_PIPE_INIT(create_vs_state
);
993 GLHD_PIPE_INIT(bind_vs_state
);
994 GLHD_PIPE_INIT(delete_vs_state
);
995 GLHD_PIPE_INIT(create_gs_state
);
996 GLHD_PIPE_INIT(bind_gs_state
);
997 GLHD_PIPE_INIT(delete_gs_state
);
998 GLHD_PIPE_INIT(create_vertex_elements_state
);
999 GLHD_PIPE_INIT(bind_vertex_elements_state
);
1000 GLHD_PIPE_INIT(delete_vertex_elements_state
);
1001 GLHD_PIPE_INIT(set_blend_color
);
1002 GLHD_PIPE_INIT(set_stencil_ref
);
1003 GLHD_PIPE_INIT(set_sample_mask
);
1004 GLHD_PIPE_INIT(set_clip_state
);
1005 GLHD_PIPE_INIT(set_constant_buffer
);
1006 GLHD_PIPE_INIT(set_framebuffer_state
);
1007 GLHD_PIPE_INIT(set_polygon_stipple
);
1008 GLHD_PIPE_INIT(set_scissor_states
);
1009 GLHD_PIPE_INIT(set_viewport_states
);
1010 GLHD_PIPE_INIT(set_sampler_views
);
1011 //GLHD_PIPE_INIT(set_shader_resources);
1012 GLHD_PIPE_INIT(set_vertex_buffers
);
1013 GLHD_PIPE_INIT(set_index_buffer
);
1014 GLHD_PIPE_INIT(create_stream_output_target
);
1015 GLHD_PIPE_INIT(stream_output_target_destroy
);
1016 GLHD_PIPE_INIT(set_stream_output_targets
);
1017 GLHD_PIPE_INIT(resource_copy_region
);
1018 GLHD_PIPE_INIT(blit
);
1019 GLHD_PIPE_INIT(flush_resource
);
1020 GLHD_PIPE_INIT(clear
);
1021 GLHD_PIPE_INIT(clear_render_target
);
1022 GLHD_PIPE_INIT(clear_depth_stencil
);
1023 GLHD_PIPE_INIT(flush
);
1024 GLHD_PIPE_INIT(create_sampler_view
);
1025 GLHD_PIPE_INIT(sampler_view_destroy
);
1026 GLHD_PIPE_INIT(create_surface
);
1027 GLHD_PIPE_INIT(surface_destroy
);
1028 GLHD_PIPE_INIT(transfer_map
);
1029 GLHD_PIPE_INIT(transfer_flush_region
);
1030 GLHD_PIPE_INIT(transfer_unmap
);
1031 GLHD_PIPE_INIT(transfer_inline_write
);
1032 //GLHD_PIPE_INIT(texture_barrier);
1033 //GLHD_PIPE_INIT(create_video_decoder);
1034 //GLHD_PIPE_INIT(create_video_buffer);
1035 //GLHD_PIPE_INIT(create_compute_state);
1036 //GLHD_PIPE_INIT(bind_compute_state);
1037 //GLHD_PIPE_INIT(delete_compute_state);
1038 //GLHD_PIPE_INIT(set_compute_resources);
1039 //GLHD_PIPE_INIT(set_global_binding);
1040 //GLHD_PIPE_INIT(launch_grid);
1042 #undef GLHD_PIPE_INIT
1044 glhd_pipe
->pipe
= pipe
;
1046 return &glhd_pipe
->base
;