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 if (pipe
->bind_sampler_states
) {
201 pipe
->bind_sampler_states(pipe
, shader
, start
, num_samplers
, samplers
);
205 case PIPE_SHADER_VERTEX
:
206 pipe
->bind_vertex_sampler_states(pipe
, num_samplers
, samplers
);
208 case PIPE_SHADER_FRAGMENT
:
209 pipe
->bind_fragment_sampler_states(pipe
, num_samplers
, samplers
);
211 case PIPE_SHADER_GEOMETRY
:
212 pipe
->bind_geometry_sampler_states(pipe
, num_samplers
, samplers
);
221 galahad_context_bind_vertex_sampler_states(struct pipe_context
*_pipe
,
222 unsigned num_samplers
,
225 galahad_context_bind_sampler_states(_pipe
, PIPE_SHADER_VERTEX
,
226 0, num_samplers
, samplers
);
230 galahad_context_bind_fragment_sampler_states(struct pipe_context
*_pipe
,
231 unsigned num_samplers
,
234 galahad_context_bind_sampler_states(_pipe
, PIPE_SHADER_FRAGMENT
,
235 0, num_samplers
, samplers
);
239 galahad_context_bind_geometry_sampler_states(struct pipe_context
*_pipe
,
240 unsigned num_samplers
,
243 galahad_context_bind_sampler_states(_pipe
, PIPE_SHADER_GEOMETRY
,
244 0, num_samplers
, samplers
);
249 galahad_context_delete_sampler_state(struct pipe_context
*_pipe
,
252 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
253 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
255 pipe
->delete_sampler_state(pipe
,
260 galahad_context_create_rasterizer_state(struct pipe_context
*_pipe
,
261 const struct pipe_rasterizer_state
*rasterizer
)
263 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
264 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
266 if (rasterizer
->point_quad_rasterization
) {
267 if (rasterizer
->point_smooth
) {
268 glhd_warn("Point smoothing requested but ignored");
271 if (rasterizer
->sprite_coord_enable
) {
272 glhd_warn("Point sprites requested but ignored");
276 return pipe
->create_rasterizer_state(pipe
,
281 galahad_context_bind_rasterizer_state(struct pipe_context
*_pipe
,
284 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
285 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
287 pipe
->bind_rasterizer_state(pipe
,
292 galahad_context_delete_rasterizer_state(struct pipe_context
*_pipe
,
295 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
296 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
298 pipe
->delete_rasterizer_state(pipe
,
303 galahad_context_create_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
304 const struct pipe_depth_stencil_alpha_state
*depth_stencil_alpha
)
306 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
307 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
309 return pipe
->create_depth_stencil_alpha_state(pipe
,
310 depth_stencil_alpha
);
314 galahad_context_bind_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
315 void *depth_stencil_alpha
)
317 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
318 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
320 pipe
->bind_depth_stencil_alpha_state(pipe
,
321 depth_stencil_alpha
);
325 galahad_context_delete_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
326 void *depth_stencil_alpha
)
328 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
329 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
331 pipe
->delete_depth_stencil_alpha_state(pipe
,
332 depth_stencil_alpha
);
335 #define GLHD_SHADER_STATE(shader_type) \
337 galahad_context_create_##shader_type##_state(struct pipe_context *_pipe, \
338 const struct pipe_shader_state *state) \
340 struct galahad_context *glhd_pipe = galahad_context(_pipe); \
341 struct pipe_context *pipe = glhd_pipe->pipe; \
342 return pipe->create_##shader_type##_state(pipe, state); \
346 galahad_context_bind_##shader_type##_state(struct pipe_context *_pipe, \
349 struct galahad_context *glhd_pipe = galahad_context(_pipe); \
350 struct pipe_context *pipe = glhd_pipe->pipe; \
351 pipe->bind_##shader_type##_state(pipe, state); \
355 galahad_context_delete_##shader_type##_state(struct pipe_context *_pipe, \
358 struct galahad_context *glhd_pipe = galahad_context(_pipe); \
359 struct pipe_context *pipe = glhd_pipe->pipe; \
360 pipe->delete_##shader_type##_state(pipe, state); \
363 GLHD_SHADER_STATE(fs
)
364 GLHD_SHADER_STATE(vs
)
365 GLHD_SHADER_STATE(gs
)
367 #undef GLHD_SHADER_STATE
370 galahad_context_create_vertex_elements_state(struct pipe_context
*_pipe
,
371 unsigned num_elements
,
372 const struct pipe_vertex_element
*vertex_elements
)
374 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
375 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
377 /* XXX check if stride lines up with element size, at least for floats */
379 return pipe
->create_vertex_elements_state(pipe
,
385 galahad_context_bind_vertex_elements_state(struct pipe_context
*_pipe
,
388 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
389 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
391 pipe
->bind_vertex_elements_state(pipe
,
396 galahad_context_delete_vertex_elements_state(struct pipe_context
*_pipe
,
399 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
400 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
402 pipe
->delete_vertex_elements_state(pipe
,
407 galahad_context_set_blend_color(struct pipe_context
*_pipe
,
408 const struct pipe_blend_color
*blend_color
)
410 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
411 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
413 pipe
->set_blend_color(pipe
,
418 galahad_context_set_stencil_ref(struct pipe_context
*_pipe
,
419 const struct pipe_stencil_ref
*stencil_ref
)
421 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
422 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
424 pipe
->set_stencil_ref(pipe
,
429 galahad_context_set_clip_state(struct pipe_context
*_pipe
,
430 const struct pipe_clip_state
*clip
)
432 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
433 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
435 pipe
->set_clip_state(pipe
,
440 galahad_context_set_sample_mask(struct pipe_context
*_pipe
,
441 unsigned sample_mask
)
443 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
444 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
446 pipe
->set_sample_mask(pipe
,
451 galahad_context_set_constant_buffer(struct pipe_context
*_pipe
,
454 struct pipe_constant_buffer
*_cb
)
456 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
457 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
458 struct pipe_constant_buffer cb
;
460 if (shader
>= PIPE_SHADER_TYPES
) {
461 glhd_error("Unknown shader type %u", shader
);
466 pipe
->screen
->get_shader_param(pipe
->screen
, shader
, PIPE_SHADER_CAP_MAX_CONST_BUFFERS
)) {
467 glhd_error("Access to constant buffer %u requested, "
468 "but only %d are supported",
470 pipe
->screen
->get_shader_param(pipe
->screen
, shader
, PIPE_SHADER_CAP_MAX_CONST_BUFFERS
));
473 /* XXX hmm? unwrap the input state */
476 cb
.buffer
= galahad_resource_unwrap(_cb
->buffer
);
479 pipe
->set_constant_buffer(pipe
,
486 galahad_context_set_framebuffer_state(struct pipe_context
*_pipe
,
487 const struct pipe_framebuffer_state
*_state
)
489 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
490 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
491 struct pipe_framebuffer_state unwrapped_state
;
492 struct pipe_framebuffer_state
*state
= NULL
;
495 if (_state
->nr_cbufs
> PIPE_MAX_COLOR_BUFS
) {
496 glhd_error("%d render targets bound, but only %d are permitted by API",
497 _state
->nr_cbufs
, PIPE_MAX_COLOR_BUFS
);
498 } else if (_state
->nr_cbufs
>
499 pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_MAX_RENDER_TARGETS
)) {
500 glhd_warn("%d render targets bound, but only %d are supported",
502 pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_MAX_RENDER_TARGETS
));
505 /* unwrap the input state */
507 memcpy(&unwrapped_state
, _state
, sizeof(unwrapped_state
));
508 for(i
= 0; i
< _state
->nr_cbufs
; i
++)
509 unwrapped_state
.cbufs
[i
] = galahad_surface_unwrap(_state
->cbufs
[i
]);
510 for (; i
< PIPE_MAX_COLOR_BUFS
; i
++)
511 unwrapped_state
.cbufs
[i
] = NULL
;
512 unwrapped_state
.zsbuf
= galahad_surface_unwrap(_state
->zsbuf
);
513 state
= &unwrapped_state
;
516 pipe
->set_framebuffer_state(pipe
,
521 galahad_context_set_polygon_stipple(struct pipe_context
*_pipe
,
522 const struct pipe_poly_stipple
*poly_stipple
)
524 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
525 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
527 pipe
->set_polygon_stipple(pipe
,
532 galahad_context_set_scissor_states(struct pipe_context
*_pipe
,
534 unsigned num_scissors
,
535 const struct pipe_scissor_state
*scissor
)
537 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
538 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
540 pipe
->set_scissor_states(pipe
, start_slot
, num_scissors
,
545 galahad_context_set_viewport_states(struct pipe_context
*_pipe
,
547 unsigned num_viewports
,
548 const struct pipe_viewport_state
*viewport
)
550 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
551 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
553 pipe
->set_viewport_states(pipe
, start_slot
, num_viewports
,
558 galahad_context_set_sampler_views(struct pipe_context
*_pipe
,
562 struct pipe_sampler_view
**_views
)
564 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
565 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
566 struct pipe_sampler_view
*unwrapped_views
[PIPE_MAX_SAMPLERS
];
567 struct pipe_sampler_view
**views
= NULL
;
571 for (i
= 0; i
< num
; i
++)
572 unwrapped_views
[i
] = galahad_sampler_view_unwrap(_views
[i
]);
573 for (; i
< PIPE_MAX_SAMPLERS
; i
++)
574 unwrapped_views
[i
] = NULL
;
576 views
= unwrapped_views
;
580 case PIPE_SHADER_VERTEX
:
581 pipe
->set_vertex_sampler_views(pipe
, num
, views
);
583 case PIPE_SHADER_FRAGMENT
:
584 pipe
->set_fragment_sampler_views(pipe
, num
, views
);
586 case PIPE_SHADER_GEOMETRY
:
587 pipe
->set_geometry_sampler_views(pipe
, num
, views
);
595 galahad_context_set_vertex_sampler_views(struct pipe_context
*_pipe
,
597 struct pipe_sampler_view
**_views
)
599 galahad_context_set_sampler_views(_pipe
, PIPE_SHADER_VERTEX
,
604 galahad_context_set_fragment_sampler_views(struct pipe_context
*_pipe
,
606 struct pipe_sampler_view
**_views
)
608 galahad_context_set_sampler_views(_pipe
, PIPE_SHADER_FRAGMENT
,
613 galahad_context_set_geometry_sampler_views(struct pipe_context
*_pipe
,
615 struct pipe_sampler_view
**_views
)
617 galahad_context_set_sampler_views(_pipe
, PIPE_SHADER_GEOMETRY
,
622 galahad_context_set_vertex_buffers(struct pipe_context
*_pipe
,
623 unsigned start_slot
, unsigned num_buffers
,
624 const struct pipe_vertex_buffer
*_buffers
)
626 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
627 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
628 struct pipe_vertex_buffer unwrapped_buffers
[PIPE_MAX_SHADER_INPUTS
];
629 struct pipe_vertex_buffer
*buffers
= NULL
;
632 if (num_buffers
&& _buffers
) {
633 memcpy(unwrapped_buffers
, _buffers
, num_buffers
* sizeof(*_buffers
));
634 for (i
= 0; i
< num_buffers
; i
++)
635 unwrapped_buffers
[i
].buffer
= galahad_resource_unwrap(_buffers
[i
].buffer
);
636 buffers
= unwrapped_buffers
;
639 pipe
->set_vertex_buffers(pipe
,
640 start_slot
, num_buffers
,
645 galahad_context_set_index_buffer(struct pipe_context
*_pipe
,
646 const struct pipe_index_buffer
*_ib
)
648 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
649 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
650 struct pipe_index_buffer unwrapped_ib
, *ib
= NULL
;
653 if (_ib
->buffer
|| _ib
->user_buffer
) {
654 switch (_ib
->index_size
) {
660 glhd_warn("unrecognized index size %d", _ib
->index_size
);
664 else if (_ib
->offset
|| _ib
->index_size
) {
665 glhd_warn("non-indexed state with index offset %d and index size %d",
666 _ib
->offset
, _ib
->index_size
);
670 unwrapped_ib
.buffer
= galahad_resource_unwrap(_ib
->buffer
);
674 pipe
->set_index_buffer(pipe
, ib
);
677 static INLINE
struct pipe_stream_output_target
*
678 galahad_context_create_stream_output_target(struct pipe_context
*_pipe
,
679 struct pipe_resource
*_res
,
680 unsigned buffer_offset
,
681 unsigned buffer_size
)
683 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
684 struct galahad_resource
*glhd_resource_res
= galahad_resource(_res
);
685 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
686 struct pipe_resource
*res
= glhd_resource_res
->resource
;
688 return pipe
->create_stream_output_target(pipe
,
689 res
, buffer_offset
, buffer_size
);
693 galahad_context_stream_output_target_destroy(
694 struct pipe_context
*_pipe
,
695 struct pipe_stream_output_target
*target
)
697 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
698 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
700 pipe
->stream_output_target_destroy(pipe
, target
);
704 galahad_context_set_stream_output_targets(struct pipe_context
*_pipe
,
705 unsigned num_targets
,
706 struct pipe_stream_output_target
**tgs
,
707 unsigned append_bitmask
)
709 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
710 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
712 pipe
->set_stream_output_targets(pipe
, num_targets
, tgs
, append_bitmask
);
716 galahad_context_resource_copy_region(struct pipe_context
*_pipe
,
717 struct pipe_resource
*_dst
,
722 struct pipe_resource
*_src
,
724 const struct pipe_box
*src_box
)
726 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
727 struct galahad_resource
*glhd_resource_dst
= galahad_resource(_dst
);
728 struct galahad_resource
*glhd_resource_src
= galahad_resource(_src
);
729 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
730 struct pipe_resource
*dst
= glhd_resource_dst
->resource
;
731 struct pipe_resource
*src
= glhd_resource_src
->resource
;
733 if (_dst
->format
!= _src
->format
) {
734 const struct util_format_description
*src_desc
=
735 util_format_description(_src
->format
);
736 const struct util_format_description
*dst_desc
=
737 util_format_description(_dst
->format
);
738 if (!util_is_format_compatible(src_desc
, dst_desc
))
739 glhd_warn("Format mismatch: Source is %s, destination is %s",
740 src_desc
->short_name
,
741 dst_desc
->short_name
);
744 if ((_src
->target
== PIPE_BUFFER
&& _dst
->target
!= PIPE_BUFFER
) ||
745 (_src
->target
!= PIPE_BUFFER
&& _dst
->target
== PIPE_BUFFER
)) {
746 glhd_warn("Resource target mismatch: Source is %i, destination is %i",
747 _src
->target
, _dst
->target
);
750 pipe
->resource_copy_region(pipe
,
762 galahad_context_blit(struct pipe_context
*_pipe
,
763 const struct pipe_blit_info
*_info
)
765 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
766 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
767 struct pipe_blit_info info
= *_info
;
769 info
.dst
.resource
= galahad_resource_unwrap(info
.dst
.resource
);
770 info
.src
.resource
= galahad_resource_unwrap(info
.src
.resource
);
772 if (info
.dst
.box
.width
< 0 ||
773 info
.dst
.box
.height
< 0)
774 glhd_error("Destination dimensions are negative");
776 if (info
.filter
!= PIPE_TEX_FILTER_NEAREST
&&
777 info
.src
.resource
->target
!= PIPE_TEXTURE_3D
&&
778 info
.dst
.box
.depth
!= info
.src
.box
.depth
)
779 glhd_error("Filtering in z-direction on non-3D texture");
781 if (util_format_is_depth_or_stencil(info
.dst
.format
) !=
782 util_format_is_depth_or_stencil(info
.src
.format
))
783 glhd_error("Invalid format conversion: %s <- %s\n",
784 util_format_name(info
.dst
.format
),
785 util_format_name(info
.src
.format
));
787 pipe
->blit(pipe
, &info
);
791 galahad_context_flush_resource(struct pipe_context
*_pipe
,
792 struct pipe_resource
*_res
)
794 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
795 struct galahad_resource
*glhd_resource_res
= galahad_resource(_res
);
796 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
797 struct pipe_resource
*res
= glhd_resource_res
->resource
;
799 pipe
->flush_resource(pipe
, res
);
803 galahad_context_clear(struct pipe_context
*_pipe
,
805 const union pipe_color_union
*color
,
809 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
810 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
820 galahad_context_clear_render_target(struct pipe_context
*_pipe
,
821 struct pipe_surface
*_dst
,
822 const union pipe_color_union
*color
,
823 unsigned dstx
, unsigned dsty
,
824 unsigned width
, unsigned height
)
826 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
827 struct galahad_surface
*glhd_surface_dst
= galahad_surface(_dst
);
828 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
829 struct pipe_surface
*dst
= glhd_surface_dst
->surface
;
831 pipe
->clear_render_target(pipe
,
840 galahad_context_clear_depth_stencil(struct pipe_context
*_pipe
,
841 struct pipe_surface
*_dst
,
842 unsigned clear_flags
,
845 unsigned dstx
, unsigned dsty
,
846 unsigned width
, unsigned height
)
848 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
849 struct galahad_surface
*glhd_surface_dst
= galahad_surface(_dst
);
850 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
851 struct pipe_surface
*dst
= glhd_surface_dst
->surface
;
853 pipe
->clear_depth_stencil(pipe
,
866 galahad_context_flush(struct pipe_context
*_pipe
,
867 struct pipe_fence_handle
**fence
,
870 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
871 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
873 pipe
->flush(pipe
, fence
, flags
);
876 static struct pipe_sampler_view
*
877 galahad_context_create_sampler_view(struct pipe_context
*_pipe
,
878 struct pipe_resource
*_resource
,
879 const struct pipe_sampler_view
*templ
)
881 struct galahad_context
*glhd_context
= galahad_context(_pipe
);
882 struct galahad_resource
*glhd_resource
= galahad_resource(_resource
);
883 struct pipe_context
*pipe
= glhd_context
->pipe
;
884 struct pipe_resource
*resource
= glhd_resource
->resource
;
885 struct pipe_sampler_view
*result
;
887 result
= pipe
->create_sampler_view(pipe
,
892 return galahad_sampler_view_create(glhd_context
, glhd_resource
, result
);
897 galahad_context_sampler_view_destroy(struct pipe_context
*_pipe
,
898 struct pipe_sampler_view
*_view
)
900 galahad_sampler_view_destroy(galahad_context(_pipe
),
901 galahad_sampler_view(_view
));
904 static struct pipe_surface
*
905 galahad_context_create_surface(struct pipe_context
*_pipe
,
906 struct pipe_resource
*_resource
,
907 const struct pipe_surface
*templ
)
909 struct galahad_context
*glhd_context
= galahad_context(_pipe
);
910 struct galahad_resource
*glhd_resource
= galahad_resource(_resource
);
911 struct pipe_context
*pipe
= glhd_context
->pipe
;
912 struct pipe_resource
*resource
= glhd_resource
->resource
;
913 struct pipe_surface
*result
;
915 result
= pipe
->create_surface(pipe
,
920 return galahad_surface_create(glhd_context
, glhd_resource
, result
);
925 galahad_context_surface_destroy(struct pipe_context
*_pipe
,
926 struct pipe_surface
*_surface
)
928 galahad_surface_destroy(galahad_context(_pipe
),
929 galahad_surface(_surface
));
934 galahad_context_transfer_map(struct pipe_context
*_context
,
935 struct pipe_resource
*_resource
,
938 const struct pipe_box
*box
,
939 struct pipe_transfer
**transfer
)
941 struct galahad_context
*glhd_context
= galahad_context(_context
);
942 struct galahad_resource
*glhd_resource
= galahad_resource(_resource
);
943 struct pipe_context
*context
= glhd_context
->pipe
;
944 struct pipe_resource
*resource
= glhd_resource
->resource
;
945 struct pipe_transfer
*result
;
948 map
= context
->transfer_map(context
,
956 glhd_resource
->map_count
++;
958 *transfer
= galahad_transfer_create(glhd_context
, glhd_resource
, result
);
959 return *transfer
? map
: NULL
;
963 galahad_context_transfer_flush_region(struct pipe_context
*_context
,
964 struct pipe_transfer
*_transfer
,
965 const struct pipe_box
*box
)
967 struct galahad_context
*glhd_context
= galahad_context(_context
);
968 struct galahad_transfer
*glhd_transfer
= galahad_transfer(_transfer
);
969 struct pipe_context
*context
= glhd_context
->pipe
;
970 struct pipe_transfer
*transfer
= glhd_transfer
->transfer
;
972 context
->transfer_flush_region(context
,
978 galahad_context_transfer_unmap(struct pipe_context
*_context
,
979 struct pipe_transfer
*_transfer
)
981 struct galahad_context
*glhd_context
= galahad_context(_context
);
982 struct galahad_transfer
*glhd_transfer
= galahad_transfer(_transfer
);
983 struct pipe_context
*context
= glhd_context
->pipe
;
984 struct pipe_transfer
*transfer
= glhd_transfer
->transfer
;
985 struct galahad_resource
*glhd_resource
= galahad_resource(_transfer
->resource
);
987 if (glhd_resource
->map_count
< 1) {
988 glhd_warn("context::transfer_unmap() called too many times"
989 " (count = %d)\n", glhd_resource
->map_count
);
992 glhd_resource
->map_count
--;
994 context
->transfer_unmap(context
,
997 galahad_transfer_destroy(galahad_context(_context
),
998 galahad_transfer(_transfer
));
1003 galahad_context_transfer_inline_write(struct pipe_context
*_context
,
1004 struct pipe_resource
*_resource
,
1007 const struct pipe_box
*box
,
1010 unsigned slice_stride
)
1012 struct galahad_context
*glhd_context
= galahad_context(_context
);
1013 struct galahad_resource
*glhd_resource
= galahad_resource(_resource
);
1014 struct pipe_context
*context
= glhd_context
->pipe
;
1015 struct pipe_resource
*resource
= glhd_resource
->resource
;
1017 context
->transfer_inline_write(context
,
1029 galahad_context_render_condition(struct pipe_context
*_context
,
1030 struct pipe_query
*query
,
1034 struct galahad_context
*glhd_context
= galahad_context(_context
);
1035 struct pipe_context
*context
= glhd_context
->pipe
;
1037 context
->render_condition(context
, query
, condition
, mode
);
1041 struct pipe_context
*
1042 galahad_context_create(struct pipe_screen
*_screen
, struct pipe_context
*pipe
)
1044 struct galahad_context
*glhd_pipe
;
1045 (void)galahad_screen(_screen
);
1047 glhd_pipe
= CALLOC_STRUCT(galahad_context
);
1052 glhd_pipe
->base
.screen
= _screen
;
1053 glhd_pipe
->base
.priv
= pipe
->priv
; /* expose wrapped data */
1054 glhd_pipe
->base
.draw
= NULL
;
1056 glhd_pipe
->base
.destroy
= galahad_context_destroy
;
1058 #define GLHD_PIPE_INIT(_member) \
1059 glhd_pipe->base . _member = pipe -> _member ? galahad_context_ ## _member : NULL
1061 GLHD_PIPE_INIT(draw_vbo
);
1062 GLHD_PIPE_INIT(render_condition
);
1063 GLHD_PIPE_INIT(create_query
);
1064 GLHD_PIPE_INIT(destroy_query
);
1065 GLHD_PIPE_INIT(begin_query
);
1066 GLHD_PIPE_INIT(end_query
);
1067 GLHD_PIPE_INIT(get_query_result
);
1068 GLHD_PIPE_INIT(create_blend_state
);
1069 GLHD_PIPE_INIT(bind_blend_state
);
1070 GLHD_PIPE_INIT(delete_blend_state
);
1071 GLHD_PIPE_INIT(create_sampler_state
);
1072 GLHD_PIPE_INIT(bind_sampler_states
);
1073 GLHD_PIPE_INIT(bind_fragment_sampler_states
);
1074 GLHD_PIPE_INIT(bind_vertex_sampler_states
);
1075 GLHD_PIPE_INIT(bind_geometry_sampler_states
);
1076 //GLHD_PIPE_INIT(bind_compute_sampler_states);
1077 GLHD_PIPE_INIT(delete_sampler_state
);
1078 GLHD_PIPE_INIT(create_rasterizer_state
);
1079 GLHD_PIPE_INIT(bind_rasterizer_state
);
1080 GLHD_PIPE_INIT(delete_rasterizer_state
);
1081 GLHD_PIPE_INIT(create_depth_stencil_alpha_state
);
1082 GLHD_PIPE_INIT(bind_depth_stencil_alpha_state
);
1083 GLHD_PIPE_INIT(delete_depth_stencil_alpha_state
);
1084 GLHD_PIPE_INIT(create_fs_state
);
1085 GLHD_PIPE_INIT(bind_fs_state
);
1086 GLHD_PIPE_INIT(delete_fs_state
);
1087 GLHD_PIPE_INIT(create_vs_state
);
1088 GLHD_PIPE_INIT(bind_vs_state
);
1089 GLHD_PIPE_INIT(delete_vs_state
);
1090 GLHD_PIPE_INIT(create_gs_state
);
1091 GLHD_PIPE_INIT(bind_gs_state
);
1092 GLHD_PIPE_INIT(delete_gs_state
);
1093 GLHD_PIPE_INIT(create_vertex_elements_state
);
1094 GLHD_PIPE_INIT(bind_vertex_elements_state
);
1095 GLHD_PIPE_INIT(delete_vertex_elements_state
);
1096 GLHD_PIPE_INIT(set_blend_color
);
1097 GLHD_PIPE_INIT(set_stencil_ref
);
1098 GLHD_PIPE_INIT(set_sample_mask
);
1099 GLHD_PIPE_INIT(set_clip_state
);
1100 GLHD_PIPE_INIT(set_constant_buffer
);
1101 GLHD_PIPE_INIT(set_framebuffer_state
);
1102 GLHD_PIPE_INIT(set_polygon_stipple
);
1103 GLHD_PIPE_INIT(set_scissor_states
);
1104 GLHD_PIPE_INIT(set_viewport_states
);
1105 GLHD_PIPE_INIT(set_fragment_sampler_views
);
1106 GLHD_PIPE_INIT(set_vertex_sampler_views
);
1107 GLHD_PIPE_INIT(set_geometry_sampler_views
);
1108 //GLHD_PIPE_INIT(set_compute_sampler_views);
1109 //GLHD_PIPE_INIT(set_shader_resources);
1110 GLHD_PIPE_INIT(set_vertex_buffers
);
1111 GLHD_PIPE_INIT(set_index_buffer
);
1112 GLHD_PIPE_INIT(create_stream_output_target
);
1113 GLHD_PIPE_INIT(stream_output_target_destroy
);
1114 GLHD_PIPE_INIT(set_stream_output_targets
);
1115 GLHD_PIPE_INIT(resource_copy_region
);
1116 GLHD_PIPE_INIT(blit
);
1117 GLHD_PIPE_INIT(flush_resource
);
1118 GLHD_PIPE_INIT(clear
);
1119 GLHD_PIPE_INIT(clear_render_target
);
1120 GLHD_PIPE_INIT(clear_depth_stencil
);
1121 GLHD_PIPE_INIT(flush
);
1122 GLHD_PIPE_INIT(create_sampler_view
);
1123 GLHD_PIPE_INIT(sampler_view_destroy
);
1124 GLHD_PIPE_INIT(create_surface
);
1125 GLHD_PIPE_INIT(surface_destroy
);
1126 GLHD_PIPE_INIT(transfer_map
);
1127 GLHD_PIPE_INIT(transfer_flush_region
);
1128 GLHD_PIPE_INIT(transfer_unmap
);
1129 GLHD_PIPE_INIT(transfer_inline_write
);
1130 //GLHD_PIPE_INIT(texture_barrier);
1131 //GLHD_PIPE_INIT(create_video_decoder);
1132 //GLHD_PIPE_INIT(create_video_buffer);
1133 //GLHD_PIPE_INIT(create_compute_state);
1134 //GLHD_PIPE_INIT(bind_compute_state);
1135 //GLHD_PIPE_INIT(delete_compute_state);
1136 //GLHD_PIPE_INIT(set_compute_resources);
1137 //GLHD_PIPE_INIT(set_global_binding);
1138 //GLHD_PIPE_INIT(launch_grid);
1140 #undef GLHD_PIPE_INIT
1142 glhd_pipe
->pipe
= pipe
;
1144 return &glhd_pipe
->base
;