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
,
202 max_slots
* sizeof ctx
->vertices
);
205 return ctx
->vbuf_slot
++ * sizeof ctx
->vertices
;
212 * Setup vertex data for the textured quad we'll draw.
216 setup_vertex_data_tex(struct blit_state
*ctx
,
217 float x0
, float y0
, float x1
, float y1
,
218 float s0
, float t0
, float s1
, float t1
,
223 ctx
->vertices
[0][0][0] = x0
;
224 ctx
->vertices
[0][0][1] = y0
;
225 ctx
->vertices
[0][0][2] = z
;
226 ctx
->vertices
[0][1][0] = s0
; /*s*/
227 ctx
->vertices
[0][1][1] = t0
; /*t*/
229 ctx
->vertices
[1][0][0] = x1
;
230 ctx
->vertices
[1][0][1] = y0
;
231 ctx
->vertices
[1][0][2] = z
;
232 ctx
->vertices
[1][1][0] = s1
; /*s*/
233 ctx
->vertices
[1][1][1] = t0
; /*t*/
235 ctx
->vertices
[2][0][0] = x1
;
236 ctx
->vertices
[2][0][1] = y1
;
237 ctx
->vertices
[2][0][2] = z
;
238 ctx
->vertices
[2][1][0] = s1
;
239 ctx
->vertices
[2][1][1] = t1
;
241 ctx
->vertices
[3][0][0] = x0
;
242 ctx
->vertices
[3][0][1] = y1
;
243 ctx
->vertices
[3][0][2] = z
;
244 ctx
->vertices
[3][1][0] = s0
;
245 ctx
->vertices
[3][1][1] = t1
;
247 offset
= get_next_slot( ctx
);
249 pipe_buffer_write_nooverlap(ctx
->pipe
, ctx
->vbuf
,
250 offset
, sizeof(ctx
->vertices
), ctx
->vertices
);
257 * \return TRUE if two regions overlap, FALSE otherwise
260 regions_overlap(int srcX0
, int srcY0
,
261 int srcX1
, int srcY1
,
262 int dstX0
, int dstY0
,
263 int dstX1
, int dstY1
)
265 if (MAX2(srcX0
, srcX1
) < MIN2(dstX0
, dstX1
))
266 return FALSE
; /* src completely left of dst */
268 if (MAX2(dstX0
, dstX1
) < MIN2(srcX0
, srcX1
))
269 return FALSE
; /* dst completely left of src */
271 if (MAX2(srcY0
, srcY1
) < MIN2(dstY0
, dstY1
))
272 return FALSE
; /* src completely above dst */
274 if (MAX2(dstY0
, dstY1
) < MIN2(srcY0
, srcY1
))
275 return FALSE
; /* dst completely above src */
277 return TRUE
; /* some overlap */
282 * Copy pixel block from src surface to dst surface.
283 * Overlapping regions are acceptable.
284 * Flipping and stretching are supported.
285 * \param filter one of PIPE_TEX_MIPFILTER_NEAREST/LINEAR
286 * \param writemask controls which channels in the dest surface are sourced
287 * from the src surface. Disabled channels are sourced
289 * XXX need some control over blitting stencil.
292 util_blit_pixels_writemask(struct blit_state
*ctx
,
293 struct pipe_resource
*src_tex
,
294 struct pipe_subresource srcsub
,
295 int srcX0
, int srcY0
,
296 int srcX1
, int srcY1
,
298 struct pipe_surface
*dst
,
299 int dstX0
, int dstY0
,
300 int dstX1
, int dstY1
,
301 float z
, uint filter
,
304 struct pipe_context
*pipe
= ctx
->pipe
;
305 struct pipe_screen
*screen
= pipe
->screen
;
306 struct pipe_sampler_view
*sampler_view
= NULL
;
307 struct pipe_sampler_view sv_templ
;
308 struct pipe_framebuffer_state fb
;
309 const int srcW
= abs(srcX1
- srcX0
);
310 const int srcH
= abs(srcY1
- srcY0
);
312 boolean overlap
, dst_is_depth
;
313 float s0
, t0
, s1
, t1
;
316 assert(filter
== PIPE_TEX_MIPFILTER_NEAREST
||
317 filter
== PIPE_TEX_MIPFILTER_LINEAR
);
319 assert(srcsub
.level
<= src_tex
->last_level
);
321 /* do the regions overlap? */
322 overlap
= src_tex
== dst
->texture
&&
323 dst
->face
== srcsub
.face
&&
324 dst
->level
== srcsub
.level
&&
325 dst
->zslice
== srcZ0
&&
326 regions_overlap(srcX0
, srcY0
, srcX1
, srcY1
,
327 dstX0
, dstY0
, dstX1
, dstY1
);
330 * Check for simple case: no format conversion, no flipping, no stretching,
332 * Filter mode should not matter since there's no stretching.
334 if (dst
->format
== src_tex
->format
&&
339 (dstX1
- dstX0
) == (srcX1
- srcX0
) &&
340 (dstY1
- dstY0
) == (srcY1
- srcY0
) &&
342 struct pipe_subresource subdst
;
343 subdst
.face
= dst
->face
;
344 subdst
.level
= dst
->level
;
345 pipe
->resource_copy_region(pipe
,
346 dst
->texture
, subdst
,
347 dstX0
, dstY0
, dst
->zslice
,/* dest */
349 srcX0
, srcY0
, srcZ0
,/* src */
350 srcW
, srcH
); /* size */
354 /* Create a temporary texture when src and dest alias or when src
355 * is anything other than a 2d texture.
356 * XXX should just use appropriate shader to access 1d / 3d slice / cube face,
357 * much like the u_blitter code does (should be pretty trivial).
359 * This can still be improved upon.
361 if ((src_tex
== dst
->texture
&&
362 dst
->face
== srcsub
.face
&&
363 dst
->level
== srcsub
.level
&&
364 dst
->zslice
== srcZ0
) ||
365 (src_tex
->target
!= PIPE_TEXTURE_2D
&&
366 src_tex
->target
!= PIPE_TEXTURE_RECT
))
368 struct pipe_resource texTemp
;
369 struct pipe_resource
*tex
;
370 struct pipe_sampler_view sv_templ
;
371 struct pipe_subresource texsub
;
372 const int srcLeft
= MIN2(srcX0
, srcX1
);
373 const int srcTop
= MIN2(srcY0
, srcY1
);
375 if (srcLeft
!= srcX0
) {
376 /* left-right flip */
382 if (srcTop
!= srcY0
) {
389 /* create temp texture */
390 memset(&texTemp
, 0, sizeof(texTemp
));
391 texTemp
.target
= ctx
->internal_target
;
392 texTemp
.format
= src_tex
->format
;
393 texTemp
.last_level
= 0;
394 texTemp
.width0
= srcW
;
395 texTemp
.height0
= srcH
;
397 texTemp
.bind
= PIPE_BIND_SAMPLER_VIEW
;
399 tex
= screen
->resource_create(screen
, &texTemp
);
405 /* load temp texture */
406 pipe
->resource_copy_region(pipe
,
407 tex
, texsub
, 0, 0, 0, /* dest */
408 src_tex
, srcsub
, srcLeft
, srcTop
, srcZ0
, /* src */
409 srcW
, srcH
); /* size */
411 normalized
= tex
->target
!= PIPE_TEXTURE_RECT
;
425 u_sampler_view_default_template(&sv_templ
, tex
, tex
->format
);
426 sampler_view
= pipe
->create_sampler_view(pipe
, tex
, &sv_templ
);
429 pipe_resource_reference(&tex
, NULL
);
432 pipe_resource_reference(&tex
, NULL
);
435 u_sampler_view_default_template(&sv_templ
, src_tex
, src_tex
->format
);
436 sv_templ
.first_level
= sv_templ
.last_level
= srcsub
.level
;
437 sampler_view
= pipe
->create_sampler_view(pipe
, src_tex
, &sv_templ
);
447 normalized
= sampler_view
->texture
->target
!= PIPE_TEXTURE_RECT
;
450 s0
/= (float)(u_minify(sampler_view
->texture
->width0
, srcsub
.level
));
451 s1
/= (float)(u_minify(sampler_view
->texture
->width0
, srcsub
.level
));
452 t0
/= (float)(u_minify(sampler_view
->texture
->height0
, srcsub
.level
));
453 t1
/= (float)(u_minify(sampler_view
->texture
->height0
, srcsub
.level
));
457 dst_is_depth
= util_format_is_depth_or_stencil(dst
->format
);
459 assert(screen
->is_format_supported(screen
, sampler_view
->format
, ctx
->internal_target
,
460 sampler_view
->texture
->nr_samples
,
461 PIPE_BIND_SAMPLER_VIEW
, 0));
462 assert(screen
->is_format_supported(screen
, dst
->format
, ctx
->internal_target
,
463 dst
->texture
->nr_samples
,
464 dst_is_depth
? PIPE_BIND_DEPTH_STENCIL
:
465 PIPE_BIND_RENDER_TARGET
, 0));
466 /* save state (restored below) */
467 cso_save_blend(ctx
->cso
);
468 cso_save_depth_stencil_alpha(ctx
->cso
);
469 cso_save_rasterizer(ctx
->cso
);
470 cso_save_samplers(ctx
->cso
);
471 cso_save_fragment_sampler_views(ctx
->cso
);
472 cso_save_viewport(ctx
->cso
);
473 cso_save_framebuffer(ctx
->cso
);
474 cso_save_fragment_shader(ctx
->cso
);
475 cso_save_vertex_shader(ctx
->cso
);
476 cso_save_clip(ctx
->cso
);
477 cso_save_vertex_elements(ctx
->cso
);
479 /* set misc state we care about */
480 cso_set_blend(ctx
->cso
, &ctx
->blend
);
481 cso_set_depth_stencil_alpha(ctx
->cso
,
482 dst_is_depth
? &ctx
->depthstencil_write
:
483 &ctx
->depthstencil_keep
);
484 cso_set_rasterizer(ctx
->cso
, &ctx
->rasterizer
);
485 cso_set_clip(ctx
->cso
, &ctx
->clip
);
486 cso_set_vertex_elements(ctx
->cso
, 2, ctx
->velem
);
489 ctx
->sampler
.normalized_coords
= normalized
;
490 ctx
->sampler
.min_img_filter
= filter
;
491 ctx
->sampler
.mag_img_filter
= filter
;
492 /* we've limited this already with the sampler view but you never know... */
493 ctx
->sampler
.min_lod
= srcsub
.level
;
494 ctx
->sampler
.max_lod
= srcsub
.level
;
495 cso_single_sampler(ctx
->cso
, 0, &ctx
->sampler
);
496 cso_single_sampler_done(ctx
->cso
);
499 ctx
->viewport
.scale
[0] = 0.5f
* dst
->width
;
500 ctx
->viewport
.scale
[1] = 0.5f
* dst
->height
;
501 ctx
->viewport
.scale
[2] = 0.5f
;
502 ctx
->viewport
.scale
[3] = 1.0f
;
503 ctx
->viewport
.translate
[0] = 0.5f
* dst
->width
;
504 ctx
->viewport
.translate
[1] = 0.5f
* dst
->height
;
505 ctx
->viewport
.translate
[2] = 0.5f
;
506 ctx
->viewport
.translate
[3] = 0.0f
;
507 cso_set_viewport(ctx
->cso
, &ctx
->viewport
);
510 cso_set_fragment_sampler_views(ctx
->cso
, 1, &sampler_view
);
514 if (ctx
->fs_depth
== NULL
)
516 util_make_fragment_tex_shader_writedepth(pipe
, TGSI_TEXTURE_2D
,
517 TGSI_INTERPOLATE_LINEAR
);
519 cso_set_fragment_shader_handle(ctx
->cso
, ctx
->fs_depth
);
521 if (ctx
->fs
[writemask
] == NULL
)
523 util_make_fragment_tex_shader_writemask(pipe
, TGSI_TEXTURE_2D
,
524 TGSI_INTERPOLATE_LINEAR
,
527 cso_set_fragment_shader_handle(ctx
->cso
, ctx
->fs
[writemask
]);
529 cso_set_vertex_shader_handle(ctx
->cso
, ctx
->vs
);
532 memset(&fb
, 0, sizeof(fb
));
533 fb
.width
= dst
->width
;
534 fb
.height
= dst
->height
;
541 cso_set_framebuffer(ctx
->cso
, &fb
);
544 offset
= setup_vertex_data_tex(ctx
,
545 (float) dstX0
/ dst
->width
* 2.0f
- 1.0f
,
546 (float) dstY0
/ dst
->height
* 2.0f
- 1.0f
,
547 (float) dstX1
/ dst
->width
* 2.0f
- 1.0f
,
548 (float) dstY1
/ dst
->height
* 2.0f
- 1.0f
,
553 util_draw_vertex_buffer(ctx
->pipe
, ctx
->vbuf
, offset
,
554 PIPE_PRIM_TRIANGLE_FAN
,
556 2); /* attribs/vert */
558 /* restore state we changed */
559 cso_restore_blend(ctx
->cso
);
560 cso_restore_depth_stencil_alpha(ctx
->cso
);
561 cso_restore_rasterizer(ctx
->cso
);
562 cso_restore_samplers(ctx
->cso
);
563 cso_restore_fragment_sampler_views(ctx
->cso
);
564 cso_restore_viewport(ctx
->cso
);
565 cso_restore_framebuffer(ctx
->cso
);
566 cso_restore_fragment_shader(ctx
->cso
);
567 cso_restore_vertex_shader(ctx
->cso
);
568 cso_restore_clip(ctx
->cso
);
569 cso_restore_vertex_elements(ctx
->cso
);
571 pipe_sampler_view_reference(&sampler_view
, NULL
);
576 util_blit_pixels(struct blit_state
*ctx
,
577 struct pipe_resource
*src_tex
,
578 struct pipe_subresource srcsub
,
579 int srcX0
, int srcY0
,
580 int srcX1
, int srcY1
,
582 struct pipe_surface
*dst
,
583 int dstX0
, int dstY0
,
584 int dstX1
, int dstY1
,
585 float z
, uint filter
)
587 util_blit_pixels_writemask( ctx
, src_tex
,
596 TGSI_WRITEMASK_XYZW
);
600 /* Release vertex buffer at end of frame to avoid synchronous
603 void util_blit_flush( struct blit_state
*ctx
)
605 pipe_resource_reference(&ctx
->vbuf
, NULL
);
612 * Copy pixel block from src texture to dst surface.
614 * XXX Should support selection of level.
615 * XXX need some control over blitting Z and/or stencil.
618 util_blit_pixels_tex(struct blit_state
*ctx
,
619 struct pipe_sampler_view
*src_sampler_view
,
620 int srcX0
, int srcY0
,
621 int srcX1
, int srcY1
,
622 struct pipe_surface
*dst
,
623 int dstX0
, int dstY0
,
624 int dstX1
, int dstY1
,
625 float z
, uint filter
)
627 boolean normalized
= src_sampler_view
->texture
->target
!= PIPE_TEXTURE_RECT
;
628 struct pipe_framebuffer_state fb
;
629 float s0
, t0
, s1
, t1
;
631 struct pipe_resource
*tex
= src_sampler_view
->texture
;
633 assert(filter
== PIPE_TEX_MIPFILTER_NEAREST
||
634 filter
== PIPE_TEX_MIPFILTER_LINEAR
);
637 assert(tex
->width0
!= 0);
638 assert(tex
->height0
!= 0);
647 s0
/= (float)tex
->width0
;
648 s1
/= (float)tex
->width0
;
649 t0
/= (float)tex
->height0
;
650 t1
/= (float)tex
->height0
;
653 assert(ctx
->pipe
->screen
->is_format_supported(ctx
->pipe
->screen
, dst
->format
,
655 dst
->texture
->nr_samples
,
656 PIPE_BIND_RENDER_TARGET
,
659 /* save state (restored below) */
660 cso_save_blend(ctx
->cso
);
661 cso_save_depth_stencil_alpha(ctx
->cso
);
662 cso_save_rasterizer(ctx
->cso
);
663 cso_save_samplers(ctx
->cso
);
664 cso_save_fragment_sampler_views(ctx
->cso
);
665 cso_save_framebuffer(ctx
->cso
);
666 cso_save_fragment_shader(ctx
->cso
);
667 cso_save_vertex_shader(ctx
->cso
);
668 cso_save_clip(ctx
->cso
);
669 cso_save_vertex_elements(ctx
->cso
);
671 /* set misc state we care about */
672 cso_set_blend(ctx
->cso
, &ctx
->blend
);
673 cso_set_depth_stencil_alpha(ctx
->cso
, &ctx
->depthstencil_keep
);
674 cso_set_rasterizer(ctx
->cso
, &ctx
->rasterizer
);
675 cso_set_clip(ctx
->cso
, &ctx
->clip
);
676 cso_set_vertex_elements(ctx
->cso
, 2, ctx
->velem
);
679 ctx
->sampler
.normalized_coords
= normalized
;
680 ctx
->sampler
.min_img_filter
= filter
;
681 ctx
->sampler
.mag_img_filter
= filter
;
682 cso_single_sampler(ctx
->cso
, 0, &ctx
->sampler
);
683 cso_single_sampler_done(ctx
->cso
);
686 ctx
->viewport
.scale
[0] = 0.5f
* dst
->width
;
687 ctx
->viewport
.scale
[1] = 0.5f
* dst
->height
;
688 ctx
->viewport
.scale
[2] = 0.5f
;
689 ctx
->viewport
.scale
[3] = 1.0f
;
690 ctx
->viewport
.translate
[0] = 0.5f
* dst
->width
;
691 ctx
->viewport
.translate
[1] = 0.5f
* dst
->height
;
692 ctx
->viewport
.translate
[2] = 0.5f
;
693 ctx
->viewport
.translate
[3] = 0.0f
;
694 cso_set_viewport(ctx
->cso
, &ctx
->viewport
);
697 cso_set_fragment_sampler_views(ctx
->cso
, 1, &src_sampler_view
);
700 cso_set_fragment_shader_handle(ctx
->cso
, ctx
->fs
[TGSI_WRITEMASK_XYZW
]);
701 cso_set_vertex_shader_handle(ctx
->cso
, ctx
->vs
);
704 memset(&fb
, 0, sizeof(fb
));
705 fb
.width
= dst
->width
;
706 fb
.height
= dst
->height
;
709 cso_set_framebuffer(ctx
->cso
, &fb
);
712 offset
= setup_vertex_data_tex(ctx
,
713 (float) dstX0
/ dst
->width
* 2.0f
- 1.0f
,
714 (float) dstY0
/ dst
->height
* 2.0f
- 1.0f
,
715 (float) dstX1
/ dst
->width
* 2.0f
- 1.0f
,
716 (float) dstY1
/ dst
->height
* 2.0f
- 1.0f
,
720 util_draw_vertex_buffer(ctx
->pipe
,
722 PIPE_PRIM_TRIANGLE_FAN
,
724 2); /* attribs/vert */
726 /* restore state we changed */
727 cso_restore_blend(ctx
->cso
);
728 cso_restore_depth_stencil_alpha(ctx
->cso
);
729 cso_restore_rasterizer(ctx
->cso
);
730 cso_restore_samplers(ctx
->cso
);
731 cso_restore_fragment_sampler_views(ctx
->cso
);
732 cso_restore_framebuffer(ctx
->cso
);
733 cso_restore_fragment_shader(ctx
->cso
);
734 cso_restore_vertex_shader(ctx
->cso
);
735 cso_restore_clip(ctx
->cso
);
736 cso_restore_vertex_elements(ctx
->cso
);