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
);
201 case PIPE_SHADER_VERTEX
:
202 pipe
->bind_vertex_sampler_states(pipe
, num_samplers
, samplers
);
204 case PIPE_SHADER_FRAGMENT
:
205 pipe
->bind_fragment_sampler_states(pipe
, num_samplers
, samplers
);
207 case PIPE_SHADER_GEOMETRY
:
208 pipe
->bind_geometry_sampler_states(pipe
, num_samplers
, samplers
);
216 galahad_context_bind_vertex_sampler_states(struct pipe_context
*_pipe
,
217 unsigned num_samplers
,
220 galahad_context_bind_sampler_states(_pipe
, PIPE_SHADER_VERTEX
,
221 0, num_samplers
, samplers
);
225 galahad_context_bind_fragment_sampler_states(struct pipe_context
*_pipe
,
226 unsigned num_samplers
,
229 galahad_context_bind_sampler_states(_pipe
, PIPE_SHADER_FRAGMENT
,
230 0, num_samplers
, samplers
);
234 galahad_context_bind_geometry_sampler_states(struct pipe_context
*_pipe
,
235 unsigned num_samplers
,
238 galahad_context_bind_sampler_states(_pipe
, PIPE_SHADER_GEOMETRY
,
239 0, num_samplers
, samplers
);
244 galahad_context_delete_sampler_state(struct pipe_context
*_pipe
,
247 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
248 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
250 pipe
->delete_sampler_state(pipe
,
255 galahad_context_create_rasterizer_state(struct pipe_context
*_pipe
,
256 const struct pipe_rasterizer_state
*rasterizer
)
258 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
259 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
261 if (rasterizer
->point_quad_rasterization
) {
262 if (rasterizer
->point_smooth
) {
263 glhd_warn("Point smoothing requested but ignored");
266 if (rasterizer
->sprite_coord_enable
) {
267 glhd_warn("Point sprites requested but ignored");
271 return pipe
->create_rasterizer_state(pipe
,
276 galahad_context_bind_rasterizer_state(struct pipe_context
*_pipe
,
279 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
280 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
282 pipe
->bind_rasterizer_state(pipe
,
287 galahad_context_delete_rasterizer_state(struct pipe_context
*_pipe
,
290 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
291 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
293 pipe
->delete_rasterizer_state(pipe
,
298 galahad_context_create_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
299 const struct pipe_depth_stencil_alpha_state
*depth_stencil_alpha
)
301 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
302 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
304 return pipe
->create_depth_stencil_alpha_state(pipe
,
305 depth_stencil_alpha
);
309 galahad_context_bind_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
310 void *depth_stencil_alpha
)
312 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
313 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
315 pipe
->bind_depth_stencil_alpha_state(pipe
,
316 depth_stencil_alpha
);
320 galahad_context_delete_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
321 void *depth_stencil_alpha
)
323 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
324 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
326 pipe
->delete_depth_stencil_alpha_state(pipe
,
327 depth_stencil_alpha
);
330 #define GLHD_SHADER_STATE(shader_type) \
332 galahad_context_create_##shader_type##_state(struct pipe_context *_pipe, \
333 const struct pipe_shader_state *state) \
335 struct galahad_context *glhd_pipe = galahad_context(_pipe); \
336 struct pipe_context *pipe = glhd_pipe->pipe; \
337 return pipe->create_##shader_type##_state(pipe, state); \
341 galahad_context_bind_##shader_type##_state(struct pipe_context *_pipe, \
344 struct galahad_context *glhd_pipe = galahad_context(_pipe); \
345 struct pipe_context *pipe = glhd_pipe->pipe; \
346 pipe->bind_##shader_type##_state(pipe, state); \
350 galahad_context_delete_##shader_type##_state(struct pipe_context *_pipe, \
353 struct galahad_context *glhd_pipe = galahad_context(_pipe); \
354 struct pipe_context *pipe = glhd_pipe->pipe; \
355 pipe->delete_##shader_type##_state(pipe, state); \
358 GLHD_SHADER_STATE(fs
)
359 GLHD_SHADER_STATE(vs
)
360 GLHD_SHADER_STATE(gs
)
362 #undef GLHD_SHADER_STATE
365 galahad_context_create_vertex_elements_state(struct pipe_context
*_pipe
,
366 unsigned num_elements
,
367 const struct pipe_vertex_element
*vertex_elements
)
369 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
370 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
372 /* XXX check if stride lines up with element size, at least for floats */
374 return pipe
->create_vertex_elements_state(pipe
,
380 galahad_context_bind_vertex_elements_state(struct pipe_context
*_pipe
,
383 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
384 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
386 pipe
->bind_vertex_elements_state(pipe
,
391 galahad_context_delete_vertex_elements_state(struct pipe_context
*_pipe
,
394 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
395 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
397 pipe
->delete_vertex_elements_state(pipe
,
402 galahad_context_set_blend_color(struct pipe_context
*_pipe
,
403 const struct pipe_blend_color
*blend_color
)
405 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
406 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
408 pipe
->set_blend_color(pipe
,
413 galahad_context_set_stencil_ref(struct pipe_context
*_pipe
,
414 const struct pipe_stencil_ref
*stencil_ref
)
416 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
417 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
419 pipe
->set_stencil_ref(pipe
,
424 galahad_context_set_clip_state(struct pipe_context
*_pipe
,
425 const struct pipe_clip_state
*clip
)
427 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
428 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
430 pipe
->set_clip_state(pipe
,
435 galahad_context_set_sample_mask(struct pipe_context
*_pipe
,
436 unsigned sample_mask
)
438 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
439 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
441 pipe
->set_sample_mask(pipe
,
446 galahad_context_set_constant_buffer(struct pipe_context
*_pipe
,
449 struct pipe_constant_buffer
*_cb
)
451 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
452 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
453 struct pipe_constant_buffer cb
;
455 if (shader
>= PIPE_SHADER_TYPES
) {
456 glhd_error("Unknown shader type %u", shader
);
461 pipe
->screen
->get_shader_param(pipe
->screen
, shader
, PIPE_SHADER_CAP_MAX_CONST_BUFFERS
)) {
462 glhd_error("Access to constant buffer %u requested, "
463 "but only %d are supported",
465 pipe
->screen
->get_shader_param(pipe
->screen
, shader
, PIPE_SHADER_CAP_MAX_CONST_BUFFERS
));
468 /* XXX hmm? unwrap the input state */
471 cb
.buffer
= galahad_resource_unwrap(_cb
->buffer
);
474 pipe
->set_constant_buffer(pipe
,
481 galahad_context_set_framebuffer_state(struct pipe_context
*_pipe
,
482 const struct pipe_framebuffer_state
*_state
)
484 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
485 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
486 struct pipe_framebuffer_state unwrapped_state
;
487 struct pipe_framebuffer_state
*state
= NULL
;
490 if (_state
->nr_cbufs
> PIPE_MAX_COLOR_BUFS
) {
491 glhd_error("%d render targets bound, but only %d are permitted by API",
492 _state
->nr_cbufs
, PIPE_MAX_COLOR_BUFS
);
493 } else if (_state
->nr_cbufs
>
494 pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_MAX_RENDER_TARGETS
)) {
495 glhd_warn("%d render targets bound, but only %d are supported",
497 pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_MAX_RENDER_TARGETS
));
500 /* unwrap the input state */
502 memcpy(&unwrapped_state
, _state
, sizeof(unwrapped_state
));
503 for(i
= 0; i
< _state
->nr_cbufs
; i
++)
504 unwrapped_state
.cbufs
[i
] = galahad_surface_unwrap(_state
->cbufs
[i
]);
505 for (; i
< PIPE_MAX_COLOR_BUFS
; i
++)
506 unwrapped_state
.cbufs
[i
] = NULL
;
507 unwrapped_state
.zsbuf
= galahad_surface_unwrap(_state
->zsbuf
);
508 state
= &unwrapped_state
;
511 pipe
->set_framebuffer_state(pipe
,
516 galahad_context_set_polygon_stipple(struct pipe_context
*_pipe
,
517 const struct pipe_poly_stipple
*poly_stipple
)
519 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
520 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
522 pipe
->set_polygon_stipple(pipe
,
527 galahad_context_set_scissor_state(struct pipe_context
*_pipe
,
528 const struct pipe_scissor_state
*scissor
)
530 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
531 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
533 pipe
->set_scissor_state(pipe
,
538 galahad_context_set_viewport_state(struct pipe_context
*_pipe
,
539 const struct pipe_viewport_state
*viewport
)
541 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
542 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
544 pipe
->set_viewport_state(pipe
,
549 galahad_context_set_sampler_views(struct pipe_context
*_pipe
,
553 struct pipe_sampler_view
**_views
)
555 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
556 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
557 struct pipe_sampler_view
*unwrapped_views
[PIPE_MAX_SAMPLERS
];
558 struct pipe_sampler_view
**views
= NULL
;
562 for (i
= 0; i
< num
; i
++)
563 unwrapped_views
[i
] = galahad_sampler_view_unwrap(_views
[i
]);
564 for (; i
< PIPE_MAX_SAMPLERS
; i
++)
565 unwrapped_views
[i
] = NULL
;
567 views
= unwrapped_views
;
571 case PIPE_SHADER_VERTEX
:
572 pipe
->set_vertex_sampler_views(pipe
, num
, views
);
574 case PIPE_SHADER_FRAGMENT
:
575 pipe
->set_fragment_sampler_views(pipe
, num
, views
);
577 case PIPE_SHADER_GEOMETRY
:
578 pipe
->set_geometry_sampler_views(pipe
, num
, views
);
586 galahad_context_set_vertex_sampler_views(struct pipe_context
*_pipe
,
588 struct pipe_sampler_view
**_views
)
590 galahad_context_set_sampler_views(_pipe
, PIPE_SHADER_VERTEX
,
595 galahad_context_set_fragment_sampler_views(struct pipe_context
*_pipe
,
597 struct pipe_sampler_view
**_views
)
599 galahad_context_set_sampler_views(_pipe
, PIPE_SHADER_FRAGMENT
,
604 galahad_context_set_geometry_sampler_views(struct pipe_context
*_pipe
,
606 struct pipe_sampler_view
**_views
)
608 galahad_context_set_sampler_views(_pipe
, PIPE_SHADER_GEOMETRY
,
613 galahad_context_set_vertex_buffers(struct pipe_context
*_pipe
,
614 unsigned start_slot
, unsigned num_buffers
,
615 const struct pipe_vertex_buffer
*_buffers
)
617 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
618 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
619 struct pipe_vertex_buffer unwrapped_buffers
[PIPE_MAX_SHADER_INPUTS
];
620 struct pipe_vertex_buffer
*buffers
= NULL
;
623 if (num_buffers
&& _buffers
) {
624 memcpy(unwrapped_buffers
, _buffers
, num_buffers
* sizeof(*_buffers
));
625 for (i
= 0; i
< num_buffers
; i
++)
626 unwrapped_buffers
[i
].buffer
= galahad_resource_unwrap(_buffers
[i
].buffer
);
627 buffers
= unwrapped_buffers
;
630 pipe
->set_vertex_buffers(pipe
,
631 start_slot
, num_buffers
,
636 galahad_context_set_index_buffer(struct pipe_context
*_pipe
,
637 const struct pipe_index_buffer
*_ib
)
639 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
640 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
641 struct pipe_index_buffer unwrapped_ib
, *ib
= NULL
;
644 if (_ib
->buffer
|| _ib
->user_buffer
) {
645 switch (_ib
->index_size
) {
651 glhd_warn("unrecognized index size %d", _ib
->index_size
);
655 else if (_ib
->offset
|| _ib
->index_size
) {
656 glhd_warn("non-indexed state with index offset %d and index size %d",
657 _ib
->offset
, _ib
->index_size
);
661 unwrapped_ib
.buffer
= galahad_resource_unwrap(_ib
->buffer
);
665 pipe
->set_index_buffer(pipe
, ib
);
668 static INLINE
struct pipe_stream_output_target
*
669 galahad_context_create_stream_output_target(struct pipe_context
*_pipe
,
670 struct pipe_resource
*_res
,
671 unsigned buffer_offset
,
672 unsigned buffer_size
)
674 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
675 struct galahad_resource
*glhd_resource_res
= galahad_resource(_res
);
676 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
677 struct pipe_resource
*res
= glhd_resource_res
->resource
;
679 return pipe
->create_stream_output_target(pipe
,
680 res
, buffer_offset
, buffer_size
);
684 galahad_context_stream_output_target_destroy(
685 struct pipe_context
*_pipe
,
686 struct pipe_stream_output_target
*target
)
688 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
689 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
691 pipe
->stream_output_target_destroy(pipe
, target
);
695 galahad_context_set_stream_output_targets(struct pipe_context
*_pipe
,
696 unsigned num_targets
,
697 struct pipe_stream_output_target
**tgs
,
698 unsigned append_bitmask
)
700 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
701 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
703 pipe
->set_stream_output_targets(pipe
, num_targets
, tgs
, append_bitmask
);
707 galahad_context_resource_copy_region(struct pipe_context
*_pipe
,
708 struct pipe_resource
*_dst
,
713 struct pipe_resource
*_src
,
715 const struct pipe_box
*src_box
)
717 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
718 struct galahad_resource
*glhd_resource_dst
= galahad_resource(_dst
);
719 struct galahad_resource
*glhd_resource_src
= galahad_resource(_src
);
720 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
721 struct pipe_resource
*dst
= glhd_resource_dst
->resource
;
722 struct pipe_resource
*src
= glhd_resource_src
->resource
;
724 if (_dst
->format
!= _src
->format
) {
725 const struct util_format_description
*src_desc
=
726 util_format_description(_src
->format
);
727 const struct util_format_description
*dst_desc
=
728 util_format_description(_dst
->format
);
729 if (!util_is_format_compatible(src_desc
, dst_desc
))
730 glhd_warn("Format mismatch: Source is %s, destination is %s",
731 src_desc
->short_name
,
732 dst_desc
->short_name
);
735 if ((_src
->target
== PIPE_BUFFER
&& _dst
->target
!= PIPE_BUFFER
) ||
736 (_src
->target
!= PIPE_BUFFER
&& _dst
->target
== PIPE_BUFFER
)) {
737 glhd_warn("Resource target mismatch: Source is %i, destination is %i",
738 _src
->target
, _dst
->target
);
741 pipe
->resource_copy_region(pipe
,
753 galahad_context_blit(struct pipe_context
*_pipe
,
754 const struct pipe_blit_info
*_info
)
756 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
757 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
758 struct pipe_blit_info info
= *_info
;
760 info
.dst
.resource
= galahad_resource_unwrap(info
.dst
.resource
);
761 info
.src
.resource
= galahad_resource_unwrap(info
.src
.resource
);
763 if (info
.dst
.box
.width
< 0 ||
764 info
.dst
.box
.height
< 0)
765 glhd_error("Destination dimensions are negative");
767 if (info
.filter
!= PIPE_TEX_FILTER_NEAREST
&&
768 info
.src
.resource
->target
!= PIPE_TEXTURE_3D
&&
769 info
.dst
.box
.depth
!= info
.src
.box
.depth
)
770 glhd_error("Filtering in z-direction on non-3D texture");
772 if (util_format_is_depth_or_stencil(info
.dst
.format
) !=
773 util_format_is_depth_or_stencil(info
.src
.format
))
774 glhd_error("Invalid format conversion: %s <- %s\n",
775 util_format_name(info
.dst
.format
),
776 util_format_name(info
.src
.format
));
778 pipe
->blit(pipe
, &info
);
782 galahad_context_clear(struct pipe_context
*_pipe
,
784 const union pipe_color_union
*color
,
788 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
789 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
799 galahad_context_clear_render_target(struct pipe_context
*_pipe
,
800 struct pipe_surface
*_dst
,
801 const union pipe_color_union
*color
,
802 unsigned dstx
, unsigned dsty
,
803 unsigned width
, unsigned height
)
805 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
806 struct galahad_surface
*glhd_surface_dst
= galahad_surface(_dst
);
807 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
808 struct pipe_surface
*dst
= glhd_surface_dst
->surface
;
810 pipe
->clear_render_target(pipe
,
819 galahad_context_clear_depth_stencil(struct pipe_context
*_pipe
,
820 struct pipe_surface
*_dst
,
821 unsigned clear_flags
,
824 unsigned dstx
, unsigned dsty
,
825 unsigned width
, unsigned height
)
827 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
828 struct galahad_surface
*glhd_surface_dst
= galahad_surface(_dst
);
829 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
830 struct pipe_surface
*dst
= glhd_surface_dst
->surface
;
832 pipe
->clear_depth_stencil(pipe
,
845 galahad_context_flush(struct pipe_context
*_pipe
,
846 struct pipe_fence_handle
**fence
,
849 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
850 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
852 pipe
->flush(pipe
, fence
, flags
);
855 static struct pipe_sampler_view
*
856 galahad_context_create_sampler_view(struct pipe_context
*_pipe
,
857 struct pipe_resource
*_resource
,
858 const struct pipe_sampler_view
*templ
)
860 struct galahad_context
*glhd_context
= galahad_context(_pipe
);
861 struct galahad_resource
*glhd_resource
= galahad_resource(_resource
);
862 struct pipe_context
*pipe
= glhd_context
->pipe
;
863 struct pipe_resource
*resource
= glhd_resource
->resource
;
864 struct pipe_sampler_view
*result
;
866 result
= pipe
->create_sampler_view(pipe
,
871 return galahad_sampler_view_create(glhd_context
, glhd_resource
, result
);
876 galahad_context_sampler_view_destroy(struct pipe_context
*_pipe
,
877 struct pipe_sampler_view
*_view
)
879 galahad_sampler_view_destroy(galahad_context(_pipe
),
880 galahad_sampler_view(_view
));
883 static struct pipe_surface
*
884 galahad_context_create_surface(struct pipe_context
*_pipe
,
885 struct pipe_resource
*_resource
,
886 const struct pipe_surface
*templ
)
888 struct galahad_context
*glhd_context
= galahad_context(_pipe
);
889 struct galahad_resource
*glhd_resource
= galahad_resource(_resource
);
890 struct pipe_context
*pipe
= glhd_context
->pipe
;
891 struct pipe_resource
*resource
= glhd_resource
->resource
;
892 struct pipe_surface
*result
;
894 result
= pipe
->create_surface(pipe
,
899 return galahad_surface_create(glhd_context
, glhd_resource
, result
);
904 galahad_context_surface_destroy(struct pipe_context
*_pipe
,
905 struct pipe_surface
*_surface
)
907 galahad_surface_destroy(galahad_context(_pipe
),
908 galahad_surface(_surface
));
913 galahad_context_transfer_map(struct pipe_context
*_context
,
914 struct pipe_resource
*_resource
,
917 const struct pipe_box
*box
,
918 struct pipe_transfer
**transfer
)
920 struct galahad_context
*glhd_context
= galahad_context(_context
);
921 struct galahad_resource
*glhd_resource
= galahad_resource(_resource
);
922 struct pipe_context
*context
= glhd_context
->pipe
;
923 struct pipe_resource
*resource
= glhd_resource
->resource
;
924 struct pipe_transfer
*result
;
927 map
= context
->transfer_map(context
,
935 glhd_resource
->map_count
++;
937 *transfer
= galahad_transfer_create(glhd_context
, glhd_resource
, result
);
938 return *transfer
? map
: NULL
;
942 galahad_context_transfer_flush_region(struct pipe_context
*_context
,
943 struct pipe_transfer
*_transfer
,
944 const struct pipe_box
*box
)
946 struct galahad_context
*glhd_context
= galahad_context(_context
);
947 struct galahad_transfer
*glhd_transfer
= galahad_transfer(_transfer
);
948 struct pipe_context
*context
= glhd_context
->pipe
;
949 struct pipe_transfer
*transfer
= glhd_transfer
->transfer
;
951 context
->transfer_flush_region(context
,
957 galahad_context_transfer_unmap(struct pipe_context
*_context
,
958 struct pipe_transfer
*_transfer
)
960 struct galahad_context
*glhd_context
= galahad_context(_context
);
961 struct galahad_transfer
*glhd_transfer
= galahad_transfer(_transfer
);
962 struct pipe_context
*context
= glhd_context
->pipe
;
963 struct pipe_transfer
*transfer
= glhd_transfer
->transfer
;
964 struct galahad_resource
*glhd_resource
= galahad_resource(_transfer
->resource
);
966 if (glhd_resource
->map_count
< 1) {
967 glhd_warn("context::transfer_unmap() called too many times"
968 " (count = %d)\n", glhd_resource
->map_count
);
971 glhd_resource
->map_count
--;
973 context
->transfer_unmap(context
,
976 galahad_transfer_destroy(galahad_context(_context
),
977 galahad_transfer(_transfer
));
982 galahad_context_transfer_inline_write(struct pipe_context
*_context
,
983 struct pipe_resource
*_resource
,
986 const struct pipe_box
*box
,
989 unsigned slice_stride
)
991 struct galahad_context
*glhd_context
= galahad_context(_context
);
992 struct galahad_resource
*glhd_resource
= galahad_resource(_resource
);
993 struct pipe_context
*context
= glhd_context
->pipe
;
994 struct pipe_resource
*resource
= glhd_resource
->resource
;
996 context
->transfer_inline_write(context
,
1008 galahad_context_render_condition(struct pipe_context
*_context
,
1009 struct pipe_query
*query
,
1012 struct galahad_context
*glhd_context
= galahad_context(_context
);
1013 struct pipe_context
*context
= glhd_context
->pipe
;
1015 context
->render_condition(context
, query
, mode
);
1019 struct pipe_context
*
1020 galahad_context_create(struct pipe_screen
*_screen
, struct pipe_context
*pipe
)
1022 struct galahad_context
*glhd_pipe
;
1023 (void)galahad_screen(_screen
);
1025 glhd_pipe
= CALLOC_STRUCT(galahad_context
);
1030 glhd_pipe
->base
.screen
= _screen
;
1031 glhd_pipe
->base
.priv
= pipe
->priv
; /* expose wrapped data */
1032 glhd_pipe
->base
.draw
= NULL
;
1034 glhd_pipe
->base
.destroy
= galahad_context_destroy
;
1036 #define GLHD_PIPE_INIT(_member) \
1037 glhd_pipe->base . _member = pipe -> _member ? galahad_context_ ## _member : NULL
1039 GLHD_PIPE_INIT(draw_vbo
);
1040 GLHD_PIPE_INIT(render_condition
);
1041 GLHD_PIPE_INIT(create_query
);
1042 GLHD_PIPE_INIT(destroy_query
);
1043 GLHD_PIPE_INIT(begin_query
);
1044 GLHD_PIPE_INIT(end_query
);
1045 GLHD_PIPE_INIT(get_query_result
);
1046 GLHD_PIPE_INIT(create_blend_state
);
1047 GLHD_PIPE_INIT(bind_blend_state
);
1048 GLHD_PIPE_INIT(delete_blend_state
);
1049 GLHD_PIPE_INIT(create_sampler_state
);
1050 GLHD_PIPE_INIT(bind_fragment_sampler_states
);
1051 GLHD_PIPE_INIT(bind_vertex_sampler_states
);
1052 GLHD_PIPE_INIT(bind_geometry_sampler_states
);
1053 //GLHD_PIPE_INIT(bind_compute_sampler_states);
1054 GLHD_PIPE_INIT(delete_sampler_state
);
1055 GLHD_PIPE_INIT(create_rasterizer_state
);
1056 GLHD_PIPE_INIT(bind_rasterizer_state
);
1057 GLHD_PIPE_INIT(delete_rasterizer_state
);
1058 GLHD_PIPE_INIT(create_depth_stencil_alpha_state
);
1059 GLHD_PIPE_INIT(bind_depth_stencil_alpha_state
);
1060 GLHD_PIPE_INIT(delete_depth_stencil_alpha_state
);
1061 GLHD_PIPE_INIT(create_fs_state
);
1062 GLHD_PIPE_INIT(bind_fs_state
);
1063 GLHD_PIPE_INIT(delete_fs_state
);
1064 GLHD_PIPE_INIT(create_vs_state
);
1065 GLHD_PIPE_INIT(bind_vs_state
);
1066 GLHD_PIPE_INIT(delete_vs_state
);
1067 GLHD_PIPE_INIT(create_gs_state
);
1068 GLHD_PIPE_INIT(bind_gs_state
);
1069 GLHD_PIPE_INIT(delete_gs_state
);
1070 GLHD_PIPE_INIT(create_vertex_elements_state
);
1071 GLHD_PIPE_INIT(bind_vertex_elements_state
);
1072 GLHD_PIPE_INIT(delete_vertex_elements_state
);
1073 GLHD_PIPE_INIT(set_blend_color
);
1074 GLHD_PIPE_INIT(set_stencil_ref
);
1075 GLHD_PIPE_INIT(set_sample_mask
);
1076 GLHD_PIPE_INIT(set_clip_state
);
1077 GLHD_PIPE_INIT(set_constant_buffer
);
1078 GLHD_PIPE_INIT(set_framebuffer_state
);
1079 GLHD_PIPE_INIT(set_polygon_stipple
);
1080 GLHD_PIPE_INIT(set_scissor_state
);
1081 GLHD_PIPE_INIT(set_viewport_state
);
1082 GLHD_PIPE_INIT(set_fragment_sampler_views
);
1083 GLHD_PIPE_INIT(set_vertex_sampler_views
);
1084 GLHD_PIPE_INIT(set_geometry_sampler_views
);
1085 //GLHD_PIPE_INIT(set_compute_sampler_views);
1086 //GLHD_PIPE_INIT(set_shader_resources);
1087 GLHD_PIPE_INIT(set_vertex_buffers
);
1088 GLHD_PIPE_INIT(set_index_buffer
);
1089 GLHD_PIPE_INIT(create_stream_output_target
);
1090 GLHD_PIPE_INIT(stream_output_target_destroy
);
1091 GLHD_PIPE_INIT(set_stream_output_targets
);
1092 GLHD_PIPE_INIT(resource_copy_region
);
1093 GLHD_PIPE_INIT(blit
);
1094 GLHD_PIPE_INIT(clear
);
1095 GLHD_PIPE_INIT(clear_render_target
);
1096 GLHD_PIPE_INIT(clear_depth_stencil
);
1097 GLHD_PIPE_INIT(flush
);
1098 GLHD_PIPE_INIT(create_sampler_view
);
1099 GLHD_PIPE_INIT(sampler_view_destroy
);
1100 GLHD_PIPE_INIT(create_surface
);
1101 GLHD_PIPE_INIT(surface_destroy
);
1102 GLHD_PIPE_INIT(transfer_map
);
1103 GLHD_PIPE_INIT(transfer_flush_region
);
1104 GLHD_PIPE_INIT(transfer_unmap
);
1105 GLHD_PIPE_INIT(transfer_inline_write
);
1106 //GLHD_PIPE_INIT(texture_barrier);
1107 //GLHD_PIPE_INIT(create_video_decoder);
1108 //GLHD_PIPE_INIT(create_video_buffer);
1109 //GLHD_PIPE_INIT(create_compute_state);
1110 //GLHD_PIPE_INIT(bind_compute_state);
1111 //GLHD_PIPE_INIT(delete_compute_state);
1112 //GLHD_PIPE_INIT(set_compute_resources);
1113 //GLHD_PIPE_INIT(set_global_binding);
1114 //GLHD_PIPE_INIT(launch_grid);
1116 #undef GLHD_PIPE_INIT
1118 glhd_pipe
->pipe
= pipe
;
1120 return &glhd_pipe
->base
;