diff options
author | Kenneth Graunke <[email protected]> | 2019-02-05 19:02:44 -0800 |
---|---|---|
committer | Kenneth Graunke <[email protected]> | 2019-02-11 21:34:40 -0800 |
commit | 04bdc56872f5b3ea00a8d2c88900cb07eea846f4 (patch) | |
tree | 3e5a8e50f472d8b28dd539c59471eb37329c0645 /src/mesa/program | |
parent | 6a4be25a908f73d1cab8ad33bd26c3f7c9ddf7ca (diff) |
program: Make prog_to_nir create texture/sampler derefs.
Until now, prog_to_nir has been setting texture_index and sampler_index
directly. This is different than GLSL shaders, which create variable
dereferences and rely on lowering passes to reach this final form.
radeonsi uses variable dereferences for samplers rather than
texture_index and sampler_index, so it doesn't even make sense to set
them there. By moving to derefs, we ensure that both GLSL and ARB
programs produce the same final form that the driver desires.
Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/mesa/program')
-rw-r--r-- | src/mesa/program/prog_to_nir.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/mesa/program/prog_to_nir.c b/src/mesa/program/prog_to_nir.c index afa490cdb36..9d4f6d63dcc 100644 --- a/src/mesa/program/prog_to_nir.c +++ b/src/mesa/program/prog_to_nir.c @@ -529,6 +529,9 @@ ptn_tex(struct ptn_compile *c, nir_alu_dest dest, nir_ssa_def **src, abort(); } + /* Deref sources */ + num_srcs += 2; + if (prog_inst->TexShadow) num_srcs++; @@ -536,8 +539,6 @@ ptn_tex(struct ptn_compile *c, nir_alu_dest dest, nir_ssa_def **src, instr->op = op; instr->dest_type = nir_type_float; instr->is_shadow = prog_inst->TexShadow; - instr->texture_index = prog_inst->TexSrcUnit; - instr->sampler_index = prog_inst->TexSrcUnit; switch (prog_inst->TexSrcTarget) { case TEXTURE_1D_INDEX: @@ -580,17 +581,27 @@ ptn_tex(struct ptn_compile *c, nir_alu_dest dest, nir_ssa_def **src, unreachable("can't reach"); } - if (!c->sampler_vars[prog_inst->TexSrcUnit]) { + nir_variable *var = c->sampler_vars[prog_inst->TexSrcUnit]; + if (!var) { const struct glsl_type *type = glsl_sampler_type(instr->sampler_dim, false, false, GLSL_TYPE_FLOAT); - nir_variable *var = - nir_variable_create(b->shader, nir_var_uniform, type, "sampler"); + var = nir_variable_create(b->shader, nir_var_uniform, type, "sampler"); var->data.binding = prog_inst->TexSrcUnit; + var->data.explicit_binding = true; c->sampler_vars[prog_inst->TexSrcUnit] = var; } + nir_deref_instr *deref = nir_build_deref_var(b, var); + unsigned src_number = 0; + instr->src[src_number].src = nir_src_for_ssa(&deref->dest.ssa); + instr->src[src_number].src_type = nir_tex_src_texture_deref; + src_number++; + instr->src[src_number].src = nir_src_for_ssa(&deref->dest.ssa); + instr->src[src_number].src_type = nir_tex_src_sampler_deref; + src_number++; + instr->src[src_number].src = nir_src_for_ssa(nir_swizzle(b, src[0], SWIZ(X, Y, Z, W), instr->coord_components, true)); |