From 9da05cd939a565e1a907030ea40f2ae435e830ad Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 21 Feb 2017 16:51:52 +0000 Subject: [PATCH] Add support for VK_NV_dedicated_allocation --- renderdoc/driver/vulkan/vk_common.cpp | 9 ++++++ renderdoc/driver/vulkan/vk_core.cpp | 3 ++ .../vulkan/wrappers/vk_resource_funcs.cpp | 28 +++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/renderdoc/driver/vulkan/vk_common.cpp b/renderdoc/driver/vulkan/vk_common.cpp index 8733889a4..d96ba3d9b 100644 --- a/renderdoc/driver/vulkan/vk_common.cpp +++ b/renderdoc/driver/vulkan/vk_common.cpp @@ -2845,6 +2845,15 @@ static void SerialiseNext(Serialiser *ser, VkStructureType &sType, const void *& { // do nothing } + // for now we don't serialise dedicated memory on replay as it's only a performance hint, + // and is only required in conjunction with shared memory (which we don't replay). In future + // it might be helpful to serialise this for informational purposes. + else if(next->sType == VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV || + next->sType == VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_IMAGE_CREATE_INFO_NV || + next->sType == VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV) + { + // do nothing + } else { RDCERR("Unrecognised extension structure type %d", next->sType); diff --git a/renderdoc/driver/vulkan/vk_core.cpp b/renderdoc/driver/vulkan/vk_core.cpp index e6f54618d..1e3dd653f 100644 --- a/renderdoc/driver/vulkan/vk_core.cpp +++ b/renderdoc/driver/vulkan/vk_core.cpp @@ -792,6 +792,9 @@ static const VkExtensionProperties supportedExtensions[] = { VK_KHR_XLIB_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_SPEC_VERSION, }, #endif + { + VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME, VK_NV_DEDICATED_ALLOCATION_SPEC_VERSION, + }, { VK_NV_EXTERNAL_MEMORY_EXTENSION_NAME, VK_NV_EXTERNAL_MEMORY_SPEC_VERSION, }, diff --git a/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp index 85e1dcf36..2b0ad15f6 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp @@ -252,6 +252,34 @@ VkResult WrappedVulkan::vkAllocateMemory(VkDevice device, const VkMemoryAllocate ObjDisp(device)->DestroyBuffer(Unwrap(device), buf, NULL); } + VkDedicatedAllocationMemoryAllocateInfoNV unwrappedDedicated; + unwrappedDedicated.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV; + + VkGenericStruct *curStruct = (VkGenericStruct *)&info; + const void *next = info.pNext; + while(next) + { + const VkGenericStruct *nextStruct = (const VkGenericStruct *)next; + + // unwrap and replace the dedicated allocation struct in the chain + if(nextStruct->sType == VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV) + { + const VkDedicatedAllocationMemoryAllocateInfoNV *dedicated = + (const VkDedicatedAllocationMemoryAllocateInfoNV *)nextStruct; + unwrappedDedicated.pNext = nextStruct->pNext; + unwrappedDedicated.buffer = Unwrap(dedicated->buffer); + unwrappedDedicated.image = Unwrap(dedicated->image); + curStruct->pNext = (const VkGenericStruct *)&unwrappedDedicated; + curStruct = (VkGenericStruct *)&unwrappedDedicated; + } + else + { + break; + } + + next = nextStruct->pNext; + } + VkResult ret = ObjDisp(device)->AllocateMemory(Unwrap(device), &info, pAllocator, pMemory); // restore the memoryTypeIndex to the original, as that's what we want to serialise,