diff options
author | Erik Faye-Lund <[email protected]> | 2018-09-27 18:23:14 +0200 |
---|---|---|
committer | Erik Faye-Lund <[email protected]> | 2019-10-28 08:51:43 +0000 |
commit | b533de12a5aab989b52573ced8a9fc7e6c15e330 (patch) | |
tree | 04c7ba39c3c2ba84366b2645fa4b49bbb22d009d /src/gallium/drivers/zink/zink_compiler.c | |
parent | 9fa7400564244bdd333066eb71285c3703b537f7 (diff) |
zink: transform z-range
In vulkan, the Z-range of clip-space goes from 0..W instead of -W..+W
as is the case in OpenGL. So we need to transform the Z-range to
account for this.
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.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c index 610caf6eaa0..520ac30ee93 100644 --- a/src/gallium/drivers/zink/zink_compiler.c +++ b/src/gallium/drivers/zink/zink_compiler.c @@ -116,6 +116,57 @@ lower_uniforms_to_ubo(nir_shader *shader) return progress; } +static void +lower_store_output(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 +position_to_vulkan(nir_shader *s) +{ + if (s->info.stage != MESA_SHADER_VERTEX) + return; + + nir_foreach_function(function, s) { + if (function->impl) { + nir_builder b; + nir_builder_init(&b, function->impl); + + nir_foreach_block(block, function->impl) { + nir_foreach_instr_safe(instr, block) + lower_store_output(&b, instr); + } + + nir_metadata_preserve(function->impl, nir_metadata_block_index | + nir_metadata_dominance); + } + } +} + static const struct nir_shader_compiler_options nir_options = { .lower_all_io_to_temps = true, .lower_ffma = true, @@ -201,6 +252,7 @@ zink_compile_nir(struct zink_screen *screen, struct nir_shader *nir) NIR_PASS_V(nir, nir_lower_io, nir_var_all, glsl_type_size, (nir_lower_io_options)0); NIR_PASS_V(nir, lower_uniforms_to_ubo); + NIR_PASS_V(nir, position_to_vulkan); NIR_PASS_V(nir, nir_lower_regs_to_ssa); NIR_PASS_V(nir, nir_lower_bool_to_float); optimize_nir(nir); |