Add GlslBuildOptions::FLAG_ALLOW_RELAXED_OFFSETS
authorArkadiusz Sarwa <arkadiusz.sarwa@mobica.com>
Tue, 9 May 2017 14:45:32 +0000 (16:45 +0200)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Tue, 25 Jul 2017 18:32:30 +0000 (14:32 -0400)
Enabling the flag allows GLSL to use layout(offset = N) qualifiers that
follow VK_KHR_relaxed_block_layout rules instead of GLSL std140/std430
rules.

Components: Vulkan

Change-Id: I4f168b04ad0916b740891b603ddde2de0f4bcf50
(cherry picked from commit 4b82e12d3a7bf0947887e0b9d586d0ab63bd4888)

external/vulkancts/framework/vulkan/vkGlslProgram.hpp
external/vulkancts/framework/vulkan/vkGlslToSpirV.cpp

index f09779d..a5e00a6 100644 (file)
@@ -40,7 +40,8 @@ struct GlslBuildOptions
 {
        enum Flags
        {
-               FLAG_USE_STORAGE_BUFFER_STORAGE_CLASS   = (1u<<0)
+               FLAG_USE_STORAGE_BUFFER_STORAGE_CLASS   = (1u<<0),
+               FLAG_ALLOW_RELAXED_OFFSETS                              = (1u<<1)       // allow block offsets to follow VK_KHR_relaxed_block_layout
        };
 
        SpirvVersion    targetVersion;
index 96a80ab..b340622 100644 (file)
@@ -226,11 +226,22 @@ std::string getShaderStageSource (const GlslSource& program, glu::ShaderType sha
                return program.sources[shaderType][0];
 }
 
+EShMessages getCompileFlags (const GlslBuildOptions& buildOpts)
+{
+       EShMessages             flags   = (EShMessages)(EShMsgSpvRules | EShMsgVulkanRules);
+
+       if ((buildOpts.flags & GlslBuildOptions::FLAG_ALLOW_RELAXED_OFFSETS) != 0)
+               flags = (EShMessages)(flags | EShMsgHlslOffsets);
+
+       return flags;
+}
+
 } // anonymous
 
 bool compileGlslToSpirV (const GlslSource& program, std::vector<deUint32>* dst, glu::ShaderProgramInfo* buildInfo)
 {
        TBuiltInResource        builtinRes;
+       const EShMessages       compileFlags    = getCompileFlags(program.buildOptions);
 
        if (program.buildOptions.targetVersion != SPIRV_VERSION_1_0)
                TCU_THROW(InternalError, "Unsupported SPIR-V target version");
@@ -258,7 +269,7 @@ bool compileGlslToSpirV (const GlslSource& program, std::vector<deUint32>* dst,
 
                        {
                                const deUint64  compileStartTime        = deGetMicroseconds();
-                               const int               compileRes                      = shader.parse(&builtinRes, 110, false, (EShMessages)(EShMsgSpvRules | EShMsgVulkanRules));
+                               const int               compileRes                      = shader.parse(&builtinRes, 110, false, compileFlags);
                                glu::ShaderInfo shaderBuildInfo;
 
                                shaderBuildInfo.type                    = (glu::ShaderType)shaderType;
@@ -274,7 +285,7 @@ bool compileGlslToSpirV (const GlslSource& program, std::vector<deUint32>* dst,
                        if (buildInfo->shaders[0].compileOk)
                        {
                                const deUint64  linkStartTime   = deGetMicroseconds();
-                               const int               linkRes                 = program.link((EShMessages)(EShMsgSpvRules | EShMsgVulkanRules));
+                               const int               linkRes                 = program.link(compileFlags);
 
                                buildInfo->program.infoLog              = program.getInfoLog(); // \todo [2015-11-05 scygan] Include debug log?
                                buildInfo->program.linkOk               = (linkRes != 0);