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 * 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
14 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 * \brief Vulkan ShaderExecutor
25 *//*--------------------------------------------------------------------*/
27 #include "deSharedPtr.hpp"
29 #include "vktTestCase.hpp"
30 #include "vkMemUtil.hpp"
31 #include "vkBuilderUtil.hpp"
33 #include "gluVarType.hpp"
35 #include "tcuTexture.hpp"
41 namespace shaderexecutor
46 //! Shader input / output variable declaration.
49 std::string name; //!< Symbol name.
50 glu::VarType varType; //!< Symbol type.
53 Symbol (const std::string& name_, const glu::VarType& varType_) : name(name_), varType(varType_) {}
56 //! Complete shader specification.
59 std::vector<Symbol> inputs;
60 std::vector<Symbol> outputs;
61 std::string globalDeclarations; //!< These are placed into global scope. Can contain uniform declarations for example.
62 std::string source; //!< Source snippet to be executed.
69 class UniformDataBase;
72 typedef de::SharedPtr<de::UniquePtr<UniformDataBase> > UniformDataSp;
77 UniformSetup (void) {}
78 virtual ~UniformSetup (void) {}
80 void addData (UniformDataBase* uniformData)
82 m_uniforms.push_back(UniformDataSp(new de::UniquePtr<UniformDataBase>(uniformData)));
85 const std::vector<UniformDataSp>& uniforms (void) const
91 UniformSetup (const UniformSetup&); // not allowed!
92 UniformSetup& operator= (const UniformSetup&); // not allowed!
94 std::vector<UniformDataSp> m_uniforms;
97 //! Base class for shader executor.
101 virtual ~ShaderExecutor (void);
103 //! Log executor details (program etc.).
104 virtual void log (tcu::TestLog& log) const = 0;
107 virtual void execute (const Context& ctx, int numValues, const void* const* inputs, void* const* outputs) = 0;
109 virtual void setShaderSources (SourceCollections& programCollection) const = 0;
111 void setUniforms (const UniformSetup* uniformSetup)
113 m_uniformSetup = de::MovePtr<const UniformSetup>(uniformSetup);
116 void setupUniformData (const VkDevice& vkDevice,
117 const DeviceInterface& vk,
119 const deUint32 queueFamilyIndex,
121 deUint32 bindingLocation,
122 VkDescriptorType descriptorType,
124 const void* dataPtr);
126 void setupUniformArray (const VkDevice& vkDevice,
127 const DeviceInterface& vk,
129 const deUint32 queueFamilyIndex,
131 deUint32 bindingLocation,
132 VkDescriptorType descriptorType,
135 const void* dataPtr);
137 void setupSamplerData (const VkDevice& vkDevice,
138 const DeviceInterface& vk,
140 const deUint32 queueFamilyIndex,
142 deUint32 bindingLocation,
143 deUint32 numSamplers,
144 const tcu::Sampler& refSampler,
145 const tcu::TextureFormat& texFormat,
146 const tcu::IVec3& texSize,
147 VkImageType imageType,
148 VkImageViewType imageViewType,
151 void addSamplerUniform (deUint32 bindingLocation,
152 VkImageView imageView,
155 const void* getBufferPtr (const deUint32 bindingLocation) const;
158 ShaderExecutor (const ShaderSpec& shaderSpec, glu::ShaderType shaderType);
160 void addUniforms (const VkDevice& vkDevice, const DeviceInterface& vk, const VkQueue queue, const deUint32 queueFamilyIndex, Allocator& memAlloc);
162 void uploadUniforms (DescriptorSetUpdateBuilder& descriptorSetUpdateBuilder, VkDescriptorSet descriptorSet);
165 typedef de::SharedPtr<de::UniquePtr<UniformInfo> > UniformInfoSp;
167 typedef de::SharedPtr<de::UniquePtr<BufferUniform> > BufferUniformSp;
168 class SamplerUniform;
169 typedef de::SharedPtr<de::UniquePtr<SamplerUniform> > SamplerUniformSp;
171 typedef de::SharedPtr<Unique<VkBuffer> > VkBufferSp;
172 typedef de::SharedPtr<Unique<VkImage> > VkImageSp;
173 typedef de::SharedPtr<Unique<VkImageView> > VkImageViewSp;
174 typedef de::SharedPtr<Unique<VkSampler> > VkSamplerSp;
175 typedef de::SharedPtr<Allocation> AllocationSp;
182 UNIFORM_TYPE_BUFFER = 0,
183 UNIFORM_TYPE_SAMPLER,
184 UNIFORM_TYPE_UNMANAGED_SAMPLER,
185 UNIFORM_TYPE_BUFFER_ARRAY,
186 UNIFORM_TYPE_SAMPLER_ARRAY,
191 UniformInfo (void) {}
192 virtual ~UniformInfo (void) {}
193 virtual UniformType getType (void) const = 0;
195 VkDescriptorType type;
199 class BufferUniform : public UniformInfo
202 BufferUniform (void) {}
203 virtual ~BufferUniform (void) {}
204 virtual UniformType getType (void) const { return UNIFORM_TYPE_BUFFER; }
208 VkDescriptorBufferInfo descriptor;
211 class SamplerUniform : public UniformInfo
214 SamplerUniform (void) {}
215 virtual ~SamplerUniform (void) {}
216 virtual UniformType getType (void) const { return UNIFORM_TYPE_SAMPLER; }
219 VkImageViewSp imageView;
222 VkDescriptorImageInfo descriptor;
225 class UnmanagedSamplerUniform : public UniformInfo
228 UnmanagedSamplerUniform (void) {}
229 virtual ~UnmanagedSamplerUniform (void) {}
230 virtual UniformType getType (void) const { return UNIFORM_TYPE_UNMANAGED_SAMPLER; }
232 VkImageView imageView;
234 VkDescriptorImageInfo descriptor;
237 class BufferArrayUniform : public UniformInfo
240 BufferArrayUniform (void) {}
241 virtual ~BufferArrayUniform (void) {}
242 virtual UniformType getType (void) const { return UNIFORM_TYPE_BUFFER_ARRAY; }
244 std::vector<BufferUniformSp> uniforms;
247 class SamplerArrayUniform : public UniformInfo
250 SamplerArrayUniform (void) {}
251 virtual ~SamplerArrayUniform (void) {}
252 virtual UniformType getType (void) const { return UNIFORM_TYPE_SAMPLER_ARRAY; }
254 std::vector<SamplerUniformSp> uniforms;
257 void uploadImage (const VkDevice& vkDevice,
258 const DeviceInterface& vk,
260 const deUint32 queueFamilyIndex,
262 const tcu::TextureFormat& texFormat,
263 const tcu::IVec3& texSize,
265 const deUint32 arraySize,
266 const VkImageAspectFlags aspectMask,
269 de::MovePtr<SamplerUniform> createSamplerUniform (const VkDevice& vkDevice,
270 const DeviceInterface& vk,
272 const deUint32 queueFamilyIndex,
274 deUint32 bindingLocation,
275 const tcu::Sampler& refSampler,
276 const tcu::TextureFormat& texFormat,
277 const tcu::IVec3& texSize,
278 VkImageType imageType,
279 VkImageViewType imageViewType,
282 de::MovePtr<BufferUniform> createBufferUniform (const VkDevice& vkDevice,
283 const DeviceInterface& vk,
285 const deUint32 queueFamilyIndex,
287 deUint32 bindingLocation,
288 VkDescriptorType descriptorType,
290 const void* dataPtr);
292 const ShaderSpec m_shaderSpec;
293 const glu::ShaderType m_shaderType;
295 std::vector<UniformInfoSp> m_uniformInfos;
296 de::MovePtr<const UniformSetup> m_uniformSetup;
297 DescriptorSetLayoutBuilder m_descriptorSetLayoutBuilder;
298 DescriptorPoolBuilder m_descriptorPoolBuilder;
302 inline tcu::TestLog& operator<< (tcu::TestLog& log, const ShaderExecutor* executor) { executor->log(log); return log; }
303 inline tcu::TestLog& operator<< (tcu::TestLog& log, const ShaderExecutor& executor) { executor.log(log); return log; }
305 ShaderExecutor* createExecutor(glu::ShaderType shaderType, const ShaderSpec& shaderSpec);
307 class UniformDataBase
310 UniformDataBase (deUint32 bindingLocation)
311 : m_bindingLocation (bindingLocation)
314 virtual ~UniformDataBase (void) {}
315 virtual void setup (ShaderExecutor&, const VkDevice&, const DeviceInterface&, const VkQueue, const deUint32, Allocator&) const = 0;
318 const deUint32 m_bindingLocation;
322 class UniformData : public UniformDataBase
325 UniformData (deUint32 bindingLocation, VkDescriptorType descriptorType, const T data);
326 virtual ~UniformData (void);
327 virtual void setup (ShaderExecutor& executor, const VkDevice& vkDevice, const DeviceInterface& vk, const VkQueue queue, const deUint32 queueFamilyIndex, Allocator& memAlloc) const;
330 VkDescriptorType m_descriptorType;
335 UniformData<T>::UniformData (deUint32 bindingLocation, VkDescriptorType descriptorType, const T data)
336 : UniformDataBase (bindingLocation)
337 , m_descriptorType (descriptorType)
343 UniformData<T>::~UniformData (void)
348 void UniformData<T>::setup (ShaderExecutor& executor, const VkDevice& vkDevice, const DeviceInterface& vk, const VkQueue queue, const deUint32 queueFamilyIndex, Allocator& memAlloc) const
350 executor.setupUniformData(vkDevice, vk, queue, queueFamilyIndex, memAlloc, m_bindingLocation, m_descriptorType, sizeof(T), &m_data);
354 class UniformArrayData : public UniformDataBase
357 UniformArrayData (deUint32 bindingLocation, VkDescriptorType descriptorType, const std::vector<T>& data);
358 virtual ~UniformArrayData (void);
359 virtual void setup (ShaderExecutor& executor, const VkDevice& vkDevice, const DeviceInterface& vk, const VkQueue queue, const deUint32 queueFamilyIndex, Allocator& memAlloc) const;
362 VkDescriptorType m_descriptorType;
363 std::vector<T> m_data;
367 UniformArrayData<T>::UniformArrayData (deUint32 bindingLocation, VkDescriptorType descriptorType, const std::vector<T>& data)
368 : UniformDataBase (bindingLocation)
369 , m_descriptorType (descriptorType)
375 UniformArrayData<T>::~UniformArrayData (void)
380 void UniformArrayData<T>::setup (ShaderExecutor& executor, const VkDevice& vkDevice, const DeviceInterface& vk, const VkQueue queue, const deUint32 queueFamilyIndex, Allocator& memAlloc) const
382 DE_ASSERT(!m_data.empty());
383 executor.setupUniformArray(vkDevice, vk, queue, queueFamilyIndex, memAlloc, m_bindingLocation, m_descriptorType, (deUint32)m_data.size(), sizeof(T), &m_data[0]);
386 class SamplerUniformData : public UniformDataBase
389 SamplerUniformData (deUint32 bindingLocation,
390 deUint32 numSamplers,
391 const tcu::Sampler& refSampler,
392 const tcu::TextureFormat& texFormat,
393 const tcu::IVec3& texSize,
394 VkImageType imageType,
395 VkImageViewType imageViewType,
397 virtual ~SamplerUniformData (void);
398 virtual void setup (ShaderExecutor& executor, const VkDevice& vkDevice, const DeviceInterface& vk, const VkQueue queue, const deUint32 queueFamilyIndex, Allocator& memAlloc) const;
401 deUint32 m_numSamplers;
402 const tcu::Sampler m_refSampler;
403 const tcu::TextureFormat m_texFormat;
404 const tcu::IVec3 m_texSize;
405 VkImageType m_imageType;
406 VkImageViewType m_imageViewType;
413 #endif // _VKTSHADEREXECUTOR_HPP