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_vertex_element velem
[2];
66 enum pipe_texture_target internal_target
;
69 void *fs
[TGSI_WRITEMASK_XYZW
+ 1];
72 struct pipe_resource
*vbuf
; /**< quad vertices */
75 float vertices
[4][2][4]; /**< vertex/texcoords for quad */
80 * Create state object for blit.
81 * Intended to be created once and re-used for many blit() calls.
84 util_create_blit(struct pipe_context
*pipe
, struct cso_context
*cso
)
86 struct blit_state
*ctx
;
89 ctx
= CALLOC_STRUCT(blit_state
);
96 /* disabled blending/masking */
97 memset(&ctx
->blend
, 0, sizeof(ctx
->blend
));
98 ctx
->blend
.rt
[0].colormask
= PIPE_MASK_RGBA
;
100 /* no-op depth/stencil/alpha */
101 memset(&ctx
->depthstencil_keep
, 0, sizeof(ctx
->depthstencil_keep
));
102 memset(&ctx
->depthstencil_write
, 0, sizeof(ctx
->depthstencil_write
));
103 ctx
->depthstencil_write
.depth
.enabled
= 1;
104 ctx
->depthstencil_write
.depth
.writemask
= 1;
105 ctx
->depthstencil_write
.depth
.func
= PIPE_FUNC_ALWAYS
;
108 memset(&ctx
->rasterizer
, 0, sizeof(ctx
->rasterizer
));
109 ctx
->rasterizer
.cull_face
= PIPE_FACE_NONE
;
110 ctx
->rasterizer
.gl_rasterization_rules
= 1;
111 ctx
->rasterizer
.depth_clip
= 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
;
133 /* init vertex data that doesn't change */
134 for (i
= 0; i
< 4; i
++) {
135 ctx
->vertices
[i
][0][3] = 1.0f
; /* w */
136 ctx
->vertices
[i
][1][2] = 0.0f
; /* r */
137 ctx
->vertices
[i
][1][3] = 1.0f
; /* q */
140 if(pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_NPOT_TEXTURES
))
141 ctx
->internal_target
= PIPE_TEXTURE_2D
;
143 ctx
->internal_target
= PIPE_TEXTURE_RECT
;
150 * Destroy a blit context
153 util_destroy_blit(struct blit_state
*ctx
)
155 struct pipe_context
*pipe
= ctx
->pipe
;
159 pipe
->delete_vs_state(pipe
, ctx
->vs
);
161 for (i
= 0; i
< Elements(ctx
->fs
); i
++)
163 pipe
->delete_fs_state(pipe
, ctx
->fs
[i
]);
166 pipe
->delete_fs_state(pipe
, ctx
->fs_depth
);
168 pipe_resource_reference(&ctx
->vbuf
, NULL
);
175 * Helper function to set the fragment shaders.
178 set_fragment_shader(struct blit_state
*ctx
, uint writemask
)
180 if (!ctx
->fs
[writemask
])
182 util_make_fragment_tex_shader_writemask(ctx
->pipe
, TGSI_TEXTURE_2D
,
183 TGSI_INTERPOLATE_LINEAR
,
186 cso_set_fragment_shader_handle(ctx
->cso
, ctx
->fs
[writemask
]);
191 * Helper function to set the depthwrite shader.
194 set_depth_fragment_shader(struct blit_state
*ctx
)
198 util_make_fragment_tex_shader_writedepth(ctx
->pipe
, TGSI_TEXTURE_2D
,
199 TGSI_INTERPOLATE_LINEAR
);
201 cso_set_fragment_shader_handle(ctx
->cso
, ctx
->fs_depth
);
206 * Helper function to set the vertex shader.
209 set_vertex_shader(struct blit_state
*ctx
)
211 /* vertex shader - still required to provide the linkage between
212 * fragment shader input semantics and vertex_element/buffers.
215 const uint semantic_names
[] = { TGSI_SEMANTIC_POSITION
,
216 TGSI_SEMANTIC_GENERIC
};
217 const uint semantic_indexes
[] = { 0, 0 };
218 ctx
->vs
= util_make_vertex_passthrough_shader(ctx
->pipe
, 2,
223 cso_set_vertex_shader_handle(ctx
->cso
, ctx
->vs
);
228 * Get offset of next free slot in vertex buffer for quad vertices.
231 get_next_slot( struct blit_state
*ctx
)
233 const unsigned max_slots
= 4096 / sizeof ctx
->vertices
;
235 if (ctx
->vbuf_slot
>= max_slots
) {
236 pipe_resource_reference(&ctx
->vbuf
, NULL
);
241 ctx
->vbuf
= pipe_buffer_create(ctx
->pipe
->screen
,
242 PIPE_BIND_VERTEX_BUFFER
,
244 max_slots
* sizeof ctx
->vertices
);
247 return ctx
->vbuf_slot
++ * sizeof ctx
->vertices
;
254 * Setup vertex data for the textured quad we'll draw.
258 setup_vertex_data_tex(struct blit_state
*ctx
,
259 float x0
, float y0
, float x1
, float y1
,
260 float s0
, float t0
, float s1
, float t1
,
265 ctx
->vertices
[0][0][0] = x0
;
266 ctx
->vertices
[0][0][1] = y0
;
267 ctx
->vertices
[0][0][2] = z
;
268 ctx
->vertices
[0][1][0] = s0
; /*s*/
269 ctx
->vertices
[0][1][1] = t0
; /*t*/
271 ctx
->vertices
[1][0][0] = x1
;
272 ctx
->vertices
[1][0][1] = y0
;
273 ctx
->vertices
[1][0][2] = z
;
274 ctx
->vertices
[1][1][0] = s1
; /*s*/
275 ctx
->vertices
[1][1][1] = t0
; /*t*/
277 ctx
->vertices
[2][0][0] = x1
;
278 ctx
->vertices
[2][0][1] = y1
;
279 ctx
->vertices
[2][0][2] = z
;
280 ctx
->vertices
[2][1][0] = s1
;
281 ctx
->vertices
[2][1][1] = t1
;
283 ctx
->vertices
[3][0][0] = x0
;
284 ctx
->vertices
[3][0][1] = y1
;
285 ctx
->vertices
[3][0][2] = z
;
286 ctx
->vertices
[3][1][0] = s0
;
287 ctx
->vertices
[3][1][1] = t1
;
289 offset
= get_next_slot( ctx
);
292 pipe_buffer_write_nooverlap(ctx
->pipe
, ctx
->vbuf
,
293 offset
, sizeof(ctx
->vertices
), ctx
->vertices
);
301 * \return TRUE if two regions overlap, FALSE otherwise
304 regions_overlap(int srcX0
, int srcY0
,
305 int srcX1
, int srcY1
,
306 int dstX0
, int dstY0
,
307 int dstX1
, int dstY1
)
309 if (MAX2(srcX0
, srcX1
) < MIN2(dstX0
, dstX1
))
310 return FALSE
; /* src completely left of dst */
312 if (MAX2(dstX0
, dstX1
) < MIN2(srcX0
, srcX1
))
313 return FALSE
; /* dst completely left of src */
315 if (MAX2(srcY0
, srcY1
) < MIN2(dstY0
, dstY1
))
316 return FALSE
; /* src completely above dst */
318 if (MAX2(dstY0
, dstY1
) < MIN2(srcY0
, srcY1
))
319 return FALSE
; /* dst completely above src */
321 return TRUE
; /* some overlap */
326 * Can we blit from src format to dest format with a simple copy?
329 formats_compatible(enum pipe_format src_format
,
330 enum pipe_format dst_format
)
332 if (src_format
== dst_format
) {
336 const struct util_format_description
*src_desc
=
337 util_format_description(src_format
);
338 const struct util_format_description
*dst_desc
=
339 util_format_description(dst_format
);
340 return util_is_format_compatible(src_desc
, dst_desc
);
346 * Copy pixel block from src surface to dst surface.
347 * Overlapping regions are acceptable.
348 * Flipping and stretching are supported.
349 * \param filter one of PIPE_TEX_MIPFILTER_NEAREST/LINEAR
350 * \param writemask controls which channels in the dest surface are sourced
351 * from the src surface. Disabled channels are sourced
353 * XXX need some control over blitting stencil.
356 util_blit_pixels_writemask(struct blit_state
*ctx
,
357 struct pipe_resource
*src_tex
,
359 int srcX0
, int srcY0
,
360 int srcX1
, int srcY1
,
362 struct pipe_surface
*dst
,
363 int dstX0
, int dstY0
,
364 int dstX1
, int dstY1
,
365 float z
, uint filter
,
368 struct pipe_context
*pipe
= ctx
->pipe
;
369 struct pipe_screen
*screen
= pipe
->screen
;
370 enum pipe_format src_format
, dst_format
;
371 struct pipe_sampler_view
*sampler_view
= NULL
;
372 struct pipe_sampler_view sv_templ
;
373 struct pipe_surface
*dst_surface
;
374 struct pipe_framebuffer_state fb
;
375 const int srcW
= abs(srcX1
- srcX0
);
376 const int srcH
= abs(srcY1
- srcY0
);
378 boolean overlap
, dst_is_depth
;
379 float s0
, t0
, s1
, t1
;
382 assert(filter
== PIPE_TEX_MIPFILTER_NEAREST
||
383 filter
== PIPE_TEX_MIPFILTER_LINEAR
);
385 assert(src_level
<= src_tex
->last_level
);
387 /* do the regions overlap? */
388 overlap
= src_tex
== dst
->texture
&&
389 dst
->u
.tex
.level
== src_level
&&
390 dst
->u
.tex
.first_layer
== srcZ0
&&
391 regions_overlap(srcX0
, srcY0
, srcX1
, srcY1
,
392 dstX0
, dstY0
, dstX1
, dstY1
);
394 src_format
= util_format_linear(src_tex
->format
);
395 dst_format
= util_format_linear(dst
->format
);
398 * Check for simple case: no format conversion, no flipping, no stretching,
400 * Filter mode should not matter since there's no stretching.
402 if (formats_compatible(src_format
, dst_format
) &&
407 (dstX1
- dstX0
) == (srcX1
- srcX0
) &&
408 (dstY1
- dstY0
) == (srcY1
- srcY0
) &&
410 struct pipe_box src_box
;
414 src_box
.width
= srcW
;
415 src_box
.height
= srcH
;
417 pipe
->resource_copy_region(pipe
,
418 dst
->texture
, dst
->u
.tex
.level
,
419 dstX0
, dstY0
, dst
->u
.tex
.first_layer
,/* dest */
425 if (dst_format
== dst
->format
) {
428 struct pipe_surface templ
= *dst
;
429 templ
.format
= dst_format
;
430 dst_surface
= pipe
->create_surface(pipe
, dst
->texture
, &templ
);
433 /* Create a temporary texture when src and dest alias or when src
434 * is anything other than a 2d texture.
435 * XXX should just use appropriate shader to access 1d / 3d slice / cube face,
436 * much like the u_blitter code does (should be pretty trivial).
438 * This can still be improved upon.
440 if ((src_tex
== dst_surface
->texture
&&
441 dst_surface
->u
.tex
.level
== src_level
&&
442 dst_surface
->u
.tex
.first_layer
== srcZ0
) ||
443 (src_tex
->target
!= PIPE_TEXTURE_2D
&&
444 src_tex
->target
!= PIPE_TEXTURE_2D
&&
445 src_tex
->target
!= PIPE_TEXTURE_RECT
))
447 struct pipe_resource texTemp
;
448 struct pipe_resource
*tex
;
449 struct pipe_sampler_view sv_templ
;
450 struct pipe_box src_box
;
451 const int srcLeft
= MIN2(srcX0
, srcX1
);
452 const int srcTop
= MIN2(srcY0
, srcY1
);
454 if (srcLeft
!= srcX0
) {
455 /* left-right flip */
461 if (srcTop
!= srcY0
) {
468 /* create temp texture */
469 memset(&texTemp
, 0, sizeof(texTemp
));
470 texTemp
.target
= ctx
->internal_target
;
471 texTemp
.format
= src_format
;
472 texTemp
.last_level
= 0;
473 texTemp
.width0
= srcW
;
474 texTemp
.height0
= srcH
;
476 texTemp
.array_size
= 1;
477 texTemp
.bind
= PIPE_BIND_SAMPLER_VIEW
;
479 tex
= screen
->resource_create(screen
, &texTemp
);
486 src_box
.width
= srcW
;
487 src_box
.height
= srcH
;
489 /* load temp texture */
490 pipe
->resource_copy_region(pipe
,
491 tex
, 0, 0, 0, 0, /* dest */
492 src_tex
, src_level
, &src_box
);
494 normalized
= tex
->target
!= PIPE_TEXTURE_RECT
;
508 u_sampler_view_default_template(&sv_templ
, tex
, tex
->format
);
509 sampler_view
= pipe
->create_sampler_view(pipe
, tex
, &sv_templ
);
512 pipe_resource_reference(&tex
, NULL
);
515 pipe_resource_reference(&tex
, NULL
);
518 u_sampler_view_default_template(&sv_templ
, src_tex
, src_format
);
519 sampler_view
= pipe
->create_sampler_view(pipe
, src_tex
, &sv_templ
);
529 normalized
= sampler_view
->texture
->target
!= PIPE_TEXTURE_RECT
;
532 s0
/= (float)(u_minify(sampler_view
->texture
->width0
, src_level
));
533 s1
/= (float)(u_minify(sampler_view
->texture
->width0
, src_level
));
534 t0
/= (float)(u_minify(sampler_view
->texture
->height0
, src_level
));
535 t1
/= (float)(u_minify(sampler_view
->texture
->height0
, src_level
));
539 dst_is_depth
= util_format_is_depth_or_stencil(dst_format
);
541 assert(screen
->is_format_supported(screen
, sampler_view
->format
, ctx
->internal_target
,
542 sampler_view
->texture
->nr_samples
,
543 PIPE_BIND_SAMPLER_VIEW
));
544 assert(screen
->is_format_supported(screen
, dst_format
, ctx
->internal_target
,
545 dst_surface
->texture
->nr_samples
,
546 dst_is_depth
? PIPE_BIND_DEPTH_STENCIL
:
547 PIPE_BIND_RENDER_TARGET
));
548 /* save state (restored below) */
549 cso_save_blend(ctx
->cso
);
550 cso_save_depth_stencil_alpha(ctx
->cso
);
551 cso_save_rasterizer(ctx
->cso
);
552 cso_save_samplers(ctx
->cso
);
553 cso_save_fragment_sampler_views(ctx
->cso
);
554 cso_save_stream_outputs(ctx
->cso
);
555 cso_save_viewport(ctx
->cso
);
556 cso_save_framebuffer(ctx
->cso
);
557 cso_save_fragment_shader(ctx
->cso
);
558 cso_save_vertex_shader(ctx
->cso
);
559 cso_save_geometry_shader(ctx
->cso
);
560 cso_save_vertex_elements(ctx
->cso
);
561 cso_save_vertex_buffers(ctx
->cso
);
563 /* set misc state we care about */
564 cso_set_blend(ctx
->cso
, &ctx
->blend
);
565 cso_set_depth_stencil_alpha(ctx
->cso
,
566 dst_is_depth
? &ctx
->depthstencil_write
:
567 &ctx
->depthstencil_keep
);
568 cso_set_rasterizer(ctx
->cso
, &ctx
->rasterizer
);
569 cso_set_vertex_elements(ctx
->cso
, 2, ctx
->velem
);
570 cso_set_stream_outputs(ctx
->cso
, 0, NULL
, 0);
573 ctx
->sampler
.normalized_coords
= normalized
;
574 ctx
->sampler
.min_img_filter
= filter
;
575 ctx
->sampler
.mag_img_filter
= filter
;
576 ctx
->sampler
.min_lod
= src_level
;
577 ctx
->sampler
.max_lod
= src_level
;
578 cso_single_sampler(ctx
->cso
, 0, &ctx
->sampler
);
579 cso_single_sampler_done(ctx
->cso
);
582 ctx
->viewport
.scale
[0] = 0.5f
* dst_surface
->width
;
583 ctx
->viewport
.scale
[1] = 0.5f
* dst_surface
->height
;
584 ctx
->viewport
.scale
[2] = 0.5f
;
585 ctx
->viewport
.scale
[3] = 1.0f
;
586 ctx
->viewport
.translate
[0] = 0.5f
* dst_surface
->width
;
587 ctx
->viewport
.translate
[1] = 0.5f
* dst_surface
->height
;
588 ctx
->viewport
.translate
[2] = 0.5f
;
589 ctx
->viewport
.translate
[3] = 0.0f
;
590 cso_set_viewport(ctx
->cso
, &ctx
->viewport
);
593 cso_set_fragment_sampler_views(ctx
->cso
, 1, &sampler_view
);
597 set_depth_fragment_shader(ctx
);
599 set_fragment_shader(ctx
, writemask
);
601 set_vertex_shader(ctx
);
602 cso_set_geometry_shader_handle(ctx
->cso
, NULL
);
605 memset(&fb
, 0, sizeof(fb
));
606 fb
.width
= dst_surface
->width
;
607 fb
.height
= dst_surface
->height
;
609 fb
.zsbuf
= dst_surface
;
612 fb
.cbufs
[0] = dst_surface
;
614 cso_set_framebuffer(ctx
->cso
, &fb
);
617 offset
= setup_vertex_data_tex(ctx
,
618 (float) dstX0
/ dst_surface
->width
* 2.0f
- 1.0f
,
619 (float) dstY0
/ dst_surface
->height
* 2.0f
- 1.0f
,
620 (float) dstX1
/ dst_surface
->width
* 2.0f
- 1.0f
,
621 (float) dstY1
/ dst_surface
->height
* 2.0f
- 1.0f
,
627 util_draw_vertex_buffer(ctx
->pipe
, ctx
->cso
, ctx
->vbuf
, offset
,
628 PIPE_PRIM_TRIANGLE_FAN
,
630 2); /* attribs/vert */
633 /* restore state we changed */
634 cso_restore_blend(ctx
->cso
);
635 cso_restore_depth_stencil_alpha(ctx
->cso
);
636 cso_restore_rasterizer(ctx
->cso
);
637 cso_restore_samplers(ctx
->cso
);
638 cso_restore_fragment_sampler_views(ctx
->cso
);
639 cso_restore_viewport(ctx
->cso
);
640 cso_restore_framebuffer(ctx
->cso
);
641 cso_restore_fragment_shader(ctx
->cso
);
642 cso_restore_vertex_shader(ctx
->cso
);
643 cso_restore_geometry_shader(ctx
->cso
);
644 cso_restore_vertex_elements(ctx
->cso
);
645 cso_restore_vertex_buffers(ctx
->cso
);
646 cso_restore_stream_outputs(ctx
->cso
);
648 pipe_sampler_view_reference(&sampler_view
, NULL
);
649 if (dst_surface
!= dst
)
650 pipe_surface_reference(&dst_surface
, NULL
);
655 util_blit_pixels(struct blit_state
*ctx
,
656 struct pipe_resource
*src_tex
,
658 int srcX0
, int srcY0
,
659 int srcX1
, int srcY1
,
661 struct pipe_surface
*dst
,
662 int dstX0
, int dstY0
,
663 int dstX1
, int dstY1
,
664 float z
, uint filter
)
666 util_blit_pixels_writemask( ctx
, src_tex
,
675 TGSI_WRITEMASK_XYZW
);
680 * Copy pixel block from src texture to dst surface.
681 * The sampler view's first_level field indicates the source
682 * mipmap level to use.
683 * XXX need some control over blitting Z and/or stencil.
686 util_blit_pixels_tex(struct blit_state
*ctx
,
687 struct pipe_sampler_view
*src_sampler_view
,
688 int srcX0
, int srcY0
,
689 int srcX1
, int srcY1
,
690 struct pipe_surface
*dst
,
691 int dstX0
, int dstY0
,
692 int dstX1
, int dstY1
,
693 float z
, uint filter
)
695 boolean normalized
= src_sampler_view
->texture
->target
!= PIPE_TEXTURE_RECT
;
696 struct pipe_framebuffer_state fb
;
697 float s0
, t0
, s1
, t1
;
699 struct pipe_resource
*tex
= src_sampler_view
->texture
;
701 assert(filter
== PIPE_TEX_MIPFILTER_NEAREST
||
702 filter
== PIPE_TEX_MIPFILTER_LINEAR
);
705 assert(tex
->width0
!= 0);
706 assert(tex
->height0
!= 0);
715 /* normalize according to the mipmap level's size */
716 int level
= src_sampler_view
->u
.tex
.first_level
;
717 float w
= (float) u_minify(tex
->width0
, level
);
718 float h
= (float) u_minify(tex
->height0
, level
);
725 assert(ctx
->pipe
->screen
->is_format_supported(ctx
->pipe
->screen
, dst
->format
,
727 dst
->texture
->nr_samples
,
728 PIPE_BIND_RENDER_TARGET
));
730 /* save state (restored below) */
731 cso_save_blend(ctx
->cso
);
732 cso_save_depth_stencil_alpha(ctx
->cso
);
733 cso_save_rasterizer(ctx
->cso
);
734 cso_save_samplers(ctx
->cso
);
735 cso_save_fragment_sampler_views(ctx
->cso
);
736 cso_save_stream_outputs(ctx
->cso
);
737 cso_save_viewport(ctx
->cso
);
738 cso_save_framebuffer(ctx
->cso
);
739 cso_save_fragment_shader(ctx
->cso
);
740 cso_save_vertex_shader(ctx
->cso
);
741 cso_save_geometry_shader(ctx
->cso
);
742 cso_save_vertex_elements(ctx
->cso
);
743 cso_save_vertex_buffers(ctx
->cso
);
745 /* set misc state we care about */
746 cso_set_blend(ctx
->cso
, &ctx
->blend
);
747 cso_set_depth_stencil_alpha(ctx
->cso
, &ctx
->depthstencil_keep
);
748 cso_set_rasterizer(ctx
->cso
, &ctx
->rasterizer
);
749 cso_set_vertex_elements(ctx
->cso
, 2, ctx
->velem
);
750 cso_set_stream_outputs(ctx
->cso
, 0, NULL
, 0);
753 ctx
->sampler
.normalized_coords
= normalized
;
754 ctx
->sampler
.min_img_filter
= filter
;
755 ctx
->sampler
.mag_img_filter
= filter
;
756 cso_single_sampler(ctx
->cso
, 0, &ctx
->sampler
);
757 cso_single_sampler_done(ctx
->cso
);
760 ctx
->viewport
.scale
[0] = 0.5f
* dst
->width
;
761 ctx
->viewport
.scale
[1] = 0.5f
* dst
->height
;
762 ctx
->viewport
.scale
[2] = 0.5f
;
763 ctx
->viewport
.scale
[3] = 1.0f
;
764 ctx
->viewport
.translate
[0] = 0.5f
* dst
->width
;
765 ctx
->viewport
.translate
[1] = 0.5f
* dst
->height
;
766 ctx
->viewport
.translate
[2] = 0.5f
;
767 ctx
->viewport
.translate
[3] = 0.0f
;
768 cso_set_viewport(ctx
->cso
, &ctx
->viewport
);
771 cso_set_fragment_sampler_views(ctx
->cso
, 1, &src_sampler_view
);
774 set_fragment_shader(ctx
, TGSI_WRITEMASK_XYZW
);
775 set_vertex_shader(ctx
);
776 cso_set_geometry_shader_handle(ctx
->cso
, NULL
);
779 memset(&fb
, 0, sizeof(fb
));
780 fb
.width
= dst
->width
;
781 fb
.height
= dst
->height
;
784 cso_set_framebuffer(ctx
->cso
, &fb
);
787 offset
= setup_vertex_data_tex(ctx
,
788 (float) dstX0
/ dst
->width
* 2.0f
- 1.0f
,
789 (float) dstY0
/ dst
->height
* 2.0f
- 1.0f
,
790 (float) dstX1
/ dst
->width
* 2.0f
- 1.0f
,
791 (float) dstY1
/ dst
->height
* 2.0f
- 1.0f
,
795 util_draw_vertex_buffer(ctx
->pipe
, ctx
->cso
,
797 PIPE_PRIM_TRIANGLE_FAN
,
799 2); /* attribs/vert */
801 /* restore state we changed */
802 cso_restore_blend(ctx
->cso
);
803 cso_restore_depth_stencil_alpha(ctx
->cso
);
804 cso_restore_rasterizer(ctx
->cso
);
805 cso_restore_samplers(ctx
->cso
);
806 cso_restore_fragment_sampler_views(ctx
->cso
);
807 cso_restore_viewport(ctx
->cso
);
808 cso_restore_framebuffer(ctx
->cso
);
809 cso_restore_fragment_shader(ctx
->cso
);
810 cso_restore_vertex_shader(ctx
->cso
);
811 cso_restore_geometry_shader(ctx
->cso
);
812 cso_restore_vertex_elements(ctx
->cso
);
813 cso_restore_vertex_buffers(ctx
->cso
);
814 cso_restore_stream_outputs(ctx
->cso
);