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