mirror of
https://github.com/KhronosGroup/SPIRV-Cross.git
synced 2024-09-19 14:19:59 +00:00
HLSL: Support PointSize output in vertex shader in SM 3.0
This commit is contained in:
parent
4212eef67e
commit
26da9c58a6
26
reference/opt/shaders-hlsl/vert/point-size.sm30.vert
Normal file
26
reference/opt/shaders-hlsl/vert/point-size.sm30.vert
Normal file
@ -0,0 +1,26 @@
|
||||
uniform float4 gl_HalfPixel;
|
||||
|
||||
static float4 gl_Position;
|
||||
static float gl_PointSize;
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float4 gl_Position : POSITION;
|
||||
float gl_PointSize : PSIZE;
|
||||
};
|
||||
|
||||
void vert_main()
|
||||
{
|
||||
gl_Position = 1.0f.xxxx;
|
||||
gl_PointSize = 4.0f;
|
||||
gl_Position.x = gl_Position.x - gl_HalfPixel.x * gl_Position.w;
|
||||
gl_Position.y = gl_Position.y + gl_HalfPixel.y * gl_Position.w;
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main()
|
||||
{
|
||||
vert_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.gl_Position = gl_Position;
|
||||
stage_output.gl_PointSize = gl_PointSize;
|
||||
return stage_output;
|
||||
}
|
26
reference/shaders-hlsl/vert/point-size.sm30.vert
Normal file
26
reference/shaders-hlsl/vert/point-size.sm30.vert
Normal file
@ -0,0 +1,26 @@
|
||||
uniform float4 gl_HalfPixel;
|
||||
|
||||
static float4 gl_Position;
|
||||
static float gl_PointSize;
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float4 gl_Position : POSITION;
|
||||
float gl_PointSize : PSIZE;
|
||||
};
|
||||
|
||||
void vert_main()
|
||||
{
|
||||
gl_Position = 1.0f.xxxx;
|
||||
gl_PointSize = 4.0f;
|
||||
gl_Position.x = gl_Position.x - gl_HalfPixel.x * gl_Position.w;
|
||||
gl_Position.y = gl_Position.y + gl_HalfPixel.y * gl_Position.w;
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main()
|
||||
{
|
||||
vert_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.gl_Position = gl_Position;
|
||||
stage_output.gl_PointSize = gl_PointSize;
|
||||
return stage_output;
|
||||
}
|
7
shaders-hlsl/vert/point-size.sm30.vert
Normal file
7
shaders-hlsl/vert/point-size.sm30.vert
Normal file
@ -0,0 +1,7 @@
|
||||
#version 310 es
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(1.0);
|
||||
gl_PointSize = 4.0;
|
||||
}
|
@ -682,10 +682,14 @@ void CompilerHLSL::emit_builtin_outputs_in_struct()
|
||||
// If point_size_compat is enabled, just ignore PointSize.
|
||||
// PointSize does not exist in HLSL, but some code bases might want to be able to use these shaders,
|
||||
// even if it means working around the missing feature.
|
||||
if (hlsl_options.point_size_compat)
|
||||
break;
|
||||
else
|
||||
if (legacy)
|
||||
{
|
||||
type = "float";
|
||||
semantic = "PSIZE";
|
||||
}
|
||||
else if (!hlsl_options.point_size_compat)
|
||||
SPIRV_CROSS_THROW("Unsupported builtin in HLSL.");
|
||||
break;
|
||||
|
||||
case BuiltInLayer:
|
||||
case BuiltInPrimitiveId:
|
||||
@ -1226,7 +1230,7 @@ void CompilerHLSL::emit_builtin_variables()
|
||||
break;
|
||||
|
||||
case BuiltInPointSize:
|
||||
if (hlsl_options.point_size_compat)
|
||||
if (hlsl_options.point_size_compat || hlsl_options.shader_model <= 30)
|
||||
{
|
||||
// Just emit the global variable, it will be ignored.
|
||||
type = "float";
|
||||
@ -3223,8 +3227,8 @@ void CompilerHLSL::emit_hlsl_entry_point()
|
||||
|
||||
// Copy builtins from globals to return struct.
|
||||
active_output_builtins.for_each_bit([&](uint32_t i) {
|
||||
// PointSize doesn't exist in HLSL.
|
||||
if (i == BuiltInPointSize)
|
||||
// PointSize doesn't exist in HLSL SM 4+.
|
||||
if (i == BuiltInPointSize && !legacy)
|
||||
return;
|
||||
|
||||
switch (static_cast<BuiltIn>(i))
|
||||
|
@ -110,7 +110,7 @@ public:
|
||||
{
|
||||
uint32_t shader_model = 30; // TODO: map ps_4_0_level_9_0,... somehow
|
||||
|
||||
// Allows the PointSize builtin, and ignores it, as PointSize is not supported in HLSL.
|
||||
// Allows the PointSize builtin in SM 4.0+, and ignores it, as PointSize is not supported in SM 4+.
|
||||
bool point_size_compat = false;
|
||||
|
||||
// Allows the PointCoord builtin, returns float2(0.5, 0.5), as PointCoord is not supported in HLSL.
|
||||
|
Loading…
Reference in New Issue
Block a user