mirror of
https://github.com/KhronosGroup/SPIRV-Cross.git
synced 2024-11-12 15:10:30 +00:00
Add workaround for PointCoord builtin on HLSL.
This commit is contained in:
parent
fb196c2565
commit
f6d08e6113
1
main.cpp
1
main.cpp
@ -818,6 +818,7 @@ static int main_inner(int argc, char *argv[])
|
||||
{
|
||||
// Enable all compat options.
|
||||
hlsl_opts.point_size_compat = true;
|
||||
hlsl_opts.point_coord_compat = true;
|
||||
}
|
||||
hlsl->set_options(hlsl_opts);
|
||||
}
|
||||
|
19
reference/opt/shaders-hlsl/frag/point-coord-compat.frag
Normal file
19
reference/opt/shaders-hlsl/frag/point-coord-compat.frag
Normal file
@ -0,0 +1,19 @@
|
||||
static float2 FragColor;
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float2 FragColor : SV_Target0;
|
||||
};
|
||||
|
||||
void frag_main()
|
||||
{
|
||||
FragColor = float2(0.5f, 0.5f);
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main()
|
||||
{
|
||||
frag_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.FragColor = FragColor;
|
||||
return stage_output;
|
||||
}
|
@ -8,7 +8,7 @@ struct SPIRV_Cross_Output
|
||||
void vert_main()
|
||||
{
|
||||
gl_Position = 1.0f.xxxx;
|
||||
gl_PointSize = 10.0f;
|
||||
gl_PointSize = 1.0f;
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main()
|
||||
|
19
reference/shaders-hlsl/frag/point-coord-compat.frag
Normal file
19
reference/shaders-hlsl/frag/point-coord-compat.frag
Normal file
@ -0,0 +1,19 @@
|
||||
static float2 FragColor;
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float2 FragColor : SV_Target0;
|
||||
};
|
||||
|
||||
void frag_main()
|
||||
{
|
||||
FragColor = float2(0.5f, 0.5f);
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main()
|
||||
{
|
||||
frag_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.FragColor = FragColor;
|
||||
return stage_output;
|
||||
}
|
@ -8,7 +8,7 @@ struct SPIRV_Cross_Output
|
||||
void vert_main()
|
||||
{
|
||||
gl_Position = 1.0f.xxxx;
|
||||
gl_PointSize = 10.0f;
|
||||
gl_PointSize = 1.0f;
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main()
|
||||
|
10
shaders-hlsl/frag/point-coord-compat.frag
Normal file
10
shaders-hlsl/frag/point-coord-compat.frag
Normal file
@ -0,0 +1,10 @@
|
||||
#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
layout(location = 0) out vec2 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = gl_PointCoord;
|
||||
}
|
||||
|
@ -3,6 +3,5 @@
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(1.0);
|
||||
gl_PointSize = 10.0;
|
||||
gl_PointSize = 1.0;
|
||||
}
|
||||
|
||||
|
@ -662,6 +662,13 @@ void CompilerHLSL::emit_builtin_inputs_in_struct()
|
||||
}
|
||||
break;
|
||||
|
||||
case BuiltInPointCoord:
|
||||
// PointCoord is not supported, but provide a way to just ignore that, similar to PointSize.
|
||||
if (options.point_coord_compat)
|
||||
break;
|
||||
else
|
||||
SPIRV_CROSS_THROW("Unsupported builtin in HLSL.");
|
||||
|
||||
default:
|
||||
SPIRV_CROSS_THROW("Unsupported builtin in HLSL.");
|
||||
break;
|
||||
@ -856,6 +863,9 @@ std::string CompilerHLSL::builtin_to_glsl(spv::BuiltIn builtin, spv::StorageClas
|
||||
auto &type = get<SPIRType>(var.basetype);
|
||||
return sanitize_underscores(join(to_name(num_workgroups_builtin), "_", get_member_name(type.self, 0)));
|
||||
}
|
||||
case BuiltInPointCoord:
|
||||
// Crude hack, but there is no real alternative. This path is only enabled if point_coord_compat is set.
|
||||
return "float2(0.5f, 0.5f)";
|
||||
default:
|
||||
return CompilerGLSL::builtin_to_glsl(builtin, storage);
|
||||
}
|
||||
@ -917,6 +927,7 @@ void CompilerHLSL::emit_builtin_variables()
|
||||
break;
|
||||
|
||||
case BuiltInNumWorkgroups:
|
||||
case BuiltInPointCoord:
|
||||
// Handled specially.
|
||||
break;
|
||||
|
||||
@ -1214,7 +1225,9 @@ void CompilerHLSL::emit_resources()
|
||||
return name1.compare(name2) < 0;
|
||||
};
|
||||
|
||||
if (!input_variables.empty() || (active_input_builtins & ~(1ull << BuiltInNumWorkgroups)))
|
||||
static const uint64_t implicit_builtins = (1ull << BuiltInNumWorkgroups) |
|
||||
(1ull << BuiltInPointCoord);
|
||||
if (!input_variables.empty() || (active_input_builtins & ~implicit_builtins))
|
||||
{
|
||||
require_input = true;
|
||||
statement("struct SPIRV_Cross_Input");
|
||||
@ -1926,6 +1939,7 @@ void CompilerHLSL::emit_hlsl_entry_point()
|
||||
break;
|
||||
|
||||
case BuiltInNumWorkgroups:
|
||||
case BuiltInPointCoord:
|
||||
break;
|
||||
|
||||
case BuiltInClipDistance:
|
||||
@ -3918,6 +3932,7 @@ string CompilerHLSL::compile(std::vector<HLSLVertexAttributeRemap> vertex_attrib
|
||||
uint32_t CompilerHLSL::remap_num_workgroups_builtin()
|
||||
{
|
||||
update_active_builtins();
|
||||
|
||||
if ((active_input_builtins & (1ull << BuiltInNumWorkgroups)) == 0)
|
||||
return 0;
|
||||
|
||||
|
@ -51,6 +51,9 @@ public:
|
||||
|
||||
// Allows the PointSize builtin, and ignores it, as PointSize is not supported in HLSL.
|
||||
bool point_size_compat = false;
|
||||
|
||||
// Allows the PointCoord builtin, returns float2(0.5, 0.5), as PointCoord is not supported in HLSL.
|
||||
bool point_coord_compat = false;
|
||||
};
|
||||
|
||||
CompilerHLSL(std::vector<uint32_t> spirv_)
|
||||
|
Loading…
Reference in New Issue
Block a user