Home | History | Annotate | Download | only in vulkan
      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 	};
     48 
     49 	deUint32		vulkanVersion;
     50 	SpirvVersion	targetVersion;
     51 	deUint32		flags;
     52 
     53 	ShaderBuildOptions (deUint32 vulkanVersion_, SpirvVersion targetVersion_, deUint32 flags_)
     54 		: vulkanVersion	(vulkanVersion_)
     55 		, targetVersion	(targetVersion_)
     56 		, flags			(flags_)
     57 	{}
     58 
     59 	ShaderBuildOptions (void)
     60 		: vulkanVersion	(VK_MAKE_VERSION(1, 0, 0))
     61 		, targetVersion	(SPIRV_VERSION_1_0)
     62 		, flags			(0u)
     63 	{}
     64 
     65 	SpirvValidatorOptions getSpirvValidatorOptions() const
     66 	{
     67 		SpirvValidatorOptions::BlockLayoutRules rules = SpirvValidatorOptions::kDefaultBlockLayout;
     68 
     69 		if (flags & FLAG_ALLOW_SCALAR_OFFSETS)
     70 		{
     71 			rules = SpirvValidatorOptions::kScalarBlockLayout;
     72 		}
     73 		else if (flags & FLAG_ALLOW_RELAXED_OFFSETS)
     74 		{
     75 			rules = SpirvValidatorOptions::kRelaxedBlockLayout;
     76 		}
     77 
     78 		return SpirvValidatorOptions(vulkanVersion, rules);
     79 	}
     80 };
     81 
     82 enum ShaderLanguage
     83 {
     84 	SHADER_LANGUAGE_GLSL = 0,
     85 	SHADER_LANGUAGE_HLSL,
     86 
     87 	SHADER_LANGUAGE_LAST
     88 };
     89 
     90 struct GlslSource
     91 {
     92 	static const ShaderLanguage	shaderLanguage = SHADER_LANGUAGE_GLSL;
     93 	std::vector<std::string>	sources[glu::SHADERTYPE_LAST];
     94 	ShaderBuildOptions			buildOptions;
     95 
     96 	GlslSource&					operator<<		(const glu::ShaderSource& shaderSource);
     97 	GlslSource&					operator<<		(const ShaderBuildOptions& buildOptions_);
     98 };
     99 
    100 struct HlslSource
    101 {
    102 	static const ShaderLanguage	shaderLanguage = SHADER_LANGUAGE_HLSL;
    103 	std::vector<std::string>	sources[glu::SHADERTYPE_LAST];
    104 	ShaderBuildOptions			buildOptions;
    105 
    106 	HlslSource&					operator<<		(const glu::ShaderSource& shaderSource);
    107 	HlslSource&					operator<<		(const ShaderBuildOptions& buildOptions_);
    108 };
    109 
    110 tcu::TestLog&	operator<<		(tcu::TestLog& log, const GlslSource& shaderSource);
    111 tcu::TestLog&	operator<<		(tcu::TestLog& log, const HlslSource& shaderSource);
    112 
    113 } // vk
    114 
    115 #endif // _VKSHADERPROGRAM_HPP
    116