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_write_color
, blend_keep_color
;
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
[PIPE_MAX_TEXTURE_TYPES
][TGSI_WRITEMASK_XYZW
+ 1];
70 void *fs_depth
[PIPE_MAX_TEXTURE_TYPES
];
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 ctx
->blend_write_color
.rt
[0].colormask
= PIPE_MASK_RGBA
;
99 /* no-op depth/stencil/alpha */
100 ctx
->depthstencil_write
.depth
.enabled
= 1;
101 ctx
->depthstencil_write
.depth
.writemask
= 1;
102 ctx
->depthstencil_write
.depth
.func
= PIPE_FUNC_ALWAYS
;
105 ctx
->rasterizer
.cull_face
= PIPE_FACE_NONE
;
106 ctx
->rasterizer
.gl_rasterization_rules
= 1;
107 ctx
->rasterizer
.depth_clip
= 1;
110 ctx
->sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
111 ctx
->sampler
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
112 ctx
->sampler
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
113 ctx
->sampler
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
114 ctx
->sampler
.min_img_filter
= 0; /* set later */
115 ctx
->sampler
.mag_img_filter
= 0; /* set later */
117 /* vertex elements state */
118 for (i
= 0; i
< 2; i
++) {
119 ctx
->velem
[i
].src_offset
= i
* 4 * sizeof(float);
120 ctx
->velem
[i
].instance_divisor
= 0;
121 ctx
->velem
[i
].vertex_buffer_index
= 0;
122 ctx
->velem
[i
].src_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
127 /* init vertex data that doesn't change */
128 for (i
= 0; i
< 4; i
++) {
129 ctx
->vertices
[i
][0][3] = 1.0f
; /* w */
130 ctx
->vertices
[i
][1][2] = 0.0f
; /* r */
131 ctx
->vertices
[i
][1][3] = 1.0f
; /* q */
134 if(pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_NPOT_TEXTURES
))
135 ctx
->internal_target
= PIPE_TEXTURE_2D
;
137 ctx
->internal_target
= PIPE_TEXTURE_RECT
;
144 * Destroy a blit context
147 util_destroy_blit(struct blit_state
*ctx
)
149 struct pipe_context
*pipe
= ctx
->pipe
;
153 pipe
->delete_vs_state(pipe
, ctx
->vs
);
155 for (i
= 0; i
< Elements(ctx
->fs
); i
++) {
156 for (j
= 0; j
< Elements(ctx
->fs
[i
]); j
++) {
158 pipe
->delete_fs_state(pipe
, ctx
->fs
[i
][j
]);
162 for (i
= 0; i
< Elements(ctx
->fs_depth
); i
++) {
163 if (ctx
->fs_depth
[i
]) {
164 pipe
->delete_fs_state(pipe
, ctx
->fs_depth
[i
]);
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
,
179 enum pipe_texture_target pipe_tex
)
181 if (!ctx
->fs
[pipe_tex
][writemask
]) {
182 unsigned tgsi_tex
= util_pipe_tex_to_tgsi_tex(pipe_tex
);
184 ctx
->fs
[pipe_tex
][writemask
] =
185 util_make_fragment_tex_shader_writemask(ctx
->pipe
, tgsi_tex
,
186 TGSI_INTERPOLATE_LINEAR
,
190 cso_set_fragment_shader_handle(ctx
->cso
, ctx
->fs
[pipe_tex
][writemask
]);
195 * Helper function to set the depthwrite shader.
198 set_depth_fragment_shader(struct blit_state
*ctx
,
199 enum pipe_texture_target pipe_tex
)
201 if (!ctx
->fs_depth
[pipe_tex
]) {
202 unsigned tgsi_tex
= util_pipe_tex_to_tgsi_tex(pipe_tex
);
204 ctx
->fs_depth
[pipe_tex
] =
205 util_make_fragment_tex_shader_writedepth(ctx
->pipe
, tgsi_tex
,
206 TGSI_INTERPOLATE_LINEAR
);
209 cso_set_fragment_shader_handle(ctx
->cso
, ctx
->fs_depth
[pipe_tex
]);
214 * Helper function to set the vertex shader.
217 set_vertex_shader(struct blit_state
*ctx
)
219 /* vertex shader - still required to provide the linkage between
220 * fragment shader input semantics and vertex_element/buffers.
223 const uint semantic_names
[] = { TGSI_SEMANTIC_POSITION
,
224 TGSI_SEMANTIC_GENERIC
};
225 const uint semantic_indexes
[] = { 0, 0 };
226 ctx
->vs
= util_make_vertex_passthrough_shader(ctx
->pipe
, 2,
231 cso_set_vertex_shader_handle(ctx
->cso
, ctx
->vs
);
236 * Get offset of next free slot in vertex buffer for quad vertices.
239 get_next_slot( struct blit_state
*ctx
)
241 const unsigned max_slots
= 4096 / sizeof ctx
->vertices
;
243 if (ctx
->vbuf_slot
>= max_slots
) {
244 pipe_resource_reference(&ctx
->vbuf
, NULL
);
249 ctx
->vbuf
= pipe_buffer_create(ctx
->pipe
->screen
,
250 PIPE_BIND_VERTEX_BUFFER
,
252 max_slots
* sizeof ctx
->vertices
);
255 return ctx
->vbuf_slot
++ * sizeof ctx
->vertices
;
262 * Setup vertex data for the textured quad we'll draw.
266 setup_vertex_data_tex(struct blit_state
*ctx
,
267 float x0
, float y0
, float x1
, float y1
,
268 float s0
, float t0
, float s1
, float t1
,
273 ctx
->vertices
[0][0][0] = x0
;
274 ctx
->vertices
[0][0][1] = y0
;
275 ctx
->vertices
[0][0][2] = z
;
276 ctx
->vertices
[0][1][0] = s0
; /*s*/
277 ctx
->vertices
[0][1][1] = t0
; /*t*/
279 ctx
->vertices
[1][0][0] = x1
;
280 ctx
->vertices
[1][0][1] = y0
;
281 ctx
->vertices
[1][0][2] = z
;
282 ctx
->vertices
[1][1][0] = s1
; /*s*/
283 ctx
->vertices
[1][1][1] = t0
; /*t*/
285 ctx
->vertices
[2][0][0] = x1
;
286 ctx
->vertices
[2][0][1] = y1
;
287 ctx
->vertices
[2][0][2] = z
;
288 ctx
->vertices
[2][1][0] = s1
;
289 ctx
->vertices
[2][1][1] = t1
;
291 ctx
->vertices
[3][0][0] = x0
;
292 ctx
->vertices
[3][0][1] = y1
;
293 ctx
->vertices
[3][0][2] = z
;
294 ctx
->vertices
[3][1][0] = s0
;
295 ctx
->vertices
[3][1][1] = t1
;
297 offset
= get_next_slot( ctx
);
300 pipe_buffer_write_nooverlap(ctx
->pipe
, ctx
->vbuf
,
301 offset
, sizeof(ctx
->vertices
), ctx
->vertices
);
309 * \return TRUE if two regions overlap, FALSE otherwise
312 regions_overlap(int srcX0
, int srcY0
,
313 int srcX1
, int srcY1
,
314 int dstX0
, int dstY0
,
315 int dstX1
, int dstY1
)
317 if (MAX2(srcX0
, srcX1
) < MIN2(dstX0
, dstX1
))
318 return FALSE
; /* src completely left of dst */
320 if (MAX2(dstX0
, dstX1
) < MIN2(srcX0
, srcX1
))
321 return FALSE
; /* dst completely left of src */
323 if (MAX2(srcY0
, srcY1
) < MIN2(dstY0
, dstY1
))
324 return FALSE
; /* src completely above dst */
326 if (MAX2(dstY0
, dstY1
) < MIN2(srcY0
, srcY1
))
327 return FALSE
; /* dst completely above src */
329 return TRUE
; /* some overlap */
334 * Can we blit from src format to dest format with a simple copy?
337 formats_compatible(enum pipe_format src_format
,
338 enum pipe_format dst_format
)
340 if (src_format
== dst_format
) {
344 const struct util_format_description
*src_desc
=
345 util_format_description(src_format
);
346 const struct util_format_description
*dst_desc
=
347 util_format_description(dst_format
);
348 return util_is_format_compatible(src_desc
, dst_desc
);
354 * Copy pixel block from src surface to dst surface.
355 * Overlapping regions are acceptable.
356 * Flipping and stretching are supported.
357 * \param filter one of PIPE_TEX_MIPFILTER_NEAREST/LINEAR
358 * \param writemask controls which channels in the dest surface are sourced
359 * from the src surface. Disabled channels are sourced
361 * XXX need some control over blitting stencil.
364 util_blit_pixels(struct blit_state
*ctx
,
365 struct pipe_resource
*src_tex
,
367 int srcX0
, int srcY0
,
368 int srcX1
, int srcY1
,
370 struct pipe_surface
*dst
,
371 int dstX0
, int dstY0
,
372 int dstX1
, int dstY1
,
373 float z
, uint filter
,
376 struct pipe_context
*pipe
= ctx
->pipe
;
377 struct pipe_screen
*screen
= pipe
->screen
;
378 enum pipe_format src_format
, dst_format
;
379 struct pipe_sampler_view
*sampler_view
= NULL
;
380 struct pipe_sampler_view sv_templ
;
381 struct pipe_surface
*dst_surface
;
382 struct pipe_framebuffer_state fb
;
383 const int srcW
= abs(srcX1
- srcX0
);
384 const int srcH
= abs(srcY1
- srcY0
);
386 boolean overlap
, dst_is_depth
;
387 float s0
, t0
, s1
, t1
;
390 assert(filter
== PIPE_TEX_MIPFILTER_NEAREST
||
391 filter
== PIPE_TEX_MIPFILTER_LINEAR
);
393 assert(src_level
<= src_tex
->last_level
);
395 /* do the regions overlap? */
396 overlap
= src_tex
== dst
->texture
&&
397 dst
->u
.tex
.level
== src_level
&&
398 dst
->u
.tex
.first_layer
== srcZ0
&&
399 regions_overlap(srcX0
, srcY0
, srcX1
, srcY1
,
400 dstX0
, dstY0
, dstX1
, dstY1
);
402 src_format
= util_format_linear(src_tex
->format
);
403 dst_format
= util_format_linear(dst
->format
);
406 * Check for simple case: no format conversion, no flipping, no stretching,
408 * Filter mode should not matter since there's no stretching.
410 if (formats_compatible(src_format
, dst_format
) &&
415 (dstX1
- dstX0
) == (srcX1
- srcX0
) &&
416 (dstY1
- dstY0
) == (srcY1
- srcY0
) &&
418 struct pipe_box src_box
;
422 src_box
.width
= srcW
;
423 src_box
.height
= srcH
;
425 pipe
->resource_copy_region(pipe
,
426 dst
->texture
, dst
->u
.tex
.level
,
427 dstX0
, dstY0
, dst
->u
.tex
.first_layer
,/* dest */
433 if (dst_format
== dst
->format
) {
436 struct pipe_surface templ
= *dst
;
437 templ
.format
= dst_format
;
438 dst_surface
= pipe
->create_surface(pipe
, dst
->texture
, &templ
);
441 /* Create a temporary texture when src and dest alias.
443 if (src_tex
== dst_surface
->texture
&&
444 dst_surface
->u
.tex
.level
== src_level
&&
445 dst_surface
->u
.tex
.first_layer
== srcZ0
) {
446 /* Make a temporary texture which contains a copy of the source pixels.
447 * Then we'll sample from the temporary texture.
449 struct pipe_resource texTemp
;
450 struct pipe_resource
*tex
;
451 struct pipe_sampler_view sv_templ
;
452 struct pipe_box src_box
;
453 const int srcLeft
= MIN2(srcX0
, srcX1
);
454 const int srcTop
= MIN2(srcY0
, srcY1
);
456 if (srcLeft
!= srcX0
) {
457 /* left-right flip */
463 if (srcTop
!= srcY0
) {
470 /* create temp texture */
471 memset(&texTemp
, 0, sizeof(texTemp
));
472 texTemp
.target
= ctx
->internal_target
;
473 texTemp
.format
= src_format
;
474 texTemp
.last_level
= 0;
475 texTemp
.width0
= srcW
;
476 texTemp
.height0
= srcH
;
478 texTemp
.array_size
= 1;
479 texTemp
.bind
= PIPE_BIND_SAMPLER_VIEW
;
481 tex
= screen
->resource_create(screen
, &texTemp
);
488 src_box
.width
= srcW
;
489 src_box
.height
= srcH
;
491 /* load temp texture */
492 pipe
->resource_copy_region(pipe
,
493 tex
, 0, 0, 0, 0, /* dest */
494 src_tex
, src_level
, &src_box
);
496 normalized
= tex
->target
!= PIPE_TEXTURE_RECT
;
510 u_sampler_view_default_template(&sv_templ
, tex
, tex
->format
);
511 sampler_view
= pipe
->create_sampler_view(pipe
, tex
, &sv_templ
);
514 pipe_resource_reference(&tex
, NULL
);
517 pipe_resource_reference(&tex
, NULL
);
520 /* Directly sample from the source resource/texture */
521 u_sampler_view_default_template(&sv_templ
, src_tex
, src_format
);
522 sampler_view
= pipe
->create_sampler_view(pipe
, src_tex
, &sv_templ
);
532 normalized
= sampler_view
->texture
->target
!= PIPE_TEXTURE_RECT
;
535 s0
/= (float)(u_minify(sampler_view
->texture
->width0
, src_level
));
536 s1
/= (float)(u_minify(sampler_view
->texture
->width0
, src_level
));
537 t0
/= (float)(u_minify(sampler_view
->texture
->height0
, src_level
));
538 t1
/= (float)(u_minify(sampler_view
->texture
->height0
, src_level
));
542 dst_is_depth
= util_format_is_depth_or_stencil(dst_format
);
544 assert(screen
->is_format_supported(screen
, sampler_view
->format
, ctx
->internal_target
,
545 sampler_view
->texture
->nr_samples
,
546 PIPE_BIND_SAMPLER_VIEW
));
547 assert(screen
->is_format_supported(screen
, dst_format
, ctx
->internal_target
,
548 dst_surface
->texture
->nr_samples
,
549 dst_is_depth
? PIPE_BIND_DEPTH_STENCIL
:
550 PIPE_BIND_RENDER_TARGET
));
551 /* save state (restored below) */
552 cso_save_blend(ctx
->cso
);
553 cso_save_depth_stencil_alpha(ctx
->cso
);
554 cso_save_rasterizer(ctx
->cso
);
555 cso_save_samplers(ctx
->cso
);
556 cso_save_fragment_sampler_views(ctx
->cso
);
557 cso_save_stream_outputs(ctx
->cso
);
558 cso_save_viewport(ctx
->cso
);
559 cso_save_framebuffer(ctx
->cso
);
560 cso_save_fragment_shader(ctx
->cso
);
561 cso_save_vertex_shader(ctx
->cso
);
562 cso_save_geometry_shader(ctx
->cso
);
563 cso_save_vertex_elements(ctx
->cso
);
564 cso_save_vertex_buffers(ctx
->cso
);
566 /* set misc state we care about */
568 cso_set_blend(ctx
->cso
, &ctx
->blend_write_color
);
570 cso_set_blend(ctx
->cso
, &ctx
->blend_keep_color
);
572 cso_set_depth_stencil_alpha(ctx
->cso
,
573 dst_is_depth
? &ctx
->depthstencil_write
:
574 &ctx
->depthstencil_keep
);
575 cso_set_rasterizer(ctx
->cso
, &ctx
->rasterizer
);
576 cso_set_vertex_elements(ctx
->cso
, 2, ctx
->velem
);
577 cso_set_stream_outputs(ctx
->cso
, 0, NULL
, 0);
580 ctx
->sampler
.normalized_coords
= normalized
;
581 ctx
->sampler
.min_img_filter
= filter
;
582 ctx
->sampler
.mag_img_filter
= filter
;
583 ctx
->sampler
.min_lod
= src_level
;
584 ctx
->sampler
.max_lod
= src_level
;
585 cso_single_sampler(ctx
->cso
, 0, &ctx
->sampler
);
586 cso_single_sampler_done(ctx
->cso
);
589 ctx
->viewport
.scale
[0] = 0.5f
* dst_surface
->width
;
590 ctx
->viewport
.scale
[1] = 0.5f
* dst_surface
->height
;
591 ctx
->viewport
.scale
[2] = 0.5f
;
592 ctx
->viewport
.scale
[3] = 1.0f
;
593 ctx
->viewport
.translate
[0] = 0.5f
* dst_surface
->width
;
594 ctx
->viewport
.translate
[1] = 0.5f
* dst_surface
->height
;
595 ctx
->viewport
.translate
[2] = 0.5f
;
596 ctx
->viewport
.translate
[3] = 0.0f
;
597 cso_set_viewport(ctx
->cso
, &ctx
->viewport
);
600 cso_set_fragment_sampler_views(ctx
->cso
, 1, &sampler_view
);
604 set_depth_fragment_shader(ctx
, sampler_view
->texture
->target
);
606 set_fragment_shader(ctx
, writemask
, sampler_view
->texture
->target
);
608 set_vertex_shader(ctx
);
609 cso_set_geometry_shader_handle(ctx
->cso
, NULL
);
612 memset(&fb
, 0, sizeof(fb
));
613 fb
.width
= dst_surface
->width
;
614 fb
.height
= dst_surface
->height
;
616 fb
.zsbuf
= dst_surface
;
619 fb
.cbufs
[0] = dst_surface
;
621 cso_set_framebuffer(ctx
->cso
, &fb
);
624 offset
= setup_vertex_data_tex(ctx
,
625 (float) dstX0
/ dst_surface
->width
* 2.0f
- 1.0f
,
626 (float) dstY0
/ dst_surface
->height
* 2.0f
- 1.0f
,
627 (float) dstX1
/ dst_surface
->width
* 2.0f
- 1.0f
,
628 (float) dstY1
/ dst_surface
->height
* 2.0f
- 1.0f
,
634 util_draw_vertex_buffer(ctx
->pipe
, ctx
->cso
, ctx
->vbuf
, offset
,
635 PIPE_PRIM_TRIANGLE_FAN
,
637 2); /* attribs/vert */
640 /* restore state we changed */
641 cso_restore_blend(ctx
->cso
);
642 cso_restore_depth_stencil_alpha(ctx
->cso
);
643 cso_restore_rasterizer(ctx
->cso
);
644 cso_restore_samplers(ctx
->cso
);
645 cso_restore_fragment_sampler_views(ctx
->cso
);
646 cso_restore_viewport(ctx
->cso
);
647 cso_restore_framebuffer(ctx
->cso
);
648 cso_restore_fragment_shader(ctx
->cso
);
649 cso_restore_vertex_shader(ctx
->cso
);
650 cso_restore_geometry_shader(ctx
->cso
);
651 cso_restore_vertex_elements(ctx
->cso
);
652 cso_restore_vertex_buffers(ctx
->cso
);
653 cso_restore_stream_outputs(ctx
->cso
);
655 pipe_sampler_view_reference(&sampler_view
, NULL
);
656 if (dst_surface
!= dst
)
657 pipe_surface_reference(&dst_surface
, NULL
);
662 * Copy pixel block from src texture to dst surface.
663 * The sampler view's first_level field indicates the source
664 * mipmap level to use.
665 * XXX need some control over blitting Z and/or stencil.
668 util_blit_pixels_tex(struct blit_state
*ctx
,
669 struct pipe_sampler_view
*src_sampler_view
,
670 int srcX0
, int srcY0
,
671 int srcX1
, int srcY1
,
672 struct pipe_surface
*dst
,
673 int dstX0
, int dstY0
,
674 int dstX1
, int dstY1
,
675 float z
, uint filter
)
677 boolean normalized
= src_sampler_view
->texture
->target
!= PIPE_TEXTURE_RECT
;
678 struct pipe_framebuffer_state fb
;
679 float s0
, t0
, s1
, t1
;
681 struct pipe_resource
*tex
= src_sampler_view
->texture
;
683 assert(filter
== PIPE_TEX_MIPFILTER_NEAREST
||
684 filter
== PIPE_TEX_MIPFILTER_LINEAR
);
687 assert(tex
->width0
!= 0);
688 assert(tex
->height0
!= 0);
697 /* normalize according to the mipmap level's size */
698 int level
= src_sampler_view
->u
.tex
.first_level
;
699 float w
= (float) u_minify(tex
->width0
, level
);
700 float h
= (float) u_minify(tex
->height0
, level
);
707 assert(ctx
->pipe
->screen
->is_format_supported(ctx
->pipe
->screen
, dst
->format
,
709 dst
->texture
->nr_samples
,
710 PIPE_BIND_RENDER_TARGET
));
712 /* save state (restored below) */
713 cso_save_blend(ctx
->cso
);
714 cso_save_depth_stencil_alpha(ctx
->cso
);
715 cso_save_rasterizer(ctx
->cso
);
716 cso_save_samplers(ctx
->cso
);
717 cso_save_fragment_sampler_views(ctx
->cso
);
718 cso_save_stream_outputs(ctx
->cso
);
719 cso_save_viewport(ctx
->cso
);
720 cso_save_framebuffer(ctx
->cso
);
721 cso_save_fragment_shader(ctx
->cso
);
722 cso_save_vertex_shader(ctx
->cso
);
723 cso_save_geometry_shader(ctx
->cso
);
724 cso_save_vertex_elements(ctx
->cso
);
725 cso_save_vertex_buffers(ctx
->cso
);
727 /* set misc state we care about */
728 cso_set_blend(ctx
->cso
, &ctx
->blend_write_color
);
729 cso_set_depth_stencil_alpha(ctx
->cso
, &ctx
->depthstencil_keep
);
730 cso_set_rasterizer(ctx
->cso
, &ctx
->rasterizer
);
731 cso_set_vertex_elements(ctx
->cso
, 2, ctx
->velem
);
732 cso_set_stream_outputs(ctx
->cso
, 0, NULL
, 0);
735 ctx
->sampler
.normalized_coords
= normalized
;
736 ctx
->sampler
.min_img_filter
= filter
;
737 ctx
->sampler
.mag_img_filter
= filter
;
738 cso_single_sampler(ctx
->cso
, 0, &ctx
->sampler
);
739 cso_single_sampler_done(ctx
->cso
);
742 ctx
->viewport
.scale
[0] = 0.5f
* dst
->width
;
743 ctx
->viewport
.scale
[1] = 0.5f
* dst
->height
;
744 ctx
->viewport
.scale
[2] = 0.5f
;
745 ctx
->viewport
.scale
[3] = 1.0f
;
746 ctx
->viewport
.translate
[0] = 0.5f
* dst
->width
;
747 ctx
->viewport
.translate
[1] = 0.5f
* dst
->height
;
748 ctx
->viewport
.translate
[2] = 0.5f
;
749 ctx
->viewport
.translate
[3] = 0.0f
;
750 cso_set_viewport(ctx
->cso
, &ctx
->viewport
);
753 cso_set_fragment_sampler_views(ctx
->cso
, 1, &src_sampler_view
);
756 set_fragment_shader(ctx
, TGSI_WRITEMASK_XYZW
,
757 src_sampler_view
->texture
->target
);
758 set_vertex_shader(ctx
);
759 cso_set_geometry_shader_handle(ctx
->cso
, NULL
);
762 memset(&fb
, 0, sizeof(fb
));
763 fb
.width
= dst
->width
;
764 fb
.height
= dst
->height
;
767 cso_set_framebuffer(ctx
->cso
, &fb
);
770 offset
= setup_vertex_data_tex(ctx
,
771 (float) dstX0
/ dst
->width
* 2.0f
- 1.0f
,
772 (float) dstY0
/ dst
->height
* 2.0f
- 1.0f
,
773 (float) dstX1
/ dst
->width
* 2.0f
- 1.0f
,
774 (float) dstY1
/ dst
->height
* 2.0f
- 1.0f
,
778 util_draw_vertex_buffer(ctx
->pipe
, ctx
->cso
,
780 PIPE_PRIM_TRIANGLE_FAN
,
782 2); /* attribs/vert */
784 /* restore state we changed */
785 cso_restore_blend(ctx
->cso
);
786 cso_restore_depth_stencil_alpha(ctx
->cso
);
787 cso_restore_rasterizer(ctx
->cso
);
788 cso_restore_samplers(ctx
->cso
);
789 cso_restore_fragment_sampler_views(ctx
->cso
);
790 cso_restore_viewport(ctx
->cso
);
791 cso_restore_framebuffer(ctx
->cso
);
792 cso_restore_fragment_shader(ctx
->cso
);
793 cso_restore_vertex_shader(ctx
->cso
);
794 cso_restore_geometry_shader(ctx
->cso
);
795 cso_restore_vertex_elements(ctx
->cso
);
796 cso_restore_vertex_buffers(ctx
->cso
);
797 cso_restore_stream_outputs(ctx
->cso
);