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