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,
149 const void* getBufferPtr (const deUint32 bindingLocation) const;
152 ShaderExecutor (const ShaderSpec& shaderSpec, glu::ShaderType shaderType);
154 void addUniforms (const VkDevice& vkDevice, const DeviceInterface& vk, const deUint32 queueFamilyIndex, Allocator& memAlloc);
156 void uploadUniforms (DescriptorSetUpdateBuilder& descriptorSetUpdateBuilder, VkDescriptorSet descriptorSet);
159 typedef de::SharedPtr<de::UniquePtr<UniformInfo> > UniformInfoSp;
161 class SamplerUniform;
162 typedef de::SharedPtr<de::UniquePtr<SamplerUniform> > SamplerUniformSp;
164 typedef de::SharedPtr<Unique<VkBuffer> > VkBufferSp;
165 typedef de::SharedPtr<Unique<VkImage> > VkImageSp;
166 typedef de::SharedPtr<Unique<VkImageView> > VkImageViewSp;
167 typedef de::SharedPtr<Unique<VkSampler> > VkSamplerSp;
168 typedef de::SharedPtr<Allocation> AllocationSp;
173 UniformInfo (void) {}
174 virtual ~UniformInfo (void) {}
175 virtual bool isSamplerArray (void) const { return false; }
176 virtual bool isBufferUniform (void) const { return false; }
177 virtual bool isSamplerUniform (void) const { return false; }
179 VkDescriptorType type;
183 class BufferUniform : public UniformInfo
186 BufferUniform (void) {}
187 virtual ~BufferUniform (void) {}
188 virtual bool isBufferUniform (void) const { return true; }
192 VkDescriptorBufferInfo descriptor;
195 class SamplerUniform : public UniformInfo
198 SamplerUniform (void) {}
199 virtual ~SamplerUniform (void) {}
200 virtual bool isSamplerUniform (void) const { return true; }
202 VkImageViewSp imageView;
205 VkDescriptorImageInfo descriptor;
208 class SamplerArrayUniform : public UniformInfo
211 SamplerArrayUniform (void) {}
212 virtual ~SamplerArrayUniform (void) {}
213 virtual bool isSamplerArray (void) const { return true; }
215 std::vector<SamplerUniformSp> uniforms;
218 Move<VkImage> createCombinedImage (const VkDevice& vkDevice,
219 const DeviceInterface& vk,
220 const deUint32 queueFamilyIndex,
221 const tcu::IVec3& texSize,
222 const VkFormat format,
223 const VkImageType imageType,
224 const VkImageViewType imageViewType,
225 const VkImageUsageFlags usage,
226 const VkImageTiling tiling);
228 de::MovePtr<Allocation> uploadImage (const VkDevice& vkDevice,
229 const DeviceInterface& vk,
231 const tcu::TextureFormat& texFormat,
232 const tcu::IVec3& texSize,
234 const VkImage& vkTexture,
235 const VkImageAspectFlags aspectMask);
237 de::MovePtr<SamplerUniform> createSamplerUniform (const VkDevice& vkDevice,
238 const DeviceInterface& vk,
239 const deUint32 queueFamilyIndex,
241 deUint32 bindingLocation,
242 const tcu::Sampler& refSampler,
243 const tcu::TextureFormat& texFormat,
244 const tcu::IVec3& texSize,
245 VkImageType imageType,
246 VkImageViewType imageViewType,
249 const ShaderSpec m_shaderSpec;
250 const glu::ShaderType m_shaderType;
252 std::vector<UniformInfoSp> m_uniformInfos;
253 de::MovePtr<const UniformSetup> m_uniformSetup;
254 DescriptorSetLayoutBuilder m_descriptorSetLayoutBuilder;
255 DescriptorPoolBuilder m_descriptorPoolBuilder;
259 inline tcu::TestLog& operator<< (tcu::TestLog& log, const ShaderExecutor* executor) { executor->log(log); return log; }
260 inline tcu::TestLog& operator<< (tcu::TestLog& log, const ShaderExecutor& executor) { executor.log(log); return log; }
262 ShaderExecutor* createExecutor(glu::ShaderType shaderType, const ShaderSpec& shaderSpec);
264 class UniformDataBase
267 UniformDataBase (deUint32 bindingLocation)
268 : m_bindingLocation (bindingLocation)
271 virtual ~UniformDataBase (void) {}
272 virtual void setup (ShaderExecutor&, const VkDevice&, const DeviceInterface&, const deUint32, Allocator&) const = 0;
275 const deUint32 m_bindingLocation;
279 class UniformData : public UniformDataBase
282 UniformData (deUint32 bindingLocation, VkDescriptorType descriptorType, const T data);
283 virtual ~UniformData (void);
284 virtual void setup (ShaderExecutor& executor, const VkDevice& vkDevice, const DeviceInterface& vk, const deUint32 queueFamilyIndex, Allocator& memAlloc) const;
287 VkDescriptorType m_descriptorType;
292 UniformData<T>::UniformData (deUint32 bindingLocation, VkDescriptorType descriptorType, const T data)
293 : UniformDataBase (bindingLocation)
294 , m_descriptorType (descriptorType)
300 UniformData<T>::~UniformData (void)
305 void UniformData<T>::setup (ShaderExecutor& executor, const VkDevice& vkDevice, const DeviceInterface& vk, const deUint32 queueFamilyIndex, Allocator& memAlloc) const
307 executor.setupUniformData(vkDevice, vk, queueFamilyIndex, memAlloc, m_bindingLocation, m_descriptorType, sizeof(T), &m_data);
310 class SamplerUniformData : public UniformDataBase
313 SamplerUniformData (deUint32 bindingLocation,
314 deUint32 numSamplers,
315 const tcu::Sampler& refSampler,
316 const tcu::TextureFormat& texFormat,
317 const tcu::IVec3& texSize,
318 VkImageType imageType,
319 VkImageViewType imageViewType,
321 virtual ~SamplerUniformData (void);
322 virtual void setup (ShaderExecutor& executor, const VkDevice& vkDevice, const DeviceInterface& vk, const deUint32 queueFamilyIndex, Allocator& memAlloc) const;
325 deUint32 m_numSamplers;
326 const tcu::Sampler m_refSampler;
327 const tcu::TextureFormat m_texFormat;
328 const tcu::IVec3 m_texSize;
329 VkImageType m_imageType;
330 VkImageViewType m_imageViewType;
337 #endif // _VKTSHADEREXECUTOR_HPP