2
* Copyright (c) 2020 Etnaviv Project
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, sub license,
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
12
* next paragraph) shall be included in all copies or substantial portions
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 NON-INFRINGEMENT. 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
21
* DEALINGS IN THE SOFTWARE.
24
* Christian Gmeiner <christian.gmeiner@gmail.com>
27
#include "etnaviv_nir.h"
30
* Pass to lower the load_ubo intrinsics for block 0 back to load_uniform intrinsics.
34
is_const_ubo(const nir_instr *instr, const void *_data)
36
if (instr->type != nir_instr_type_intrinsic)
39
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
40
if (intr->intrinsic != nir_intrinsic_load_ubo)
43
if (!nir_src_is_const(intr->src[0]) || !nir_src_is_const(intr->src[1]))
46
const uint32_t block = nir_src_as_uint(intr->src[0]);
54
lower_ubo_to_uniform(nir_builder *b, nir_instr *instr, void *_data)
56
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
57
b->cursor = nir_before_instr(instr);
59
/* Undo the operations done in nir_lower_uniforms_to_ubo. */
60
nir_ssa_def *ubo_offset = nir_ssa_for_src(b, intr->src[1], 1);
61
nir_ssa_def *range_base = nir_imm_int(b, nir_intrinsic_range_base(intr));
63
nir_ssa_def *uniform_offset =
64
nir_ushr(b, nir_isub(b, ubo_offset, range_base), nir_imm_int(b, 4));
66
nir_ssa_def *uniform =
67
nir_load_uniform(b, intr->num_components, intr->dest.ssa.bit_size, uniform_offset,
68
.base = nir_intrinsic_range_base(intr) / 16,
69
.range = nir_intrinsic_range(intr) / 16,
70
.dest_type = nir_type_float32);
72
nir_ssa_def_rewrite_uses(&intr->dest.ssa, uniform);
78
etna_nir_lower_ubo_to_uniform(nir_shader *shader)
80
return nir_shader_lower_instructions(shader,