fe14a287efbb2c37080f77a8a98bd4947fd090e1
[mesa.git] / src / gallium / drivers / galahad / glhd_context.c
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28
29 #include "pipe/p_context.h"
30
31 #include "util/u_format.h"
32 #include "util/u_memory.h"
33 #include "util/u_inlines.h"
34
35 #include "glhd_context.h"
36 #include "glhd_objects.h"
37
38
39 static void
40 galahad_destroy(struct pipe_context *_pipe)
41 {
42 struct galahad_context *glhd_pipe = galahad_context(_pipe);
43 struct pipe_context *pipe = glhd_pipe->pipe;
44
45 pipe->destroy(pipe);
46
47 FREE(glhd_pipe);
48 }
49
50 static void
51 galahad_draw_vbo(struct pipe_context *_pipe,
52 const struct pipe_draw_info *info)
53 {
54 struct galahad_context *glhd_pipe = galahad_context(_pipe);
55 struct pipe_context *pipe = glhd_pipe->pipe;
56
57 pipe->draw_vbo(pipe, info);
58 }
59
60 static struct pipe_query *
61 galahad_create_query(struct pipe_context *_pipe,
62 unsigned query_type)
63 {
64 struct galahad_context *glhd_pipe = galahad_context(_pipe);
65 struct pipe_context *pipe = glhd_pipe->pipe;
66
67 if (query_type == PIPE_QUERY_OCCLUSION_COUNTER &&
68 !pipe->screen->get_param(pipe->screen, PIPE_CAP_OCCLUSION_QUERY)) {
69 glhd_error("Occlusion query requested but not supported");
70 }
71
72 if (query_type == PIPE_QUERY_TIME_ELAPSED &&
73 !pipe->screen->get_param(pipe->screen, PIPE_CAP_TIMER_QUERY)) {
74 glhd_error("Timer query requested but not supported");
75 }
76
77 return pipe->create_query(pipe,
78 query_type);
79 }
80
81 static void
82 galahad_destroy_query(struct pipe_context *_pipe,
83 struct pipe_query *query)
84 {
85 struct galahad_context *glhd_pipe = galahad_context(_pipe);
86 struct pipe_context *pipe = glhd_pipe->pipe;
87
88 pipe->destroy_query(pipe,
89 query);
90 }
91
92 static void
93 galahad_begin_query(struct pipe_context *_pipe,
94 struct pipe_query *query)
95 {
96 struct galahad_context *glhd_pipe = galahad_context(_pipe);
97 struct pipe_context *pipe = glhd_pipe->pipe;
98
99 pipe->begin_query(pipe,
100 query);
101 }
102
103 static void
104 galahad_end_query(struct pipe_context *_pipe,
105 struct pipe_query *query)
106 {
107 struct galahad_context *glhd_pipe = galahad_context(_pipe);
108 struct pipe_context *pipe = glhd_pipe->pipe;
109
110 pipe->end_query(pipe,
111 query);
112 }
113
114 static boolean
115 galahad_get_query_result(struct pipe_context *_pipe,
116 struct pipe_query *query,
117 boolean wait,
118 void *result)
119 {
120 struct galahad_context *glhd_pipe = galahad_context(_pipe);
121 struct pipe_context *pipe = glhd_pipe->pipe;
122
123 return pipe->get_query_result(pipe,
124 query,
125 wait,
126 result);
127 }
128
129 static void *
130 galahad_create_blend_state(struct pipe_context *_pipe,
131 const struct pipe_blend_state *blend)
132 {
133 struct galahad_context *glhd_pipe = galahad_context(_pipe);
134 struct pipe_context *pipe = glhd_pipe->pipe;
135
136 if (blend->logicop_enable) {
137 if (blend->rt[0].blend_enable) {
138 glhd_warn("Blending enabled for render target 0, but logicops "
139 "are enabled");
140 }
141 }
142
143 return pipe->create_blend_state(pipe,
144 blend);
145 }
146
147 static void
148 galahad_bind_blend_state(struct pipe_context *_pipe,
149 void *blend)
150 {
151 struct galahad_context *glhd_pipe = galahad_context(_pipe);
152 struct pipe_context *pipe = glhd_pipe->pipe;
153
154 pipe->bind_blend_state(pipe,
155 blend);
156 }
157
158 static void
159 galahad_delete_blend_state(struct pipe_context *_pipe,
160 void *blend)
161 {
162 struct galahad_context *glhd_pipe = galahad_context(_pipe);
163 struct pipe_context *pipe = glhd_pipe->pipe;
164
165 pipe->delete_blend_state(pipe,
166 blend);
167 }
168
169 static void *
170 galahad_create_sampler_state(struct pipe_context *_pipe,
171 const struct pipe_sampler_state *sampler)
172 {
173 struct galahad_context *glhd_pipe = galahad_context(_pipe);
174 struct pipe_context *pipe = glhd_pipe->pipe;
175
176 return pipe->create_sampler_state(pipe,
177 sampler);
178 }
179
180 static void
181 galahad_bind_fragment_sampler_states(struct pipe_context *_pipe,
182 unsigned num_samplers,
183 void **samplers)
184 {
185 struct galahad_context *glhd_pipe = galahad_context(_pipe);
186 struct pipe_context *pipe = glhd_pipe->pipe;
187
188 pipe->bind_fragment_sampler_states(pipe,
189 num_samplers,
190 samplers);
191 }
192
193 static void
194 galahad_bind_vertex_sampler_states(struct pipe_context *_pipe,
195 unsigned num_samplers,
196 void **samplers)
197 {
198 struct galahad_context *glhd_pipe = galahad_context(_pipe);
199 struct pipe_context *pipe = glhd_pipe->pipe;
200
201 pipe->bind_vertex_sampler_states(pipe,
202 num_samplers,
203 samplers);
204 }
205
206 static void
207 galahad_delete_sampler_state(struct pipe_context *_pipe,
208 void *sampler)
209 {
210 struct galahad_context *glhd_pipe = galahad_context(_pipe);
211 struct pipe_context *pipe = glhd_pipe->pipe;
212
213 pipe->delete_sampler_state(pipe,
214 sampler);
215 }
216
217 static void *
218 galahad_create_rasterizer_state(struct pipe_context *_pipe,
219 const struct pipe_rasterizer_state *rasterizer)
220 {
221 struct galahad_context *glhd_pipe = galahad_context(_pipe);
222 struct pipe_context *pipe = glhd_pipe->pipe;
223
224 if (rasterizer->point_quad_rasterization) {
225 if (rasterizer->point_smooth) {
226 glhd_warn("Point smoothing requested but ignored");
227 }
228 } else {
229 if (rasterizer->sprite_coord_enable) {
230 glhd_warn("Point sprites requested but ignored");
231 }
232 }
233
234 return pipe->create_rasterizer_state(pipe,
235 rasterizer);
236 }
237
238 static void
239 galahad_bind_rasterizer_state(struct pipe_context *_pipe,
240 void *rasterizer)
241 {
242 struct galahad_context *glhd_pipe = galahad_context(_pipe);
243 struct pipe_context *pipe = glhd_pipe->pipe;
244
245 pipe->bind_rasterizer_state(pipe,
246 rasterizer);
247 }
248
249 static void
250 galahad_delete_rasterizer_state(struct pipe_context *_pipe,
251 void *rasterizer)
252 {
253 struct galahad_context *glhd_pipe = galahad_context(_pipe);
254 struct pipe_context *pipe = glhd_pipe->pipe;
255
256 pipe->delete_rasterizer_state(pipe,
257 rasterizer);
258 }
259
260 static void *
261 galahad_create_depth_stencil_alpha_state(struct pipe_context *_pipe,
262 const struct pipe_depth_stencil_alpha_state *depth_stencil_alpha)
263 {
264 struct galahad_context *glhd_pipe = galahad_context(_pipe);
265 struct pipe_context *pipe = glhd_pipe->pipe;
266
267 return pipe->create_depth_stencil_alpha_state(pipe,
268 depth_stencil_alpha);
269 }
270
271 static void
272 galahad_bind_depth_stencil_alpha_state(struct pipe_context *_pipe,
273 void *depth_stencil_alpha)
274 {
275 struct galahad_context *glhd_pipe = galahad_context(_pipe);
276 struct pipe_context *pipe = glhd_pipe->pipe;
277
278 pipe->bind_depth_stencil_alpha_state(pipe,
279 depth_stencil_alpha);
280 }
281
282 static void
283 galahad_delete_depth_stencil_alpha_state(struct pipe_context *_pipe,
284 void *depth_stencil_alpha)
285 {
286 struct galahad_context *glhd_pipe = galahad_context(_pipe);
287 struct pipe_context *pipe = glhd_pipe->pipe;
288
289 pipe->delete_depth_stencil_alpha_state(pipe,
290 depth_stencil_alpha);
291 }
292
293 static void *
294 galahad_create_fs_state(struct pipe_context *_pipe,
295 const struct pipe_shader_state *fs)
296 {
297 struct galahad_context *glhd_pipe = galahad_context(_pipe);
298 struct pipe_context *pipe = glhd_pipe->pipe;
299
300 return pipe->create_fs_state(pipe,
301 fs);
302 }
303
304 static void
305 galahad_bind_fs_state(struct pipe_context *_pipe,
306 void *fs)
307 {
308 struct galahad_context *glhd_pipe = galahad_context(_pipe);
309 struct pipe_context *pipe = glhd_pipe->pipe;
310
311 pipe->bind_fs_state(pipe,
312 fs);
313 }
314
315 static void
316 galahad_delete_fs_state(struct pipe_context *_pipe,
317 void *fs)
318 {
319 struct galahad_context *glhd_pipe = galahad_context(_pipe);
320 struct pipe_context *pipe = glhd_pipe->pipe;
321
322 pipe->delete_fs_state(pipe,
323 fs);
324 }
325
326 static void *
327 galahad_create_vs_state(struct pipe_context *_pipe,
328 const struct pipe_shader_state *vs)
329 {
330 struct galahad_context *glhd_pipe = galahad_context(_pipe);
331 struct pipe_context *pipe = glhd_pipe->pipe;
332
333 return pipe->create_vs_state(pipe,
334 vs);
335 }
336
337 static void
338 galahad_bind_vs_state(struct pipe_context *_pipe,
339 void *vs)
340 {
341 struct galahad_context *glhd_pipe = galahad_context(_pipe);
342 struct pipe_context *pipe = glhd_pipe->pipe;
343
344 pipe->bind_vs_state(pipe,
345 vs);
346 }
347
348 static void
349 galahad_delete_vs_state(struct pipe_context *_pipe,
350 void *vs)
351 {
352 struct galahad_context *glhd_pipe = galahad_context(_pipe);
353 struct pipe_context *pipe = glhd_pipe->pipe;
354
355 pipe->delete_vs_state(pipe,
356 vs);
357 }
358
359
360 static void *
361 galahad_create_vertex_elements_state(struct pipe_context *_pipe,
362 unsigned num_elements,
363 const struct pipe_vertex_element *vertex_elements)
364 {
365 struct galahad_context *glhd_pipe = galahad_context(_pipe);
366 struct pipe_context *pipe = glhd_pipe->pipe;
367
368 return pipe->create_vertex_elements_state(pipe,
369 num_elements,
370 vertex_elements);
371 }
372
373 static void
374 galahad_bind_vertex_elements_state(struct pipe_context *_pipe,
375 void *velems)
376 {
377 struct galahad_context *glhd_pipe = galahad_context(_pipe);
378 struct pipe_context *pipe = glhd_pipe->pipe;
379
380 pipe->bind_vertex_elements_state(pipe,
381 velems);
382 }
383
384 static void
385 galahad_delete_vertex_elements_state(struct pipe_context *_pipe,
386 void *velems)
387 {
388 struct galahad_context *glhd_pipe = galahad_context(_pipe);
389 struct pipe_context *pipe = glhd_pipe->pipe;
390
391 pipe->delete_vertex_elements_state(pipe,
392 velems);
393 }
394
395 static void
396 galahad_set_blend_color(struct pipe_context *_pipe,
397 const struct pipe_blend_color *blend_color)
398 {
399 struct galahad_context *glhd_pipe = galahad_context(_pipe);
400 struct pipe_context *pipe = glhd_pipe->pipe;
401
402 pipe->set_blend_color(pipe,
403 blend_color);
404 }
405
406 static void
407 galahad_set_stencil_ref(struct pipe_context *_pipe,
408 const struct pipe_stencil_ref *stencil_ref)
409 {
410 struct galahad_context *glhd_pipe = galahad_context(_pipe);
411 struct pipe_context *pipe = glhd_pipe->pipe;
412
413 pipe->set_stencil_ref(pipe,
414 stencil_ref);
415 }
416
417 static void
418 galahad_set_clip_state(struct pipe_context *_pipe,
419 const struct pipe_clip_state *clip)
420 {
421 struct galahad_context *glhd_pipe = galahad_context(_pipe);
422 struct pipe_context *pipe = glhd_pipe->pipe;
423
424 pipe->set_clip_state(pipe,
425 clip);
426 }
427
428 static void
429 galahad_set_sample_mask(struct pipe_context *_pipe,
430 unsigned sample_mask)
431 {
432 struct galahad_context *glhd_pipe = galahad_context(_pipe);
433 struct pipe_context *pipe = glhd_pipe->pipe;
434
435 pipe->set_sample_mask(pipe,
436 sample_mask);
437 }
438
439 static void
440 galahad_set_constant_buffer(struct pipe_context *_pipe,
441 uint shader,
442 uint index,
443 struct pipe_resource *_resource)
444 {
445 struct galahad_context *glhd_pipe = galahad_context(_pipe);
446 struct pipe_context *pipe = glhd_pipe->pipe;
447 struct pipe_resource *unwrapped_resource;
448 struct pipe_resource *resource = NULL;
449
450 /* XXX hmm? unwrap the input state */
451 if (_resource) {
452 unwrapped_resource = galahad_resource_unwrap(_resource);
453 resource = unwrapped_resource;
454 }
455
456 pipe->set_constant_buffer(pipe,
457 shader,
458 index,
459 resource);
460 }
461
462 static void
463 galahad_set_framebuffer_state(struct pipe_context *_pipe,
464 const struct pipe_framebuffer_state *_state)
465 {
466 struct galahad_context *glhd_pipe = galahad_context(_pipe);
467 struct pipe_context *pipe = glhd_pipe->pipe;
468 struct pipe_framebuffer_state unwrapped_state;
469 struct pipe_framebuffer_state *state = NULL;
470 unsigned i;
471
472 if (_state->nr_cbufs > PIPE_MAX_COLOR_BUFS) {
473 glhd_error("%d render targets bound, but only %d are permitted by API",
474 _state->nr_cbufs, PIPE_MAX_COLOR_BUFS);
475 } else if (_state->nr_cbufs >
476 pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_RENDER_TARGETS)) {
477 glhd_warn("%d render targets bound, but only %d are supported",
478 _state->nr_cbufs,
479 pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_RENDER_TARGETS));
480 }
481
482 /* unwrap the input state */
483 if (_state) {
484 memcpy(&unwrapped_state, _state, sizeof(unwrapped_state));
485 for(i = 0; i < _state->nr_cbufs; i++)
486 unwrapped_state.cbufs[i] = galahad_surface_unwrap(_state->cbufs[i]);
487 for (; i < PIPE_MAX_COLOR_BUFS; i++)
488 unwrapped_state.cbufs[i] = NULL;
489 unwrapped_state.zsbuf = galahad_surface_unwrap(_state->zsbuf);
490 state = &unwrapped_state;
491 }
492
493 pipe->set_framebuffer_state(pipe,
494 state);
495 }
496
497 static void
498 galahad_set_polygon_stipple(struct pipe_context *_pipe,
499 const struct pipe_poly_stipple *poly_stipple)
500 {
501 struct galahad_context *glhd_pipe = galahad_context(_pipe);
502 struct pipe_context *pipe = glhd_pipe->pipe;
503
504 pipe->set_polygon_stipple(pipe,
505 poly_stipple);
506 }
507
508 static void
509 galahad_set_scissor_state(struct pipe_context *_pipe,
510 const struct pipe_scissor_state *scissor)
511 {
512 struct galahad_context *glhd_pipe = galahad_context(_pipe);
513 struct pipe_context *pipe = glhd_pipe->pipe;
514
515 pipe->set_scissor_state(pipe,
516 scissor);
517 }
518
519 static void
520 galahad_set_viewport_state(struct pipe_context *_pipe,
521 const struct pipe_viewport_state *viewport)
522 {
523 struct galahad_context *glhd_pipe = galahad_context(_pipe);
524 struct pipe_context *pipe = glhd_pipe->pipe;
525
526 pipe->set_viewport_state(pipe,
527 viewport);
528 }
529
530 static void
531 galahad_set_fragment_sampler_views(struct pipe_context *_pipe,
532 unsigned num,
533 struct pipe_sampler_view **_views)
534 {
535 struct galahad_context *glhd_pipe = galahad_context(_pipe);
536 struct pipe_context *pipe = glhd_pipe->pipe;
537 struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS];
538 struct pipe_sampler_view **views = NULL;
539 unsigned i;
540
541 if (_views) {
542 for (i = 0; i < num; i++)
543 unwrapped_views[i] = galahad_sampler_view_unwrap(_views[i]);
544 for (; i < PIPE_MAX_SAMPLERS; i++)
545 unwrapped_views[i] = NULL;
546
547 views = unwrapped_views;
548 }
549
550 pipe->set_fragment_sampler_views(pipe, num, views);
551 }
552
553 static void
554 galahad_set_vertex_sampler_views(struct pipe_context *_pipe,
555 unsigned num,
556 struct pipe_sampler_view **_views)
557 {
558 struct galahad_context *glhd_pipe = galahad_context(_pipe);
559 struct pipe_context *pipe = glhd_pipe->pipe;
560 struct pipe_sampler_view *unwrapped_views[PIPE_MAX_VERTEX_SAMPLERS];
561 struct pipe_sampler_view **views = NULL;
562 unsigned i;
563
564 if (_views) {
565 for (i = 0; i < num; i++)
566 unwrapped_views[i] = galahad_sampler_view_unwrap(_views[i]);
567 for (; i < PIPE_MAX_VERTEX_SAMPLERS; i++)
568 unwrapped_views[i] = NULL;
569
570 views = unwrapped_views;
571 }
572
573 pipe->set_vertex_sampler_views(pipe, num, views);
574 }
575
576 static void
577 galahad_set_vertex_buffers(struct pipe_context *_pipe,
578 unsigned num_buffers,
579 const struct pipe_vertex_buffer *_buffers)
580 {
581 struct galahad_context *glhd_pipe = galahad_context(_pipe);
582 struct pipe_context *pipe = glhd_pipe->pipe;
583 struct pipe_vertex_buffer unwrapped_buffers[PIPE_MAX_SHADER_INPUTS];
584 struct pipe_vertex_buffer *buffers = NULL;
585 unsigned i;
586
587 if (num_buffers) {
588 memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers));
589 for (i = 0; i < num_buffers; i++)
590 unwrapped_buffers[i].buffer = galahad_resource_unwrap(_buffers[i].buffer);
591 buffers = unwrapped_buffers;
592 }
593
594 pipe->set_vertex_buffers(pipe,
595 num_buffers,
596 buffers);
597 }
598
599 static void
600 galahad_set_index_buffer(struct pipe_context *_pipe,
601 const struct pipe_index_buffer *_ib)
602 {
603 struct galahad_context *glhd_pipe = galahad_context(_pipe);
604 struct pipe_context *pipe = glhd_pipe->pipe;
605 struct pipe_index_buffer unwrapped_ib, *ib = NULL;
606
607 if (_ib->buffer) {
608 switch (_ib->index_size) {
609 case 1:
610 case 2:
611 case 4:
612 break;
613 default:
614 glhd_warn("index buffer %p has unrecognized index size %d",
615 _ib->buffer, _ib->index_size);
616 break;
617 }
618 }
619 else if (_ib->offset || _ib->index_size) {
620 glhd_warn("non-indexed state with index offset %d and index size %d",
621 _ib->offset, _ib->index_size);
622 }
623
624 if (_ib) {
625 unwrapped_ib = *_ib;
626 unwrapped_ib.buffer = galahad_resource_unwrap(_ib->buffer);
627 ib = &unwrapped_ib;
628 }
629
630 pipe->set_index_buffer(pipe, ib);
631 }
632
633 static void
634 galahad_resource_copy_region(struct pipe_context *_pipe,
635 struct pipe_resource *_dst,
636 struct pipe_subresource subdst,
637 unsigned dstx,
638 unsigned dsty,
639 unsigned dstz,
640 struct pipe_resource *_src,
641 struct pipe_subresource subsrc,
642 unsigned srcx,
643 unsigned srcy,
644 unsigned srcz,
645 unsigned width,
646 unsigned height)
647 {
648 struct galahad_context *glhd_pipe = galahad_context(_pipe);
649 struct galahad_resource *glhd_resource_dst = galahad_resource(_dst);
650 struct galahad_resource *glhd_resource_src = galahad_resource(_src);
651 struct pipe_context *pipe = glhd_pipe->pipe;
652 struct pipe_resource *dst = glhd_resource_dst->resource;
653 struct pipe_resource *src = glhd_resource_src->resource;
654
655 if (_dst->format != _src->format) {
656 glhd_warn("Format mismatch: Source is %s, destination is %s",
657 util_format_short_name(_src->format),
658 util_format_short_name(_dst->format));
659 }
660
661 pipe->resource_copy_region(pipe,
662 dst,
663 subdst,
664 dstx,
665 dsty,
666 dstz,
667 src,
668 subsrc,
669 srcx,
670 srcy,
671 srcz,
672 width,
673 height);
674 }
675
676 static void
677 galahad_clear(struct pipe_context *_pipe,
678 unsigned buffers,
679 const float *rgba,
680 double depth,
681 unsigned stencil)
682 {
683 struct galahad_context *glhd_pipe = galahad_context(_pipe);
684 struct pipe_context *pipe = glhd_pipe->pipe;
685
686 pipe->clear(pipe,
687 buffers,
688 rgba,
689 depth,
690 stencil);
691 }
692
693 static void
694 galahad_clear_render_target(struct pipe_context *_pipe,
695 struct pipe_surface *_dst,
696 const float *rgba,
697 unsigned dstx, unsigned dsty,
698 unsigned width, unsigned height)
699 {
700 struct galahad_context *glhd_pipe = galahad_context(_pipe);
701 struct galahad_surface *glhd_surface_dst = galahad_surface(_dst);
702 struct pipe_context *pipe = glhd_pipe->pipe;
703 struct pipe_surface *dst = glhd_surface_dst->surface;
704
705 pipe->clear_render_target(pipe,
706 dst,
707 rgba,
708 dstx,
709 dsty,
710 width,
711 height);
712 }
713 static void
714 galahad_clear_depth_stencil(struct pipe_context *_pipe,
715 struct pipe_surface *_dst,
716 unsigned clear_flags,
717 double depth,
718 unsigned stencil,
719 unsigned dstx, unsigned dsty,
720 unsigned width, unsigned height)
721 {
722 struct galahad_context *glhd_pipe = galahad_context(_pipe);
723 struct galahad_surface *glhd_surface_dst = galahad_surface(_dst);
724 struct pipe_context *pipe = glhd_pipe->pipe;
725 struct pipe_surface *dst = glhd_surface_dst->surface;
726
727 pipe->clear_depth_stencil(pipe,
728 dst,
729 clear_flags,
730 depth,
731 stencil,
732 dstx,
733 dsty,
734 width,
735 height);
736
737 }
738
739 static void
740 galahad_flush(struct pipe_context *_pipe,
741 unsigned flags,
742 struct pipe_fence_handle **fence)
743 {
744 struct galahad_context *glhd_pipe = galahad_context(_pipe);
745 struct pipe_context *pipe = glhd_pipe->pipe;
746
747 pipe->flush(pipe,
748 flags,
749 fence);
750 }
751
752 static unsigned int
753 galahad_is_resource_referenced(struct pipe_context *_pipe,
754 struct pipe_resource *_resource,
755 unsigned face,
756 unsigned level)
757 {
758 struct galahad_context *glhd_pipe = galahad_context(_pipe);
759 struct galahad_resource *glhd_resource = galahad_resource(_resource);
760 struct pipe_context *pipe = glhd_pipe->pipe;
761 struct pipe_resource *resource = glhd_resource->resource;
762
763 return pipe->is_resource_referenced(pipe,
764 resource,
765 face,
766 level);
767 }
768
769 static struct pipe_sampler_view *
770 galahad_context_create_sampler_view(struct pipe_context *_pipe,
771 struct pipe_resource *_resource,
772 const struct pipe_sampler_view *templ)
773 {
774 struct galahad_context *glhd_context = galahad_context(_pipe);
775 struct galahad_resource *glhd_resource = galahad_resource(_resource);
776 struct pipe_context *pipe = glhd_context->pipe;
777 struct pipe_resource *resource = glhd_resource->resource;
778 struct pipe_sampler_view *result;
779
780 result = pipe->create_sampler_view(pipe,
781 resource,
782 templ);
783
784 if (result)
785 return galahad_sampler_view_create(glhd_context, glhd_resource, result);
786 return NULL;
787 }
788
789 static void
790 galahad_context_sampler_view_destroy(struct pipe_context *_pipe,
791 struct pipe_sampler_view *_view)
792 {
793 galahad_sampler_view_destroy(galahad_context(_pipe),
794 galahad_sampler_view(_view));
795 }
796
797 static struct pipe_transfer *
798 galahad_context_get_transfer(struct pipe_context *_context,
799 struct pipe_resource *_resource,
800 struct pipe_subresource sr,
801 unsigned usage,
802 const struct pipe_box *box)
803 {
804 struct galahad_context *glhd_context = galahad_context(_context);
805 struct galahad_resource *glhd_resource = galahad_resource(_resource);
806 struct pipe_context *context = glhd_context->pipe;
807 struct pipe_resource *resource = glhd_resource->resource;
808 struct pipe_transfer *result;
809
810 result = context->get_transfer(context,
811 resource,
812 sr,
813 usage,
814 box);
815
816 if (result)
817 return galahad_transfer_create(glhd_context, glhd_resource, result);
818 return NULL;
819 }
820
821 static void
822 galahad_context_transfer_destroy(struct pipe_context *_pipe,
823 struct pipe_transfer *_transfer)
824 {
825 galahad_transfer_destroy(galahad_context(_pipe),
826 galahad_transfer(_transfer));
827 }
828
829 static void *
830 galahad_context_transfer_map(struct pipe_context *_context,
831 struct pipe_transfer *_transfer)
832 {
833 struct galahad_context *glhd_context = galahad_context(_context);
834 struct galahad_transfer *glhd_transfer = galahad_transfer(_transfer);
835 struct pipe_context *context = glhd_context->pipe;
836 struct pipe_transfer *transfer = glhd_transfer->transfer;
837
838 return context->transfer_map(context,
839 transfer);
840 }
841
842
843
844 static void
845 galahad_context_transfer_flush_region(struct pipe_context *_context,
846 struct pipe_transfer *_transfer,
847 const struct pipe_box *box)
848 {
849 struct galahad_context *glhd_context = galahad_context(_context);
850 struct galahad_transfer *glhd_transfer = galahad_transfer(_transfer);
851 struct pipe_context *context = glhd_context->pipe;
852 struct pipe_transfer *transfer = glhd_transfer->transfer;
853
854 context->transfer_flush_region(context,
855 transfer,
856 box);
857 }
858
859
860 static void
861 galahad_context_transfer_unmap(struct pipe_context *_context,
862 struct pipe_transfer *_transfer)
863 {
864 struct galahad_context *glhd_context = galahad_context(_context);
865 struct galahad_transfer *glhd_transfer = galahad_transfer(_transfer);
866 struct pipe_context *context = glhd_context->pipe;
867 struct pipe_transfer *transfer = glhd_transfer->transfer;
868
869 context->transfer_unmap(context,
870 transfer);
871 }
872
873
874 static void
875 galahad_context_transfer_inline_write(struct pipe_context *_context,
876 struct pipe_resource *_resource,
877 struct pipe_subresource sr,
878 unsigned usage,
879 const struct pipe_box *box,
880 const void *data,
881 unsigned stride,
882 unsigned slice_stride)
883 {
884 struct galahad_context *glhd_context = galahad_context(_context);
885 struct galahad_resource *glhd_resource = galahad_resource(_resource);
886 struct pipe_context *context = glhd_context->pipe;
887 struct pipe_resource *resource = glhd_resource->resource;
888
889 context->transfer_inline_write(context,
890 resource,
891 sr,
892 usage,
893 box,
894 data,
895 stride,
896 slice_stride);
897 }
898
899
900 struct pipe_context *
901 galahad_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
902 {
903 struct galahad_context *glhd_pipe;
904 (void)galahad_screen(_screen);
905
906 glhd_pipe = CALLOC_STRUCT(galahad_context);
907 if (!glhd_pipe) {
908 return NULL;
909 }
910
911 glhd_pipe->base.winsys = NULL;
912 glhd_pipe->base.screen = _screen;
913 glhd_pipe->base.priv = pipe->priv; /* expose wrapped data */
914 glhd_pipe->base.draw = NULL;
915
916 glhd_pipe->base.destroy = galahad_destroy;
917 glhd_pipe->base.draw_vbo = galahad_draw_vbo;
918 glhd_pipe->base.create_query = galahad_create_query;
919 glhd_pipe->base.destroy_query = galahad_destroy_query;
920 glhd_pipe->base.begin_query = galahad_begin_query;
921 glhd_pipe->base.end_query = galahad_end_query;
922 glhd_pipe->base.get_query_result = galahad_get_query_result;
923 glhd_pipe->base.create_blend_state = galahad_create_blend_state;
924 glhd_pipe->base.bind_blend_state = galahad_bind_blend_state;
925 glhd_pipe->base.delete_blend_state = galahad_delete_blend_state;
926 glhd_pipe->base.create_sampler_state = galahad_create_sampler_state;
927 glhd_pipe->base.bind_fragment_sampler_states = galahad_bind_fragment_sampler_states;
928 glhd_pipe->base.bind_vertex_sampler_states = galahad_bind_vertex_sampler_states;
929 glhd_pipe->base.delete_sampler_state = galahad_delete_sampler_state;
930 glhd_pipe->base.create_rasterizer_state = galahad_create_rasterizer_state;
931 glhd_pipe->base.bind_rasterizer_state = galahad_bind_rasterizer_state;
932 glhd_pipe->base.delete_rasterizer_state = galahad_delete_rasterizer_state;
933 glhd_pipe->base.create_depth_stencil_alpha_state = galahad_create_depth_stencil_alpha_state;
934 glhd_pipe->base.bind_depth_stencil_alpha_state = galahad_bind_depth_stencil_alpha_state;
935 glhd_pipe->base.delete_depth_stencil_alpha_state = galahad_delete_depth_stencil_alpha_state;
936 glhd_pipe->base.create_fs_state = galahad_create_fs_state;
937 glhd_pipe->base.bind_fs_state = galahad_bind_fs_state;
938 glhd_pipe->base.delete_fs_state = galahad_delete_fs_state;
939 glhd_pipe->base.create_vs_state = galahad_create_vs_state;
940 glhd_pipe->base.bind_vs_state = galahad_bind_vs_state;
941 glhd_pipe->base.delete_vs_state = galahad_delete_vs_state;
942 glhd_pipe->base.create_vertex_elements_state = galahad_create_vertex_elements_state;
943 glhd_pipe->base.bind_vertex_elements_state = galahad_bind_vertex_elements_state;
944 glhd_pipe->base.delete_vertex_elements_state = galahad_delete_vertex_elements_state;
945 glhd_pipe->base.set_blend_color = galahad_set_blend_color;
946 glhd_pipe->base.set_stencil_ref = galahad_set_stencil_ref;
947 glhd_pipe->base.set_clip_state = galahad_set_clip_state;
948 glhd_pipe->base.set_sample_mask = galahad_set_sample_mask;
949 glhd_pipe->base.set_constant_buffer = galahad_set_constant_buffer;
950 glhd_pipe->base.set_framebuffer_state = galahad_set_framebuffer_state;
951 glhd_pipe->base.set_polygon_stipple = galahad_set_polygon_stipple;
952 glhd_pipe->base.set_scissor_state = galahad_set_scissor_state;
953 glhd_pipe->base.set_viewport_state = galahad_set_viewport_state;
954 glhd_pipe->base.set_fragment_sampler_views = galahad_set_fragment_sampler_views;
955 glhd_pipe->base.set_vertex_sampler_views = galahad_set_vertex_sampler_views;
956 glhd_pipe->base.set_vertex_buffers = galahad_set_vertex_buffers;
957 glhd_pipe->base.set_index_buffer = galahad_set_index_buffer;
958 glhd_pipe->base.resource_copy_region = galahad_resource_copy_region;
959 glhd_pipe->base.clear = galahad_clear;
960 glhd_pipe->base.clear_render_target = galahad_clear_render_target;
961 glhd_pipe->base.clear_depth_stencil = galahad_clear_depth_stencil;
962 glhd_pipe->base.flush = galahad_flush;
963 glhd_pipe->base.is_resource_referenced = galahad_is_resource_referenced;
964 glhd_pipe->base.create_sampler_view = galahad_context_create_sampler_view;
965 glhd_pipe->base.sampler_view_destroy = galahad_context_sampler_view_destroy;
966 glhd_pipe->base.get_transfer = galahad_context_get_transfer;
967 glhd_pipe->base.transfer_destroy = galahad_context_transfer_destroy;
968 glhd_pipe->base.transfer_map = galahad_context_transfer_map;
969 glhd_pipe->base.transfer_unmap = galahad_context_transfer_unmap;
970 glhd_pipe->base.transfer_flush_region = galahad_context_transfer_flush_region;
971 glhd_pipe->base.transfer_inline_write = galahad_context_transfer_inline_write;
972
973 glhd_pipe->pipe = pipe;
974
975 return &glhd_pipe->base;
976 }