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