aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium
diff options
context:
space:
mode:
authorErik Faye-Lund <[email protected]>2020-04-24 17:13:45 +0200
committerMarge Bot <[email protected]>2020-05-05 09:17:52 +0000
commit7983d97174de10670fce5a422ce6c1cb5e783b88 (patch)
treefc6b820adfab7e051421ceb8caff4748f14e8a26 /src/gallium
parent4777ee1a62f0620efa2a105215eb589fc44dfa0f (diff)
zink: use nir_lower_uniforms_to_ubo
Instead of open-coding uniform -> UBO lowering, let's instead use the one that already exists. This should make things a bit simpler going forward. Reviewed-by: Alyssa Rosenzweig <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4734>
Diffstat (limited to 'src/gallium')
-rw-r--r--src/gallium/drivers/zink/zink_compiler.c84
1 files changed, 1 insertions, 83 deletions
diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c
index 399e2cd4071..3d9a44ae169 100644
--- a/src/gallium/drivers/zink/zink_compiler.c
+++ b/src/gallium/drivers/zink/zink_compiler.c
@@ -37,88 +37,6 @@
#include "util/u_memory.h"
static bool
-lower_instr(nir_intrinsic_instr *instr, nir_builder *b)
-{
- b->cursor = nir_before_instr(&instr->instr);
-
- if (instr->intrinsic == nir_intrinsic_load_ubo) {
- nir_ssa_def *old_idx = nir_ssa_for_src(b, instr->src[0], 1);
- nir_ssa_def *new_idx = nir_iadd(b, old_idx, nir_imm_int(b, 1));
- nir_instr_rewrite_src(&instr->instr, &instr->src[0],
- nir_src_for_ssa(new_idx));
- return true;
- }
-
- 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, nir_intrinsic_base(instr)),
- nir_ssa_for_src(b, instr->src[0], 1));
-
- nir_intrinsic_instr *load =
- nir_intrinsic_instr_create(b->shader, nir_intrinsic_load_ubo);
- load->num_components = instr->num_components;
- load->src[0] = nir_src_for_ssa(ubo_idx);
- load->src[1] = nir_src_for_ssa(ubo_offset);
- assert(instr->dest.ssa.bit_size >= 8);
- nir_intrinsic_set_align(load, instr->dest.ssa.bit_size / 8, 0);
- nir_ssa_dest_init(&load->instr, &load->dest,
- load->num_components, instr->dest.ssa.bit_size,
- instr->dest.ssa.name);
- nir_builder_instr_insert(b, &load->instr);
- nir_ssa_def_rewrite_uses(&instr->dest.ssa, nir_src_for_ssa(&load->dest.ssa));
-
- nir_instr_remove(&instr->instr);
- return true;
- }
-
- return false;
-}
-
-static bool
-lower_uniforms_to_ubo(nir_shader *shader)
-{
- bool progress = false;
-
- nir_foreach_function(function, shader) {
- if (function->impl) {
- nir_builder builder;
- nir_builder_init(&builder, function->impl);
- nir_foreach_block(block, function->impl) {
- nir_foreach_instr_safe(instr, block) {
- if (instr->type == nir_instr_type_intrinsic)
- progress |= lower_instr(nir_instr_as_intrinsic(instr),
- &builder);
- }
- }
-
- nir_metadata_preserve(function->impl, nir_metadata_block_index |
- nir_metadata_dominance);
- }
- }
-
- if (progress) {
- assert(shader->num_uniforms > 0);
- const struct glsl_type *type = glsl_array_type(glsl_vec4_type(),
- shader->num_uniforms, 0);
- nir_variable *ubo = nir_variable_create(shader, nir_var_mem_ubo, type,
- "uniform_0");
- ubo->data.binding = 0;
-
- struct glsl_struct_field field = {
- .type = type,
- .name = "data",
- .location = -1,
- };
- ubo->interface_type =
- glsl_interface_type(&field, 1, GLSL_INTERFACE_PACKING_STD430,
- false, "__ubo0_interface");
- }
-
- return progress;
-}
-
-static bool
lower_discard_if_instr(nir_intrinsic_instr *instr, nir_builder *b)
{
if (instr->intrinsic == nir_intrinsic_discard_if) {
@@ -217,7 +135,7 @@ zink_compile_nir(struct zink_screen *screen, struct nir_shader *nir)
{
struct zink_shader *ret = CALLOC_STRUCT(zink_shader);
- NIR_PASS_V(nir, lower_uniforms_to_ubo);
+ NIR_PASS_V(nir, nir_lower_uniforms_to_ubo, 1);
NIR_PASS_V(nir, nir_lower_clip_halfz);
NIR_PASS_V(nir, nir_lower_regs_to_ssa);
optimize_nir(nir);