From 291cdb415be16d2ee421d5cf8c0ae0c1b5b53c24 Mon Sep 17 00:00:00 2001 From: Mark Lobodzinski Date: Wed, 7 Sep 2016 16:34:56 -0600 Subject: [PATCH] tests: Clang-format vktestbinding files Change-Id: Idbec767a4a587639b59ff42201c1c024c1b4fa7e --- tests/vktestbinding.cpp | 286 ++++++++++++----------------------- tests/vktestbinding.h | 390 +++++++++++++++--------------------------------- 2 files changed, 219 insertions(+), 457 deletions(-) diff --git a/tests/vktestbinding.cpp b/tests/vktestbinding.cpp index c1dfe49..fe5a59b 100644 --- a/tests/vktestbinding.cpp +++ b/tests/vktestbinding.cpp @@ -19,62 +19,53 @@ * Author: Tony Barbour */ -#include -#include // memset(), memcmp() +#include "vktestbinding.h" #include +#include #include -#include "vktestbinding.h" +#include // memset(), memcmp() namespace { -#define NON_DISPATCHABLE_HANDLE_INIT(create_func, dev, ...) \ - do { \ - handle_type handle; \ - if (EXPECT(create_func(dev.handle(), __VA_ARGS__, NULL, &handle) == \ - VK_SUCCESS)) \ - NonDispHandle::init(dev.handle(), handle); \ +#define NON_DISPATCHABLE_HANDLE_INIT(create_func, dev, ...) \ + do { \ + handle_type handle; \ + if (EXPECT(create_func(dev.handle(), __VA_ARGS__, NULL, &handle) == VK_SUCCESS)) \ + NonDispHandle::init(dev.handle(), handle); \ } while (0) -#define NON_DISPATCHABLE_HANDLE_DTOR(cls, destroy_func) \ - cls::~cls() { \ - if (initialized()) \ - destroy_func(device(), handle(), NULL); \ +#define NON_DISPATCHABLE_HANDLE_DTOR(cls, destroy_func) \ + cls::~cls() { \ + if (initialized()) \ + destroy_func(device(), handle(), NULL); \ } #define STRINGIFY(x) #x -#define EXPECT(expr) \ - ((expr) ? true : expect_failure(STRINGIFY(expr), __FILE__, __LINE__, \ - __FUNCTION__)) +#define EXPECT(expr) ((expr) ? true : expect_failure(STRINGIFY(expr), __FILE__, __LINE__, __FUNCTION__)) vk_testing::ErrorCallback error_callback; -bool expect_failure(const char *expr, const char *file, unsigned int line, - const char *function) { +bool expect_failure(const char *expr, const char *file, unsigned int line, const char *function) { if (error_callback) { error_callback(expr, file, line, function); } else { - std::cerr << file << ":" << line << ": " << function - << ": Expectation `" << expr << "' failed.\n"; + std::cerr << file << ":" << line << ": " << function << ": Expectation `" << expr << "' failed.\n"; } return false; } -template -std::vector make_handles(const std::vector &v) { +template std::vector make_handles(const std::vector &v) { std::vector handles; handles.reserve(v.size()); - for (typename std::vector::const_iterator it = v.begin(); it != v.end(); - it++) + for (typename std::vector::const_iterator it = v.begin(); it != v.end(); it++) handles.push_back((*it)->handle()); return handles; } -VkMemoryAllocateInfo get_resource_alloc_info(const vk_testing::Device &dev, - const VkMemoryRequirements &reqs, +VkMemoryAllocateInfo get_resource_alloc_info(const vk_testing::Device &dev, const VkMemoryRequirements &reqs, VkMemoryPropertyFlags mem_props) { - VkMemoryAllocateInfo info = - vk_testing::DeviceMemory::alloc_info(reqs.size, 0); + VkMemoryAllocateInfo info = vk_testing::DeviceMemory::alloc_info(reqs.size, 0); dev.phy().set_memory_type(reqs.memoryTypeBits, &info, mem_props); return info; @@ -134,8 +125,7 @@ std::vector GetGlobalLayers() { if (err == VK_SUCCESS) { layers.reserve(layer_count); - err = - vkEnumerateInstanceLayerProperties(&layer_count, layers.data()); + err = vkEnumerateInstanceLayerProperties(&layer_count, layers.data()); } } while (err == VK_INCOMPLETE); @@ -147,9 +137,7 @@ std::vector GetGlobalLayers() { /* * Return list of Global extensions provided by the ICD / Loader */ -std::vector GetGlobalExtensions() { - return GetGlobalExtensions(NULL); -} +std::vector GetGlobalExtensions() { return GetGlobalExtensions(NULL); } /* * Return list of Global extensions provided by the specified layer @@ -163,13 +151,11 @@ std::vector GetGlobalExtensions(const char *pLayerName) { do { ext_count = 0; - err = vkEnumerateInstanceExtensionProperties(pLayerName, &ext_count, - NULL); + err = vkEnumerateInstanceExtensionProperties(pLayerName, &ext_count, NULL); if (err == VK_SUCCESS) { exts.resize(ext_count); - err = vkEnumerateInstanceExtensionProperties(pLayerName, &ext_count, - exts.data()); + err = vkEnumerateInstanceExtensionProperties(pLayerName, &ext_count, exts.data()); } } while (err == VK_INCOMPLETE); @@ -181,28 +167,23 @@ std::vector GetGlobalExtensions(const char *pLayerName) { /* * Return list of PhysicalDevice extensions provided by the ICD / Loader */ -std::vector PhysicalDevice::extensions() const { - return extensions(NULL); -} +std::vector PhysicalDevice::extensions() const { return extensions(NULL); } /* * Return list of PhysicalDevice extensions provided by the specified layer * If pLayerName is NULL, will return extensions for ICD / loader. */ -std::vector -PhysicalDevice::extensions(const char *pLayerName) const { +std::vector PhysicalDevice::extensions(const char *pLayerName) const { std::vector exts; VkResult err; do { uint32_t extCount = 0; - err = vkEnumerateDeviceExtensionProperties(handle(), pLayerName, - &extCount, NULL); + err = vkEnumerateDeviceExtensionProperties(handle(), pLayerName, &extCount, NULL); if (err == VK_SUCCESS) { exts.resize(extCount); - err = vkEnumerateDeviceExtensionProperties(handle(), pLayerName, - &extCount, exts.data()); + err = vkEnumerateDeviceExtensionProperties(handle(), pLayerName, &extCount, exts.data()); } } while (err == VK_INCOMPLETE); @@ -211,19 +192,15 @@ PhysicalDevice::extensions(const char *pLayerName) const { return exts; } -bool PhysicalDevice::set_memory_type(const uint32_t type_bits, - VkMemoryAllocateInfo *info, - const VkFlags properties, +bool PhysicalDevice::set_memory_type(const uint32_t type_bits, VkMemoryAllocateInfo *info, const VkFlags properties, const VkFlags forbid) const { uint32_t type_mask = type_bits; // Search memtypes to find first index with those properties for (uint32_t i = 0; i < memory_properties_.memoryTypeCount; i++) { if ((type_mask & 1) == 1) { // Type is available, does it match user properties? - if ((memory_properties_.memoryTypes[i].propertyFlags & - properties) == properties && - (memory_properties_.memoryTypes[i].propertyFlags & forbid) == - 0) { + if ((memory_properties_.memoryTypes[i].propertyFlags & properties) == properties && + (memory_properties_.memoryTypes[i].propertyFlags & forbid) == 0) { info->memoryTypeIndex = i; return true; } @@ -247,8 +224,7 @@ std::vector PhysicalDevice::layers() const { if (err == VK_SUCCESS) { layer_props.reserve(layer_count); - err = vkEnumerateDeviceLayerProperties(handle(), &layer_count, - layer_props.data()); + err = vkEnumerateDeviceLayerProperties(handle(), &layer_count, layer_props.data()); } } while (err == VK_INCOMPLETE); @@ -262,8 +238,7 @@ Device::~Device() { return; for (int i = 0; i < QUEUE_COUNT; i++) { - for (std::vector::iterator it = queues_[i].begin(); - it != queues_[i].end(); it++) + for (std::vector::iterator it = queues_[i].begin(); it != queues_[i].end(); it++) delete *it; queues_[i].clear(); } @@ -273,8 +248,7 @@ Device::~Device() { void Device::init(std::vector &extensions, VkPhysicalDeviceFeatures *features) { // request all queues - const std::vector queue_props = - phy_.queue_properties(); + const std::vector queue_props = phy_.queue_properties(); std::vector queue_info; queue_info.reserve(queue_props.size()); @@ -332,15 +306,12 @@ void Device::init_queues() { uint32_t queue_node_count; // Call with NULL data to get count - vkGetPhysicalDeviceQueueFamilyProperties(phy_.handle(), &queue_node_count, - NULL); + vkGetPhysicalDeviceQueueFamilyProperties(phy_.handle(), &queue_node_count, NULL); EXPECT(queue_node_count >= 1); - VkQueueFamilyProperties *queue_props = - new VkQueueFamilyProperties[queue_node_count]; + VkQueueFamilyProperties *queue_props = new VkQueueFamilyProperties[queue_node_count]; - vkGetPhysicalDeviceQueueFamilyProperties(phy_.handle(), &queue_node_count, - queue_props); + vkGetPhysicalDeviceQueueFamilyProperties(phy_.handle(), &queue_node_count, queue_props); for (uint32_t i = 0; i < queue_node_count; i++) { VkQueue queue; @@ -375,14 +346,12 @@ void Device::init_formats() { const VkFormatProperties props = format_properties(fmt); if (props.linearTilingFeatures) { - const Format tmp = {fmt, VK_IMAGE_TILING_LINEAR, - props.linearTilingFeatures}; + const Format tmp = {fmt, VK_IMAGE_TILING_LINEAR, props.linearTilingFeatures}; formats_.push_back(tmp); } if (props.optimalTilingFeatures) { - const Format tmp = {fmt, VK_IMAGE_TILING_OPTIMAL, - props.optimalTilingFeatures}; + const Format tmp = {fmt, VK_IMAGE_TILING_OPTIMAL, props.optimalTilingFeatures}; formats_.push_back(tmp); } } @@ -399,27 +368,21 @@ VkFormatProperties Device::format_properties(VkFormat format) { void Device::wait() { EXPECT(vkDeviceWaitIdle(handle()) == VK_SUCCESS); } -VkResult Device::wait(const std::vector &fences, bool wait_all, - uint64_t timeout) { +VkResult Device::wait(const std::vector &fences, bool wait_all, uint64_t timeout) { const std::vector fence_handles = make_handles(fences); - VkResult err = vkWaitForFences(handle(), fence_handles.size(), - fence_handles.data(), wait_all, timeout); + VkResult err = vkWaitForFences(handle(), fence_handles.size(), fence_handles.data(), wait_all, timeout); EXPECT(err == VK_SUCCESS || err == VK_TIMEOUT); return err; } -void Device::update_descriptor_sets( - const std::vector &writes, - const std::vector &copies) { - vkUpdateDescriptorSets(handle(), writes.size(), writes.data(), - copies.size(), copies.data()); +void Device::update_descriptor_sets(const std::vector &writes, + const std::vector &copies) { + vkUpdateDescriptorSets(handle(), writes.size(), writes.data(), copies.size(), copies.data()); } -void Queue::submit(const std::vector &cmds, - Fence &fence) { - const std::vector cmd_handles = - make_handles(cmds); +void Queue::submit(const std::vector &cmds, Fence &fence) { + const std::vector cmd_handles = make_handles(cmds); VkSubmitInfo submit_info; submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; submit_info.pNext = NULL; @@ -431,13 +394,10 @@ void Queue::submit(const std::vector &cmds, submit_info.signalSemaphoreCount = 0; submit_info.pSignalSemaphores = NULL; - EXPECT(vkQueueSubmit(handle(), 1, &submit_info, fence.handle()) == - VK_SUCCESS); + EXPECT(vkQueueSubmit(handle(), 1, &submit_info, fence.handle()) == VK_SUCCESS); } -void Queue::submit(const CommandBuffer &cmd, Fence &fence) { - submit(std::vector(1, &cmd), fence); -} +void Queue::submit(const CommandBuffer &cmd, Fence &fence) { submit(std::vector(1, &cmd), fence); } void Queue::submit(const CommandBuffer &cmd) { Fence fence; @@ -457,8 +417,7 @@ void DeviceMemory::init(const Device &dev, const VkMemoryAllocateInfo &info) { const void *DeviceMemory::map(VkFlags flags) const { void *data; - if (!EXPECT(vkMapMemory(device(), handle(), 0, VK_WHOLE_SIZE, flags, - &data) == VK_SUCCESS)) + if (!EXPECT(vkMapMemory(device(), handle(), 0, VK_WHOLE_SIZE, flags, &data) == VK_SUCCESS)) data = NULL; return data; @@ -466,8 +425,7 @@ const void *DeviceMemory::map(VkFlags flags) const { void *DeviceMemory::map(VkFlags flags) { void *data; - if (!EXPECT(vkMapMemory(device(), handle(), 0, VK_WHOLE_SIZE, flags, - &data) == VK_SUCCESS)) + if (!EXPECT(vkMapMemory(device(), handle(), 0, VK_WHOLE_SIZE, flags, &data) == VK_SUCCESS)) data = NULL; return data; @@ -477,9 +435,7 @@ void DeviceMemory::unmap() const { vkUnmapMemory(device(), handle()); } NON_DISPATCHABLE_HANDLE_DTOR(Fence, vkDestroyFence) -void Fence::init(const Device &dev, const VkFenceCreateInfo &info) { - NON_DISPATCHABLE_HANDLE_INIT(vkCreateFence, dev, &info); -} +void Fence::init(const Device &dev, const VkFenceCreateInfo &info) { NON_DISPATCHABLE_HANDLE_INIT(vkCreateFence, dev, &info); } NON_DISPATCHABLE_HANDLE_DTOR(Semaphore, vkDestroySemaphore) @@ -489,9 +445,7 @@ void Semaphore::init(const Device &dev, const VkSemaphoreCreateInfo &info) { NON_DISPATCHABLE_HANDLE_DTOR(Event, vkDestroyEvent) -void Event::init(const Device &dev, const VkEventCreateInfo &info) { - NON_DISPATCHABLE_HANDLE_INIT(vkCreateEvent, dev, &info); -} +void Event::init(const Device &dev, const VkEventCreateInfo &info) { NON_DISPATCHABLE_HANDLE_INIT(vkCreateEvent, dev, &info); } void Event::set() { EXPECT(vkSetEvent(device(), handle()) == VK_SUCCESS); } @@ -503,10 +457,8 @@ void QueryPool::init(const Device &dev, const VkQueryPoolCreateInfo &info) { NON_DISPATCHABLE_HANDLE_INIT(vkCreateQueryPool, dev, &info); } -VkResult QueryPool::results(uint32_t first, uint32_t count, size_t size, - void *data, size_t stride) { - VkResult err = vkGetQueryPoolResults(device(), handle(), first, count, size, - data, stride, 0); +VkResult QueryPool::results(uint32_t first, uint32_t count, size_t size, void *data, size_t stride) { + VkResult err = vkGetQueryPoolResults(device(), handle(), first, count, size, data, stride, 0); EXPECT(err == VK_SUCCESS || err == VK_NOT_READY); return err; @@ -514,12 +466,10 @@ VkResult QueryPool::results(uint32_t first, uint32_t count, size_t size, NON_DISPATCHABLE_HANDLE_DTOR(Buffer, vkDestroyBuffer) -void Buffer::init(const Device &dev, const VkBufferCreateInfo &info, - VkMemoryPropertyFlags mem_props) { +void Buffer::init(const Device &dev, const VkBufferCreateInfo &info, VkMemoryPropertyFlags mem_props) { init_no_mem(dev, info); - internal_mem_.init( - dev, get_resource_alloc_info(dev, memory_requirements(), mem_props)); + internal_mem_.init(dev, get_resource_alloc_info(dev, memory_requirements(), mem_props)); bind_memory(internal_mem_, 0); } @@ -537,8 +487,7 @@ VkMemoryRequirements Buffer::memory_requirements() const { } void Buffer::bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset) { - EXPECT(vkBindBufferMemory(device(), handle(), mem.handle(), mem_offset) == - VK_SUCCESS); + EXPECT(vkBindBufferMemory(device(), handle(), mem.handle(), mem_offset) == VK_SUCCESS); } NON_DISPATCHABLE_HANDLE_DTOR(BufferView, vkDestroyBufferView) @@ -549,13 +498,11 @@ void BufferView::init(const Device &dev, const VkBufferViewCreateInfo &info) { NON_DISPATCHABLE_HANDLE_DTOR(Image, vkDestroyImage) -void Image::init(const Device &dev, const VkImageCreateInfo &info, - VkMemoryPropertyFlags mem_props) { +void Image::init(const Device &dev, const VkImageCreateInfo &info, VkMemoryPropertyFlags mem_props) { init_no_mem(dev, info); if (initialized()) { - internal_mem_.init( - dev, get_resource_alloc_info(dev, memory_requirements(), mem_props)); + internal_mem_.init(dev, get_resource_alloc_info(dev, memory_requirements(), mem_props)); bind_memory(internal_mem_, 0); } } @@ -570,11 +517,8 @@ void Image::init_no_mem(const Device &dev, const VkImageCreateInfo &info) { void Image::init_info(const Device &dev, const VkImageCreateInfo &info) { create_info_ = info; - for (std::vector::const_iterator it = dev.formats().begin(); - it != dev.formats().end(); it++) { - if (memcmp(&it->format, &create_info_.format, sizeof(it->format)) == - 0 && - it->tiling == create_info_.tiling) { + for (std::vector::const_iterator it = dev.formats().begin(); it != dev.formats().end(); it++) { + if (memcmp(&it->format, &create_info_.format, sizeof(it->format)) == 0 && it->tiling == create_info_.tiling) { format_features_ = it->features; break; } @@ -590,12 +534,10 @@ VkMemoryRequirements Image::memory_requirements() const { } void Image::bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset) { - EXPECT(vkBindImageMemory(device(), handle(), mem.handle(), mem_offset) == - VK_SUCCESS); + EXPECT(vkBindImageMemory(device(), handle(), mem.handle(), mem_offset) == VK_SUCCESS); } -VkSubresourceLayout -Image::subresource_layout(const VkImageSubresource &subres) const { +VkSubresourceLayout Image::subresource_layout(const VkImageSubresource &subres) const { VkSubresourceLayout data; size_t size = sizeof(data); vkGetImageSubresourceLayout(device(), handle(), &subres, &data); @@ -605,12 +547,9 @@ Image::subresource_layout(const VkImageSubresource &subres) const { return data; } -VkSubresourceLayout -Image::subresource_layout(const VkImageSubresourceLayers &subrescopy) const { +VkSubresourceLayout Image::subresource_layout(const VkImageSubresourceLayers &subrescopy) const { VkSubresourceLayout data; - VkImageSubresource subres = - subresource(subrescopy.aspectMask, subrescopy.mipLevel, - subrescopy.baseArrayLayer); + VkImageSubresource subres = subresource(subrescopy.aspectMask, subrescopy.mipLevel, subrescopy.baseArrayLayer); size_t size = sizeof(data); vkGetImageSubresourceLayout(device(), handle(), &subres, &data); if (size != sizeof(data)) @@ -620,11 +559,8 @@ Image::subresource_layout(const VkImageSubresourceLayers &subrescopy) const { } bool Image::transparent() const { - return ( - create_info_.tiling == VK_IMAGE_TILING_LINEAR && - create_info_.samples == VK_SAMPLE_COUNT_1_BIT && - !(create_info_.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | - VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT))); + return (create_info_.tiling == VK_IMAGE_TILING_LINEAR && create_info_.samples == VK_SAMPLE_COUNT_1_BIT && + !(create_info_.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT))); } NON_DISPATCHABLE_HANDLE_DTOR(ImageView, vkDestroyImageView) @@ -635,13 +571,11 @@ void ImageView::init(const Device &dev, const VkImageViewCreateInfo &info) { NON_DISPATCHABLE_HANDLE_DTOR(ShaderModule, vkDestroyShaderModule) -void ShaderModule::init(const Device &dev, - const VkShaderModuleCreateInfo &info) { +void ShaderModule::init(const Device &dev, const VkShaderModuleCreateInfo &info) { NON_DISPATCHABLE_HANDLE_INIT(vkCreateShaderModule, dev, &info); } -VkResult ShaderModule::init_try(const Device &dev, - const VkShaderModuleCreateInfo &info) { +VkResult ShaderModule::init_try(const Device &dev, const VkShaderModuleCreateInfo &info) { VkShaderModule mod; VkResult err = vkCreateShaderModule(dev.handle(), &info, NULL, &mod); @@ -653,22 +587,19 @@ VkResult ShaderModule::init_try(const Device &dev, NON_DISPATCHABLE_HANDLE_DTOR(Pipeline, vkDestroyPipeline) -void Pipeline::init(const Device &dev, - const VkGraphicsPipelineCreateInfo &info) { +void Pipeline::init(const Device &dev, const VkGraphicsPipelineCreateInfo &info) { VkPipelineCache cache; VkPipelineCacheCreateInfo ci; memset((void *)&ci, 0, sizeof(VkPipelineCacheCreateInfo)); ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; VkResult err = vkCreatePipelineCache(dev.handle(), &ci, NULL, &cache); if (err == VK_SUCCESS) { - NON_DISPATCHABLE_HANDLE_INIT(vkCreateGraphicsPipelines, dev, cache, 1, - &info); + NON_DISPATCHABLE_HANDLE_INIT(vkCreateGraphicsPipelines, dev, cache, 1, &info); vkDestroyPipelineCache(dev.handle(), cache, NULL); } } -VkResult Pipeline::init_try(const Device &dev, - const VkGraphicsPipelineCreateInfo &info) { +VkResult Pipeline::init_try(const Device &dev, const VkGraphicsPipelineCreateInfo &info) { VkPipeline pipe; VkPipelineCache cache; VkPipelineCacheCreateInfo ci; @@ -677,8 +608,7 @@ VkResult Pipeline::init_try(const Device &dev, VkResult err = vkCreatePipelineCache(dev.handle(), &ci, NULL, &cache); EXPECT(err == VK_SUCCESS); if (err == VK_SUCCESS) { - err = vkCreateGraphicsPipelines(dev.handle(), cache, 1, &info, NULL, - &pipe); + err = vkCreateGraphicsPipelines(dev.handle(), cache, 1, &info, NULL, &pipe); if (err == VK_SUCCESS) { NonDispHandle::init(dev.handle(), pipe); } @@ -688,27 +618,23 @@ VkResult Pipeline::init_try(const Device &dev, return err; } -void Pipeline::init(const Device &dev, - const VkComputePipelineCreateInfo &info) { +void Pipeline::init(const Device &dev, const VkComputePipelineCreateInfo &info) { VkPipelineCache cache; VkPipelineCacheCreateInfo ci; memset((void *)&ci, 0, sizeof(VkPipelineCacheCreateInfo)); ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; VkResult err = vkCreatePipelineCache(dev.handle(), &ci, NULL, &cache); if (err == VK_SUCCESS) { - NON_DISPATCHABLE_HANDLE_INIT(vkCreateComputePipelines, dev, cache, 1, - &info); + NON_DISPATCHABLE_HANDLE_INIT(vkCreateComputePipelines, dev, cache, 1, &info); vkDestroyPipelineCache(dev.handle(), cache, NULL); } } NON_DISPATCHABLE_HANDLE_DTOR(PipelineLayout, vkDestroyPipelineLayout) -void PipelineLayout::init( - const Device &dev, VkPipelineLayoutCreateInfo &info, - const std::vector &layouts) { - const std::vector layout_handles = - make_handles(layouts); +void PipelineLayout::init(const Device &dev, VkPipelineLayoutCreateInfo &info, + const std::vector &layouts) { + const std::vector layout_handles = make_handles(layouts); info.pSetLayouts = layout_handles.data(); NON_DISPATCHABLE_HANDLE_INIT(vkCreatePipelineLayout, dev, &info); @@ -722,29 +648,22 @@ void Sampler::init(const Device &dev, const VkSamplerCreateInfo &info) { NON_DISPATCHABLE_HANDLE_DTOR(DescriptorSetLayout, vkDestroyDescriptorSetLayout) -void DescriptorSetLayout::init(const Device &dev, - const VkDescriptorSetLayoutCreateInfo &info) { +void DescriptorSetLayout::init(const Device &dev, const VkDescriptorSetLayoutCreateInfo &info) { NON_DISPATCHABLE_HANDLE_INIT(vkCreateDescriptorSetLayout, dev, &info); } NON_DISPATCHABLE_HANDLE_DTOR(DescriptorPool, vkDestroyDescriptorPool) -void DescriptorPool::init(const Device &dev, - const VkDescriptorPoolCreateInfo &info) { - setDynamicUsage(info.flags & - VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT); +void DescriptorPool::init(const Device &dev, const VkDescriptorPoolCreateInfo &info) { + setDynamicUsage(info.flags & VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT); NON_DISPATCHABLE_HANDLE_INIT(vkCreateDescriptorPool, dev, &info); } -void DescriptorPool::reset() { - EXPECT(vkResetDescriptorPool(device(), handle(), 0) == VK_SUCCESS); -} +void DescriptorPool::reset() { EXPECT(vkResetDescriptorPool(device(), handle(), 0) == VK_SUCCESS); } -std::vector DescriptorPool::alloc_sets( - const Device &dev, - const std::vector &layouts) { - const std::vector layout_handles = - make_handles(layouts); +std::vector DescriptorPool::alloc_sets(const Device &dev, + const std::vector &layouts) { + const std::vector layout_handles = make_handles(layouts); std::vector set_handles; set_handles.resize(layout_handles.size()); @@ -754,13 +673,11 @@ std::vector DescriptorPool::alloc_sets( alloc_info.descriptorSetCount = layout_handles.size(); alloc_info.descriptorPool = handle(); alloc_info.pSetLayouts = layout_handles.data(); - VkResult err = - vkAllocateDescriptorSets(device(), &alloc_info, set_handles.data()); + VkResult err = vkAllocateDescriptorSets(device(), &alloc_info, set_handles.data()); EXPECT(err == VK_SUCCESS); std::vector sets; - for (std::vector::const_iterator it = set_handles.begin(); - it != set_handles.end(); it++) { + for (std::vector::const_iterator it = set_handles.begin(); it != set_handles.end(); it++) { // do descriptor sets need memories bound? DescriptorSet *descriptorSet = new DescriptorSet(dev, this, *it); sets.push_back(descriptorSet); @@ -768,15 +685,11 @@ std::vector DescriptorPool::alloc_sets( return sets; } -std::vector -DescriptorPool::alloc_sets(const Device &dev, const DescriptorSetLayout &layout, - uint32_t count) { - return alloc_sets(dev, - std::vector(count, &layout)); +std::vector DescriptorPool::alloc_sets(const Device &dev, const DescriptorSetLayout &layout, uint32_t count) { + return alloc_sets(dev, std::vector(count, &layout)); } -DescriptorSet *DescriptorPool::alloc_sets(const Device &dev, - const DescriptorSetLayout &layout) { +DescriptorSet *DescriptorPool::alloc_sets(const Device &dev, const DescriptorSetLayout &layout) { std::vector set = alloc_sets(dev, layout, 1); return (set.empty()) ? NULL : set[0]; } @@ -786,8 +699,7 @@ DescriptorSet::~DescriptorSet() { // Only call vkFree* on sets allocated from pool with usage *_DYNAMIC if (containing_pool_->getDynamicUsage()) { VkDescriptorSet sets[1] = {handle()}; - EXPECT(vkFreeDescriptorSets(device(), containing_pool_->GetObj(), 1, - sets) == VK_SUCCESS); + EXPECT(vkFreeDescriptorSets(device(), containing_pool_->GetObj(), 1, sets) == VK_SUCCESS); } } } @@ -805,24 +717,20 @@ CommandBuffer::~CommandBuffer() { } } -void CommandBuffer::init(const Device &dev, - const VkCommandBufferAllocateInfo &info) { +void CommandBuffer::init(const Device &dev, const VkCommandBufferAllocateInfo &info) { VkCommandBuffer cmd; // Make sure commandPool is set assert(info.commandPool); - if (EXPECT(vkAllocateCommandBuffers(dev.handle(), &info, &cmd) == - VK_SUCCESS)) { + if (EXPECT(vkAllocateCommandBuffers(dev.handle(), &info, &cmd) == VK_SUCCESS)) { Handle::init(cmd); dev_handle_ = dev.handle(); cmd_pool_ = info.commandPool; } } -void CommandBuffer::begin(const VkCommandBufferBeginInfo *info) { - EXPECT(vkBeginCommandBuffer(handle(), info) == VK_SUCCESS); -} +void CommandBuffer::begin(const VkCommandBufferBeginInfo *info) { EXPECT(vkBeginCommandBuffer(handle(), info) == VK_SUCCESS); } void CommandBuffer::begin() { VkCommandBufferBeginInfo info = {}; @@ -842,12 +750,8 @@ void CommandBuffer::begin() { begin(&info); } -void CommandBuffer::end() { - EXPECT(vkEndCommandBuffer(handle()) == VK_SUCCESS); -} +void CommandBuffer::end() { EXPECT(vkEndCommandBuffer(handle()) == VK_SUCCESS); } -void CommandBuffer::reset(VkCommandBufferResetFlags flags) { - EXPECT(vkResetCommandBuffer(handle(), flags) == VK_SUCCESS); -} +void CommandBuffer::reset(VkCommandBufferResetFlags flags) { EXPECT(vkResetCommandBuffer(handle(), flags) == VK_SUCCESS); } }; // namespace vk_testing diff --git a/tests/vktestbinding.h b/tests/vktestbinding.h index 59bcfa8..40d73c8 100644 --- a/tests/vktestbinding.h +++ b/tests/vktestbinding.h @@ -22,15 +22,14 @@ #ifndef VKTESTBINDING_H #define VKTESTBINDING_H -#include #include +#include #include "vulkan/vulkan.h" namespace vk_testing { -typedef void (*ErrorCallback)(const char *expr, const char *file, - unsigned int line, const char *function); +typedef void (*ErrorCallback)(const char *expr, const char *file, unsigned int line, const char *function); void set_error_callback(ErrorCallback callback); class PhysicalDevice; @@ -90,8 +89,7 @@ template class Handle { template class NonDispHandle : public Handle { protected: explicit NonDispHandle() : Handle(), dev_handle_(VK_NULL_HANDLE) {} - explicit NonDispHandle(VkDevice dev, T handle) - : Handle(handle), dev_handle_(dev) {} + explicit NonDispHandle(VkDevice dev, T handle) : Handle(handle), dev_handle_(dev) {} const VkDevice &device() const { return dev_handle_; } @@ -119,8 +117,7 @@ class PhysicalDevice : public internal::Handle { std::vector queue_properties() const; VkPhysicalDeviceFeatures features() const; - bool set_memory_type(const uint32_t type_bits, VkMemoryAllocateInfo *info, - const VkMemoryPropertyFlags properties, + bool set_memory_type(const uint32_t type_bits, VkMemoryAllocateInfo *info, const VkMemoryPropertyFlags properties, const VkMemoryPropertyFlags forbid = 0) const; // vkEnumerateDeviceExtensionProperties() @@ -131,10 +128,8 @@ class PhysicalDevice : public internal::Handle { std::vector layers() const; private: - void - add_extension_dependencies(uint32_t dependency_count, - VkExtensionProperties *depencency_props, - std::vector &ext_list); + void add_extension_dependencies(uint32_t dependency_count, VkExtensionProperties *depencency_props, + std::vector &ext_list); VkPhysicalDeviceMemoryProperties memory_properties_; @@ -148,8 +143,8 @@ class Device : public internal::Handle { // vkCreateDevice() void init(const VkDeviceCreateInfo &info); - void init(std::vector - &extensions, VkPhysicalDeviceFeatures *features = nullptr); // all queues, all extensions, etc + void init(std::vector &extensions, + VkPhysicalDeviceFeatures *features = nullptr); // all queues, all extensions, etc void init() { std::vector extensions; init(extensions); @@ -158,14 +153,10 @@ class Device : public internal::Handle { const PhysicalDevice &phy() const { return phy_; } // vkGetDeviceProcAddr() - PFN_vkVoidFunction get_proc(const char *name) const { - return vkGetDeviceProcAddr(handle(), name); - } + PFN_vkVoidFunction get_proc(const char *name) const { return vkGetDeviceProcAddr(handle(), name); } // vkGetDeviceQueue() - const std::vector &graphics_queues() const { - return queues_[GRAPHICS]; - } + const std::vector &graphics_queues() const { return queues_[GRAPHICS]; } const std::vector &compute_queues() { return queues_[COMPUTE]; } const std::vector &dma_queues() { return queues_[DMA]; } uint32_t graphics_queue_node_index_; @@ -183,53 +174,33 @@ class Device : public internal::Handle { void wait(); // vkWaitForFences() - VkResult wait(const std::vector &fences, bool wait_all, - uint64_t timeout); - VkResult wait(const Fence &fence) { - return wait(std::vector(1, &fence), true, (uint64_t)-1); - } + VkResult wait(const std::vector &fences, bool wait_all, uint64_t timeout); + VkResult wait(const Fence &fence) { return wait(std::vector(1, &fence), true, (uint64_t)-1); } // vkUpdateDescriptorSets() - void update_descriptor_sets(const std::vector &writes, - const std::vector &copies); - void - update_descriptor_sets(const std::vector &writes) { - return update_descriptor_sets(writes, - std::vector()); + void update_descriptor_sets(const std::vector &writes, const std::vector &copies); + void update_descriptor_sets(const std::vector &writes) { + return update_descriptor_sets(writes, std::vector()); } - static VkWriteDescriptorSet - write_descriptor_set(const DescriptorSet &set, uint32_t binding, - uint32_t array_element, VkDescriptorType type, - uint32_t count, - const VkDescriptorImageInfo *image_info); - static VkWriteDescriptorSet - write_descriptor_set(const DescriptorSet &set, uint32_t binding, - uint32_t array_element, VkDescriptorType type, - uint32_t count, - const VkDescriptorBufferInfo *buffer_info); - static VkWriteDescriptorSet - write_descriptor_set(const DescriptorSet &set, uint32_t binding, - uint32_t array_element, VkDescriptorType type, - uint32_t count, const VkBufferView *buffer_views); - static VkWriteDescriptorSet - write_descriptor_set(const DescriptorSet &set, uint32_t binding, - uint32_t array_element, VkDescriptorType type, - const std::vector &image_info); - static VkWriteDescriptorSet write_descriptor_set( - const DescriptorSet &set, uint32_t binding, uint32_t array_element, - VkDescriptorType type, - const std::vector &buffer_info); - static VkWriteDescriptorSet - write_descriptor_set(const DescriptorSet &set, uint32_t binding, - uint32_t array_element, VkDescriptorType type, - const std::vector &buffer_views); - - static VkCopyDescriptorSet - copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, - uint32_t src_array_element, - const DescriptorSet &dst_set, uint32_t dst_binding, - uint32_t dst_array_element, uint32_t count); + static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, + VkDescriptorType type, uint32_t count, + const VkDescriptorImageInfo *image_info); + static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, + VkDescriptorType type, uint32_t count, + const VkDescriptorBufferInfo *buffer_info); + static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, + VkDescriptorType type, uint32_t count, const VkBufferView *buffer_views); + static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, + VkDescriptorType type, const std::vector &image_info); + static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, + VkDescriptorType type, const std::vector &buffer_info); + static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, + VkDescriptorType type, const std::vector &buffer_views); + + static VkCopyDescriptorSet copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, uint32_t src_array_element, + const DescriptorSet &dst_set, uint32_t dst_binding, uint32_t dst_array_element, + uint32_t count); private: enum QueueIndex { @@ -250,9 +221,7 @@ class Device : public internal::Handle { class Queue : public internal::Handle { public: - explicit Queue(VkQueue queue, int index) : Handle(queue) { - family_index_ = index; - } + explicit Queue(VkQueue queue, int index) : Handle(queue) { family_index_ = index; } // vkQueueSubmit() void submit(const std::vector &cmds, Fence &fence); @@ -284,8 +253,7 @@ class DeviceMemory : public internal::NonDispHandle { // vkUnmapMemory() void unmap() const; - static VkMemoryAllocateInfo alloc_info(VkDeviceSize size, - uint32_t memory_type_index); + static VkMemoryAllocateInfo alloc_info(VkDeviceSize size, uint32_t memory_type_index); }; class Fence : public internal::NonDispHandle { @@ -337,47 +305,32 @@ class QueryPool : public internal::NonDispHandle { void init(const Device &dev, const VkQueryPoolCreateInfo &info); // vkGetQueryPoolResults() - VkResult results(uint32_t first, uint32_t count, size_t size, void *data, - size_t stride); + VkResult results(uint32_t first, uint32_t count, size_t size, void *data, size_t stride); - static VkQueryPoolCreateInfo create_info(VkQueryType type, - uint32_t slot_count); + static VkQueryPoolCreateInfo create_info(VkQueryType type, uint32_t slot_count); }; class Buffer : public internal::NonDispHandle { public: explicit Buffer() : NonDispHandle() {} - explicit Buffer(const Device &dev, const VkBufferCreateInfo &info) { - init(dev, info); - } + explicit Buffer(const Device &dev, const VkBufferCreateInfo &info) { init(dev, info); } explicit Buffer(const Device &dev, VkDeviceSize size) { init(dev, size); } ~Buffer(); // vkCreateBuffer() - void init(const Device &dev, const VkBufferCreateInfo &info, - VkMemoryPropertyFlags mem_props); - void init(const Device &dev, const VkBufferCreateInfo &info) { - init(dev, info, 0); - } - void init(const Device &dev, VkDeviceSize size, - VkMemoryPropertyFlags mem_props) { - init(dev, create_info(size, 0), mem_props); - } + void init(const Device &dev, const VkBufferCreateInfo &info, VkMemoryPropertyFlags mem_props); + void init(const Device &dev, const VkBufferCreateInfo &info) { init(dev, info, 0); } + void init(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags mem_props) { init(dev, create_info(size, 0), mem_props); } void init(const Device &dev, VkDeviceSize size) { init(dev, size, 0); } - void init_as_src(const Device &dev, VkDeviceSize size, - VkMemoryPropertyFlags &reqs) { + void init_as_src(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) { init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT), reqs); } - void init_as_dst(const Device &dev, VkDeviceSize size, - VkMemoryPropertyFlags &reqs) { + void init_as_dst(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) { init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_DST_BIT), reqs); } - void init_as_src_and_dst(const Device &dev, VkDeviceSize size, - VkMemoryPropertyFlags &reqs) { - init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | - VK_BUFFER_USAGE_TRANSFER_DST_BIT), - reqs); + void init_as_src_and_dst(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) { + init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT), reqs); } void init_no_mem(const Device &dev, const VkBufferCreateInfo &info); @@ -393,9 +346,7 @@ class Buffer : public internal::NonDispHandle { static VkBufferCreateInfo create_info(VkDeviceSize size, VkFlags usage); - VkBufferMemoryBarrier buffer_memory_barrier(VkFlags output_mask, - VkFlags input_mask, - VkDeviceSize offset, + VkBufferMemoryBarrier buffer_memory_barrier(VkFlags output_mask, VkFlags input_mask, VkDeviceSize offset, VkDeviceSize size) const { VkBufferMemoryBarrier barrier = {}; barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; @@ -424,19 +375,13 @@ class BufferView : public internal::NonDispHandle { class Image : public internal::NonDispHandle { public: explicit Image() : NonDispHandle(), format_features_(0) {} - explicit Image(const Device &dev, const VkImageCreateInfo &info) - : format_features_(0) { - init(dev, info); - } + explicit Image(const Device &dev, const VkImageCreateInfo &info) : format_features_(0) { init(dev, info); } ~Image(); // vkCreateImage() - void init(const Device &dev, const VkImageCreateInfo &info, - VkMemoryPropertyFlags mem_props); - void init(const Device &dev, const VkImageCreateInfo &info) { - init(dev, info, 0); - } + void init(const Device &dev, const VkImageCreateInfo &info, VkMemoryPropertyFlags mem_props); + void init(const Device &dev, const VkImageCreateInfo &info) { init(dev, info, 0); } void init_no_mem(const Device &dev, const VkImageCreateInfo &info); // get the internal memory @@ -450,30 +395,21 @@ class Image : public internal::NonDispHandle { void bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset); // vkGetImageSubresourceLayout() - VkSubresourceLayout - subresource_layout(const VkImageSubresource &subres) const; - VkSubresourceLayout - subresource_layout(const VkImageSubresourceLayers &subres) const; + VkSubresourceLayout subresource_layout(const VkImageSubresource &subres) const; + VkSubresourceLayout subresource_layout(const VkImageSubresourceLayers &subres) const; bool transparent() const; - bool copyable() const { - return (format_features_ & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); - } + bool copyable() const { return (format_features_ & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); } - VkImageSubresourceRange - subresource_range(VkImageAspectFlagBits aspect) const { + VkImageSubresourceRange subresource_range(VkImageAspectFlagBits aspect) const { return subresource_range(create_info_, aspect); } VkExtent3D extent() const { return create_info_.extent; } - VkExtent3D extent(uint32_t mip_level) const { - return extent(create_info_.extent, mip_level); - } + VkExtent3D extent(uint32_t mip_level) const { return extent(create_info_.extent, mip_level); } VkFormat format() const { return create_info_.format; } - VkImageMemoryBarrier - image_memory_barrier(VkFlags output_mask, VkFlags input_mask, - VkImageLayout old_layout, VkImageLayout new_layout, - const VkImageSubresourceRange &range) const { + VkImageMemoryBarrier image_memory_barrier(VkFlags output_mask, VkFlags input_mask, VkImageLayout old_layout, + VkImageLayout new_layout, const VkImageSubresourceRange &range) const { VkImageMemoryBarrier barrier = {}; barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; barrier.srcAccessMask = output_mask; @@ -486,28 +422,16 @@ class Image : public internal::NonDispHandle { } static VkImageCreateInfo create_info(); - static VkImageSubresource subresource(VkImageAspectFlags aspect, - uint32_t mip_level, - uint32_t array_layer); - static VkImageSubresource subresource(const VkImageSubresourceRange &range, - uint32_t mip_level, - uint32_t array_layer); - static VkImageSubresourceLayers subresource(VkImageAspectFlags aspect, - uint32_t mip_level, - uint32_t array_layer, + static VkImageSubresource subresource(VkImageAspectFlags aspect, uint32_t mip_level, uint32_t array_layer); + static VkImageSubresource subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer); + static VkImageSubresourceLayers subresource(VkImageAspectFlags aspect, uint32_t mip_level, uint32_t array_layer, + uint32_t array_size); + static VkImageSubresourceLayers subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer, uint32_t array_size); - static VkImageSubresourceLayers - subresource(const VkImageSubresourceRange &range, uint32_t mip_level, - uint32_t array_layer, uint32_t array_size); - static VkImageSubresourceRange - subresource_range(VkImageAspectFlags aspect_mask, uint32_t base_mip_level, - uint32_t mip_levels, uint32_t base_array_layer, - uint32_t num_layers); - static VkImageSubresourceRange - subresource_range(const VkImageCreateInfo &info, - VkImageAspectFlags aspect_mask); - static VkImageSubresourceRange - subresource_range(const VkImageSubresource &subres); + static VkImageSubresourceRange subresource_range(VkImageAspectFlags aspect_mask, uint32_t base_mip_level, uint32_t mip_levels, + uint32_t base_array_layer, uint32_t num_layers); + static VkImageSubresourceRange subresource_range(const VkImageCreateInfo &info, VkImageAspectFlags aspect_mask); + static VkImageSubresourceRange subresource_range(const VkImageSubresource &subres); static VkExtent2D extent(int32_t width, int32_t height); static VkExtent2D extent(const VkExtent2D &extent, uint32_t mip_level); @@ -541,8 +465,7 @@ class ShaderModule : public internal::NonDispHandle { void init(const Device &dev, const VkShaderModuleCreateInfo &info); VkResult init_try(const Device &dev, const VkShaderModuleCreateInfo &info); - static VkShaderModuleCreateInfo - create_info(size_t code_size, const uint32_t *code, VkFlags flags); + static VkShaderModuleCreateInfo create_info(size_t code_size, const uint32_t *code, VkFlags flags); }; class Pipeline : public internal::NonDispHandle { @@ -552,19 +475,16 @@ class Pipeline : public internal::NonDispHandle { // vkCreateGraphicsPipeline() void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info); // vkCreateGraphicsPipelineDerivative() - void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info, - const VkPipeline basePipeline); + void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info, const VkPipeline basePipeline); // vkCreateComputePipeline() void init(const Device &dev, const VkComputePipelineCreateInfo &info); // vkLoadPipeline() void init(const Device &dev, size_t size, const void *data); // vkLoadPipelineDerivative() - void init(const Device &dev, size_t size, const void *data, - VkPipeline basePipeline); + void init(const Device &dev, size_t size, const void *data, VkPipeline basePipeline); // vkCreateGraphicsPipeline with error return - VkResult init_try(const Device &dev, - const VkGraphicsPipelineCreateInfo &info); + VkResult init_try(const Device &dev, const VkGraphicsPipelineCreateInfo &info); // vkStorePipeline() size_t store(size_t size, void *data); @@ -575,8 +495,7 @@ class PipelineLayout : public internal::NonDispHandle { ~PipelineLayout(); // vCreatePipelineLayout() - void init(const Device &dev, VkPipelineLayoutCreateInfo &info, - const std::vector &layouts); + void init(const Device &dev, VkPipelineLayoutCreateInfo &info, const std::vector &layouts); }; class Sampler : public internal::NonDispHandle { @@ -587,8 +506,7 @@ class Sampler : public internal::NonDispHandle { void init(const Device &dev, const VkSamplerCreateInfo &info); }; -class DescriptorSetLayout - : public internal::NonDispHandle { +class DescriptorSetLayout : public internal::NonDispHandle { public: ~DescriptorSetLayout(); @@ -615,14 +533,9 @@ class DescriptorPool : public internal::NonDispHandle { bool getDynamicUsage() { return dynamic_usage_; } // vkAllocateDescriptorSets() - std::vector - alloc_sets(const Device &dev, - const std::vector &layouts); - std::vector alloc_sets(const Device &dev, - const DescriptorSetLayout &layout, - uint32_t count); - DescriptorSet *alloc_sets(const Device &dev, - const DescriptorSetLayout &layout); + std::vector alloc_sets(const Device &dev, const std::vector &layouts); + std::vector alloc_sets(const Device &dev, const DescriptorSetLayout &layout, uint32_t count); + DescriptorSet *alloc_sets(const Device &dev, const DescriptorSetLayout &layout); private: VkDescriptorPool pool_; @@ -636,9 +549,7 @@ class DescriptorSet : public internal::NonDispHandle { ~DescriptorSet(); explicit DescriptorSet() : NonDispHandle() {} - explicit DescriptorSet(const Device &dev, DescriptorPool *pool, - VkDescriptorSet set) - : NonDispHandle(dev.handle(), set) { + explicit DescriptorSet(const Device &dev, DescriptorPool *pool, VkDescriptorSet set) : NonDispHandle(dev.handle(), set) { containing_pool_ = pool; } @@ -651,18 +562,14 @@ class CommandPool : public internal::NonDispHandle { ~CommandPool(); explicit CommandPool() : NonDispHandle() {} - explicit CommandPool(const Device &dev, - const VkCommandPoolCreateInfo &info) { - init(dev, info); - } + explicit CommandPool(const Device &dev, const VkCommandPoolCreateInfo &info) { init(dev, info); } void init(const Device &dev, const VkCommandPoolCreateInfo &info); static VkCommandPoolCreateInfo create_info(uint32_t queue_family_index); }; -inline VkCommandPoolCreateInfo -CommandPool::create_info(uint32_t queue_family_index) { +inline VkCommandPoolCreateInfo CommandPool::create_info(uint32_t queue_family_index) { VkCommandPoolCreateInfo info = {}; info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; info.queueFamilyIndex = queue_family_index; @@ -675,10 +582,7 @@ class CommandBuffer : public internal::Handle { ~CommandBuffer(); explicit CommandBuffer() : Handle() {} - explicit CommandBuffer(const Device &dev, - const VkCommandBufferAllocateInfo &info) { - init(dev, info); - } + explicit CommandBuffer(const Device &dev, const VkCommandBufferAllocateInfo &info) { init(dev, info); } // vkAllocateCommandBuffers() void init(const Device &dev, const VkCommandBufferAllocateInfo &info); @@ -700,8 +604,7 @@ class CommandBuffer : public internal::Handle { VkCommandPool cmd_pool_; }; -inline VkMemoryAllocateInfo -DeviceMemory::alloc_info(VkDeviceSize size, uint32_t memory_type_index) { +inline VkMemoryAllocateInfo DeviceMemory::alloc_info(VkDeviceSize size, uint32_t memory_type_index) { VkMemoryAllocateInfo info = {}; info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; info.allocationSize = size; @@ -709,8 +612,7 @@ DeviceMemory::alloc_info(VkDeviceSize size, uint32_t memory_type_index) { return info; } -inline VkBufferCreateInfo Buffer::create_info(VkDeviceSize size, - VkFlags usage) { +inline VkBufferCreateInfo Buffer::create_info(VkDeviceSize size, VkFlags usage) { VkBufferCreateInfo info = {}; info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; info.size = size; @@ -745,8 +647,7 @@ inline VkEventCreateInfo Event::create_info(VkFlags flags) { return info; } -inline VkQueryPoolCreateInfo QueryPool::create_info(VkQueryType type, - uint32_t slot_count) { +inline VkQueryPoolCreateInfo QueryPool::create_info(VkQueryType type, uint32_t slot_count) { VkQueryPoolCreateInfo info = {}; info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; info.queryType = type; @@ -766,9 +667,7 @@ inline VkImageCreateInfo Image::create_info() { return info; } -inline VkImageSubresource Image::subresource(VkImageAspectFlags aspect, - uint32_t mip_level, - uint32_t array_layer) { +inline VkImageSubresource Image::subresource(VkImageAspectFlags aspect, uint32_t mip_level, uint32_t array_layer) { VkImageSubresource subres = {}; if (aspect == 0) { assert(!"Invalid VkImageAspectFlags"); @@ -779,17 +678,11 @@ inline VkImageSubresource Image::subresource(VkImageAspectFlags aspect, return subres; } -inline VkImageSubresource -Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, - uint32_t array_layer) { - return subresource(range.aspectMask, - range.baseMipLevel + mip_level, - range.baseArrayLayer + array_layer); +inline VkImageSubresource Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer) { + return subresource(range.aspectMask, range.baseMipLevel + mip_level, range.baseArrayLayer + array_layer); } -inline VkImageSubresourceLayers Image::subresource(VkImageAspectFlags aspect, - uint32_t mip_level, - uint32_t array_layer, +inline VkImageSubresourceLayers Image::subresource(VkImageAspectFlags aspect, uint32_t mip_level, uint32_t array_layer, uint32_t array_size) { VkImageSubresourceLayers subres = {}; switch (aspect) { @@ -809,18 +702,13 @@ inline VkImageSubresourceLayers Image::subresource(VkImageAspectFlags aspect, return subres; } -inline VkImageSubresourceLayers -Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, - uint32_t array_layer, uint32_t array_size) { - return subresource(range.aspectMask, - range.baseMipLevel + mip_level, - range.baseArrayLayer + array_layer, array_size); +inline VkImageSubresourceLayers Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer, + uint32_t array_size) { + return subresource(range.aspectMask, range.baseMipLevel + mip_level, range.baseArrayLayer + array_layer, array_size); } -inline VkImageSubresourceRange -Image::subresource_range(VkImageAspectFlags aspect_mask, - uint32_t base_mip_level, uint32_t mip_levels, - uint32_t base_array_layer, uint32_t num_layers) { +inline VkImageSubresourceRange Image::subresource_range(VkImageAspectFlags aspect_mask, uint32_t base_mip_level, + uint32_t mip_levels, uint32_t base_array_layer, uint32_t num_layers) { VkImageSubresourceRange range = {}; if (aspect_mask == 0) { assert(!"Invalid VkImageAspectFlags"); @@ -833,17 +721,12 @@ Image::subresource_range(VkImageAspectFlags aspect_mask, return range; } -inline VkImageSubresourceRange -Image::subresource_range(const VkImageCreateInfo &info, - VkImageAspectFlags aspect_mask) { - return subresource_range(aspect_mask, 0, info.mipLevels, 0, - info.arrayLayers); +inline VkImageSubresourceRange Image::subresource_range(const VkImageCreateInfo &info, VkImageAspectFlags aspect_mask) { + return subresource_range(aspect_mask, 0, info.mipLevels, 0, info.arrayLayers); } -inline VkImageSubresourceRange -Image::subresource_range(const VkImageSubresource &subres) { - return subresource_range(subres.aspectMask, subres.mipLevel, 1, - subres.arrayLayer, 1); +inline VkImageSubresourceRange Image::subresource_range(const VkImageSubresource &subres) { + return subresource_range(subres.aspectMask, subres.mipLevel, 1, subres.arrayLayer, 1); } inline VkExtent2D Image::extent(int32_t width, int32_t height) { @@ -854,16 +737,12 @@ inline VkExtent2D Image::extent(int32_t width, int32_t height) { } inline VkExtent2D Image::extent(const VkExtent2D &extent, uint32_t mip_level) { - const int32_t width = - (extent.width >> mip_level) ? extent.width >> mip_level : 1; - const int32_t height = - (extent.height >> mip_level) ? extent.height >> mip_level : 1; + const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1; + const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1; return Image::extent(width, height); } -inline VkExtent2D Image::extent(const VkExtent3D &extent) { - return Image::extent(extent.width, extent.height); -} +inline VkExtent2D Image::extent(const VkExtent3D &extent) { return Image::extent(extent.width, extent.height); } inline VkExtent3D Image::extent(int32_t width, int32_t height, int32_t depth) { VkExtent3D extent = {}; @@ -874,18 +753,13 @@ inline VkExtent3D Image::extent(int32_t width, int32_t height, int32_t depth) { } inline VkExtent3D Image::extent(const VkExtent3D &extent, uint32_t mip_level) { - const int32_t width = - (extent.width >> mip_level) ? extent.width >> mip_level : 1; - const int32_t height = - (extent.height >> mip_level) ? extent.height >> mip_level : 1; - const int32_t depth = - (extent.depth >> mip_level) ? extent.depth >> mip_level : 1; + const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1; + const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1; + const int32_t depth = (extent.depth >> mip_level) ? extent.depth >> mip_level : 1; return Image::extent(width, height, depth); } -inline VkShaderModuleCreateInfo ShaderModule::create_info(size_t code_size, - const uint32_t *code, - VkFlags flags) { +inline VkShaderModuleCreateInfo ShaderModule::create_info(size_t code_size, const uint32_t *code, VkFlags flags) { VkShaderModuleCreateInfo info = {}; info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; info.codeSize = code_size; @@ -894,11 +768,9 @@ inline VkShaderModuleCreateInfo ShaderModule::create_info(size_t code_size, return info; } -inline VkWriteDescriptorSet -Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, - uint32_t array_element, VkDescriptorType type, - uint32_t count, - const VkDescriptorImageInfo *image_info) { +inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, + VkDescriptorType type, uint32_t count, + const VkDescriptorImageInfo *image_info) { VkWriteDescriptorSet write = {}; write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; write.dstSet = set.handle(); @@ -910,11 +782,9 @@ Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, return write; } -inline VkWriteDescriptorSet -Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, - uint32_t array_element, VkDescriptorType type, - uint32_t count, - const VkDescriptorBufferInfo *buffer_info) { +inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, + VkDescriptorType type, uint32_t count, + const VkDescriptorBufferInfo *buffer_info) { VkWriteDescriptorSet write = {}; write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; write.dstSet = set.handle(); @@ -926,10 +796,8 @@ Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, return write; } -inline VkWriteDescriptorSet -Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, - uint32_t array_element, VkDescriptorType type, - uint32_t count, const VkBufferView *buffer_views) { +inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, + VkDescriptorType type, uint32_t count, const VkBufferView *buffer_views) { VkWriteDescriptorSet write = {}; write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; write.dstSet = set.handle(); @@ -941,35 +809,26 @@ Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, return write; } -inline VkWriteDescriptorSet Device::write_descriptor_set( - const DescriptorSet &set, uint32_t binding, uint32_t array_element, - VkDescriptorType type, - const std::vector &image_info) { - return write_descriptor_set(set, binding, array_element, type, - image_info.size(), &image_info[0]); +inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, + VkDescriptorType type, + const std::vector &image_info) { + return write_descriptor_set(set, binding, array_element, type, image_info.size(), &image_info[0]); } -inline VkWriteDescriptorSet Device::write_descriptor_set( - const DescriptorSet &set, uint32_t binding, uint32_t array_element, - VkDescriptorType type, - const std::vector &buffer_info) { - return write_descriptor_set(set, binding, array_element, type, - buffer_info.size(), &buffer_info[0]); +inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, + VkDescriptorType type, + const std::vector &buffer_info) { + return write_descriptor_set(set, binding, array_element, type, buffer_info.size(), &buffer_info[0]); } -inline VkWriteDescriptorSet -Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, - uint32_t array_element, VkDescriptorType type, - const std::vector &buffer_views) { - return write_descriptor_set(set, binding, array_element, type, - buffer_views.size(), &buffer_views[0]); +inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, + VkDescriptorType type, const std::vector &buffer_views) { + return write_descriptor_set(set, binding, array_element, type, buffer_views.size(), &buffer_views[0]); } -inline VkCopyDescriptorSet -Device::copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, - uint32_t src_array_element, - const DescriptorSet &dst_set, uint32_t dst_binding, - uint32_t dst_array_element, uint32_t count) { +inline VkCopyDescriptorSet Device::copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, + uint32_t src_array_element, const DescriptorSet &dst_set, + uint32_t dst_binding, uint32_t dst_array_element, uint32_t count) { VkCopyDescriptorSet copy = {}; copy.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; copy.srcSet = src_set.handle(); @@ -983,8 +842,7 @@ Device::copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, return copy; } -inline VkCommandBufferAllocateInfo -CommandBuffer::create_info(VkCommandPool const &pool) { +inline VkCommandBufferAllocateInfo CommandBuffer::create_info(VkCommandPool const &pool) { VkCommandBufferAllocateInfo info = {}; info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; info.commandPool = pool; -- 2.7.4