gallium: remove PIPE_MAX_VERTEX/GEOMETRY_SAMPLERS #define
[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_context_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_context_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 /* XXX we should check that all bound resources are unmapped
58 * before drawing.
59 */
60
61 pipe->draw_vbo(pipe, info);
62 }
63
64 static struct pipe_query *
65 galahad_context_create_query(struct pipe_context *_pipe,
66 unsigned query_type)
67 {
68 struct galahad_context *glhd_pipe = galahad_context(_pipe);
69 struct pipe_context *pipe = glhd_pipe->pipe;
70
71 if (query_type == PIPE_QUERY_OCCLUSION_COUNTER &&
72 !pipe->screen->get_param(pipe->screen, PIPE_CAP_OCCLUSION_QUERY)) {
73 glhd_error("Occlusion query requested but not supported");
74 }
75
76 if (query_type == PIPE_QUERY_TIME_ELAPSED &&
77 !pipe->screen->get_param(pipe->screen, PIPE_CAP_TIMER_QUERY)) {
78 glhd_error("Timer query requested but not supported");
79 }
80
81 return pipe->create_query(pipe,
82 query_type);
83 }
84
85 static void
86 galahad_context_destroy_query(struct pipe_context *_pipe,
87 struct pipe_query *query)
88 {
89 struct galahad_context *glhd_pipe = galahad_context(_pipe);
90 struct pipe_context *pipe = glhd_pipe->pipe;
91
92 pipe->destroy_query(pipe,
93 query);
94 }
95
96 static void
97 galahad_context_begin_query(struct pipe_context *_pipe,
98 struct pipe_query *query)
99 {
100 struct galahad_context *glhd_pipe = galahad_context(_pipe);
101 struct pipe_context *pipe = glhd_pipe->pipe;
102
103 pipe->begin_query(pipe,
104 query);
105 }
106
107 static void
108 galahad_context_end_query(struct pipe_context *_pipe,
109 struct pipe_query *query)
110 {
111 struct galahad_context *glhd_pipe = galahad_context(_pipe);
112 struct pipe_context *pipe = glhd_pipe->pipe;
113
114 pipe->end_query(pipe,
115 query);
116 }
117
118 static boolean
119 galahad_context_get_query_result(struct pipe_context *_pipe,
120 struct pipe_query *query,
121 boolean wait,
122 union pipe_query_result *result)
123 {
124 struct galahad_context *glhd_pipe = galahad_context(_pipe);
125 struct pipe_context *pipe = glhd_pipe->pipe;
126
127 return pipe->get_query_result(pipe,
128 query,
129 wait,
130 result);
131 }
132
133 static void *
134 galahad_context_create_blend_state(struct pipe_context *_pipe,
135 const struct pipe_blend_state *blend)
136 {
137 struct galahad_context *glhd_pipe = galahad_context(_pipe);
138 struct pipe_context *pipe = glhd_pipe->pipe;
139
140 if (blend->logicop_enable) {
141 if (blend->rt[0].blend_enable) {
142 glhd_warn("Blending enabled for render target 0, but logicops "
143 "are enabled");
144 }
145 }
146
147 return pipe->create_blend_state(pipe,
148 blend);
149 }
150
151 static void
152 galahad_context_bind_blend_state(struct pipe_context *_pipe,
153 void *blend)
154 {
155 struct galahad_context *glhd_pipe = galahad_context(_pipe);
156 struct pipe_context *pipe = glhd_pipe->pipe;
157
158 pipe->bind_blend_state(pipe,
159 blend);
160 }
161
162 static void
163 galahad_context_delete_blend_state(struct pipe_context *_pipe,
164 void *blend)
165 {
166 struct galahad_context *glhd_pipe = galahad_context(_pipe);
167 struct pipe_context *pipe = glhd_pipe->pipe;
168
169 pipe->delete_blend_state(pipe,
170 blend);
171 }
172
173 static void *
174 galahad_context_create_sampler_state(struct pipe_context *_pipe,
175 const struct pipe_sampler_state *sampler)
176 {
177 struct galahad_context *glhd_pipe = galahad_context(_pipe);
178 struct pipe_context *pipe = glhd_pipe->pipe;
179
180 return pipe->create_sampler_state(pipe,
181 sampler);
182 }
183
184 static void
185 galahad_context_bind_fragment_sampler_states(struct pipe_context *_pipe,
186 unsigned num_samplers,
187 void **samplers)
188 {
189 struct galahad_context *glhd_pipe = galahad_context(_pipe);
190 struct pipe_context *pipe = glhd_pipe->pipe;
191
192 if (num_samplers > PIPE_MAX_SAMPLERS) {
193 glhd_error("%u fragment samplers requested, "
194 "but only %u are permitted by API",
195 num_samplers, PIPE_MAX_SAMPLERS);
196 }
197
198 pipe->bind_fragment_sampler_states(pipe,
199 num_samplers,
200 samplers);
201 }
202
203 static void
204 galahad_context_bind_vertex_sampler_states(struct pipe_context *_pipe,
205 unsigned num_samplers,
206 void **samplers)
207 {
208 struct galahad_context *glhd_pipe = galahad_context(_pipe);
209 struct pipe_context *pipe = glhd_pipe->pipe;
210
211 if (num_samplers > PIPE_MAX_SAMPLERS) {
212 glhd_error("%u vertex samplers requested, "
213 "but only %u are permitted by API",
214 num_samplers, PIPE_MAX_SAMPLERS);
215 }
216
217 pipe->bind_vertex_sampler_states(pipe,
218 num_samplers,
219 samplers);
220 }
221
222 static void
223 galahad_context_delete_sampler_state(struct pipe_context *_pipe,
224 void *sampler)
225 {
226 struct galahad_context *glhd_pipe = galahad_context(_pipe);
227 struct pipe_context *pipe = glhd_pipe->pipe;
228
229 pipe->delete_sampler_state(pipe,
230 sampler);
231 }
232
233 static void *
234 galahad_context_create_rasterizer_state(struct pipe_context *_pipe,
235 const struct pipe_rasterizer_state *rasterizer)
236 {
237 struct galahad_context *glhd_pipe = galahad_context(_pipe);
238 struct pipe_context *pipe = glhd_pipe->pipe;
239
240 if (rasterizer->point_quad_rasterization) {
241 if (rasterizer->point_smooth) {
242 glhd_warn("Point smoothing requested but ignored");
243 }
244 } else {
245 if (rasterizer->sprite_coord_enable) {
246 glhd_warn("Point sprites requested but ignored");
247 }
248 }
249
250 return pipe->create_rasterizer_state(pipe,
251 rasterizer);
252 }
253
254 static void
255 galahad_context_bind_rasterizer_state(struct pipe_context *_pipe,
256 void *rasterizer)
257 {
258 struct galahad_context *glhd_pipe = galahad_context(_pipe);
259 struct pipe_context *pipe = glhd_pipe->pipe;
260
261 pipe->bind_rasterizer_state(pipe,
262 rasterizer);
263 }
264
265 static void
266 galahad_context_delete_rasterizer_state(struct pipe_context *_pipe,
267 void *rasterizer)
268 {
269 struct galahad_context *glhd_pipe = galahad_context(_pipe);
270 struct pipe_context *pipe = glhd_pipe->pipe;
271
272 pipe->delete_rasterizer_state(pipe,
273 rasterizer);
274 }
275
276 static void *
277 galahad_context_create_depth_stencil_alpha_state(struct pipe_context *_pipe,
278 const struct pipe_depth_stencil_alpha_state *depth_stencil_alpha)
279 {
280 struct galahad_context *glhd_pipe = galahad_context(_pipe);
281 struct pipe_context *pipe = glhd_pipe->pipe;
282
283 return pipe->create_depth_stencil_alpha_state(pipe,
284 depth_stencil_alpha);
285 }
286
287 static void
288 galahad_context_bind_depth_stencil_alpha_state(struct pipe_context *_pipe,
289 void *depth_stencil_alpha)
290 {
291 struct galahad_context *glhd_pipe = galahad_context(_pipe);
292 struct pipe_context *pipe = glhd_pipe->pipe;
293
294 pipe->bind_depth_stencil_alpha_state(pipe,
295 depth_stencil_alpha);
296 }
297
298 static void
299 galahad_context_delete_depth_stencil_alpha_state(struct pipe_context *_pipe,
300 void *depth_stencil_alpha)
301 {
302 struct galahad_context *glhd_pipe = galahad_context(_pipe);
303 struct pipe_context *pipe = glhd_pipe->pipe;
304
305 pipe->delete_depth_stencil_alpha_state(pipe,
306 depth_stencil_alpha);
307 }
308
309 static void *
310 galahad_context_create_fs_state(struct pipe_context *_pipe,
311 const struct pipe_shader_state *fs)
312 {
313 struct galahad_context *glhd_pipe = galahad_context(_pipe);
314 struct pipe_context *pipe = glhd_pipe->pipe;
315
316 return pipe->create_fs_state(pipe,
317 fs);
318 }
319
320 static void
321 galahad_context_bind_fs_state(struct pipe_context *_pipe,
322 void *fs)
323 {
324 struct galahad_context *glhd_pipe = galahad_context(_pipe);
325 struct pipe_context *pipe = glhd_pipe->pipe;
326
327 pipe->bind_fs_state(pipe,
328 fs);
329 }
330
331 static void
332 galahad_context_delete_fs_state(struct pipe_context *_pipe,
333 void *fs)
334 {
335 struct galahad_context *glhd_pipe = galahad_context(_pipe);
336 struct pipe_context *pipe = glhd_pipe->pipe;
337
338 pipe->delete_fs_state(pipe,
339 fs);
340 }
341
342 static void *
343 galahad_context_create_vs_state(struct pipe_context *_pipe,
344 const struct pipe_shader_state *vs)
345 {
346 struct galahad_context *glhd_pipe = galahad_context(_pipe);
347 struct pipe_context *pipe = glhd_pipe->pipe;
348
349 return pipe->create_vs_state(pipe,
350 vs);
351 }
352
353 static void
354 galahad_context_bind_vs_state(struct pipe_context *_pipe,
355 void *vs)
356 {
357 struct galahad_context *glhd_pipe = galahad_context(_pipe);
358 struct pipe_context *pipe = glhd_pipe->pipe;
359
360 pipe->bind_vs_state(pipe,
361 vs);
362 }
363
364 static void
365 galahad_context_delete_vs_state(struct pipe_context *_pipe,
366 void *vs)
367 {
368 struct galahad_context *glhd_pipe = galahad_context(_pipe);
369 struct pipe_context *pipe = glhd_pipe->pipe;
370
371 pipe->delete_vs_state(pipe,
372 vs);
373 }
374
375
376 static void *
377 galahad_context_create_vertex_elements_state(struct pipe_context *_pipe,
378 unsigned num_elements,
379 const struct pipe_vertex_element *vertex_elements)
380 {
381 struct galahad_context *glhd_pipe = galahad_context(_pipe);
382 struct pipe_context *pipe = glhd_pipe->pipe;
383
384 /* XXX check if stride lines up with element size, at least for floats */
385
386 return pipe->create_vertex_elements_state(pipe,
387 num_elements,
388 vertex_elements);
389 }
390
391 static void
392 galahad_context_bind_vertex_elements_state(struct pipe_context *_pipe,
393 void *velems)
394 {
395 struct galahad_context *glhd_pipe = galahad_context(_pipe);
396 struct pipe_context *pipe = glhd_pipe->pipe;
397
398 pipe->bind_vertex_elements_state(pipe,
399 velems);
400 }
401
402 static void
403 galahad_context_delete_vertex_elements_state(struct pipe_context *_pipe,
404 void *velems)
405 {
406 struct galahad_context *glhd_pipe = galahad_context(_pipe);
407 struct pipe_context *pipe = glhd_pipe->pipe;
408
409 pipe->delete_vertex_elements_state(pipe,
410 velems);
411 }
412
413 static void
414 galahad_context_set_blend_color(struct pipe_context *_pipe,
415 const struct pipe_blend_color *blend_color)
416 {
417 struct galahad_context *glhd_pipe = galahad_context(_pipe);
418 struct pipe_context *pipe = glhd_pipe->pipe;
419
420 pipe->set_blend_color(pipe,
421 blend_color);
422 }
423
424 static void
425 galahad_context_set_stencil_ref(struct pipe_context *_pipe,
426 const struct pipe_stencil_ref *stencil_ref)
427 {
428 struct galahad_context *glhd_pipe = galahad_context(_pipe);
429 struct pipe_context *pipe = glhd_pipe->pipe;
430
431 pipe->set_stencil_ref(pipe,
432 stencil_ref);
433 }
434
435 static void
436 galahad_context_set_clip_state(struct pipe_context *_pipe,
437 const struct pipe_clip_state *clip)
438 {
439 struct galahad_context *glhd_pipe = galahad_context(_pipe);
440 struct pipe_context *pipe = glhd_pipe->pipe;
441
442 pipe->set_clip_state(pipe,
443 clip);
444 }
445
446 static void
447 galahad_context_set_sample_mask(struct pipe_context *_pipe,
448 unsigned sample_mask)
449 {
450 struct galahad_context *glhd_pipe = galahad_context(_pipe);
451 struct pipe_context *pipe = glhd_pipe->pipe;
452
453 pipe->set_sample_mask(pipe,
454 sample_mask);
455 }
456
457 static void
458 galahad_context_set_constant_buffer(struct pipe_context *_pipe,
459 uint shader,
460 uint index,
461 struct pipe_constant_buffer *_cb)
462 {
463 struct galahad_context *glhd_pipe = galahad_context(_pipe);
464 struct pipe_context *pipe = glhd_pipe->pipe;
465 struct pipe_constant_buffer cb;
466
467 if (shader >= PIPE_SHADER_TYPES) {
468 glhd_error("Unknown shader type %u", shader);
469 }
470
471 if (index &&
472 index >=
473 pipe->screen->get_shader_param(pipe->screen, shader, PIPE_SHADER_CAP_MAX_CONST_BUFFERS)) {
474 glhd_error("Access to constant buffer %u requested, "
475 "but only %d are supported",
476 index,
477 pipe->screen->get_shader_param(pipe->screen, shader, PIPE_SHADER_CAP_MAX_CONST_BUFFERS));
478 }
479
480 /* XXX hmm? unwrap the input state */
481 if (_cb) {
482 cb = *_cb;
483 cb.buffer = galahad_resource_unwrap(_cb->buffer);
484 }
485
486 pipe->set_constant_buffer(pipe,
487 shader,
488 index,
489 _cb ? &cb : NULL);
490 }
491
492 static void
493 galahad_context_set_framebuffer_state(struct pipe_context *_pipe,
494 const struct pipe_framebuffer_state *_state)
495 {
496 struct galahad_context *glhd_pipe = galahad_context(_pipe);
497 struct pipe_context *pipe = glhd_pipe->pipe;
498 struct pipe_framebuffer_state unwrapped_state;
499 struct pipe_framebuffer_state *state = NULL;
500 unsigned i;
501
502 if (_state->nr_cbufs > PIPE_MAX_COLOR_BUFS) {
503 glhd_error("%d render targets bound, but only %d are permitted by API",
504 _state->nr_cbufs, PIPE_MAX_COLOR_BUFS);
505 } else if (_state->nr_cbufs >
506 pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_RENDER_TARGETS)) {
507 glhd_warn("%d render targets bound, but only %d are supported",
508 _state->nr_cbufs,
509 pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_RENDER_TARGETS));
510 }
511
512 /* unwrap the input state */
513 if (_state) {
514 memcpy(&unwrapped_state, _state, sizeof(unwrapped_state));
515 for(i = 0; i < _state->nr_cbufs; i++)
516 unwrapped_state.cbufs[i] = galahad_surface_unwrap(_state->cbufs[i]);
517 for (; i < PIPE_MAX_COLOR_BUFS; i++)
518 unwrapped_state.cbufs[i] = NULL;
519 unwrapped_state.zsbuf = galahad_surface_unwrap(_state->zsbuf);
520 state = &unwrapped_state;
521 }
522
523 pipe->set_framebuffer_state(pipe,
524 state);
525 }
526
527 static void
528 galahad_context_set_polygon_stipple(struct pipe_context *_pipe,
529 const struct pipe_poly_stipple *poly_stipple)
530 {
531 struct galahad_context *glhd_pipe = galahad_context(_pipe);
532 struct pipe_context *pipe = glhd_pipe->pipe;
533
534 pipe->set_polygon_stipple(pipe,
535 poly_stipple);
536 }
537
538 static void
539 galahad_context_set_scissor_state(struct pipe_context *_pipe,
540 const struct pipe_scissor_state *scissor)
541 {
542 struct galahad_context *glhd_pipe = galahad_context(_pipe);
543 struct pipe_context *pipe = glhd_pipe->pipe;
544
545 pipe->set_scissor_state(pipe,
546 scissor);
547 }
548
549 static void
550 galahad_context_set_viewport_state(struct pipe_context *_pipe,
551 const struct pipe_viewport_state *viewport)
552 {
553 struct galahad_context *glhd_pipe = galahad_context(_pipe);
554 struct pipe_context *pipe = glhd_pipe->pipe;
555
556 pipe->set_viewport_state(pipe,
557 viewport);
558 }
559
560 static void
561 galahad_context_set_fragment_sampler_views(struct pipe_context *_pipe,
562 unsigned num,
563 struct pipe_sampler_view **_views)
564 {
565 struct galahad_context *glhd_pipe = galahad_context(_pipe);
566 struct pipe_context *pipe = glhd_pipe->pipe;
567 struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS];
568 struct pipe_sampler_view **views = NULL;
569 unsigned i;
570
571 if (_views) {
572 for (i = 0; i < num; i++)
573 unwrapped_views[i] = galahad_sampler_view_unwrap(_views[i]);
574 for (; i < PIPE_MAX_SAMPLERS; i++)
575 unwrapped_views[i] = NULL;
576
577 views = unwrapped_views;
578 }
579
580 pipe->set_fragment_sampler_views(pipe, num, views);
581 }
582
583 static void
584 galahad_context_set_vertex_sampler_views(struct pipe_context *_pipe,
585 unsigned num,
586 struct pipe_sampler_view **_views)
587 {
588 struct galahad_context *glhd_pipe = galahad_context(_pipe);
589 struct pipe_context *pipe = glhd_pipe->pipe;
590 struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS];
591 struct pipe_sampler_view **views = NULL;
592 unsigned i;
593
594 if (_views) {
595 for (i = 0; i < num; i++)
596 unwrapped_views[i] = galahad_sampler_view_unwrap(_views[i]);
597 for (; i < Elements(unwrapped_views); i++)
598 unwrapped_views[i] = NULL;
599
600 views = unwrapped_views;
601 }
602
603 pipe->set_vertex_sampler_views(pipe, num, views);
604 }
605
606 static void
607 galahad_context_set_vertex_buffers(struct pipe_context *_pipe,
608 unsigned num_buffers,
609 const struct pipe_vertex_buffer *_buffers)
610 {
611 struct galahad_context *glhd_pipe = galahad_context(_pipe);
612 struct pipe_context *pipe = glhd_pipe->pipe;
613 struct pipe_vertex_buffer unwrapped_buffers[PIPE_MAX_SHADER_INPUTS];
614 struct pipe_vertex_buffer *buffers = NULL;
615 unsigned i;
616
617 if (num_buffers) {
618 memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers));
619 for (i = 0; i < num_buffers; i++)
620 unwrapped_buffers[i].buffer = galahad_resource_unwrap(_buffers[i].buffer);
621 buffers = unwrapped_buffers;
622 }
623
624 pipe->set_vertex_buffers(pipe,
625 num_buffers,
626 buffers);
627 }
628
629 static void
630 galahad_context_set_index_buffer(struct pipe_context *_pipe,
631 const struct pipe_index_buffer *_ib)
632 {
633 struct galahad_context *glhd_pipe = galahad_context(_pipe);
634 struct pipe_context *pipe = glhd_pipe->pipe;
635 struct pipe_index_buffer unwrapped_ib, *ib = NULL;
636
637 if (_ib) {
638 if (_ib->buffer || _ib->user_buffer) {
639 switch (_ib->index_size) {
640 case 1:
641 case 2:
642 case 4:
643 break;
644 default:
645 glhd_warn("unrecognized index size %d", _ib->index_size);
646 break;
647 }
648 }
649 else if (_ib->offset || _ib->index_size) {
650 glhd_warn("non-indexed state with index offset %d and index size %d",
651 _ib->offset, _ib->index_size);
652 }
653
654 unwrapped_ib = *_ib;
655 unwrapped_ib.buffer = galahad_resource_unwrap(_ib->buffer);
656 ib = &unwrapped_ib;
657 }
658
659 pipe->set_index_buffer(pipe, ib);
660 }
661
662 static void
663 galahad_context_resource_copy_region(struct pipe_context *_pipe,
664 struct pipe_resource *_dst,
665 unsigned dst_level,
666 unsigned dstx,
667 unsigned dsty,
668 unsigned dstz,
669 struct pipe_resource *_src,
670 unsigned src_level,
671 const struct pipe_box *src_box)
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 const struct util_format_description *src_desc =
682 util_format_description(_src->format);
683 const struct util_format_description *dst_desc =
684 util_format_description(_dst->format);
685 if (!util_is_format_compatible(src_desc, dst_desc))
686 glhd_warn("Format mismatch: Source is %s, destination is %s",
687 src_desc->short_name,
688 dst_desc->short_name);
689 }
690
691 if ((_src->target == PIPE_BUFFER && _dst->target != PIPE_BUFFER) ||
692 (_src->target != PIPE_BUFFER && _dst->target == PIPE_BUFFER)) {
693 glhd_warn("Resource target mismatch: Source is %i, destination is %i",
694 _src->target, _dst->target);
695 }
696
697 pipe->resource_copy_region(pipe,
698 dst,
699 dst_level,
700 dstx,
701 dsty,
702 dstz,
703 src,
704 src_level,
705 src_box);
706 }
707
708 static void
709 galahad_context_clear(struct pipe_context *_pipe,
710 unsigned buffers,
711 const union pipe_color_union *color,
712 double depth,
713 unsigned stencil)
714 {
715 struct galahad_context *glhd_pipe = galahad_context(_pipe);
716 struct pipe_context *pipe = glhd_pipe->pipe;
717
718 pipe->clear(pipe,
719 buffers,
720 color,
721 depth,
722 stencil);
723 }
724
725 static void
726 galahad_context_clear_render_target(struct pipe_context *_pipe,
727 struct pipe_surface *_dst,
728 const union pipe_color_union *color,
729 unsigned dstx, unsigned dsty,
730 unsigned width, unsigned height)
731 {
732 struct galahad_context *glhd_pipe = galahad_context(_pipe);
733 struct galahad_surface *glhd_surface_dst = galahad_surface(_dst);
734 struct pipe_context *pipe = glhd_pipe->pipe;
735 struct pipe_surface *dst = glhd_surface_dst->surface;
736
737 pipe->clear_render_target(pipe,
738 dst,
739 color,
740 dstx,
741 dsty,
742 width,
743 height);
744 }
745 static void
746 galahad_context_clear_depth_stencil(struct pipe_context *_pipe,
747 struct pipe_surface *_dst,
748 unsigned clear_flags,
749 double depth,
750 unsigned stencil,
751 unsigned dstx, unsigned dsty,
752 unsigned width, unsigned height)
753 {
754 struct galahad_context *glhd_pipe = galahad_context(_pipe);
755 struct galahad_surface *glhd_surface_dst = galahad_surface(_dst);
756 struct pipe_context *pipe = glhd_pipe->pipe;
757 struct pipe_surface *dst = glhd_surface_dst->surface;
758
759 pipe->clear_depth_stencil(pipe,
760 dst,
761 clear_flags,
762 depth,
763 stencil,
764 dstx,
765 dsty,
766 width,
767 height);
768
769 }
770
771 static void
772 galahad_context_flush(struct pipe_context *_pipe,
773 struct pipe_fence_handle **fence)
774 {
775 struct galahad_context *glhd_pipe = galahad_context(_pipe);
776 struct pipe_context *pipe = glhd_pipe->pipe;
777
778 pipe->flush(pipe,
779 fence);
780 }
781
782 static struct pipe_sampler_view *
783 galahad_context_create_sampler_view(struct pipe_context *_pipe,
784 struct pipe_resource *_resource,
785 const struct pipe_sampler_view *templ)
786 {
787 struct galahad_context *glhd_context = galahad_context(_pipe);
788 struct galahad_resource *glhd_resource = galahad_resource(_resource);
789 struct pipe_context *pipe = glhd_context->pipe;
790 struct pipe_resource *resource = glhd_resource->resource;
791 struct pipe_sampler_view *result;
792
793 result = pipe->create_sampler_view(pipe,
794 resource,
795 templ);
796
797 if (result)
798 return galahad_sampler_view_create(glhd_context, glhd_resource, result);
799 return NULL;
800 }
801
802 static void
803 galahad_context_sampler_view_destroy(struct pipe_context *_pipe,
804 struct pipe_sampler_view *_view)
805 {
806 galahad_sampler_view_destroy(galahad_context(_pipe),
807 galahad_sampler_view(_view));
808 }
809
810 static struct pipe_surface *
811 galahad_context_create_surface(struct pipe_context *_pipe,
812 struct pipe_resource *_resource,
813 const struct pipe_surface *templ)
814 {
815 struct galahad_context *glhd_context = galahad_context(_pipe);
816 struct galahad_resource *glhd_resource = galahad_resource(_resource);
817 struct pipe_context *pipe = glhd_context->pipe;
818 struct pipe_resource *resource = glhd_resource->resource;
819 struct pipe_surface *result;
820
821 result = pipe->create_surface(pipe,
822 resource,
823 templ);
824
825 if (result)
826 return galahad_surface_create(glhd_context, glhd_resource, result);
827 return NULL;
828 }
829
830 static void
831 galahad_context_surface_destroy(struct pipe_context *_pipe,
832 struct pipe_surface *_surface)
833 {
834 galahad_surface_destroy(galahad_context(_pipe),
835 galahad_surface(_surface));
836 }
837
838
839
840 static struct pipe_transfer *
841 galahad_context_get_transfer(struct pipe_context *_context,
842 struct pipe_resource *_resource,
843 unsigned level,
844 unsigned usage,
845 const struct pipe_box *box)
846 {
847 struct galahad_context *glhd_context = galahad_context(_context);
848 struct galahad_resource *glhd_resource = galahad_resource(_resource);
849 struct pipe_context *context = glhd_context->pipe;
850 struct pipe_resource *resource = glhd_resource->resource;
851 struct pipe_transfer *result;
852
853 result = context->get_transfer(context,
854 resource,
855 level,
856 usage,
857 box);
858
859 if (result)
860 return galahad_transfer_create(glhd_context, glhd_resource, result);
861 return NULL;
862 }
863
864 static void
865 galahad_context_transfer_destroy(struct pipe_context *_pipe,
866 struct pipe_transfer *_transfer)
867 {
868 galahad_transfer_destroy(galahad_context(_pipe),
869 galahad_transfer(_transfer));
870 }
871
872 static void *
873 galahad_context_transfer_map(struct pipe_context *_context,
874 struct pipe_transfer *_transfer)
875 {
876 struct galahad_context *glhd_context = galahad_context(_context);
877 struct galahad_transfer *glhd_transfer = galahad_transfer(_transfer);
878 struct pipe_context *context = glhd_context->pipe;
879 struct pipe_transfer *transfer = glhd_transfer->transfer;
880
881 struct galahad_resource *glhd_resource = galahad_resource(_transfer->resource);
882
883 glhd_resource->map_count++;
884
885 return context->transfer_map(context,
886 transfer);
887 }
888
889
890
891 static void
892 galahad_context_transfer_flush_region(struct pipe_context *_context,
893 struct pipe_transfer *_transfer,
894 const struct pipe_box *box)
895 {
896 struct galahad_context *glhd_context = galahad_context(_context);
897 struct galahad_transfer *glhd_transfer = galahad_transfer(_transfer);
898 struct pipe_context *context = glhd_context->pipe;
899 struct pipe_transfer *transfer = glhd_transfer->transfer;
900
901 context->transfer_flush_region(context,
902 transfer,
903 box);
904 }
905
906
907 static void
908 galahad_context_transfer_unmap(struct pipe_context *_context,
909 struct pipe_transfer *_transfer)
910 {
911 struct galahad_context *glhd_context = galahad_context(_context);
912 struct galahad_transfer *glhd_transfer = galahad_transfer(_transfer);
913 struct pipe_context *context = glhd_context->pipe;
914 struct pipe_transfer *transfer = glhd_transfer->transfer;
915 struct galahad_resource *glhd_resource = galahad_resource(_transfer->resource);
916
917 if (glhd_resource->map_count < 1) {
918 glhd_warn("context::transfer_unmap() called too many times"
919 " (count = %d)\n", glhd_resource->map_count);
920 }
921
922 glhd_resource->map_count--;
923
924 context->transfer_unmap(context,
925 transfer);
926 }
927
928
929 static void
930 galahad_context_transfer_inline_write(struct pipe_context *_context,
931 struct pipe_resource *_resource,
932 unsigned level,
933 unsigned usage,
934 const struct pipe_box *box,
935 const void *data,
936 unsigned stride,
937 unsigned slice_stride)
938 {
939 struct galahad_context *glhd_context = galahad_context(_context);
940 struct galahad_resource *glhd_resource = galahad_resource(_resource);
941 struct pipe_context *context = glhd_context->pipe;
942 struct pipe_resource *resource = glhd_resource->resource;
943
944 context->transfer_inline_write(context,
945 resource,
946 level,
947 usage,
948 box,
949 data,
950 stride,
951 slice_stride);
952 }
953
954
955 static void
956 galahad_context_render_condition(struct pipe_context *_context,
957 struct pipe_query *query,
958 uint mode)
959 {
960 struct galahad_context *glhd_context = galahad_context(_context);
961 struct pipe_context *context = glhd_context->pipe;
962
963 context->render_condition(context, query, mode);
964 }
965
966
967 struct pipe_context *
968 galahad_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
969 {
970 struct galahad_context *glhd_pipe;
971 (void)galahad_screen(_screen);
972
973 glhd_pipe = CALLOC_STRUCT(galahad_context);
974 if (!glhd_pipe) {
975 return NULL;
976 }
977
978 glhd_pipe->base.screen = _screen;
979 glhd_pipe->base.priv = pipe->priv; /* expose wrapped data */
980 glhd_pipe->base.draw = NULL;
981
982 glhd_pipe->base.destroy = galahad_context_destroy;
983
984 #define GLHD_PIPE_INIT(_member) \
985 glhd_pipe->base . _member = pipe -> _member ? galahad_context_ ## _member : NULL
986
987 GLHD_PIPE_INIT(draw_vbo);
988 GLHD_PIPE_INIT(render_condition);
989 GLHD_PIPE_INIT(create_query);
990 GLHD_PIPE_INIT(destroy_query);
991 GLHD_PIPE_INIT(begin_query);
992 GLHD_PIPE_INIT(end_query);
993 GLHD_PIPE_INIT(get_query_result);
994 GLHD_PIPE_INIT(create_blend_state);
995 GLHD_PIPE_INIT(bind_blend_state);
996 GLHD_PIPE_INIT(delete_blend_state);
997 GLHD_PIPE_INIT(create_sampler_state);
998 GLHD_PIPE_INIT(bind_fragment_sampler_states);
999 GLHD_PIPE_INIT(bind_vertex_sampler_states);
1000 //GLHD_PIPE_INIT(bind_geometry_sampler_states);
1001 //GLHD_PIPE_INIT(bind_compute_sampler_states);
1002 GLHD_PIPE_INIT(delete_sampler_state);
1003 GLHD_PIPE_INIT(create_rasterizer_state);
1004 GLHD_PIPE_INIT(bind_rasterizer_state);
1005 GLHD_PIPE_INIT(delete_rasterizer_state);
1006 GLHD_PIPE_INIT(create_depth_stencil_alpha_state);
1007 GLHD_PIPE_INIT(bind_depth_stencil_alpha_state);
1008 GLHD_PIPE_INIT(delete_depth_stencil_alpha_state);
1009 GLHD_PIPE_INIT(create_fs_state);
1010 GLHD_PIPE_INIT(bind_fs_state);
1011 GLHD_PIPE_INIT(delete_fs_state);
1012 GLHD_PIPE_INIT(create_vs_state);
1013 GLHD_PIPE_INIT(bind_vs_state);
1014 GLHD_PIPE_INIT(delete_vs_state);
1015 //GLHD_PIPE_INIT(create_gs_state);
1016 //GLHD_PIPE_INIT(bind_gs_state);
1017 //GLHD_PIPE_INIT(delete_gs_state);
1018 GLHD_PIPE_INIT(create_vertex_elements_state);
1019 GLHD_PIPE_INIT(bind_vertex_elements_state);
1020 GLHD_PIPE_INIT(delete_vertex_elements_state);
1021 GLHD_PIPE_INIT(set_blend_color);
1022 GLHD_PIPE_INIT(set_stencil_ref);
1023 GLHD_PIPE_INIT(set_sample_mask);
1024 GLHD_PIPE_INIT(set_clip_state);
1025 GLHD_PIPE_INIT(set_constant_buffer);
1026 GLHD_PIPE_INIT(set_framebuffer_state);
1027 GLHD_PIPE_INIT(set_polygon_stipple);
1028 GLHD_PIPE_INIT(set_scissor_state);
1029 GLHD_PIPE_INIT(set_viewport_state);
1030 GLHD_PIPE_INIT(set_fragment_sampler_views);
1031 GLHD_PIPE_INIT(set_vertex_sampler_views);
1032 //GLHD_PIPE_INIT(set_geometry_sampler_views);
1033 //GLHD_PIPE_INIT(set_compute_sampler_views);
1034 //GLHD_PIPE_INIT(set_shader_resources);
1035 GLHD_PIPE_INIT(set_vertex_buffers);
1036 GLHD_PIPE_INIT(set_index_buffer);
1037 //GLHD_PIPE_INIT(create_stream_output_target);
1038 //GLHD_PIPE_INIT(stream_output_target_destroy);
1039 //GLHD_PIPE_INIT(set_stream_output_targets);
1040 GLHD_PIPE_INIT(resource_copy_region);
1041 //GLHD_PIPE_INIT(resource_resolve);
1042 GLHD_PIPE_INIT(clear);
1043 GLHD_PIPE_INIT(clear_render_target);
1044 GLHD_PIPE_INIT(clear_depth_stencil);
1045 GLHD_PIPE_INIT(flush);
1046 GLHD_PIPE_INIT(create_sampler_view);
1047 GLHD_PIPE_INIT(sampler_view_destroy);
1048 GLHD_PIPE_INIT(create_surface);
1049 GLHD_PIPE_INIT(surface_destroy);
1050 GLHD_PIPE_INIT(get_transfer);
1051 GLHD_PIPE_INIT(transfer_destroy);
1052 GLHD_PIPE_INIT(transfer_map);
1053 GLHD_PIPE_INIT(transfer_flush_region);
1054 GLHD_PIPE_INIT(transfer_unmap);
1055 GLHD_PIPE_INIT(transfer_inline_write);
1056 //GLHD_PIPE_INIT(texture_barrier);
1057 //GLHD_PIPE_INIT(create_video_decoder);
1058 //GLHD_PIPE_INIT(create_video_buffer);
1059 //GLHD_PIPE_INIT(create_compute_state);
1060 //GLHD_PIPE_INIT(bind_compute_state);
1061 //GLHD_PIPE_INIT(delete_compute_state);
1062 //GLHD_PIPE_INIT(set_compute_resources);
1063 //GLHD_PIPE_INIT(set_global_binding);
1064 //GLHD_PIPE_INIT(launch_grid);
1065
1066 #undef GLHD_PIPE_INIT
1067
1068 glhd_pipe->pipe = pipe;
1069
1070 return &glhd_pipe->base;
1071 }