From 56350cadfe88ca847e920a1ac377b700b84190c7 Mon Sep 17 00:00:00 2001 From: Sidney Just Date: Mon, 2 Nov 2020 11:27:40 -0800 Subject: [PATCH] Support for CapabilityShaderViewportIndex and CapabilityShaderLayer (#2432) * When targeting SPIR-V 1.5, using gl_ViewportIndex will emit OpCapability ShaderViewportIndex and using gl_Layer will emit OpCapability CapabilityShaderLayer. OpCapability ShaderViewportIndexLayerEXT will only get emitted if the target < SPIR-V 1.5 * When using one of the viewport/layer arrays extensions, fallback to OpCapability ShaderViewportIndexLayerEXT, even when targeting SPIR-V 1.5 * Revert "When using one of the viewport/layer arrays extensions, fallback to OpCapability ShaderViewportIndexLayerEXT, even when targeting SPIR-V 1.5" This reverts commit dccca82f4076ea6e2bc01dd6d1e5d290c59fab20. * Using gl_Layer and gl_ViewportIndex outside of the geometry shader stage still requires one of the viewport extensions even when targeting SPIR-V 1.5 (Fixes a problem introduced by 670536b663f396815645b2f907f0ee92117b44f0) --- SPIRV/GlslangToSpv.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index 1d153c0..0b6c62b 100644 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -714,8 +714,12 @@ spv::BuiltIn TGlslangToSpvTraverser::TranslateBuiltInDecoration(glslang::TBuiltI glslangIntermediate->getStage() == EShLangTessControl || glslangIntermediate->getStage() == EShLangTessEvaluation) { - builder.addIncorporatedExtension(spv::E_SPV_EXT_shader_viewport_index_layer, spv::Spv_1_5); - builder.addCapability(spv::CapabilityShaderViewportIndexLayerEXT); + if (builder.getSpvVersion() < spv::Spv_1_5) { + builder.addIncorporatedExtension(spv::E_SPV_EXT_shader_viewport_index_layer, spv::Spv_1_5); + builder.addCapability(spv::CapabilityShaderViewportIndexLayerEXT); + } + else + builder.addCapability(spv::CapabilityShaderViewportIndex); } return spv::BuiltInViewportIndex; @@ -739,8 +743,11 @@ spv::BuiltIn TGlslangToSpvTraverser::TranslateBuiltInDecoration(glslang::TBuiltI glslangIntermediate->getStage() == EShLangTessControl || glslangIntermediate->getStage() == EShLangTessEvaluation) { - builder.addIncorporatedExtension(spv::E_SPV_EXT_shader_viewport_index_layer, spv::Spv_1_5); - builder.addCapability(spv::CapabilityShaderViewportIndexLayerEXT); + if (builder.getSpvVersion() < spv::Spv_1_5) { + builder.addIncorporatedExtension(spv::E_SPV_EXT_shader_viewport_index_layer, spv::Spv_1_5); + builder.addCapability(spv::CapabilityShaderViewportIndexLayerEXT); + } else + builder.addCapability(spv::CapabilityShaderLayer); } return spv::BuiltInLayer; -- 2.7.4