Deal with some builtins being declared with wrong signedness.
This commit is contained in:
parent
76c8e3c1c4
commit
d94d20f4f3
@ -0,0 +1,28 @@
|
||||
static float4 gl_Position;
|
||||
static int gl_VertexIndex;
|
||||
static int gl_InstanceIndex;
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
uint gl_VertexIndex : SV_VertexID;
|
||||
uint gl_InstanceIndex : SV_InstanceID;
|
||||
};
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float4 gl_Position : SV_Position;
|
||||
};
|
||||
|
||||
void vert_main()
|
||||
{
|
||||
gl_Position = float(uint(gl_VertexIndex) + uint(gl_InstanceIndex)).xxxx;
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
|
||||
{
|
||||
gl_VertexIndex = int(stage_input.gl_VertexIndex);
|
||||
gl_InstanceIndex = int(stage_input.gl_InstanceIndex);
|
||||
vert_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.gl_Position = gl_Position;
|
||||
return stage_output;
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
struct main0_out
|
||||
{
|
||||
float4 gl_Position [[position]];
|
||||
};
|
||||
|
||||
vertex main0_out main0(uint gl_VertexIndex [[vertex_id]], uint gl_InstanceIndex [[instance_id]])
|
||||
{
|
||||
main0_out out = {};
|
||||
out.gl_Position = float4(float(gl_VertexIndex + gl_InstanceIndex));
|
||||
return out;
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
#version 450
|
||||
layout(triangles) in;
|
||||
layout(max_vertices = 3, triangle_strip) out;
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
vec4 pos;
|
||||
};
|
||||
|
||||
struct GeometryOutput
|
||||
{
|
||||
vec4 pos;
|
||||
uint layer;
|
||||
};
|
||||
|
||||
void _main(VertexOutput _input[3], GeometryOutput stream)
|
||||
{
|
||||
GeometryOutput _output;
|
||||
_output.layer = 1u;
|
||||
for (int v = 0; v < 3; v++)
|
||||
{
|
||||
_output.pos = _input[v].pos;
|
||||
gl_Position = _output.pos;
|
||||
gl_Layer = int(_output.layer);
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
VertexOutput _input[3];
|
||||
_input[0].pos = gl_in[0].gl_Position;
|
||||
_input[1].pos = gl_in[1].gl_Position;
|
||||
_input[2].pos = gl_in[2].gl_Position;
|
||||
VertexOutput param[3] = _input;
|
||||
GeometryOutput param_1;
|
||||
_main(param, param_1);
|
||||
GeometryOutput stream = param_1;
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
#version 450
|
||||
|
||||
uniform int SPIRV_Cross_BaseInstance;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(float(uint(gl_VertexID) + uint((gl_InstanceID + SPIRV_Cross_BaseInstance))));
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
static float4 gl_Position;
|
||||
static int gl_VertexIndex;
|
||||
static int gl_InstanceIndex;
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
uint gl_VertexIndex : SV_VertexID;
|
||||
uint gl_InstanceIndex : SV_InstanceID;
|
||||
};
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float4 gl_Position : SV_Position;
|
||||
};
|
||||
|
||||
float4 _main(uint vid, uint iid)
|
||||
{
|
||||
return float(vid + iid).xxxx;
|
||||
}
|
||||
|
||||
void vert_main()
|
||||
{
|
||||
uint vid = uint(gl_VertexIndex);
|
||||
uint iid = uint(gl_InstanceIndex);
|
||||
uint param = vid;
|
||||
uint param_1 = iid;
|
||||
gl_Position = _main(param, param_1);
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
|
||||
{
|
||||
gl_VertexIndex = int(stage_input.gl_VertexIndex);
|
||||
gl_InstanceIndex = int(stage_input.gl_InstanceIndex);
|
||||
vert_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.gl_Position = gl_Position;
|
||||
return stage_output;
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
#pragma clang diagnostic ignored "-Wmissing-prototypes"
|
||||
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
struct main0_out
|
||||
{
|
||||
float4 gl_Position [[position]];
|
||||
};
|
||||
|
||||
float4 _main(thread const uint& vid, thread const uint& iid)
|
||||
{
|
||||
return float4(float(vid + iid));
|
||||
}
|
||||
|
||||
vertex main0_out main0(uint gl_VertexIndex [[vertex_id]], uint gl_InstanceIndex [[instance_id]])
|
||||
{
|
||||
main0_out out = {};
|
||||
uint vid = gl_VertexIndex;
|
||||
uint iid = gl_InstanceIndex;
|
||||
uint param = vid;
|
||||
uint param_1 = iid;
|
||||
out.gl_Position = _main(param, param_1);
|
||||
return out;
|
||||
}
|
||||
|
41
reference/shaders/asm/geom/store-uint-layer.invalid.asm.geom
Normal file
41
reference/shaders/asm/geom/store-uint-layer.invalid.asm.geom
Normal file
@ -0,0 +1,41 @@
|
||||
#version 450
|
||||
layout(triangles) in;
|
||||
layout(max_vertices = 3, triangle_strip) out;
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
vec4 pos;
|
||||
};
|
||||
|
||||
struct GeometryOutput
|
||||
{
|
||||
vec4 pos;
|
||||
uint layer;
|
||||
};
|
||||
|
||||
void _main(VertexOutput _input[3], GeometryOutput stream)
|
||||
{
|
||||
GeometryOutput _output;
|
||||
_output.layer = 1u;
|
||||
for (int v = 0; v < 3; v++)
|
||||
{
|
||||
_output.pos = _input[v].pos;
|
||||
gl_Position = _output.pos;
|
||||
gl_Layer = int(_output.layer);
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
VertexOutput _input[3];
|
||||
_input[0].pos = gl_in[0].gl_Position;
|
||||
_input[1].pos = gl_in[1].gl_Position;
|
||||
_input[2].pos = gl_in[2].gl_Position;
|
||||
VertexOutput param[3] = _input;
|
||||
GeometryOutput param_1;
|
||||
_main(param, param_1);
|
||||
GeometryOutput stream = param_1;
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
#version 450
|
||||
|
||||
uniform int SPIRV_Cross_BaseInstance;
|
||||
|
||||
vec4 _main(uint vid, uint iid)
|
||||
{
|
||||
return vec4(float(vid + iid));
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
uint vid = uint(gl_VertexID);
|
||||
uint iid = uint((gl_InstanceID + SPIRV_Cross_BaseInstance));
|
||||
uint param = vid;
|
||||
uint param_1 = iid;
|
||||
gl_Position = _main(param, param_1);
|
||||
}
|
||||
|
65
shaders-hlsl/asm/vert/uint-vertex-id-instance-id.asm.vert
Normal file
65
shaders-hlsl/asm/vert/uint-vertex-id-instance-id.asm.vert
Normal file
@ -0,0 +1,65 @@
|
||||
; SPIR-V
|
||||
; Version: 1.0
|
||||
; Generator: Khronos Glslang Reference Front End; 6
|
||||
; Bound: 36
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Vertex %main "main" %vid_1 %iid_1 %_entryPointOutput
|
||||
OpSource HLSL 500
|
||||
OpName %main "main"
|
||||
OpName %_main_u1_u1_ "@main(u1;u1;"
|
||||
OpName %vid "vid"
|
||||
OpName %iid "iid"
|
||||
OpName %vid_0 "vid"
|
||||
OpName %vid_1 "vid"
|
||||
OpName %iid_0 "iid"
|
||||
OpName %iid_1 "iid"
|
||||
OpName %_entryPointOutput "@entryPointOutput"
|
||||
OpName %param "param"
|
||||
OpName %param_0 "param"
|
||||
OpDecorate %vid_1 BuiltIn VertexIndex
|
||||
OpDecorate %iid_1 BuiltIn InstanceIndex
|
||||
OpDecorate %_entryPointOutput BuiltIn Position
|
||||
%void = OpTypeVoid
|
||||
%3 = OpTypeFunction %void
|
||||
%uint = OpTypeInt 32 0
|
||||
%_ptr_Function_uint = OpTypePointer Function %uint
|
||||
%float = OpTypeFloat 32
|
||||
%v4float = OpTypeVector %float 4
|
||||
%10 = OpTypeFunction %v4float %_ptr_Function_uint %_ptr_Function_uint
|
||||
%_ptr_Input_uint = OpTypePointer Input %uint
|
||||
%vid_1 = OpVariable %_ptr_Input_uint Input
|
||||
%iid_1 = OpVariable %_ptr_Input_uint Input
|
||||
%_ptr_Output_v4float = OpTypePointer Output %v4float
|
||||
%_entryPointOutput = OpVariable %_ptr_Output_v4float Output
|
||||
%main = OpFunction %void None %3
|
||||
%5 = OpLabel
|
||||
%vid_0 = OpVariable %_ptr_Function_uint Function
|
||||
%iid_0 = OpVariable %_ptr_Function_uint Function
|
||||
%param = OpVariable %_ptr_Function_uint Function
|
||||
%param_0 = OpVariable %_ptr_Function_uint Function
|
||||
%25 = OpLoad %uint %vid_1
|
||||
OpStore %vid_0 %25
|
||||
%28 = OpLoad %uint %iid_1
|
||||
OpStore %iid_0 %28
|
||||
%32 = OpLoad %uint %vid_0
|
||||
OpStore %param %32
|
||||
%34 = OpLoad %uint %iid_0
|
||||
OpStore %param_0 %34
|
||||
%35 = OpFunctionCall %v4float %_main_u1_u1_ %param %param_0
|
||||
OpStore %_entryPointOutput %35
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
%_main_u1_u1_ = OpFunction %v4float None %10
|
||||
%vid = OpFunctionParameter %_ptr_Function_uint
|
||||
%iid = OpFunctionParameter %_ptr_Function_uint
|
||||
%14 = OpLabel
|
||||
%15 = OpLoad %uint %vid
|
||||
%16 = OpLoad %uint %iid
|
||||
%17 = OpIAdd %uint %15 %16
|
||||
%18 = OpConvertUToF %float %17
|
||||
%19 = OpCompositeConstruct %v4float %18 %18 %18 %18
|
||||
OpReturnValue %19
|
||||
OpFunctionEnd
|
65
shaders-msl/asm/vert/uint-vertex-id-instance-id.asm.vert
Normal file
65
shaders-msl/asm/vert/uint-vertex-id-instance-id.asm.vert
Normal file
@ -0,0 +1,65 @@
|
||||
; SPIR-V
|
||||
; Version: 1.0
|
||||
; Generator: Khronos Glslang Reference Front End; 6
|
||||
; Bound: 36
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Vertex %main "main" %vid_1 %iid_1 %_entryPointOutput
|
||||
OpSource HLSL 500
|
||||
OpName %main "main"
|
||||
OpName %_main_u1_u1_ "@main(u1;u1;"
|
||||
OpName %vid "vid"
|
||||
OpName %iid "iid"
|
||||
OpName %vid_0 "vid"
|
||||
OpName %vid_1 "vid"
|
||||
OpName %iid_0 "iid"
|
||||
OpName %iid_1 "iid"
|
||||
OpName %_entryPointOutput "@entryPointOutput"
|
||||
OpName %param "param"
|
||||
OpName %param_0 "param"
|
||||
OpDecorate %vid_1 BuiltIn VertexIndex
|
||||
OpDecorate %iid_1 BuiltIn InstanceIndex
|
||||
OpDecorate %_entryPointOutput BuiltIn Position
|
||||
%void = OpTypeVoid
|
||||
%3 = OpTypeFunction %void
|
||||
%uint = OpTypeInt 32 0
|
||||
%_ptr_Function_uint = OpTypePointer Function %uint
|
||||
%float = OpTypeFloat 32
|
||||
%v4float = OpTypeVector %float 4
|
||||
%10 = OpTypeFunction %v4float %_ptr_Function_uint %_ptr_Function_uint
|
||||
%_ptr_Input_uint = OpTypePointer Input %uint
|
||||
%vid_1 = OpVariable %_ptr_Input_uint Input
|
||||
%iid_1 = OpVariable %_ptr_Input_uint Input
|
||||
%_ptr_Output_v4float = OpTypePointer Output %v4float
|
||||
%_entryPointOutput = OpVariable %_ptr_Output_v4float Output
|
||||
%main = OpFunction %void None %3
|
||||
%5 = OpLabel
|
||||
%vid_0 = OpVariable %_ptr_Function_uint Function
|
||||
%iid_0 = OpVariable %_ptr_Function_uint Function
|
||||
%param = OpVariable %_ptr_Function_uint Function
|
||||
%param_0 = OpVariable %_ptr_Function_uint Function
|
||||
%25 = OpLoad %uint %vid_1
|
||||
OpStore %vid_0 %25
|
||||
%28 = OpLoad %uint %iid_1
|
||||
OpStore %iid_0 %28
|
||||
%32 = OpLoad %uint %vid_0
|
||||
OpStore %param %32
|
||||
%34 = OpLoad %uint %iid_0
|
||||
OpStore %param_0 %34
|
||||
%35 = OpFunctionCall %v4float %_main_u1_u1_ %param %param_0
|
||||
OpStore %_entryPointOutput %35
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
%_main_u1_u1_ = OpFunction %v4float None %10
|
||||
%vid = OpFunctionParameter %_ptr_Function_uint
|
||||
%iid = OpFunctionParameter %_ptr_Function_uint
|
||||
%14 = OpLabel
|
||||
%15 = OpLoad %uint %vid
|
||||
%16 = OpLoad %uint %iid
|
||||
%17 = OpIAdd %uint %15 %16
|
||||
%18 = OpConvertUToF %float %17
|
||||
%19 = OpCompositeConstruct %v4float %18 %18 %18 %18
|
||||
OpReturnValue %19
|
||||
OpFunctionEnd
|
130
shaders/asm/geom/store-uint-layer.invalid.asm.geom
Normal file
130
shaders/asm/geom/store-uint-layer.invalid.asm.geom
Normal file
@ -0,0 +1,130 @@
|
||||
; SPIR-V
|
||||
; Version: 1.0
|
||||
; Generator: Khronos Glslang Reference Front End; 6
|
||||
; Bound: 74
|
||||
; Schema: 0
|
||||
OpCapability Geometry
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Geometry %main "main" %stream_pos %stream_layer %input_pos
|
||||
OpExecutionMode %main Triangles
|
||||
OpExecutionMode %main Invocations 1
|
||||
OpExecutionMode %main OutputTriangleStrip
|
||||
OpExecutionMode %main OutputVertices 3
|
||||
OpSource HLSL 500
|
||||
OpName %main "main"
|
||||
OpName %VertexOutput "VertexOutput"
|
||||
OpMemberName %VertexOutput 0 "pos"
|
||||
OpName %GeometryOutput "GeometryOutput"
|
||||
OpMemberName %GeometryOutput 0 "pos"
|
||||
OpMemberName %GeometryOutput 1 "layer"
|
||||
OpName %_main_struct_VertexOutput_vf41_3__struct_GeometryOutput_vf4_u11_ "@main(struct-VertexOutput-vf41[3];struct-GeometryOutput-vf4-u11;"
|
||||
OpName %input "input"
|
||||
OpName %stream "stream"
|
||||
OpName %output "output"
|
||||
OpName %v "v"
|
||||
OpName %stream_pos "stream.pos"
|
||||
OpName %stream_layer "stream.layer"
|
||||
OpName %input_0 "input"
|
||||
OpName %input_pos "input.pos"
|
||||
OpName %stream_0 "stream"
|
||||
OpName %param "param"
|
||||
OpName %param_0 "param"
|
||||
OpDecorate %stream_pos BuiltIn Position
|
||||
OpDecorate %stream_layer BuiltIn Layer
|
||||
OpDecorate %input_pos BuiltIn Position
|
||||
%void = OpTypeVoid
|
||||
%3 = OpTypeFunction %void
|
||||
%float = OpTypeFloat 32
|
||||
%v4float = OpTypeVector %float 4
|
||||
%VertexOutput = OpTypeStruct %v4float
|
||||
%uint = OpTypeInt 32 0
|
||||
%uint_3 = OpConstant %uint 3
|
||||
%_arr_VertexOutput_uint_3 = OpTypeArray %VertexOutput %uint_3
|
||||
%_ptr_Function__arr_VertexOutput_uint_3 = OpTypePointer Function %_arr_VertexOutput_uint_3
|
||||
%GeometryOutput = OpTypeStruct %v4float %uint
|
||||
%_ptr_Function_GeometryOutput = OpTypePointer Function %GeometryOutput
|
||||
%15 = OpTypeFunction %void %_ptr_Function__arr_VertexOutput_uint_3 %_ptr_Function_GeometryOutput
|
||||
%int = OpTypeInt 32 1
|
||||
%int_1 = OpConstant %int 1
|
||||
%uint_1 = OpConstant %uint 1
|
||||
%_ptr_Function_uint = OpTypePointer Function %uint
|
||||
%_ptr_Function_int = OpTypePointer Function %int
|
||||
%int_0 = OpConstant %int 0
|
||||
%int_3 = OpConstant %int 3
|
||||
%bool = OpTypeBool
|
||||
%_ptr_Function_v4float = OpTypePointer Function %v4float
|
||||
%_ptr_Output_v4float = OpTypePointer Output %v4float
|
||||
%stream_pos = OpVariable %_ptr_Output_v4float Output
|
||||
%_ptr_Output_uint = OpTypePointer Output %uint
|
||||
%stream_layer = OpVariable %_ptr_Output_uint Output
|
||||
%_arr_v4float_uint_3 = OpTypeArray %v4float %uint_3
|
||||
%_ptr_Input__arr_v4float_uint_3 = OpTypePointer Input %_arr_v4float_uint_3
|
||||
%input_pos = OpVariable %_ptr_Input__arr_v4float_uint_3 Input
|
||||
%_ptr_Input_v4float = OpTypePointer Input %v4float
|
||||
%int_2 = OpConstant %int 2
|
||||
%main = OpFunction %void None %3
|
||||
%5 = OpLabel
|
||||
%input_0 = OpVariable %_ptr_Function__arr_VertexOutput_uint_3 Function
|
||||
%stream_0 = OpVariable %_ptr_Function_GeometryOutput Function
|
||||
%param = OpVariable %_ptr_Function__arr_VertexOutput_uint_3 Function
|
||||
%param_0 = OpVariable %_ptr_Function_GeometryOutput Function
|
||||
%58 = OpAccessChain %_ptr_Input_v4float %input_pos %int_0
|
||||
%59 = OpLoad %v4float %58
|
||||
%60 = OpAccessChain %_ptr_Function_v4float %input_0 %int_0 %int_0
|
||||
OpStore %60 %59
|
||||
%61 = OpAccessChain %_ptr_Input_v4float %input_pos %int_1
|
||||
%62 = OpLoad %v4float %61
|
||||
%63 = OpAccessChain %_ptr_Function_v4float %input_0 %int_1 %int_0
|
||||
OpStore %63 %62
|
||||
%65 = OpAccessChain %_ptr_Input_v4float %input_pos %int_2
|
||||
%66 = OpLoad %v4float %65
|
||||
%67 = OpAccessChain %_ptr_Function_v4float %input_0 %int_2 %int_0
|
||||
OpStore %67 %66
|
||||
%70 = OpLoad %_arr_VertexOutput_uint_3 %input_0
|
||||
OpStore %param %70
|
||||
%72 = OpFunctionCall %void %_main_struct_VertexOutput_vf41_3__struct_GeometryOutput_vf4_u11_ %param %param_0
|
||||
%73 = OpLoad %GeometryOutput %param_0
|
||||
OpStore %stream_0 %73
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
%_main_struct_VertexOutput_vf41_3__struct_GeometryOutput_vf4_u11_ = OpFunction %void None %15
|
||||
%input = OpFunctionParameter %_ptr_Function__arr_VertexOutput_uint_3
|
||||
%stream = OpFunctionParameter %_ptr_Function_GeometryOutput
|
||||
%19 = OpLabel
|
||||
%output = OpVariable %_ptr_Function_GeometryOutput Function
|
||||
%v = OpVariable %_ptr_Function_int Function
|
||||
%25 = OpAccessChain %_ptr_Function_uint %output %int_1
|
||||
OpStore %25 %uint_1
|
||||
OpStore %v %int_0
|
||||
OpBranch %29
|
||||
%29 = OpLabel
|
||||
OpLoopMerge %31 %32 None
|
||||
OpBranch %33
|
||||
%33 = OpLabel
|
||||
%34 = OpLoad %int %v
|
||||
%37 = OpSLessThan %bool %34 %int_3
|
||||
OpBranchConditional %37 %30 %31
|
||||
%30 = OpLabel
|
||||
%38 = OpLoad %int %v
|
||||
%40 = OpAccessChain %_ptr_Function_v4float %input %38 %int_0
|
||||
%41 = OpLoad %v4float %40
|
||||
%42 = OpAccessChain %_ptr_Function_v4float %output %int_0
|
||||
OpStore %42 %41
|
||||
%45 = OpAccessChain %_ptr_Function_v4float %output %int_0
|
||||
%46 = OpLoad %v4float %45
|
||||
OpStore %stream_pos %46
|
||||
%49 = OpAccessChain %_ptr_Function_uint %output %int_1
|
||||
%50 = OpLoad %uint %49
|
||||
OpStore %stream_layer %50
|
||||
OpEmitVertex
|
||||
OpBranch %32
|
||||
%32 = OpLabel
|
||||
%51 = OpLoad %int %v
|
||||
%52 = OpIAdd %int %51 %int_1
|
||||
OpStore %v %52
|
||||
OpBranch %29
|
||||
%31 = OpLabel
|
||||
OpEndPrimitive
|
||||
OpReturn
|
||||
OpFunctionEnd
|
65
shaders/asm/vert/uint-vertex-id-instance-id.asm.vert
Normal file
65
shaders/asm/vert/uint-vertex-id-instance-id.asm.vert
Normal file
@ -0,0 +1,65 @@
|
||||
; SPIR-V
|
||||
; Version: 1.0
|
||||
; Generator: Khronos Glslang Reference Front End; 6
|
||||
; Bound: 36
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Vertex %main "main" %vid_1 %iid_1 %_entryPointOutput
|
||||
OpSource HLSL 500
|
||||
OpName %main "main"
|
||||
OpName %_main_u1_u1_ "@main(u1;u1;"
|
||||
OpName %vid "vid"
|
||||
OpName %iid "iid"
|
||||
OpName %vid_0 "vid"
|
||||
OpName %vid_1 "vid"
|
||||
OpName %iid_0 "iid"
|
||||
OpName %iid_1 "iid"
|
||||
OpName %_entryPointOutput "@entryPointOutput"
|
||||
OpName %param "param"
|
||||
OpName %param_0 "param"
|
||||
OpDecorate %vid_1 BuiltIn VertexIndex
|
||||
OpDecorate %iid_1 BuiltIn InstanceIndex
|
||||
OpDecorate %_entryPointOutput BuiltIn Position
|
||||
%void = OpTypeVoid
|
||||
%3 = OpTypeFunction %void
|
||||
%uint = OpTypeInt 32 0
|
||||
%_ptr_Function_uint = OpTypePointer Function %uint
|
||||
%float = OpTypeFloat 32
|
||||
%v4float = OpTypeVector %float 4
|
||||
%10 = OpTypeFunction %v4float %_ptr_Function_uint %_ptr_Function_uint
|
||||
%_ptr_Input_uint = OpTypePointer Input %uint
|
||||
%vid_1 = OpVariable %_ptr_Input_uint Input
|
||||
%iid_1 = OpVariable %_ptr_Input_uint Input
|
||||
%_ptr_Output_v4float = OpTypePointer Output %v4float
|
||||
%_entryPointOutput = OpVariable %_ptr_Output_v4float Output
|
||||
%main = OpFunction %void None %3
|
||||
%5 = OpLabel
|
||||
%vid_0 = OpVariable %_ptr_Function_uint Function
|
||||
%iid_0 = OpVariable %_ptr_Function_uint Function
|
||||
%param = OpVariable %_ptr_Function_uint Function
|
||||
%param_0 = OpVariable %_ptr_Function_uint Function
|
||||
%25 = OpLoad %uint %vid_1
|
||||
OpStore %vid_0 %25
|
||||
%28 = OpLoad %uint %iid_1
|
||||
OpStore %iid_0 %28
|
||||
%32 = OpLoad %uint %vid_0
|
||||
OpStore %param %32
|
||||
%34 = OpLoad %uint %iid_0
|
||||
OpStore %param_0 %34
|
||||
%35 = OpFunctionCall %v4float %_main_u1_u1_ %param %param_0
|
||||
OpStore %_entryPointOutput %35
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
%_main_u1_u1_ = OpFunction %v4float None %10
|
||||
%vid = OpFunctionParameter %_ptr_Function_uint
|
||||
%iid = OpFunctionParameter %_ptr_Function_uint
|
||||
%14 = OpLabel
|
||||
%15 = OpLoad %uint %vid
|
||||
%16 = OpLoad %uint %iid
|
||||
%17 = OpIAdd %uint %15 %16
|
||||
%18 = OpConvertUToF %float %17
|
||||
%19 = OpCompositeConstruct %v4float %18 %18 %18 %18
|
||||
OpReturnValue %19
|
||||
OpFunctionEnd
|
@ -4922,7 +4922,10 @@ string CompilerGLSL::builtin_to_glsl(BuiltIn builtin, StorageClass storage)
|
||||
else
|
||||
return "gl_InstanceID";
|
||||
case BuiltInPrimitiveId:
|
||||
return "gl_PrimitiveID";
|
||||
if (storage == StorageClassInput && get_entry_point().model == ExecutionModelGeometry)
|
||||
return "gl_PrimitiveIDIn";
|
||||
else
|
||||
return "gl_PrimitiveID";
|
||||
case BuiltInInvocationId:
|
||||
return "gl_InvocationID";
|
||||
case BuiltInLayer:
|
||||
@ -6083,6 +6086,9 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
|
||||
|
||||
auto expr = to_expression(ptr);
|
||||
|
||||
// We might need to bitcast in order to load from a builtin.
|
||||
bitcast_from_builtin_load(ptr, expr, get<SPIRType>(result_type));
|
||||
|
||||
if (ptr_expression)
|
||||
ptr_expression->need_transpose = old_need_transpose;
|
||||
|
||||
@ -6140,11 +6146,15 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
|
||||
else
|
||||
{
|
||||
auto rhs = to_expression(ops[1]);
|
||||
|
||||
// Statements to OpStore may be empty if it is a struct with zero members. Just forward the store to /dev/null.
|
||||
if (!rhs.empty())
|
||||
{
|
||||
auto lhs = to_expression(ops[0]);
|
||||
|
||||
// We might need to bitcast in order to store to a builtin.
|
||||
bitcast_to_builtin_store(ops[0], rhs, expression_type(ops[1]));
|
||||
|
||||
// Tries to optimize assignments like "<lhs> = <lhs> op expr".
|
||||
// While this is purely cosmetic, this is important for legacy ESSL where loop
|
||||
// variable increments must be in either i++ or i += const-expr.
|
||||
@ -9861,3 +9871,66 @@ void CompilerGLSL::emit_array_copy(const string &lhs, uint32_t rhs_id)
|
||||
{
|
||||
statement(lhs, " = ", to_expression(rhs_id), ";");
|
||||
}
|
||||
|
||||
void CompilerGLSL::bitcast_from_builtin_load(uint32_t source_id, std::string &expr,
|
||||
const spirv_cross::SPIRType &expr_type)
|
||||
{
|
||||
// Only interested in standalone builtin variables.
|
||||
if (!has_decoration(source_id, DecorationBuiltIn))
|
||||
return;
|
||||
|
||||
auto builtin = static_cast<BuiltIn>(get_decoration(source_id, DecorationBuiltIn));
|
||||
auto expected_type = expr_type.basetype;
|
||||
|
||||
// TODO: Fill in for more builtins.
|
||||
switch (builtin)
|
||||
{
|
||||
case BuiltInLayer:
|
||||
case BuiltInPrimitiveId:
|
||||
case BuiltInViewportIndex:
|
||||
case BuiltInInstanceId:
|
||||
case BuiltInInstanceIndex:
|
||||
case BuiltInVertexId:
|
||||
case BuiltInVertexIndex:
|
||||
case BuiltInSampleId:
|
||||
expected_type = SPIRType::Int;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (expected_type != expr_type.basetype)
|
||||
expr = bitcast_expression(expr_type, expected_type, expr);
|
||||
}
|
||||
|
||||
void CompilerGLSL::bitcast_to_builtin_store(uint32_t target_id, std::string &expr,
|
||||
const spirv_cross::SPIRType &expr_type)
|
||||
{
|
||||
// Only interested in standalone builtin variables.
|
||||
if (!has_decoration(target_id, DecorationBuiltIn))
|
||||
return;
|
||||
|
||||
auto builtin = static_cast<BuiltIn>(get_decoration(target_id, DecorationBuiltIn));
|
||||
auto expected_type = expr_type.basetype;
|
||||
|
||||
// TODO: Fill in for more builtins.
|
||||
switch (builtin)
|
||||
{
|
||||
case BuiltInLayer:
|
||||
case BuiltInPrimitiveId:
|
||||
case BuiltInViewportIndex:
|
||||
expected_type = SPIRType::Int;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (expected_type != expr_type.basetype)
|
||||
{
|
||||
auto type = expr_type;
|
||||
type.basetype = expected_type;
|
||||
expr = bitcast_expression(type, expr_type.basetype, expr);
|
||||
}
|
||||
}
|
||||
|
@ -565,6 +565,12 @@ protected:
|
||||
|
||||
std::string convert_separate_image_to_combined(uint32_t id);
|
||||
|
||||
// Builtins in GLSL are always specific signedness, but the SPIR-V can declare them
|
||||
// as either unsigned or signed.
|
||||
// Sometimes we will need to automatically perform bitcasts on load and store to make this work.
|
||||
virtual void bitcast_to_builtin_store(uint32_t target_id, std::string &expr, const SPIRType &expr_type);
|
||||
virtual void bitcast_from_builtin_load(uint32_t source_id, std::string &expr, const SPIRType &expr_type);
|
||||
|
||||
private:
|
||||
void init()
|
||||
{
|
||||
|
@ -4179,3 +4179,12 @@ void CompilerMSL::remap_constexpr_sampler(uint32_t id, const spirv_cross::MSLCon
|
||||
SPIRV_CROSS_THROW("Can not remap array of samplers.");
|
||||
constexpr_samplers[id] = sampler;
|
||||
}
|
||||
|
||||
// MSL always declares builtins with their SPIR-V type.
|
||||
void CompilerMSL::bitcast_from_builtin_load(uint32_t, std::string &, const spirv_cross::SPIRType &)
|
||||
{
|
||||
}
|
||||
|
||||
void CompilerMSL::bitcast_to_builtin_store(uint32_t, std::string &, const spirv_cross::SPIRType &)
|
||||
{
|
||||
}
|
||||
|
@ -356,6 +356,9 @@ protected:
|
||||
void emit_entry_point_declarations() override;
|
||||
uint32_t builtin_frag_coord_id = 0;
|
||||
|
||||
void bitcast_to_builtin_store(uint32_t target_id, std::string &expr, const SPIRType &expr_type) override;
|
||||
void bitcast_from_builtin_load(uint32_t source_id, std::string &expr, const SPIRType &expr_type) override;
|
||||
|
||||
Options msl_options;
|
||||
std::set<SPVFuncImpl> spv_function_implementations;
|
||||
std::unordered_map<uint32_t, MSLVertexAttr *> vtx_attrs_by_location;
|
||||
|
Loading…
Reference in New Issue
Block a user