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