Merge branch 'gallium-newclear'
[mesa.git] / src / gallium / auxiliary / util / u_blit.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 * @file
30 * Copy/blit pixel rect between surfaces
31 *
32 * @author Brian Paul
33 */
34
35
36 #include "pipe/p_context.h"
37 #include "util/u_debug.h"
38 #include "pipe/p_defines.h"
39 #include "util/u_inlines.h"
40 #include "pipe/p_shader_tokens.h"
41 #include "pipe/p_state.h"
42
43 #include "util/u_blit.h"
44 #include "util/u_draw_quad.h"
45 #include "util/u_math.h"
46 #include "util/u_memory.h"
47 #include "util/u_sampler.h"
48 #include "util/u_simple_shaders.h"
49
50 #include "cso_cache/cso_context.h"
51
52
53 struct blit_state
54 {
55 struct pipe_context *pipe;
56 struct cso_context *cso;
57
58 struct pipe_blend_state blend;
59 struct pipe_depth_stencil_alpha_state depthstencil;
60 struct pipe_rasterizer_state rasterizer;
61 struct pipe_sampler_state sampler;
62 struct pipe_viewport_state viewport;
63 struct pipe_clip_state clip;
64 struct pipe_vertex_element velem[2];
65
66 void *vs;
67 void *fs[TGSI_WRITEMASK_XYZW + 1];
68
69 struct pipe_resource *vbuf; /**< quad vertices */
70 unsigned vbuf_slot;
71
72 float vertices[4][2][4]; /**< vertex/texcoords for quad */
73 };
74
75
76 /**
77 * Create state object for blit.
78 * Intended to be created once and re-used for many blit() calls.
79 */
80 struct blit_state *
81 util_create_blit(struct pipe_context *pipe, struct cso_context *cso)
82 {
83 struct blit_state *ctx;
84 uint i;
85
86 ctx = CALLOC_STRUCT(blit_state);
87 if (!ctx)
88 return NULL;
89
90 ctx->pipe = pipe;
91 ctx->cso = cso;
92
93 /* disabled blending/masking */
94 memset(&ctx->blend, 0, sizeof(ctx->blend));
95 ctx->blend.rt[0].colormask = PIPE_MASK_RGBA;
96
97 /* no-op depth/stencil/alpha */
98 memset(&ctx->depthstencil, 0, sizeof(ctx->depthstencil));
99
100 /* rasterizer */
101 memset(&ctx->rasterizer, 0, sizeof(ctx->rasterizer));
102 ctx->rasterizer.cull_face = PIPE_FACE_NONE;
103 ctx->rasterizer.gl_rasterization_rules = 1;
104
105 /* samplers */
106 memset(&ctx->sampler, 0, sizeof(ctx->sampler));
107 ctx->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
108 ctx->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
109 ctx->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
110 ctx->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
111 ctx->sampler.min_img_filter = 0; /* set later */
112 ctx->sampler.mag_img_filter = 0; /* set later */
113 ctx->sampler.normalized_coords = 1;
114
115 /* vertex elements state */
116 memset(&ctx->velem[0], 0, sizeof(ctx->velem[0]) * 2);
117 for (i = 0; i < 2; i++) {
118 ctx->velem[i].src_offset = i * 4 * sizeof(float);
119 ctx->velem[i].instance_divisor = 0;
120 ctx->velem[i].vertex_buffer_index = 0;
121 ctx->velem[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
122 }
123
124 /* vertex shader - still required to provide the linkage between
125 * fragment shader input semantics and vertex_element/buffers.
126 */
127 {
128 const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
129 TGSI_SEMANTIC_GENERIC };
130 const uint semantic_indexes[] = { 0, 0 };
131 ctx->vs = util_make_vertex_passthrough_shader(pipe, 2, semantic_names,
132 semantic_indexes);
133 }
134
135 /* fragment shader */
136 ctx->fs[TGSI_WRITEMASK_XYZW] =
137 util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D,
138 TGSI_INTERPOLATE_LINEAR);
139 ctx->vbuf = NULL;
140
141 /* init vertex data that doesn't change */
142 for (i = 0; i < 4; i++) {
143 ctx->vertices[i][0][3] = 1.0f; /* w */
144 ctx->vertices[i][1][2] = 0.0f; /* r */
145 ctx->vertices[i][1][3] = 1.0f; /* q */
146 }
147
148 return ctx;
149 }
150
151
152 /**
153 * Destroy a blit context
154 */
155 void
156 util_destroy_blit(struct blit_state *ctx)
157 {
158 struct pipe_context *pipe = ctx->pipe;
159 unsigned i;
160
161 pipe->delete_vs_state(pipe, ctx->vs);
162
163 for (i = 0; i < Elements(ctx->fs); i++)
164 if (ctx->fs[i])
165 pipe->delete_fs_state(pipe, ctx->fs[i]);
166
167 pipe_resource_reference(&ctx->vbuf, NULL);
168
169 FREE(ctx);
170 }
171
172
173 /**
174 * Get offset of next free slot in vertex buffer for quad vertices.
175 */
176 static unsigned
177 get_next_slot( struct blit_state *ctx )
178 {
179 const unsigned max_slots = 4096 / sizeof ctx->vertices;
180
181 if (ctx->vbuf_slot >= max_slots)
182 util_blit_flush( ctx );
183
184 if (!ctx->vbuf) {
185 ctx->vbuf = pipe_buffer_create(ctx->pipe->screen,
186 PIPE_BIND_VERTEX_BUFFER,
187 max_slots * sizeof ctx->vertices);
188 }
189
190 return ctx->vbuf_slot++ * sizeof ctx->vertices;
191 }
192
193
194
195
196 /**
197 * Setup vertex data for the textured quad we'll draw.
198 * Note: y=0=top
199 */
200 static unsigned
201 setup_vertex_data_tex(struct blit_state *ctx,
202 float x0, float y0, float x1, float y1,
203 float s0, float t0, float s1, float t1,
204 float z)
205 {
206 unsigned offset;
207
208 ctx->vertices[0][0][0] = x0;
209 ctx->vertices[0][0][1] = y0;
210 ctx->vertices[0][0][2] = z;
211 ctx->vertices[0][1][0] = s0; /*s*/
212 ctx->vertices[0][1][1] = t0; /*t*/
213
214 ctx->vertices[1][0][0] = x1;
215 ctx->vertices[1][0][1] = y0;
216 ctx->vertices[1][0][2] = z;
217 ctx->vertices[1][1][0] = s1; /*s*/
218 ctx->vertices[1][1][1] = t0; /*t*/
219
220 ctx->vertices[2][0][0] = x1;
221 ctx->vertices[2][0][1] = y1;
222 ctx->vertices[2][0][2] = z;
223 ctx->vertices[2][1][0] = s1;
224 ctx->vertices[2][1][1] = t1;
225
226 ctx->vertices[3][0][0] = x0;
227 ctx->vertices[3][0][1] = y1;
228 ctx->vertices[3][0][2] = z;
229 ctx->vertices[3][1][0] = s0;
230 ctx->vertices[3][1][1] = t1;
231
232 offset = get_next_slot( ctx );
233
234 pipe_buffer_write_nooverlap(ctx->pipe, ctx->vbuf,
235 offset, sizeof(ctx->vertices), ctx->vertices);
236
237 return offset;
238 }
239
240
241 /**
242 * \return TRUE if two regions overlap, FALSE otherwise
243 */
244 static boolean
245 regions_overlap(int srcX0, int srcY0,
246 int srcX1, int srcY1,
247 int dstX0, int dstY0,
248 int dstX1, int dstY1)
249 {
250 if (MAX2(srcX0, srcX1) < MIN2(dstX0, dstX1))
251 return FALSE; /* src completely left of dst */
252
253 if (MAX2(dstX0, dstX1) < MIN2(srcX0, srcX1))
254 return FALSE; /* dst completely left of src */
255
256 if (MAX2(srcY0, srcY1) < MIN2(dstY0, dstY1))
257 return FALSE; /* src completely above dst */
258
259 if (MAX2(dstY0, dstY1) < MIN2(srcY0, srcY1))
260 return FALSE; /* dst completely above src */
261
262 return TRUE; /* some overlap */
263 }
264
265
266 /**
267 * Copy pixel block from src surface to dst surface.
268 * Overlapping regions are acceptable.
269 * Flipping and stretching are supported.
270 * \param filter one of PIPE_TEX_MIPFILTER_NEAREST/LINEAR
271 * \param writemask controls which channels in the dest surface are sourced
272 * from the src surface. Disabled channels are sourced
273 * from (0,0,0,1).
274 * XXX need some control over blitting Z and/or stencil.
275 */
276 void
277 util_blit_pixels_writemask(struct blit_state *ctx,
278 struct pipe_resource *src_tex,
279 struct pipe_subresource srcsub,
280 int srcX0, int srcY0,
281 int srcX1, int srcY1,
282 int srcZ0,
283 struct pipe_surface *dst,
284 int dstX0, int dstY0,
285 int dstX1, int dstY1,
286 float z, uint filter,
287 uint writemask)
288 {
289 struct pipe_context *pipe = ctx->pipe;
290 struct pipe_screen *screen = pipe->screen;
291 struct pipe_sampler_view *sampler_view = NULL;
292 struct pipe_sampler_view sv_templ;
293 struct pipe_framebuffer_state fb;
294 const int srcW = abs(srcX1 - srcX0);
295 const int srcH = abs(srcY1 - srcY0);
296 unsigned offset;
297 boolean overlap;
298 float s0, t0, s1, t1;
299
300 assert(filter == PIPE_TEX_MIPFILTER_NEAREST ||
301 filter == PIPE_TEX_MIPFILTER_LINEAR);
302
303 assert(srcsub.level <= src_tex->last_level);
304
305 /* do the regions overlap? */
306 overlap = src_tex == dst->texture &&
307 dst->face == srcsub.face &&
308 dst->level == srcsub.level &&
309 dst->zslice == srcZ0 &&
310 regions_overlap(srcX0, srcY0, srcX1, srcY1,
311 dstX0, dstY0, dstX1, dstY1);
312
313 /*
314 * Check for simple case: no format conversion, no flipping, no stretching,
315 * no overlapping.
316 * Filter mode should not matter since there's no stretching.
317 */
318 if (dst->format == src_tex->format &&
319 srcX0 < srcX1 &&
320 dstX0 < dstX1 &&
321 srcY0 < srcY1 &&
322 dstY0 < dstY1 &&
323 (dstX1 - dstX0) == (srcX1 - srcX0) &&
324 (dstY1 - dstY0) == (srcY1 - srcY0) &&
325 !overlap) {
326 struct pipe_subresource subdst;
327 subdst.face = dst->face;
328 subdst.level = dst->level;
329 pipe->resource_copy_region(pipe,
330 dst->texture, subdst,
331 dstX0, dstY0, dst->zslice,/* dest */
332 src_tex, srcsub,
333 srcX0, srcY0, srcZ0,/* src */
334 srcW, srcH); /* size */
335 return;
336 }
337
338
339 /* Create a temporary texture when src and dest alias or when src
340 * is anything other than a 2d texture.
341 * XXX should just use appropriate shader to access 1d / 3d slice / cube face,
342 * much like the u_blitter code does (should be pretty trivial).
343 *
344 * This can still be improved upon.
345 */
346 if ((src_tex == dst->texture &&
347 dst->face == srcsub.face &&
348 dst->level == srcsub.level &&
349 dst->zslice == srcZ0) ||
350 src_tex->target != PIPE_TEXTURE_2D)
351 {
352 struct pipe_resource texTemp;
353 struct pipe_resource *tex;
354 struct pipe_sampler_view sv_templ;
355 struct pipe_subresource texsub;
356 const int srcLeft = MIN2(srcX0, srcX1);
357 const int srcTop = MIN2(srcY0, srcY1);
358
359 if (srcLeft != srcX0) {
360 /* left-right flip */
361 int tmp = dstX0;
362 dstX0 = dstX1;
363 dstX1 = tmp;
364 }
365
366 if (srcTop != srcY0) {
367 /* up-down flip */
368 int tmp = dstY0;
369 dstY0 = dstY1;
370 dstY1 = tmp;
371 }
372
373 /* create temp texture */
374 memset(&texTemp, 0, sizeof(texTemp));
375 texTemp.target = PIPE_TEXTURE_2D;
376 texTemp.format = src_tex->format;
377 texTemp.last_level = 0;
378 texTemp.width0 = srcW;
379 texTemp.height0 = srcH;
380 texTemp.depth0 = 1;
381 texTemp.bind = PIPE_BIND_SAMPLER_VIEW;
382
383 tex = screen->resource_create(screen, &texTemp);
384 if (!tex)
385 return;
386
387 texsub.face = 0;
388 texsub.level = 0;
389 /* load temp texture */
390 pipe->resource_copy_region(pipe,
391 tex, texsub, 0, 0, 0, /* dest */
392 src_tex, srcsub, srcLeft, srcTop, srcZ0, /* src */
393 srcW, srcH); /* size */
394
395 s0 = 0.0f;
396 s1 = 1.0f;
397 t0 = 0.0f;
398 t1 = 1.0f;
399
400 u_sampler_view_default_template(&sv_templ, tex, tex->format);
401 sampler_view = pipe->create_sampler_view(pipe, tex, &sv_templ);
402
403 if (!sampler_view) {
404 pipe_resource_reference(&tex, NULL);
405 return;
406 }
407 pipe_resource_reference(&tex, NULL);
408 }
409 else {
410 u_sampler_view_default_template(&sv_templ, src_tex, src_tex->format);
411 sv_templ.first_level = sv_templ.last_level = srcsub.level;
412 sampler_view = pipe->create_sampler_view(pipe, src_tex, &sv_templ);
413
414 if (!sampler_view) {
415 return;
416 }
417
418 s0 = srcX0 / (float)(u_minify(sampler_view->texture->width0, srcsub.level));
419 s1 = srcX1 / (float)(u_minify(sampler_view->texture->width0, srcsub.level));
420 t0 = srcY0 / (float)(u_minify(sampler_view->texture->height0, srcsub.level));
421 t1 = srcY1 / (float)(u_minify(sampler_view->texture->height0, srcsub.level));
422 }
423
424
425 assert(screen->is_format_supported(screen, sampler_view->format, PIPE_TEXTURE_2D,
426 sampler_view->texture->nr_samples,
427 PIPE_BIND_SAMPLER_VIEW, 0));
428 assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D,
429 dst->texture->nr_samples,
430 PIPE_BIND_RENDER_TARGET, 0));
431
432 /* save state (restored below) */
433 cso_save_blend(ctx->cso);
434 cso_save_depth_stencil_alpha(ctx->cso);
435 cso_save_rasterizer(ctx->cso);
436 cso_save_samplers(ctx->cso);
437 cso_save_fragment_sampler_views(ctx->cso);
438 cso_save_viewport(ctx->cso);
439 cso_save_framebuffer(ctx->cso);
440 cso_save_fragment_shader(ctx->cso);
441 cso_save_vertex_shader(ctx->cso);
442 cso_save_clip(ctx->cso);
443 cso_save_vertex_elements(ctx->cso);
444
445 /* set misc state we care about */
446 cso_set_blend(ctx->cso, &ctx->blend);
447 cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil);
448 cso_set_rasterizer(ctx->cso, &ctx->rasterizer);
449 cso_set_clip(ctx->cso, &ctx->clip);
450 cso_set_vertex_elements(ctx->cso, 2, ctx->velem);
451
452 /* sampler */
453 ctx->sampler.min_img_filter = filter;
454 ctx->sampler.mag_img_filter = filter;
455 /* we've limited this already with the sampler view but you never know... */
456 ctx->sampler.min_lod = srcsub.level;
457 ctx->sampler.max_lod = srcsub.level;
458 cso_single_sampler(ctx->cso, 0, &ctx->sampler);
459 cso_single_sampler_done(ctx->cso);
460
461 /* viewport */
462 ctx->viewport.scale[0] = 0.5f * dst->width;
463 ctx->viewport.scale[1] = 0.5f * dst->height;
464 ctx->viewport.scale[2] = 0.5f;
465 ctx->viewport.scale[3] = 1.0f;
466 ctx->viewport.translate[0] = 0.5f * dst->width;
467 ctx->viewport.translate[1] = 0.5f * dst->height;
468 ctx->viewport.translate[2] = 0.5f;
469 ctx->viewport.translate[3] = 0.0f;
470 cso_set_viewport(ctx->cso, &ctx->viewport);
471
472 /* texture */
473 cso_set_fragment_sampler_views(ctx->cso, 1, &sampler_view);
474
475 if (ctx->fs[writemask] == NULL)
476 ctx->fs[writemask] =
477 util_make_fragment_tex_shader_writemask(pipe, TGSI_TEXTURE_2D,
478 TGSI_INTERPOLATE_LINEAR,
479 writemask);
480
481 /* shaders */
482 cso_set_fragment_shader_handle(ctx->cso, ctx->fs[writemask]);
483 cso_set_vertex_shader_handle(ctx->cso, ctx->vs);
484
485 /* drawing dest */
486 memset(&fb, 0, sizeof(fb));
487 fb.width = dst->width;
488 fb.height = dst->height;
489 fb.nr_cbufs = 1;
490 fb.cbufs[0] = dst;
491 cso_set_framebuffer(ctx->cso, &fb);
492
493 /* draw quad */
494 offset = setup_vertex_data_tex(ctx,
495 (float) dstX0 / dst->width * 2.0f - 1.0f,
496 (float) dstY0 / dst->height * 2.0f - 1.0f,
497 (float) dstX1 / dst->width * 2.0f - 1.0f,
498 (float) dstY1 / dst->height * 2.0f - 1.0f,
499 s0, t0,
500 s1, t1,
501 z);
502
503 util_draw_vertex_buffer(ctx->pipe, ctx->vbuf, offset,
504 PIPE_PRIM_TRIANGLE_FAN,
505 4, /* verts */
506 2); /* attribs/vert */
507
508 /* restore state we changed */
509 cso_restore_blend(ctx->cso);
510 cso_restore_depth_stencil_alpha(ctx->cso);
511 cso_restore_rasterizer(ctx->cso);
512 cso_restore_samplers(ctx->cso);
513 cso_restore_fragment_sampler_views(ctx->cso);
514 cso_restore_viewport(ctx->cso);
515 cso_restore_framebuffer(ctx->cso);
516 cso_restore_fragment_shader(ctx->cso);
517 cso_restore_vertex_shader(ctx->cso);
518 cso_restore_clip(ctx->cso);
519 cso_restore_vertex_elements(ctx->cso);
520
521 pipe_sampler_view_reference(&sampler_view, NULL);
522 }
523
524
525 void
526 util_blit_pixels(struct blit_state *ctx,
527 struct pipe_resource *src_tex,
528 struct pipe_subresource srcsub,
529 int srcX0, int srcY0,
530 int srcX1, int srcY1,
531 int srcZ,
532 struct pipe_surface *dst,
533 int dstX0, int dstY0,
534 int dstX1, int dstY1,
535 float z, uint filter )
536 {
537 util_blit_pixels_writemask( ctx, src_tex,
538 srcsub,
539 srcX0, srcY0,
540 srcX1, srcY1,
541 srcZ,
542 dst,
543 dstX0, dstY0,
544 dstX1, dstY1,
545 z, filter,
546 TGSI_WRITEMASK_XYZW );
547 }
548
549
550 /* Release vertex buffer at end of frame to avoid synchronous
551 * rendering.
552 */
553 void util_blit_flush( struct blit_state *ctx )
554 {
555 pipe_resource_reference(&ctx->vbuf, NULL);
556 ctx->vbuf_slot = 0;
557 }
558
559
560
561 /**
562 * Copy pixel block from src texture to dst surface.
563 *
564 * XXX Should support selection of level.
565 * XXX need some control over blitting Z and/or stencil.
566 */
567 void
568 util_blit_pixels_tex(struct blit_state *ctx,
569 struct pipe_sampler_view *src_sampler_view,
570 int srcX0, int srcY0,
571 int srcX1, int srcY1,
572 struct pipe_surface *dst,
573 int dstX0, int dstY0,
574 int dstX1, int dstY1,
575 float z, uint filter)
576 {
577 struct pipe_framebuffer_state fb;
578 float s0, t0, s1, t1;
579 unsigned offset;
580 struct pipe_resource *tex = src_sampler_view->texture;
581
582 assert(filter == PIPE_TEX_MIPFILTER_NEAREST ||
583 filter == PIPE_TEX_MIPFILTER_LINEAR);
584
585 assert(tex);
586 assert(tex->width0 != 0);
587 assert(tex->height0 != 0);
588
589 s0 = srcX0 / (float)tex->width0;
590 s1 = srcX1 / (float)tex->width0;
591 t0 = srcY0 / (float)tex->height0;
592 t1 = srcY1 / (float)tex->height0;
593
594 assert(ctx->pipe->screen->is_format_supported(ctx->pipe->screen, dst->format,
595 PIPE_TEXTURE_2D,
596 dst->texture->nr_samples,
597 PIPE_BIND_RENDER_TARGET,
598 0));
599
600 /* save state (restored below) */
601 cso_save_blend(ctx->cso);
602 cso_save_depth_stencil_alpha(ctx->cso);
603 cso_save_rasterizer(ctx->cso);
604 cso_save_samplers(ctx->cso);
605 cso_save_fragment_sampler_views(ctx->cso);
606 cso_save_framebuffer(ctx->cso);
607 cso_save_fragment_shader(ctx->cso);
608 cso_save_vertex_shader(ctx->cso);
609 cso_save_clip(ctx->cso);
610 cso_save_vertex_elements(ctx->cso);
611
612 /* set misc state we care about */
613 cso_set_blend(ctx->cso, &ctx->blend);
614 cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil);
615 cso_set_rasterizer(ctx->cso, &ctx->rasterizer);
616 cso_set_clip(ctx->cso, &ctx->clip);
617 cso_set_vertex_elements(ctx->cso, 2, ctx->velem);
618
619 /* sampler */
620 ctx->sampler.min_img_filter = filter;
621 ctx->sampler.mag_img_filter = filter;
622 cso_single_sampler(ctx->cso, 0, &ctx->sampler);
623 cso_single_sampler_done(ctx->cso);
624
625 /* viewport */
626 ctx->viewport.scale[0] = 0.5f * dst->width;
627 ctx->viewport.scale[1] = 0.5f * dst->height;
628 ctx->viewport.scale[2] = 0.5f;
629 ctx->viewport.scale[3] = 1.0f;
630 ctx->viewport.translate[0] = 0.5f * dst->width;
631 ctx->viewport.translate[1] = 0.5f * dst->height;
632 ctx->viewport.translate[2] = 0.5f;
633 ctx->viewport.translate[3] = 0.0f;
634 cso_set_viewport(ctx->cso, &ctx->viewport);
635
636 /* texture */
637 cso_set_fragment_sampler_views(ctx->cso, 1, &src_sampler_view);
638
639 /* shaders */
640 cso_set_fragment_shader_handle(ctx->cso, ctx->fs[TGSI_WRITEMASK_XYZW]);
641 cso_set_vertex_shader_handle(ctx->cso, ctx->vs);
642
643 /* drawing dest */
644 memset(&fb, 0, sizeof(fb));
645 fb.width = dst->width;
646 fb.height = dst->height;
647 fb.nr_cbufs = 1;
648 fb.cbufs[0] = dst;
649 cso_set_framebuffer(ctx->cso, &fb);
650
651 /* draw quad */
652 offset = setup_vertex_data_tex(ctx,
653 (float) dstX0 / dst->width * 2.0f - 1.0f,
654 (float) dstY0 / dst->height * 2.0f - 1.0f,
655 (float) dstX1 / dst->width * 2.0f - 1.0f,
656 (float) dstY1 / dst->height * 2.0f - 1.0f,
657 s0, t0, s1, t1,
658 z);
659
660 util_draw_vertex_buffer(ctx->pipe,
661 ctx->vbuf, offset,
662 PIPE_PRIM_TRIANGLE_FAN,
663 4, /* verts */
664 2); /* attribs/vert */
665
666 /* restore state we changed */
667 cso_restore_blend(ctx->cso);
668 cso_restore_depth_stencil_alpha(ctx->cso);
669 cso_restore_rasterizer(ctx->cso);
670 cso_restore_samplers(ctx->cso);
671 cso_restore_fragment_sampler_views(ctx->cso);
672 cso_restore_framebuffer(ctx->cso);
673 cso_restore_fragment_shader(ctx->cso);
674 cso_restore_vertex_shader(ctx->cso);
675 cso_restore_clip(ctx->cso);
676 cso_restore_vertex_elements(ctx->cso);
677 }