diff --git a/renderdoc/driver/vulkan/vk_core.cpp b/renderdoc/driver/vulkan/vk_core.cpp index 001725788..532a24f98 100644 --- a/renderdoc/driver/vulkan/vk_core.cpp +++ b/renderdoc/driver/vulkan/vk_core.cpp @@ -505,7 +505,7 @@ VkResult WrappedVulkan::vkCreateInstance( VkResult WrappedVulkan::vkDestroyInstance( VkInstance instance) { - dispatch_key key = get_dispatch_key(instance); + dispatch_key key = get_dispatch_key(instance); VkResult ret = ObjDisp(instance)->DestroyInstance(Unwrap(instance)); if(ret != VK_SUCCESS) @@ -516,9 +516,9 @@ VkResult WrappedVulkan::vkDestroyInstance( ObjDisp(instance)->DbgDestroyMsgCallback(Unwrap(instance), m_MsgCallback); } - GetResourceManager()->ReleaseCurrentResource(GetResID(instance)); + GetResourceManager()->ReleaseWrappedResource(instance); - destroy_dispatch_table(renderdoc_instance_table_map, key); + destroy_dispatch_table(renderdoc_instance_table_map, key); return VK_SUCCESS; } @@ -597,14 +597,24 @@ VkResult WrappedVulkan::vkEnumeratePhysicalDevices( for(uint32_t i=0; i < count; i++) { - GetResourceManager()->WrapResource(devices[i]); - - if(m_State >= WRITING) + // it's perfectly valid for enumerate type functions to return the same handle + // each time. If that happens, we will already have a wrapper created so just + // return the wrapped object to the user and do nothing else + if(GetResourceManager()->HasWrapper(RealVkRes((void *)devices[i]))) { - SCOPED_SERIALISE_CONTEXT(ENUM_PHYSICALS); - Serialise_vkEnumeratePhysicalDevices(instance, &i, &devices[i]); + devices[i] = (VkPhysicalDevice)GetResourceManager()->GetWrapper(RealVkRes((void *)devices[i])); + } + else + { + GetResourceManager()->WrapResource(devices[i]); - m_InstanceRecord->AddChunk(scope.Get()); + if(m_State >= WRITING) + { + SCOPED_SERIALISE_CONTEXT(ENUM_PHYSICALS); + Serialise_vkEnumeratePhysicalDevices(instance, &i, &devices[i]); + + m_InstanceRecord->AddChunk(scope.Get()); + } } } @@ -870,18 +880,19 @@ VkResult WrappedVulkan::vkCreateDevice( m_PhysicalReplayData[i].qFamilyIdx = qFamilyIdx; - vkr = ObjDisp(*pDevice)->GetDeviceQueue(Unwrap(*pDevice), qFamilyIdx, 0, &m_PhysicalReplayData[i].q); + // we call our own vkGetDeviceQueue so that its initialisation is properly serialised in case when + // the application fetches this queue it gets the same handle - the already wrapped one created + // here will be returned. + vkr = vkGetDeviceQueue(*pDevice, qFamilyIdx, 0, &m_PhysicalReplayData[i].q); RDCASSERT(vkr == VK_SUCCESS); - GetResourceManager()->WrapResource(m_PhysicalReplayData[i].q); - VkCmdPoolCreateInfo poolInfo = { VK_STRUCTURE_TYPE_CMD_POOL_CREATE_INFO, NULL, qFamilyIdx, VK_CMD_POOL_CREATE_RESET_COMMAND_BUFFER_BIT }; vkr = ObjDisp(*pDevice)->CreateCommandPool(Unwrap(*pDevice), &poolInfo, &m_PhysicalReplayData[i].cmdpool); RDCASSERT(vkr == VK_SUCCESS); GetResourceManager()->WrapResource(m_PhysicalReplayData[i].cmdpool); - VkCmdBufferCreateInfo cmdInfo = { VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO, NULL, m_PhysicalReplayData[i].cmdpool, VK_CMD_BUFFER_LEVEL_PRIMARY, 0 }; + VkCmdBufferCreateInfo cmdInfo = { VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO, NULL, Unwrap(m_PhysicalReplayData[i].cmdpool), VK_CMD_BUFFER_LEVEL_PRIMARY, 0 }; vkr = ObjDisp(*pDevice)->CreateCommandBuffer(Unwrap(*pDevice), &cmdInfo, &m_PhysicalReplayData[i].cmd); RDCASSERT(vkr == VK_SUCCESS); found = true; @@ -966,11 +977,11 @@ VkResult WrappedVulkan::vkDestroyDevice(VkDevice device) } } - dispatch_key key = get_dispatch_key(device); + dispatch_key key = get_dispatch_key(device); VkResult ret = ObjDisp(device)->DestroyDevice(device); - destroy_dispatch_table(renderdoc_device_table_map, key); + destroy_dispatch_table(renderdoc_device_table_map, key); - GetResourceManager()->ReleaseCurrentResource(GetResID(device)); + GetResourceManager()->ReleaseWrappedResource(device); return ret; } @@ -1064,29 +1075,27 @@ VkResult WrappedVulkan::vkGetImageMemoryRequirements( VkResult WrappedVulkan::vkGetGlobalExtensionProperties( const char* pLayerName, - uint32_t* pCount, - VkExtensionProperties* pProperties) + uint32_t* pCount, + VkExtensionProperties* pProperties) { - if(pLayerName == NULL) - { - if(pCount) *pCount = uint32_t(globalExts.extensions.size()); - if(pProperties) - memcpy(pProperties, &globalExts.extensions[0], sizeof(VkExtensionProperties)*globalExts.extensions.size()); - return VK_SUCCESS; - } + if(pLayerName == NULL) + { + if(pCount) *pCount = uint32_t(globalExts.extensions.size()); + if(pProperties) + memcpy(pProperties, &globalExts.extensions[0], sizeof(VkExtensionProperties)*globalExts.extensions.size()); + return VK_SUCCESS; + } - return util_GetExtensionProperties(0, NULL, pCount, pProperties); + return util_GetExtensionProperties(0, NULL, pCount, pProperties); } #define DESTROY_IMPL(type, func) \ VkResult WrappedVulkan::vk ## func(VkDevice device, type obj) \ { \ - WrappedVkNonDispRes *wrapped = (WrappedVkNonDispRes *)GetWrapped(obj); \ - GetResourceManager()->MarkCleanResource(wrapped->id); \ - GetResourceManager()->ReleaseCurrentResource(wrapped->id); \ - if(wrapped->record) wrapped->record->Delete(GetResourceManager()); \ - if(m_ImageInfo.find(wrapped->id) != m_ImageInfo.end()) m_ImageInfo.erase(wrapped->id); \ - return ObjDisp(device)->func(Unwrap(device), wrapped->real.As()); \ + if(m_ImageInfo.find(GetResID(obj)) != m_ImageInfo.end()) m_ImageInfo.erase(GetResID(obj)); \ + VkResult ret = ObjDisp(device)->func(Unwrap(device), Unwrap(obj)); \ + GetResourceManager()->ReleaseWrappedResource(obj); \ + return ret; \ } DESTROY_IMPL(VkBuffer, DestroyBuffer) @@ -1159,27 +1168,37 @@ VkResult WrappedVulkan::vkGetDeviceQueue( if(ret == VK_SUCCESS) { - ResourceId id = GetResourceManager()->WrapResource(*pQueue); - - if(m_State >= WRITING) + // it's perfectly valid for enumerate type functions to return the same handle + // each time. If that happens, we will already have a wrapper created so just + // return the wrapped object to the user and do nothing else + if(GetResourceManager()->HasWrapper(RealVkRes((void *)*pQueue))) { - Chunk *chunk = NULL; - - { - SCOPED_SERIALISE_CONTEXT(GET_DEVICE_QUEUE); - Serialise_vkGetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue); - - chunk = scope.Get(); - } - - VkResourceRecord *record = GetResourceManager()->AddResourceRecord(*pQueue); - RDCASSERT(record); - - record->AddChunk(chunk); + *pQueue = (VkQueue)GetResourceManager()->GetWrapper(RealVkRes((void *)*pQueue)); } else { - GetResourceManager()->AddLiveResource(id, *pQueue); + ResourceId id = GetResourceManager()->WrapResource(*pQueue); + + if(m_State >= WRITING) + { + Chunk *chunk = NULL; + + { + SCOPED_SERIALISE_CONTEXT(GET_DEVICE_QUEUE); + Serialise_vkGetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue); + + chunk = scope.Get(); + } + + VkResourceRecord *record = GetResourceManager()->AddResourceRecord(*pQueue); + RDCASSERT(record); + + record->AddChunk(chunk); + } + else + { + GetResourceManager()->AddLiveResource(id, *pQueue); + } } } @@ -1663,11 +1682,11 @@ VkResult WrappedVulkan::vkFreeMemory( // we just need to clean up after ourselves on replay WrappedVkNonDispRes *wrapped = (WrappedVkNonDispRes *)GetWrapped(mem); m_MemoryInfo.erase(wrapped->id); - GetResourceManager()->MarkCleanResource(wrapped->id); - if(wrapped->record) wrapped->record->Delete(GetResourceManager()); - GetResourceManager()->ReleaseCurrentResource(wrapped->id); + VkResult res = ObjDisp(device)->FreeMemory(Unwrap(device), wrapped->real.As()); - return ObjDisp(device)->FreeMemory(Unwrap(device), wrapped->real.As()); + GetResourceManager()->ReleaseWrappedResource(mem); + + return res; } VkResult WrappedVulkan::vkMapMemory( @@ -3568,7 +3587,7 @@ VkResult WrappedVulkan::vkFreeDescriptorSets( VkResourceRecord *record = GetResourceManager()->GetResourceRecord(id); if(record) record->Delete(GetResourceManager()); - GetResourceManager()->ReleaseCurrentResource(id); + GetResourceManager()->ReleaseWrappedResource(pDescriptorSets[i]); } } @@ -5853,8 +5872,8 @@ bool WrappedVulkan::Serialise_BeginCaptureFrame(bool applyInitialState) ObjDisp(cmd)->BeginCommandBuffer(Unwrap(cmd), &beginInfo); RDCASSERT(vkr == VK_SUCCESS); - VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; - VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; + VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; + VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; if(!imgTransitions.empty()) { @@ -5866,8 +5885,7 @@ bool WrappedVulkan::Serialise_BeginCaptureFrame(bool applyInitialState) vkr = ObjDisp(cmd)->EndCommandBuffer(Unwrap(cmd)); RDCASSERT(vkr == VK_SUCCESS); - VkCmdBuffer unwrapped = Unwrap(cmd); - vkr = ObjDisp(q)->QueueSubmit(Unwrap(q), 1, &unwrapped, VK_NULL_HANDLE); + vkr = ObjDisp(q)->QueueSubmit(Unwrap(q), 1, UnwrapPtr(cmd), VK_NULL_HANDLE); RDCASSERT(vkr == VK_SUCCESS); // VKTODOMED while we're reusing cmd buffer, we have to ensure this one // is done before continuing @@ -6547,35 +6565,44 @@ VkResult WrappedVulkan::vkGetSwapChainInfoWSI( for(size_t i=0; i < numImages; i++) { - ResourceId id = GetResourceManager()->WrapResource(images[i].image); - - if(m_State >= WRITING) + // these were all wrapped and serialised on swapchain create - we just have to + // return the wrapped image in that case + if(GetResourceManager()->HasWrapper(RealVkRes(images[i].image.handle))) { - Chunk *chunk = NULL; - - { - SCOPED_SERIALISE_CONTEXT(PRESENT_IMAGE); - Serialise_vkGetSwapChainInfoWSI(device, swapChain, infoType, &i, (void *)&images[i]); - - chunk = scope.Get(); - } - - VkResourceRecord *record = GetResourceManager()->AddResourceRecord(images[i].image); - record->AddChunk(chunk); - - // we invert the usual scheme - we make the swapchain record take parent refs - // on these images, so that we can just ref the swapchain on present and pull - // in all the images - VkResourceRecord *swaprecord = GetRecord(swapChain); - - swaprecord->AddParent(record); - // decrement refcount on swap images, so that they are only ref'd from the swapchain - // (and will be deleted when it is deleted) - record->Delete(GetResourceManager()); + images[i].image = (VkImage)(uint64_t)GetResourceManager()->GetWrapper(RealVkRes(images[i].image.handle)); } else { - GetResourceManager()->AddLiveResource(id, images[i].image); + ResourceId id = GetResourceManager()->WrapResource(images[i].image); + + if(m_State >= WRITING) + { + Chunk *chunk = NULL; + + { + SCOPED_SERIALISE_CONTEXT(PRESENT_IMAGE); + Serialise_vkGetSwapChainInfoWSI(device, swapChain, infoType, &i, (void *)&images[i]); + + chunk = scope.Get(); + } + + VkResourceRecord *record = GetResourceManager()->AddResourceRecord(images[i].image); + record->AddChunk(chunk); + + // we invert the usual scheme - we make the swapchain record take parent refs + // on these images, so that we can just ref the swapchain on present and pull + // in all the images + VkResourceRecord *swaprecord = GetRecord(swapChain); + + swaprecord->AddParent(record); + // decrement refcount on swap images, so that they are only ref'd from the swapchain + // (and will be deleted when it is deleted) + record->Delete(GetResourceManager()); + } + else + { + GetResourceManager()->AddLiveResource(id, images[i].image); + } } } } @@ -7161,8 +7188,7 @@ VkResult WrappedVulkan::vkQueuePresentWSI( vkr = vt->EndCommandBuffer(Unwrap(cmd)); RDCASSERT(vkr == VK_SUCCESS); - VkCmdBuffer unwrapped = Unwrap(cmd); - vkr = vt->QueueSubmit(Unwrap(q), 1, &unwrapped, VK_NULL_HANDLE); + vkr = vt->QueueSubmit(Unwrap(q), 1, UnwrapPtr(cmd), VK_NULL_HANDLE); RDCASSERT(vkr == VK_SUCCESS); // wait queue idle @@ -7484,8 +7510,7 @@ bool WrappedVulkan::Prepare_InitialState(WrappedVkRes *res) vkr = ObjDisp(d)->EndCommandBuffer(Unwrap(cmd)); RDCASSERT(vkr == VK_SUCCESS); - VkCmdBuffer unwrapped = Unwrap(cmd); - vkr = ObjDisp(d)->QueueSubmit(Unwrap(q), 1, &unwrapped, VK_NULL_HANDLE); + vkr = ObjDisp(d)->QueueSubmit(Unwrap(q), 1, UnwrapPtr(cmd), VK_NULL_HANDLE); RDCASSERT(vkr == VK_SUCCESS); // VKTODOMED would be nice to store a fence too at this point @@ -7774,8 +7799,7 @@ void WrappedVulkan::Apply_InitialState(WrappedVkRes *live, VulkanResourceManager vkr = ObjDisp(cmd)->EndCommandBuffer(Unwrap(cmd)); RDCASSERT(vkr == VK_SUCCESS); - VkCmdBuffer unwrapped = Unwrap(cmd); - vkr = ObjDisp(q)->QueueSubmit(Unwrap(q), 1, &unwrapped, VK_NULL_HANDLE); + vkr = ObjDisp(q)->QueueSubmit(Unwrap(q), 1, UnwrapPtr(cmd), VK_NULL_HANDLE); RDCASSERT(vkr == VK_SUCCESS); // VKTODOMED would be nice to store a fence too at this point @@ -8179,8 +8203,7 @@ void WrappedVulkan::ReplayLog(uint32_t frameID, uint32_t startEventID, uint32_t vkr = ObjDisp(cmd)->EndCommandBuffer(Unwrap(cmd)); RDCASSERT(vkr == VK_SUCCESS); - VkCmdBuffer unwrapped = Unwrap(cmd); - vkr = ObjDisp(q)->QueueSubmit(q, 1, &unwrapped, VK_NULL_HANDLE); + vkr = ObjDisp(q)->QueueSubmit(q, 1, UnwrapPtr(cmd), VK_NULL_HANDLE); RDCASSERT(vkr == VK_SUCCESS); // VKTODOMED while we're reusing cmd buffer, we have to ensure this one // is done before continuing diff --git a/renderdoc/driver/vulkan/vk_debug.cpp b/renderdoc/driver/vulkan/vk_debug.cpp index 156ed1529..1d04d690d 100644 --- a/renderdoc/driver/vulkan/vk_debug.cpp +++ b/renderdoc/driver/vulkan/vk_debug.cpp @@ -114,7 +114,7 @@ void VulkanDebugManager::UBO::Create(WrappedVulkan *driver, VkDevice dev, VkDevi VkBufferViewCreateInfo bufviewInfo = { VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO, NULL, - buf, VK_BUFFER_VIEW_TYPE_RAW, + Unwrap(buf), VK_BUFFER_VIEW_TYPE_RAW, VK_FORMAT_UNDEFINED, 0, size, }; @@ -129,25 +129,25 @@ void VulkanDebugManager::UBO::Destroy(const VkLayerDispatchTable *vt, VkDevice d VkResult vkr = VK_SUCCESS; if(view != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(view)); vkr = vt->DestroyBufferView(Unwrap(dev), Unwrap(view)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(view); view = VK_NULL_HANDLE; } if(buf != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(buf)); vkr = vt->DestroyBuffer(Unwrap(dev), Unwrap(buf)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(buf); buf = VK_NULL_HANDLE; } if(mem != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(mem)); vkr = vt->FreeMemory(Unwrap(dev), Unwrap(mem)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(mem); mem = VK_NULL_HANDLE; } } @@ -224,6 +224,8 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev, VkIm vkr = vt->CreateSampler(Unwrap(dev), &sampInfo, &m_LinearSampler); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->WrapResource(m_LinearSampler); + sampInfo.minFilter = VK_TEX_FILTER_NEAREST; sampInfo.magFilter = VK_TEX_FILTER_NEAREST; sampInfo.mipMode = VK_TEX_MIPMAP_MODE_NEAREST; @@ -231,11 +233,15 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev, VkIm vkr = vt->CreateSampler(Unwrap(dev), &sampInfo, &m_PointSampler); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->WrapResource(m_PointSampler); + VkPipelineCacheCreateInfo cacheInfo = { VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO, NULL, 0, NULL, 0 }; vkr = vt->CreatePipelineCache(Unwrap(dev), &cacheInfo, &m_PipelineCache); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->WrapResource(m_PipelineCache); + { // VKTODOLOW not sure if these stage flags VK_SHADER_STAGE_... work yet? VkDescriptorSetLayoutBinding layoutBinding[] = { @@ -249,6 +255,8 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev, VkIm vkr = vt->CreateDescriptorSetLayout(Unwrap(dev), &descsetLayoutInfo, &m_CheckerboardDescSetLayout); RDCASSERT(vkr == VK_SUCCESS); + + VKMGR()->WrapResource(m_CheckerboardDescSetLayout); } { @@ -264,6 +272,8 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev, VkIm vkr = vt->CreateDescriptorSetLayout(Unwrap(dev), &descsetLayoutInfo, &m_TexDisplayDescSetLayout); RDCASSERT(vkr == VK_SUCCESS); + + VKMGR()->WrapResource(m_TexDisplayDescSetLayout); } { @@ -281,27 +291,35 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev, VkIm vkr = vt->CreateDescriptorSetLayout(Unwrap(dev), &descsetLayoutInfo, &m_TextDescSetLayout); RDCASSERT(vkr == VK_SUCCESS); + + VKMGR()->WrapResource(m_TextDescSetLayout); } VkPipelineLayoutCreateInfo pipeLayoutInfo = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, NULL, - 1, &m_TexDisplayDescSetLayout, + 1, UnwrapPtr(m_TexDisplayDescSetLayout), 0, NULL, // push constant ranges }; vkr = vt->CreatePipelineLayout(Unwrap(dev), &pipeLayoutInfo, &m_TexDisplayPipeLayout); RDCASSERT(vkr == VK_SUCCESS); - pipeLayoutInfo.pSetLayouts = &m_CheckerboardDescSetLayout; + VKMGR()->WrapResource(m_TexDisplayPipeLayout); + + pipeLayoutInfo.pSetLayouts = UnwrapPtr(m_CheckerboardDescSetLayout); vkr = vt->CreatePipelineLayout(Unwrap(dev), &pipeLayoutInfo, &m_CheckerboardPipeLayout); RDCASSERT(vkr == VK_SUCCESS); - pipeLayoutInfo.pSetLayouts = &m_TextDescSetLayout; + VKMGR()->WrapResource(m_CheckerboardPipeLayout); + + pipeLayoutInfo.pSetLayouts = UnwrapPtr(m_TextDescSetLayout); vkr = vt->CreatePipelineLayout(Unwrap(dev), &pipeLayoutInfo, &m_TextPipeLayout); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->WrapResource(m_TextPipeLayout); + VkDescriptorTypeCount descPoolTypes[] = { { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1024, }, { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1024, }, @@ -309,34 +327,42 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev, VkIm VkDescriptorPoolCreateInfo descpoolInfo = { VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, NULL, - ARRAY_COUNT(descPoolTypes), &descPoolTypes[0], + ARRAY_COUNT(descPoolTypes), &descPoolTypes[0], }; vkr = vt->CreateDescriptorPool(Unwrap(dev), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 3, &descpoolInfo, &m_DescriptorPool); RDCASSERT(vkr == VK_SUCCESS); + + VKMGR()->WrapResource(m_DescriptorPool); uint32_t count; - vkr = vt->AllocDescriptorSets(Unwrap(dev), m_DescriptorPool, VK_DESCRIPTOR_SET_USAGE_STATIC, 1, - &m_CheckerboardDescSetLayout, &m_CheckerboardDescSet, &count); + vkr = vt->AllocDescriptorSets(Unwrap(dev), Unwrap(m_DescriptorPool), VK_DESCRIPTOR_SET_USAGE_STATIC, 1, + UnwrapPtr(m_CheckerboardDescSetLayout), &m_CheckerboardDescSet, &count); RDCASSERT(vkr == VK_SUCCESS); + + VKMGR()->WrapResource(m_CheckerboardDescSet); - vkr = vt->AllocDescriptorSets(Unwrap(dev), m_DescriptorPool, VK_DESCRIPTOR_SET_USAGE_STATIC, 1, - &m_TexDisplayDescSetLayout, &m_TexDisplayDescSet, &count); + vkr = vt->AllocDescriptorSets(Unwrap(dev), Unwrap(m_DescriptorPool), VK_DESCRIPTOR_SET_USAGE_STATIC, 1, + UnwrapPtr(m_TexDisplayDescSetLayout), &m_TexDisplayDescSet, &count); RDCASSERT(vkr == VK_SUCCESS); + + VKMGR()->WrapResource(m_TexDisplayDescSet); - vkr = vt->AllocDescriptorSets(Unwrap(dev), m_DescriptorPool, VK_DESCRIPTOR_SET_USAGE_STATIC, 1, - &m_TextDescSetLayout, &m_TextDescSet, &count); + vkr = vt->AllocDescriptorSets(Unwrap(dev), Unwrap(m_DescriptorPool), VK_DESCRIPTOR_SET_USAGE_STATIC, 1, + UnwrapPtr(m_TextDescSetLayout), &m_TextDescSet, &count); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->WrapResource(m_TextDescSet); + m_CheckerboardUBO.Create(driver, dev, 128); m_TexDisplayUBO.Create(driver, dev, 128); RDCCOMPILE_ASSERT(sizeof(displayuniforms) <= 128, "tex display size"); - m_TextGeneralUBO.Create(driver, Unwrap(dev), 128); + m_TextGeneralUBO.Create(driver, dev, 128); RDCCOMPILE_ASSERT(sizeof(fontuniforms) <= 128, "font uniforms size"); - m_TextStringUBO.Create(driver, Unwrap(dev), 4096); + m_TextStringUBO.Create(driver, dev, 4096); RDCCOMPILE_ASSERT(sizeof(stringdata) <= 4096, "font uniforms size"); VkDynamicRasterStateCreateInfo rsInfo = { @@ -346,6 +372,8 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev, VkIm vkr = vt->CreateDynamicRasterState(Unwrap(dev), &rsInfo, &m_DynamicRSState); RDCASSERT(vkr == VK_SUCCESS); + + VKMGR()->WrapResource(m_DynamicRSState); VkDynamicColorBlendStateCreateInfo cbInfo = { VK_STRUCTURE_TYPE_DYNAMIC_COLOR_BLEND_STATE_CREATE_INFO, NULL, @@ -354,6 +382,8 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev, VkIm vkr = vt->CreateDynamicColorBlendState(Unwrap(dev), &cbInfo, &m_DynamicCBStateWhite); RDCASSERT(vkr == VK_SUCCESS); + + VKMGR()->WrapResource(m_DynamicCBStateWhite); VkDynamicDepthStencilStateCreateInfo dsInfo = { VK_STRUCTURE_TYPE_DYNAMIC_DEPTH_STENCIL_STATE_CREATE_INFO, NULL, @@ -362,6 +392,8 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev, VkIm vkr = vt->CreateDynamicDepthStencilState(Unwrap(dev), &dsInfo, &m_DynamicDSStateDisabled); RDCASSERT(vkr == VK_SUCCESS); + + VKMGR()->WrapResource(m_DynamicDSStateDisabled); string shaderSources[] = { GetEmbeddedResource(blitvs_spv), @@ -393,18 +425,22 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev, VkIm vkr = vt->CreateShaderModule(Unwrap(dev), &modinfo, &module[i]); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->WrapResource(module[i]); + VkShaderCreateInfo shadinfo = { VK_STRUCTURE_TYPE_SHADER_CREATE_INFO, NULL, - module[i], "main", 0, + Unwrap(module[i]), "main", 0, }; vkr = vt->CreateShader(Unwrap(dev), &shadinfo, &shader[i]); RDCASSERT(vkr == VK_SUCCESS); + + VKMGR()->WrapResource(shader[i]); } VkPipelineShaderStageCreateInfo stages[2] = { - { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, NULL, VK_SHADER_STAGE_VERTEX, shader[0], NULL }, - { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, NULL, VK_SHADER_STAGE_FRAGMENT, shader[1], NULL }, + { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, NULL, VK_SHADER_STAGE_VERTEX, VK_NULL_HANDLE, NULL }, + { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, NULL, VK_SHADER_STAGE_FRAGMENT, VK_NULL_HANDLE, NULL }, }; VkPipelineInputAssemblyStateCreateInfo ia = { @@ -459,50 +495,61 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev, VkIm &ds, &cb, 0, // flags - m_CheckerboardPipeLayout, + Unwrap(m_CheckerboardPipeLayout), VK_NULL_HANDLE, // render pass 0, // sub pass VK_NULL_HANDLE, // base pipeline handle 0, // base pipeline index }; - stages[0].shader = shader[BLITVS]; - stages[1].shader = shader[CHECKERBOARDFS]; + stages[0].shader = Unwrap(shader[BLITVS]); + stages[1].shader = Unwrap(shader[CHECKERBOARDFS]); - vkr = vt->CreateGraphicsPipelines(Unwrap(dev), m_PipelineCache, 1, &pipeInfo, &m_CheckerboardPipeline); + vkr = vt->CreateGraphicsPipelines(Unwrap(dev), Unwrap(m_PipelineCache), 1, &pipeInfo, &m_CheckerboardPipeline); RDCASSERT(vkr == VK_SUCCESS); - stages[1].shader = shader[TEXDISPLAYFS]; + VKMGR()->WrapResource(m_CheckerboardPipeline); + + stages[0].shader = Unwrap(shader[BLITVS]); + stages[1].shader = Unwrap(shader[TEXDISPLAYFS]); - pipeInfo.layout = m_TexDisplayPipeLayout; + pipeInfo.layout = Unwrap(m_TexDisplayPipeLayout); - vkr = vt->CreateGraphicsPipelines(Unwrap(dev), m_PipelineCache, 1, &pipeInfo, &m_TexDisplayPipeline); + vkr = vt->CreateGraphicsPipelines(Unwrap(dev), Unwrap(m_PipelineCache), 1, &pipeInfo, &m_TexDisplayPipeline); RDCASSERT(vkr == VK_SUCCESS); + + VKMGR()->WrapResource(m_TexDisplayPipeline); attState.blendEnable = true; attState.srcBlendColor = VK_BLEND_SRC_ALPHA; attState.destBlendColor = VK_BLEND_ONE_MINUS_SRC_ALPHA; - vkr = vt->CreateGraphicsPipelines(Unwrap(dev), m_PipelineCache, 1, &pipeInfo, &m_TexDisplayBlendPipeline); + vkr = vt->CreateGraphicsPipelines(Unwrap(dev), Unwrap(m_PipelineCache), 1, &pipeInfo, &m_TexDisplayBlendPipeline); RDCASSERT(vkr == VK_SUCCESS); + + VKMGR()->WrapResource(m_TexDisplayBlendPipeline); ia.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; - stages[0].shader = shader[TEXTVS]; - stages[1].shader = shader[TEXTFS]; + stages[0].shader = Unwrap(shader[TEXTVS]); + stages[1].shader = Unwrap(shader[TEXTFS]); - pipeInfo.layout = m_TextPipeLayout; + pipeInfo.layout = Unwrap(m_TextPipeLayout); - vkr = vt->CreateGraphicsPipelines(Unwrap(dev), m_PipelineCache, 1, &pipeInfo, &m_TextPipeline); + vkr = vt->CreateGraphicsPipelines(Unwrap(dev), Unwrap(m_PipelineCache), 1, &pipeInfo, &m_TextPipeline); RDCASSERT(vkr == VK_SUCCESS); + + VKMGR()->WrapResource(m_TextPipeline); for(size_t i=0; i < ARRAY_COUNT(module); i++) { - vkr = vt->DestroyShader(Unwrap(dev), shader[i]); + vkr = vt->DestroyShader(Unwrap(dev), Unwrap(shader[i])); RDCASSERT(vkr == VK_SUCCESS); - - vkr = vt->DestroyShaderModule(Unwrap(dev), module[i]); + VKMGR()->ReleaseWrappedResource(shader[i]); + + vkr = vt->DestroyShaderModule(Unwrap(dev), Unwrap(module[i])); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(module[i]); } { @@ -551,14 +598,16 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev, VkIm { vkr = vt->CreateImage(Unwrap(dev), &imInfo, &m_TextAtlas); RDCASSERT(vkr == VK_SUCCESS); + + VKMGR()->WrapResource(m_TextAtlas); VkMemoryRequirements mrq; - vkr = vt->GetImageMemoryRequirements(Unwrap(dev), m_TextAtlas, &mrq); + vkr = vt->GetImageMemoryRequirements(Unwrap(dev), Unwrap(m_TextAtlas), &mrq); RDCASSERT(vkr == VK_SUCCESS); VkImageSubresource subr = { VK_IMAGE_ASPECT_COLOR, 0, 0 }; VkSubresourceLayout layout = { 0 }; - vt->GetImageSubresourceLayout(Unwrap(dev), m_TextAtlas, &subr, &layout); + vt->GetImageSubresourceLayout(Unwrap(dev), Unwrap(m_TextAtlas), &subr, &layout); // allocate readback memory VkMemoryAllocInfo allocInfo = { @@ -568,12 +617,15 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev, VkIm vkr = vt->AllocMemory(Unwrap(dev), &allocInfo, &m_TextAtlasMem); RDCASSERT(vkr == VK_SUCCESS); - vkr = vt->BindImageMemory(Unwrap(dev), m_TextAtlas, m_TextAtlasMem, 0); + + VKMGR()->WrapResource(m_TextAtlasMem); + + vkr = vt->BindImageMemory(Unwrap(dev), Unwrap(m_TextAtlas), Unwrap(m_TextAtlasMem), 0); RDCASSERT(vkr == VK_SUCCESS); VkImageViewCreateInfo viewInfo = { VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, NULL, - m_TextAtlas, VK_IMAGE_VIEW_TYPE_2D, + Unwrap(m_TextAtlas), VK_IMAGE_VIEW_TYPE_2D, imInfo.format, { VK_CHANNEL_SWIZZLE_R, VK_CHANNEL_SWIZZLE_G, VK_CHANNEL_SWIZZLE_B, VK_CHANNEL_SWIZZLE_A }, { VK_IMAGE_ASPECT_COLOR, 0, 1, 0, 1, } @@ -581,8 +633,10 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev, VkIm // VKTODOMED used for texture display, but eventually will have to be created on the fly // for whichever image we're viewing (and cached), not specifically created here. - VkResult vkr = vt->CreateImageView(Unwrap(dev), &viewInfo, &m_TextAtlasView); + vkr = vt->CreateImageView(Unwrap(dev), &viewInfo, &m_TextAtlasView); RDCASSERT(vkr == VK_SUCCESS); + + VKMGR()->WrapResource(m_TextAtlasView); // need to transition image into valid state, then upload VkCmdBuffer cmd = driver->GetCmd(); @@ -590,32 +644,32 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev, VkIm VkCmdBufferBeginInfo beginInfo = { VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO, NULL, VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT | VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT }; - vkr = vt->ResetCommandBuffer(cmd, 0); + vkr = vt->ResetCommandBuffer(Unwrap(cmd), 0); RDCASSERT(vkr == VK_SUCCESS); - vkr = vt->BeginCommandBuffer(cmd, &beginInfo); + vkr = vt->BeginCommandBuffer(Unwrap(cmd), &beginInfo); RDCASSERT(vkr == VK_SUCCESS); VkImageMemoryBarrier trans = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, NULL, 0, 0, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, - 0, 0, m_TextAtlas, + 0, 0, Unwrap(m_TextAtlas), { VK_IMAGE_ASPECT_COLOR, 0, 1, 0, 1 } }; void *barrier = (void *)&trans; - vt->CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, false, 1, &barrier); + vt->CmdPipelineBarrier(Unwrap(cmd), VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, false, 1, &barrier); - vt->EndCommandBuffer(cmd); + vt->EndCommandBuffer(Unwrap(cmd)); - vt->QueueSubmit(q, 1, &cmd, VK_NULL_HANDLE); + vt->QueueSubmit(Unwrap(q), 1, UnwrapPtr(cmd), VK_NULL_HANDLE); // VKTODOMED ideally all the commands from Bind to Flip would be recorded // into a single command buffer and we can just have several allocated // ring-buffer style - vt->QueueWaitIdle(q); + vt->QueueWaitIdle(Unwrap(q)); byte *pData = NULL; - vkr = vt->MapMemory(Unwrap(dev), m_TextAtlasMem, 0, 0, 0, (void **)&pData); + vkr = vt->MapMemory(Unwrap(dev), Unwrap(m_TextAtlasMem), 0, 0, 0, (void **)&pData); RDCASSERT(vkr == VK_SUCCESS); RDCASSERT(pData != NULL); @@ -627,7 +681,7 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev, VkIm buf += width; } - vkr = vt->UnmapMemory(Unwrap(dev), m_TextAtlasMem); + vkr = vt->UnmapMemory(Unwrap(dev), Unwrap(m_TextAtlasMem)); RDCASSERT(vkr == VK_SUCCESS); } @@ -654,51 +708,51 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver, VkDevice dev, VkIm RDCEraseEl(desc); // checkerboard - desc[0].bufferView = m_CheckerboardUBO.view; + desc[0].bufferView = Unwrap(m_CheckerboardUBO.view); // tex display - desc[1].bufferView = m_TexDisplayUBO.view; + desc[1].bufferView = Unwrap(m_TexDisplayUBO.view); desc[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL; - desc[2].imageView = m_FakeBBImView; - desc[2].sampler = m_LinearSampler; + desc[2].imageView = Unwrap(m_FakeBBImView); + desc[2].sampler = Unwrap(m_LinearSampler); // text - desc[3].bufferView = m_TextGeneralUBO.view; - desc[4].bufferView = m_TextGlyphUBO.view; - desc[5].bufferView = m_TextStringUBO.view; + desc[3].bufferView = Unwrap(m_TextGeneralUBO.view); + desc[4].bufferView = Unwrap(m_TextGlyphUBO.view); + desc[5].bufferView = Unwrap(m_TextStringUBO.view); desc[6].imageLayout = VK_IMAGE_LAYOUT_GENERAL; - desc[6].imageView = m_TextAtlasView; - desc[6].sampler = m_LinearSampler; + desc[6].imageView = Unwrap(m_TextAtlasView); + desc[6].sampler = Unwrap(m_LinearSampler); VkWriteDescriptorSet writeSet[] = { { VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, NULL, - m_CheckerboardDescSet, 0, 0, 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &desc[0] + Unwrap(m_TextDescSet), 3, 0, 1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, &desc[6] }, { VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, NULL, - m_TexDisplayDescSet, 0, 0, 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &desc[1] + Unwrap(m_CheckerboardDescSet), 0, 0, 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &desc[0] }, { VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, NULL, - m_TextDescSet, 0, 0, 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &desc[3] + Unwrap(m_TexDisplayDescSet), 0, 0, 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &desc[1] }, { VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, NULL, - m_TextDescSet, 1, 0, 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &desc[4] + Unwrap(m_TextDescSet), 0, 0, 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &desc[3] }, { VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, NULL, - m_TextDescSet, 2, 0, 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &desc[5] + Unwrap(m_TextDescSet), 1, 0, 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &desc[4] }, { VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, NULL, - m_TextDescSet, 3, 0, 1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, &desc[6] + Unwrap(m_TextDescSet), 2, 0, 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &desc[5] }, // this one is last so that we can skip it if we don't have m_FakeBBImView { VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, NULL, - m_TexDisplayDescSet, 1, 0, 1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, &desc[2] + Unwrap(m_TexDisplayDescSet), 1, 0, 1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, &desc[2] }, }; @@ -719,107 +773,107 @@ VulkanDebugManager::~VulkanDebugManager() if(m_PipelineCache != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_PipelineCache)); vkr = vt->DestroyPipelineCache(Unwrap(dev), Unwrap(m_PipelineCache)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_PipelineCache); } if(m_DescriptorPool != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_DescriptorPool)); vkr = vt->DestroyDescriptorPool(Unwrap(dev), Unwrap(m_DescriptorPool)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_DescriptorPool); } if(m_DynamicCBStateWhite != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_DynamicCBStateWhite)); vkr = vt->DestroyDynamicColorBlendState(Unwrap(dev), Unwrap(m_DynamicCBStateWhite)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_DynamicCBStateWhite); } if(m_DynamicRSState != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_DynamicRSState)); vkr = vt->DestroyDynamicRasterState(Unwrap(dev), Unwrap(m_DynamicRSState)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_DynamicRSState); } if(m_DynamicDSStateDisabled != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_DynamicDSStateDisabled)); vkr = vt->DestroyDynamicDepthStencilState(Unwrap(dev), Unwrap(m_DynamicDSStateDisabled)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_DynamicDSStateDisabled); } if(m_LinearSampler != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_LinearSampler)); vkr = vt->DestroySampler(Unwrap(dev), Unwrap(m_LinearSampler)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_LinearSampler); } if(m_PointSampler != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_PointSampler)); vkr = vt->DestroySampler(Unwrap(dev), Unwrap(m_PointSampler)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_PointSampler); } if(m_FakeBBImView != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_FakeBBImView)); vkr = vt->DestroyImageView(Unwrap(dev), Unwrap(m_FakeBBImView)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_FakeBBImView); } if(m_CheckerboardDescSetLayout != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_CheckerboardDescSetLayout)); vkr = vt->DestroyDescriptorSetLayout(Unwrap(dev), Unwrap(m_CheckerboardDescSetLayout)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_CheckerboardDescSetLayout); } if(m_CheckerboardPipeLayout != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_CheckerboardPipeLayout)); vkr = vt->DestroyPipelineLayout(Unwrap(dev), Unwrap(m_CheckerboardPipeLayout)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_CheckerboardPipeLayout); } if(m_CheckerboardPipeline != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_CheckerboardPipeline)); vkr = vt->DestroyPipeline(Unwrap(dev), Unwrap(m_CheckerboardPipeline)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_CheckerboardPipeline); } if(m_TexDisplayDescSetLayout != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_TexDisplayDescSetLayout)); vkr = vt->DestroyDescriptorSetLayout(Unwrap(dev), Unwrap(m_TexDisplayDescSetLayout)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_TexDisplayDescSetLayout); } if(m_TexDisplayPipeLayout != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_TexDisplayPipeLayout)); vkr = vt->DestroyPipelineLayout(Unwrap(dev), Unwrap(m_TexDisplayPipeLayout)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_TexDisplayPipeLayout); } if(m_TexDisplayPipeline != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_TexDisplayPipeline)); vkr = vt->DestroyPipeline(Unwrap(dev), Unwrap(m_TexDisplayPipeline)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_TexDisplayPipeline); } if(m_TexDisplayBlendPipeline != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_TexDisplayBlendPipeline)); vkr = vt->DestroyPipeline(Unwrap(dev), Unwrap(m_TexDisplayBlendPipeline)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_TexDisplayBlendPipeline); } m_CheckerboardUBO.Destroy(vt, dev); @@ -827,23 +881,23 @@ VulkanDebugManager::~VulkanDebugManager() if(m_TextDescSetLayout != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_TextDescSetLayout)); vkr = vt->DestroyDescriptorSetLayout(Unwrap(dev), Unwrap(m_TextDescSetLayout)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_TextDescSetLayout); } if(m_TextPipeLayout != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_TextPipeLayout)); vkr = vt->DestroyPipelineLayout(Unwrap(dev), Unwrap(m_TextPipeLayout)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_TextPipeLayout); } if(m_TextPipeline != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_TextPipeline)); vkr = vt->DestroyPipeline(Unwrap(dev), Unwrap(m_TextPipeline)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_TextPipeline); } m_TextGeneralUBO.Destroy(vt, dev); @@ -852,23 +906,23 @@ VulkanDebugManager::~VulkanDebugManager() if(m_TextAtlasView != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_TextAtlasView)); vkr = vt->DestroyImageView(Unwrap(dev), Unwrap(m_TextAtlasView)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_TextAtlasView); } if(m_TextAtlas != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_TextAtlas)); vkr = vt->DestroyImage(Unwrap(dev), Unwrap(m_TextAtlas)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_TextAtlas); } if(m_TextAtlasMem != VK_NULL_HANDLE) { - VKMGR()->ReleaseCurrentResource(GetResID(m_TextAtlasMem)); vkr = vt->FreeMemory(Unwrap(dev), Unwrap(m_TextAtlasMem)); RDCASSERT(vkr == VK_SUCCESS); + VKMGR()->ReleaseWrappedResource(m_TextAtlasMem); } } @@ -937,8 +991,7 @@ void VulkanDebugManager::RenderTextInternal(const TextPrintState &textstate, flo // VKTODOMED will need a way to disable blend for other things vt->CmdBindPipeline(Unwrap(textstate.cmd), VK_PIPELINE_BIND_POINT_GRAPHICS, Unwrap(m_TextPipeline)); - VkDescriptorSet descset = Unwrap(m_TextDescSet); - vt->CmdBindDescriptorSets(Unwrap(textstate.cmd), VK_PIPELINE_BIND_POINT_GRAPHICS, Unwrap(m_TextPipeLayout), 0, 1, &descset, 0, NULL); + vt->CmdBindDescriptorSets(Unwrap(textstate.cmd), VK_PIPELINE_BIND_POINT_GRAPHICS, Unwrap(m_TextPipeLayout), 0, 1, UnwrapPtr(m_TextDescSet), 0, NULL); vt->CmdBindDynamicViewportState(Unwrap(textstate.cmd), Unwrap(textstate.vp)); vt->CmdBindDynamicRasterState(Unwrap(textstate.cmd), Unwrap(m_DynamicRSState)); @@ -953,8 +1006,7 @@ void VulkanDebugManager::RenderTextInternal(const TextPrintState &textstate, flo vt->EndCommandBuffer(Unwrap(textstate.cmd)); - VkCmdBuffer unwrapped = Unwrap(textstate.cmd); - vt->QueueSubmit(Unwrap(textstate.q), 1, &unwrapped, VK_NULL_HANDLE); + vt->QueueSubmit(Unwrap(textstate.q), 1, UnwrapPtr(textstate.cmd), VK_NULL_HANDLE); vt->QueueWaitIdle(Unwrap(textstate.q)); } \ No newline at end of file diff --git a/renderdoc/driver/vulkan/vk_info.cpp b/renderdoc/driver/vulkan/vk_info.cpp index 3a6836611..c8ac88831 100644 --- a/renderdoc/driver/vulkan/vk_info.cpp +++ b/renderdoc/driver/vulkan/vk_info.cpp @@ -72,31 +72,31 @@ void VulkanCreationInfo::Pipeline::Init(const VkGraphicsPipelineCreateInfo* pCre viewportCount = pCreateInfo->pViewportState->viewportCount; // VkPipelineRasterStateCreateInfo - depthClipEnable = pCreateInfo->pRasterState->depthClipEnable ? true : false; - rasterizerDiscardEnable = pCreateInfo->pRasterState->rasterizerDiscardEnable ? true : false; - fillMode = pCreateInfo->pRasterState->fillMode; - cullMode = pCreateInfo->pRasterState->cullMode; - frontFace = pCreateInfo->pRasterState->frontFace; - + depthClipEnable = pCreateInfo->pRasterState->depthClipEnable ? true : false; + rasterizerDiscardEnable = pCreateInfo->pRasterState->rasterizerDiscardEnable ? true : false; + fillMode = pCreateInfo->pRasterState->fillMode; + cullMode = pCreateInfo->pRasterState->cullMode; + frontFace = pCreateInfo->pRasterState->frontFace; + // VkPipelineMultisampleStateCreateInfo - rasterSamples = pCreateInfo->pMultisampleState->rasterSamples; - sampleShadingEnable = pCreateInfo->pMultisampleState->sampleShadingEnable ? true : false; - minSampleShading = pCreateInfo->pMultisampleState->minSampleShading; - sampleMask = pCreateInfo->pMultisampleState->sampleMask; - + rasterSamples = pCreateInfo->pMultisampleState->rasterSamples; + sampleShadingEnable = pCreateInfo->pMultisampleState->sampleShadingEnable ? true : false; + minSampleShading = pCreateInfo->pMultisampleState->minSampleShading; + sampleMask = pCreateInfo->pMultisampleState->sampleMask; + // VkPipelineDepthStencilStateCreateInfo - depthTestEnable = pCreateInfo->pDepthStencilState->depthTestEnable ? true : false; - depthWriteEnable = pCreateInfo->pDepthStencilState->depthWriteEnable ? true : false; - depthCompareOp = pCreateInfo->pDepthStencilState->depthCompareOp; - depthBoundsEnable = pCreateInfo->pDepthStencilState->depthBoundsEnable ? true : false; - stencilTestEnable = pCreateInfo->pDepthStencilState->stencilTestEnable ? true : false; - front = pCreateInfo->pDepthStencilState->front; - back = pCreateInfo->pDepthStencilState->back; + depthTestEnable = pCreateInfo->pDepthStencilState->depthTestEnable ? true : false; + depthWriteEnable = pCreateInfo->pDepthStencilState->depthWriteEnable ? true : false; + depthCompareOp = pCreateInfo->pDepthStencilState->depthCompareOp; + depthBoundsEnable = pCreateInfo->pDepthStencilState->depthBoundsEnable ? true : false; + stencilTestEnable = pCreateInfo->pDepthStencilState->stencilTestEnable ? true : false; + front = pCreateInfo->pDepthStencilState->front; + back = pCreateInfo->pDepthStencilState->back; // VkPipelineColorBlendStateCreateInfo - alphaToCoverageEnable = pCreateInfo->pColorBlendState->alphaToCoverageEnable ? true : false; - logicOpEnable = pCreateInfo->pColorBlendState->logicOpEnable ? true : false; - logicOp = pCreateInfo->pColorBlendState->logicOp; + alphaToCoverageEnable = pCreateInfo->pColorBlendState->alphaToCoverageEnable ? true : false; + logicOpEnable = pCreateInfo->pColorBlendState->logicOpEnable ? true : false; + logicOp = pCreateInfo->pColorBlendState->logicOp; attachments.resize(pCreateInfo->pColorBlendState->attachmentCount); diff --git a/renderdoc/driver/vulkan/vk_info.h b/renderdoc/driver/vulkan/vk_info.h index 34f6b09a2..cfe6b388e 100644 --- a/renderdoc/driver/vulkan/vk_info.h +++ b/renderdoc/driver/vulkan/vk_info.h @@ -34,7 +34,7 @@ struct VulkanCreationInfo void Init(const VkGraphicsPipelineCreateInfo* pCreateInfo); // VkGraphicsPipelineCreateInfo - VkPipelineCreateFlags flags; + VkPipelineCreateFlags flags; // VkPipelineShaderStageCreateInfo ResourceId shaders[6]; @@ -68,31 +68,31 @@ struct VulkanCreationInfo uint32_t viewportCount; // VkPipelineRasterStateCreateInfo - bool depthClipEnable; - bool rasterizerDiscardEnable; - VkFillMode fillMode; - VkCullMode cullMode; - VkFrontFace frontFace; - + bool depthClipEnable; + bool rasterizerDiscardEnable; + VkFillMode fillMode; + VkCullMode cullMode; + VkFrontFace frontFace; + // VkPipelineMultisampleStateCreateInfo - uint32_t rasterSamples; - bool sampleShadingEnable; - float minSampleShading; - VkSampleMask sampleMask; - + uint32_t rasterSamples; + bool sampleShadingEnable; + float minSampleShading; + VkSampleMask sampleMask; + // VkPipelineDepthStencilStateCreateInfo - bool depthTestEnable; - bool depthWriteEnable; - VkCompareOp depthCompareOp; - bool depthBoundsEnable; - bool stencilTestEnable; - VkStencilOpState front; - VkStencilOpState back; + bool depthTestEnable; + bool depthWriteEnable; + VkCompareOp depthCompareOp; + bool depthBoundsEnable; + bool stencilTestEnable; + VkStencilOpState front; + VkStencilOpState back; // VkPipelineColorBlendStateCreateInfo - bool alphaToCoverageEnable; - bool logicOpEnable; - VkLogicOp logicOp; + bool alphaToCoverageEnable; + bool logicOpEnable; + VkLogicOp logicOp; struct Attachment { @@ -124,10 +124,10 @@ struct VulkanCreationInfo { void Init(const VkDynamicRasterStateCreateInfo* pCreateInfo); - float depthBias; - float depthBiasClamp; - float slopeScaledDepthBias; - float lineWidth; + float depthBias; + float depthBiasClamp; + float slopeScaledDepthBias; + float lineWidth; }; map m_Raster; @@ -142,13 +142,13 @@ struct VulkanCreationInfo struct DepthStencil { void Init(const VkDynamicDepthStencilStateCreateInfo* pCreateInfo); - - float minDepthBounds; - float maxDepthBounds; - uint32_t stencilReadMask; - uint32_t stencilWriteMask; - uint32_t stencilFrontRef; - uint32_t stencilBackRef; + + float minDepthBounds; + float maxDepthBounds; + uint32_t stencilReadMask; + uint32_t stencilWriteMask; + uint32_t stencilFrontRef; + uint32_t stencilBackRef; }; map m_DepthStencil; diff --git a/renderdoc/driver/vulkan/vk_manager.h b/renderdoc/driver/vulkan/vk_manager.h index 1536f1450..9656d614d 100644 --- a/renderdoc/driver/vulkan/vk_manager.h +++ b/renderdoc/driver/vulkan/vk_manager.h @@ -75,14 +75,14 @@ class VulkanResourceManager : public ResourceManager realtype GetLiveHandle(ResourceId origid) { - RealVkRes res = ((typename UnwrapHelper::ParentType *)ResourceManager::GetLiveResource(origid))->real; + RealVkRes &res = ((typename UnwrapHelper::ParentType *)ResourceManager::GetLiveResource(origid))->real; return res.As(); } template realtype GetCurrentHandle(ResourceId id) { - RealVkRes res = ((typename UnwrapHelper::ParentType *)ResourceManager::GetCurrentResource(id))->real; + RealVkRes &res = ((typename UnwrapHelper::ParentType *)ResourceManager::GetCurrentResource(id))->real; return res.As(); } @@ -122,6 +122,17 @@ class VulkanResourceManager : public ResourceManager + void ReleaseWrappedResource(realtype obj) + { + ResourceId id = GetResID(obj); + ResourceManager::MarkCleanResource(id); + ResourceManager::RemoveWrapper(UnwrapHelper::ToRealRes(Unwrap(obj))); + ResourceManager::ReleaseCurrentResource(id); + if(GetRecord(obj)) GetRecord(obj)->Delete(this); + delete GetWrapped(obj); + } private: bool SerialisableResource(ResourceId id, VkResourceRecord *record); diff --git a/renderdoc/driver/vulkan/vk_replay.cpp b/renderdoc/driver/vulkan/vk_replay.cpp index d90e7f48c..02f56c56a 100644 --- a/renderdoc/driver/vulkan/vk_replay.cpp +++ b/renderdoc/driver/vulkan/vk_replay.cpp @@ -584,8 +584,7 @@ void VulkanReplay::PickPixel(ResourceId texture, uint32_t x, uint32_t y, uint32_ vt->EndCommandBuffer(Unwrap(cmd)); - VkCmdBuffer unwrapped = Unwrap(cmd); - vt->QueueSubmit(Unwrap(q), 1, &unwrapped, VK_NULL_HANDLE); + vt->QueueSubmit(Unwrap(q), 1, UnwrapPtr(cmd), VK_NULL_HANDLE); vt->QueueWaitIdle(Unwrap(q)); } @@ -778,8 +777,7 @@ bool VulkanReplay::RenderTexture(TextureDisplay cfg) // VKTODOMED will need a way to disable blend for other things vt->CmdBindPipeline(Unwrap(cmd), VK_PIPELINE_BIND_POINT_GRAPHICS, cfg.rawoutput ? Unwrap(GetDebugManager()->m_TexDisplayPipeline) : Unwrap(GetDebugManager()->m_TexDisplayBlendPipeline)); - VkDescriptorSet descset = Unwrap(GetDebugManager()->m_TexDisplayDescSet); - vt->CmdBindDescriptorSets(Unwrap(cmd), VK_PIPELINE_BIND_POINT_GRAPHICS, Unwrap(GetDebugManager()->m_TexDisplayPipeLayout), 0, 1, &descset, 0, NULL); + vt->CmdBindDescriptorSets(Unwrap(cmd), VK_PIPELINE_BIND_POINT_GRAPHICS, Unwrap(GetDebugManager()->m_TexDisplayPipeLayout), 0, 1, UnwrapPtr(GetDebugManager()->m_TexDisplayDescSet), 0, NULL); vt->CmdBindDynamicViewportState(Unwrap(cmd), Unwrap(outw.fullVP)); vt->CmdBindDynamicRasterState(Unwrap(cmd), Unwrap(GetDebugManager()->m_DynamicRSState)); @@ -795,8 +793,7 @@ bool VulkanReplay::RenderTexture(TextureDisplay cfg) vt->EndCommandBuffer(Unwrap(cmd)); - VkCmdBuffer unwrapped = Unwrap(cmd); - vt->QueueSubmit(Unwrap(q), 1, &unwrapped, VK_NULL_HANDLE); + vt->QueueSubmit(Unwrap(q), 1, UnwrapPtr(cmd), VK_NULL_HANDLE); // VKTODOMED ideally all the commands from Bind to Flip would be recorded // into a single command buffer and we can just have several allocated @@ -850,8 +847,7 @@ void VulkanReplay::RenderCheckerboard(Vec3f light, Vec3f dark) vt->CmdBeginRenderPass(Unwrap(cmd), &rpbegin, VK_RENDER_PASS_CONTENTS_INLINE); vt->CmdBindPipeline(Unwrap(cmd), VK_PIPELINE_BIND_POINT_GRAPHICS, Unwrap(GetDebugManager()->m_CheckerboardPipeline)); - VkDescriptorSet descset = Unwrap(GetDebugManager()->m_CheckerboardDescSet); - vt->CmdBindDescriptorSets(Unwrap(cmd), VK_PIPELINE_BIND_POINT_GRAPHICS, Unwrap(GetDebugManager()->m_CheckerboardPipeLayout), 0, 1, &descset, 0, NULL); + vt->CmdBindDescriptorSets(Unwrap(cmd), VK_PIPELINE_BIND_POINT_GRAPHICS, Unwrap(GetDebugManager()->m_CheckerboardPipeLayout), 0, 1, UnwrapPtr(GetDebugManager()->m_CheckerboardDescSet), 0, NULL); vt->CmdBindDynamicViewportState(Unwrap(cmd), outw.fullVP); vt->CmdBindDynamicRasterState(Unwrap(cmd), Unwrap(GetDebugManager()->m_DynamicRSState)); @@ -865,8 +861,7 @@ void VulkanReplay::RenderCheckerboard(Vec3f light, Vec3f dark) vkr = vt->EndCommandBuffer(Unwrap(cmd)); RDCASSERT(vkr == VK_SUCCESS); - VkCmdBuffer unwrapped = Unwrap(cmd); - vkr = vt->QueueSubmit(Unwrap(q), 1, &unwrapped, VK_NULL_HANDLE); + vkr = vt->QueueSubmit(Unwrap(q), 1, UnwrapPtr(cmd), VK_NULL_HANDLE); RDCASSERT(vkr == VK_SUCCESS); // VKTODOMED ideally all the commands from Bind to Flip would be recorded @@ -978,8 +973,7 @@ void VulkanReplay::BindOutputWindow(uint64_t id, bool depth) vt->EndCommandBuffer(Unwrap(cmd)); - VkCmdBuffer unwrapped = Unwrap(cmd); - vt->QueueSubmit(Unwrap(q), 1, &unwrapped, VK_NULL_HANDLE); + vt->QueueSubmit(Unwrap(q), 1, UnwrapPtr(cmd), VK_NULL_HANDLE); // VKTODOMED ideally all the commands from Bind to Flip would be recorded // into a single command buffer and we can just have several allocated @@ -1011,8 +1005,7 @@ void VulkanReplay::ClearOutputWindowColour(uint64_t id, float col[4]) vt->EndCommandBuffer(Unwrap(cmd)); - VkCmdBuffer unwrapped = Unwrap(cmd); - vt->QueueSubmit(Unwrap(q), 1, &unwrapped, VK_NULL_HANDLE); + vt->QueueSubmit(Unwrap(q), 1, UnwrapPtr(cmd), VK_NULL_HANDLE); // VKTODOMED ideally all the commands from Bind to Flip would be recorded // into a single command buffer and we can just have several allocated @@ -1076,11 +1069,9 @@ void VulkanReplay::FlipOutputWindow(uint64_t id) vt->EndCommandBuffer(Unwrap(cmd)); - VkCmdBuffer unwrapped = Unwrap(cmd); - vt->QueueSubmit(Unwrap(q), 1, &unwrapped, VK_NULL_HANDLE); + vt->QueueSubmit(Unwrap(q), 1, UnwrapPtr(cmd), VK_NULL_HANDLE); - VkSwapChainWSI swap = Unwrap(outw.swap); - VkPresentInfoWSI presentInfo = { VK_STRUCTURE_TYPE_QUEUE_PRESENT_INFO_WSI, NULL, 1, &swap, &outw.curidx }; + VkPresentInfoWSI presentInfo = { VK_STRUCTURE_TYPE_QUEUE_PRESENT_INFO_WSI, NULL, 1, UnwrapPtr(outw.swap), &outw.curidx }; vt->QueuePresentWSI(Unwrap(q), &presentInfo); diff --git a/renderdoc/driver/vulkan/vk_resources.cpp b/renderdoc/driver/vulkan/vk_resources.cpp index 3e1e14250..ce4d6df97 100644 --- a/renderdoc/driver/vulkan/vk_resources.cpp +++ b/renderdoc/driver/vulkan/vk_resources.cpp @@ -172,13 +172,13 @@ bool IsDepthStencilFormat(VkFormat f) { switch(f) { - case VK_FORMAT_D16_UNORM: - case VK_FORMAT_D24_UNORM: - case VK_FORMAT_D32_SFLOAT: - case VK_FORMAT_S8_UINT: - case VK_FORMAT_D16_UNORM_S8_UINT: - case VK_FORMAT_D24_UNORM_S8_UINT: - case VK_FORMAT_D32_SFLOAT_S8_UINT: + case VK_FORMAT_D16_UNORM: + case VK_FORMAT_D24_UNORM: + case VK_FORMAT_D32_SFLOAT: + case VK_FORMAT_S8_UINT: + case VK_FORMAT_D16_UNORM_S8_UINT: + case VK_FORMAT_D24_UNORM_S8_UINT: + case VK_FORMAT_D32_SFLOAT_S8_UINT: return true; default: break; diff --git a/renderdoc/driver/vulkan/vk_resources.h b/renderdoc/driver/vulkan/vk_resources.h index e175bb30b..627cf5d52 100644 --- a/renderdoc/driver/vulkan/vk_resources.h +++ b/renderdoc/driver/vulkan/vk_resources.h @@ -60,6 +60,7 @@ struct RealVkRes uint64_t handle; template T As() { return (T)handle; } + template T *AsPtr() { return (T*)&handle; } }; struct WrappedVkNonDispRes : public WrappedVkRes @@ -406,11 +407,21 @@ RealType Unwrap(RealType obj) { if(obj == VK_NULL_HANDLE) return VK_NULL_HANDLE; - RealVkRes res = GetWrapped(obj)->real; + RealVkRes &res = GetWrapped(obj)->real; return res.As(); } +template +RealType *UnwrapPtr(RealType obj) +{ + if(obj == VK_NULL_HANDLE) return NULL; + + RealVkRes &res = GetWrapped(obj)->real; + + return res.AsPtr(); +} + template ResourceId GetResID(RealType obj) { @@ -430,7 +441,7 @@ VkResourceRecord *GetRecord(RealType obj) template RealType ToHandle(WrappedVkRes *ptr) { - RealVkRes res = ((typename UnwrapHelper::Outer *)ptr)->real; + RealVkRes &res = ((typename UnwrapHelper::Outer *)ptr)->real; return res.As(); }