• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**************************************************************************
2  *
3  * Copyright 2011 Christian König
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 #include <assert.h>
29 
30 #include "pipe/p_screen.h"
31 #include "pipe/p_context.h"
32 
33 #include "util/u_draw.h"
34 #include "util/u_sampler.h"
35 #include "util/u_inlines.h"
36 #include "util/u_memory.h"
37 
38 #include "tgsi/tgsi_ureg.h"
39 
40 #include "vl_defines.h"
41 #include "vl_types.h"
42 
43 #include "vl_zscan.h"
44 #include "vl_vertex_buffers.h"
45 
46 enum VS_OUTPUT
47 {
48    VS_O_VPOS = 0,
49    VS_O_VTEX = 0
50 };
51 
52 static void *
create_vert_shader(struct vl_zscan * zscan)53 create_vert_shader(struct vl_zscan *zscan)
54 {
55    struct ureg_program *shader;
56    struct ureg_src scale;
57    struct ureg_src vrect, vpos, block_num;
58    struct ureg_dst tmp;
59    struct ureg_dst o_vpos;
60    struct ureg_dst *o_vtex;
61    unsigned i;
62 
63    shader = ureg_create(PIPE_SHADER_VERTEX);
64    if (!shader)
65       return NULL;
66 
67    o_vtex = MALLOC(zscan->num_channels * sizeof(struct ureg_dst));
68 
69    scale = ureg_imm2f(shader,
70       (float)VL_BLOCK_WIDTH / zscan->buffer_width,
71       (float)VL_BLOCK_HEIGHT / zscan->buffer_height);
72 
73    vrect = ureg_DECL_vs_input(shader, VS_I_RECT);
74    vpos = ureg_DECL_vs_input(shader, VS_I_VPOS);
75    block_num = ureg_DECL_vs_input(shader, VS_I_BLOCK_NUM);
76 
77    tmp = ureg_DECL_temporary(shader);
78 
79    o_vpos = ureg_DECL_output(shader, TGSI_SEMANTIC_POSITION, VS_O_VPOS);
80 
81    for (i = 0; i < zscan->num_channels; ++i)
82       o_vtex[i] = ureg_DECL_output(shader, TGSI_SEMANTIC_GENERIC, VS_O_VTEX + i);
83 
84    /*
85     * o_vpos.xy = (vpos + vrect) * scale
86     * o_vpos.zw = 1.0f
87     *
88     * tmp.xy = InstanceID / blocks_per_line
89     * tmp.x = frac(tmp.x)
90     * tmp.y = floor(tmp.y)
91     *
92     * o_vtex.x = vrect.x / blocks_per_line + tmp.x
93     * o_vtex.y = vrect.y
94     * o_vtex.z = tmp.z * blocks_per_line / blocks_total
95     */
96    ureg_ADD(shader, ureg_writemask(tmp, TGSI_WRITEMASK_XY), vpos, vrect);
97    ureg_MUL(shader, ureg_writemask(o_vpos, TGSI_WRITEMASK_XY), ureg_src(tmp), scale);
98    ureg_MOV(shader, ureg_writemask(o_vpos, TGSI_WRITEMASK_ZW), ureg_imm1f(shader, 1.0f));
99 
100    ureg_MUL(shader, ureg_writemask(tmp, TGSI_WRITEMASK_XW), ureg_scalar(block_num, TGSI_SWIZZLE_X),
101             ureg_imm1f(shader, 1.0f / zscan->blocks_per_line));
102 
103    ureg_FRC(shader, ureg_writemask(tmp, TGSI_WRITEMASK_Y), ureg_scalar(ureg_src(tmp), TGSI_SWIZZLE_X));
104    ureg_FLR(shader, ureg_writemask(tmp, TGSI_WRITEMASK_W), ureg_src(tmp));
105 
106    for (i = 0; i < zscan->num_channels; ++i) {
107       ureg_ADD(shader, ureg_writemask(tmp, TGSI_WRITEMASK_X), ureg_scalar(ureg_src(tmp), TGSI_SWIZZLE_Y),
108                ureg_imm1f(shader, 1.0f / (zscan->blocks_per_line * VL_BLOCK_WIDTH)
109                 * ((signed)i - (signed)zscan->num_channels / 2)));
110 
111       ureg_MAD(shader, ureg_writemask(o_vtex[i], TGSI_WRITEMASK_X), vrect,
112                ureg_imm1f(shader, 1.0f / zscan->blocks_per_line), ureg_src(tmp));
113       ureg_MOV(shader, ureg_writemask(o_vtex[i], TGSI_WRITEMASK_Y), vrect);
114       ureg_MOV(shader, ureg_writemask(o_vtex[i], TGSI_WRITEMASK_Z), vpos);
115       ureg_MUL(shader, ureg_writemask(o_vtex[i], TGSI_WRITEMASK_W), ureg_src(tmp),
116                ureg_imm1f(shader, (float)zscan->blocks_per_line / zscan->blocks_total));
117    }
118 
119    ureg_release_temporary(shader, tmp);
120    ureg_END(shader);
121 
122    FREE(o_vtex);
123 
124    return ureg_create_shader_and_destroy(shader, zscan->pipe);
125 }
126 
127 static void *
create_frag_shader(struct vl_zscan * zscan)128 create_frag_shader(struct vl_zscan *zscan)
129 {
130    struct ureg_program *shader;
131    struct ureg_src *vtex;
132 
133    struct ureg_src samp_src, samp_scan, samp_quant;
134 
135    struct ureg_dst *tmp;
136    struct ureg_dst quant, fragment;
137 
138    unsigned i;
139 
140    shader = ureg_create(PIPE_SHADER_FRAGMENT);
141    if (!shader)
142       return NULL;
143 
144    vtex = MALLOC(zscan->num_channels * sizeof(struct ureg_src));
145    tmp = MALLOC(zscan->num_channels * sizeof(struct ureg_dst));
146 
147    for (i = 0; i < zscan->num_channels; ++i)
148       vtex[i] = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_VTEX + i, TGSI_INTERPOLATE_LINEAR);
149 
150    samp_src = ureg_DECL_sampler(shader, 0);
151    samp_scan = ureg_DECL_sampler(shader, 1);
152    samp_quant = ureg_DECL_sampler(shader, 2);
153 
154    for (i = 0; i < zscan->num_channels; ++i)
155       tmp[i] = ureg_DECL_temporary(shader);
156    quant = ureg_DECL_temporary(shader);
157 
158    fragment = ureg_DECL_output(shader, TGSI_SEMANTIC_COLOR, 0);
159 
160    /*
161     * tmp.x = tex(vtex, 1)
162     * tmp.y = vtex.z
163     * fragment = tex(tmp, 0) * quant
164     */
165    for (i = 0; i < zscan->num_channels; ++i)
166       ureg_TEX(shader, ureg_writemask(tmp[i], TGSI_WRITEMASK_X), TGSI_TEXTURE_2D, vtex[i], samp_scan);
167 
168    for (i = 0; i < zscan->num_channels; ++i)
169       ureg_MOV(shader, ureg_writemask(tmp[i], TGSI_WRITEMASK_Y), ureg_scalar(vtex[i], TGSI_SWIZZLE_W));
170 
171    for (i = 0; i < zscan->num_channels; ++i) {
172       ureg_TEX(shader, ureg_writemask(tmp[0], TGSI_WRITEMASK_X << i), TGSI_TEXTURE_2D, ureg_src(tmp[i]), samp_src);
173       ureg_TEX(shader, ureg_writemask(quant, TGSI_WRITEMASK_X << i), TGSI_TEXTURE_3D, vtex[i], samp_quant);
174    }
175 
176    ureg_MUL(shader, quant, ureg_src(quant), ureg_imm1f(shader, 16.0f));
177    ureg_MUL(shader, fragment, ureg_src(tmp[0]), ureg_src(quant));
178 
179    for (i = 0; i < zscan->num_channels; ++i)
180       ureg_release_temporary(shader, tmp[i]);
181    ureg_END(shader);
182 
183    FREE(vtex);
184    FREE(tmp);
185 
186    return ureg_create_shader_and_destroy(shader, zscan->pipe);
187 }
188 
189 static bool
init_shaders(struct vl_zscan * zscan)190 init_shaders(struct vl_zscan *zscan)
191 {
192    assert(zscan);
193 
194    zscan->vs = create_vert_shader(zscan);
195    if (!zscan->vs)
196       goto error_vs;
197 
198    zscan->fs = create_frag_shader(zscan);
199    if (!zscan->fs)
200       goto error_fs;
201 
202    return true;
203 
204 error_fs:
205    zscan->pipe->delete_vs_state(zscan->pipe, zscan->vs);
206 
207 error_vs:
208    return false;
209 }
210 
211 static void
cleanup_shaders(struct vl_zscan * zscan)212 cleanup_shaders(struct vl_zscan *zscan)
213 {
214    assert(zscan);
215 
216    zscan->pipe->delete_vs_state(zscan->pipe, zscan->vs);
217    zscan->pipe->delete_fs_state(zscan->pipe, zscan->fs);
218 }
219 
220 static bool
init_state(struct vl_zscan * zscan)221 init_state(struct vl_zscan *zscan)
222 {
223    struct pipe_blend_state blend;
224    struct pipe_rasterizer_state rs_state;
225    struct pipe_sampler_state sampler;
226    unsigned i;
227 
228    assert(zscan);
229 
230    memset(&rs_state, 0, sizeof(rs_state));
231    rs_state.half_pixel_center = true;
232    rs_state.bottom_edge_rule = true;
233    rs_state.depth_clip_near = 1;
234    rs_state.depth_clip_far = 1;
235 
236    zscan->rs_state = zscan->pipe->create_rasterizer_state(zscan->pipe, &rs_state);
237    if (!zscan->rs_state)
238       goto error_rs_state;
239 
240    memset(&blend, 0, sizeof blend);
241 
242    blend.independent_blend_enable = 0;
243    blend.rt[0].blend_enable = 0;
244    blend.rt[0].rgb_func = PIPE_BLEND_ADD;
245    blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE;
246    blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ONE;
247    blend.rt[0].alpha_func = PIPE_BLEND_ADD;
248    blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE;
249    blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ONE;
250    blend.logicop_enable = 0;
251    blend.logicop_func = PIPE_LOGICOP_CLEAR;
252    /* Needed to allow color writes to FB, even if blending disabled */
253    blend.rt[0].colormask = PIPE_MASK_RGBA;
254    blend.dither = 0;
255    zscan->blend = zscan->pipe->create_blend_state(zscan->pipe, &blend);
256    if (!zscan->blend)
257       goto error_blend;
258 
259    for (i = 0; i < 3; ++i) {
260       memset(&sampler, 0, sizeof(sampler));
261       sampler.wrap_s = PIPE_TEX_WRAP_REPEAT;
262       sampler.wrap_t = PIPE_TEX_WRAP_REPEAT;
263       sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
264       sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST;
265       sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
266       sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST;
267       sampler.compare_mode = PIPE_TEX_COMPARE_NONE;
268       sampler.compare_func = PIPE_FUNC_ALWAYS;
269       zscan->samplers[i] = zscan->pipe->create_sampler_state(zscan->pipe, &sampler);
270       if (!zscan->samplers[i])
271          goto error_samplers;
272    }
273 
274    return true;
275 
276 error_samplers:
277    for (i = 0; i < 2; ++i)
278       if (zscan->samplers[i])
279          zscan->pipe->delete_sampler_state(zscan->pipe, zscan->samplers[i]);
280 
281    zscan->pipe->delete_rasterizer_state(zscan->pipe, zscan->rs_state);
282 
283 error_blend:
284    zscan->pipe->delete_blend_state(zscan->pipe, zscan->blend);
285 
286 error_rs_state:
287    return false;
288 }
289 
290 static void
cleanup_state(struct vl_zscan * zscan)291 cleanup_state(struct vl_zscan *zscan)
292 {
293    unsigned i;
294 
295    assert(zscan);
296 
297    for (i = 0; i < 3; ++i)
298       zscan->pipe->delete_sampler_state(zscan->pipe, zscan->samplers[i]);
299 
300    zscan->pipe->delete_rasterizer_state(zscan->pipe, zscan->rs_state);
301    zscan->pipe->delete_blend_state(zscan->pipe, zscan->blend);
302 }
303 
304 struct pipe_sampler_view *
vl_zscan_layout(struct pipe_context * pipe,const int layout[64],unsigned blocks_per_line)305 vl_zscan_layout(struct pipe_context *pipe, const int layout[64], unsigned blocks_per_line)
306 {
307    const unsigned total_size = blocks_per_line * VL_BLOCK_WIDTH * VL_BLOCK_HEIGHT;
308 
309    int patched_layout[64];
310 
311    struct pipe_resource res_tmpl, *res;
312    struct pipe_sampler_view sv_tmpl, *sv;
313    struct pipe_transfer *buf_transfer;
314    unsigned x, y, i, pitch;
315    float *f;
316 
317    struct pipe_box rect =
318    {
319       0, 0, 0,
320       VL_BLOCK_WIDTH * blocks_per_line,
321       VL_BLOCK_HEIGHT,
322       1
323    };
324 
325    assert(pipe && layout && blocks_per_line);
326 
327    for (i = 0; i < 64; ++i)
328       patched_layout[layout[i]] = i;
329 
330    memset(&res_tmpl, 0, sizeof(res_tmpl));
331    res_tmpl.target = PIPE_TEXTURE_2D;
332    res_tmpl.format = PIPE_FORMAT_R32_FLOAT;
333    res_tmpl.width0 = VL_BLOCK_WIDTH * blocks_per_line;
334    res_tmpl.height0 = VL_BLOCK_HEIGHT;
335    res_tmpl.depth0 = 1;
336    res_tmpl.array_size = 1;
337    res_tmpl.usage = PIPE_USAGE_IMMUTABLE;
338    res_tmpl.bind = PIPE_BIND_SAMPLER_VIEW;
339 
340    res = pipe->screen->resource_create(pipe->screen, &res_tmpl);
341    if (!res)
342       goto error_resource;
343 
344    f = pipe->texture_map(pipe, res,
345                           0, PIPE_MAP_WRITE | PIPE_MAP_DISCARD_RANGE,
346                           &rect, &buf_transfer);
347    if (!f)
348       goto error_map;
349 
350    pitch = buf_transfer->stride / sizeof(float);
351 
352    for (i = 0; i < blocks_per_line; ++i)
353       for (y = 0; y < VL_BLOCK_HEIGHT; ++y)
354          for (x = 0; x < VL_BLOCK_WIDTH; ++x) {
355             float addr = patched_layout[x + y * VL_BLOCK_WIDTH] +
356                i * VL_BLOCK_WIDTH * VL_BLOCK_HEIGHT;
357 
358             addr /= total_size;
359 
360             f[i * VL_BLOCK_WIDTH + y * pitch + x] = addr;
361          }
362 
363    pipe->texture_unmap(pipe, buf_transfer);
364 
365    memset(&sv_tmpl, 0, sizeof(sv_tmpl));
366    u_sampler_view_default_template(&sv_tmpl, res, res->format);
367    sv = pipe->create_sampler_view(pipe, res, &sv_tmpl);
368    pipe_resource_reference(&res, NULL);
369    if (!sv)
370       goto error_map;
371 
372    return sv;
373 
374 error_map:
375    pipe_resource_reference(&res, NULL);
376 
377 error_resource:
378    return NULL;
379 }
380 
381 bool
vl_zscan_init(struct vl_zscan * zscan,struct pipe_context * pipe,unsigned buffer_width,unsigned buffer_height,unsigned blocks_per_line,unsigned blocks_total,unsigned num_channels)382 vl_zscan_init(struct vl_zscan *zscan, struct pipe_context *pipe,
383               unsigned buffer_width, unsigned buffer_height,
384               unsigned blocks_per_line, unsigned blocks_total,
385               unsigned num_channels)
386 {
387    assert(zscan && pipe);
388 
389    zscan->pipe = pipe;
390    zscan->buffer_width = buffer_width;
391    zscan->buffer_height = buffer_height;
392    zscan->num_channels = num_channels;
393    zscan->blocks_per_line = blocks_per_line;
394    zscan->blocks_total = blocks_total;
395 
396    if(!init_shaders(zscan))
397       return false;
398 
399    if(!init_state(zscan)) {
400       cleanup_shaders(zscan);
401       return false;
402    }
403 
404    return true;
405 }
406 
407 void
vl_zscan_cleanup(struct vl_zscan * zscan)408 vl_zscan_cleanup(struct vl_zscan *zscan)
409 {
410    assert(zscan);
411 
412    cleanup_shaders(zscan);
413    cleanup_state(zscan);
414 }
415 
416 bool
vl_zscan_init_buffer(struct vl_zscan * zscan,struct vl_zscan_buffer * buffer,struct pipe_sampler_view * src,struct pipe_surface * dst)417 vl_zscan_init_buffer(struct vl_zscan *zscan, struct vl_zscan_buffer *buffer,
418                      struct pipe_sampler_view *src, struct pipe_surface *dst)
419 {
420    struct pipe_resource res_tmpl, *res;
421    struct pipe_sampler_view sv_tmpl;
422 
423    assert(zscan && buffer);
424 
425    memset(buffer, 0, sizeof(struct vl_zscan_buffer));
426 
427    pipe_sampler_view_reference(&buffer->src, src);
428 
429    buffer->viewport.scale[0] = dst->width;
430    buffer->viewport.scale[1] = dst->height;
431    buffer->viewport.scale[2] = 1;
432    buffer->viewport.translate[0] = 0;
433    buffer->viewport.translate[1] = 0;
434    buffer->viewport.translate[2] = 0;
435    buffer->viewport.swizzle_x = PIPE_VIEWPORT_SWIZZLE_POSITIVE_X;
436    buffer->viewport.swizzle_y = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Y;
437    buffer->viewport.swizzle_z = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Z;
438    buffer->viewport.swizzle_w = PIPE_VIEWPORT_SWIZZLE_POSITIVE_W;
439 
440    buffer->fb_state.width = dst->width;
441    buffer->fb_state.height = dst->height;
442    buffer->fb_state.nr_cbufs = 1;
443    pipe_surface_reference(&buffer->fb_state.cbufs[0], dst);
444 
445    memset(&res_tmpl, 0, sizeof(res_tmpl));
446    res_tmpl.target = PIPE_TEXTURE_3D;
447    res_tmpl.format = PIPE_FORMAT_R8_UNORM;
448    res_tmpl.width0 = VL_BLOCK_WIDTH * zscan->blocks_per_line;
449    res_tmpl.height0 = VL_BLOCK_HEIGHT;
450    res_tmpl.depth0 = 2;
451    res_tmpl.array_size = 1;
452    res_tmpl.usage = PIPE_USAGE_IMMUTABLE;
453    res_tmpl.bind = PIPE_BIND_SAMPLER_VIEW;
454 
455    res = zscan->pipe->screen->resource_create(zscan->pipe->screen, &res_tmpl);
456    if (!res)
457       return false;
458 
459    memset(&sv_tmpl, 0, sizeof(sv_tmpl));
460    u_sampler_view_default_template(&sv_tmpl, res, res->format);
461    sv_tmpl.swizzle_r = sv_tmpl.swizzle_g = sv_tmpl.swizzle_b = sv_tmpl.swizzle_a = TGSI_SWIZZLE_X;
462    buffer->quant = zscan->pipe->create_sampler_view(zscan->pipe, res, &sv_tmpl);
463    pipe_resource_reference(&res, NULL);
464    if (!buffer->quant)
465       return false;
466 
467    return true;
468 }
469 
470 void
vl_zscan_cleanup_buffer(struct vl_zscan_buffer * buffer)471 vl_zscan_cleanup_buffer(struct vl_zscan_buffer *buffer)
472 {
473    assert(buffer);
474 
475    pipe_sampler_view_reference(&buffer->src, NULL);
476    pipe_sampler_view_reference(&buffer->layout, NULL);
477    pipe_sampler_view_reference(&buffer->quant, NULL);
478    pipe_surface_reference(&buffer->fb_state.cbufs[0], NULL);
479 }
480 
481 void
vl_zscan_set_layout(struct vl_zscan_buffer * buffer,struct pipe_sampler_view * layout)482 vl_zscan_set_layout(struct vl_zscan_buffer *buffer, struct pipe_sampler_view *layout)
483 {
484    assert(buffer);
485    assert(layout);
486 
487    pipe_sampler_view_reference(&buffer->layout, layout);
488 }
489 
490 void
vl_zscan_upload_quant(struct vl_zscan * zscan,struct vl_zscan_buffer * buffer,const uint8_t matrix[64],bool intra)491 vl_zscan_upload_quant(struct vl_zscan *zscan, struct vl_zscan_buffer *buffer,
492                       const uint8_t matrix[64], bool intra)
493 {
494    struct pipe_context *pipe;
495    struct pipe_transfer *buf_transfer;
496    unsigned x, y, i, pitch;
497    uint8_t *data;
498 
499    struct pipe_box rect =
500    {
501       0, 0, intra ? 1 : 0,
502       VL_BLOCK_WIDTH,
503       VL_BLOCK_HEIGHT,
504       1
505    };
506 
507    assert(buffer);
508    assert(matrix);
509 
510    pipe = zscan->pipe;
511 
512    rect.width *= zscan->blocks_per_line;
513 
514    data = pipe->texture_map(pipe, buffer->quant->texture,
515                              0, PIPE_MAP_WRITE |
516                              PIPE_MAP_DISCARD_RANGE,
517                              &rect, &buf_transfer);
518    if (!data)
519       return;
520 
521    pitch = buf_transfer->stride;
522 
523    for (i = 0; i < zscan->blocks_per_line; ++i)
524       for (y = 0; y < VL_BLOCK_HEIGHT; ++y)
525          for (x = 0; x < VL_BLOCK_WIDTH; ++x)
526             data[i * VL_BLOCK_WIDTH + y * pitch + x] = matrix[x + y * VL_BLOCK_WIDTH];
527 
528    pipe->texture_unmap(pipe, buf_transfer);
529 }
530 
531 void
vl_zscan_render(struct vl_zscan * zscan,struct vl_zscan_buffer * buffer,unsigned num_instances)532 vl_zscan_render(struct vl_zscan *zscan, struct vl_zscan_buffer *buffer, unsigned num_instances)
533 {
534    assert(buffer);
535 
536    zscan->pipe->bind_rasterizer_state(zscan->pipe, zscan->rs_state);
537    zscan->pipe->bind_blend_state(zscan->pipe, zscan->blend);
538    zscan->pipe->bind_sampler_states(zscan->pipe, PIPE_SHADER_FRAGMENT,
539                                     0, 3, zscan->samplers);
540    zscan->pipe->set_framebuffer_state(zscan->pipe, &buffer->fb_state);
541    zscan->pipe->set_viewport_states(zscan->pipe, 0, 1, &buffer->viewport);
542    zscan->pipe->set_sampler_views(zscan->pipe, PIPE_SHADER_FRAGMENT,
543                                   0, 3, 0, false, &buffer->src);
544    zscan->pipe->bind_vs_state(zscan->pipe, zscan->vs);
545    zscan->pipe->bind_fs_state(zscan->pipe, zscan->fs);
546    util_draw_arrays_instanced(zscan->pipe, MESA_PRIM_QUADS, 0, 4, 0, num_instances);
547 }
548