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_TIMER_QUERY
)) {
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
);
213 galahad_context_bind_vertex_sampler_states(struct pipe_context
*_pipe
,
214 unsigned num_samplers
,
217 galahad_context_bind_sampler_states(_pipe
, PIPE_SHADER_VERTEX
,
218 0, num_samplers
, samplers
);
222 galahad_context_bind_fragment_sampler_states(struct pipe_context
*_pipe
,
223 unsigned num_samplers
,
226 galahad_context_bind_sampler_states(_pipe
, PIPE_SHADER_FRAGMENT
,
227 0, num_samplers
, samplers
);
232 galahad_context_delete_sampler_state(struct pipe_context
*_pipe
,
235 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
236 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
238 pipe
->delete_sampler_state(pipe
,
243 galahad_context_create_rasterizer_state(struct pipe_context
*_pipe
,
244 const struct pipe_rasterizer_state
*rasterizer
)
246 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
247 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
249 if (rasterizer
->point_quad_rasterization
) {
250 if (rasterizer
->point_smooth
) {
251 glhd_warn("Point smoothing requested but ignored");
254 if (rasterizer
->sprite_coord_enable
) {
255 glhd_warn("Point sprites requested but ignored");
259 return pipe
->create_rasterizer_state(pipe
,
264 galahad_context_bind_rasterizer_state(struct pipe_context
*_pipe
,
267 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
268 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
270 pipe
->bind_rasterizer_state(pipe
,
275 galahad_context_delete_rasterizer_state(struct pipe_context
*_pipe
,
278 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
279 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
281 pipe
->delete_rasterizer_state(pipe
,
286 galahad_context_create_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
287 const struct pipe_depth_stencil_alpha_state
*depth_stencil_alpha
)
289 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
290 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
292 return pipe
->create_depth_stencil_alpha_state(pipe
,
293 depth_stencil_alpha
);
297 galahad_context_bind_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
298 void *depth_stencil_alpha
)
300 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
301 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
303 pipe
->bind_depth_stencil_alpha_state(pipe
,
304 depth_stencil_alpha
);
308 galahad_context_delete_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
309 void *depth_stencil_alpha
)
311 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
312 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
314 pipe
->delete_depth_stencil_alpha_state(pipe
,
315 depth_stencil_alpha
);
319 galahad_context_create_fs_state(struct pipe_context
*_pipe
,
320 const struct pipe_shader_state
*fs
)
322 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
323 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
325 return pipe
->create_fs_state(pipe
,
330 galahad_context_bind_fs_state(struct pipe_context
*_pipe
,
333 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
334 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
336 pipe
->bind_fs_state(pipe
,
341 galahad_context_delete_fs_state(struct pipe_context
*_pipe
,
344 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
345 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
347 pipe
->delete_fs_state(pipe
,
352 galahad_context_create_vs_state(struct pipe_context
*_pipe
,
353 const struct pipe_shader_state
*vs
)
355 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
356 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
358 return pipe
->create_vs_state(pipe
,
363 galahad_context_bind_vs_state(struct pipe_context
*_pipe
,
366 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
367 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
369 pipe
->bind_vs_state(pipe
,
374 galahad_context_delete_vs_state(struct pipe_context
*_pipe
,
377 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
378 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
380 pipe
->delete_vs_state(pipe
,
386 galahad_context_create_vertex_elements_state(struct pipe_context
*_pipe
,
387 unsigned num_elements
,
388 const struct pipe_vertex_element
*vertex_elements
)
390 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
391 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
393 /* XXX check if stride lines up with element size, at least for floats */
395 return pipe
->create_vertex_elements_state(pipe
,
401 galahad_context_bind_vertex_elements_state(struct pipe_context
*_pipe
,
404 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
405 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
407 pipe
->bind_vertex_elements_state(pipe
,
412 galahad_context_delete_vertex_elements_state(struct pipe_context
*_pipe
,
415 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
416 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
418 pipe
->delete_vertex_elements_state(pipe
,
423 galahad_context_set_blend_color(struct pipe_context
*_pipe
,
424 const struct pipe_blend_color
*blend_color
)
426 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
427 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
429 pipe
->set_blend_color(pipe
,
434 galahad_context_set_stencil_ref(struct pipe_context
*_pipe
,
435 const struct pipe_stencil_ref
*stencil_ref
)
437 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
438 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
440 pipe
->set_stencil_ref(pipe
,
445 galahad_context_set_clip_state(struct pipe_context
*_pipe
,
446 const struct pipe_clip_state
*clip
)
448 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
449 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
451 pipe
->set_clip_state(pipe
,
456 galahad_context_set_sample_mask(struct pipe_context
*_pipe
,
457 unsigned sample_mask
)
459 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
460 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
462 pipe
->set_sample_mask(pipe
,
467 galahad_context_set_constant_buffer(struct pipe_context
*_pipe
,
470 struct pipe_constant_buffer
*_cb
)
472 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
473 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
474 struct pipe_constant_buffer cb
;
476 if (shader
>= PIPE_SHADER_TYPES
) {
477 glhd_error("Unknown shader type %u", shader
);
482 pipe
->screen
->get_shader_param(pipe
->screen
, shader
, PIPE_SHADER_CAP_MAX_CONST_BUFFERS
)) {
483 glhd_error("Access to constant buffer %u requested, "
484 "but only %d are supported",
486 pipe
->screen
->get_shader_param(pipe
->screen
, shader
, PIPE_SHADER_CAP_MAX_CONST_BUFFERS
));
489 /* XXX hmm? unwrap the input state */
492 cb
.buffer
= galahad_resource_unwrap(_cb
->buffer
);
495 pipe
->set_constant_buffer(pipe
,
502 galahad_context_set_framebuffer_state(struct pipe_context
*_pipe
,
503 const struct pipe_framebuffer_state
*_state
)
505 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
506 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
507 struct pipe_framebuffer_state unwrapped_state
;
508 struct pipe_framebuffer_state
*state
= NULL
;
511 if (_state
->nr_cbufs
> PIPE_MAX_COLOR_BUFS
) {
512 glhd_error("%d render targets bound, but only %d are permitted by API",
513 _state
->nr_cbufs
, PIPE_MAX_COLOR_BUFS
);
514 } else if (_state
->nr_cbufs
>
515 pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_MAX_RENDER_TARGETS
)) {
516 glhd_warn("%d render targets bound, but only %d are supported",
518 pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_MAX_RENDER_TARGETS
));
521 /* unwrap the input state */
523 memcpy(&unwrapped_state
, _state
, sizeof(unwrapped_state
));
524 for(i
= 0; i
< _state
->nr_cbufs
; i
++)
525 unwrapped_state
.cbufs
[i
] = galahad_surface_unwrap(_state
->cbufs
[i
]);
526 for (; i
< PIPE_MAX_COLOR_BUFS
; i
++)
527 unwrapped_state
.cbufs
[i
] = NULL
;
528 unwrapped_state
.zsbuf
= galahad_surface_unwrap(_state
->zsbuf
);
529 state
= &unwrapped_state
;
532 pipe
->set_framebuffer_state(pipe
,
537 galahad_context_set_polygon_stipple(struct pipe_context
*_pipe
,
538 const struct pipe_poly_stipple
*poly_stipple
)
540 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
541 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
543 pipe
->set_polygon_stipple(pipe
,
548 galahad_context_set_scissor_state(struct pipe_context
*_pipe
,
549 const struct pipe_scissor_state
*scissor
)
551 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
552 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
554 pipe
->set_scissor_state(pipe
,
559 galahad_context_set_viewport_state(struct pipe_context
*_pipe
,
560 const struct pipe_viewport_state
*viewport
)
562 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
563 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
565 pipe
->set_viewport_state(pipe
,
570 galahad_context_set_sampler_views(struct pipe_context
*_pipe
,
574 struct pipe_sampler_view
**_views
)
576 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
577 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
578 struct pipe_sampler_view
*unwrapped_views
[PIPE_MAX_SAMPLERS
];
579 struct pipe_sampler_view
**views
= NULL
;
583 for (i
= 0; i
< num
; i
++)
584 unwrapped_views
[i
] = galahad_sampler_view_unwrap(_views
[i
]);
585 for (; i
< PIPE_MAX_SAMPLERS
; i
++)
586 unwrapped_views
[i
] = NULL
;
588 views
= unwrapped_views
;
592 case PIPE_SHADER_VERTEX
:
593 pipe
->set_vertex_sampler_views(pipe
, num
, views
);
595 case PIPE_SHADER_FRAGMENT
:
596 pipe
->set_fragment_sampler_views(pipe
, num
, views
);
604 galahad_context_set_vertex_sampler_views(struct pipe_context
*_pipe
,
606 struct pipe_sampler_view
**_views
)
608 galahad_context_set_sampler_views(_pipe
, PIPE_SHADER_VERTEX
,
613 galahad_context_set_fragment_sampler_views(struct pipe_context
*_pipe
,
615 struct pipe_sampler_view
**_views
)
617 galahad_context_set_sampler_views(_pipe
, PIPE_SHADER_FRAGMENT
,
623 galahad_context_set_vertex_buffers(struct pipe_context
*_pipe
,
624 unsigned start_slot
, unsigned num_buffers
,
625 const struct pipe_vertex_buffer
*_buffers
)
627 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
628 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
629 struct pipe_vertex_buffer unwrapped_buffers
[PIPE_MAX_SHADER_INPUTS
];
630 struct pipe_vertex_buffer
*buffers
= NULL
;
634 memcpy(unwrapped_buffers
, _buffers
, num_buffers
* sizeof(*_buffers
));
635 for (i
= 0; i
< num_buffers
; i
++)
636 unwrapped_buffers
[i
].buffer
= galahad_resource_unwrap(_buffers
[i
].buffer
);
637 buffers
= unwrapped_buffers
;
640 pipe
->set_vertex_buffers(pipe
,
641 start_slot
, num_buffers
,
646 galahad_context_set_index_buffer(struct pipe_context
*_pipe
,
647 const struct pipe_index_buffer
*_ib
)
649 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
650 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
651 struct pipe_index_buffer unwrapped_ib
, *ib
= NULL
;
654 if (_ib
->buffer
|| _ib
->user_buffer
) {
655 switch (_ib
->index_size
) {
661 glhd_warn("unrecognized index size %d", _ib
->index_size
);
665 else if (_ib
->offset
|| _ib
->index_size
) {
666 glhd_warn("non-indexed state with index offset %d and index size %d",
667 _ib
->offset
, _ib
->index_size
);
671 unwrapped_ib
.buffer
= galahad_resource_unwrap(_ib
->buffer
);
675 pipe
->set_index_buffer(pipe
, ib
);
679 galahad_context_resource_copy_region(struct pipe_context
*_pipe
,
680 struct pipe_resource
*_dst
,
685 struct pipe_resource
*_src
,
687 const struct pipe_box
*src_box
)
689 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
690 struct galahad_resource
*glhd_resource_dst
= galahad_resource(_dst
);
691 struct galahad_resource
*glhd_resource_src
= galahad_resource(_src
);
692 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
693 struct pipe_resource
*dst
= glhd_resource_dst
->resource
;
694 struct pipe_resource
*src
= glhd_resource_src
->resource
;
696 if (_dst
->format
!= _src
->format
) {
697 const struct util_format_description
*src_desc
=
698 util_format_description(_src
->format
);
699 const struct util_format_description
*dst_desc
=
700 util_format_description(_dst
->format
);
701 if (!util_is_format_compatible(src_desc
, dst_desc
))
702 glhd_warn("Format mismatch: Source is %s, destination is %s",
703 src_desc
->short_name
,
704 dst_desc
->short_name
);
707 if ((_src
->target
== PIPE_BUFFER
&& _dst
->target
!= PIPE_BUFFER
) ||
708 (_src
->target
!= PIPE_BUFFER
&& _dst
->target
== PIPE_BUFFER
)) {
709 glhd_warn("Resource target mismatch: Source is %i, destination is %i",
710 _src
->target
, _dst
->target
);
713 pipe
->resource_copy_region(pipe
,
725 galahad_context_blit(struct pipe_context
*_pipe
,
726 const struct pipe_blit_info
*_info
)
728 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
729 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
730 struct pipe_blit_info info
= *_info
;
732 info
.dst
.resource
= galahad_resource_unwrap(info
.dst
.resource
);
733 info
.src
.resource
= galahad_resource_unwrap(info
.src
.resource
);
735 if (info
.dst
.box
.width
< 0 ||
736 info
.dst
.box
.height
< 0)
737 glhd_error("Destination dimensions are negative");
739 if (info
.filter
!= PIPE_TEX_FILTER_NEAREST
&&
740 info
.src
.resource
->target
!= PIPE_TEXTURE_3D
&&
741 info
.dst
.box
.depth
!= info
.src
.box
.depth
)
742 glhd_error("Filtering in z-direction on non-3D texture");
744 if (util_format_is_depth_or_stencil(info
.dst
.format
) !=
745 util_format_is_depth_or_stencil(info
.src
.format
))
746 glhd_error("Invalid format conversion: %s <- %s\n",
747 util_format_name(info
.dst
.format
),
748 util_format_name(info
.src
.format
));
750 pipe
->blit(pipe
, &info
);
754 galahad_context_clear(struct pipe_context
*_pipe
,
756 const union pipe_color_union
*color
,
760 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
761 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
771 galahad_context_clear_render_target(struct pipe_context
*_pipe
,
772 struct pipe_surface
*_dst
,
773 const union pipe_color_union
*color
,
774 unsigned dstx
, unsigned dsty
,
775 unsigned width
, unsigned height
)
777 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
778 struct galahad_surface
*glhd_surface_dst
= galahad_surface(_dst
);
779 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
780 struct pipe_surface
*dst
= glhd_surface_dst
->surface
;
782 pipe
->clear_render_target(pipe
,
791 galahad_context_clear_depth_stencil(struct pipe_context
*_pipe
,
792 struct pipe_surface
*_dst
,
793 unsigned clear_flags
,
796 unsigned dstx
, unsigned dsty
,
797 unsigned width
, unsigned height
)
799 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
800 struct galahad_surface
*glhd_surface_dst
= galahad_surface(_dst
);
801 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
802 struct pipe_surface
*dst
= glhd_surface_dst
->surface
;
804 pipe
->clear_depth_stencil(pipe
,
817 galahad_context_flush(struct pipe_context
*_pipe
,
818 struct pipe_fence_handle
**fence
)
820 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
821 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
827 static struct pipe_sampler_view
*
828 galahad_context_create_sampler_view(struct pipe_context
*_pipe
,
829 struct pipe_resource
*_resource
,
830 const struct pipe_sampler_view
*templ
)
832 struct galahad_context
*glhd_context
= galahad_context(_pipe
);
833 struct galahad_resource
*glhd_resource
= galahad_resource(_resource
);
834 struct pipe_context
*pipe
= glhd_context
->pipe
;
835 struct pipe_resource
*resource
= glhd_resource
->resource
;
836 struct pipe_sampler_view
*result
;
838 result
= pipe
->create_sampler_view(pipe
,
843 return galahad_sampler_view_create(glhd_context
, glhd_resource
, result
);
848 galahad_context_sampler_view_destroy(struct pipe_context
*_pipe
,
849 struct pipe_sampler_view
*_view
)
851 galahad_sampler_view_destroy(galahad_context(_pipe
),
852 galahad_sampler_view(_view
));
855 static struct pipe_surface
*
856 galahad_context_create_surface(struct pipe_context
*_pipe
,
857 struct pipe_resource
*_resource
,
858 const struct pipe_surface
*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_surface
*result
;
866 result
= pipe
->create_surface(pipe
,
871 return galahad_surface_create(glhd_context
, glhd_resource
, result
);
876 galahad_context_surface_destroy(struct pipe_context
*_pipe
,
877 struct pipe_surface
*_surface
)
879 galahad_surface_destroy(galahad_context(_pipe
),
880 galahad_surface(_surface
));
885 galahad_context_transfer_map(struct pipe_context
*_context
,
886 struct pipe_resource
*_resource
,
889 const struct pipe_box
*box
,
890 struct pipe_transfer
**transfer
)
892 struct galahad_context
*glhd_context
= galahad_context(_context
);
893 struct galahad_resource
*glhd_resource
= galahad_resource(_resource
);
894 struct pipe_context
*context
= glhd_context
->pipe
;
895 struct pipe_resource
*resource
= glhd_resource
->resource
;
896 struct pipe_transfer
*result
;
899 map
= context
->transfer_map(context
,
907 glhd_resource
->map_count
++;
909 *transfer
= galahad_transfer_create(glhd_context
, glhd_resource
, result
);
910 return *transfer
? map
: NULL
;
914 galahad_context_transfer_flush_region(struct pipe_context
*_context
,
915 struct pipe_transfer
*_transfer
,
916 const struct pipe_box
*box
)
918 struct galahad_context
*glhd_context
= galahad_context(_context
);
919 struct galahad_transfer
*glhd_transfer
= galahad_transfer(_transfer
);
920 struct pipe_context
*context
= glhd_context
->pipe
;
921 struct pipe_transfer
*transfer
= glhd_transfer
->transfer
;
923 context
->transfer_flush_region(context
,
929 galahad_context_transfer_unmap(struct pipe_context
*_context
,
930 struct pipe_transfer
*_transfer
)
932 struct galahad_context
*glhd_context
= galahad_context(_context
);
933 struct galahad_transfer
*glhd_transfer
= galahad_transfer(_transfer
);
934 struct pipe_context
*context
= glhd_context
->pipe
;
935 struct pipe_transfer
*transfer
= glhd_transfer
->transfer
;
936 struct galahad_resource
*glhd_resource
= galahad_resource(_transfer
->resource
);
938 if (glhd_resource
->map_count
< 1) {
939 glhd_warn("context::transfer_unmap() called too many times"
940 " (count = %d)\n", glhd_resource
->map_count
);
943 glhd_resource
->map_count
--;
945 context
->transfer_unmap(context
,
948 galahad_transfer_destroy(galahad_context(_context
),
949 galahad_transfer(_transfer
));
954 galahad_context_transfer_inline_write(struct pipe_context
*_context
,
955 struct pipe_resource
*_resource
,
958 const struct pipe_box
*box
,
961 unsigned slice_stride
)
963 struct galahad_context
*glhd_context
= galahad_context(_context
);
964 struct galahad_resource
*glhd_resource
= galahad_resource(_resource
);
965 struct pipe_context
*context
= glhd_context
->pipe
;
966 struct pipe_resource
*resource
= glhd_resource
->resource
;
968 context
->transfer_inline_write(context
,
980 galahad_context_render_condition(struct pipe_context
*_context
,
981 struct pipe_query
*query
,
984 struct galahad_context
*glhd_context
= galahad_context(_context
);
985 struct pipe_context
*context
= glhd_context
->pipe
;
987 context
->render_condition(context
, query
, mode
);
991 struct pipe_context
*
992 galahad_context_create(struct pipe_screen
*_screen
, struct pipe_context
*pipe
)
994 struct galahad_context
*glhd_pipe
;
995 (void)galahad_screen(_screen
);
997 glhd_pipe
= CALLOC_STRUCT(galahad_context
);
1002 glhd_pipe
->base
.screen
= _screen
;
1003 glhd_pipe
->base
.priv
= pipe
->priv
; /* expose wrapped data */
1004 glhd_pipe
->base
.draw
= NULL
;
1006 glhd_pipe
->base
.destroy
= galahad_context_destroy
;
1008 #define GLHD_PIPE_INIT(_member) \
1009 glhd_pipe->base . _member = pipe -> _member ? galahad_context_ ## _member : NULL
1011 GLHD_PIPE_INIT(draw_vbo
);
1012 GLHD_PIPE_INIT(render_condition
);
1013 GLHD_PIPE_INIT(create_query
);
1014 GLHD_PIPE_INIT(destroy_query
);
1015 GLHD_PIPE_INIT(begin_query
);
1016 GLHD_PIPE_INIT(end_query
);
1017 GLHD_PIPE_INIT(get_query_result
);
1018 GLHD_PIPE_INIT(create_blend_state
);
1019 GLHD_PIPE_INIT(bind_blend_state
);
1020 GLHD_PIPE_INIT(delete_blend_state
);
1021 GLHD_PIPE_INIT(create_sampler_state
);
1022 GLHD_PIPE_INIT(bind_fragment_sampler_states
);
1023 GLHD_PIPE_INIT(bind_vertex_sampler_states
);
1024 //GLHD_PIPE_INIT(bind_geometry_sampler_states);
1025 //GLHD_PIPE_INIT(bind_compute_sampler_states);
1026 GLHD_PIPE_INIT(delete_sampler_state
);
1027 GLHD_PIPE_INIT(create_rasterizer_state
);
1028 GLHD_PIPE_INIT(bind_rasterizer_state
);
1029 GLHD_PIPE_INIT(delete_rasterizer_state
);
1030 GLHD_PIPE_INIT(create_depth_stencil_alpha_state
);
1031 GLHD_PIPE_INIT(bind_depth_stencil_alpha_state
);
1032 GLHD_PIPE_INIT(delete_depth_stencil_alpha_state
);
1033 GLHD_PIPE_INIT(create_fs_state
);
1034 GLHD_PIPE_INIT(bind_fs_state
);
1035 GLHD_PIPE_INIT(delete_fs_state
);
1036 GLHD_PIPE_INIT(create_vs_state
);
1037 GLHD_PIPE_INIT(bind_vs_state
);
1038 GLHD_PIPE_INIT(delete_vs_state
);
1039 //GLHD_PIPE_INIT(create_gs_state);
1040 //GLHD_PIPE_INIT(bind_gs_state);
1041 //GLHD_PIPE_INIT(delete_gs_state);
1042 GLHD_PIPE_INIT(create_vertex_elements_state
);
1043 GLHD_PIPE_INIT(bind_vertex_elements_state
);
1044 GLHD_PIPE_INIT(delete_vertex_elements_state
);
1045 GLHD_PIPE_INIT(set_blend_color
);
1046 GLHD_PIPE_INIT(set_stencil_ref
);
1047 GLHD_PIPE_INIT(set_sample_mask
);
1048 GLHD_PIPE_INIT(set_clip_state
);
1049 GLHD_PIPE_INIT(set_constant_buffer
);
1050 GLHD_PIPE_INIT(set_framebuffer_state
);
1051 GLHD_PIPE_INIT(set_polygon_stipple
);
1052 GLHD_PIPE_INIT(set_scissor_state
);
1053 GLHD_PIPE_INIT(set_viewport_state
);
1054 GLHD_PIPE_INIT(set_fragment_sampler_views
);
1055 GLHD_PIPE_INIT(set_vertex_sampler_views
);
1056 //GLHD_PIPE_INIT(set_geometry_sampler_views);
1057 //GLHD_PIPE_INIT(set_compute_sampler_views);
1058 //GLHD_PIPE_INIT(set_shader_resources);
1059 GLHD_PIPE_INIT(set_vertex_buffers
);
1060 GLHD_PIPE_INIT(set_index_buffer
);
1061 //GLHD_PIPE_INIT(create_stream_output_target);
1062 //GLHD_PIPE_INIT(stream_output_target_destroy);
1063 //GLHD_PIPE_INIT(set_stream_output_targets);
1064 GLHD_PIPE_INIT(resource_copy_region
);
1065 GLHD_PIPE_INIT(blit
);
1066 GLHD_PIPE_INIT(clear
);
1067 GLHD_PIPE_INIT(clear_render_target
);
1068 GLHD_PIPE_INIT(clear_depth_stencil
);
1069 GLHD_PIPE_INIT(flush
);
1070 GLHD_PIPE_INIT(create_sampler_view
);
1071 GLHD_PIPE_INIT(sampler_view_destroy
);
1072 GLHD_PIPE_INIT(create_surface
);
1073 GLHD_PIPE_INIT(surface_destroy
);
1074 GLHD_PIPE_INIT(transfer_map
);
1075 GLHD_PIPE_INIT(transfer_flush_region
);
1076 GLHD_PIPE_INIT(transfer_unmap
);
1077 GLHD_PIPE_INIT(transfer_inline_write
);
1078 //GLHD_PIPE_INIT(texture_barrier);
1079 //GLHD_PIPE_INIT(create_video_decoder);
1080 //GLHD_PIPE_INIT(create_video_buffer);
1081 //GLHD_PIPE_INIT(create_compute_state);
1082 //GLHD_PIPE_INIT(bind_compute_state);
1083 //GLHD_PIPE_INIT(delete_compute_state);
1084 //GLHD_PIPE_INIT(set_compute_resources);
1085 //GLHD_PIPE_INIT(set_global_binding);
1086 //GLHD_PIPE_INIT(launch_grid);
1088 #undef GLHD_PIPE_INIT
1090 glhd_pipe
->pipe
= pipe
;
1092 return &glhd_pipe
->base
;