From a07b462e36141a84f32c8b027bee92f2c36eb044 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Thu, 23 Jan 2025 11:36:46 +0100 Subject: [PATCH] GLSL: Deal with gl_Layer in vert/tese. --- reference/shaders-no-opt/vert/vertex-layer.vert | 17 +++++++++++++++++ shaders-no-opt/vert/vertex-layer.vert | 7 +++++++ spirv_glsl.cpp | 10 ++++++++++ 3 files changed, 34 insertions(+) create mode 100644 reference/shaders-no-opt/vert/vertex-layer.vert create mode 100644 shaders-no-opt/vert/vertex-layer.vert diff --git a/reference/shaders-no-opt/vert/vertex-layer.vert b/reference/shaders-no-opt/vert/vertex-layer.vert new file mode 100644 index 000000000..ae2388bdf --- /dev/null +++ b/reference/shaders-no-opt/vert/vertex-layer.vert @@ -0,0 +1,17 @@ +#version 450 +#ifdef GL_ARB_shader_draw_parameters +#extension GL_ARB_shader_draw_parameters : enable +#endif +#extension GL_ARB_shader_viewport_layer_array : require + +#ifdef GL_ARB_shader_draw_parameters +#define SPIRV_Cross_BaseInstance gl_BaseInstanceARB +#else +uniform int SPIRV_Cross_BaseInstance; +#endif + +void main() +{ + gl_Layer = (gl_InstanceID + SPIRV_Cross_BaseInstance); +} + diff --git a/shaders-no-opt/vert/vertex-layer.vert b/shaders-no-opt/vert/vertex-layer.vert new file mode 100644 index 000000000..a6f4ec87f --- /dev/null +++ b/shaders-no-opt/vert/vertex-layer.vert @@ -0,0 +1,7 @@ +#version 450 +#extension GL_ARB_shader_viewport_layer_array : require + +void main() +{ + gl_Layer = gl_InstanceIndex; +} diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index be65c042c..5f087a847 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -9824,7 +9824,17 @@ string CompilerGLSL::builtin_to_glsl(BuiltIn builtin, StorageClass storage) case BuiltInInvocationId: return "gl_InvocationID"; case BuiltInLayer: + { + auto model = get_execution_model(); + if (model == ExecutionModelVertex || model == ExecutionModelTessellationEvaluation) + { + if (options.es) + require_extension_internal("GL_NV_viewport_array2"); + else + require_extension_internal("GL_ARB_shader_viewport_layer_array"); + } return "gl_Layer"; + } case BuiltInViewportIndex: return "gl_ViewportIndex"; case BuiltInTessLevelOuter: