1 /*-------------------------------------------------------------------------
5 * Copyright (c) 2015 Google Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and/or associated documentation files (the
9 * "Materials"), to deal in the Materials without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Materials, and to
12 * permit persons to whom the Materials are furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice(s) and this permission notice shall be
16 * included in all copies or substantial portions of the Materials.
18 * The Materials are Confidential Information as defined by the
19 * Khronos Membership Agreement until designated non-confidential by
20 * Khronos, at which point this condition clause shall be removed.
22 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
32 * \brief Null (dummy) Vulkan implementation.
33 *//*--------------------------------------------------------------------*/
35 #include "vkNullDriver.hpp"
36 #include "vkPlatform.hpp"
37 #include "tcuFunctionLibrary.hpp"
48 #define VK_NULL_RETURN(STMT) \
53 } catch (const std::bad_alloc&) { \
54 return VK_ERROR_OUT_OF_HOST_MEMORY; \
55 } catch (VkResult res) { \
58 } while (deGetFalse())
60 // \todo [2015-07-14 pyry] Check FUNC type by checkedCastToPtr<T>() or similar
61 #define VK_NULL_FUNC_ENTRY(NAME, FUNC) { #NAME, (deFunctionPtr)FUNC }
63 #define VK_NULL_DEFINE_DEVICE_OBJ(NAME) \
66 NAME (VkDevice, const Vk##NAME##CreateInfo*) {} \
72 Instance (const VkInstanceCreateInfo* instanceInfo);
75 PFN_vkVoidFunction getProcAddr (const char* name) const { return (PFN_vkVoidFunction)m_functions.getFunction(name); }
78 const tcu::StaticFunctionLibrary m_functions;
84 Device (VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* deviceInfo);
87 PFN_vkVoidFunction getProcAddr (const char* name) const { return (PFN_vkVoidFunction)m_functions.getFunction(name); }
90 const tcu::StaticFunctionLibrary m_functions;
96 DescriptorSet (VkDevice, VkDescriptorPool, VkDescriptorSetLayout) {}
102 Pipeline (VkDevice, const VkGraphicsPipelineCreateInfo*) {}
103 Pipeline (VkDevice, const VkComputePipelineCreateInfo*) {}
109 DeviceMemory (VkDevice, const VkMemoryAllocateInfo* pAllocInfo)
110 : m_memory(deMalloc((size_t)pAllocInfo->allocationSize))
113 throw std::bad_alloc();
120 void* getPtr (void) const { return m_memory; }
123 void* const m_memory;
129 Buffer (VkDevice, const VkBufferCreateInfo* pCreateInfo)
130 : m_size(pCreateInfo->size)
133 VkDeviceSize getSize (void) const { return m_size; }
136 const VkDeviceSize m_size;
142 CommandBuffer(VkDevice, VkCommandPool, VkCommandBufferLevel)
146 VK_NULL_DEFINE_DEVICE_OBJ(Fence);
147 VK_NULL_DEFINE_DEVICE_OBJ(Image);
148 VK_NULL_DEFINE_DEVICE_OBJ(Semaphore);
149 VK_NULL_DEFINE_DEVICE_OBJ(Event);
150 VK_NULL_DEFINE_DEVICE_OBJ(QueryPool);
151 VK_NULL_DEFINE_DEVICE_OBJ(BufferView);
152 VK_NULL_DEFINE_DEVICE_OBJ(ImageView);
153 VK_NULL_DEFINE_DEVICE_OBJ(ShaderModule);
154 VK_NULL_DEFINE_DEVICE_OBJ(PipelineCache);
155 VK_NULL_DEFINE_DEVICE_OBJ(PipelineLayout);
156 VK_NULL_DEFINE_DEVICE_OBJ(RenderPass);
157 VK_NULL_DEFINE_DEVICE_OBJ(DescriptorSetLayout);
158 VK_NULL_DEFINE_DEVICE_OBJ(Sampler);
159 VK_NULL_DEFINE_DEVICE_OBJ(Framebuffer);
160 VK_NULL_DEFINE_DEVICE_OBJ(CommandPool);
161 VK_NULL_DEFINE_DEVICE_OBJ(DescriptorPool);
166 PFN_vkVoidFunction getInstanceProcAddr (VkInstance instance, const char* pName)
168 return reinterpret_cast<Instance*>(instance)->getProcAddr(pName);
171 PFN_vkVoidFunction getDeviceProcAddr (VkDevice device, const char* pName)
173 return reinterpret_cast<Device*>(device)->getProcAddr(pName);
176 VkResult createGraphicsPipelines (VkDevice device, VkPipelineCache, deUint32 count, const VkGraphicsPipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks*, VkPipeline* pPipelines)
178 for (deUint32 ndx = 0; ndx < count; ndx++)
179 pPipelines[ndx] = VkPipeline((deUint64)(deUintptr)new Pipeline(device, pCreateInfos+ndx));
183 VkResult createComputePipelines (VkDevice device, VkPipelineCache, deUint32 count, const VkComputePipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks*, VkPipeline* pPipelines)
185 for (deUint32 ndx = 0; ndx < count; ndx++)
186 pPipelines[ndx] = VkPipeline((deUint64)(deUintptr)new Pipeline(device, pCreateInfos+ndx));
190 VkResult enumeratePhysicalDevices (VkInstance, deUint32* pPhysicalDeviceCount, VkPhysicalDevice* pDevices)
192 if (pDevices && *pPhysicalDeviceCount >= 1u)
193 *pDevices = reinterpret_cast<VkPhysicalDevice>((void*)(deUintptr)1u);
195 *pPhysicalDeviceCount = 1;
200 VkResult getPhysicalDeviceProperties (VkPhysicalDevice, VkPhysicalDeviceProperties* props)
202 deMemset(props, 0, sizeof(VkPhysicalDeviceProperties));
204 props->apiVersion = VK_API_VERSION;
205 props->driverVersion = 1u;
206 props->deviceType = VK_PHYSICAL_DEVICE_TYPE_OTHER;
208 deMemcpy(props->deviceName, "null", 5);
210 // \todo [2015-09-25 pyry] Fill in reasonable limits
215 VkResult getPhysicalDeviceQueueFamilyProperties (VkPhysicalDevice, deUint32* count, VkQueueFamilyProperties* props)
217 if (props && *count >= 1u)
219 deMemset(props, 0, sizeof(VkQueueFamilyProperties));
221 props->queueCount = 1u;
222 props->queueFlags = VK_QUEUE_GRAPHICS_BIT|VK_QUEUE_COMPUTE_BIT;
223 props->timestampValidBits = 64;
231 VkResult getPhysicalDeviceMemoryProperties (VkPhysicalDevice, VkPhysicalDeviceMemoryProperties* props)
233 deMemset(props, 0, sizeof(VkPhysicalDeviceMemoryProperties));
235 props->memoryTypeCount = 1u;
236 props->memoryTypes[0].heapIndex = 0u;
237 props->memoryTypes[0].propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
239 props->memoryHeapCount = 1u;
240 props->memoryHeaps[0].size = 1ull << 31;
241 props->memoryHeaps[0].flags = 0u;
246 VkResult getPhysicalDeviceFormatProperties (VkPhysicalDevice, VkFormat, VkFormatProperties* pFormatProperties)
248 const VkFormatFeatureFlags allFeatures = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
249 | VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
250 | VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT
251 | VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT
252 | VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT
253 | VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT
254 | VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT
255 | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
256 | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT
257 | VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
258 | VK_FORMAT_FEATURE_BLIT_SRC_BIT
259 | VK_FORMAT_FEATURE_BLIT_DST_BIT;
261 pFormatProperties->linearTilingFeatures = allFeatures;
262 pFormatProperties->optimalTilingFeatures = allFeatures;
263 pFormatProperties->bufferFeatures = allFeatures;
268 VkResult getBufferMemoryRequirements (VkDevice, VkBuffer bufferHandle, VkMemoryRequirements* requirements)
270 const Buffer* buffer = reinterpret_cast<Buffer*>(bufferHandle.getInternal());
272 requirements->memoryTypeBits = 1u;
273 requirements->size = buffer->getSize();
274 requirements->alignment = (VkDeviceSize)1u;
279 VkResult getImageMemoryRequirements (VkDevice, VkImage, VkMemoryRequirements* requirements)
281 requirements->memoryTypeBits = 1u;
282 requirements->size = 4u;
283 requirements->alignment = 4u;
288 VkResult mapMemory (VkDevice, VkDeviceMemory memHandle, VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags, void** ppData)
290 const DeviceMemory* memory = reinterpret_cast<DeviceMemory*>(memHandle.getInternal());
295 *ppData = (deUint8*)memory->getPtr() + offset;
300 VkResult allocateDescriptorSets (VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
302 for (deUint32 ndx = 0; ndx < pAllocateInfo->setLayoutCount; ++ndx)
306 pDescriptorSets[ndx] = VkDescriptorSet((deUint64)(deUintptr)new DescriptorSet(device, pAllocateInfo->descriptorPool, pAllocateInfo->pSetLayouts[ndx]));
308 catch (const std::bad_alloc&)
310 for (deUint32 freeNdx = 0; freeNdx < ndx; freeNdx++)
311 delete reinterpret_cast<DescriptorSet*>((deUintptr)pDescriptorSets[freeNdx].getInternal());
313 return VK_ERROR_OUT_OF_HOST_MEMORY;
317 for (deUint32 freeNdx = 0; freeNdx < ndx; freeNdx++)
318 delete reinterpret_cast<DescriptorSet*>((deUintptr)pDescriptorSets[freeNdx].getInternal());
327 void freeDescriptorSets (VkDevice, VkDescriptorPool, deUint32 count, const VkDescriptorSet* pDescriptorSets)
329 for (deUint32 ndx = 0; ndx < count; ++ndx)
331 // \note: delete cannot fail
332 delete reinterpret_cast<DescriptorSet*>((deUintptr)pDescriptorSets[ndx].getInternal());
336 VkResult allocateCommandBuffers (VkDevice device, const VkCommandBufferAllocateInfo* pAllocateInfo, VkCommandBuffer* pCommandBuffers)
338 if (pAllocateInfo && pCommandBuffers)
340 for (deUint32 ndx = 0; ndx < pAllocateInfo->bufferCount; ++ndx)
342 pCommandBuffers[ndx] = reinterpret_cast<VkCommandBuffer>(new CommandBuffer(device, pAllocateInfo->commandPool, pAllocateInfo->level));
349 void freeCommandBuffers (VkDevice device, VkCommandPool commandPool, deUint32 commandBufferCount, const VkCommandBuffer* pCommandBuffers)
352 DE_UNREF(commandPool);
354 for (deUint32 ndx = 0; ndx < commandBufferCount; ++ndx)
355 delete reinterpret_cast<CommandBuffer*>(pCommandBuffers[ndx]);
358 #include "vkNullDriverImpl.inl"
362 Instance::Instance (const VkInstanceCreateInfo*)
363 : m_functions(s_instanceFunctions, DE_LENGTH_OF_ARRAY(s_instanceFunctions))
367 Device::Device (VkPhysicalDevice, const VkDeviceCreateInfo*)
368 : m_functions(s_deviceFunctions, DE_LENGTH_OF_ARRAY(s_deviceFunctions))
372 class NullDriverLibrary : public Library
375 NullDriverLibrary (void)
376 : m_library (s_platformFunctions, DE_LENGTH_OF_ARRAY(s_platformFunctions))
377 , m_driver (m_library)
380 const PlatformInterface& getPlatformInterface (void) const { return m_driver; }
383 const tcu::StaticFunctionLibrary m_library;
384 const PlatformDriver m_driver;
389 Library* createNullDriver (void)
391 return new NullDriverLibrary();