From a5c5fb61180e8703ca85f36d618f98e16dc317e2 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Fri, 5 May 2017 05:09:58 -0600 Subject: [PATCH] SPV: Emit extension for using StorageClassStorageBuffer. --- SPIRV/GLSL.ext.KHR.h | 13 +++--- SPIRV/GlslangToSpv.cpp | 72 +++++++++++++++-------------- Test/baseResults/spv.storageBuffer.vert.out | 1 + 3 files changed, 45 insertions(+), 41 deletions(-) diff --git a/SPIRV/GLSL.ext.KHR.h b/SPIRV/GLSL.ext.KHR.h index 4c3a571..c9e31a6 100644 --- a/SPIRV/GLSL.ext.KHR.h +++ b/SPIRV/GLSL.ext.KHR.h @@ -34,11 +34,12 @@ enum Capability; static const int GLSLextKHRVersion = 100; static const int GLSLextKHRRevision = 1; -static const char* const E_SPV_KHR_shader_ballot = "SPV_KHR_shader_ballot"; -static const char* const E_SPV_KHR_subgroup_vote = "SPV_KHR_subgroup_vote"; -static const char* const E_SPV_KHR_device_group = "SPV_KHR_device_group"; -static const char* const E_SPV_KHR_multiview = "SPV_KHR_multiview"; -static const char* const E_SPV_KHR_shader_draw_parameters = "SPV_KHR_shader_draw_parameters"; -static const char* const E_SPV_KHR_16bit_storage = "SPV_KHR_16bit_storage"; +static const char* const E_SPV_KHR_shader_ballot = "SPV_KHR_shader_ballot"; +static const char* const E_SPV_KHR_subgroup_vote = "SPV_KHR_subgroup_vote"; +static const char* const E_SPV_KHR_device_group = "SPV_KHR_device_group"; +static const char* const E_SPV_KHR_multiview = "SPV_KHR_multiview"; +static const char* const E_SPV_KHR_shader_draw_parameters = "SPV_KHR_shader_draw_parameters"; +static const char* const E_SPV_KHR_16bit_storage = "SPV_KHR_16bit_storage"; +static const char* const E_SPV_KHR_storage_buffer_storage_class = "SPV_KHR_storage_buffer_storage_class"; #endif // #ifndef GLSLextKHR_H diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index cb48d34..95ad7f9 100755 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -123,6 +123,7 @@ protected: spv::BuiltIn TranslateBuiltInDecoration(glslang::TBuiltInVariable, bool memberDeclaration); spv::ImageFormat TranslateImageFormat(const glslang::TType& type); spv::LoopControlMask TranslateLoopControl(glslang::TLoopControl) const; + spv::StorageClass TranslateStorageClass(const glslang::TType&); spv::Id createSpvVariable(const glslang::TIntermSymbol*); spv::Id getSampledType(const glslang::TSampler&); spv::Id getInvertedSwizzleType(const glslang::TIntermTyped&); @@ -245,39 +246,6 @@ spv::ExecutionModel TranslateExecutionModel(EShLanguage stage) } } -// Translate glslang type to SPIR-V storage class. -spv::StorageClass TranslateStorageClass(const glslang::TType& type, bool useStorageBuffer) -{ - if (type.getQualifier().isPipeInput()) - return spv::StorageClassInput; - else if (type.getQualifier().isPipeOutput()) - return spv::StorageClassOutput; - else if (type.getBasicType() == glslang::EbtAtomicUint) - return spv::StorageClassAtomicCounter; - else if (type.containsOpaque()) - return spv::StorageClassUniformConstant; - else if (useStorageBuffer && type.getQualifier().storage == glslang::EvqBuffer) - return spv::StorageClassStorageBuffer; - else if (type.getQualifier().isUniformOrBuffer()) { - if (type.getQualifier().layoutPushConstant) - return spv::StorageClassPushConstant; - if (type.getBasicType() == glslang::EbtBlock) - return spv::StorageClassUniform; - else - return spv::StorageClassUniformConstant; - } else { - switch (type.getQualifier().storage) { - case glslang::EvqShared: return spv::StorageClassWorkgroup; break; - case glslang::EvqGlobal: return spv::StorageClassPrivate; - case glslang::EvqConstReadOnly: return spv::StorageClassFunction; - case glslang::EvqTemporary: return spv::StorageClassFunction; - default: - assert(0); - return spv::StorageClassFunction; - } - } -} - // Translate glslang sampler type to SPIR-V dimensionality. spv::Dim TranslateDimensionality(const glslang::TSampler& sampler) { @@ -780,6 +748,40 @@ spv::LoopControlMask TGlslangToSpvTraverser::TranslateLoopControl(glslang::TLoop } } +// Translate glslang type to SPIR-V storage class. +spv::StorageClass TGlslangToSpvTraverser::TranslateStorageClass(const glslang::TType& type) +{ + if (type.getQualifier().isPipeInput()) + return spv::StorageClassInput; + else if (type.getQualifier().isPipeOutput()) + return spv::StorageClassOutput; + else if (type.getBasicType() == glslang::EbtAtomicUint) + return spv::StorageClassAtomicCounter; + else if (type.containsOpaque()) + return spv::StorageClassUniformConstant; + else if (glslangIntermediate->usingStorageBuffer() && type.getQualifier().storage == glslang::EvqBuffer) { + builder.addExtension(spv::E_SPV_KHR_storage_buffer_storage_class); + return spv::StorageClassStorageBuffer; + } else if (type.getQualifier().isUniformOrBuffer()) { + if (type.getQualifier().layoutPushConstant) + return spv::StorageClassPushConstant; + if (type.getBasicType() == glslang::EbtBlock) + return spv::StorageClassUniform; + else + return spv::StorageClassUniformConstant; + } else { + switch (type.getQualifier().storage) { + case glslang::EvqShared: return spv::StorageClassWorkgroup; break; + case glslang::EvqGlobal: return spv::StorageClassPrivate; + case glslang::EvqConstReadOnly: return spv::StorageClassFunction; + case glslang::EvqTemporary: return spv::StorageClassFunction; + default: + assert(0); + return spv::StorageClassFunction; + } + } +} + // Return whether or not the given type is something that should be tied to a // descriptor set. bool IsDescriptorResource(const glslang::TType& type) @@ -2092,7 +2094,7 @@ spv::Id TGlslangToSpvTraverser::createSpvVariable(const glslang::TIntermSymbol* } // Now, handle actual variables - spv::StorageClass storageClass = TranslateStorageClass(node->getType(), glslangIntermediate->usingStorageBuffer()); + spv::StorageClass storageClass = TranslateStorageClass(node->getType()); spv::Id spvType = convertGlslangToSpvType(node->getType()); #ifdef AMD_EXTENSIONS @@ -2855,7 +2857,7 @@ void TGlslangToSpvTraverser::makeFunctions(const glslang::TIntermSequence& glslF (paramType.getBasicType() == glslang::EbtBlock && paramType.getQualifier().storage == glslang::EvqBuffer) || // SSBO (p == 0 && implicitThis)) // implicit 'this' - typeId = builder.makePointer(TranslateStorageClass(paramType, glslangIntermediate->usingStorageBuffer()), typeId); + typeId = builder.makePointer(TranslateStorageClass(paramType), typeId); else if (paramType.getQualifier().storage != glslang::EvqConstReadOnly) typeId = builder.makePointer(spv::StorageClassFunction, typeId); else diff --git a/Test/baseResults/spv.storageBuffer.vert.out b/Test/baseResults/spv.storageBuffer.vert.out index 2bf4549..fa08ca8 100755 --- a/Test/baseResults/spv.storageBuffer.vert.out +++ b/Test/baseResults/spv.storageBuffer.vert.out @@ -6,6 +6,7 @@ Warning, version 450 is not yet complete; most version-specific features are pre // Id's are bound by 31 Capability Shader + Extension "SPV_KHR_storage_buffer_storage_class" 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 EntryPoint Vertex 4 "main" 13 -- 2.7.4