From 7ff2db4570d26c551222313fc3022568201b41cc Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Tue, 27 Aug 2019 11:41:54 +0200 Subject: [PATCH] Do not allow base expressions for non-native row-major matrices. --- .../opt/shaders-msl/vert/read-from-row-major-array.vert | 2 +- .../asm/packing/composite-extract-row-major.asm.comp | 2 +- spirv_glsl.cpp | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/reference/opt/shaders-msl/vert/read-from-row-major-array.vert b/reference/opt/shaders-msl/vert/read-from-row-major-array.vert index be3c5e4e..ec3e7b72 100644 --- a/reference/opt/shaders-msl/vert/read-from-row-major-array.vert +++ b/reference/opt/shaders-msl/vert/read-from-row-major-array.vert @@ -23,7 +23,7 @@ vertex main0_out main0(main0_in in [[stage_in]], constant Block& _104 [[buffer(0 { main0_out out = {}; out.gl_Position = in.a_position; - out.v_vtxResult = ((float(abs(float3(_104.var[0][0][0][0], _104.var[0][0][1][0], _104.var[0][0][2][0])[0] - 2.0) < 0.0500000007450580596923828125) * float(abs(float3(_104.var[0][0][0][0], _104.var[0][0][1][0], _104.var[0][0][2][0])[1] - 6.0) < 0.0500000007450580596923828125)) * float(abs(float3(_104.var[0][0][0][0], _104.var[0][0][1][0], _104.var[0][0][2][0])[2] - (-6.0)) < 0.0500000007450580596923828125)) * ((float(abs(float3(_104.var[0][0][0][1], _104.var[0][0][1][1], _104.var[0][0][2][1])[0]) < 0.0500000007450580596923828125) * float(abs(float3(_104.var[0][0][0][1], _104.var[0][0][1][1], _104.var[0][0][2][1])[1] - 5.0) < 0.0500000007450580596923828125)) * float(abs(float3(_104.var[0][0][0][1], _104.var[0][0][1][1], _104.var[0][0][2][1])[2] - 5.0) < 0.0500000007450580596923828125)); + out.v_vtxResult = ((float(abs(_104.var[0][0][0][0] - 2.0) < 0.0500000007450580596923828125) * float(abs(_104.var[0][0][1][0] - 6.0) < 0.0500000007450580596923828125)) * float(abs(_104.var[0][0][2][0] - (-6.0)) < 0.0500000007450580596923828125)) * ((float(abs(_104.var[0][0][0][1]) < 0.0500000007450580596923828125) * float(abs(_104.var[0][0][1][1] - 5.0) < 0.0500000007450580596923828125)) * float(abs(_104.var[0][0][2][1] - 5.0) < 0.0500000007450580596923828125)); return out; } diff --git a/reference/shaders-msl-no-opt/asm/packing/composite-extract-row-major.asm.comp b/reference/shaders-msl-no-opt/asm/packing/composite-extract-row-major.asm.comp index a2d2acbb..d2c368b8 100644 --- a/reference/shaders-msl-no-opt/asm/packing/composite-extract-row-major.asm.comp +++ b/reference/shaders-msl-no-opt/asm/packing/composite-extract-row-major.asm.comp @@ -11,6 +11,6 @@ struct SSBORow kernel void main0(device SSBORow& _4 [[buffer(0)]]) { - _4.v = float4(_4.row_major0[0][1], _4.row_major0[1][1], _4.row_major0[2][1], _4.row_major0[3][1])[2]; + _4.v = _4.row_major0[2][1]; } diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 51803a66..2cb13608 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -8245,6 +8245,11 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction) if (has_extended_decoration(ops[2], SPIRVCrossDecorationPhysicalTypePacked)) allow_base_expression = false; + // Cannot use base expression for row-major matrix row-extraction since we need to interleave access pattern + // into the base expression. + if (is_non_native_row_major_matrix(ops[2])) + allow_base_expression = false; + AccessChainMeta meta; SPIRExpression *e = nullptr;