1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
30 * Copy/blit pixel rect between surfaces
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"
43 #include "util/u_blit.h"
44 #include "util/u_draw_quad.h"
45 #include "util/u_format.h"
46 #include "util/u_math.h"
47 #include "util/u_memory.h"
48 #include "util/u_sampler.h"
49 #include "util/u_simple_shaders.h"
51 #include "cso_cache/cso_context.h"
56 struct pipe_context
*pipe
;
57 struct cso_context
*cso
;
59 struct pipe_blend_state blend
;
60 struct pipe_depth_stencil_alpha_state depthstencil_keep
;
61 struct pipe_depth_stencil_alpha_state depthstencil_write
;
62 struct pipe_rasterizer_state rasterizer
;
63 struct pipe_sampler_state sampler
;
64 struct pipe_viewport_state viewport
;
65 struct pipe_clip_state clip
;
66 struct pipe_vertex_element velem
[2];
67 enum pipe_texture_target internal_target
;
70 void *fs
[TGSI_WRITEMASK_XYZW
+ 1];
73 struct pipe_resource
*vbuf
; /**< quad vertices */
76 float vertices
[4][2][4]; /**< vertex/texcoords for quad */
81 * Create state object for blit.
82 * Intended to be created once and re-used for many blit() calls.
85 util_create_blit(struct pipe_context
*pipe
, struct cso_context
*cso
)
87 struct blit_state
*ctx
;
90 ctx
= CALLOC_STRUCT(blit_state
);
97 /* disabled blending/masking */
98 memset(&ctx
->blend
, 0, sizeof(ctx
->blend
));
99 ctx
->blend
.rt
[0].colormask
= PIPE_MASK_RGBA
;
101 /* no-op depth/stencil/alpha */
102 memset(&ctx
->depthstencil_keep
, 0, sizeof(ctx
->depthstencil_keep
));
103 memset(&ctx
->depthstencil_write
, 0, sizeof(ctx
->depthstencil_write
));
104 ctx
->depthstencil_write
.depth
.enabled
= 1;
105 ctx
->depthstencil_write
.depth
.writemask
= 1;
106 ctx
->depthstencil_write
.depth
.func
= PIPE_FUNC_ALWAYS
;
109 memset(&ctx
->rasterizer
, 0, sizeof(ctx
->rasterizer
));
110 ctx
->rasterizer
.cull_face
= PIPE_FACE_NONE
;
111 ctx
->rasterizer
.gl_rasterization_rules
= 1;
114 memset(&ctx
->sampler
, 0, sizeof(ctx
->sampler
));
115 ctx
->sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
116 ctx
->sampler
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
117 ctx
->sampler
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
118 ctx
->sampler
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
119 ctx
->sampler
.min_img_filter
= 0; /* set later */
120 ctx
->sampler
.mag_img_filter
= 0; /* set later */
122 /* vertex elements state */
123 memset(&ctx
->velem
[0], 0, sizeof(ctx
->velem
[0]) * 2);
124 for (i
= 0; i
< 2; i
++) {
125 ctx
->velem
[i
].src_offset
= i
* 4 * sizeof(float);
126 ctx
->velem
[i
].instance_divisor
= 0;
127 ctx
->velem
[i
].vertex_buffer_index
= 0;
128 ctx
->velem
[i
].src_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
131 /* vertex shader - still required to provide the linkage between
132 * fragment shader input semantics and vertex_element/buffers.
135 const uint semantic_names
[] = { TGSI_SEMANTIC_POSITION
,
136 TGSI_SEMANTIC_GENERIC
};
137 const uint semantic_indexes
[] = { 0, 0 };
138 ctx
->vs
= util_make_vertex_passthrough_shader(pipe
, 2, semantic_names
,
142 /* fragment shader */
143 ctx
->fs
[TGSI_WRITEMASK_XYZW
] =
144 util_make_fragment_tex_shader(pipe
, TGSI_TEXTURE_2D
,
145 TGSI_INTERPOLATE_LINEAR
);
148 /* init vertex data that doesn't change */
149 for (i
= 0; i
< 4; i
++) {
150 ctx
->vertices
[i
][0][3] = 1.0f
; /* w */
151 ctx
->vertices
[i
][1][2] = 0.0f
; /* r */
152 ctx
->vertices
[i
][1][3] = 1.0f
; /* q */
155 if(pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_NPOT_TEXTURES
))
156 ctx
->internal_target
= PIPE_TEXTURE_2D
;
158 ctx
->internal_target
= PIPE_TEXTURE_RECT
;
165 * Destroy a blit context
168 util_destroy_blit(struct blit_state
*ctx
)
170 struct pipe_context
*pipe
= ctx
->pipe
;
173 pipe
->delete_vs_state(pipe
, ctx
->vs
);
175 for (i
= 0; i
< Elements(ctx
->fs
); i
++)
177 pipe
->delete_fs_state(pipe
, ctx
->fs
[i
]);
180 pipe
->delete_fs_state(pipe
, ctx
->fs_depth
);
182 pipe_resource_reference(&ctx
->vbuf
, NULL
);
189 * Get offset of next free slot in vertex buffer for quad vertices.
192 get_next_slot( struct blit_state
*ctx
)
194 const unsigned max_slots
= 4096 / sizeof ctx
->vertices
;
196 if (ctx
->vbuf_slot
>= max_slots
)
197 util_blit_flush( ctx
);
200 ctx
->vbuf
= pipe_buffer_create(ctx
->pipe
->screen
,
201 PIPE_BIND_VERTEX_BUFFER
,
203 max_slots
* sizeof ctx
->vertices
);
206 return ctx
->vbuf_slot
++ * sizeof ctx
->vertices
;
213 * Setup vertex data for the textured quad we'll draw.
217 setup_vertex_data_tex(struct blit_state
*ctx
,
218 float x0
, float y0
, float x1
, float y1
,
219 float s0
, float t0
, float s1
, float t1
,
224 ctx
->vertices
[0][0][0] = x0
;
225 ctx
->vertices
[0][0][1] = y0
;
226 ctx
->vertices
[0][0][2] = z
;
227 ctx
->vertices
[0][1][0] = s0
; /*s*/
228 ctx
->vertices
[0][1][1] = t0
; /*t*/
230 ctx
->vertices
[1][0][0] = x1
;
231 ctx
->vertices
[1][0][1] = y0
;
232 ctx
->vertices
[1][0][2] = z
;
233 ctx
->vertices
[1][1][0] = s1
; /*s*/
234 ctx
->vertices
[1][1][1] = t0
; /*t*/
236 ctx
->vertices
[2][0][0] = x1
;
237 ctx
->vertices
[2][0][1] = y1
;
238 ctx
->vertices
[2][0][2] = z
;
239 ctx
->vertices
[2][1][0] = s1
;
240 ctx
->vertices
[2][1][1] = t1
;
242 ctx
->vertices
[3][0][0] = x0
;
243 ctx
->vertices
[3][0][1] = y1
;
244 ctx
->vertices
[3][0][2] = z
;
245 ctx
->vertices
[3][1][0] = s0
;
246 ctx
->vertices
[3][1][1] = t1
;
248 offset
= get_next_slot( ctx
);
250 pipe_buffer_write_nooverlap(ctx
->pipe
, ctx
->vbuf
,
251 offset
, sizeof(ctx
->vertices
), ctx
->vertices
);
258 * \return TRUE if two regions overlap, FALSE otherwise
261 regions_overlap(int srcX0
, int srcY0
,
262 int srcX1
, int srcY1
,
263 int dstX0
, int dstY0
,
264 int dstX1
, int dstY1
)
266 if (MAX2(srcX0
, srcX1
) < MIN2(dstX0
, dstX1
))
267 return FALSE
; /* src completely left of dst */
269 if (MAX2(dstX0
, dstX1
) < MIN2(srcX0
, srcX1
))
270 return FALSE
; /* dst completely left of src */
272 if (MAX2(srcY0
, srcY1
) < MIN2(dstY0
, dstY1
))
273 return FALSE
; /* src completely above dst */
275 if (MAX2(dstY0
, dstY1
) < MIN2(srcY0
, srcY1
))
276 return FALSE
; /* dst completely above src */
278 return TRUE
; /* some overlap */
283 * Copy pixel block from src surface to dst surface.
284 * Overlapping regions are acceptable.
285 * Flipping and stretching are supported.
286 * \param filter one of PIPE_TEX_MIPFILTER_NEAREST/LINEAR
287 * \param writemask controls which channels in the dest surface are sourced
288 * from the src surface. Disabled channels are sourced
290 * XXX need some control over blitting stencil.
293 util_blit_pixels_writemask(struct blit_state
*ctx
,
294 struct pipe_resource
*src_tex
,
296 int srcX0
, int srcY0
,
297 int srcX1
, int srcY1
,
299 struct pipe_surface
*dst
,
300 int dstX0
, int dstY0
,
301 int dstX1
, int dstY1
,
302 float z
, uint filter
,
305 struct pipe_context
*pipe
= ctx
->pipe
;
306 struct pipe_screen
*screen
= pipe
->screen
;
307 enum pipe_format src_format
, dst_format
;
308 struct pipe_sampler_view
*sampler_view
= NULL
;
309 struct pipe_sampler_view sv_templ
;
310 struct pipe_surface
*dst_surface
;
311 struct pipe_framebuffer_state fb
;
312 const int srcW
= abs(srcX1
- srcX0
);
313 const int srcH
= abs(srcY1
- srcY0
);
315 boolean overlap
, dst_is_depth
;
316 float s0
, t0
, s1
, t1
;
319 assert(filter
== PIPE_TEX_MIPFILTER_NEAREST
||
320 filter
== PIPE_TEX_MIPFILTER_LINEAR
);
322 assert(src_level
<= src_tex
->last_level
);
324 /* do the regions overlap? */
325 overlap
= src_tex
== dst
->texture
&&
326 dst
->u
.tex
.level
== src_level
&&
327 dst
->u
.tex
.first_layer
== srcZ0
&&
328 regions_overlap(srcX0
, srcY0
, srcX1
, srcY1
,
329 dstX0
, dstY0
, dstX1
, dstY1
);
331 src_format
= util_format_linear(src_tex
->format
);
332 dst_format
= util_format_linear(dst
->format
);
335 * Check for simple case: no format conversion, no flipping, no stretching,
337 * Filter mode should not matter since there's no stretching.
339 if (dst_format
== src_format
&&
344 (dstX1
- dstX0
) == (srcX1
- srcX0
) &&
345 (dstY1
- dstY0
) == (srcY1
- srcY0
) &&
347 struct pipe_box src_box
;
351 src_box
.width
= srcW
;
352 src_box
.height
= srcH
;
354 pipe
->resource_copy_region(pipe
,
355 dst
->texture
, dst
->u
.tex
.level
,
356 dstX0
, dstY0
, dst
->u
.tex
.first_layer
,/* dest */
362 if (dst_format
== dst
->format
) {
365 struct pipe_surface templ
= *dst
;
366 templ
.format
= dst_format
;
367 dst_surface
= pipe
->create_surface(pipe
, dst
->texture
, &templ
);
370 /* Create a temporary texture when src and dest alias or when src
371 * is anything other than a 2d texture.
372 * XXX should just use appropriate shader to access 1d / 3d slice / cube face,
373 * much like the u_blitter code does (should be pretty trivial).
375 * This can still be improved upon.
377 if ((src_tex
== dst_surface
->texture
&&
378 dst_surface
->u
.tex
.level
== src_level
&&
379 dst_surface
->u
.tex
.first_layer
== srcZ0
) ||
380 (src_tex
->target
!= PIPE_TEXTURE_2D
&&
381 src_tex
->target
!= PIPE_TEXTURE_2D
&&
382 src_tex
->target
!= PIPE_TEXTURE_RECT
))
384 struct pipe_resource texTemp
;
385 struct pipe_resource
*tex
;
386 struct pipe_sampler_view sv_templ
;
387 struct pipe_box src_box
;
388 const int srcLeft
= MIN2(srcX0
, srcX1
);
389 const int srcTop
= MIN2(srcY0
, srcY1
);
391 if (srcLeft
!= srcX0
) {
392 /* left-right flip */
398 if (srcTop
!= srcY0
) {
405 /* create temp texture */
406 memset(&texTemp
, 0, sizeof(texTemp
));
407 texTemp
.target
= ctx
->internal_target
;
408 texTemp
.format
= src_format
;
409 texTemp
.last_level
= 0;
410 texTemp
.width0
= srcW
;
411 texTemp
.height0
= srcH
;
413 texTemp
.array_size
= 1;
414 texTemp
.bind
= PIPE_BIND_SAMPLER_VIEW
;
416 tex
= screen
->resource_create(screen
, &texTemp
);
423 src_box
.width
= srcW
;
424 src_box
.height
= srcH
;
426 /* load temp texture */
427 pipe
->resource_copy_region(pipe
,
428 tex
, 0, 0, 0, 0, /* dest */
429 src_tex
, src_level
, &src_box
);
431 normalized
= tex
->target
!= PIPE_TEXTURE_RECT
;
445 u_sampler_view_default_template(&sv_templ
, tex
, tex
->format
);
446 sampler_view
= pipe
->create_sampler_view(pipe
, tex
, &sv_templ
);
449 pipe_resource_reference(&tex
, NULL
);
452 pipe_resource_reference(&tex
, NULL
);
455 u_sampler_view_default_template(&sv_templ
, src_tex
, src_format
);
456 sampler_view
= pipe
->create_sampler_view(pipe
, src_tex
, &sv_templ
);
466 normalized
= sampler_view
->texture
->target
!= PIPE_TEXTURE_RECT
;
469 s0
/= (float)(u_minify(sampler_view
->texture
->width0
, src_level
));
470 s1
/= (float)(u_minify(sampler_view
->texture
->width0
, src_level
));
471 t0
/= (float)(u_minify(sampler_view
->texture
->height0
, src_level
));
472 t1
/= (float)(u_minify(sampler_view
->texture
->height0
, src_level
));
476 dst_is_depth
= util_format_is_depth_or_stencil(dst_format
);
478 assert(screen
->is_format_supported(screen
, sampler_view
->format
, ctx
->internal_target
,
479 sampler_view
->texture
->nr_samples
,
480 PIPE_BIND_SAMPLER_VIEW
));
481 assert(screen
->is_format_supported(screen
, dst_format
, ctx
->internal_target
,
482 dst_surface
->texture
->nr_samples
,
483 dst_is_depth
? PIPE_BIND_DEPTH_STENCIL
:
484 PIPE_BIND_RENDER_TARGET
));
485 /* save state (restored below) */
486 cso_save_blend(ctx
->cso
);
487 cso_save_depth_stencil_alpha(ctx
->cso
);
488 cso_save_rasterizer(ctx
->cso
);
489 cso_save_samplers(ctx
->cso
);
490 cso_save_fragment_sampler_views(ctx
->cso
);
491 cso_save_viewport(ctx
->cso
);
492 cso_save_framebuffer(ctx
->cso
);
493 cso_save_fragment_shader(ctx
->cso
);
494 cso_save_vertex_shader(ctx
->cso
);
495 cso_save_clip(ctx
->cso
);
496 cso_save_vertex_elements(ctx
->cso
);
497 cso_save_vertex_buffers(ctx
->cso
);
499 /* set misc state we care about */
500 cso_set_blend(ctx
->cso
, &ctx
->blend
);
501 cso_set_depth_stencil_alpha(ctx
->cso
,
502 dst_is_depth
? &ctx
->depthstencil_write
:
503 &ctx
->depthstencil_keep
);
504 cso_set_rasterizer(ctx
->cso
, &ctx
->rasterizer
);
505 cso_set_clip(ctx
->cso
, &ctx
->clip
);
506 cso_set_vertex_elements(ctx
->cso
, 2, ctx
->velem
);
509 ctx
->sampler
.normalized_coords
= normalized
;
510 ctx
->sampler
.min_img_filter
= filter
;
511 ctx
->sampler
.mag_img_filter
= filter
;
512 ctx
->sampler
.min_lod
= src_level
;
513 ctx
->sampler
.max_lod
= src_level
;
514 cso_single_sampler(ctx
->cso
, 0, &ctx
->sampler
);
515 cso_single_sampler_done(ctx
->cso
);
518 ctx
->viewport
.scale
[0] = 0.5f
* dst_surface
->width
;
519 ctx
->viewport
.scale
[1] = 0.5f
* dst_surface
->height
;
520 ctx
->viewport
.scale
[2] = 0.5f
;
521 ctx
->viewport
.scale
[3] = 1.0f
;
522 ctx
->viewport
.translate
[0] = 0.5f
* dst_surface
->width
;
523 ctx
->viewport
.translate
[1] = 0.5f
* dst_surface
->height
;
524 ctx
->viewport
.translate
[2] = 0.5f
;
525 ctx
->viewport
.translate
[3] = 0.0f
;
526 cso_set_viewport(ctx
->cso
, &ctx
->viewport
);
529 cso_set_fragment_sampler_views(ctx
->cso
, 1, &sampler_view
);
533 if (ctx
->fs_depth
== NULL
)
535 util_make_fragment_tex_shader_writedepth(pipe
, TGSI_TEXTURE_2D
,
536 TGSI_INTERPOLATE_LINEAR
);
538 cso_set_fragment_shader_handle(ctx
->cso
, ctx
->fs_depth
);
540 if (ctx
->fs
[writemask
] == NULL
)
542 util_make_fragment_tex_shader_writemask(pipe
, TGSI_TEXTURE_2D
,
543 TGSI_INTERPOLATE_LINEAR
,
546 cso_set_fragment_shader_handle(ctx
->cso
, ctx
->fs
[writemask
]);
548 cso_set_vertex_shader_handle(ctx
->cso
, ctx
->vs
);
551 memset(&fb
, 0, sizeof(fb
));
552 fb
.width
= dst_surface
->width
;
553 fb
.height
= dst_surface
->height
;
555 fb
.zsbuf
= dst_surface
;
558 fb
.cbufs
[0] = dst_surface
;
560 cso_set_framebuffer(ctx
->cso
, &fb
);
563 offset
= setup_vertex_data_tex(ctx
,
564 (float) dstX0
/ dst_surface
->width
* 2.0f
- 1.0f
,
565 (float) dstY0
/ dst_surface
->height
* 2.0f
- 1.0f
,
566 (float) dstX1
/ dst_surface
->width
* 2.0f
- 1.0f
,
567 (float) dstY1
/ dst_surface
->height
* 2.0f
- 1.0f
,
572 util_draw_vertex_buffer(ctx
->pipe
, ctx
->cso
, ctx
->vbuf
, offset
,
573 PIPE_PRIM_TRIANGLE_FAN
,
575 2); /* attribs/vert */
577 /* restore state we changed */
578 cso_restore_blend(ctx
->cso
);
579 cso_restore_depth_stencil_alpha(ctx
->cso
);
580 cso_restore_rasterizer(ctx
->cso
);
581 cso_restore_samplers(ctx
->cso
);
582 cso_restore_fragment_sampler_views(ctx
->cso
);
583 cso_restore_viewport(ctx
->cso
);
584 cso_restore_framebuffer(ctx
->cso
);
585 cso_restore_fragment_shader(ctx
->cso
);
586 cso_restore_vertex_shader(ctx
->cso
);
587 cso_restore_clip(ctx
->cso
);
588 cso_restore_vertex_elements(ctx
->cso
);
589 cso_restore_vertex_buffers(ctx
->cso
);
591 pipe_sampler_view_reference(&sampler_view
, NULL
);
592 if (dst_surface
!= dst
)
593 pipe_surface_reference(&dst_surface
, NULL
);
598 util_blit_pixels(struct blit_state
*ctx
,
599 struct pipe_resource
*src_tex
,
601 int srcX0
, int srcY0
,
602 int srcX1
, int srcY1
,
604 struct pipe_surface
*dst
,
605 int dstX0
, int dstY0
,
606 int dstX1
, int dstY1
,
607 float z
, uint filter
)
609 util_blit_pixels_writemask( ctx
, src_tex
,
618 TGSI_WRITEMASK_XYZW
);
622 /* Release vertex buffer at end of frame to avoid synchronous
625 void util_blit_flush( struct blit_state
*ctx
)
627 pipe_resource_reference(&ctx
->vbuf
, NULL
);
634 * Copy pixel block from src texture to dst surface.
636 * XXX Should support selection of level.
637 * XXX need some control over blitting Z and/or stencil.
640 util_blit_pixels_tex(struct blit_state
*ctx
,
641 struct pipe_sampler_view
*src_sampler_view
,
642 int srcX0
, int srcY0
,
643 int srcX1
, int srcY1
,
644 struct pipe_surface
*dst
,
645 int dstX0
, int dstY0
,
646 int dstX1
, int dstY1
,
647 float z
, uint filter
)
649 boolean normalized
= src_sampler_view
->texture
->target
!= PIPE_TEXTURE_RECT
;
650 struct pipe_framebuffer_state fb
;
651 float s0
, t0
, s1
, t1
;
653 struct pipe_resource
*tex
= src_sampler_view
->texture
;
655 assert(filter
== PIPE_TEX_MIPFILTER_NEAREST
||
656 filter
== PIPE_TEX_MIPFILTER_LINEAR
);
659 assert(tex
->width0
!= 0);
660 assert(tex
->height0
!= 0);
669 s0
/= (float)tex
->width0
;
670 s1
/= (float)tex
->width0
;
671 t0
/= (float)tex
->height0
;
672 t1
/= (float)tex
->height0
;
675 assert(ctx
->pipe
->screen
->is_format_supported(ctx
->pipe
->screen
, dst
->format
,
677 dst
->texture
->nr_samples
,
678 PIPE_BIND_RENDER_TARGET
));
680 /* save state (restored below) */
681 cso_save_blend(ctx
->cso
);
682 cso_save_depth_stencil_alpha(ctx
->cso
);
683 cso_save_rasterizer(ctx
->cso
);
684 cso_save_samplers(ctx
->cso
);
685 cso_save_fragment_sampler_views(ctx
->cso
);
686 cso_save_viewport(ctx
->cso
);
687 cso_save_framebuffer(ctx
->cso
);
688 cso_save_fragment_shader(ctx
->cso
);
689 cso_save_vertex_shader(ctx
->cso
);
690 cso_save_clip(ctx
->cso
);
691 cso_save_vertex_elements(ctx
->cso
);
692 cso_save_vertex_buffers(ctx
->cso
);
694 /* set misc state we care about */
695 cso_set_blend(ctx
->cso
, &ctx
->blend
);
696 cso_set_depth_stencil_alpha(ctx
->cso
, &ctx
->depthstencil_keep
);
697 cso_set_rasterizer(ctx
->cso
, &ctx
->rasterizer
);
698 cso_set_clip(ctx
->cso
, &ctx
->clip
);
699 cso_set_vertex_elements(ctx
->cso
, 2, ctx
->velem
);
702 ctx
->sampler
.normalized_coords
= normalized
;
703 ctx
->sampler
.min_img_filter
= filter
;
704 ctx
->sampler
.mag_img_filter
= filter
;
705 cso_single_sampler(ctx
->cso
, 0, &ctx
->sampler
);
706 cso_single_sampler_done(ctx
->cso
);
709 ctx
->viewport
.scale
[0] = 0.5f
* dst
->width
;
710 ctx
->viewport
.scale
[1] = 0.5f
* dst
->height
;
711 ctx
->viewport
.scale
[2] = 0.5f
;
712 ctx
->viewport
.scale
[3] = 1.0f
;
713 ctx
->viewport
.translate
[0] = 0.5f
* dst
->width
;
714 ctx
->viewport
.translate
[1] = 0.5f
* dst
->height
;
715 ctx
->viewport
.translate
[2] = 0.5f
;
716 ctx
->viewport
.translate
[3] = 0.0f
;
717 cso_set_viewport(ctx
->cso
, &ctx
->viewport
);
720 cso_set_fragment_sampler_views(ctx
->cso
, 1, &src_sampler_view
);
723 cso_set_fragment_shader_handle(ctx
->cso
, ctx
->fs
[TGSI_WRITEMASK_XYZW
]);
724 cso_set_vertex_shader_handle(ctx
->cso
, ctx
->vs
);
727 memset(&fb
, 0, sizeof(fb
));
728 fb
.width
= dst
->width
;
729 fb
.height
= dst
->height
;
732 cso_set_framebuffer(ctx
->cso
, &fb
);
735 offset
= setup_vertex_data_tex(ctx
,
736 (float) dstX0
/ dst
->width
* 2.0f
- 1.0f
,
737 (float) dstY0
/ dst
->height
* 2.0f
- 1.0f
,
738 (float) dstX1
/ dst
->width
* 2.0f
- 1.0f
,
739 (float) dstY1
/ dst
->height
* 2.0f
- 1.0f
,
743 util_draw_vertex_buffer(ctx
->pipe
, ctx
->cso
,
745 PIPE_PRIM_TRIANGLE_FAN
,
747 2); /* attribs/vert */
749 /* restore state we changed */
750 cso_restore_blend(ctx
->cso
);
751 cso_restore_depth_stencil_alpha(ctx
->cso
);
752 cso_restore_rasterizer(ctx
->cso
);
753 cso_restore_samplers(ctx
->cso
);
754 cso_restore_fragment_sampler_views(ctx
->cso
);
755 cso_restore_viewport(ctx
->cso
);
756 cso_restore_framebuffer(ctx
->cso
);
757 cso_restore_fragment_shader(ctx
->cso
);
758 cso_restore_vertex_shader(ctx
->cso
);
759 cso_restore_clip(ctx
->cso
);
760 cso_restore_vertex_elements(ctx
->cso
);
761 cso_restore_vertex_buffers(ctx
->cso
);