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 } // namespace 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 FLAG_ALLOW_WORKGROUP_SCALAR_OFFSETS = 49 (1u 50 << 4), // allow scalar block offsets for Workgroup memory, part of VK_KHR_workgroup_memory_explicit_layout 51 }; 52 53 uint32_t vulkanVersion; 54 SpirvVersion targetVersion; 55 uint32_t flags; 56 bool supports_VK_KHR_spirv_1_4; 57 ShaderBuildOptionsvk::ShaderBuildOptions58 ShaderBuildOptions(uint32_t vulkanVersion_, SpirvVersion targetVersion_, uint32_t flags_, bool allowSpirv14 = false) 59 : vulkanVersion(vulkanVersion_) 60 , targetVersion(targetVersion_) 61 , flags(flags_) 62 , supports_VK_KHR_spirv_1_4(allowSpirv14) 63 { 64 } 65 ShaderBuildOptionsvk::ShaderBuildOptions66 ShaderBuildOptions(void) 67 : vulkanVersion(VK_MAKE_API_VERSION(0, 1, 0, 0)) 68 , targetVersion(SPIRV_VERSION_1_0) 69 , flags(0u) 70 , supports_VK_KHR_spirv_1_4(false) 71 { 72 } 73 getSpirvValidatorOptionsvk::ShaderBuildOptions74 SpirvValidatorOptions getSpirvValidatorOptions() const 75 { 76 SpirvValidatorOptions::BlockLayoutRules rules = SpirvValidatorOptions::kDefaultBlockLayout; 77 uint32_t validator_flags = 0u; 78 79 if (flags & FLAG_ALLOW_SCALAR_OFFSETS) 80 { 81 rules = SpirvValidatorOptions::kScalarBlockLayout; 82 } 83 else if (flags & FLAG_ALLOW_STD430_UBOS) 84 { 85 rules = SpirvValidatorOptions::kUniformStandardLayout; 86 } 87 else if (flags & FLAG_ALLOW_RELAXED_OFFSETS) 88 { 89 rules = SpirvValidatorOptions::kRelaxedBlockLayout; 90 } 91 92 if (flags & FLAG_ALLOW_WORKGROUP_SCALAR_OFFSETS) 93 { 94 validator_flags |= SpirvValidatorOptions::FLAG_SPIRV_VALIDATOR_WORKGROUP_SCALAR_BLOCK_LAYOUT; 95 } 96 97 return SpirvValidatorOptions(vulkanVersion, rules, supports_VK_KHR_spirv_1_4, validator_flags); 98 } 99 }; 100 101 enum ShaderLanguage 102 { 103 SHADER_LANGUAGE_GLSL = 0, 104 SHADER_LANGUAGE_HLSL, 105 106 SHADER_LANGUAGE_LAST 107 }; 108 109 struct GlslSource 110 { 111 static const ShaderLanguage shaderLanguage = SHADER_LANGUAGE_GLSL; 112 std::vector<std::string> sources[glu::SHADERTYPE_LAST]; 113 ShaderBuildOptions buildOptions; 114 115 GlslSource &operator<<(const glu::ShaderSource &shaderSource); 116 GlslSource &operator<<(const ShaderBuildOptions &buildOptions_); 117 }; 118 119 struct HlslSource 120 { 121 static const ShaderLanguage shaderLanguage = SHADER_LANGUAGE_HLSL; 122 std::vector<std::string> sources[glu::SHADERTYPE_LAST]; 123 ShaderBuildOptions buildOptions; 124 125 HlslSource &operator<<(const glu::ShaderSource &shaderSource); 126 HlslSource &operator<<(const ShaderBuildOptions &buildOptions_); 127 }; 128 129 tcu::TestLog &operator<<(tcu::TestLog &log, const GlslSource &shaderSource); 130 tcu::TestLog &operator<<(tcu::TestLog &log, const HlslSource &shaderSource); 131 132 } // namespace vk 133 134 #endif // _VKSHADERPROGRAM_HPP 135