summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimur Kristóf <[email protected]>2019-02-28 10:53:11 +0100
committerEric Anholt <[email protected]>2019-03-05 19:13:27 +0000
commit6684e039eba9c2e9602b1cc9d5177f69e478ff46 (patch)
treef2d93cf6d84b5a2c44d41e57980e22905c10a1fb
parent909d1f50f3ffc62d5a23669ad0bc8eedb9416af0 (diff)
nir: Add multiplier argument to nir_lower_uniforms_to_ubo.
Note that locations can be set in different units, and the multiplier argument caters to supporting these different units. For example, st_glsl_to_nir uses dwords (4 bytes) so the multiplier should be 4, while tgsi_to_nir uses bytes, so the multiplier should be 16. Signed-Off-By: Timur Kristóf <[email protected]> Tested-by: Andre Heider <[email protected]> Tested-by: Rob Clark <[email protected]> Reviewed-by: Timothy Arceri <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
-rw-r--r--src/compiler/nir/nir.h2
-rw-r--r--src/compiler/nir/nir_lower_uniforms_to_ubo.c23
-rw-r--r--src/mesa/state_tracker/st_glsl_to_nir.cpp2
-rw-r--r--src/mesa/state_tracker/st_nir_builtins.c2
4 files changed, 18 insertions, 11 deletions
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index a0b6db80b76..401635712f9 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -3036,7 +3036,7 @@ void nir_lower_io_arrays_to_elements_no_indirects(nir_shader *shader,
void nir_lower_io_to_scalar(nir_shader *shader, nir_variable_mode mask);
void nir_lower_io_to_scalar_early(nir_shader *shader, nir_variable_mode mask);
-bool nir_lower_uniforms_to_ubo(nir_shader *shader);
+bool nir_lower_uniforms_to_ubo(nir_shader *shader, int multiplier);
typedef struct nir_lower_subgroups_options {
uint8_t subgroup_size;
diff --git a/src/compiler/nir/nir_lower_uniforms_to_ubo.c b/src/compiler/nir/nir_lower_uniforms_to_ubo.c
index b54c9943ab7..2f6b23a248f 100644
--- a/src/compiler/nir/nir_lower_uniforms_to_ubo.c
+++ b/src/compiler/nir/nir_lower_uniforms_to_ubo.c
@@ -22,18 +22,24 @@
*/
/*
- * Remap load_uniform intrinsics to UBO accesses of UBO binding point 0. Both
- * the base and the offset are interpreted as 16-byte units.
- *
+ * Remap load_uniform intrinsics to UBO accesses of UBO binding point 0.
* Simultaneously, remap existing UBO accesses by increasing their binding
* point by 1.
+ *
+ * Both the base and the offset are interpreted as 16-byte units.
+ *
+ * Note that locations can be set in different units, and the multiplier
+ * argument caters to supporting these different units.
+ * For example:
+ * - st_glsl_to_nir uses dwords (4 bytes) so the multiplier should be 4
+ * - tgsi_to_nir uses bytes, so the multiplier should be 16
*/
#include "nir.h"
#include "nir_builder.h"
static bool
-lower_instr(nir_intrinsic_instr *instr, nir_builder *b)
+lower_instr(nir_intrinsic_instr *instr, nir_builder *b, int multiplier)
{
b->cursor = nir_before_instr(&instr->instr);
@@ -48,8 +54,8 @@ lower_instr(nir_intrinsic_instr *instr, nir_builder *b)
if (instr->intrinsic == nir_intrinsic_load_uniform) {
nir_ssa_def *ubo_idx = nir_imm_int(b, 0);
nir_ssa_def *ubo_offset =
- nir_iadd(b, nir_imm_int(b, 4 * nir_intrinsic_base(instr)),
- nir_imul(b, nir_imm_int(b, 4),
+ nir_iadd(b, nir_imm_int(b, multiplier * nir_intrinsic_base(instr)),
+ nir_imul(b, nir_imm_int(b, multiplier),
nir_ssa_for_src(b, instr->src[0], 1)));
nir_intrinsic_instr *load =
@@ -71,7 +77,7 @@ lower_instr(nir_intrinsic_instr *instr, nir_builder *b)
}
bool
-nir_lower_uniforms_to_ubo(nir_shader *shader)
+nir_lower_uniforms_to_ubo(nir_shader *shader, int multiplier)
{
bool progress = false;
@@ -83,7 +89,8 @@ nir_lower_uniforms_to_ubo(nir_shader *shader)
nir_foreach_instr_safe(instr, block) {
if (instr->type == nir_instr_type_intrinsic)
progress |= lower_instr(nir_instr_as_intrinsic(instr),
- &builder);
+ &builder,
+ multiplier);
}
}
diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index 84638fd88a5..dab98f18604 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -991,7 +991,7 @@ st_finalize_nir(struct st_context *st, struct gl_program *prog,
if (st->ctx->Const.PackedDriverUniformStorage) {
NIR_PASS_V(nir, nir_lower_io, nir_var_uniform, st_glsl_type_dword_size,
(nir_lower_io_options)0);
- NIR_PASS_V(nir, nir_lower_uniforms_to_ubo);
+ NIR_PASS_V(nir, nir_lower_uniforms_to_ubo, 4);
}
st_nir_lower_samplers(screen, nir, shader_program, prog);
diff --git a/src/mesa/state_tracker/st_nir_builtins.c b/src/mesa/state_tracker/st_nir_builtins.c
index ce00b5e1671..8ec320cbb9c 100644
--- a/src/mesa/state_tracker/st_nir_builtins.c
+++ b/src/mesa/state_tracker/st_nir_builtins.c
@@ -66,7 +66,7 @@ st_nir_finish_builtin_shader(struct st_context *st,
if (st->ctx->Const.PackedDriverUniformStorage) {
NIR_PASS_V(nir, nir_lower_io, nir_var_uniform, st_glsl_type_dword_size,
(nir_lower_io_options)0);
- NIR_PASS_V(nir, nir_lower_uniforms_to_ubo);
+ NIR_PASS_V(nir, nir_lower_uniforms_to_ubo, 4);
}
struct pipe_shader_state state = {