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