Skip to content

Commit c7b75a8

Browse files
MSL: Do not use base expression with PhysicalTypeID OpCompositeExtract.
Similar reasoning as packed expressions.
1 parent 6637610 commit c7b75a8

File tree

3 files changed

+97
-2
lines changed

3 files changed

+97
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma clang diagnostic ignored "-Wmissing-prototypes"
2+
3+
#include <metal_stdlib>
4+
#include <simd/simd.h>
5+
6+
using namespace metal;
7+
8+
struct type_Float2Array
9+
{
10+
float4 arr[3];
11+
};
12+
13+
struct main0_out
14+
{
15+
float4 gl_Position [[position]];
16+
};
17+
18+
static inline __attribute__((always_inline))
19+
float4 src_VSMain(thread const uint& i, constant type_Float2Array& Float2Array)
20+
{
21+
return float4(Float2Array.arr[i].x, Float2Array.arr[i].y, 0.0, 1.0);
22+
}
23+
24+
vertex main0_out main0(constant type_Float2Array& Float2Array [[buffer(0)]], uint gl_VertexIndex [[vertex_id]])
25+
{
26+
main0_out out = {};
27+
uint param_var_i = gl_VertexIndex;
28+
out.gl_Position = src_VSMain(param_var_i, Float2Array);
29+
return out;
30+
}
31+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
OpCapability Shader
2+
OpMemoryModel Logical GLSL450
3+
OpEntryPoint Vertex %VSMain "main" %gl_VertexIndex %gl_Position
4+
OpSource HLSL 600
5+
OpName %type_Float2Array "type.Float2Array"
6+
OpMemberName %type_Float2Array 0 "arr"
7+
OpName %Float2Array "Float2Array"
8+
OpName %VSMain "VSMain"
9+
OpName %param_var_i "param.var.i"
10+
OpName %src_VSMain "src.VSMain"
11+
OpName %i "i"
12+
OpName %bb_entry "bb.entry"
13+
OpDecorate %gl_VertexIndex BuiltIn VertexIndex
14+
OpDecorate %gl_Position BuiltIn Position
15+
OpDecorate %Float2Array DescriptorSet 0
16+
OpDecorate %Float2Array Binding 0
17+
OpDecorate %_arr_v2float_uint_3 ArrayStride 16
18+
OpMemberDecorate %type_Float2Array 0 Offset 0
19+
OpDecorate %type_Float2Array Block
20+
%int = OpTypeInt 32 1
21+
%int_0 = OpConstant %int 0
22+
%float = OpTypeFloat 32
23+
%float_0 = OpConstant %float 0
24+
%float_1 = OpConstant %float 1
25+
%uint = OpTypeInt 32 0
26+
%uint_3 = OpConstant %uint 3
27+
%v2float = OpTypeVector %float 2
28+
%_arr_v2float_uint_3 = OpTypeArray %v2float %uint_3
29+
%type_Float2Array = OpTypeStruct %_arr_v2float_uint_3
30+
%_ptr_Uniform_type_Float2Array = OpTypePointer Uniform %type_Float2Array
31+
%_ptr_Input_uint = OpTypePointer Input %uint
32+
%v4float = OpTypeVector %float 4
33+
%_ptr_Output_v4float = OpTypePointer Output %v4float
34+
%void = OpTypeVoid
35+
%20 = OpTypeFunction %void
36+
%_ptr_Function_uint = OpTypePointer Function %uint
37+
%27 = OpTypeFunction %v4float %_ptr_Function_uint
38+
%_ptr_Uniform__arr_v2float_uint_3 = OpTypePointer Uniform %_arr_v2float_uint_3
39+
%_ptr_Uniform_v2float = OpTypePointer Uniform %v2float
40+
%Float2Array = OpVariable %_ptr_Uniform_type_Float2Array Uniform
41+
%gl_VertexIndex = OpVariable %_ptr_Input_uint Input
42+
%gl_Position = OpVariable %_ptr_Output_v4float Output
43+
%VSMain = OpFunction %void None %20
44+
%21 = OpLabel
45+
%param_var_i = OpVariable %_ptr_Function_uint Function
46+
%24 = OpLoad %uint %gl_VertexIndex
47+
OpStore %param_var_i %24
48+
%25 = OpFunctionCall %v4float %src_VSMain %param_var_i
49+
OpStore %gl_Position %25
50+
OpReturn
51+
OpFunctionEnd
52+
%src_VSMain = OpFunction %v4float None %27
53+
%i = OpFunctionParameter %_ptr_Function_uint
54+
%bb_entry = OpLabel
55+
%30 = OpLoad %uint %i
56+
%32 = OpAccessChain %_ptr_Uniform__arr_v2float_uint_3 %Float2Array %int_0
57+
%34 = OpAccessChain %_ptr_Uniform_v2float %32 %30
58+
%35 = OpLoad %v2float %34
59+
%36 = OpCompositeExtract %float %35 0
60+
%37 = OpCompositeExtract %float %35 1
61+
%38 = OpCompositeConstruct %v4float %36 %37 %float_0 %float_1
62+
OpReturnValue %38
63+
OpFunctionEnd

spirv_glsl.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -8849,8 +8849,9 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
88498849
if (composite_type.basetype == SPIRType::Struct || !composite_type.array.empty())
88508850
allow_base_expression = false;
88518851

8852-
// Packed expressions cannot be split up.
8853-
if (has_extended_decoration(ops[2], SPIRVCrossDecorationPhysicalTypePacked))
8852+
// Packed expressions or physical ID mapped expressions cannot be split up.
8853+
if (has_extended_decoration(ops[2], SPIRVCrossDecorationPhysicalTypePacked) ||
8854+
has_extended_decoration(ops[2], SPIRVCrossDecorationPhysicalTypeID))
88548855
allow_base_expression = false;
88558856

88568857
// Cannot use base expression for row-major matrix row-extraction since we need to interleave access pattern

0 commit comments

Comments
 (0)