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