Handle reserved identifiers for functions.
gl_ identifiers are already handled by fixups, so remove redundant code.
This commit is contained in:
parent
c4ff129fe3
commit
ddb3c65648
@ -0,0 +1,31 @@
|
||||
static float FragColor;
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float FragColor : SV_Target0;
|
||||
};
|
||||
|
||||
float _mat3(float a)
|
||||
{
|
||||
return a + 1.0f;
|
||||
}
|
||||
|
||||
float _RESERVED_IDENTIFIER_FIXUP_gl_Foo(int a)
|
||||
{
|
||||
return float(a) + 1.0f;
|
||||
}
|
||||
|
||||
void frag_main()
|
||||
{
|
||||
float param = 2.0f;
|
||||
int param_1 = 4;
|
||||
FragColor = _mat3(param) + _RESERVED_IDENTIFIER_FIXUP_gl_Foo(param_1);
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main()
|
||||
{
|
||||
frag_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.FragColor = FragColor;
|
||||
return stage_output;
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
#pragma clang diagnostic ignored "-Wmissing-prototypes"
|
||||
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
struct main0_out
|
||||
{
|
||||
float FragColor [[color(0)]];
|
||||
};
|
||||
|
||||
static inline __attribute__((always_inline))
|
||||
float _mat3(thread const float& a)
|
||||
{
|
||||
return a + 1.0;
|
||||
}
|
||||
|
||||
static inline __attribute__((always_inline))
|
||||
float _RESERVED_IDENTIFIER_FIXUP_gl_Foo(thread const int& a)
|
||||
{
|
||||
return float(a) + 1.0;
|
||||
}
|
||||
|
||||
fragment main0_out main0()
|
||||
{
|
||||
main0_out out = {};
|
||||
float param = 2.0;
|
||||
int param_1 = 4;
|
||||
out.FragColor = _mat3(param) + _RESERVED_IDENTIFIER_FIXUP_gl_Foo(param_1);
|
||||
return out;
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) out float FragColor;
|
||||
|
||||
float _mat3(float a)
|
||||
{
|
||||
return a + 1.0;
|
||||
}
|
||||
|
||||
float _RESERVED_IDENTIFIER_FIXUP_gl_Foo(int a)
|
||||
{
|
||||
return float(a) + 1.0;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float param = 2.0;
|
||||
int param_1 = 4;
|
||||
FragColor = _mat3(param) + _RESERVED_IDENTIFIER_FIXUP_gl_Foo(param_1);
|
||||
}
|
||||
|
@ -0,0 +1,60 @@
|
||||
; SPIR-V
|
||||
; Version: 1.0
|
||||
; Generator: Khronos Glslang Reference Front End; 10
|
||||
; Bound: 37
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Fragment %main "main" %FragColor
|
||||
OpExecutionMode %main OriginUpperLeft
|
||||
OpSource GLSL 450
|
||||
OpName %main "main"
|
||||
OpName %ACOS_f1_ "mat3"
|
||||
OpName %a "a"
|
||||
OpName %ACOS_i1_ "gl_Foo"
|
||||
OpName %a_0 "a"
|
||||
OpName %FragColor "FragColor"
|
||||
OpName %param "param"
|
||||
OpName %param_0 "param"
|
||||
OpDecorate %FragColor Location 0
|
||||
%void = OpTypeVoid
|
||||
%3 = OpTypeFunction %void
|
||||
%float = OpTypeFloat 32
|
||||
%_ptr_Function_float = OpTypePointer Function %float
|
||||
%8 = OpTypeFunction %float %_ptr_Function_float
|
||||
%int = OpTypeInt 32 1
|
||||
%_ptr_Function_int = OpTypePointer Function %int
|
||||
%14 = OpTypeFunction %float %_ptr_Function_int
|
||||
%float_1 = OpConstant %float 1
|
||||
%_ptr_Output_float = OpTypePointer Output %float
|
||||
%FragColor = OpVariable %_ptr_Output_float Output
|
||||
%float_2 = OpConstant %float 2
|
||||
%int_4 = OpConstant %int 4
|
||||
%main = OpFunction %void None %3
|
||||
%5 = OpLabel
|
||||
%param = OpVariable %_ptr_Function_float Function
|
||||
%param_0 = OpVariable %_ptr_Function_int Function
|
||||
OpStore %param %float_2
|
||||
%32 = OpFunctionCall %float %ACOS_f1_ %param
|
||||
OpStore %param_0 %int_4
|
||||
%35 = OpFunctionCall %float %ACOS_i1_ %param_0
|
||||
%36 = OpFAdd %float %32 %35
|
||||
OpStore %FragColor %36
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
%ACOS_f1_ = OpFunction %float None %8
|
||||
%a = OpFunctionParameter %_ptr_Function_float
|
||||
%11 = OpLabel
|
||||
%18 = OpLoad %float %a
|
||||
%20 = OpFAdd %float %18 %float_1
|
||||
OpReturnValue %20
|
||||
OpFunctionEnd
|
||||
%ACOS_i1_ = OpFunction %float None %14
|
||||
%a_0 = OpFunctionParameter %_ptr_Function_int
|
||||
%17 = OpLabel
|
||||
%23 = OpLoad %int %a_0
|
||||
%24 = OpConvertSToF %float %23
|
||||
%25 = OpFAdd %float %24 %float_1
|
||||
OpReturnValue %25
|
||||
OpFunctionEnd
|
@ -0,0 +1,60 @@
|
||||
; SPIR-V
|
||||
; Version: 1.0
|
||||
; Generator: Khronos Glslang Reference Front End; 10
|
||||
; Bound: 37
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Fragment %main "main" %FragColor
|
||||
OpExecutionMode %main OriginUpperLeft
|
||||
OpSource GLSL 450
|
||||
OpName %main "main"
|
||||
OpName %ACOS_f1_ "mat3"
|
||||
OpName %a "a"
|
||||
OpName %ACOS_i1_ "gl_Foo"
|
||||
OpName %a_0 "a"
|
||||
OpName %FragColor "FragColor"
|
||||
OpName %param "param"
|
||||
OpName %param_0 "param"
|
||||
OpDecorate %FragColor Location 0
|
||||
%void = OpTypeVoid
|
||||
%3 = OpTypeFunction %void
|
||||
%float = OpTypeFloat 32
|
||||
%_ptr_Function_float = OpTypePointer Function %float
|
||||
%8 = OpTypeFunction %float %_ptr_Function_float
|
||||
%int = OpTypeInt 32 1
|
||||
%_ptr_Function_int = OpTypePointer Function %int
|
||||
%14 = OpTypeFunction %float %_ptr_Function_int
|
||||
%float_1 = OpConstant %float 1
|
||||
%_ptr_Output_float = OpTypePointer Output %float
|
||||
%FragColor = OpVariable %_ptr_Output_float Output
|
||||
%float_2 = OpConstant %float 2
|
||||
%int_4 = OpConstant %int 4
|
||||
%main = OpFunction %void None %3
|
||||
%5 = OpLabel
|
||||
%param = OpVariable %_ptr_Function_float Function
|
||||
%param_0 = OpVariable %_ptr_Function_int Function
|
||||
OpStore %param %float_2
|
||||
%32 = OpFunctionCall %float %ACOS_f1_ %param
|
||||
OpStore %param_0 %int_4
|
||||
%35 = OpFunctionCall %float %ACOS_i1_ %param_0
|
||||
%36 = OpFAdd %float %32 %35
|
||||
OpStore %FragColor %36
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
%ACOS_f1_ = OpFunction %float None %8
|
||||
%a = OpFunctionParameter %_ptr_Function_float
|
||||
%11 = OpLabel
|
||||
%18 = OpLoad %float %a
|
||||
%20 = OpFAdd %float %18 %float_1
|
||||
OpReturnValue %20
|
||||
OpFunctionEnd
|
||||
%ACOS_i1_ = OpFunction %float None %14
|
||||
%a_0 = OpFunctionParameter %_ptr_Function_int
|
||||
%17 = OpLabel
|
||||
%23 = OpLoad %int %a_0
|
||||
%24 = OpConvertSToF %float %23
|
||||
%25 = OpFAdd %float %24 %float_1
|
||||
OpReturnValue %25
|
||||
OpFunctionEnd
|
@ -0,0 +1,60 @@
|
||||
; SPIR-V
|
||||
; Version: 1.0
|
||||
; Generator: Khronos Glslang Reference Front End; 10
|
||||
; Bound: 37
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Fragment %main "main" %FragColor
|
||||
OpExecutionMode %main OriginUpperLeft
|
||||
OpSource GLSL 450
|
||||
OpName %main "main"
|
||||
OpName %ACOS_f1_ "mat3"
|
||||
OpName %a "a"
|
||||
OpName %ACOS_i1_ "gl_Foo"
|
||||
OpName %a_0 "a"
|
||||
OpName %FragColor "FragColor"
|
||||
OpName %param "param"
|
||||
OpName %param_0 "param"
|
||||
OpDecorate %FragColor Location 0
|
||||
%void = OpTypeVoid
|
||||
%3 = OpTypeFunction %void
|
||||
%float = OpTypeFloat 32
|
||||
%_ptr_Function_float = OpTypePointer Function %float
|
||||
%8 = OpTypeFunction %float %_ptr_Function_float
|
||||
%int = OpTypeInt 32 1
|
||||
%_ptr_Function_int = OpTypePointer Function %int
|
||||
%14 = OpTypeFunction %float %_ptr_Function_int
|
||||
%float_1 = OpConstant %float 1
|
||||
%_ptr_Output_float = OpTypePointer Output %float
|
||||
%FragColor = OpVariable %_ptr_Output_float Output
|
||||
%float_2 = OpConstant %float 2
|
||||
%int_4 = OpConstant %int 4
|
||||
%main = OpFunction %void None %3
|
||||
%5 = OpLabel
|
||||
%param = OpVariable %_ptr_Function_float Function
|
||||
%param_0 = OpVariable %_ptr_Function_int Function
|
||||
OpStore %param %float_2
|
||||
%32 = OpFunctionCall %float %ACOS_f1_ %param
|
||||
OpStore %param_0 %int_4
|
||||
%35 = OpFunctionCall %float %ACOS_i1_ %param_0
|
||||
%36 = OpFAdd %float %32 %35
|
||||
OpStore %FragColor %36
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
%ACOS_f1_ = OpFunction %float None %8
|
||||
%a = OpFunctionParameter %_ptr_Function_float
|
||||
%11 = OpLabel
|
||||
%18 = OpLoad %float %a
|
||||
%20 = OpFAdd %float %18 %float_1
|
||||
OpReturnValue %20
|
||||
OpFunctionEnd
|
||||
%ACOS_i1_ = OpFunction %float None %14
|
||||
%a_0 = OpFunctionParameter %_ptr_Function_int
|
||||
%17 = OpLabel
|
||||
%23 = OpLoad %int %a_0
|
||||
%24 = OpConvertSToF %float %23
|
||||
%25 = OpFAdd %float %24 %float_1
|
||||
OpReturnValue %25
|
||||
OpFunctionEnd
|
@ -2551,7 +2551,17 @@ void CompilerGLSL::replace_illegal_names(const unordered_set<string> &keywords)
|
||||
return;
|
||||
|
||||
auto &m = meta->decoration;
|
||||
if (m.alias.compare(0, 3, "gl_") == 0 || keywords.find(m.alias) != end(keywords))
|
||||
if (keywords.find(m.alias) != end(keywords))
|
||||
m.alias = join("_", m.alias);
|
||||
});
|
||||
|
||||
ir.for_each_typed_id<SPIRFunction>([&](uint32_t, const SPIRFunction &func) {
|
||||
auto *meta = ir.find_meta(func.self);
|
||||
if (!meta)
|
||||
return;
|
||||
|
||||
auto &m = meta->decoration;
|
||||
if (keywords.find(m.alias) != end(keywords))
|
||||
m.alias = join("_", m.alias);
|
||||
});
|
||||
|
||||
@ -2561,11 +2571,11 @@ void CompilerGLSL::replace_illegal_names(const unordered_set<string> &keywords)
|
||||
return;
|
||||
|
||||
auto &m = meta->decoration;
|
||||
if (m.alias.compare(0, 3, "gl_") == 0 || keywords.find(m.alias) != end(keywords))
|
||||
if (keywords.find(m.alias) != end(keywords))
|
||||
m.alias = join("_", m.alias);
|
||||
|
||||
for (auto &memb : meta->members)
|
||||
if (memb.alias.compare(0, 3, "gl_") == 0 || keywords.find(memb.alias) != end(keywords))
|
||||
if (keywords.find(memb.alias) != end(keywords))
|
||||
memb.alias = join("_", memb.alias);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user