• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2018 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #include "isl/isl.h"
25 
26 #include "brw_nir.h"
27 #include "compiler/nir/nir_builder.h"
28 #include "compiler/nir/nir_format_convert.h"
29 
30 static nir_def *
_load_image_param(nir_builder * b,nir_deref_instr * deref,unsigned offset)31 _load_image_param(nir_builder *b, nir_deref_instr *deref, unsigned offset)
32 {
33    nir_intrinsic_instr *load =
34       nir_intrinsic_instr_create(b->shader,
35                                  nir_intrinsic_image_deref_load_param_intel);
36    load->src[0] = nir_src_for_ssa(&deref->def);
37    nir_intrinsic_set_base(load, offset / 4);
38 
39    switch (offset) {
40    case ISL_IMAGE_PARAM_OFFSET_OFFSET:
41    case ISL_IMAGE_PARAM_SWIZZLING_OFFSET:
42       load->num_components = 2;
43       break;
44    case ISL_IMAGE_PARAM_TILING_OFFSET:
45    case ISL_IMAGE_PARAM_SIZE_OFFSET:
46       load->num_components = 3;
47       break;
48    case ISL_IMAGE_PARAM_STRIDE_OFFSET:
49       load->num_components = 4;
50       break;
51    default:
52       unreachable("Invalid param offset");
53    }
54    nir_def_init(&load->instr, &load->def, load->num_components, 32);
55 
56    nir_builder_instr_insert(b, &load->instr);
57    return &load->def;
58 }
59 
60 #define load_image_param(b, d, o) \
61    _load_image_param(b, d, ISL_IMAGE_PARAM_##o##_OFFSET)
62 
63 static nir_def *
image_coord_is_in_bounds(nir_builder * b,nir_deref_instr * deref,nir_def * coord)64 image_coord_is_in_bounds(nir_builder *b, nir_deref_instr *deref,
65                          nir_def *coord)
66 {
67    nir_def *size = load_image_param(b, deref, SIZE);
68    nir_def *cmp = nir_ilt(b, coord, size);
69 
70    unsigned coord_comps = glsl_get_sampler_coordinate_components(deref->type);
71    nir_def *in_bounds = nir_imm_true(b);
72    for (unsigned i = 0; i < coord_comps; i++)
73       in_bounds = nir_iand(b, in_bounds, nir_channel(b, cmp, i));
74 
75    return in_bounds;
76 }
77 
78 /** Calculate the offset in memory of the texel given by \p coord.
79  *
80  * This is meant to be used with untyped surface messages to access a tiled
81  * surface, what involves taking into account the tiling and swizzling modes
82  * of the surface manually so it will hopefully not happen very often.
83  *
84  * The tiling algorithm implemented here matches either the X or Y tiling
85  * layouts supported by the hardware depending on the tiling coefficients
86  * passed to the program as uniforms.  See Volume 1 Part 2 Section 4.5
87  * "Address Tiling Function" of the IVB PRM for an in-depth explanation of
88  * the hardware tiling format.
89  */
90 static nir_def *
image_address(nir_builder * b,const struct intel_device_info * devinfo,nir_deref_instr * deref,nir_def * coord)91 image_address(nir_builder *b, const struct intel_device_info *devinfo,
92               nir_deref_instr *deref, nir_def *coord)
93 {
94    if (glsl_get_sampler_dim(deref->type) == GLSL_SAMPLER_DIM_1D &&
95        glsl_sampler_type_is_array(deref->type)) {
96       /* It's easier if 1D arrays are treated like 2D arrays */
97       coord = nir_vec3(b, nir_channel(b, coord, 0),
98                           nir_imm_int(b, 0),
99                           nir_channel(b, coord, 1));
100    } else {
101       unsigned dims = glsl_get_sampler_coordinate_components(deref->type);
102       coord = nir_trim_vector(b, coord, dims);
103    }
104 
105    nir_def *offset = load_image_param(b, deref, OFFSET);
106    nir_def *tiling = load_image_param(b, deref, TILING);
107    nir_def *stride = load_image_param(b, deref, STRIDE);
108 
109    /* Shift the coordinates by the fixed surface offset.  It may be non-zero
110     * if the image is a single slice of a higher-dimensional surface, or if a
111     * non-zero mipmap level of the surface is bound to the pipeline.  The
112     * offset needs to be applied here rather than at surface state set-up time
113     * because the desired slice-level may start mid-tile, so simply shifting
114     * the surface base address wouldn't give a well-formed tiled surface in
115     * the general case.
116     */
117    nir_def *xypos = (coord->num_components == 1) ?
118                         nir_vec2(b, coord, nir_imm_int(b, 0)) :
119                         nir_trim_vector(b, coord, 2);
120    xypos = nir_iadd(b, xypos, offset);
121 
122    /* The layout of 3-D textures in memory is sort-of like a tiling
123     * format.  At each miplevel, the slices are arranged in rows of
124     * 2^level slices per row.  The slice row is stored in tmp.y and
125     * the slice within the row is stored in tmp.x.
126     *
127     * The layout of 2-D array textures and cubemaps is much simpler:
128     * Depending on whether the ARYSPC_LOD0 layout is in use it will be
129     * stored in memory as an array of slices, each one being a 2-D
130     * arrangement of miplevels, or as a 2D arrangement of miplevels,
131     * each one being an array of slices.  In either case the separation
132     * between slices of the same LOD is equal to the qpitch value
133     * provided as stride.w.
134     *
135     * This code can be made to handle either 2D arrays and 3D textures
136     * by passing in the miplevel as tile.z for 3-D textures and 0 in
137     * tile.z for 2-D array textures.
138     *
139     * See Volume 1 Part 1 of the Gfx7 PRM, sections 6.18.4.7 "Surface
140     * Arrays" and 6.18.6 "3D Surfaces" for a more extensive discussion
141     * of the hardware 3D texture and 2D array layouts.
142     */
143    if (coord->num_components > 2) {
144       /* Decompose z into a major (tmp.y) and a minor (tmp.x)
145        * index.
146        */
147       nir_def *z = nir_channel(b, coord, 2);
148       nir_def *z_x = nir_ubfe(b, z, nir_imm_int(b, 0),
149                                   nir_channel(b, tiling, 2));
150       nir_def *z_y = nir_ushr(b, z, nir_channel(b, tiling, 2));
151 
152       /* Take into account the horizontal (tmp.x) and vertical (tmp.y)
153        * slice offset.
154        */
155       xypos = nir_iadd(b, xypos, nir_imul(b, nir_vec2(b, z_x, z_y),
156                                              nir_channels(b, stride, 0xc)));
157    }
158 
159    nir_def *addr;
160    if (coord->num_components > 1) {
161       /* Calculate the major/minor x and y indices.  In order to
162        * accommodate both X and Y tiling, the Y-major tiling format is
163        * treated as being a bunch of narrow X-tiles placed next to each
164        * other.  This means that the tile width for Y-tiling is actually
165        * the width of one sub-column of the Y-major tile where each 4K
166        * tile has 8 512B sub-columns.
167        *
168        * The major Y value is the row of tiles in which the pixel lives.
169        * The major X value is the tile sub-column in which the pixel
170        * lives; for X tiling, this is the same as the tile column, for Y
171        * tiling, each tile has 8 sub-columns.  The minor X and Y indices
172        * are the position within the sub-column.
173        */
174 
175       /* Calculate the minor x and y indices. */
176       nir_def *minor = nir_ubfe(b, xypos, nir_imm_int(b, 0),
177                                        nir_trim_vector(b, tiling, 2));
178       nir_def *major = nir_ushr(b, xypos, nir_trim_vector(b, tiling, 2));
179 
180       /* Calculate the texel index from the start of the tile row and the
181        * vertical coordinate of the row.
182        * Equivalent to:
183        *   tmp.x = (major.x << tile.y << tile.x) +
184        *           (minor.y << tile.x) + minor.x
185        *   tmp.y = major.y << tile.y
186        */
187       nir_def *idx_x, *idx_y;
188       idx_x = nir_ishl(b, nir_channel(b, major, 0), nir_channel(b, tiling, 1));
189       idx_x = nir_iadd(b, idx_x, nir_channel(b, minor, 1));
190       idx_x = nir_ishl(b, idx_x, nir_channel(b, tiling, 0));
191       idx_x = nir_iadd(b, idx_x, nir_channel(b, minor, 0));
192       idx_y = nir_ishl(b, nir_channel(b, major, 1), nir_channel(b, tiling, 1));
193 
194       /* Add it to the start of the tile row. */
195       nir_def *idx;
196       idx = nir_imul(b, idx_y, nir_channel(b, stride, 1));
197       idx = nir_iadd(b, idx, idx_x);
198 
199       /* Multiply by the Bpp value. */
200       addr = nir_imul(b, idx, nir_channel(b, stride, 0));
201    } else {
202       /* Multiply by the Bpp/stride value.  Note that the addr.y may be
203        * non-zero even if the image is one-dimensional because a vertical
204        * offset may have been applied above to select a non-zero slice or
205        * level of a higher-dimensional texture.
206        */
207       nir_def *idx;
208       idx = nir_imul(b, nir_channel(b, xypos, 1), nir_channel(b, stride, 1));
209       idx = nir_iadd(b, nir_channel(b, xypos, 0), idx);
210       addr = nir_imul(b, idx, nir_channel(b, stride, 0));
211    }
212 
213    return addr;
214 }
215 
216 struct format_info {
217    const struct isl_format_layout *fmtl;
218    unsigned chans;
219    unsigned bits[4];
220 };
221 
222 static struct format_info
get_format_info(enum isl_format fmt)223 get_format_info(enum isl_format fmt)
224 {
225    const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);
226 
227    return (struct format_info) {
228       .fmtl = fmtl,
229       .chans = isl_format_get_num_channels(fmt),
230       .bits = {
231          fmtl->channels.r.bits,
232          fmtl->channels.g.bits,
233          fmtl->channels.b.bits,
234          fmtl->channels.a.bits
235       },
236    };
237 }
238 
239 static nir_def *
convert_color_for_load(nir_builder * b,const struct intel_device_info * devinfo,nir_def * color,enum isl_format image_fmt,enum isl_format lower_fmt,unsigned dest_components)240 convert_color_for_load(nir_builder *b, const struct intel_device_info *devinfo,
241                        nir_def *color,
242                        enum isl_format image_fmt, enum isl_format lower_fmt,
243                        unsigned dest_components)
244 {
245    if (image_fmt == lower_fmt)
246       goto expand_vec;
247 
248    if (image_fmt == ISL_FORMAT_R11G11B10_FLOAT) {
249       assert(lower_fmt == ISL_FORMAT_R32_UINT);
250       color = nir_format_unpack_11f11f10f(b, color);
251       goto expand_vec;
252    }
253 
254    struct format_info image = get_format_info(image_fmt);
255    struct format_info lower = get_format_info(lower_fmt);
256 
257    const bool needs_sign_extension =
258       isl_format_has_snorm_channel(image_fmt) ||
259       isl_format_has_sint_channel(image_fmt);
260 
261    /* We only check the red channel to detect if we need to pack/unpack */
262    assert(image.bits[0] != lower.bits[0] ||
263           memcmp(image.bits, lower.bits, sizeof(image.bits)) == 0);
264 
265    if (image.bits[0] != lower.bits[0] && lower_fmt == ISL_FORMAT_R32_UINT) {
266       if (needs_sign_extension)
267          color = nir_format_unpack_sint(b, color, image.bits, image.chans);
268       else
269          color = nir_format_unpack_uint(b, color, image.bits, image.chans);
270    } else {
271       /* All these formats are homogeneous */
272       for (unsigned i = 1; i < image.chans; i++)
273          assert(image.bits[i] == image.bits[0]);
274 
275       if (image.bits[0] != lower.bits[0]) {
276          color = nir_format_bitcast_uvec_unmasked(b, color, lower.bits[0],
277                                                   image.bits[0]);
278       }
279 
280       if (needs_sign_extension)
281          color = nir_format_sign_extend_ivec(b, color, image.bits);
282    }
283 
284    switch (image.fmtl->channels.r.type) {
285    case ISL_UNORM:
286       assert(isl_format_has_uint_channel(lower_fmt));
287       color = nir_format_unorm_to_float(b, color, image.bits);
288       break;
289 
290    case ISL_SNORM:
291       assert(isl_format_has_uint_channel(lower_fmt));
292       color = nir_format_snorm_to_float(b, color, image.bits);
293       break;
294 
295    case ISL_SFLOAT:
296       if (image.bits[0] == 16)
297          color = nir_unpack_half_2x16_split_x(b, color);
298       break;
299 
300    case ISL_UINT:
301    case ISL_SINT:
302       break;
303 
304    default:
305       unreachable("Invalid image channel type");
306    }
307 
308 expand_vec:
309    assert(dest_components == 1 || dest_components == 4);
310    assert(color->num_components <= dest_components);
311    if (color->num_components == dest_components)
312       return color;
313 
314    nir_def *comps[4];
315    for (unsigned i = 0; i < color->num_components; i++)
316       comps[i] = nir_channel(b, color, i);
317 
318    for (unsigned i = color->num_components; i < 3; i++)
319       comps[i] = nir_imm_int(b, 0);
320 
321    if (color->num_components < 4) {
322       if (isl_format_has_int_channel(image_fmt))
323          comps[3] = nir_imm_int(b, 1);
324       else
325          comps[3] = nir_imm_float(b, 1);
326    }
327 
328    return nir_vec(b, comps, dest_components);
329 }
330 
331 static bool
lower_image_load_instr(nir_builder * b,const struct intel_device_info * devinfo,nir_intrinsic_instr * intrin,bool sparse)332 lower_image_load_instr(nir_builder *b,
333                        const struct intel_device_info *devinfo,
334                        nir_intrinsic_instr *intrin,
335                        bool sparse)
336 {
337    nir_deref_instr *deref = nir_src_as_deref(intrin->src[0]);
338    nir_variable *var = nir_deref_instr_get_variable(deref);
339 
340    if (var->data.image.format == PIPE_FORMAT_NONE)
341       return false;
342 
343    const enum isl_format image_fmt =
344       isl_format_for_pipe_format(var->data.image.format);
345 
346    if (isl_has_matching_typed_storage_image_format(devinfo, image_fmt)) {
347       const enum isl_format lower_fmt =
348          isl_lower_storage_image_format(devinfo, image_fmt);
349       const unsigned dest_components =
350          sparse ? (intrin->num_components - 1) : intrin->num_components;
351 
352       /* Use an undef to hold the uses of the load while we do the color
353        * conversion.
354        */
355       nir_def *placeholder = nir_undef(b, 4, 32);
356       nir_def_rewrite_uses(&intrin->def, placeholder);
357 
358       intrin->num_components = isl_format_get_num_channels(lower_fmt);
359       intrin->def.num_components = intrin->num_components;
360 
361       b->cursor = nir_after_instr(&intrin->instr);
362 
363       nir_def *color = convert_color_for_load(b, devinfo,
364                                                   &intrin->def,
365                                                   image_fmt, lower_fmt,
366                                                   dest_components);
367 
368       if (sparse) {
369          /* Put the sparse component back on the original instruction */
370          intrin->num_components++;
371          intrin->def.num_components = intrin->num_components;
372 
373          /* Carry over the sparse component without modifying it with the
374           * converted color.
375           */
376          nir_def *sparse_color[NIR_MAX_VEC_COMPONENTS];
377          for (unsigned i = 0; i < dest_components; i++)
378             sparse_color[i] = nir_channel(b, color, i);
379          sparse_color[dest_components] =
380             nir_channel(b, &intrin->def, intrin->num_components - 1);
381          color = nir_vec(b, sparse_color, dest_components + 1);
382       }
383 
384       nir_def_rewrite_uses(placeholder, color);
385       nir_instr_remove(placeholder->parent_instr);
386    } else {
387       /* This code part is only useful prior to Gfx9, we do not have plans to
388        * enable sparse there.
389        */
390       assert(!sparse);
391 
392       const struct isl_format_layout *image_fmtl =
393          isl_format_get_layout(image_fmt);
394       /* We have a matching typed format for everything 32b and below */
395       assert(image_fmtl->bpb == 64 || image_fmtl->bpb == 128);
396       enum isl_format raw_fmt = (image_fmtl->bpb == 64) ?
397                                 ISL_FORMAT_R32G32_UINT :
398                                 ISL_FORMAT_R32G32B32A32_UINT;
399       const unsigned dest_components = intrin->num_components;
400 
401       b->cursor = nir_instr_remove(&intrin->instr);
402 
403       nir_def *coord = intrin->src[1].ssa;
404 
405       nir_def *do_load = image_coord_is_in_bounds(b, deref, coord);
406       nir_push_if(b, do_load);
407 
408       nir_def *addr = image_address(b, devinfo, deref, coord);
409       nir_def *load =
410          nir_image_deref_load_raw_intel(b, image_fmtl->bpb / 32, 32,
411                                         &deref->def, addr);
412 
413       nir_push_else(b, NULL);
414 
415       nir_def *zero = nir_imm_zero(b, load->num_components, 32);
416 
417       nir_pop_if(b, NULL);
418 
419       nir_def *value = nir_if_phi(b, load, zero);
420 
421       nir_def *color = convert_color_for_load(b, devinfo, value,
422                                                   image_fmt, raw_fmt,
423                                                   dest_components);
424 
425       nir_def_rewrite_uses(&intrin->def, color);
426    }
427 
428    return true;
429 }
430 
431 static nir_def *
convert_color_for_store(nir_builder * b,const struct intel_device_info * devinfo,nir_def * color,enum isl_format image_fmt,enum isl_format lower_fmt)432 convert_color_for_store(nir_builder *b, const struct intel_device_info *devinfo,
433                         nir_def *color,
434                         enum isl_format image_fmt, enum isl_format lower_fmt)
435 {
436    struct format_info image = get_format_info(image_fmt);
437    struct format_info lower = get_format_info(lower_fmt);
438 
439    color = nir_trim_vector(b, color, image.chans);
440 
441    if (image_fmt == lower_fmt)
442       return color;
443 
444    if (image_fmt == ISL_FORMAT_R11G11B10_FLOAT) {
445       assert(lower_fmt == ISL_FORMAT_R32_UINT);
446       return nir_format_pack_11f11f10f(b, color);
447    }
448 
449    switch (image.fmtl->channels.r.type) {
450    case ISL_UNORM:
451       assert(isl_format_has_uint_channel(lower_fmt));
452       color = nir_format_float_to_unorm(b, color, image.bits);
453       break;
454 
455    case ISL_SNORM:
456       assert(isl_format_has_uint_channel(lower_fmt));
457       color = nir_format_float_to_snorm(b, color, image.bits);
458       break;
459 
460    case ISL_SFLOAT:
461       if (image.bits[0] == 16)
462          color = nir_format_float_to_half(b, color);
463       break;
464 
465    case ISL_UINT:
466       color = nir_format_clamp_uint(b, color, image.bits);
467       break;
468 
469    case ISL_SINT:
470       color = nir_format_clamp_sint(b, color, image.bits);
471       break;
472 
473    default:
474       unreachable("Invalid image channel type");
475    }
476 
477    if (image.bits[0] < 32 &&
478        (isl_format_has_snorm_channel(image_fmt) ||
479         isl_format_has_sint_channel(image_fmt)))
480       color = nir_format_mask_uvec(b, color, image.bits);
481 
482    if (image.bits[0] != lower.bits[0] && lower_fmt == ISL_FORMAT_R32_UINT) {
483       color = nir_format_pack_uint(b, color, image.bits, image.chans);
484    } else {
485       /* All these formats are homogeneous */
486       for (unsigned i = 1; i < image.chans; i++)
487          assert(image.bits[i] == image.bits[0]);
488 
489       if (image.bits[0] != lower.bits[0]) {
490          color = nir_format_bitcast_uvec_unmasked(b, color, image.bits[0],
491                                                   lower.bits[0]);
492       }
493    }
494 
495    return color;
496 }
497 
498 static bool
lower_image_store_instr(nir_builder * b,const struct intel_device_info * devinfo,nir_intrinsic_instr * intrin)499 lower_image_store_instr(nir_builder *b,
500                         const struct intel_device_info *devinfo,
501                         nir_intrinsic_instr *intrin)
502 {
503    nir_deref_instr *deref = nir_src_as_deref(intrin->src[0]);
504    nir_variable *var = nir_deref_instr_get_variable(deref);
505 
506    /* For write-only surfaces, we trust that the hardware can just do the
507     * conversion for us.
508     */
509    if (var->data.access & ACCESS_NON_READABLE)
510       return false;
511 
512    if (var->data.image.format == PIPE_FORMAT_NONE)
513       return false;
514 
515    const enum isl_format image_fmt =
516       isl_format_for_pipe_format(var->data.image.format);
517 
518    if (isl_has_matching_typed_storage_image_format(devinfo, image_fmt)) {
519       const enum isl_format lower_fmt =
520          isl_lower_storage_image_format(devinfo, image_fmt);
521 
522       /* Color conversion goes before the store */
523       b->cursor = nir_before_instr(&intrin->instr);
524 
525       nir_def *color = convert_color_for_store(b, devinfo,
526                                                    intrin->src[3].ssa,
527                                                    image_fmt, lower_fmt);
528       intrin->num_components = isl_format_get_num_channels(lower_fmt);
529       nir_src_rewrite(&intrin->src[3], color);
530    } else {
531       const struct isl_format_layout *image_fmtl =
532          isl_format_get_layout(image_fmt);
533       /* We have a matching typed format for everything 32b and below */
534       assert(image_fmtl->bpb == 64 || image_fmtl->bpb == 128);
535       enum isl_format raw_fmt = (image_fmtl->bpb == 64) ?
536                                 ISL_FORMAT_R32G32_UINT :
537                                 ISL_FORMAT_R32G32B32A32_UINT;
538 
539       b->cursor = nir_instr_remove(&intrin->instr);
540 
541       nir_def *coord = intrin->src[1].ssa;
542 
543       nir_def *do_store = image_coord_is_in_bounds(b, deref, coord);
544       nir_push_if(b, do_store);
545 
546       nir_def *addr = image_address(b, devinfo, deref, coord);
547       nir_def *color = convert_color_for_store(b, devinfo,
548                                                    intrin->src[3].ssa,
549                                                    image_fmt, raw_fmt);
550 
551       nir_intrinsic_instr *store =
552          nir_intrinsic_instr_create(b->shader,
553                                     nir_intrinsic_image_deref_store_raw_intel);
554       store->src[0] = nir_src_for_ssa(&deref->def);
555       store->src[1] = nir_src_for_ssa(addr);
556       store->src[2] = nir_src_for_ssa(color);
557       store->num_components = image_fmtl->bpb / 32;
558       nir_builder_instr_insert(b, &store->instr);
559 
560       nir_pop_if(b, NULL);
561    }
562 
563    return true;
564 }
565 
566 static bool
brw_nir_lower_storage_image_instr(nir_builder * b,nir_instr * instr,void * cb_data)567 brw_nir_lower_storage_image_instr(nir_builder *b,
568                                   nir_instr *instr,
569                                   void *cb_data)
570 {
571    if (instr->type != nir_instr_type_intrinsic)
572       return false;
573    const struct brw_nir_lower_storage_image_opts *opts = cb_data;
574 
575    nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
576    switch (intrin->intrinsic) {
577    case nir_intrinsic_image_deref_load:
578       if (opts->lower_loads)
579          return lower_image_load_instr(b, opts->devinfo, intrin, false);
580       return false;
581 
582    case nir_intrinsic_image_deref_sparse_load:
583       if (opts->lower_loads)
584          return lower_image_load_instr(b, opts->devinfo, intrin, true);
585       return false;
586 
587    case nir_intrinsic_image_deref_store:
588       if (opts->lower_stores)
589          return lower_image_store_instr(b, opts->devinfo, intrin);
590       return false;
591 
592    default:
593       /* Nothing to do */
594       return false;
595    }
596 }
597 
598 bool
brw_nir_lower_storage_image(nir_shader * shader,const struct brw_nir_lower_storage_image_opts * opts)599 brw_nir_lower_storage_image(nir_shader *shader,
600                             const struct brw_nir_lower_storage_image_opts *opts)
601 {
602    bool progress = false;
603 
604    const nir_lower_image_options image_options = {
605       .lower_cube_size = true,
606       .lower_image_samples_to_one = true,
607    };
608 
609    progress |= nir_lower_image(shader, &image_options);
610 
611    progress |= nir_shader_instructions_pass(shader,
612                                             brw_nir_lower_storage_image_instr,
613                                             nir_metadata_none,
614                                             (void *)opts);
615 
616    return progress;
617 }
618