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