GLSL: Support shading rate builtins.

This commit is contained in:
Hans-Kristian Arntzen 2021-04-20 13:58:07 +02:00
parent 3cb8e7c223
commit c89b5a1a3f
5 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,10 @@
#version 450
#extension GL_EXT_fragment_shading_rate : require
layout(location = 0) out uint FragColor;
void main()
{
FragColor = uint(gl_ShadingRateEXT);
}

View File

@ -0,0 +1,9 @@
#version 450
#extension GL_EXT_fragment_shading_rate : require
void main()
{
gl_PrimitiveShadingRateEXT = 3;
gl_Position = vec4(1.0);
}

View File

@ -0,0 +1,9 @@
#version 450
#extension GL_EXT_fragment_shading_rate : require
layout(location = 0) out uint FragColor;
void main()
{
FragColor = gl_ShadingRateEXT;
}

View File

@ -0,0 +1,8 @@
#version 450
#extension GL_EXT_fragment_shading_rate : require
void main()
{
gl_PrimitiveShadingRateEXT = 3;
gl_Position = vec4(1.0);
}

View File

@ -8317,6 +8317,22 @@ string CompilerGLSL::builtin_to_glsl(BuiltIn builtin, StorageClass storage)
SPIRV_CROSS_THROW("Stencil export not supported in GLES.");
}
case BuiltInPrimitiveShadingRateKHR:
{
if (!options.vulkan_semantics)
SPIRV_CROSS_THROW("Can only use PrimitiveShadingRateKHR in Vulkan GLSL.");
require_extension_internal("GL_EXT_fragment_shading_rate");
return "gl_PrimitiveShadingRateEXT";
}
case BuiltInShadingRateKHR:
{
if (!options.vulkan_semantics)
SPIRV_CROSS_THROW("Can only use ShadingRateKHR in Vulkan GLSL.");
require_extension_internal("GL_EXT_fragment_shading_rate");
return "gl_ShadingRateEXT";
}
case BuiltInDeviceIndex:
if (!options.vulkan_semantics)
SPIRV_CROSS_THROW("Need Vulkan semantics for device group support.");
@ -15149,6 +15165,8 @@ void CompilerGLSL::cast_from_builtin_load(uint32_t source_id, std::string &expr,
case BuiltInFragStencilRefEXT:
case BuiltInInstanceCustomIndexNV:
case BuiltInSampleMask:
case BuiltInPrimitiveShadingRateKHR:
case BuiltInShadingRateKHR:
expected_type = SPIRType::Int;
break;
@ -15193,6 +15211,8 @@ void CompilerGLSL::cast_to_builtin_store(uint32_t target_id, std::string &expr,
case BuiltInViewportIndex:
case BuiltInFragStencilRefEXT:
case BuiltInSampleMask:
case BuiltInPrimitiveShadingRateKHR:
case BuiltInShadingRateKHR:
expected_type = SPIRType::Int;
break;