1 #ifndef _VKSHADERPROGRAM_HPP 2 #define _VKSHADERPROGRAM_HPP 3 /*------------------------------------------------------------------------- 4 * Vulkan CTS Framework 5 * -------------------- 6 * 7 * Copyright (c) 2017 Google Inc. 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 *//*! 22 * \file 23 * \brief Shader (GLSL/HLSL) source program. 24 *//*--------------------------------------------------------------------*/ 25 26 #include "vkDefs.hpp" 27 #include "gluShaderProgram.hpp" 28 #include "vkValidatorOptions.hpp" 29 30 #include <string> 31 32 namespace tcu 33 { 34 class TestLog; 35 } // tcu 36 37 namespace vk 38 { 39 40 struct ShaderBuildOptions 41 { 42 enum Flags 43 { 44 FLAG_USE_STORAGE_BUFFER_STORAGE_CLASS = (1u<<0), 45 FLAG_ALLOW_RELAXED_OFFSETS = (1u<<1), // allow block offsets to follow VK_KHR_relaxed_block_layout 46 FLAG_ALLOW_SCALAR_OFFSETS = (1u<<2), // allow block offsets to follow VK_EXT_scalar_block_layout 47 FLAG_ALLOW_STD430_UBOS = (1u<<3) // allow block offsets to follow VK_EXT_uniform_buffer_standard_layout 48 }; 49 50 deUint32 vulkanVersion; 51 SpirvVersion targetVersion; 52 deUint32 flags; 53 bool supports_VK_KHR_spirv_1_4; 54 ShaderBuildOptionsvk::ShaderBuildOptions55 ShaderBuildOptions (deUint32 vulkanVersion_, SpirvVersion targetVersion_, deUint32 flags_, bool allowSpirv14 = false) 56 : vulkanVersion (vulkanVersion_) 57 , targetVersion (targetVersion_) 58 , flags (flags_) 59 , supports_VK_KHR_spirv_1_4(allowSpirv14) 60 {} 61 ShaderBuildOptionsvk::ShaderBuildOptions62 ShaderBuildOptions (void) 63 : vulkanVersion (VK_MAKE_VERSION(1, 0, 0)) 64 , targetVersion (SPIRV_VERSION_1_0) 65 , flags (0u) 66 , supports_VK_KHR_spirv_1_4 (false) 67 {} 68 getSpirvValidatorOptionsvk::ShaderBuildOptions69 SpirvValidatorOptions getSpirvValidatorOptions() const 70 { 71 SpirvValidatorOptions::BlockLayoutRules rules = SpirvValidatorOptions::kDefaultBlockLayout; 72 73 if (flags & FLAG_ALLOW_SCALAR_OFFSETS) 74 { 75 rules = SpirvValidatorOptions::kScalarBlockLayout; 76 } 77 else if (flags & FLAG_ALLOW_STD430_UBOS) 78 { 79 rules = SpirvValidatorOptions::kUniformStandardLayout; 80 } 81 else if (flags & FLAG_ALLOW_RELAXED_OFFSETS) 82 { 83 rules = SpirvValidatorOptions::kRelaxedBlockLayout; 84 } 85 86 return SpirvValidatorOptions(vulkanVersion, rules, supports_VK_KHR_spirv_1_4); 87 } 88 }; 89 90 enum ShaderLanguage 91 { 92 SHADER_LANGUAGE_GLSL = 0, 93 SHADER_LANGUAGE_HLSL, 94 95 SHADER_LANGUAGE_LAST 96 }; 97 98 struct GlslSource 99 { 100 static const ShaderLanguage shaderLanguage = SHADER_LANGUAGE_GLSL; 101 std::vector<std::string> sources[glu::SHADERTYPE_LAST]; 102 ShaderBuildOptions buildOptions; 103 104 GlslSource& operator<< (const glu::ShaderSource& shaderSource); 105 GlslSource& operator<< (const ShaderBuildOptions& buildOptions_); 106 }; 107 108 struct HlslSource 109 { 110 static const ShaderLanguage shaderLanguage = SHADER_LANGUAGE_HLSL; 111 std::vector<std::string> sources[glu::SHADERTYPE_LAST]; 112 ShaderBuildOptions buildOptions; 113 114 HlslSource& operator<< (const glu::ShaderSource& shaderSource); 115 HlslSource& operator<< (const ShaderBuildOptions& buildOptions_); 116 }; 117 118 tcu::TestLog& operator<< (tcu::TestLog& log, const GlslSource& shaderSource); 119 tcu::TestLog& operator<< (tcu::TestLog& log, const HlslSource& shaderSource); 120 121 } // vk 122 123 #endif // _VKSHADERPROGRAM_HPP 124