• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _VKTSHADEREXECUTOR_HPP
2 #define _VKTSHADEREXECUTOR_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2015 The Khronos Group Inc.
8  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  *//*!
23  * \file
24  * \brief Vulkan ShaderExecutor
25  *//*--------------------------------------------------------------------*/
26 
27 #include "tcuDefs.hpp"
28 #include "vktTestCase.hpp"
29 #include "gluVarType.hpp"
30 #include "vkShaderProgram.hpp"
31 
32 #include <vector>
33 #include <string>
34 
35 namespace vkt
36 {
37 namespace shaderexecutor
38 {
39 
40 //! Shader input / output variable declaration.
41 struct Symbol
42 {
43 	std::string				name;		//!< Symbol name.
44 	glu::VarType			varType;	//!< Symbol type.
45 
Symbolvkt::shaderexecutor::Symbol46 	Symbol (void) {}
Symbolvkt::shaderexecutor::Symbol47 	Symbol (const std::string& name_, const glu::VarType& varType_) : name(name_), varType(varType_) {}
48 };
49 
50 //! Complete shader specification.
51 struct ShaderSpec
52 {
53 	glu::GLSLVersion		glslVersion;
54 	std::vector<Symbol>		inputs;
55 	std::vector<Symbol>		outputs;
56 	std::string				globalDeclarations;	//!< These are placed into global scope. Can contain uniform declarations for example.
57 	std::string				source;				//!< Source snippet to be executed.
58 	vk::ShaderBuildOptions	buildOptions;
59 	bool					packFloat16Bit;
60 	bool					spirVShader;
61 
ShaderSpecvkt::shaderexecutor::ShaderSpec62 	ShaderSpec (void)
63 		: glslVersion		(glu::GLSL_VERSION_450)
64 		, packFloat16Bit	(false)
65 		, spirVShader		(false)
66 	{}
67 };
68 
69 enum
70 {
71 	//!< Descriptor set index for additional resources
72 	EXTRA_RESOURCES_DESCRIPTOR_SET_INDEX		= 1,
73 };
74 
75 //! Base class for shader executor.
76 class ShaderExecutor
77 {
78 public:
79 	virtual					~ShaderExecutor		(void);
80 
81 	//! Execute
82 	virtual void			execute				(int numValues, const void* const* inputs, void* const* outputs, vk::VkDescriptorSet extraResources = (vk::VkDescriptorSet)0) = 0;
83 	bool					areInputs16Bit		(void) const;
84 	bool					areOutputs16Bit		(void) const;
85 	bool					isOutput16Bit		(const size_t ndx) const;
isSpirVShader(void)86 	bool					isSpirVShader		(void) {return m_shaderSpec.spirVShader;}
87 
88 protected:
ShaderExecutor(Context & context,const ShaderSpec & shaderSpec)89 							ShaderExecutor		(Context& context, const ShaderSpec& shaderSpec)
90 								: m_context		(context)
91 								, m_shaderSpec	(shaderSpec)
92 							{}
93 
94 	Context&				m_context;
95 	const ShaderSpec		m_shaderSpec;
96 
97 private:
98 							ShaderExecutor		(const ShaderExecutor&);
99 	ShaderExecutor&			operator=			(const ShaderExecutor&);
100 };
101 
102 void				generateSources		(glu::ShaderType shaderType, const ShaderSpec& shaderSpec, vk::SourceCollections& dst);
103 ShaderExecutor*		createExecutor		(Context& context, glu::ShaderType shaderType, const ShaderSpec& shaderSpec, vk::VkDescriptorSetLayout extraResourcesLayout = (vk::VkDescriptorSetLayout)0);
104 
105 } // shaderexecutor
106 } // vkt
107 
108 #endif // _VKTSHADEREXECUTOR_HPP
109