Added few more stubs so that control reaches to DestroyDevice().
[mesa.git] / src / intel / compiler / brw_nir_clamp_image_1d_2d_array_sizes.c
1 /*
2 * Copyright © 2020 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 "compiler/nir/nir_builder.h"
25 #include "brw_nir.h"
26
27 /**
28 * GEN:BUG:1806565034:
29 *
30 * Gen12+ allows to set RENDER_SURFACE_STATE::SurfaceArray to 1 only if
31 * array_len > 1. Setting RENDER_SURFACE_STATE::SurfaceArray to 0 results in
32 * the HW RESINFO message to report an array size of 0 which breaks texture
33 * array size queries.
34 *
35 * This NIR pass works around this by patching the array size with a
36 * MAX(array_size, 1) for array textures.
37 */
38
39 bool
40 brw_nir_clamp_image_1d_2d_array_sizes(nir_shader *shader)
41 {
42 bool progress = false;
43 nir_builder b;
44
45 nir_foreach_function(func, shader) {
46 bool function_progress = false;
47
48 if (!func->impl)
49 continue;
50
51 nir_builder_init(&b, func->impl);
52
53 nir_foreach_block(block, func->impl) {
54 nir_foreach_instr_safe(instr, block) {
55 nir_ssa_def *image_size = NULL;
56
57 switch (instr->type) {
58 case nir_instr_type_intrinsic: {
59 nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
60
61 switch (intr->intrinsic) {
62 case nir_intrinsic_image_size:
63 case nir_intrinsic_bindless_image_size:
64 if (!nir_intrinsic_image_array(intr))
65 break;
66
67 image_size = &intr->dest.ssa;
68 break;
69
70 case nir_intrinsic_image_deref_size: {
71 nir_deref_instr *deref = nir_src_as_deref(intr->src[0]);
72
73 assert(glsl_type_is_image(deref->type));
74
75 if (!glsl_sampler_type_is_array(deref->type))
76 break;
77
78 image_size = &intr->dest.ssa;
79 break;
80 }
81
82 default:
83 break;
84 }
85 break;
86 }
87
88 case nir_instr_type_tex: {
89 nir_tex_instr *tex_instr = nir_instr_as_tex(instr);
90 if (tex_instr->op != nir_texop_txs)
91 break;
92
93 if (!tex_instr->is_array)
94 break;
95
96 image_size = &tex_instr->dest.ssa;
97 break;
98 }
99
100 default:
101 break;
102 }
103
104 if (!image_size)
105 continue;
106
107 b.cursor = nir_after_instr(instr);
108
109 nir_ssa_def *components[4];
110 for (int i = 0; i < image_size->num_components; i++) {
111 if (i == (image_size->num_components - 1)) {
112 components[i] = nir_imax(&b, nir_channel(&b, image_size, i),
113 nir_imm_int(&b, 1));
114 } else {
115 components[i] = nir_channel(&b, image_size, i);
116 }
117 }
118 nir_ssa_def *image_size_replacement =
119 nir_vec(&b, components, image_size->num_components);
120
121 b.cursor = nir_after_instr(instr);
122
123 nir_ssa_def_rewrite_uses_after(image_size,
124 nir_src_for_ssa(image_size_replacement),
125 image_size_replacement->parent_instr);
126
127 function_progress = true;
128 }
129 }
130
131 if (function_progress) {
132 nir_metadata_preserve(func->impl, nir_metadata_block_index |
133 nir_metadata_dominance);
134 progress = function_progress;
135 } else {
136 nir_metadata_preserve(func->impl, nir_metadata_all);
137 }
138 }
139
140 return progress;
141 }