Mesa (master): zink: re-transform gl_Position for gs input
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Oct 16 13:57:04 UTC 2020
Module: Mesa
Branch: master
Commit: 9671cd9215150d8eeecfe0868dbedba3493f8b5a
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=9671cd9215150d8eeecfe0868dbedba3493f8b5a
Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date: Wed Oct 14 10:34:06 2020 -0400
zink: re-transform gl_Position for gs input
we've transformed this in the vertex output, so we need to undo that here
ideally we'd only be performing this transform once, but that's going to get
complicated later with the halfz extension which requires shader keys on top
of this, so we can get around to simplifying things at that stage
Reviewed-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7139>
---
.../drivers/zink/nir_to_spirv/nir_to_spirv.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c
index 498cb274a39..a22b4cf8b3e 100644
--- a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c
+++ b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c
@@ -1577,6 +1577,28 @@ emit_load_deref(struct ntv_context *ctx, nir_intrinsic_instr *intr)
ptr);
unsigned num_components = nir_dest_num_components(intr->dest);
unsigned bit_size = nir_dest_bit_size(intr->dest);
+ if (ctx->stage > MESA_SHADER_VERTEX && ctx->stage <= MESA_SHADER_GEOMETRY &&
+ (nir_deref_instr_get_variable(nir_src_as_deref(intr->src[0]))->data.location == VARYING_SLOT_POS)) {
+ /* we previously transformed opengl gl_Position -> vulkan gl_Position in vertex shader,
+ * so now we have to reverse that and construct a new gl_Position:
+
+ gl_Position.z = gl_Position.z * 2 - gl_Position.w
+
+ */
+ SpvId components[4];
+ SpvId f_type = get_fvec_type(ctx, 32, 1);
+ SpvId base_type = get_fvec_type(ctx, 32, 4);
+ for (unsigned c = 0; c < 4; c++) {
+ uint32_t member[] = { c };
+
+ components[c] = spirv_builder_emit_composite_extract(&ctx->builder, f_type, result, member, 1);
+ }
+ components[2] = emit_binop(ctx, SpvOpFMul, f_type, components[2], emit_float_const(ctx, 32, 2.0));
+ components[2] = emit_binop(ctx, SpvOpFSub, f_type, components[2], components[3]);
+
+ result = spirv_builder_emit_composite_construct(&ctx->builder, base_type,
+ components, 4);
+ }
result = bitcast_to_uvec(ctx, result, bit_size, num_components);
store_dest(ctx, &intr->dest, result, nir_type_uint);
}
More information about the mesa-commit
mailing list