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