gallium: new, unified pipe_context::set_sampler_views() function
[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 unsigned i;
523
524 for (i = 0; i < num; i++)
525 unwrapped_views[i] = galahad_sampler_view_unwrap(_views[i]);
526
527 pipe->set_sampler_views(pipe, shader, start, num, unwrapped_views);
528 }
529
530 static void
531 galahad_context_set_vertex_buffers(struct pipe_context *_pipe,
532 unsigned start_slot, unsigned num_buffers,
533 const struct pipe_vertex_buffer *_buffers)
534 {
535 struct galahad_context *glhd_pipe = galahad_context(_pipe);
536 struct pipe_context *pipe = glhd_pipe->pipe;
537 struct pipe_vertex_buffer unwrapped_buffers[PIPE_MAX_SHADER_INPUTS];
538 struct pipe_vertex_buffer *buffers = NULL;
539 unsigned i;
540
541 if (num_buffers && _buffers) {
542 memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers));
543 for (i = 0; i < num_buffers; i++)
544 unwrapped_buffers[i].buffer = galahad_resource_unwrap(_buffers[i].buffer);
545 buffers = unwrapped_buffers;
546 }
547
548 pipe->set_vertex_buffers(pipe,
549 start_slot, num_buffers,
550 buffers);
551 }
552
553 static void
554 galahad_context_set_index_buffer(struct pipe_context *_pipe,
555 const struct pipe_index_buffer *_ib)
556 {
557 struct galahad_context *glhd_pipe = galahad_context(_pipe);
558 struct pipe_context *pipe = glhd_pipe->pipe;
559 struct pipe_index_buffer unwrapped_ib, *ib = NULL;
560
561 if (_ib) {
562 if (_ib->buffer || _ib->user_buffer) {
563 switch (_ib->index_size) {
564 case 1:
565 case 2:
566 case 4:
567 break;
568 default:
569 glhd_warn("unrecognized index size %d", _ib->index_size);
570 break;
571 }
572 }
573 else if (_ib->offset || _ib->index_size) {
574 glhd_warn("non-indexed state with index offset %d and index size %d",
575 _ib->offset, _ib->index_size);
576 }
577
578 unwrapped_ib = *_ib;
579 unwrapped_ib.buffer = galahad_resource_unwrap(_ib->buffer);
580 ib = &unwrapped_ib;
581 }
582
583 pipe->set_index_buffer(pipe, ib);
584 }
585
586 static INLINE struct pipe_stream_output_target *
587 galahad_context_create_stream_output_target(struct pipe_context *_pipe,
588 struct pipe_resource *_res,
589 unsigned buffer_offset,
590 unsigned buffer_size)
591 {
592 struct galahad_context *glhd_pipe = galahad_context(_pipe);
593 struct galahad_resource *glhd_resource_res = galahad_resource(_res);
594 struct pipe_context *pipe = glhd_pipe->pipe;
595 struct pipe_resource *res = glhd_resource_res->resource;
596
597 return pipe->create_stream_output_target(pipe,
598 res, buffer_offset, buffer_size);
599 }
600
601 static INLINE void
602 galahad_context_stream_output_target_destroy(
603 struct pipe_context *_pipe,
604 struct pipe_stream_output_target *target)
605 {
606 struct galahad_context *glhd_pipe = galahad_context(_pipe);
607 struct pipe_context *pipe = glhd_pipe->pipe;
608
609 pipe->stream_output_target_destroy(pipe, target);
610 }
611
612 static INLINE void
613 galahad_context_set_stream_output_targets(struct pipe_context *_pipe,
614 unsigned num_targets,
615 struct pipe_stream_output_target **tgs,
616 unsigned append_bitmask)
617 {
618 struct galahad_context *glhd_pipe = galahad_context(_pipe);
619 struct pipe_context *pipe = glhd_pipe->pipe;
620
621 pipe->set_stream_output_targets(pipe, num_targets, tgs, append_bitmask);
622 }
623
624 static void
625 galahad_context_resource_copy_region(struct pipe_context *_pipe,
626 struct pipe_resource *_dst,
627 unsigned dst_level,
628 unsigned dstx,
629 unsigned dsty,
630 unsigned dstz,
631 struct pipe_resource *_src,
632 unsigned src_level,
633 const struct pipe_box *src_box)
634 {
635 struct galahad_context *glhd_pipe = galahad_context(_pipe);
636 struct galahad_resource *glhd_resource_dst = galahad_resource(_dst);
637 struct galahad_resource *glhd_resource_src = galahad_resource(_src);
638 struct pipe_context *pipe = glhd_pipe->pipe;
639 struct pipe_resource *dst = glhd_resource_dst->resource;
640 struct pipe_resource *src = glhd_resource_src->resource;
641
642 if (_dst->format != _src->format) {
643 const struct util_format_description *src_desc =
644 util_format_description(_src->format);
645 const struct util_format_description *dst_desc =
646 util_format_description(_dst->format);
647 if (!util_is_format_compatible(src_desc, dst_desc))
648 glhd_warn("Format mismatch: Source is %s, destination is %s",
649 src_desc->short_name,
650 dst_desc->short_name);
651 }
652
653 if ((_src->target == PIPE_BUFFER && _dst->target != PIPE_BUFFER) ||
654 (_src->target != PIPE_BUFFER && _dst->target == PIPE_BUFFER)) {
655 glhd_warn("Resource target mismatch: Source is %i, destination is %i",
656 _src->target, _dst->target);
657 }
658
659 pipe->resource_copy_region(pipe,
660 dst,
661 dst_level,
662 dstx,
663 dsty,
664 dstz,
665 src,
666 src_level,
667 src_box);
668 }
669
670 static void
671 galahad_context_blit(struct pipe_context *_pipe,
672 const struct pipe_blit_info *_info)
673 {
674 struct galahad_context *glhd_pipe = galahad_context(_pipe);
675 struct pipe_context *pipe = glhd_pipe->pipe;
676 struct pipe_blit_info info = *_info;
677
678 info.dst.resource = galahad_resource_unwrap(info.dst.resource);
679 info.src.resource = galahad_resource_unwrap(info.src.resource);
680
681 if (info.dst.box.width < 0 ||
682 info.dst.box.height < 0)
683 glhd_error("Destination dimensions are negative");
684
685 if (info.filter != PIPE_TEX_FILTER_NEAREST &&
686 info.src.resource->target != PIPE_TEXTURE_3D &&
687 info.dst.box.depth != info.src.box.depth)
688 glhd_error("Filtering in z-direction on non-3D texture");
689
690 if (util_format_is_depth_or_stencil(info.dst.format) !=
691 util_format_is_depth_or_stencil(info.src.format))
692 glhd_error("Invalid format conversion: %s <- %s\n",
693 util_format_name(info.dst.format),
694 util_format_name(info.src.format));
695
696 pipe->blit(pipe, &info);
697 }
698
699 static void
700 galahad_context_flush_resource(struct pipe_context *_pipe,
701 struct pipe_resource *_res)
702 {
703 struct galahad_context *glhd_pipe = galahad_context(_pipe);
704 struct galahad_resource *glhd_resource_res = galahad_resource(_res);
705 struct pipe_context *pipe = glhd_pipe->pipe;
706 struct pipe_resource *res = glhd_resource_res->resource;
707
708 pipe->flush_resource(pipe, res);
709 }
710
711 static void
712 galahad_context_clear(struct pipe_context *_pipe,
713 unsigned buffers,
714 const union pipe_color_union *color,
715 double depth,
716 unsigned stencil)
717 {
718 struct galahad_context *glhd_pipe = galahad_context(_pipe);
719 struct pipe_context *pipe = glhd_pipe->pipe;
720
721 pipe->clear(pipe,
722 buffers,
723 color,
724 depth,
725 stencil);
726 }
727
728 static void
729 galahad_context_clear_render_target(struct pipe_context *_pipe,
730 struct pipe_surface *_dst,
731 const union pipe_color_union *color,
732 unsigned dstx, unsigned dsty,
733 unsigned width, unsigned height)
734 {
735 struct galahad_context *glhd_pipe = galahad_context(_pipe);
736 struct galahad_surface *glhd_surface_dst = galahad_surface(_dst);
737 struct pipe_context *pipe = glhd_pipe->pipe;
738 struct pipe_surface *dst = glhd_surface_dst->surface;
739
740 pipe->clear_render_target(pipe,
741 dst,
742 color,
743 dstx,
744 dsty,
745 width,
746 height);
747 }
748 static void
749 galahad_context_clear_depth_stencil(struct pipe_context *_pipe,
750 struct pipe_surface *_dst,
751 unsigned clear_flags,
752 double depth,
753 unsigned stencil,
754 unsigned dstx, unsigned dsty,
755 unsigned width, unsigned height)
756 {
757 struct galahad_context *glhd_pipe = galahad_context(_pipe);
758 struct galahad_surface *glhd_surface_dst = galahad_surface(_dst);
759 struct pipe_context *pipe = glhd_pipe->pipe;
760 struct pipe_surface *dst = glhd_surface_dst->surface;
761
762 pipe->clear_depth_stencil(pipe,
763 dst,
764 clear_flags,
765 depth,
766 stencil,
767 dstx,
768 dsty,
769 width,
770 height);
771
772 }
773
774 static void
775 galahad_context_flush(struct pipe_context *_pipe,
776 struct pipe_fence_handle **fence,
777 unsigned flags)
778 {
779 struct galahad_context *glhd_pipe = galahad_context(_pipe);
780 struct pipe_context *pipe = glhd_pipe->pipe;
781
782 pipe->flush(pipe, fence, flags);
783 }
784
785 static struct pipe_sampler_view *
786 galahad_context_create_sampler_view(struct pipe_context *_pipe,
787 struct pipe_resource *_resource,
788 const struct pipe_sampler_view *templ)
789 {
790 struct galahad_context *glhd_context = galahad_context(_pipe);
791 struct galahad_resource *glhd_resource = galahad_resource(_resource);
792 struct pipe_context *pipe = glhd_context->pipe;
793 struct pipe_resource *resource = glhd_resource->resource;
794 struct pipe_sampler_view *result;
795
796 result = pipe->create_sampler_view(pipe,
797 resource,
798 templ);
799
800 if (result)
801 return galahad_sampler_view_create(glhd_context, glhd_resource, result);
802 return NULL;
803 }
804
805 static void
806 galahad_context_sampler_view_destroy(struct pipe_context *_pipe,
807 struct pipe_sampler_view *_view)
808 {
809 galahad_sampler_view_destroy(galahad_context(_pipe),
810 galahad_sampler_view(_view));
811 }
812
813 static struct pipe_surface *
814 galahad_context_create_surface(struct pipe_context *_pipe,
815 struct pipe_resource *_resource,
816 const struct pipe_surface *templ)
817 {
818 struct galahad_context *glhd_context = galahad_context(_pipe);
819 struct galahad_resource *glhd_resource = galahad_resource(_resource);
820 struct pipe_context *pipe = glhd_context->pipe;
821 struct pipe_resource *resource = glhd_resource->resource;
822 struct pipe_surface *result;
823
824 result = pipe->create_surface(pipe,
825 resource,
826 templ);
827
828 if (result)
829 return galahad_surface_create(glhd_context, glhd_resource, result);
830 return NULL;
831 }
832
833 static void
834 galahad_context_surface_destroy(struct pipe_context *_pipe,
835 struct pipe_surface *_surface)
836 {
837 galahad_surface_destroy(galahad_context(_pipe),
838 galahad_surface(_surface));
839 }
840
841
842 static void *
843 galahad_context_transfer_map(struct pipe_context *_context,
844 struct pipe_resource *_resource,
845 unsigned level,
846 unsigned usage,
847 const struct pipe_box *box,
848 struct pipe_transfer **transfer)
849 {
850 struct galahad_context *glhd_context = galahad_context(_context);
851 struct galahad_resource *glhd_resource = galahad_resource(_resource);
852 struct pipe_context *context = glhd_context->pipe;
853 struct pipe_resource *resource = glhd_resource->resource;
854 struct pipe_transfer *result;
855 void *map;
856
857 map = context->transfer_map(context,
858 resource,
859 level,
860 usage,
861 box, &result);
862 if (!map)
863 return NULL;
864
865 glhd_resource->map_count++;
866
867 *transfer = galahad_transfer_create(glhd_context, glhd_resource, result);
868 return *transfer ? map : NULL;
869 }
870
871 static void
872 galahad_context_transfer_flush_region(struct pipe_context *_context,
873 struct pipe_transfer *_transfer,
874 const struct pipe_box *box)
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 context->transfer_flush_region(context,
882 transfer,
883 box);
884 }
885
886 static void
887 galahad_context_transfer_unmap(struct pipe_context *_context,
888 struct pipe_transfer *_transfer)
889 {
890 struct galahad_context *glhd_context = galahad_context(_context);
891 struct galahad_transfer *glhd_transfer = galahad_transfer(_transfer);
892 struct pipe_context *context = glhd_context->pipe;
893 struct pipe_transfer *transfer = glhd_transfer->transfer;
894 struct galahad_resource *glhd_resource = galahad_resource(_transfer->resource);
895
896 if (glhd_resource->map_count < 1) {
897 glhd_warn("context::transfer_unmap() called too many times"
898 " (count = %d)\n", glhd_resource->map_count);
899 }
900
901 glhd_resource->map_count--;
902
903 context->transfer_unmap(context,
904 transfer);
905
906 galahad_transfer_destroy(galahad_context(_context),
907 galahad_transfer(_transfer));
908 }
909
910
911 static void
912 galahad_context_transfer_inline_write(struct pipe_context *_context,
913 struct pipe_resource *_resource,
914 unsigned level,
915 unsigned usage,
916 const struct pipe_box *box,
917 const void *data,
918 unsigned stride,
919 unsigned slice_stride)
920 {
921 struct galahad_context *glhd_context = galahad_context(_context);
922 struct galahad_resource *glhd_resource = galahad_resource(_resource);
923 struct pipe_context *context = glhd_context->pipe;
924 struct pipe_resource *resource = glhd_resource->resource;
925
926 context->transfer_inline_write(context,
927 resource,
928 level,
929 usage,
930 box,
931 data,
932 stride,
933 slice_stride);
934 }
935
936
937 static void
938 galahad_context_render_condition(struct pipe_context *_context,
939 struct pipe_query *query,
940 boolean condition,
941 uint mode)
942 {
943 struct galahad_context *glhd_context = galahad_context(_context);
944 struct pipe_context *context = glhd_context->pipe;
945
946 context->render_condition(context, query, condition, mode);
947 }
948
949
950 struct pipe_context *
951 galahad_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
952 {
953 struct galahad_context *glhd_pipe;
954 (void)galahad_screen(_screen);
955
956 glhd_pipe = CALLOC_STRUCT(galahad_context);
957 if (!glhd_pipe) {
958 return NULL;
959 }
960
961 glhd_pipe->base.screen = _screen;
962 glhd_pipe->base.priv = pipe->priv; /* expose wrapped data */
963 glhd_pipe->base.draw = NULL;
964
965 glhd_pipe->base.destroy = galahad_context_destroy;
966
967 #define GLHD_PIPE_INIT(_member) \
968 glhd_pipe->base . _member = pipe -> _member ? galahad_context_ ## _member : NULL
969
970 GLHD_PIPE_INIT(draw_vbo);
971 GLHD_PIPE_INIT(render_condition);
972 GLHD_PIPE_INIT(create_query);
973 GLHD_PIPE_INIT(destroy_query);
974 GLHD_PIPE_INIT(begin_query);
975 GLHD_PIPE_INIT(end_query);
976 GLHD_PIPE_INIT(get_query_result);
977 GLHD_PIPE_INIT(create_blend_state);
978 GLHD_PIPE_INIT(bind_blend_state);
979 GLHD_PIPE_INIT(delete_blend_state);
980 GLHD_PIPE_INIT(create_sampler_state);
981 GLHD_PIPE_INIT(bind_sampler_states);
982 GLHD_PIPE_INIT(delete_sampler_state);
983 GLHD_PIPE_INIT(create_rasterizer_state);
984 GLHD_PIPE_INIT(bind_rasterizer_state);
985 GLHD_PIPE_INIT(delete_rasterizer_state);
986 GLHD_PIPE_INIT(create_depth_stencil_alpha_state);
987 GLHD_PIPE_INIT(bind_depth_stencil_alpha_state);
988 GLHD_PIPE_INIT(delete_depth_stencil_alpha_state);
989 GLHD_PIPE_INIT(create_fs_state);
990 GLHD_PIPE_INIT(bind_fs_state);
991 GLHD_PIPE_INIT(delete_fs_state);
992 GLHD_PIPE_INIT(create_vs_state);
993 GLHD_PIPE_INIT(bind_vs_state);
994 GLHD_PIPE_INIT(delete_vs_state);
995 GLHD_PIPE_INIT(create_gs_state);
996 GLHD_PIPE_INIT(bind_gs_state);
997 GLHD_PIPE_INIT(delete_gs_state);
998 GLHD_PIPE_INIT(create_vertex_elements_state);
999 GLHD_PIPE_INIT(bind_vertex_elements_state);
1000 GLHD_PIPE_INIT(delete_vertex_elements_state);
1001 GLHD_PIPE_INIT(set_blend_color);
1002 GLHD_PIPE_INIT(set_stencil_ref);
1003 GLHD_PIPE_INIT(set_sample_mask);
1004 GLHD_PIPE_INIT(set_clip_state);
1005 GLHD_PIPE_INIT(set_constant_buffer);
1006 GLHD_PIPE_INIT(set_framebuffer_state);
1007 GLHD_PIPE_INIT(set_polygon_stipple);
1008 GLHD_PIPE_INIT(set_scissor_states);
1009 GLHD_PIPE_INIT(set_viewport_states);
1010 GLHD_PIPE_INIT(set_sampler_views);
1011 //GLHD_PIPE_INIT(set_shader_resources);
1012 GLHD_PIPE_INIT(set_vertex_buffers);
1013 GLHD_PIPE_INIT(set_index_buffer);
1014 GLHD_PIPE_INIT(create_stream_output_target);
1015 GLHD_PIPE_INIT(stream_output_target_destroy);
1016 GLHD_PIPE_INIT(set_stream_output_targets);
1017 GLHD_PIPE_INIT(resource_copy_region);
1018 GLHD_PIPE_INIT(blit);
1019 GLHD_PIPE_INIT(flush_resource);
1020 GLHD_PIPE_INIT(clear);
1021 GLHD_PIPE_INIT(clear_render_target);
1022 GLHD_PIPE_INIT(clear_depth_stencil);
1023 GLHD_PIPE_INIT(flush);
1024 GLHD_PIPE_INIT(create_sampler_view);
1025 GLHD_PIPE_INIT(sampler_view_destroy);
1026 GLHD_PIPE_INIT(create_surface);
1027 GLHD_PIPE_INIT(surface_destroy);
1028 GLHD_PIPE_INIT(transfer_map);
1029 GLHD_PIPE_INIT(transfer_flush_region);
1030 GLHD_PIPE_INIT(transfer_unmap);
1031 GLHD_PIPE_INIT(transfer_inline_write);
1032 //GLHD_PIPE_INIT(texture_barrier);
1033 //GLHD_PIPE_INIT(create_video_decoder);
1034 //GLHD_PIPE_INIT(create_video_buffer);
1035 //GLHD_PIPE_INIT(create_compute_state);
1036 //GLHD_PIPE_INIT(bind_compute_state);
1037 //GLHD_PIPE_INIT(delete_compute_state);
1038 //GLHD_PIPE_INIT(set_compute_resources);
1039 //GLHD_PIPE_INIT(set_global_binding);
1040 //GLHD_PIPE_INIT(launch_grid);
1041
1042 #undef GLHD_PIPE_INIT
1043
1044 glhd_pipe->pipe = pipe;
1045
1046 return &glhd_pipe->base;
1047 }