aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/zink/zink_compiler.c
diff options
context:
space:
mode:
authorErik Faye-Lund <[email protected]>2019-10-09 11:25:50 +0200
committerErik Faye-Lund <[email protected]>2019-10-28 08:51:48 +0000
commit86ed8132a52bc880a4bb7f698ec1abdeef29d6ad (patch)
treee8bc3320044fb01f6a02637080ce7d63897ae5a8 /src/gallium/drivers/zink/zink_compiler.c
parent412e2aa23b8e145ca3eaa6df13dba1fe6c176b71 (diff)
zink: simplify gl-to-vulkan lowering
Acked-by: Jordan Justen <[email protected]>
Diffstat (limited to 'src/gallium/drivers/zink/zink_compiler.c')
-rw-r--r--src/gallium/drivers/zink/zink_compiler.c71
1 files changed, 23 insertions, 48 deletions
diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c
index d5c9a42b29c..d08b82a8ce9 100644
--- a/src/gallium/drivers/zink/zink_compiler.c
+++ b/src/gallium/drivers/zink/zink_compiler.c
@@ -117,67 +117,43 @@ lower_uniforms_to_ubo(nir_shader *shader)
}
static void
-lower_store_output(nir_builder *b,
- struct nir_instr *instr)
+lower_pos_write(nir_builder *b, struct nir_instr *instr)
{
if (instr->type != nir_instr_type_intrinsic)
return;
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
- if (intr->intrinsic != nir_intrinsic_store_output)
- return;
-
- if (nir_intrinsic_base(intr) != VARYING_SLOT_POS)
- return;
-
- b->cursor = nir_before_instr(&intr->instr);
-
- nir_ssa_def *src = nir_ssa_for_src(b, intr->src[0], 4);
- nir_ssa_def *def = nir_vec4(b,
- nir_channel(b, src, 0),
- nir_channel(b, src, 1),
- nir_fmul(b,
- nir_fadd(b,
- nir_channel(b, src, 2),
- nir_channel(b, src, 3)),
- nir_imm_float(b, 0.5)),
- nir_channel(b, src, 3));
- nir_instr_rewrite_src(&intr->instr, &intr->src[0], nir_src_for_ssa(def));
-}
-
-static void
-lower_store_deref(nir_builder *b,
- struct nir_instr *instr)
-{
- if (instr->type != nir_instr_type_intrinsic)
- return;
-
- nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
- if (intr->intrinsic != nir_intrinsic_store_deref)
- return;
-
- nir_variable *var = nir_intrinsic_get_var(intr, 0);
- if (var->data.mode != nir_var_shader_out ||
- var->data.location != VARYING_SLOT_POS)
+ struct nir_src *src;
+ if (intr->intrinsic == nir_intrinsic_store_output) {
+ if (nir_intrinsic_base(intr) != VARYING_SLOT_POS)
+ return;
+ src = &intr->src[0];
+ } else if (intr->intrinsic == nir_intrinsic_store_deref) {
+ nir_variable *var = nir_intrinsic_get_var(intr, 0);
+ if (var->data.mode != nir_var_shader_out ||
+ var->data.location != VARYING_SLOT_POS)
+ return;
+ src = &intr->src[1];
+ } else
return;
b->cursor = nir_before_instr(&intr->instr);
- nir_ssa_def *src = nir_ssa_for_src(b, intr->src[1], 4);
+ nir_ssa_def *pos = nir_ssa_for_src(b, *src, 4);
nir_ssa_def *def = nir_vec4(b,
- nir_channel(b, src, 0),
- nir_channel(b, src, 1),
+ nir_channel(b, pos, 0),
+ nir_channel(b, pos, 1),
nir_fmul(b,
nir_fadd(b,
- nir_channel(b, src, 2),
- nir_channel(b, src, 3)),
+ nir_channel(b, pos, 2),
+ nir_channel(b, pos, 3)),
nir_imm_float(b, 0.5)),
- nir_channel(b, src, 3));
- nir_instr_rewrite_src(&intr->instr, &intr->src[1], nir_src_for_ssa(def));
+ nir_channel(b, pos, 3));
+ nir_instr_rewrite_src(&intr->instr, src, nir_src_for_ssa(def));
}
static void
-position_to_vulkan(nir_shader *s)
+lower_clip_halfz(nir_shader *s)
{
if (s->info.stage != MESA_SHADER_VERTEX)
return;
@@ -189,8 +165,7 @@ position_to_vulkan(nir_shader *s)
nir_foreach_block(block, function->impl) {
nir_foreach_instr_safe(instr, block) {
- lower_store_output(&b, instr);
- lower_store_deref(&b, instr);
+ lower_pos_write(&b, instr);
}
}
@@ -323,7 +298,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, position_to_vulkan);
+ NIR_PASS_V(nir, lower_clip_halfz);
NIR_PASS_V(nir, nir_lower_regs_to_ssa);
optimize_nir(nir);
NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_function_temp);