2 * Copyright © 2019 Valve Corporation
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:
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
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
26 #include "util/debug.h"
28 /* This pass removes information which is only useful for debugging,
29 * making cache hits from similar shaders more likely.
33 strip_variable(nir_variable
*var
)
37 if (var
->data
.mode
!= nir_var_shader_in
&&
38 var
->data
.mode
!= nir_var_shader_out
) {
39 /* We assume that this is called after nir_lower_io(), at which point
40 * the original user-facing location is irrelevant except for inputs and
43 var
->data
.location
= 0;
48 strip_register(nir_register
*reg
)
54 strip_def(nir_ssa_def
*def
, void *_unused
)
62 strip_impl(nir_function_impl
*impl
)
64 nir_index_ssa_defs(impl
);
66 nir_foreach_variable(var
, &impl
->locals
)
68 nir_foreach_register(reg
, &impl
->registers
)
70 nir_foreach_block(block
, impl
) {
71 nir_foreach_instr(instr
, block
) {
72 nir_foreach_ssa_def(instr
, strip_def
, NULL
);
78 nir_strip(nir_shader
*shader
)
80 static int should_strip
= -1;
82 should_strip
= env_var_as_boolean("NIR_STRIP", true);
86 shader
->info
.name
= NULL
;
87 shader
->info
.label
= NULL
;
89 nir_foreach_variable(var
, &shader
->uniforms
)
91 nir_foreach_variable(var
, &shader
->inputs
)
93 nir_foreach_variable(var
, &shader
->outputs
)
95 nir_foreach_variable(var
, &shader
->system_values
)
97 nir_foreach_variable(var
, &shader
->globals
)
100 nir_foreach_register(reg
, &shader
->registers
)
103 nir_foreach_function(func
, shader
) {
105 strip_impl(func
->impl
);