xref: /aosp_15_r20/external/mesa3d/src/gallium/auxiliary/vl/vl_zscan.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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    u_box_3d(0, 0, 0,
319             VL_BLOCK_WIDTH * blocks_per_line,
320             VL_BLOCK_HEIGHT,
321             1, &rect);
322 
323    assert(pipe && layout && blocks_per_line);
324 
325    for (i = 0; i < 64; ++i)
326       patched_layout[layout[i]] = i;
327 
328    memset(&res_tmpl, 0, sizeof(res_tmpl));
329    res_tmpl.target = PIPE_TEXTURE_2D;
330    res_tmpl.format = PIPE_FORMAT_R32_FLOAT;
331    res_tmpl.width0 = VL_BLOCK_WIDTH * blocks_per_line;
332    res_tmpl.height0 = VL_BLOCK_HEIGHT;
333    res_tmpl.depth0 = 1;
334    res_tmpl.array_size = 1;
335    res_tmpl.usage = PIPE_USAGE_IMMUTABLE;
336    res_tmpl.bind = PIPE_BIND_SAMPLER_VIEW;
337 
338    res = pipe->screen->resource_create(pipe->screen, &res_tmpl);
339    if (!res)
340       goto error_resource;
341 
342    f = pipe->texture_map(pipe, res,
343                           0, PIPE_MAP_WRITE | PIPE_MAP_DISCARD_RANGE,
344                           &rect, &buf_transfer);
345    if (!f)
346       goto error_map;
347 
348    pitch = buf_transfer->stride / sizeof(float);
349 
350    for (i = 0; i < blocks_per_line; ++i)
351       for (y = 0; y < VL_BLOCK_HEIGHT; ++y)
352          for (x = 0; x < VL_BLOCK_WIDTH; ++x) {
353             float addr = patched_layout[x + y * VL_BLOCK_WIDTH] +
354                i * VL_BLOCK_WIDTH * VL_BLOCK_HEIGHT;
355 
356             addr /= total_size;
357 
358             f[i * VL_BLOCK_WIDTH + y * pitch + x] = addr;
359          }
360 
361    pipe->texture_unmap(pipe, buf_transfer);
362 
363    memset(&sv_tmpl, 0, sizeof(sv_tmpl));
364    u_sampler_view_default_template(&sv_tmpl, res, res->format);
365    sv = pipe->create_sampler_view(pipe, res, &sv_tmpl);
366    pipe_resource_reference(&res, NULL);
367    if (!sv)
368       goto error_map;
369 
370    return sv;
371 
372 error_map:
373    pipe_resource_reference(&res, NULL);
374 
375 error_resource:
376    return NULL;
377 }
378 
379 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)380 vl_zscan_init(struct vl_zscan *zscan, struct pipe_context *pipe,
381               unsigned buffer_width, unsigned buffer_height,
382               unsigned blocks_per_line, unsigned blocks_total,
383               unsigned num_channels)
384 {
385    assert(zscan && pipe);
386 
387    zscan->pipe = pipe;
388    zscan->buffer_width = buffer_width;
389    zscan->buffer_height = buffer_height;
390    zscan->num_channels = num_channels;
391    zscan->blocks_per_line = blocks_per_line;
392    zscan->blocks_total = blocks_total;
393 
394    if(!init_shaders(zscan))
395       return false;
396 
397    if(!init_state(zscan)) {
398       cleanup_shaders(zscan);
399       return false;
400    }
401 
402    return true;
403 }
404 
405 void
vl_zscan_cleanup(struct vl_zscan * zscan)406 vl_zscan_cleanup(struct vl_zscan *zscan)
407 {
408    assert(zscan);
409 
410    cleanup_shaders(zscan);
411    cleanup_state(zscan);
412 }
413 
414 bool
vl_zscan_init_buffer(struct vl_zscan * zscan,struct vl_zscan_buffer * buffer,struct pipe_sampler_view * src,struct pipe_surface * dst)415 vl_zscan_init_buffer(struct vl_zscan *zscan, struct vl_zscan_buffer *buffer,
416                      struct pipe_sampler_view *src, struct pipe_surface *dst)
417 {
418    struct pipe_resource res_tmpl, *res;
419    struct pipe_sampler_view sv_tmpl;
420 
421    assert(zscan && buffer);
422 
423    memset(buffer, 0, sizeof(struct vl_zscan_buffer));
424 
425    pipe_sampler_view_reference(&buffer->src, src);
426 
427    buffer->viewport.scale[0] = dst->width;
428    buffer->viewport.scale[1] = dst->height;
429    buffer->viewport.scale[2] = 1;
430    buffer->viewport.translate[0] = 0;
431    buffer->viewport.translate[1] = 0;
432    buffer->viewport.translate[2] = 0;
433    buffer->viewport.swizzle_x = PIPE_VIEWPORT_SWIZZLE_POSITIVE_X;
434    buffer->viewport.swizzle_y = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Y;
435    buffer->viewport.swizzle_z = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Z;
436    buffer->viewport.swizzle_w = PIPE_VIEWPORT_SWIZZLE_POSITIVE_W;
437 
438    buffer->fb_state.width = dst->width;
439    buffer->fb_state.height = dst->height;
440    buffer->fb_state.nr_cbufs = 1;
441    pipe_surface_reference(&buffer->fb_state.cbufs[0], dst);
442 
443    memset(&res_tmpl, 0, sizeof(res_tmpl));
444    res_tmpl.target = PIPE_TEXTURE_3D;
445    res_tmpl.format = PIPE_FORMAT_R8_UNORM;
446    res_tmpl.width0 = VL_BLOCK_WIDTH * zscan->blocks_per_line;
447    res_tmpl.height0 = VL_BLOCK_HEIGHT;
448    res_tmpl.depth0 = 2;
449    res_tmpl.array_size = 1;
450    res_tmpl.usage = PIPE_USAGE_IMMUTABLE;
451    res_tmpl.bind = PIPE_BIND_SAMPLER_VIEW;
452 
453    res = zscan->pipe->screen->resource_create(zscan->pipe->screen, &res_tmpl);
454    if (!res)
455       return false;
456 
457    memset(&sv_tmpl, 0, sizeof(sv_tmpl));
458    u_sampler_view_default_template(&sv_tmpl, res, res->format);
459    sv_tmpl.swizzle_r = sv_tmpl.swizzle_g = sv_tmpl.swizzle_b = sv_tmpl.swizzle_a = TGSI_SWIZZLE_X;
460    buffer->quant = zscan->pipe->create_sampler_view(zscan->pipe, res, &sv_tmpl);
461    pipe_resource_reference(&res, NULL);
462    if (!buffer->quant)
463       return false;
464 
465    return true;
466 }
467 
468 void
vl_zscan_cleanup_buffer(struct vl_zscan_buffer * buffer)469 vl_zscan_cleanup_buffer(struct vl_zscan_buffer *buffer)
470 {
471    assert(buffer);
472 
473    pipe_sampler_view_reference(&buffer->src, NULL);
474    pipe_sampler_view_reference(&buffer->layout, NULL);
475    pipe_sampler_view_reference(&buffer->quant, NULL);
476    pipe_surface_reference(&buffer->fb_state.cbufs[0], NULL);
477 }
478 
479 void
vl_zscan_set_layout(struct vl_zscan_buffer * buffer,struct pipe_sampler_view * layout)480 vl_zscan_set_layout(struct vl_zscan_buffer *buffer, struct pipe_sampler_view *layout)
481 {
482    assert(buffer);
483    assert(layout);
484 
485    pipe_sampler_view_reference(&buffer->layout, layout);
486 }
487 
488 void
vl_zscan_upload_quant(struct vl_zscan * zscan,struct vl_zscan_buffer * buffer,const uint8_t matrix[64],bool intra)489 vl_zscan_upload_quant(struct vl_zscan *zscan, struct vl_zscan_buffer *buffer,
490                       const uint8_t matrix[64], bool intra)
491 {
492    struct pipe_context *pipe;
493    struct pipe_transfer *buf_transfer;
494    unsigned x, y, i, pitch;
495    uint8_t *data;
496 
497    struct pipe_box rect;
498    u_box_3d(0, 0, intra ? 1 : 0,
499             VL_BLOCK_WIDTH,
500             VL_BLOCK_HEIGHT,
501             1, &rect);
502 
503    assert(buffer);
504    assert(matrix);
505 
506    pipe = zscan->pipe;
507 
508    rect.width *= zscan->blocks_per_line;
509 
510    data = pipe->texture_map(pipe, buffer->quant->texture,
511                              0, PIPE_MAP_WRITE |
512                              PIPE_MAP_DISCARD_RANGE,
513                              &rect, &buf_transfer);
514    if (!data)
515       return;
516 
517    pitch = buf_transfer->stride;
518 
519    for (i = 0; i < zscan->blocks_per_line; ++i)
520       for (y = 0; y < VL_BLOCK_HEIGHT; ++y)
521          for (x = 0; x < VL_BLOCK_WIDTH; ++x)
522             data[i * VL_BLOCK_WIDTH + y * pitch + x] = matrix[x + y * VL_BLOCK_WIDTH];
523 
524    pipe->texture_unmap(pipe, buf_transfer);
525 }
526 
527 void
vl_zscan_render(struct vl_zscan * zscan,struct vl_zscan_buffer * buffer,unsigned num_instances)528 vl_zscan_render(struct vl_zscan *zscan, struct vl_zscan_buffer *buffer, unsigned num_instances)
529 {
530    assert(buffer);
531 
532    zscan->pipe->bind_rasterizer_state(zscan->pipe, zscan->rs_state);
533    zscan->pipe->bind_blend_state(zscan->pipe, zscan->blend);
534    zscan->pipe->bind_sampler_states(zscan->pipe, PIPE_SHADER_FRAGMENT,
535                                     0, 3, zscan->samplers);
536    zscan->pipe->set_framebuffer_state(zscan->pipe, &buffer->fb_state);
537    zscan->pipe->set_viewport_states(zscan->pipe, 0, 1, &buffer->viewport);
538    zscan->pipe->set_sampler_views(zscan->pipe, PIPE_SHADER_FRAGMENT,
539                                   0, 3, 0, false, &buffer->src);
540    zscan->pipe->bind_vs_state(zscan->pipe, zscan->vs);
541    zscan->pipe->bind_fs_state(zscan->pipe, zscan->fs);
542    util_draw_arrays_instanced(zscan->pipe, MESA_PRIM_QUADS, 0, 4, 0, num_instances);
543 }
544