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