• 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 enum SpirVCaseT
51 {
52 	SPIRV_CASETYPE_NONE = 0,
53 	SPIRV_CASETYPE_COMPARE,
54 	SPIRV_CASETYPE_FREM,
55 	SPIRV_CASETYPE_MODFSTRUCT,
56 	SPIRV_CASETYPE_FREXPSTRUCT,
57 	SPIRV_CASETYPE_MAX_ENUM,
58 };
59 
60 //! Complete shader specification.
61 struct ShaderSpec
62 {
63 	glu::GLSLVersion		glslVersion;
64 	std::vector<Symbol>		inputs;
65 	std::vector<Symbol>		outputs;
66 	std::string				globalDeclarations;	//!< These are placed into global scope. Can contain uniform declarations for example.
67 	std::string				source;				//!< Source snippet to be executed.
68 	vk::ShaderBuildOptions	buildOptions;
69 	bool					packFloat16Bit;
70 	SpirVCaseT				spirvCase;
71 	int						localSizeX;			// May be used for compute shaders.
72 
ShaderSpecvkt::shaderexecutor::ShaderSpec73 	ShaderSpec (void)
74 		: glslVersion		(glu::GLSL_VERSION_450)
75 		, packFloat16Bit	(false)
76 		, spirvCase			(SPIRV_CASETYPE_NONE)
77 		, localSizeX		(1)
78 	{}
79 };
80 
81 enum
82 {
83 	//!< Descriptor set index for additional resources
84 	EXTRA_RESOURCES_DESCRIPTOR_SET_INDEX		= 1,
85 };
86 
87 //! Base class for shader executor.
88 class ShaderExecutor
89 {
90 public:
91 	virtual					~ShaderExecutor		(void);
92 
93 	//! Execute
94 	virtual void			execute				(int numValues, const void* const* inputs, void* const* outputs, vk::VkDescriptorSet extraResources = (vk::VkDescriptorSet)0) = 0;
95 	bool					areInputs16Bit		(void) const;
96 	bool					areOutputs16Bit		(void) const;
97 	bool					isOutput16Bit		(const size_t ndx) const;
98 	bool					areInputs64Bit		(void) const;
99 	bool					areOutputs64Bit		(void) const;
100 	bool					isOutput64Bit		(const size_t ndx) const;
isSpirVShader(void)101 	bool					isSpirVShader		(void) { return (m_shaderSpec.spirvCase != SPIRV_CASETYPE_NONE); }
spirvCase(void)102 	SpirVCaseT				spirvCase			(void) { return m_shaderSpec.spirvCase; }
103 
104 protected:
ShaderExecutor(Context & context,const ShaderSpec & shaderSpec)105 							ShaderExecutor		(Context& context, const ShaderSpec& shaderSpec)
106 								: m_context		(context)
107 								, m_shaderSpec	(shaderSpec)
108 							{}
109 
110 	Context&				m_context;
111 	const ShaderSpec		m_shaderSpec;
112 
113 private:
114 							ShaderExecutor		(const ShaderExecutor&);
115 	ShaderExecutor&			operator=			(const ShaderExecutor&);
116 };
117 
118 bool				executorSupported	(glu::ShaderType shaderType);
119 void				generateSources		(glu::ShaderType shaderType, const ShaderSpec& shaderSpec, vk::SourceCollections& dst);
120 ShaderExecutor*		createExecutor		(Context& context, glu::ShaderType shaderType, const ShaderSpec& shaderSpec, vk::VkDescriptorSetLayout extraResourcesLayout = (vk::VkDescriptorSetLayout)0);
121 void				checkSupportShader	(Context& context, const glu::ShaderType shaderType);
122 
123 } // shaderexecutor
124 } // vkt
125 
126 #endif // _VKTSHADEREXECUTOR_HPP
127