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_fragment_sampler_states(struct pipe_context
*_pipe
,
186 unsigned num_samplers
,
189 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
190 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
192 if (num_samplers
> PIPE_MAX_SAMPLERS
) {
193 glhd_error("%u fragment samplers requested, "
194 "but only %u are permitted by API",
195 num_samplers
, PIPE_MAX_SAMPLERS
);
198 pipe
->bind_fragment_sampler_states(pipe
,
204 galahad_context_bind_vertex_sampler_states(struct pipe_context
*_pipe
,
205 unsigned num_samplers
,
208 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
209 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
211 if (num_samplers
> PIPE_MAX_VERTEX_SAMPLERS
) {
212 glhd_error("%u vertex samplers requested, "
213 "but only %u are permitted by API",
214 num_samplers
, PIPE_MAX_VERTEX_SAMPLERS
);
217 pipe
->bind_vertex_sampler_states(pipe
,
223 galahad_context_delete_sampler_state(struct pipe_context
*_pipe
,
226 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
227 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
229 pipe
->delete_sampler_state(pipe
,
234 galahad_context_create_rasterizer_state(struct pipe_context
*_pipe
,
235 const struct pipe_rasterizer_state
*rasterizer
)
237 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
238 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
240 if (rasterizer
->point_quad_rasterization
) {
241 if (rasterizer
->point_smooth
) {
242 glhd_warn("Point smoothing requested but ignored");
245 if (rasterizer
->sprite_coord_enable
) {
246 glhd_warn("Point sprites requested but ignored");
250 return pipe
->create_rasterizer_state(pipe
,
255 galahad_context_bind_rasterizer_state(struct pipe_context
*_pipe
,
258 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
259 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
261 pipe
->bind_rasterizer_state(pipe
,
266 galahad_context_delete_rasterizer_state(struct pipe_context
*_pipe
,
269 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
270 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
272 pipe
->delete_rasterizer_state(pipe
,
277 galahad_context_create_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
278 const struct pipe_depth_stencil_alpha_state
*depth_stencil_alpha
)
280 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
281 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
283 return pipe
->create_depth_stencil_alpha_state(pipe
,
284 depth_stencil_alpha
);
288 galahad_context_bind_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
289 void *depth_stencil_alpha
)
291 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
292 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
294 pipe
->bind_depth_stencil_alpha_state(pipe
,
295 depth_stencil_alpha
);
299 galahad_context_delete_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
300 void *depth_stencil_alpha
)
302 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
303 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
305 pipe
->delete_depth_stencil_alpha_state(pipe
,
306 depth_stencil_alpha
);
310 galahad_context_create_fs_state(struct pipe_context
*_pipe
,
311 const struct pipe_shader_state
*fs
)
313 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
314 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
316 return pipe
->create_fs_state(pipe
,
321 galahad_context_bind_fs_state(struct pipe_context
*_pipe
,
324 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
325 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
327 pipe
->bind_fs_state(pipe
,
332 galahad_context_delete_fs_state(struct pipe_context
*_pipe
,
335 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
336 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
338 pipe
->delete_fs_state(pipe
,
343 galahad_context_create_vs_state(struct pipe_context
*_pipe
,
344 const struct pipe_shader_state
*vs
)
346 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
347 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
349 return pipe
->create_vs_state(pipe
,
354 galahad_context_bind_vs_state(struct pipe_context
*_pipe
,
357 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
358 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
360 pipe
->bind_vs_state(pipe
,
365 galahad_context_delete_vs_state(struct pipe_context
*_pipe
,
368 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
369 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
371 pipe
->delete_vs_state(pipe
,
377 galahad_context_create_vertex_elements_state(struct pipe_context
*_pipe
,
378 unsigned num_elements
,
379 const struct pipe_vertex_element
*vertex_elements
)
381 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
382 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
384 /* XXX check if stride lines up with element size, at least for floats */
386 return pipe
->create_vertex_elements_state(pipe
,
392 galahad_context_bind_vertex_elements_state(struct pipe_context
*_pipe
,
395 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
396 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
398 pipe
->bind_vertex_elements_state(pipe
,
403 galahad_context_delete_vertex_elements_state(struct pipe_context
*_pipe
,
406 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
407 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
409 pipe
->delete_vertex_elements_state(pipe
,
414 galahad_context_set_blend_color(struct pipe_context
*_pipe
,
415 const struct pipe_blend_color
*blend_color
)
417 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
418 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
420 pipe
->set_blend_color(pipe
,
425 galahad_context_set_stencil_ref(struct pipe_context
*_pipe
,
426 const struct pipe_stencil_ref
*stencil_ref
)
428 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
429 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
431 pipe
->set_stencil_ref(pipe
,
436 galahad_context_set_clip_state(struct pipe_context
*_pipe
,
437 const struct pipe_clip_state
*clip
)
439 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
440 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
442 pipe
->set_clip_state(pipe
,
447 galahad_context_set_sample_mask(struct pipe_context
*_pipe
,
448 unsigned sample_mask
)
450 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
451 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
453 pipe
->set_sample_mask(pipe
,
458 galahad_context_set_constant_buffer(struct pipe_context
*_pipe
,
461 struct pipe_constant_buffer
*_cb
)
463 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
464 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
465 struct pipe_constant_buffer cb
;
467 if (shader
>= PIPE_SHADER_TYPES
) {
468 glhd_error("Unknown shader type %u", shader
);
473 pipe
->screen
->get_shader_param(pipe
->screen
, shader
, PIPE_SHADER_CAP_MAX_CONST_BUFFERS
)) {
474 glhd_error("Access to constant buffer %u requested, "
475 "but only %d are supported",
477 pipe
->screen
->get_shader_param(pipe
->screen
, shader
, PIPE_SHADER_CAP_MAX_CONST_BUFFERS
));
480 /* XXX hmm? unwrap the input state */
483 cb
.buffer
= galahad_resource_unwrap(_cb
->buffer
);
486 pipe
->set_constant_buffer(pipe
,
493 galahad_context_set_framebuffer_state(struct pipe_context
*_pipe
,
494 const struct pipe_framebuffer_state
*_state
)
496 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
497 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
498 struct pipe_framebuffer_state unwrapped_state
;
499 struct pipe_framebuffer_state
*state
= NULL
;
502 if (_state
->nr_cbufs
> PIPE_MAX_COLOR_BUFS
) {
503 glhd_error("%d render targets bound, but only %d are permitted by API",
504 _state
->nr_cbufs
, PIPE_MAX_COLOR_BUFS
);
505 } else if (_state
->nr_cbufs
>
506 pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_MAX_RENDER_TARGETS
)) {
507 glhd_warn("%d render targets bound, but only %d are supported",
509 pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_MAX_RENDER_TARGETS
));
512 /* unwrap the input state */
514 memcpy(&unwrapped_state
, _state
, sizeof(unwrapped_state
));
515 for(i
= 0; i
< _state
->nr_cbufs
; i
++)
516 unwrapped_state
.cbufs
[i
] = galahad_surface_unwrap(_state
->cbufs
[i
]);
517 for (; i
< PIPE_MAX_COLOR_BUFS
; i
++)
518 unwrapped_state
.cbufs
[i
] = NULL
;
519 unwrapped_state
.zsbuf
= galahad_surface_unwrap(_state
->zsbuf
);
520 state
= &unwrapped_state
;
523 pipe
->set_framebuffer_state(pipe
,
528 galahad_context_set_polygon_stipple(struct pipe_context
*_pipe
,
529 const struct pipe_poly_stipple
*poly_stipple
)
531 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
532 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
534 pipe
->set_polygon_stipple(pipe
,
539 galahad_context_set_scissor_state(struct pipe_context
*_pipe
,
540 const struct pipe_scissor_state
*scissor
)
542 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
543 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
545 pipe
->set_scissor_state(pipe
,
550 galahad_context_set_viewport_state(struct pipe_context
*_pipe
,
551 const struct pipe_viewport_state
*viewport
)
553 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
554 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
556 pipe
->set_viewport_state(pipe
,
561 galahad_context_set_fragment_sampler_views(struct pipe_context
*_pipe
,
563 struct pipe_sampler_view
**_views
)
565 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
566 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
567 struct pipe_sampler_view
*unwrapped_views
[PIPE_MAX_SAMPLERS
];
568 struct pipe_sampler_view
**views
= NULL
;
572 for (i
= 0; i
< num
; i
++)
573 unwrapped_views
[i
] = galahad_sampler_view_unwrap(_views
[i
]);
574 for (; i
< PIPE_MAX_SAMPLERS
; i
++)
575 unwrapped_views
[i
] = NULL
;
577 views
= unwrapped_views
;
580 pipe
->set_fragment_sampler_views(pipe
, num
, views
);
584 galahad_context_set_vertex_sampler_views(struct pipe_context
*_pipe
,
586 struct pipe_sampler_view
**_views
)
588 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
589 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
590 struct pipe_sampler_view
*unwrapped_views
[PIPE_MAX_VERTEX_SAMPLERS
];
591 struct pipe_sampler_view
**views
= NULL
;
595 for (i
= 0; i
< num
; i
++)
596 unwrapped_views
[i
] = galahad_sampler_view_unwrap(_views
[i
]);
597 for (; i
< PIPE_MAX_VERTEX_SAMPLERS
; i
++)
598 unwrapped_views
[i
] = NULL
;
600 views
= unwrapped_views
;
603 pipe
->set_vertex_sampler_views(pipe
, num
, views
);
607 galahad_context_set_vertex_buffers(struct pipe_context
*_pipe
,
608 unsigned num_buffers
,
609 const struct pipe_vertex_buffer
*_buffers
)
611 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
612 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
613 struct pipe_vertex_buffer unwrapped_buffers
[PIPE_MAX_SHADER_INPUTS
];
614 struct pipe_vertex_buffer
*buffers
= NULL
;
618 memcpy(unwrapped_buffers
, _buffers
, num_buffers
* sizeof(*_buffers
));
619 for (i
= 0; i
< num_buffers
; i
++)
620 unwrapped_buffers
[i
].buffer
= galahad_resource_unwrap(_buffers
[i
].buffer
);
621 buffers
= unwrapped_buffers
;
624 pipe
->set_vertex_buffers(pipe
,
630 galahad_context_set_index_buffer(struct pipe_context
*_pipe
,
631 const struct pipe_index_buffer
*_ib
)
633 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
634 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
635 struct pipe_index_buffer unwrapped_ib
, *ib
= NULL
;
639 switch (_ib
->index_size
) {
645 glhd_warn("index buffer %p has unrecognized index size %d",
646 (void *) _ib
->buffer
, _ib
->index_size
);
650 else if (_ib
->offset
|| _ib
->index_size
) {
651 glhd_warn("non-indexed state with index offset %d and index size %d",
652 _ib
->offset
, _ib
->index_size
);
656 unwrapped_ib
.buffer
= galahad_resource_unwrap(_ib
->buffer
);
660 pipe
->set_index_buffer(pipe
, ib
);
664 galahad_context_resource_copy_region(struct pipe_context
*_pipe
,
665 struct pipe_resource
*_dst
,
670 struct pipe_resource
*_src
,
672 const struct pipe_box
*src_box
)
674 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
675 struct galahad_resource
*glhd_resource_dst
= galahad_resource(_dst
);
676 struct galahad_resource
*glhd_resource_src
= galahad_resource(_src
);
677 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
678 struct pipe_resource
*dst
= glhd_resource_dst
->resource
;
679 struct pipe_resource
*src
= glhd_resource_src
->resource
;
681 if (_dst
->format
!= _src
->format
) {
682 glhd_warn("Format mismatch: Source is %s, destination is %s",
683 util_format_short_name(_src
->format
),
684 util_format_short_name(_dst
->format
));
687 if ((_src
->target
== PIPE_BUFFER
&& _dst
->target
!= PIPE_BUFFER
) ||
688 (_src
->target
!= PIPE_BUFFER
&& _dst
->target
== PIPE_BUFFER
)) {
689 glhd_warn("Resource target mismatch: Source is %i, destination is %i",
690 _src
->target
, _dst
->target
);
693 pipe
->resource_copy_region(pipe
,
705 galahad_context_clear(struct pipe_context
*_pipe
,
707 const union pipe_color_union
*color
,
711 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
712 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
722 galahad_context_clear_render_target(struct pipe_context
*_pipe
,
723 struct pipe_surface
*_dst
,
724 const union pipe_color_union
*color
,
725 unsigned dstx
, unsigned dsty
,
726 unsigned width
, unsigned height
)
728 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
729 struct galahad_surface
*glhd_surface_dst
= galahad_surface(_dst
);
730 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
731 struct pipe_surface
*dst
= glhd_surface_dst
->surface
;
733 pipe
->clear_render_target(pipe
,
742 galahad_context_clear_depth_stencil(struct pipe_context
*_pipe
,
743 struct pipe_surface
*_dst
,
744 unsigned clear_flags
,
747 unsigned dstx
, unsigned dsty
,
748 unsigned width
, unsigned height
)
750 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
751 struct galahad_surface
*glhd_surface_dst
= galahad_surface(_dst
);
752 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
753 struct pipe_surface
*dst
= glhd_surface_dst
->surface
;
755 pipe
->clear_depth_stencil(pipe
,
768 galahad_context_flush(struct pipe_context
*_pipe
,
769 struct pipe_fence_handle
**fence
)
771 struct galahad_context
*glhd_pipe
= galahad_context(_pipe
);
772 struct pipe_context
*pipe
= glhd_pipe
->pipe
;
778 static struct pipe_sampler_view
*
779 galahad_context_create_sampler_view(struct pipe_context
*_pipe
,
780 struct pipe_resource
*_resource
,
781 const struct pipe_sampler_view
*templ
)
783 struct galahad_context
*glhd_context
= galahad_context(_pipe
);
784 struct galahad_resource
*glhd_resource
= galahad_resource(_resource
);
785 struct pipe_context
*pipe
= glhd_context
->pipe
;
786 struct pipe_resource
*resource
= glhd_resource
->resource
;
787 struct pipe_sampler_view
*result
;
789 result
= pipe
->create_sampler_view(pipe
,
794 return galahad_sampler_view_create(glhd_context
, glhd_resource
, result
);
799 galahad_context_sampler_view_destroy(struct pipe_context
*_pipe
,
800 struct pipe_sampler_view
*_view
)
802 galahad_sampler_view_destroy(galahad_context(_pipe
),
803 galahad_sampler_view(_view
));
806 static struct pipe_surface
*
807 galahad_context_create_surface(struct pipe_context
*_pipe
,
808 struct pipe_resource
*_resource
,
809 const struct pipe_surface
*templ
)
811 struct galahad_context
*glhd_context
= galahad_context(_pipe
);
812 struct galahad_resource
*glhd_resource
= galahad_resource(_resource
);
813 struct pipe_context
*pipe
= glhd_context
->pipe
;
814 struct pipe_resource
*resource
= glhd_resource
->resource
;
815 struct pipe_surface
*result
;
817 result
= pipe
->create_surface(pipe
,
822 return galahad_surface_create(glhd_context
, glhd_resource
, result
);
827 galahad_context_surface_destroy(struct pipe_context
*_pipe
,
828 struct pipe_surface
*_surface
)
830 galahad_surface_destroy(galahad_context(_pipe
),
831 galahad_surface(_surface
));
836 static struct pipe_transfer
*
837 galahad_context_get_transfer(struct pipe_context
*_context
,
838 struct pipe_resource
*_resource
,
841 const struct pipe_box
*box
)
843 struct galahad_context
*glhd_context
= galahad_context(_context
);
844 struct galahad_resource
*glhd_resource
= galahad_resource(_resource
);
845 struct pipe_context
*context
= glhd_context
->pipe
;
846 struct pipe_resource
*resource
= glhd_resource
->resource
;
847 struct pipe_transfer
*result
;
849 result
= context
->get_transfer(context
,
856 return galahad_transfer_create(glhd_context
, glhd_resource
, result
);
861 galahad_context_transfer_destroy(struct pipe_context
*_pipe
,
862 struct pipe_transfer
*_transfer
)
864 galahad_transfer_destroy(galahad_context(_pipe
),
865 galahad_transfer(_transfer
));
869 galahad_context_transfer_map(struct pipe_context
*_context
,
870 struct pipe_transfer
*_transfer
)
872 struct galahad_context
*glhd_context
= galahad_context(_context
);
873 struct galahad_transfer
*glhd_transfer
= galahad_transfer(_transfer
);
874 struct pipe_context
*context
= glhd_context
->pipe
;
875 struct pipe_transfer
*transfer
= glhd_transfer
->transfer
;
877 struct galahad_resource
*glhd_resource
= galahad_resource(_transfer
->resource
);
879 glhd_resource
->map_count
++;
881 return context
->transfer_map(context
,
888 galahad_context_transfer_flush_region(struct pipe_context
*_context
,
889 struct pipe_transfer
*_transfer
,
890 const struct pipe_box
*box
)
892 struct galahad_context
*glhd_context
= galahad_context(_context
);
893 struct galahad_transfer
*glhd_transfer
= galahad_transfer(_transfer
);
894 struct pipe_context
*context
= glhd_context
->pipe
;
895 struct pipe_transfer
*transfer
= glhd_transfer
->transfer
;
897 context
->transfer_flush_region(context
,
904 galahad_context_transfer_unmap(struct pipe_context
*_context
,
905 struct pipe_transfer
*_transfer
)
907 struct galahad_context
*glhd_context
= galahad_context(_context
);
908 struct galahad_transfer
*glhd_transfer
= galahad_transfer(_transfer
);
909 struct pipe_context
*context
= glhd_context
->pipe
;
910 struct pipe_transfer
*transfer
= glhd_transfer
->transfer
;
911 struct galahad_resource
*glhd_resource
= galahad_resource(_transfer
->resource
);
913 if (glhd_resource
->map_count
< 1) {
914 glhd_warn("context::transfer_unmap() called too many times"
915 " (count = %d)\n", glhd_resource
->map_count
);
918 glhd_resource
->map_count
--;
920 context
->transfer_unmap(context
,
926 galahad_context_transfer_inline_write(struct pipe_context
*_context
,
927 struct pipe_resource
*_resource
,
930 const struct pipe_box
*box
,
933 unsigned slice_stride
)
935 struct galahad_context
*glhd_context
= galahad_context(_context
);
936 struct galahad_resource
*glhd_resource
= galahad_resource(_resource
);
937 struct pipe_context
*context
= glhd_context
->pipe
;
938 struct pipe_resource
*resource
= glhd_resource
->resource
;
940 context
->transfer_inline_write(context
,
952 galahad_context_render_condition(struct pipe_context
*_context
,
953 struct pipe_query
*query
,
956 struct galahad_context
*glhd_context
= galahad_context(_context
);
957 struct pipe_context
*context
= glhd_context
->pipe
;
959 context
->render_condition(context
, query
, mode
);
963 struct pipe_context
*
964 galahad_context_create(struct pipe_screen
*_screen
, struct pipe_context
*pipe
)
966 struct galahad_context
*glhd_pipe
;
967 (void)galahad_screen(_screen
);
969 glhd_pipe
= CALLOC_STRUCT(galahad_context
);
974 glhd_pipe
->base
.screen
= _screen
;
975 glhd_pipe
->base
.priv
= pipe
->priv
; /* expose wrapped data */
976 glhd_pipe
->base
.draw
= NULL
;
978 glhd_pipe
->base
.destroy
= galahad_context_destroy
;
980 #define GLHD_PIPE_INIT(_member) \
981 glhd_pipe->base . _member = pipe -> _member ? galahad_context_ ## _member : NULL
983 GLHD_PIPE_INIT(draw_vbo
);
984 GLHD_PIPE_INIT(render_condition
);
985 GLHD_PIPE_INIT(create_query
);
986 GLHD_PIPE_INIT(destroy_query
);
987 GLHD_PIPE_INIT(begin_query
);
988 GLHD_PIPE_INIT(end_query
);
989 GLHD_PIPE_INIT(get_query_result
);
990 GLHD_PIPE_INIT(create_blend_state
);
991 GLHD_PIPE_INIT(bind_blend_state
);
992 GLHD_PIPE_INIT(delete_blend_state
);
993 GLHD_PIPE_INIT(create_sampler_state
);
994 GLHD_PIPE_INIT(bind_fragment_sampler_states
);
995 GLHD_PIPE_INIT(bind_vertex_sampler_states
);
996 //GLHD_PIPE_INIT(bind_geometry_sampler_states);
997 //GLHD_PIPE_INIT(bind_compute_sampler_states);
998 GLHD_PIPE_INIT(delete_sampler_state
);
999 GLHD_PIPE_INIT(create_rasterizer_state
);
1000 GLHD_PIPE_INIT(bind_rasterizer_state
);
1001 GLHD_PIPE_INIT(delete_rasterizer_state
);
1002 GLHD_PIPE_INIT(create_depth_stencil_alpha_state
);
1003 GLHD_PIPE_INIT(bind_depth_stencil_alpha_state
);
1004 GLHD_PIPE_INIT(delete_depth_stencil_alpha_state
);
1005 GLHD_PIPE_INIT(create_fs_state
);
1006 GLHD_PIPE_INIT(bind_fs_state
);
1007 GLHD_PIPE_INIT(delete_fs_state
);
1008 GLHD_PIPE_INIT(create_vs_state
);
1009 GLHD_PIPE_INIT(bind_vs_state
);
1010 GLHD_PIPE_INIT(delete_vs_state
);
1011 //GLHD_PIPE_INIT(create_gs_state);
1012 //GLHD_PIPE_INIT(bind_gs_state);
1013 //GLHD_PIPE_INIT(delete_gs_state);
1014 GLHD_PIPE_INIT(create_vertex_elements_state
);
1015 GLHD_PIPE_INIT(bind_vertex_elements_state
);
1016 GLHD_PIPE_INIT(delete_vertex_elements_state
);
1017 GLHD_PIPE_INIT(set_blend_color
);
1018 GLHD_PIPE_INIT(set_stencil_ref
);
1019 GLHD_PIPE_INIT(set_sample_mask
);
1020 GLHD_PIPE_INIT(set_clip_state
);
1021 GLHD_PIPE_INIT(set_constant_buffer
);
1022 GLHD_PIPE_INIT(set_framebuffer_state
);
1023 GLHD_PIPE_INIT(set_polygon_stipple
);
1024 GLHD_PIPE_INIT(set_scissor_state
);
1025 GLHD_PIPE_INIT(set_viewport_state
);
1026 GLHD_PIPE_INIT(set_fragment_sampler_views
);
1027 GLHD_PIPE_INIT(set_vertex_sampler_views
);
1028 //GLHD_PIPE_INIT(set_geometry_sampler_views);
1029 //GLHD_PIPE_INIT(set_compute_sampler_views);
1030 //GLHD_PIPE_INIT(set_shader_resources);
1031 GLHD_PIPE_INIT(set_vertex_buffers
);
1032 GLHD_PIPE_INIT(set_index_buffer
);
1033 //GLHD_PIPE_INIT(create_stream_output_target);
1034 //GLHD_PIPE_INIT(stream_output_target_destroy);
1035 //GLHD_PIPE_INIT(set_stream_output_targets);
1036 GLHD_PIPE_INIT(resource_copy_region
);
1037 //GLHD_PIPE_INIT(resource_resolve);
1038 GLHD_PIPE_INIT(clear
);
1039 GLHD_PIPE_INIT(clear_render_target
);
1040 GLHD_PIPE_INIT(clear_depth_stencil
);
1041 GLHD_PIPE_INIT(flush
);
1042 GLHD_PIPE_INIT(create_sampler_view
);
1043 GLHD_PIPE_INIT(sampler_view_destroy
);
1044 GLHD_PIPE_INIT(create_surface
);
1045 GLHD_PIPE_INIT(surface_destroy
);
1046 GLHD_PIPE_INIT(get_transfer
);
1047 GLHD_PIPE_INIT(transfer_destroy
);
1048 GLHD_PIPE_INIT(transfer_map
);
1049 GLHD_PIPE_INIT(transfer_flush_region
);
1050 GLHD_PIPE_INIT(transfer_unmap
);
1051 GLHD_PIPE_INIT(transfer_inline_write
);
1052 //GLHD_PIPE_INIT(texture_barrier);
1053 //GLHD_PIPE_INIT(create_video_decoder);
1054 //GLHD_PIPE_INIT(create_video_buffer);
1055 //GLHD_PIPE_INIT(create_compute_state);
1056 //GLHD_PIPE_INIT(bind_compute_state);
1057 //GLHD_PIPE_INIT(delete_compute_state);
1058 //GLHD_PIPE_INIT(set_compute_resources);
1059 //GLHD_PIPE_INIT(set_global_binding);
1060 //GLHD_PIPE_INIT(launch_grid);
1062 #undef GLHD_PIPE_INIT
1064 glhd_pipe
->pipe
= pipe
;
1066 return &glhd_pipe
->base
;