1 #ifndef _VKTSHADEREXECUTOR_HPP
2 #define _VKTSHADEREXECUTOR_HPP
3 /*------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
7 * Copyright (c) 2015 The Khronos Group Inc.
8 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and/or associated documentation files (the
12 * "Materials"), to deal in the Materials without restriction, including
13 * without limitation the rights to use, copy, modify, merge, publish,
14 * distribute, sublicense, and/or sell copies of the Materials, and to
15 * permit persons to whom the Materials are furnished to do so, subject to
16 * the following conditions:
18 * The above copyright notice(s) and this permission notice shall be included
19 * in all copies or substantial portions of the Materials.
21 * The Materials are Confidential Information as defined by the
22 * Khronos Membership Agreement until designated non-confidential by Khronos,
23 * at which point this condition clause shall be removed.
25 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
28 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
29 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
30 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
31 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
35 * \brief Vulkan ShaderExecutor
36 *//*--------------------------------------------------------------------*/
38 #include "deSharedPtr.hpp"
40 #include "vktTestCase.hpp"
41 #include "vkMemUtil.hpp"
42 #include "vkBuilderUtil.hpp"
44 #include "gluVarType.hpp"
46 #include "tcuTexture.hpp"
52 namespace shaderexecutor
57 //! Shader input / output variable declaration.
60 std::string name; //!< Symbol name.
61 glu::VarType varType; //!< Symbol type.
64 Symbol (const std::string& name_, const glu::VarType& varType_) : name(name_), varType(varType_) {}
67 //! Complete shader specification.
70 std::vector<Symbol> inputs;
71 std::vector<Symbol> outputs;
72 std::string globalDeclarations; //!< These are placed into global scope. Can contain uniform declarations for example.
73 std::string source; //!< Source snippet to be executed.
80 class UniformDataBase;
83 typedef de::SharedPtr<de::UniquePtr<UniformDataBase> > UniformDataSp;
88 UniformSetup (void) {}
89 virtual ~UniformSetup (void) {}
91 void addData (UniformDataBase* uniformData)
93 m_uniforms.push_back(UniformDataSp(new de::UniquePtr<UniformDataBase>(uniformData)));
96 const std::vector<UniformDataSp>& uniforms (void) const
102 UniformSetup (const UniformSetup&); // not allowed!
103 UniformSetup& operator= (const UniformSetup&); // not allowed!
105 std::vector<UniformDataSp> m_uniforms;
108 //! Base class for shader executor.
112 virtual ~ShaderExecutor (void);
114 //! Log executor details (program etc.).
115 virtual void log (tcu::TestLog& log) const = 0;
118 virtual void execute (const Context& ctx, int numValues, const void* const* inputs, void* const* outputs) = 0;
120 virtual void setShaderSources (SourceCollections& programCollection) const = 0;
122 void setUniforms (const UniformSetup* uniformSetup)
124 m_uniformSetup = de::MovePtr<const UniformSetup>(uniformSetup);
127 void setupUniformData (const VkDevice& vkDevice,
128 const DeviceInterface& vk,
129 const deUint32 queueFamilyIndex,
131 deUint32 bindingLocation,
132 VkDescriptorType descriptorType,
134 const void* dataPtr);
136 void setupSamplerData (const VkDevice& vkDevice,
137 const DeviceInterface& vk,
138 const deUint32 queueFamilyIndex,
140 deUint32 bindingLocation,
141 deUint32 numSamplers,
142 const tcu::Sampler& refSampler,
143 const tcu::TextureFormat& texFormat,
144 const tcu::IVec3& texSize,
145 VkImageType imageType,
146 VkImageViewType imageViewType,
150 ShaderExecutor (const ShaderSpec& shaderSpec, glu::ShaderType shaderType);
152 void addUniforms (const VkDevice& vkDevice, const DeviceInterface& vk, const deUint32 queueFamilyIndex, Allocator& memAlloc);
154 void uploadUniforms (DescriptorSetUpdateBuilder& descriptorSetUpdateBuilder, VkDescriptorSet descriptorSet);
157 typedef de::SharedPtr<de::UniquePtr<UniformInfo> > UniformInfoSp;
159 class SamplerUniform;
160 typedef de::SharedPtr<de::UniquePtr<SamplerUniform> > SamplerUniformSp;
162 typedef de::SharedPtr<Unique<VkBuffer> > VkBufferSp;
163 typedef de::SharedPtr<Unique<VkImage> > VkImageSp;
164 typedef de::SharedPtr<Unique<VkImageView> > VkImageViewSp;
165 typedef de::SharedPtr<Unique<VkSampler> > VkSamplerSp;
166 typedef de::SharedPtr<Allocation> AllocationSp;
171 UniformInfo (void) {}
172 virtual ~UniformInfo (void) {}
173 virtual bool isSamplerArray (void) const { return false; }
174 virtual bool isBufferUniform (void) const { return false; }
175 virtual bool isSamplerUniform (void) const { return false; }
177 VkDescriptorType type;
181 class BufferUniform : public UniformInfo
184 BufferUniform (void) {}
185 virtual ~BufferUniform (void) {}
186 virtual bool isBufferUniform (void) const { return true; }
190 VkDescriptorBufferInfo descriptor;
193 class SamplerUniform : public UniformInfo
196 SamplerUniform (void) {}
197 virtual ~SamplerUniform (void) {}
198 virtual bool isSamplerUniform (void) const { return true; }
200 VkImageViewSp imageView;
203 VkDescriptorImageInfo descriptor;
206 class SamplerArrayUniform : public UniformInfo
209 SamplerArrayUniform (void) {}
210 virtual ~SamplerArrayUniform (void) {}
211 virtual bool isSamplerArray (void) const { return true; }
213 std::vector<SamplerUniformSp> uniforms;
216 Move<VkImage> createCombinedImage (const VkDevice& vkDevice,
217 const DeviceInterface& vk,
218 const deUint32 queueFamilyIndex,
219 const tcu::IVec3& texSize,
220 const VkFormat format,
221 const VkImageType imageType,
222 const VkImageViewType imageViewType,
223 const VkImageUsageFlags usage,
224 const VkImageTiling tiling);
226 de::MovePtr<Allocation> uploadImage (const VkDevice& vkDevice,
227 const DeviceInterface& vk,
229 const tcu::TextureFormat& texFormat,
230 const tcu::IVec3& texSize,
232 const VkImage& vkTexture,
233 const VkImageAspectFlags aspectMask);
235 de::MovePtr<SamplerUniform> createSamplerUniform (const VkDevice& vkDevice,
236 const DeviceInterface& vk,
237 const deUint32 queueFamilyIndex,
239 deUint32 bindingLocation,
240 const tcu::Sampler& refSampler,
241 const tcu::TextureFormat& texFormat,
242 const tcu::IVec3& texSize,
243 VkImageType imageType,
244 VkImageViewType imageViewType,
247 const ShaderSpec m_shaderSpec;
248 const glu::ShaderType m_shaderType;
250 std::vector<UniformInfoSp> m_uniformInfos;
251 de::MovePtr<const UniformSetup> m_uniformSetup;
252 DescriptorSetLayoutBuilder m_descriptorSetLayoutBuilder;
253 DescriptorPoolBuilder m_descriptorPoolBuilder;
257 inline tcu::TestLog& operator<< (tcu::TestLog& log, const ShaderExecutor* executor) { executor->log(log); return log; }
258 inline tcu::TestLog& operator<< (tcu::TestLog& log, const ShaderExecutor& executor) { executor.log(log); return log; }
260 ShaderExecutor* createExecutor(glu::ShaderType shaderType, const ShaderSpec& shaderSpec);
262 class UniformDataBase
265 UniformDataBase (deUint32 bindingLocation)
266 : m_bindingLocation (bindingLocation)
269 virtual ~UniformDataBase (void) {}
270 virtual void setup (ShaderExecutor&, const VkDevice&, const DeviceInterface&, const deUint32, Allocator&) const = 0;
273 const deUint32 m_bindingLocation;
277 class UniformData : public UniformDataBase
280 UniformData (deUint32 bindingLocation, VkDescriptorType descriptorType, const T data);
281 virtual ~UniformData (void);
282 virtual void setup (ShaderExecutor& executor, const VkDevice& vkDevice, const DeviceInterface& vk, const deUint32 queueFamilyIndex, Allocator& memAlloc) const;
285 VkDescriptorType m_descriptorType;
290 UniformData<T>::UniformData (deUint32 bindingLocation, VkDescriptorType descriptorType, const T data)
291 : UniformDataBase (bindingLocation)
292 , m_descriptorType (descriptorType)
298 UniformData<T>::~UniformData (void)
303 void UniformData<T>::setup (ShaderExecutor& executor, const VkDevice& vkDevice, const DeviceInterface& vk, const deUint32 queueFamilyIndex, Allocator& memAlloc) const
305 executor.setupUniformData(vkDevice, vk, queueFamilyIndex, memAlloc, m_bindingLocation, m_descriptorType, sizeof(T), &m_data);
308 class SamplerUniformData : public UniformDataBase
311 SamplerUniformData (deUint32 bindingLocation,
312 deUint32 numSamplers,
313 const tcu::Sampler& refSampler,
314 const tcu::TextureFormat& texFormat,
315 const tcu::IVec3& texSize,
316 VkImageType imageType,
317 VkImageViewType imageViewType,
319 virtual ~SamplerUniformData (void);
320 virtual void setup (ShaderExecutor& executor, const VkDevice& vkDevice, const DeviceInterface& vk, const deUint32 queueFamilyIndex, Allocator& memAlloc) const;
323 deUint32 m_numSamplers;
324 const tcu::Sampler m_refSampler;
325 const tcu::TextureFormat m_texFormat;
326 const tcu::IVec3 m_texSize;
327 VkImageType m_imageType;
328 VkImageViewType m_imageViewType;
335 #endif // _VKTSHADEREXECUTOR_HPP