Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /**************************************************************************
  2.  *
  3.  * Copyright 2008 VMware, Inc.
  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 VMWARE 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_format.h"
  46. #include "util/u_math.h"
  47. #include "util/u_memory.h"
  48. #include "util/u_sampler.h"
  49. #include "util/u_texture.h"
  50. #include "util/u_simple_shaders.h"
  51.  
  52. #include "cso_cache/cso_context.h"
  53.  
  54.  
  55. struct blit_state
  56. {
  57.    struct pipe_context *pipe;
  58.    struct cso_context *cso;
  59.  
  60.    struct pipe_blend_state blend_write_color;
  61.    struct pipe_depth_stencil_alpha_state dsa_keep_depthstencil;
  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.  
  67.    void *vs;
  68.    void *fs[PIPE_MAX_TEXTURE_TYPES][TGSI_WRITEMASK_XYZW + 1];
  69.  
  70.    struct pipe_resource *vbuf;  /**< quad vertices */
  71.    unsigned vbuf_slot;
  72.  
  73.    float vertices[4][2][4];   /**< vertex/texcoords for quad */
  74. };
  75.  
  76.  
  77. /**
  78.  * Create state object for blit.
  79.  * Intended to be created once and re-used for many blit() calls.
  80.  */
  81. struct blit_state *
  82. util_create_blit(struct pipe_context *pipe, struct cso_context *cso)
  83. {
  84.    struct blit_state *ctx;
  85.    uint i;
  86.  
  87.    ctx = CALLOC_STRUCT(blit_state);
  88.    if (!ctx)
  89.       return NULL;
  90.  
  91.    ctx->pipe = pipe;
  92.    ctx->cso = cso;
  93.  
  94.    /* disabled blending/masking */
  95.    ctx->blend_write_color.rt[0].colormask = PIPE_MASK_RGBA;
  96.  
  97.    /* rasterizer */
  98.    ctx->rasterizer.cull_face = PIPE_FACE_NONE;
  99.    ctx->rasterizer.half_pixel_center = 1;
  100.    ctx->rasterizer.bottom_edge_rule = 1;
  101.    ctx->rasterizer.depth_clip = 1;
  102.  
  103.    /* samplers */
  104.    ctx->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
  105.    ctx->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
  106.    ctx->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
  107.    ctx->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
  108.    ctx->sampler.min_img_filter = 0; /* set later */
  109.    ctx->sampler.mag_img_filter = 0; /* set later */
  110.  
  111.    /* vertex elements state */
  112.    for (i = 0; i < 2; i++) {
  113.       ctx->velem[i].src_offset = i * 4 * sizeof(float);
  114.       ctx->velem[i].instance_divisor = 0;
  115.       ctx->velem[i].vertex_buffer_index = cso_get_aux_vertex_buffer_slot(cso);
  116.       ctx->velem[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
  117.    }
  118.  
  119.    ctx->vbuf = NULL;
  120.  
  121.    /* init vertex data that doesn't change */
  122.    for (i = 0; i < 4; i++) {
  123.       ctx->vertices[i][0][3] = 1.0f; /* w */
  124.       ctx->vertices[i][1][3] = 1.0f; /* q */
  125.    }
  126.  
  127.    return ctx;
  128. }
  129.  
  130.  
  131. /**
  132.  * Destroy a blit context
  133.  */
  134. void
  135. util_destroy_blit(struct blit_state *ctx)
  136. {
  137.    struct pipe_context *pipe = ctx->pipe;
  138.    unsigned i, j;
  139.  
  140.    if (ctx->vs)
  141.       pipe->delete_vs_state(pipe, ctx->vs);
  142.  
  143.    for (i = 0; i < Elements(ctx->fs); i++) {
  144.       for (j = 0; j < Elements(ctx->fs[i]); j++) {
  145.          if (ctx->fs[i][j])
  146.             pipe->delete_fs_state(pipe, ctx->fs[i][j]);
  147.       }
  148.    }
  149.  
  150.    pipe_resource_reference(&ctx->vbuf, NULL);
  151.  
  152.    FREE(ctx);
  153. }
  154.  
  155.  
  156. /**
  157.  * Helper function to set the fragment shaders.
  158.  */
  159. static INLINE void
  160. set_fragment_shader(struct blit_state *ctx, uint writemask,
  161.                     enum pipe_texture_target pipe_tex)
  162. {
  163.    if (!ctx->fs[pipe_tex][writemask]) {
  164.       unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(pipe_tex, 0);
  165.  
  166.       ctx->fs[pipe_tex][writemask] =
  167.          util_make_fragment_tex_shader_writemask(ctx->pipe, tgsi_tex,
  168.                                                  TGSI_INTERPOLATE_LINEAR,
  169.                                                  writemask);
  170.    }
  171.  
  172.    cso_set_fragment_shader_handle(ctx->cso, ctx->fs[pipe_tex][writemask]);
  173. }
  174.  
  175.  
  176. /**
  177.  * Helper function to set the vertex shader.
  178.  */
  179. static INLINE void
  180. set_vertex_shader(struct blit_state *ctx)
  181. {
  182.    /* vertex shader - still required to provide the linkage between
  183.     * fragment shader input semantics and vertex_element/buffers.
  184.     */
  185.    if (!ctx->vs) {
  186.       const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
  187.                                       TGSI_SEMANTIC_GENERIC };
  188.       const uint semantic_indexes[] = { 0, 0 };
  189.       ctx->vs = util_make_vertex_passthrough_shader(ctx->pipe, 2,
  190.                                                     semantic_names,
  191.                                                     semantic_indexes, FALSE);
  192.    }
  193.  
  194.    cso_set_vertex_shader_handle(ctx->cso, ctx->vs);
  195. }
  196.  
  197.  
  198. /**
  199.  * Get offset of next free slot in vertex buffer for quad vertices.
  200.  */
  201. static unsigned
  202. get_next_slot( struct blit_state *ctx )
  203. {
  204.    const unsigned max_slots = 4096 / sizeof ctx->vertices;
  205.  
  206.    if (ctx->vbuf_slot >= max_slots) {
  207.       pipe_resource_reference(&ctx->vbuf, NULL);
  208.       ctx->vbuf_slot = 0;
  209.    }
  210.  
  211.    if (!ctx->vbuf) {
  212.       ctx->vbuf = pipe_buffer_create(ctx->pipe->screen,
  213.                                      PIPE_BIND_VERTEX_BUFFER,
  214.                                      PIPE_USAGE_STREAM,
  215.                                      max_slots * sizeof ctx->vertices);
  216.    }
  217.    
  218.    return ctx->vbuf_slot++ * sizeof ctx->vertices;
  219. }
  220.  
  221.  
  222.  
  223.  
  224. /**
  225.  * Setup vertex data for the textured quad we'll draw.
  226.  * Note: y=0=top
  227.  *
  228.  * FIXME: We should call util_map_texcoords2d_onto_cubemap
  229.  * for cubemaps.
  230.  */
  231. static unsigned
  232. setup_vertex_data_tex(struct blit_state *ctx,
  233.                       unsigned src_target,
  234.                       unsigned src_face,
  235.                       float x0, float y0, float x1, float y1,
  236.                       float s0, float t0, float s1, float t1,
  237.                       float z)
  238. {
  239.    unsigned offset;
  240.  
  241.    ctx->vertices[0][0][0] = x0;
  242.    ctx->vertices[0][0][1] = y0;
  243.    ctx->vertices[0][0][2] = z;
  244.    ctx->vertices[0][1][0] = s0; /*s*/
  245.    ctx->vertices[0][1][1] = t0; /*t*/
  246.    ctx->vertices[0][1][2] = 0;  /*r*/
  247.  
  248.    ctx->vertices[1][0][0] = x1;
  249.    ctx->vertices[1][0][1] = y0;
  250.    ctx->vertices[1][0][2] = z;
  251.    ctx->vertices[1][1][0] = s1; /*s*/
  252.    ctx->vertices[1][1][1] = t0; /*t*/
  253.    ctx->vertices[1][1][2] = 0;  /*r*/
  254.  
  255.    ctx->vertices[2][0][0] = x1;
  256.    ctx->vertices[2][0][1] = y1;
  257.    ctx->vertices[2][0][2] = z;
  258.    ctx->vertices[2][1][0] = s1;
  259.    ctx->vertices[2][1][1] = t1;
  260.    ctx->vertices[3][1][2] = 0;
  261.  
  262.    ctx->vertices[3][0][0] = x0;
  263.    ctx->vertices[3][0][1] = y1;
  264.    ctx->vertices[3][0][2] = z;
  265.    ctx->vertices[3][1][0] = s0;
  266.    ctx->vertices[3][1][1] = t1;
  267.    ctx->vertices[3][1][2] = 0;
  268.  
  269.    if (src_target == PIPE_TEXTURE_CUBE ||
  270.        src_target == PIPE_TEXTURE_CUBE_ARRAY) {
  271.       /* Map cubemap texture coordinates inplace. */
  272.       const unsigned stride = sizeof ctx->vertices[0] / sizeof ctx->vertices[0][0][0];
  273.       util_map_texcoords2d_onto_cubemap(src_face,
  274.                                         &ctx->vertices[0][1][0], stride,
  275.                                         &ctx->vertices[0][1][0], stride,
  276.                                         TRUE);
  277.    }
  278.  
  279.    offset = get_next_slot( ctx );
  280.  
  281.    if (ctx->vbuf) {
  282.       pipe_buffer_write_nooverlap(ctx->pipe, ctx->vbuf,
  283.                                   offset, sizeof(ctx->vertices), ctx->vertices);
  284.    }
  285.  
  286.    return offset;
  287. }
  288.  
  289.  
  290. /**
  291.  * \return TRUE if two regions overlap, FALSE otherwise
  292.  */
  293. static boolean
  294. regions_overlap(int srcX0, int srcY0,
  295.                 int srcX1, int srcY1,
  296.                 int dstX0, int dstY0,
  297.                 int dstX1, int dstY1)
  298. {
  299.    if (MAX2(srcX0, srcX1) < MIN2(dstX0, dstX1))
  300.       return FALSE; /* src completely left of dst */
  301.  
  302.    if (MAX2(dstX0, dstX1) < MIN2(srcX0, srcX1))
  303.       return FALSE; /* dst completely left of src */
  304.  
  305.    if (MAX2(srcY0, srcY1) < MIN2(dstY0, dstY1))
  306.       return FALSE; /* src completely above dst */
  307.  
  308.    if (MAX2(dstY0, dstY1) < MIN2(srcY0, srcY1))
  309.       return FALSE; /* dst completely above src */
  310.  
  311.    return TRUE; /* some overlap */
  312. }
  313.  
  314.  
  315. /**
  316.  * Can we blit from src format to dest format with a simple copy?
  317.  */
  318. static boolean
  319. formats_compatible(enum pipe_format src_format,
  320.                    enum pipe_format dst_format)
  321. {
  322.    if (src_format == dst_format) {
  323.       return TRUE;
  324.    }
  325.    else {
  326.       const struct util_format_description *src_desc =
  327.          util_format_description(src_format);
  328.       const struct util_format_description *dst_desc =
  329.          util_format_description(dst_format);
  330.       return util_is_format_compatible(src_desc, dst_desc);
  331.    }
  332. }
  333.  
  334.  
  335. /**
  336.  * Copy pixel block from src surface to dst surface.
  337.  * Overlapping regions are acceptable.
  338.  * Flipping and stretching are supported.
  339.  * \param filter  one of PIPE_TEX_FILTER_NEAREST/LINEAR
  340.  * \param writemask  bitmask of PIPE_MASK_[RGBAZS].  Controls which channels
  341.  *                   in the dest surface are sourced from the src surface.
  342.  *                   Disabled color channels are sourced from (0,0,0,1).
  343.  */
  344. void
  345. util_blit_pixels(struct blit_state *ctx,
  346.                  struct pipe_resource *src_tex,
  347.                  unsigned src_level,
  348.                  int srcX0, int srcY0,
  349.                  int srcX1, int srcY1,
  350.                  int srcZ0,
  351.                  struct pipe_surface *dst,
  352.                  int dstX0, int dstY0,
  353.                  int dstX1, int dstY1,
  354.                  float z, uint filter,
  355.                  uint writemask)
  356. {
  357.    struct pipe_context *pipe = ctx->pipe;
  358.    enum pipe_format src_format, dst_format;
  359.    const int srcW = abs(srcX1 - srcX0);
  360.    const int srcH = abs(srcY1 - srcY0);
  361.    boolean overlap;
  362.    boolean is_stencil, is_depth, blit_depth, blit_stencil;
  363.    const struct util_format_description *src_desc =
  364.          util_format_description(src_tex->format);
  365.    struct pipe_blit_info info;
  366.  
  367.    assert(filter == PIPE_TEX_FILTER_NEAREST ||
  368.           filter == PIPE_TEX_FILTER_LINEAR);
  369.  
  370.    assert(src_level <= src_tex->last_level);
  371.  
  372.    /* do the regions overlap? */
  373.    overlap = src_tex == dst->texture &&
  374.              dst->u.tex.level == src_level &&
  375.              dst->u.tex.first_layer == srcZ0 &&
  376.       regions_overlap(srcX0, srcY0, srcX1, srcY1,
  377.                       dstX0, dstY0, dstX1, dstY1);
  378.  
  379.    src_format = util_format_linear(src_tex->format);
  380.    dst_format = util_format_linear(dst->texture->format);
  381.  
  382.    /* See whether we will blit depth or stencil. */
  383.    is_depth = util_format_has_depth(src_desc);
  384.    is_stencil = util_format_has_stencil(src_desc);
  385.  
  386.    blit_depth = is_depth && (writemask & PIPE_MASK_Z);
  387.    blit_stencil = is_stencil && (writemask & PIPE_MASK_S);
  388.  
  389.    if (is_depth || is_stencil) {
  390.       assert((writemask & PIPE_MASK_RGBA) == 0);
  391.       assert(blit_depth || blit_stencil);
  392.    }
  393.    else {
  394.       assert((writemask & PIPE_MASK_ZS) == 0);
  395.       assert(!blit_depth);
  396.       assert(!blit_stencil);
  397.    }
  398.  
  399.    /*
  400.     * XXX: z parameter is deprecated. dst->u.tex.first_layer
  401.     * specificies the destination layer.
  402.     */
  403.    assert(z == 0.0f);
  404.  
  405.    /*
  406.     * Check for simple case:  no format conversion, no flipping, no stretching,
  407.     * no overlapping, same number of samples.
  408.     * Filter mode should not matter since there's no stretching.
  409.     */
  410.    if (formats_compatible(src_format, dst_format) &&
  411.        src_tex->nr_samples == dst->texture->nr_samples &&
  412.        is_stencil == blit_stencil &&
  413.        is_depth == blit_depth &&
  414.        srcX0 < srcX1 &&
  415.        dstX0 < dstX1 &&
  416.        srcY0 < srcY1 &&
  417.        dstY0 < dstY1 &&
  418.        (dstX1 - dstX0) == (srcX1 - srcX0) &&
  419.        (dstY1 - dstY0) == (srcY1 - srcY0) &&
  420.        !overlap) {
  421.       struct pipe_box src_box;
  422.       src_box.x = srcX0;
  423.       src_box.y = srcY0;
  424.       src_box.z = srcZ0;
  425.       src_box.width = srcW;
  426.       src_box.height = srcH;
  427.       src_box.depth = 1;
  428.       pipe->resource_copy_region(pipe,
  429.                                  dst->texture, dst->u.tex.level,
  430.                                  dstX0, dstY0, dst->u.tex.first_layer,/* dest */
  431.                                  src_tex, src_level,
  432.                                  &src_box);
  433.       return;
  434.    }
  435.  
  436.    memset(&info, 0, sizeof info);
  437.    info.dst.resource = dst->texture;
  438.    info.dst.level = dst->u.tex.level;
  439.    info.dst.box.x = dstX0;
  440.    info.dst.box.y = dstY0;
  441.    info.dst.box.z = dst->u.tex.first_layer;
  442.    info.dst.box.width = dstX1 - dstX0;
  443.    info.dst.box.height = dstY1 - dstY0;
  444.    assert(info.dst.box.width >= 0);
  445.    assert(info.dst.box.height >= 0);
  446.    info.dst.box.depth = 1;
  447.    info.dst.format = dst_format;
  448.    info.src.resource = src_tex;
  449.    info.src.level = src_level;
  450.    info.src.box.x = srcX0;
  451.    info.src.box.y = srcY0;
  452.    info.src.box.z = srcZ0;
  453.    info.src.box.width = srcX1 - srcX0;
  454.    info.src.box.height = srcY1 - srcY0;
  455.    info.src.box.depth = 1;
  456.    info.src.format = src_format;
  457.    info.mask = writemask;
  458.    info.filter = filter;
  459.    info.scissor_enable = 0;
  460.  
  461.    pipe->blit(pipe, &info);
  462. }
  463.  
  464.  
  465. /**
  466.  * Copy pixel block from src sampler view to dst surface.
  467.  *
  468.  * The sampler view's first_level field indicates the source
  469.  * mipmap level to use.
  470.  *
  471.  * The sampler view's first_layer indicate the layer to use, but for
  472.  * cube maps it must point to the first face.  Face is passed in src_face.
  473.  *
  474.  * The main advantage over util_blit_pixels is that it allows to specify swizzles in
  475.  * pipe_sampler_view::swizzle_?.
  476.  *
  477.  * But there is no control over blitting Z and/or stencil.
  478.  */
  479. void
  480. util_blit_pixels_tex(struct blit_state *ctx,
  481.                      struct pipe_sampler_view *src_sampler_view,
  482.                      int srcX0, int srcY0,
  483.                      int srcX1, int srcY1,
  484.                      unsigned src_face,
  485.                      struct pipe_surface *dst,
  486.                      int dstX0, int dstY0,
  487.                      int dstX1, int dstY1,
  488.                      float z, uint filter)
  489. {
  490.    boolean normalized = src_sampler_view->texture->target != PIPE_TEXTURE_RECT;
  491.    struct pipe_framebuffer_state fb;
  492.    float s0, t0, s1, t1;
  493.    unsigned offset;
  494.    struct pipe_resource *tex = src_sampler_view->texture;
  495.  
  496.    assert(filter == PIPE_TEX_FILTER_NEAREST ||
  497.           filter == PIPE_TEX_FILTER_LINEAR);
  498.  
  499.    assert(tex);
  500.    assert(tex->width0 != 0);
  501.    assert(tex->height0 != 0);
  502.  
  503.    s0 = (float) srcX0;
  504.    s1 = (float) srcX1;
  505.    t0 = (float) srcY0;
  506.    t1 = (float) srcY1;
  507.  
  508.    if(normalized)
  509.    {
  510.       /* normalize according to the mipmap level's size */
  511.       int level = src_sampler_view->u.tex.first_level;
  512.       float w = (float) u_minify(tex->width0, level);
  513.       float h = (float) u_minify(tex->height0, level);
  514.       s0 /= w;
  515.       s1 /= w;
  516.       t0 /= h;
  517.       t1 /= h;
  518.    }
  519.  
  520.    assert(ctx->pipe->screen->is_format_supported(ctx->pipe->screen, dst->format,
  521.                                                  PIPE_TEXTURE_2D,
  522.                                                  dst->texture->nr_samples,
  523.                                                  PIPE_BIND_RENDER_TARGET));
  524.  
  525.    /* save state (restored below) */
  526.    cso_save_blend(ctx->cso);
  527.    cso_save_depth_stencil_alpha(ctx->cso);
  528.    cso_save_rasterizer(ctx->cso);
  529.    cso_save_sample_mask(ctx->cso);
  530.    cso_save_min_samples(ctx->cso);
  531.    cso_save_samplers(ctx->cso, PIPE_SHADER_FRAGMENT);
  532.    cso_save_sampler_views(ctx->cso, PIPE_SHADER_FRAGMENT);
  533.    cso_save_stream_outputs(ctx->cso);
  534.    cso_save_viewport(ctx->cso);
  535.    cso_save_framebuffer(ctx->cso);
  536.    cso_save_fragment_shader(ctx->cso);
  537.    cso_save_vertex_shader(ctx->cso);
  538.    cso_save_tessctrl_shader(ctx->cso);
  539.    cso_save_tesseval_shader(ctx->cso);
  540.    cso_save_geometry_shader(ctx->cso);
  541.    cso_save_vertex_elements(ctx->cso);
  542.    cso_save_aux_vertex_buffer_slot(ctx->cso);
  543.  
  544.    /* set misc state we care about */
  545.    cso_set_blend(ctx->cso, &ctx->blend_write_color);
  546.    cso_set_depth_stencil_alpha(ctx->cso, &ctx->dsa_keep_depthstencil);
  547.    cso_set_sample_mask(ctx->cso, ~0);
  548.    cso_set_min_samples(ctx->cso, 1);
  549.    cso_set_rasterizer(ctx->cso, &ctx->rasterizer);
  550.    cso_set_vertex_elements(ctx->cso, 2, ctx->velem);
  551.    cso_set_stream_outputs(ctx->cso, 0, NULL, NULL);
  552.  
  553.    /* sampler */
  554.    ctx->sampler.normalized_coords = normalized;
  555.    ctx->sampler.min_img_filter = filter;
  556.    ctx->sampler.mag_img_filter = filter;
  557.    cso_single_sampler(ctx->cso, PIPE_SHADER_FRAGMENT, 0, &ctx->sampler);
  558.    cso_single_sampler_done(ctx->cso, PIPE_SHADER_FRAGMENT);
  559.  
  560.    /* viewport */
  561.    ctx->viewport.scale[0] = 0.5f * dst->width;
  562.    ctx->viewport.scale[1] = 0.5f * dst->height;
  563.    ctx->viewport.scale[2] = 0.5f;
  564.    ctx->viewport.translate[0] = 0.5f * dst->width;
  565.    ctx->viewport.translate[1] = 0.5f * dst->height;
  566.    ctx->viewport.translate[2] = 0.5f;
  567.    cso_set_viewport(ctx->cso, &ctx->viewport);
  568.  
  569.    /* texture */
  570.    cso_set_sampler_views(ctx->cso, PIPE_SHADER_FRAGMENT, 1, &src_sampler_view);
  571.  
  572.    /* shaders */
  573.    set_fragment_shader(ctx, TGSI_WRITEMASK_XYZW,
  574.                        src_sampler_view->texture->target);
  575.    set_vertex_shader(ctx);
  576.    cso_set_tessctrl_shader_handle(ctx->cso, NULL);
  577.    cso_set_tesseval_shader_handle(ctx->cso, NULL);
  578.    cso_set_geometry_shader_handle(ctx->cso, NULL);
  579.  
  580.    /* drawing dest */
  581.    memset(&fb, 0, sizeof(fb));
  582.    fb.width = dst->width;
  583.    fb.height = dst->height;
  584.    fb.nr_cbufs = 1;
  585.    fb.cbufs[0] = dst;
  586.    cso_set_framebuffer(ctx->cso, &fb);
  587.  
  588.    /* draw quad */
  589.    offset = setup_vertex_data_tex(ctx,
  590.                                   src_sampler_view->texture->target,
  591.                                   src_face,
  592.                                   (float) dstX0 / dst->width * 2.0f - 1.0f,
  593.                                   (float) dstY0 / dst->height * 2.0f - 1.0f,
  594.                                   (float) dstX1 / dst->width * 2.0f - 1.0f,
  595.                                   (float) dstY1 / dst->height * 2.0f - 1.0f,
  596.                                   s0, t0, s1, t1,
  597.                                   z);
  598.  
  599.    util_draw_vertex_buffer(ctx->pipe, ctx->cso, ctx->vbuf,
  600.                            cso_get_aux_vertex_buffer_slot(ctx->cso),
  601.                            offset,
  602.                            PIPE_PRIM_TRIANGLE_FAN,
  603.                            4,  /* verts */
  604.                            2); /* attribs/vert */
  605.  
  606.    /* restore state we changed */
  607.    cso_restore_blend(ctx->cso);
  608.    cso_restore_depth_stencil_alpha(ctx->cso);
  609.    cso_restore_rasterizer(ctx->cso);
  610.    cso_restore_sample_mask(ctx->cso);
  611.    cso_restore_min_samples(ctx->cso);
  612.    cso_restore_samplers(ctx->cso, PIPE_SHADER_FRAGMENT);
  613.    cso_restore_sampler_views(ctx->cso, PIPE_SHADER_FRAGMENT);
  614.    cso_restore_viewport(ctx->cso);
  615.    cso_restore_framebuffer(ctx->cso);
  616.    cso_restore_fragment_shader(ctx->cso);
  617.    cso_restore_vertex_shader(ctx->cso);
  618.    cso_restore_tessctrl_shader(ctx->cso);
  619.    cso_restore_tesseval_shader(ctx->cso);
  620.    cso_restore_geometry_shader(ctx->cso);
  621.    cso_restore_vertex_elements(ctx->cso);
  622.    cso_restore_aux_vertex_buffer_slot(ctx->cso);
  623.    cso_restore_stream_outputs(ctx->cso);
  624. }
  625.