From e88580ae649c2a8488aeb26d39cec5d8289a22a4 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Wed, 28 Feb 2024 19:09:44 -0800 Subject: [PATCH] implement resource containers --- include/Refresh.h | 21 +- src/Refresh.c | 12 +- src/Refresh_Driver.h | 6 +- src/Refresh_Driver_Vulkan.c | 775 +++++++++++++++++++++--------------- 4 files changed, 475 insertions(+), 339 deletions(-) diff --git a/include/Refresh.h b/include/Refresh.h index 8ad8888..644c9a6 100644 --- a/include/Refresh.h +++ b/include/Refresh.h @@ -1144,7 +1144,8 @@ REFRESHAPI void Refresh_DownloadFromTexture( Refresh_CommandBuffer *commandBuffer, Refresh_TextureSlice *textureSlice, Refresh_TransferBuffer *transferBuffer, - Refresh_BufferImageCopy *copyParams + Refresh_BufferImageCopy *copyParams, + Refresh_TransferOptions option ); /* Downloads data from a GpuBuffer object. */ @@ -1153,13 +1154,29 @@ REFRESHAPI void Refresh_DownloadFromBuffer( Refresh_CommandBuffer *commandBuffer, Refresh_GpuBuffer *gpuBuffer, Refresh_TransferBuffer *transferBuffer, - Refresh_BufferCopy *copyParams + Refresh_BufferCopy *copyParams, + Refresh_TransferOptions option ); /* GPU-to-GPU copies occur on the GPU timeline, * and you may assume the copy has finished in subsequent commands. */ +/* + * option: + * SAFEDISCARD: + * If the destination resource has been used in a copy command that has not completed, + * the issued copy commands will still be valid at the cost of increased memory usage. + * Otherwise the data will safely overwrite. + * This is a good option to prevent stalls on resources with frequent updates. + * It is not recommended to use this option with large resources. + * + * SAFEOVERWRITE: + * Overwrites the data regardless of whether a copy has been issued. + * This will insert a memory barrier, so it could cause suboptimal performance compared to SAFEDISCARD + * on resources that update frequently across submissions. + */ + /* Performs a texture-to-texture copy. */ REFRESHAPI void Refresh_CopyTextureToTexture( Refresh_Device *device, diff --git a/src/Refresh.c b/src/Refresh.c index ac170a0..986922f 100644 --- a/src/Refresh.c +++ b/src/Refresh.c @@ -820,7 +820,8 @@ void Refresh_DownloadFromTexture( Refresh_CommandBuffer *commandBuffer, Refresh_TextureSlice *textureSlice, Refresh_TransferBuffer *transferBuffer, - Refresh_BufferImageCopy *copyParams + Refresh_BufferImageCopy *copyParams, + Refresh_TransferOptions option ) { NULL_RETURN(device); device->DownloadFromTexture( @@ -828,7 +829,8 @@ void Refresh_DownloadFromTexture( commandBuffer, textureSlice, transferBuffer, - copyParams + copyParams, + option ); } @@ -837,7 +839,8 @@ void Refresh_DownloadFromBuffer( Refresh_CommandBuffer *commandBuffer, Refresh_GpuBuffer *gpuBuffer, Refresh_TransferBuffer *transferBuffer, - Refresh_BufferCopy *copyParams + Refresh_BufferCopy *copyParams, + Refresh_TransferOptions option ) { NULL_RETURN(device); device->DownloadFromBuffer( @@ -845,7 +848,8 @@ void Refresh_DownloadFromBuffer( commandBuffer, gpuBuffer, transferBuffer, - copyParams + copyParams, + option ); } diff --git a/src/Refresh_Driver.h b/src/Refresh_Driver.h index 7629855..6e92761 100644 --- a/src/Refresh_Driver.h +++ b/src/Refresh_Driver.h @@ -460,7 +460,8 @@ struct Refresh_Device Refresh_CommandBuffer *commandBuffer, Refresh_TextureSlice *textureSlice, Refresh_TransferBuffer *transferBuffer, - Refresh_BufferImageCopy *copyParams + Refresh_BufferImageCopy *copyParams, + Refresh_TransferOptions option ); void (*DownloadFromBuffer)( @@ -468,7 +469,8 @@ struct Refresh_Device Refresh_CommandBuffer *commandBuffer, Refresh_GpuBuffer *gpuBuffer, Refresh_TransferBuffer *transferBuffer, - Refresh_BufferCopy *copyParams + Refresh_BufferCopy *copyParams, + Refresh_TransferOptions option ); void (*CopyTextureToTexture)( diff --git a/src/Refresh_Driver_Vulkan.c b/src/Refresh_Driver_Vulkan.c index 930a978..61927a7 100644 --- a/src/Refresh_Driver_Vulkan.c +++ b/src/Refresh_Driver_Vulkan.c @@ -778,6 +778,12 @@ typedef struct VulkanShaderModule SDL_atomic_t referenceCount; } VulkanShaderModule; +typedef struct VulkanRenderTarget +{ + VkImageView view; + VulkanTexture *msaaTex; /* NULL if sample count is 1 or is depth target */ +} VulkanRenderTarget; + typedef struct VulkanTextureHandle { VulkanTexture *vulkanTexture; @@ -797,13 +803,12 @@ struct VulkanTexture uint32_t depth; uint32_t layerCount; uint32_t levelCount; - Refresh_SampleCount sampleCount; /* actual sample account of the texture */ + VkSampleCountFlagBits sampleCount; /* NOTE: This refers to the sample count of a render target pass using this texture, not the actual sample count of the texture */ VkFormat format; VulkanResourceAccessType resourceAccessType; VkImageUsageFlags usageFlags; VkImageAspectFlags aspectFlags; - Refresh_SampleCount renderTargetSampleCount; /* requested sample count for target */ VulkanRenderTarget *renderTargets; /* NULL if usage is not color target or depth target, or if this texture is itself an MSAA texture */ SDL_atomic_t referenceCount; @@ -835,12 +840,6 @@ typedef struct VulkanTextureContainer uint8_t canBeDiscarded; } VulkanTextureContainer; -typedef struct VulkanRenderTarget -{ - VkImageView view; - VulkanTexture *msaaTex; /* NULL if sample count is 1 or is depth target */ -} VulkanRenderTarget; - typedef struct VulkanFramebuffer { VkFramebuffer framebuffer; @@ -1034,7 +1033,7 @@ typedef struct RenderPassHash RenderPassColorTargetDescription colorTargetDescriptions[MAX_COLOR_TARGET_BINDINGS]; uint32_t colorAttachmentCount; RenderPassDepthStencilTargetDescription depthStencilTargetDescription; - Refresh_SampleCount colorAttachmentSampleCount; + VkSampleCountFlagBits colorAttachmentSampleCount; } RenderPassHash; typedef struct RenderPassHashMap @@ -1755,6 +1754,15 @@ static void VULKAN_INTERNAL_BeginCommandBuffer(VulkanRenderer *renderer, VulkanC static void VULKAN_UnclaimWindow(Refresh_Renderer *driverData, void *windowHandle); static void VULKAN_Wait(Refresh_Renderer *driverData); static void VULKAN_Submit(Refresh_Renderer *driverData, Refresh_CommandBuffer *commandBuffer); +static void VULKAN_INTERNAL_CreateRenderTarget( + VulkanRenderer *renderer, + VulkanTexture *texture, + uint32_t depth, + uint32_t layer, + uint32_t level, + VkSampleCountFlagBits sampleCount, + VulkanRenderTarget *renderTarget +); static void VULKAN_INTERNAL_DestroyRenderTarget(VulkanRenderer *renderer, VulkanRenderTarget *renderTarget); /* Error Handling */ @@ -1985,24 +1993,24 @@ static inline VkDeviceSize VULKAN_INTERNAL_BytesPerImage( return (width * height * VULKAN_INTERNAL_BytesPerPixel(format)) / (blockSize * blockSize); } -static inline Refresh_SampleCount VULKAN_INTERNAL_GetMaxMultiSampleCount( +static inline VkSampleCountFlagBits VULKAN_INTERNAL_GetMaxMultiSampleCount( VulkanRenderer *renderer, - Refresh_SampleCount multiSampleCount + VkSampleCountFlagBits multiSampleCount ) { VkSampleCountFlags flags = renderer->physicalDeviceProperties.properties.limits.framebufferColorSampleCounts; - Refresh_SampleCount maxSupported = REFRESH_SAMPLECOUNT_1; + VkSampleCountFlagBits maxSupported = VK_SAMPLE_COUNT_1_BIT; if (flags & VK_SAMPLE_COUNT_8_BIT) { - maxSupported = REFRESH_SAMPLECOUNT_8; + maxSupported = VK_SAMPLE_COUNT_8_BIT; } else if (flags & VK_SAMPLE_COUNT_4_BIT) { - maxSupported = REFRESH_SAMPLECOUNT_4; + maxSupported = VK_SAMPLE_COUNT_4_BIT; } else if (flags & VK_SAMPLE_COUNT_2_BIT) { - maxSupported = REFRESH_SAMPLECOUNT_2; + maxSupported = VK_SAMPLE_COUNT_2_BIT; } return SDL_min(multiSampleCount, maxSupported); @@ -3480,23 +3488,20 @@ static void VULKAN_INTERNAL_DestroyTexture( if (isRenderTarget) { + rtIndex = 0; + for (i = 0; i < texture->depth; i += 1) { for (j = 0; j < texture->layerCount; j += 1) { for (k = 0; k < texture->levelCount; k += 1) { - rtIndex = VULKAN_INTERNAL_GetRenderTargetIndex( - texture, - i, - j, - k - ); - VULKAN_INTERNAL_DestroyRenderTarget( renderer, &texture->renderTargets[rtIndex] ); + + rtIndex += 1; } } } @@ -4882,7 +4887,7 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain( swapchainData->textureContainers[i].activeTextureHandle->vulkanTexture->depth = 1; swapchainData->textureContainers[i].activeTextureHandle->vulkanTexture->layerCount = 1; swapchainData->textureContainers[i].activeTextureHandle->vulkanTexture->levelCount = 1; - swapchainData->textureContainers[i].activeTextureHandle->vulkanTexture->sampleCount = REFRESH_SAMPLECOUNT_1; + swapchainData->textureContainers[i].activeTextureHandle->vulkanTexture->sampleCount = VK_SAMPLE_COUNT_1_BIT; swapchainData->textureContainers[i].activeTextureHandle->vulkanTexture->usageFlags = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; @@ -4890,7 +4895,6 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain( swapchainData->textureContainers[i].activeTextureHandle->vulkanTexture->resourceAccessType = RESOURCE_ACCESS_NONE; /* Create render target */ - swapchainData->textureContainers[i].activeTextureHandle->vulkanTexture->renderTargetSampleCount = REFRESH_SAMPLECOUNT_1; swapchainData->textureContainers[i].activeTextureHandle->vulkanTexture->renderTargets = SDL_malloc(sizeof(VulkanRenderTarget)); VULKAN_INTERNAL_CreateRenderTarget( renderer, @@ -4898,7 +4902,7 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain( 0, 0, 0, - REFRESH_SAMPLECOUNT_1, + VK_SAMPLE_COUNT_1_BIT, &swapchainData->textureContainers[i].activeTextureHandle->vulkanTexture->renderTargets[0] ); } @@ -5339,7 +5343,7 @@ static void VULKAN_DrawPrimitivesIndirect( ) { VulkanRenderer* renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; - VulkanBuffer *vulkanBuffer = ((VulkanBufferHandle*) gpuBuffer)->vulkanBuffer; + VulkanBuffer *vulkanBuffer = ((VulkanBufferContainer*) gpuBuffer)->activeBufferHandle->vulkanBuffer; VkDescriptorSet descriptorSets[4]; uint32_t dynamicOffsets[2]; @@ -5373,101 +5377,6 @@ static void VULKAN_DrawPrimitivesIndirect( VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, vulkanBuffer); } -static void VULKAN_INTERNAL_CreateRenderTarget( - VulkanRenderer *renderer, - VulkanTexture *texture, - uint32_t depth, - uint32_t layer, - uint32_t level, - Refresh_SampleCount sampleCount, - VulkanRenderTarget *renderTarget -) { - VkResult vulkanResult; - VkImageViewCreateInfo imageViewCreateInfo; - VkComponentMapping swizzle = IDENTITY_SWIZZLE; - VkImageAspectFlags aspectFlags = 0; - - if (IsDepthFormat(texture->format)) - { - aspectFlags |= VK_IMAGE_ASPECT_DEPTH_BIT; - - if (IsStencilFormat(texture->format)) - { - aspectFlags |= VK_IMAGE_ASPECT_STENCIL_BIT; - } - } - else - { - aspectFlags |= VK_IMAGE_ASPECT_COLOR_BIT; - } - - /* create framebuffer compatible views for RenderTarget */ - imageViewCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; - imageViewCreateInfo.pNext = NULL; - imageViewCreateInfo.flags = 0; - imageViewCreateInfo.image = texture->image; - imageViewCreateInfo.format = texture->format; - imageViewCreateInfo.components = swizzle; - imageViewCreateInfo.subresourceRange.aspectMask = aspectFlags; - imageViewCreateInfo.subresourceRange.baseMipLevel = level; - imageViewCreateInfo.subresourceRange.levelCount = 1; - imageViewCreateInfo.subresourceRange.baseArrayLayer = 0; - if (texture->is3D) - { - imageViewCreateInfo.subresourceRange.baseArrayLayer = depth; - } - else if (texture->isCube) - { - imageViewCreateInfo.subresourceRange.baseArrayLayer = layer; - } - imageViewCreateInfo.subresourceRange.layerCount = 1; - imageViewCreateInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; - - vulkanResult = renderer->vkCreateImageView( - renderer->logicalDevice, - &imageViewCreateInfo, - NULL, - &renderTarget->view - ); - - if (vulkanResult != VK_SUCCESS) - { - LogVulkanResultAsError( - "vkCreateImageView", - vulkanResult - ); - Refresh_LogError("Failed to create color attachment image view"); - return; - } - - if (sampleCount > REFRESH_SAMPLECOUNT_1) - { - /* Create MSAA texture */ - renderTarget->msaaTex = VULKAN_INTERNAL_CreateTexture( - renderer, - texture->dimensions.width, - texture->dimensions.height, - 1, - 0, - 1, - sampleCount, - texture->format, - texture->aspectFlags, - texture->usageFlags - ); - - if (renderTarget->msaaTex == NULL) - { - Refresh_LogError("Failed to create MSAA render texture!"); - return; - } - } - else - { - renderTarget->msaaTex = NULL; - } -} - static VulkanTexture* VULKAN_INTERNAL_CreateTexture( VulkanRenderer *renderer, uint32_t width, @@ -5475,10 +5384,11 @@ static VulkanTexture* VULKAN_INTERNAL_CreateTexture( uint32_t depth, uint32_t isCube, uint32_t levelCount, - Refresh_SampleCount sampleCount, + VkSampleCountFlagBits sampleCount, VkFormat format, VkImageAspectFlags aspectMask, - VkImageUsageFlags imageUsageFlags + VkImageUsageFlags imageUsageFlags, + uint8_t isMsaaTexture ) { VkResult vulkanResult; VkImageCreateInfo imageCreateInfo; @@ -5491,7 +5401,7 @@ static VulkanTexture* VULKAN_INTERNAL_CreateTexture( ((imageUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) != 0) || ((imageUsageFlags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) != 0); VkComponentMapping swizzle = IDENTITY_SWIZZLE; - uint32_t i, j, k; + uint32_t i, j, k, rtIndex; VulkanTexture *texture = SDL_malloc(sizeof(VulkanTexture)); texture->isCube = 0; @@ -5519,7 +5429,7 @@ static VulkanTexture* VULKAN_INTERNAL_CreateTexture( imageCreateInfo.extent.depth = depth; imageCreateInfo.mipLevels = levelCount; imageCreateInfo.arrayLayers = layerCount; - imageCreateInfo.samples = sampleCount; + imageCreateInfo.samples = isMsaaTexture ? sampleCount : VK_SAMPLE_COUNT_1_BIT; imageCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL; imageCreateInfo.usage = imageUsageFlags; imageCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; @@ -5608,12 +5518,185 @@ static VulkanTexture* VULKAN_INTERNAL_CreateTexture( SDL_AtomicSet(&texture->referenceCount, 0); /* these get overwritten if render targets are created */ - texture->renderTargetSampleCount = REFRESH_SAMPLECOUNT_1; texture->renderTargets = NULL; + /* Create render target structures if necessary */ + if (isRenderTarget && !isMsaaTexture) + { + texture->renderTargets = SDL_malloc( + texture->depth * + texture->layerCount * + texture->levelCount * + sizeof(VulkanRenderTarget) + ); + + rtIndex = 0; + + for (i = 0; i < texture->depth; i += 1) + { + for (j = 0; j < texture->layerCount; j += 1) + { + for (k = 0; k < texture->levelCount; k += 1) + { + /* NOTE: this will recursively create an MSAA texture if sampleCount > 1 */ + VULKAN_INTERNAL_CreateRenderTarget( + renderer, + texture, + i, + j, + k, + sampleCount, + &texture->renderTargets[rtIndex] + ); + + rtIndex += 1; + } + } + } + } + return texture; } +static VulkanTextureHandle* VULKAN_INTERNAL_CreateTextureHandle( + VulkanRenderer *renderer, + uint32_t width, + uint32_t height, + uint32_t depth, + uint32_t isCube, + uint32_t levelCount, + VkSampleCountFlagBits sampleCount, + VkFormat format, + VkImageAspectFlags aspectMask, + VkImageUsageFlags imageUsageFlags, + uint8_t isMsaaTexture +) { + VulkanTextureHandle *textureHandle; + VulkanTexture *texture; + + texture = VULKAN_INTERNAL_CreateTexture( + renderer, + width, + height, + depth, + isCube, + levelCount, + sampleCount, + format, + aspectMask, + imageUsageFlags, + isMsaaTexture + ); + + if (texture == NULL) + { + Refresh_LogError("Failed to create texture!"); + return NULL; + } + + textureHandle = SDL_malloc(sizeof(VulkanTextureHandle)); + textureHandle->vulkanTexture = texture; + texture->handle = textureHandle; + + return textureHandle; +} + +static void VULKAN_INTERNAL_CreateRenderTarget( + VulkanRenderer *renderer, + VulkanTexture *texture, + uint32_t depth, + uint32_t layer, + uint32_t level, + VkSampleCountFlagBits sampleCount, + VulkanRenderTarget *renderTarget +) { + VkResult vulkanResult; + VkImageViewCreateInfo imageViewCreateInfo; + VkComponentMapping swizzle = IDENTITY_SWIZZLE; + VkImageAspectFlags aspectFlags = 0; + + if (IsDepthFormat(texture->format)) + { + aspectFlags |= VK_IMAGE_ASPECT_DEPTH_BIT; + + if (IsStencilFormat(texture->format)) + { + aspectFlags |= VK_IMAGE_ASPECT_STENCIL_BIT; + } + } + else + { + aspectFlags |= VK_IMAGE_ASPECT_COLOR_BIT; + } + + /* create framebuffer compatible views for RenderTarget */ + imageViewCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + imageViewCreateInfo.pNext = NULL; + imageViewCreateInfo.flags = 0; + imageViewCreateInfo.image = texture->image; + imageViewCreateInfo.format = texture->format; + imageViewCreateInfo.components = swizzle; + imageViewCreateInfo.subresourceRange.aspectMask = aspectFlags; + imageViewCreateInfo.subresourceRange.baseMipLevel = level; + imageViewCreateInfo.subresourceRange.levelCount = 1; + imageViewCreateInfo.subresourceRange.baseArrayLayer = 0; + if (texture->is3D) + { + imageViewCreateInfo.subresourceRange.baseArrayLayer = depth; + } + else if (texture->isCube) + { + imageViewCreateInfo.subresourceRange.baseArrayLayer = layer; + } + imageViewCreateInfo.subresourceRange.layerCount = 1; + imageViewCreateInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; + + vulkanResult = renderer->vkCreateImageView( + renderer->logicalDevice, + &imageViewCreateInfo, + NULL, + &renderTarget->view + ); + + if (vulkanResult != VK_SUCCESS) + { + LogVulkanResultAsError( + "vkCreateImageView", + vulkanResult + ); + Refresh_LogError("Failed to create color attachment image view"); + return; + } + + if (sampleCount > VK_SAMPLE_COUNT_1_BIT) + { + /* Create MSAA texture */ + renderTarget->msaaTex = VULKAN_INTERNAL_CreateTexture( + renderer, + texture->dimensions.width, + texture->dimensions.height, + 1, + 0, + 1, + sampleCount, + texture->format, + texture->aspectFlags, + texture->usageFlags, + 1 + ); + + if (renderTarget->msaaTex == NULL) + { + Refresh_LogError("Failed to create MSAA render texture!"); + return; + } + } + else + { + renderTarget->msaaTex = NULL; + } +} + static uint32_t VULKAN_INTERNAL_GetRenderTargetIndex( VulkanTexture *texture, uint32_t depth, @@ -5685,9 +5768,9 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass( for (i = 0; i < colorAttachmentCount; i += 1) { - texture = ((VulkanTextureHandle*) colorAttachmentInfos[i].texture)->vulkanTexture; + texture = ((VulkanTextureContainer*) colorAttachmentInfos[i].texture)->activeTextureHandle->vulkanTexture; - if (texture->renderTargetSampleCount > REFRESH_SAMPLECOUNT_1) + if (texture->sampleCount > VK_SAMPLE_COUNT_1_BIT) { /* Resolve attachment and multisample attachment */ @@ -5720,7 +5803,7 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass( attachmentDescriptions[attachmentDescriptionCount].flags = 0; attachmentDescriptions[attachmentDescriptionCount].format = texture->format; attachmentDescriptions[attachmentDescriptionCount].samples = RefreshToVK_SampleCount[ - texture->renderTargetSampleCount + texture->sampleCount ]; attachmentDescriptions[attachmentDescriptionCount].loadOp = RefreshToVK_LoadOp[ colorAttachmentInfos[i].loadOp @@ -5790,7 +5873,7 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass( } else { - texture = ((VulkanTextureHandle*) depthStencilAttachmentInfo->texture)->vulkanTexture; + texture = ((VulkanTextureContainer*) depthStencilAttachmentInfo->texture)->activeTextureHandle->vulkanTexture; attachmentDescriptions[attachmentDescriptionCount].flags = 0; attachmentDescriptions[attachmentDescriptionCount].format = texture->format; @@ -5825,7 +5908,7 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass( attachmentDescriptionCount += 1; } - if (texture->renderTargetSampleCount > REFRESH_SAMPLECOUNT_1) + if (texture->sampleCount > VK_SAMPLE_COUNT_1_BIT) { subpass.pResolveAttachments = resolveReferences; } @@ -5863,7 +5946,7 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass( static VkRenderPass VULKAN_INTERNAL_CreateTransientRenderPass( VulkanRenderer *renderer, Refresh_GraphicsPipelineAttachmentInfo attachmentInfo, - Refresh_SampleCount sampleCount + VkSampleCountFlagBits sampleCount ) { VkAttachmentDescription attachmentDescriptions[2 * MAX_COLOR_TARGET_BINDINGS + 1]; VkAttachmentReference colorAttachmentReferences[MAX_COLOR_TARGET_BINDINGS]; @@ -5885,7 +5968,7 @@ static VkRenderPass VULKAN_INTERNAL_CreateTransientRenderPass( { attachmentDescription = attachmentInfo.colorAttachmentDescriptions[i]; - if (sampleCount > REFRESH_SAMPLECOUNT_1) + if (sampleCount > VK_SAMPLE_COUNT_1_BIT) { multisampling = 1; @@ -6046,7 +6129,7 @@ static Refresh_GraphicsPipeline* VULKAN_CreateGraphicsPipeline( ) { VkResult vulkanResult; uint32_t i; - Refresh_SampleCount actualSampleCount; + VkSampleCountFlagBits actualSampleCount; VulkanGraphicsPipeline *graphicsPipeline = (VulkanGraphicsPipeline*) SDL_malloc(sizeof(VulkanGraphicsPipeline)); VkGraphicsPipelineCreateInfo vkPipelineCreateInfo; @@ -6088,7 +6171,7 @@ static Refresh_GraphicsPipeline* VULKAN_CreateGraphicsPipeline( actualSampleCount = VULKAN_INTERNAL_GetMaxMultiSampleCount( renderer, - pipelineCreateInfo->multisampleState.multisampleCount + RefreshToVK_SampleCount[pipelineCreateInfo->multisampleState.multisampleCount] ); /* Create a "compatible" render pass */ @@ -6227,7 +6310,7 @@ static Refresh_GraphicsPipeline* VULKAN_CreateGraphicsPipeline( multisampleStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; multisampleStateCreateInfo.pNext = NULL; multisampleStateCreateInfo.flags = 0; - multisampleStateCreateInfo.rasterizationSamples = RefreshToVK_SampleCount[actualSampleCount]; + multisampleStateCreateInfo.rasterizationSamples = actualSampleCount; multisampleStateCreateInfo.sampleShadingEnable = VK_FALSE; multisampleStateCreateInfo.minSampleShading = 1.0f; multisampleStateCreateInfo.pSampleMask = @@ -6689,8 +6772,6 @@ static Refresh_Texture* VULKAN_CreateTexture( VkFormat format; VulkanTextureContainer *container; VulkanTextureHandle *textureHandle; - VulkanTexture *vulkanTexture; - uint32_t i, j, k, rtIndex; if (isDepthFormat) { @@ -6735,67 +6816,26 @@ static Refresh_Texture* VULKAN_CreateTexture( imageAspectFlags = VK_IMAGE_ASPECT_COLOR_BIT; } - vulkanTexture = VULKAN_INTERNAL_CreateTexture( + textureHandle = VULKAN_INTERNAL_CreateTextureHandle( renderer, textureCreateInfo->width, textureCreateInfo->height, textureCreateInfo->depth, textureCreateInfo->isCube, textureCreateInfo->levelCount, - REFRESH_SAMPLECOUNT_1, /* attachments themselves are always sample count 1, have msaaTex in render target */ + RefreshToVK_SampleCount[textureCreateInfo->sampleCount], format, imageAspectFlags, - imageUsageFlags + imageUsageFlags, + 0 ); - if (vulkanTexture == NULL) + if (textureHandle == NULL) { - Refresh_LogInfo("Failed to create texture!"); + Refresh_LogInfo("Failed to create texture container!"); return NULL; } - /* Create render target structures if necessary */ - if (isRenderTarget) - { - vulkanTexture->renderTargetSampleCount = textureCreateInfo->sampleCount; - vulkanTexture->renderTargets = SDL_malloc( - vulkanTexture->depth * - vulkanTexture->layerCount * - vulkanTexture->levelCount * - sizeof(VulkanRenderTarget) - ); - - for (i = 0; i < vulkanTexture->depth; i += 1) - { - for (j = 0; j < vulkanTexture->layerCount; j += 1) - { - for (k = 0; k < vulkanTexture->levelCount; k += 1) - { - rtIndex = VULKAN_INTERNAL_GetRenderTargetIndex( - vulkanTexture, - i, - j, - k - ); - - VULKAN_INTERNAL_CreateRenderTarget( - renderer, - vulkanTexture, - i, - j, - k, - textureCreateInfo->sampleCount, - &vulkanTexture->renderTargets[rtIndex] - ); - } - } - } - } - - textureHandle = SDL_malloc(sizeof(VulkanTextureHandle)); - textureHandle->vulkanTexture = vulkanTexture; - vulkanTexture->handle = textureHandle; - container = SDL_malloc(sizeof(VulkanTextureContainer)); container->canBeDiscarded = 1; container->activeTextureHandle = textureHandle; @@ -7134,7 +7174,7 @@ static void VULKAN_BindVertexSamplers( for (i = 0; i < samplerCount; i += 1) { - currentTexture = ((VulkanTextureHandle*) pTextures[i])->vulkanTexture; + currentTexture = ((VulkanTextureContainer*) pTextures[i])->activeTextureHandle->vulkanTexture; currentSampler = (VulkanSampler*) pSamplers[i]; descriptorImageInfos[i].imageView = currentTexture->view; descriptorImageInfos[i].sampler = currentSampler->sampler; @@ -7177,7 +7217,7 @@ static void VULKAN_BindFragmentSamplers( for (i = 0; i < samplerCount; i += 1) { - currentTexture = ((VulkanTextureHandle*) pTextures[i])->vulkanTexture; + currentTexture = ((VulkanTextureContainer*) pTextures[i])->activeTextureHandle->vulkanTexture; currentSampler = (VulkanSampler*) pSamplers[i]; descriptorImageInfos[i].imageView = currentTexture->view; descriptorImageInfos[i].sampler = currentSampler->sampler; @@ -7227,14 +7267,19 @@ static void VULKAN_QueueDestroyTexture( Refresh_Texture *texture ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; - VulkanTextureHandle *vulkanTextureContainer = (VulkanTextureHandle *)texture; - VulkanTexture *vulkanTexture = vulkanTextureContainer->vulkanTexture; + VulkanTextureContainer *vulkanTextureContainer = (VulkanTextureContainer*) texture; + uint32_t i; SDL_LockMutex(renderer->disposeLock); - VULKAN_INTERNAL_QueueDestroyTexture(renderer, vulkanTexture); + for (i = 0; i < vulkanTextureContainer->textureCount; i += 1) + { + VULKAN_INTERNAL_QueueDestroyTexture(renderer, vulkanTextureContainer->textureHandles[i]->vulkanTexture); + SDL_free(vulkanTextureContainer->textureHandles[i]); + } /* Containers are just client handles, so we can destroy immediately */ + SDL_free(vulkanTextureContainer->textureHandles); SDL_free(vulkanTextureContainer); SDL_UnlockMutex(renderer->disposeLock); @@ -7294,14 +7339,19 @@ static void VULKAN_QueueDestroyGpuBuffer( Refresh_GpuBuffer *gpuBuffer ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; - VulkanBufferHandle *vulkanBufferContainer = (VulkanBufferHandle*) gpuBuffer; - VulkanBuffer *vulkanBuffer = vulkanBufferContainer->vulkanBuffer; + VulkanBufferContainer *vulkanBufferContainer = (VulkanBufferContainer*) gpuBuffer; + uint32_t i; SDL_LockMutex(renderer->disposeLock); - VULKAN_INTERNAL_QueueDestroyBuffer(renderer, vulkanBuffer); + for (i = 0; i < vulkanBufferContainer->bufferCount; i += 1) + { + VULKAN_INTERNAL_QueueDestroyBuffer(renderer, vulkanBufferContainer->bufferHandles[i]->vulkanBuffer); + SDL_free(vulkanBufferContainer->bufferHandles[i]); + } /* Containers are just client handles, so we can free immediately */ + SDL_free(vulkanBufferContainer->bufferHandles); SDL_free(vulkanBufferContainer); SDL_UnlockMutex(renderer->disposeLock); @@ -7411,23 +7461,21 @@ static VkRenderPass VULKAN_INTERNAL_FetchRenderPass( VkRenderPass renderPass; RenderPassHash hash; uint32_t i; - VulkanTexture *texture; SDL_LockMutex(renderer->renderPassFetchLock); for (i = 0; i < colorAttachmentCount; i += 1) { - hash.colorTargetDescriptions[i].format = ((VulkanTextureHandle*) colorAttachmentInfos[i].texture)->vulkanTexture->format; + hash.colorTargetDescriptions[i].format = ((VulkanTextureContainer*) colorAttachmentInfos[i].texture)->activeTextureHandle->vulkanTexture->format; hash.colorTargetDescriptions[i].clearColor = colorAttachmentInfos[i].clearColor; hash.colorTargetDescriptions[i].loadOp = colorAttachmentInfos[i].loadOp; hash.colorTargetDescriptions[i].storeOp = colorAttachmentInfos[i].storeOp; } - hash.colorAttachmentSampleCount = REFRESH_SAMPLECOUNT_1; + hash.colorAttachmentSampleCount = VK_SAMPLE_COUNT_1_BIT; if (colorAttachmentCount > 0) { - texture = ((VulkanTextureHandle*) colorAttachmentInfos[0].texture)->vulkanTexture; - hash.colorAttachmentSampleCount = texture->renderTargetSampleCount; + hash.colorAttachmentSampleCount = ((VulkanTextureContainer*) colorAttachmentInfos[0].texture)->activeTextureHandle->vulkanTexture->sampleCount; } hash.colorAttachmentCount = colorAttachmentCount; @@ -7442,7 +7490,7 @@ static VkRenderPass VULKAN_INTERNAL_FetchRenderPass( } else { - hash.depthStencilTargetDescription.format = ((VulkanTextureHandle*) depthStencilAttachmentInfo->texture)->vulkanTexture->format; + hash.depthStencilTargetDescription.format = ((VulkanTextureContainer*) depthStencilAttachmentInfo->texture)->activeTextureHandle->vulkanTexture->format; hash.depthStencilTargetDescription.loadOp = depthStencilAttachmentInfo->loadOp; hash.depthStencilTargetDescription.storeOp = depthStencilAttachmentInfo->storeOp; hash.depthStencilTargetDescription.stencilLoadOp = depthStencilAttachmentInfo->stencilLoadOp; @@ -7510,7 +7558,7 @@ static VulkanFramebuffer* VULKAN_INTERNAL_FetchFramebuffer( for (i = 0; i < colorAttachmentCount; i += 1) { - texture = ((VulkanTextureHandle*) colorAttachmentInfos[i].texture)->vulkanTexture; + texture = ((VulkanTextureContainer*) colorAttachmentInfos[i].texture)->activeTextureHandle->vulkanTexture; renderTarget = VULKAN_INTERNAL_FetchRenderTarget( renderer, @@ -7536,7 +7584,7 @@ static VulkanFramebuffer* VULKAN_INTERNAL_FetchFramebuffer( } else { - texture = ((VulkanTextureHandle*) depthStencilAttachmentInfo->texture)->vulkanTexture; + texture = ((VulkanTextureContainer*) depthStencilAttachmentInfo->texture)->activeTextureHandle->vulkanTexture; renderTarget = VULKAN_INTERNAL_FetchRenderTarget( renderer, texture, @@ -7572,7 +7620,7 @@ static VulkanFramebuffer* VULKAN_INTERNAL_FetchFramebuffer( for (i = 0; i < colorAttachmentCount; i += 1) { - texture = ((VulkanTextureHandle*) colorAttachmentInfos[i].texture)->vulkanTexture; + texture = ((VulkanTextureContainer*) colorAttachmentInfos[i].texture)->activeTextureHandle->vulkanTexture; renderTarget = VULKAN_INTERNAL_FetchRenderTarget( renderer, @@ -7598,7 +7646,7 @@ static VulkanFramebuffer* VULKAN_INTERNAL_FetchFramebuffer( if (depthStencilAttachmentInfo != NULL) { - texture = ((VulkanTextureHandle*) depthStencilAttachmentInfo->texture)->vulkanTexture; + texture = ((VulkanTextureContainer*) depthStencilAttachmentInfo->texture)->activeTextureHandle->vulkanTexture; renderTarget = VULKAN_INTERNAL_FetchRenderTarget( renderer, texture, @@ -7747,7 +7795,7 @@ static void VULKAN_BeginRenderPass( for (i = 0; i < colorAttachmentCount; i += 1) { - texture = ((VulkanTextureHandle*) colorAttachmentInfos[i].texture)->vulkanTexture; + texture = ((VulkanTextureContainer*) colorAttachmentInfos[i].texture)->activeTextureHandle->vulkanTexture; w = texture->dimensions.width >> colorAttachmentInfos[i].level; h = texture->dimensions.height >> colorAttachmentInfos[i].level; @@ -7770,7 +7818,7 @@ static void VULKAN_BeginRenderPass( if (depthStencilAttachmentInfo != NULL) { - texture = ((VulkanTextureHandle*) depthStencilAttachmentInfo->texture)->vulkanTexture; + texture = ((VulkanTextureContainer*) depthStencilAttachmentInfo->texture)->activeTextureHandle->vulkanTexture; w = texture->dimensions.width >> depthStencilAttachmentInfo->level; h = texture->dimensions.height >> depthStencilAttachmentInfo->level; @@ -7817,7 +7865,7 @@ static void VULKAN_BeginRenderPass( for (i = 0; i < colorAttachmentCount; i += 1) { - texture = ((VulkanTextureHandle*) colorAttachmentInfos[i].texture)->vulkanTexture; + texture = ((VulkanTextureContainer*) colorAttachmentInfos[i].texture)->activeTextureHandle->vulkanTexture; /* Transition the attachment */ VULKAN_INTERNAL_ImageMemoryBarrier( @@ -7834,7 +7882,7 @@ static void VULKAN_BeginRenderPass( &texture->resourceAccessType ); - if (texture->renderTargetSampleCount > REFRESH_SAMPLECOUNT_1) + if (texture->sampleCount > VK_SAMPLE_COUNT_1_BIT) { msaaTexture = VULKAN_INTERNAL_FetchRenderTargetMSAATexture( renderer, @@ -7869,7 +7917,7 @@ static void VULKAN_BeginRenderPass( if (depthStencilAttachmentInfo != NULL) { - texture = ((VulkanTextureHandle*) depthStencilAttachmentInfo->texture)->vulkanTexture; + texture = ((VulkanTextureContainer*) depthStencilAttachmentInfo->texture)->activeTextureHandle->vulkanTexture; depthAspectFlags = VK_IMAGE_ASPECT_DEPTH_BIT; if (IsStencilFormat(texture->format)) @@ -7909,8 +7957,8 @@ static void VULKAN_BeginRenderPass( clearValues[i].color.float32[2] = colorAttachmentInfos[i].clearColor.z; clearValues[i].color.float32[3] = colorAttachmentInfos[i].clearColor.w; - texture = ((VulkanTextureHandle*) colorAttachmentInfos[i].texture)->vulkanTexture; - if (texture->renderTargetSampleCount > REFRESH_SAMPLECOUNT_1) + texture = ((VulkanTextureContainer*) colorAttachmentInfos[i].texture)->activeTextureHandle->vulkanTexture; + if (texture->sampleCount > VK_SAMPLE_COUNT_1_BIT) { clearValues[i+1].color.float32[0] = colorAttachmentInfos[i].clearColor.x; clearValues[i+1].color.float32[1] = colorAttachmentInfos[i].clearColor.y; @@ -7951,14 +7999,13 @@ static void VULKAN_BeginRenderPass( for (i = 0; i < colorAttachmentCount; i += 1) { vulkanCommandBuffer->renderPassColorTargetTextures[i] = - ((VulkanTextureHandle*) colorAttachmentInfos[i].texture)->vulkanTexture; + ((VulkanTextureContainer*) colorAttachmentInfos[i].texture)->activeTextureHandle->vulkanTexture; } vulkanCommandBuffer->renderPassColorTargetCount = colorAttachmentCount; if (depthStencilAttachmentInfo != NULL) { - vulkanCommandBuffer->renderPassDepthTexture = ((VulkanTextureHandle*) depthStencilAttachmentInfo->texture)->vulkanTexture; - } + vulkanCommandBuffer->renderPassDepthTexture = ((VulkanTextureContainer*) depthStencilAttachmentInfo->texture)->activeTextureHandle->vulkanTexture; } /* Set sensible default viewport state */ @@ -8125,7 +8172,7 @@ static void VULKAN_BindVertexBuffers( for (i = 0; i < bindingCount; i += 1) { - currentVulkanBuffer = ((VulkanBufferHandle*) pBuffers[i])->vulkanBuffer; + currentVulkanBuffer = ((VulkanBufferContainer*) pBuffers[i])->activeBufferHandle->vulkanBuffer; buffers[i] = currentVulkanBuffer->buffer; VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, currentVulkanBuffer); } @@ -8150,7 +8197,7 @@ static void VULKAN_BindIndexBuffer( ) { VulkanRenderer* renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; - VulkanBuffer* vulkanBuffer = ((VulkanBufferHandle*) gpuBuffer)->vulkanBuffer; + VulkanBuffer* vulkanBuffer = ((VulkanBufferContainer*) gpuBuffer)->activeBufferHandle->vulkanBuffer; VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, vulkanBuffer); @@ -8223,7 +8270,7 @@ static void VULKAN_BindComputeBuffers( for (i = 0; i < computePipeline->pipelineLayout->bufferDescriptorSetCache->bindingCount; i += 1) { - currentVulkanBuffer = ((VulkanBufferHandle*) pBuffers[i])->vulkanBuffer; + currentVulkanBuffer = ((VulkanBufferContainer*) pBuffers[i])->activeBufferHandle->vulkanBuffer; descriptorBufferInfos[i].buffer = currentVulkanBuffer->buffer; descriptorBufferInfos[i].offset = 0; @@ -8271,7 +8318,7 @@ static void VULKAN_BindComputeTextures( for (i = 0; i < computePipeline->pipelineLayout->imageDescriptorSetCache->bindingCount; i += 1) { - currentTexture = ((VulkanTextureHandle*) pTextures[i])->vulkanTexture; + currentTexture = ((VulkanTextureContainer*) pTextures[i])->activeTextureHandle->vulkanTexture; descriptorImageInfos[i].imageView = currentTexture->view; descriptorImageInfos[i].sampler = VK_NULL_HANDLE; descriptorImageInfos[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL; @@ -8469,8 +8516,18 @@ static void VULKAN_INTERNAL_DiscardActiveTexture( } /* No texture handle is available, generate a new one. */ - textureContainer->activeTextureHandle = VULKAN_INTERNAL_CreateTexture( - + textureContainer->activeTextureHandle = VULKAN_INTERNAL_CreateTextureHandle( + renderer, + textureContainer->activeTextureHandle->vulkanTexture->dimensions.width, + textureContainer->activeTextureHandle->vulkanTexture->dimensions.height, + textureContainer->activeTextureHandle->vulkanTexture->depth, + textureContainer->activeTextureHandle->vulkanTexture->isCube, + textureContainer->activeTextureHandle->vulkanTexture->levelCount, + textureContainer->activeTextureHandle->vulkanTexture->sampleCount, + textureContainer->activeTextureHandle->vulkanTexture->format, + textureContainer->activeTextureHandle->vulkanTexture->aspectFlags, + textureContainer->activeTextureHandle->vulkanTexture->usageFlags, + 0 ); EXPAND_ARRAY_IF_NEEDED( @@ -8632,9 +8689,17 @@ static void VULKAN_UploadToBuffer( VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; VulkanBufferContainer *transferBufferContainer = (VulkanBufferContainer*) transferBuffer; - VulkanBuffer *vulkanGpuBuffer = ((VulkanBufferHandle*) gpuBuffer)->vulkanBuffer; + VulkanBufferContainer *gpuBufferContainer = (VulkanBufferContainer*) gpuBuffer; VkBufferCopy bufferCopy; + if (option == REFRESH_COPYOPTIONS_SAFEDISCARD && SDL_AtomicGet(&gpuBufferContainer->activeBufferHandle->vulkanBuffer->referenceCount) > 0) + { + VULKAN_INTERNAL_DiscardActiveBuffer( + renderer, + gpuBufferContainer + ); + } + VULKAN_INTERNAL_BufferMemoryBarrier( renderer, vulkanCommandBuffer->commandBuffer, @@ -8646,7 +8711,7 @@ static void VULKAN_UploadToBuffer( renderer, vulkanCommandBuffer->commandBuffer, RESOURCE_ACCESS_TRANSFER_WRITE, - vulkanGpuBuffer + gpuBufferContainer->activeBufferHandle->vulkanBuffer ); bufferCopy.srcOffset = copyParams->srcOffset; @@ -8656,14 +8721,14 @@ static void VULKAN_UploadToBuffer( renderer->vkCmdCopyBuffer( vulkanCommandBuffer->commandBuffer, transferBufferContainer->activeBufferHandle->vulkanBuffer->buffer, - vulkanGpuBuffer->buffer, + gpuBufferContainer->activeBufferHandle->vulkanBuffer->buffer, 1, &bufferCopy ); VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, transferBufferContainer->activeBufferHandle->vulkanBuffer); - VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, vulkanGpuBuffer); - VULKAN_INTERNAL_TrackCopiedBuffer(renderer, vulkanCommandBuffer, vulkanGpuBuffer); + VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, gpuBufferContainer->activeBufferHandle->vulkanBuffer); + VULKAN_INTERNAL_TrackCopiedBuffer(renderer, vulkanCommandBuffer, gpuBufferContainer->activeBufferHandle->vulkanBuffer); } static void VULKAN_DownloadFromTexture( @@ -8671,33 +8736,42 @@ static void VULKAN_DownloadFromTexture( Refresh_CommandBuffer *commandBuffer, Refresh_TextureSlice *textureSlice, Refresh_TransferBuffer *transferBuffer, - Refresh_BufferImageCopy *copyParams + Refresh_BufferImageCopy *copyParams, + Refresh_TransferOptions option ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; - VulkanTexture *vulkanTexture = ((VulkanTextureHandle*) textureSlice->texture)->vulkanTexture; - VulkanTransferBufferContainer *transferBufferContainer = (VulkanTransferBufferContainer*) transferBuffer; + VulkanTextureContainer *vulkanTextureContainer = (VulkanTextureContainer*) textureSlice->texture; + VulkanBufferContainer *transferBufferContainer = (VulkanBufferContainer*) transferBuffer; VkBufferImageCopy imageCopy; + if (option == REFRESH_TRANSFEROPTIONS_SAFEDISCARD && SDL_AtomicGet(&transferBufferContainer->activeBufferHandle->vulkanBuffer->referenceCount) > 0) + { + VULKAN_INTERNAL_DiscardActiveBuffer( + renderer, + transferBufferContainer + ); + } + VULKAN_INTERNAL_BufferMemoryBarrier( renderer, vulkanCommandBuffer->commandBuffer, RESOURCE_ACCESS_TRANSFER_WRITE, - transferBufferContainer->activeBuffer->vulkanBuffer + transferBufferContainer->activeBufferHandle->vulkanBuffer ); VULKAN_INTERNAL_ImageMemoryBarrier( renderer, vulkanCommandBuffer->commandBuffer, RESOURCE_ACCESS_TRANSFER_READ, - vulkanTexture->aspectFlags, + vulkanTextureContainer->activeTextureHandle->vulkanTexture->aspectFlags, 0, - vulkanTexture->layerCount, + vulkanTextureContainer->activeTextureHandle->vulkanTexture->layerCount, 0, - vulkanTexture->levelCount, + vulkanTextureContainer->activeTextureHandle->vulkanTexture->levelCount, 0, - vulkanTexture->image, - &vulkanTexture->resourceAccessType + vulkanTextureContainer->activeTextureHandle->vulkanTexture->image, + &vulkanTextureContainer->activeTextureHandle->vulkanTexture->resourceAccessType ); imageCopy.imageExtent.width = textureSlice->w; @@ -8706,7 +8780,7 @@ static void VULKAN_DownloadFromTexture( imageCopy.imageOffset.x = textureSlice->x; imageCopy.imageOffset.y = textureSlice->y; imageCopy.imageOffset.z = textureSlice->z; - imageCopy.imageSubresource.aspectMask = vulkanTexture->aspectFlags; + imageCopy.imageSubresource.aspectMask = vulkanTextureContainer->activeTextureHandle->vulkanTexture->aspectFlags; imageCopy.imageSubresource.baseArrayLayer = textureSlice->baseLayer; imageCopy.imageSubresource.layerCount = textureSlice->layerCount; imageCopy.imageSubresource.mipLevel = textureSlice->mipLevel; @@ -8716,18 +8790,16 @@ static void VULKAN_DownloadFromTexture( renderer->vkCmdCopyImageToBuffer( vulkanCommandBuffer->commandBuffer, - vulkanTexture->image, - AccessMap[vulkanTexture->resourceAccessType].imageLayout, - transferBufferContainer->activeBuffer->vulkanBuffer->buffer, + vulkanTextureContainer->activeTextureHandle->vulkanTexture->image, + AccessMap[vulkanTextureContainer->activeTextureHandle->vulkanTexture->resourceAccessType].imageLayout, + transferBufferContainer->activeBufferHandle->vulkanBuffer->buffer, 1, &imageCopy ); - VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, transferBufferContainer->activeBuffer->vulkanBuffer); - VULKAN_INTERNAL_TrackTexture(renderer, vulkanCommandBuffer, vulkanTexture); - VULKAN_INTERNAL_TrackCopiedTexture(renderer, vulkanCommandBuffer, vulkanTexture); - - transferBufferContainer->activeBuffer->vulkanBuffer->preserveContentsOnDefrag = 1; + VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, transferBufferContainer->activeBufferHandle->vulkanBuffer); + VULKAN_INTERNAL_TrackTexture(renderer, vulkanCommandBuffer, vulkanTextureContainer->activeTextureHandle->vulkanTexture); + VULKAN_INTERNAL_TrackCopiedTexture(renderer, vulkanCommandBuffer, vulkanTextureContainer->activeTextureHandle->vulkanTexture); } static void VULKAN_DownloadFromBuffer( @@ -8735,26 +8807,35 @@ static void VULKAN_DownloadFromBuffer( Refresh_CommandBuffer *commandBuffer, Refresh_GpuBuffer *gpuBuffer, Refresh_TransferBuffer *transferBuffer, - Refresh_BufferCopy *copyParams + Refresh_BufferCopy *copyParams, + Refresh_TransferOptions option ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; - VulkanTransferBufferContainer *transferBufferContainer = (VulkanTransferBufferContainer*) transferBuffer; - VulkanBuffer *vulkanGpuBuffer = ((VulkanBufferHandle*) gpuBuffer)->vulkanBuffer; + VulkanBufferContainer *gpuBufferContainer = (VulkanBufferContainer*) gpuBuffer; + VulkanBufferContainer *transferBufferContainer = (VulkanBufferContainer*) transferBuffer; VkBufferCopy bufferCopy; + if (option == REFRESH_TRANSFEROPTIONS_SAFEDISCARD && SDL_AtomicGet(&transferBufferContainer->activeBufferHandle->vulkanBuffer->referenceCount) > 0) + { + VULKAN_INTERNAL_DiscardActiveBuffer( + renderer, + transferBufferContainer + ); + } + VULKAN_INTERNAL_BufferMemoryBarrier( renderer, vulkanCommandBuffer->commandBuffer, RESOURCE_ACCESS_TRANSFER_WRITE, - transferBufferContainer->activeBuffer->vulkanBuffer + transferBufferContainer->activeBufferHandle->vulkanBuffer ); VULKAN_INTERNAL_BufferMemoryBarrier( renderer, vulkanCommandBuffer->commandBuffer, RESOURCE_ACCESS_TRANSFER_READ, - vulkanGpuBuffer + gpuBufferContainer->activeBufferHandle->vulkanBuffer ); bufferCopy.srcOffset = copyParams->srcOffset; @@ -8763,43 +8844,50 @@ static void VULKAN_DownloadFromBuffer( renderer->vkCmdCopyBuffer( vulkanCommandBuffer->commandBuffer, - vulkanGpuBuffer->buffer, - transferBufferContainer->activeBuffer->vulkanBuffer->buffer, + gpuBufferContainer->activeBufferHandle->vulkanBuffer->buffer, + transferBufferContainer->activeBufferHandle->vulkanBuffer->buffer, 1, &bufferCopy ); - VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, transferBufferContainer->activeBuffer->vulkanBuffer); - VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, vulkanGpuBuffer); - VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, vulkanGpuBuffer); - - transferBufferContainer->activeBuffer->vulkanBuffer->preserveContentsOnDefrag = 1; + VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, transferBufferContainer->activeBufferHandle->vulkanBuffer); + VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, gpuBufferContainer->activeBufferHandle->vulkanBuffer); + VULKAN_INTERNAL_TrackCopiedBuffer(renderer, vulkanCommandBuffer, gpuBufferContainer->activeBufferHandle->vulkanBuffer); } static void VULKAN_CopyTextureToTexture( Refresh_Renderer *driverData, Refresh_CommandBuffer *commandBuffer, Refresh_TextureSlice *source, - Refresh_TextureSlice *destination + Refresh_TextureSlice *destination, + Refresh_CopyOptions option ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; - VulkanTexture *srcTexture = ((VulkanTextureHandle*) source->texture)->vulkanTexture; - VulkanTexture *dstTexture = ((VulkanTextureHandle*) destination->texture)->vulkanTexture; + VulkanTextureContainer *srcContainer = (VulkanTextureContainer*) source->texture; + VulkanTextureContainer *dstContainer = (VulkanTextureContainer*) destination->texture; VkImageCopy imageCopy; + if (option == REFRESH_COPYOPTIONS_SAFEDISCARD && SDL_AtomicGet(&dstContainer->activeTextureHandle->vulkanTexture->referenceCount) > 0) + { + VULKAN_INTERNAL_DiscardActiveTexture( + renderer, + dstContainer + ); + } + VULKAN_INTERNAL_ImageMemoryBarrier( renderer, vulkanCommandBuffer->commandBuffer, RESOURCE_ACCESS_TRANSFER_READ, VK_IMAGE_ASPECT_COLOR_BIT, 0, - srcTexture->layerCount, + srcContainer->activeTextureHandle->vulkanTexture->layerCount, 0, - srcTexture->levelCount, + srcContainer->activeTextureHandle->vulkanTexture->levelCount, 0, - srcTexture->image, - &srcTexture->resourceAccessType + srcContainer->activeTextureHandle->vulkanTexture->image, + &srcContainer->activeTextureHandle->vulkanTexture->resourceAccessType ); VULKAN_INTERNAL_ImageMemoryBarrier( @@ -8808,25 +8896,25 @@ static void VULKAN_CopyTextureToTexture( RESOURCE_ACCESS_TRANSFER_WRITE, VK_IMAGE_ASPECT_COLOR_BIT, 0, - dstTexture->layerCount, + dstContainer->activeTextureHandle->vulkanTexture->layerCount, 0, - dstTexture->levelCount, + dstContainer->activeTextureHandle->vulkanTexture->levelCount, 0, - dstTexture->image, - &dstTexture->resourceAccessType + dstContainer->activeTextureHandle->vulkanTexture->image, + &dstContainer->activeTextureHandle->vulkanTexture->resourceAccessType ); imageCopy.srcOffset.x = source->x; imageCopy.srcOffset.y = source->y; imageCopy.srcOffset.z = source->z; - imageCopy.srcSubresource.aspectMask = srcTexture->aspectFlags; + imageCopy.srcSubresource.aspectMask = srcContainer->activeTextureHandle->vulkanTexture->aspectFlags; imageCopy.srcSubresource.baseArrayLayer = source->baseLayer; imageCopy.srcSubresource.layerCount = source->layerCount; imageCopy.srcSubresource.mipLevel = source->mipLevel; imageCopy.dstOffset.x = destination->x; imageCopy.dstOffset.y = destination->y; imageCopy.dstOffset.z = destination->z; - imageCopy.dstSubresource.aspectMask = dstTexture->aspectFlags; + imageCopy.dstSubresource.aspectMask = dstContainer->activeTextureHandle->vulkanTexture->aspectFlags; imageCopy.dstSubresource.baseArrayLayer = destination->baseLayer; imageCopy.dstSubresource.layerCount = destination->layerCount; imageCopy.dstSubresource.mipLevel = destination->mipLevel; @@ -8836,18 +8924,18 @@ static void VULKAN_CopyTextureToTexture( renderer->vkCmdCopyImage( vulkanCommandBuffer->commandBuffer, - srcTexture->image, - AccessMap[srcTexture->resourceAccessType].imageLayout, - dstTexture->image, - AccessMap[dstTexture->resourceAccessType].imageLayout, + srcContainer->activeTextureHandle->vulkanTexture->image, + AccessMap[srcContainer->activeTextureHandle->vulkanTexture->resourceAccessType].imageLayout, + dstContainer->activeTextureHandle->vulkanTexture->image, + AccessMap[dstContainer->activeTextureHandle->vulkanTexture->resourceAccessType].imageLayout, 1, &imageCopy ); - VULKAN_INTERNAL_TrackTexture(renderer, vulkanCommandBuffer, srcTexture); - VULKAN_INTERNAL_TrackTexture(renderer, vulkanCommandBuffer, dstTexture); - VULKAN_INTERNAL_TrackCopiedTexture(renderer, vulkanCommandBuffer, srcTexture); - VULKAN_INTERNAL_TrackCopiedTexture(renderer, vulkanCommandBuffer, dstTexture); + VULKAN_INTERNAL_TrackTexture(renderer, vulkanCommandBuffer, srcContainer->activeTextureHandle->vulkanTexture); + VULKAN_INTERNAL_TrackTexture(renderer, vulkanCommandBuffer, dstContainer->activeTextureHandle->vulkanTexture); + VULKAN_INTERNAL_TrackCopiedTexture(renderer, vulkanCommandBuffer, srcContainer->activeTextureHandle->vulkanTexture); + VULKAN_INTERNAL_TrackCopiedTexture(renderer, vulkanCommandBuffer, dstContainer->activeTextureHandle->vulkanTexture); } static void VULKAN_CopyTextureToBuffer( @@ -8855,33 +8943,42 @@ static void VULKAN_CopyTextureToBuffer( Refresh_CommandBuffer *commandBuffer, Refresh_TextureSlice *textureSlice, Refresh_GpuBuffer *gpuBuffer, - Refresh_BufferImageCopy *copyParams + Refresh_BufferImageCopy *copyParams, + Refresh_CopyOptions option ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; - VulkanTexture *vulkanTexture = ((VulkanTextureHandle*) textureSlice->texture)->vulkanTexture; - VulkanBuffer *vulkanBuffer = ((VulkanBufferHandle*) gpuBuffer)->vulkanBuffer; + VulkanTextureContainer *textureContainer = (VulkanTextureContainer*) textureSlice->texture; + VulkanBufferContainer *bufferContainer = (VulkanBufferContainer*) gpuBuffer; VkBufferImageCopy imageCopy; + if (option == REFRESH_COPYOPTIONS_SAFEDISCARD && SDL_AtomicGet(&bufferContainer->activeBufferHandle->vulkanBuffer->referenceCount) > 0) + { + VULKAN_INTERNAL_DiscardActiveBuffer( + renderer, + bufferContainer + ); + } + VULKAN_INTERNAL_ImageMemoryBarrier( renderer, vulkanCommandBuffer->commandBuffer, RESOURCE_ACCESS_TRANSFER_READ, - vulkanTexture->aspectFlags, + textureContainer->activeTextureHandle->vulkanTexture->aspectFlags, 0, - vulkanTexture->layerCount, + textureContainer->activeTextureHandle->vulkanTexture->layerCount, 0, - vulkanTexture->levelCount, + textureContainer->activeTextureHandle->vulkanTexture->levelCount, 0, - vulkanTexture->image, - &vulkanTexture->resourceAccessType + textureContainer->activeTextureHandle->vulkanTexture->image, + &textureContainer->activeTextureHandle->vulkanTexture->resourceAccessType ); VULKAN_INTERNAL_BufferMemoryBarrier( renderer, vulkanCommandBuffer->commandBuffer, RESOURCE_ACCESS_TRANSFER_WRITE, - vulkanBuffer + bufferContainer->activeBufferHandle->vulkanBuffer ); imageCopy.imageExtent.width = textureSlice->w; @@ -8890,7 +8987,7 @@ static void VULKAN_CopyTextureToBuffer( imageCopy.imageOffset.x = textureSlice->x; imageCopy.imageOffset.y = textureSlice->y; imageCopy.imageOffset.z = textureSlice->z; - imageCopy.imageSubresource.aspectMask = vulkanTexture->aspectFlags; + imageCopy.imageSubresource.aspectMask = textureContainer->activeTextureHandle->vulkanTexture->aspectFlags; imageCopy.imageSubresource.baseArrayLayer = textureSlice->baseLayer; imageCopy.imageSubresource.layerCount = textureSlice->layerCount; imageCopy.imageSubresource.mipLevel = textureSlice->mipLevel; @@ -8900,17 +8997,17 @@ static void VULKAN_CopyTextureToBuffer( renderer->vkCmdCopyImageToBuffer( vulkanCommandBuffer->commandBuffer, - vulkanTexture->image, - AccessMap[vulkanTexture->resourceAccessType].imageLayout, - vulkanBuffer->buffer, + textureContainer->activeTextureHandle->vulkanTexture->image, + AccessMap[textureContainer->activeTextureHandle->vulkanTexture->resourceAccessType].imageLayout, + bufferContainer->activeBufferHandle->vulkanBuffer->buffer, 1, &imageCopy ); - VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, vulkanBuffer); - VULKAN_INTERNAL_TrackTexture(renderer, vulkanCommandBuffer, vulkanTexture); - VULKAN_INTERNAL_TrackCopiedBuffer(renderer, vulkanCommandBuffer, vulkanBuffer); - VULKAN_INTERNAL_TrackCopiedTexture(renderer, vulkanCommandBuffer, vulkanTexture); + VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, bufferContainer->activeBufferHandle->vulkanBuffer); + VULKAN_INTERNAL_TrackTexture(renderer, vulkanCommandBuffer, textureContainer->activeTextureHandle->vulkanTexture); + VULKAN_INTERNAL_TrackCopiedBuffer(renderer, vulkanCommandBuffer, bufferContainer->activeBufferHandle->vulkanBuffer); + VULKAN_INTERNAL_TrackCopiedTexture(renderer, vulkanCommandBuffer, textureContainer->activeTextureHandle->vulkanTexture); } static void VULKAN_CopyBufferToTexture( @@ -8918,33 +9015,42 @@ static void VULKAN_CopyBufferToTexture( Refresh_CommandBuffer *commandBuffer, Refresh_GpuBuffer *gpuBuffer, Refresh_TextureSlice *textureSlice, - Refresh_BufferImageCopy *copyParams + Refresh_BufferImageCopy *copyParams, + Refresh_CopyOptions option ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; - VulkanBuffer *vulkanBuffer = ((VulkanBufferHandle*) gpuBuffer)->vulkanBuffer; - VulkanTexture *vulkanTexture = ((VulkanTextureHandle*) textureSlice->texture)->vulkanTexture; + VulkanBufferContainer *bufferContainer = (VulkanBufferContainer*) gpuBuffer; + VulkanTextureContainer *textureContainer = (VulkanTextureContainer*) textureSlice->texture; VkBufferImageCopy imageCopy; + if (option == REFRESH_COPYOPTIONS_SAFEDISCARD && SDL_AtomicGet(&textureContainer->activeTextureHandle->vulkanTexture->referenceCount) > 0) + { + VULKAN_INTERNAL_DiscardActiveTexture( + renderer, + textureContainer + ); + } + VULKAN_INTERNAL_BufferMemoryBarrier( renderer, vulkanCommandBuffer->commandBuffer, RESOURCE_ACCESS_TRANSFER_READ, - vulkanBuffer + bufferContainer->activeBufferHandle->vulkanBuffer ); VULKAN_INTERNAL_ImageMemoryBarrier( renderer, vulkanCommandBuffer->commandBuffer, RESOURCE_ACCESS_TRANSFER_WRITE, - vulkanTexture->aspectFlags, + textureContainer->activeTextureHandle->vulkanTexture->aspectFlags, 0, - vulkanTexture->layerCount, + textureContainer->activeTextureHandle->vulkanTexture->layerCount, 0, - vulkanTexture->levelCount, + textureContainer->activeTextureHandle->vulkanTexture->levelCount, 0, - vulkanTexture->image, - &vulkanTexture->resourceAccessType + textureContainer->activeTextureHandle->vulkanTexture->image, + &textureContainer->activeTextureHandle->vulkanTexture->resourceAccessType ); imageCopy.imageExtent.width = textureSlice->w; @@ -8953,7 +9059,7 @@ static void VULKAN_CopyBufferToTexture( imageCopy.imageOffset.x = textureSlice->x; imageCopy.imageOffset.y = textureSlice->y; imageCopy.imageOffset.z = textureSlice->z; - imageCopy.imageSubresource.aspectMask = vulkanTexture->aspectFlags; + imageCopy.imageSubresource.aspectMask = textureContainer->activeTextureHandle->vulkanTexture->aspectFlags; imageCopy.imageSubresource.baseArrayLayer = textureSlice->baseLayer; imageCopy.imageSubresource.layerCount = textureSlice->layerCount; imageCopy.imageSubresource.mipLevel = textureSlice->mipLevel; @@ -8963,17 +9069,17 @@ static void VULKAN_CopyBufferToTexture( renderer->vkCmdCopyBufferToImage( vulkanCommandBuffer->commandBuffer, - vulkanBuffer->buffer, - vulkanTexture->image, - AccessMap[vulkanTexture->resourceAccessType].imageLayout, + bufferContainer->activeBufferHandle->vulkanBuffer->buffer, + textureContainer->activeTextureHandle->vulkanTexture->image, + AccessMap[textureContainer->activeTextureHandle->vulkanTexture->resourceAccessType].imageLayout, 1, &imageCopy ); - VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, vulkanBuffer); - VULKAN_INTERNAL_TrackTexture(renderer, vulkanCommandBuffer, vulkanTexture); - VULKAN_INTERNAL_TrackCopiedBuffer(renderer, vulkanCommandBuffer, vulkanBuffer); - VULKAN_INTERNAL_TrackCopiedTexture(renderer, vulkanCommandBuffer, vulkanTexture); + VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, bufferContainer->activeBufferHandle->vulkanBuffer); + VULKAN_INTERNAL_TrackTexture(renderer, vulkanCommandBuffer, textureContainer->activeTextureHandle->vulkanTexture); + VULKAN_INTERNAL_TrackCopiedBuffer(renderer, vulkanCommandBuffer, bufferContainer->activeBufferHandle->vulkanBuffer); + VULKAN_INTERNAL_TrackCopiedTexture(renderer, vulkanCommandBuffer, textureContainer->activeTextureHandle->vulkanTexture); } static void VULKAN_CopyBufferToBuffer( @@ -8981,26 +9087,35 @@ static void VULKAN_CopyBufferToBuffer( Refresh_CommandBuffer *commandBuffer, Refresh_GpuBuffer *source, Refresh_GpuBuffer *destination, - Refresh_BufferCopy *copyParams + Refresh_BufferCopy *copyParams, + Refresh_CopyOptions option ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; - VulkanBuffer *vulkanSrcBuffer = ((VulkanBufferHandle*) source)->vulkanBuffer; - VulkanBuffer *vulkanDstBuffer = ((VulkanBufferHandle*) destination)->vulkanBuffer; + VulkanBufferContainer *srcContainer = (VulkanBufferContainer*) source; + VulkanBufferContainer *dstContainer = (VulkanBufferContainer*) destination; VkBufferCopy bufferCopy; + if (option == REFRESH_COPYOPTIONS_SAFEDISCARD && SDL_AtomicGet(&dstContainer->activeBufferHandle->vulkanBuffer->referenceCount) > 0) + { + VULKAN_INTERNAL_DiscardActiveBuffer( + renderer, + dstContainer + ); + } + VULKAN_INTERNAL_BufferMemoryBarrier( renderer, vulkanCommandBuffer->commandBuffer, RESOURCE_ACCESS_TRANSFER_READ, - vulkanSrcBuffer + srcContainer->activeBufferHandle->vulkanBuffer ); VULKAN_INTERNAL_BufferMemoryBarrier( renderer, vulkanCommandBuffer->commandBuffer, RESOURCE_ACCESS_TRANSFER_WRITE, - vulkanDstBuffer + dstContainer->activeBufferHandle->vulkanBuffer ); bufferCopy.srcOffset = copyParams->srcOffset; @@ -9009,16 +9124,16 @@ static void VULKAN_CopyBufferToBuffer( renderer->vkCmdCopyBuffer( vulkanCommandBuffer->commandBuffer, - vulkanSrcBuffer->buffer, - vulkanDstBuffer->buffer, + srcContainer->activeBufferHandle->vulkanBuffer->buffer, + dstContainer->activeBufferHandle->vulkanBuffer->buffer, 1, &bufferCopy ); - VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, vulkanSrcBuffer); - VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, vulkanDstBuffer); - VULKAN_INTERNAL_TrackCopiedBuffer(renderer, vulkanCommandBuffer, vulkanSrcBuffer); - VULKAN_INTERNAL_TrackCopiedBuffer(renderer, vulkanCommandBuffer, vulkanDstBuffer); + VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, srcContainer->activeBufferHandle->vulkanBuffer); + VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, dstContainer->activeBufferHandle->vulkanBuffer); + VULKAN_INTERNAL_TrackCopiedBuffer(renderer, vulkanCommandBuffer, srcContainer->activeBufferHandle->vulkanBuffer); + VULKAN_INTERNAL_TrackCopiedBuffer(renderer, vulkanCommandBuffer, dstContainer->activeBufferHandle->vulkanBuffer); } static void VULKAN_GenerateMipmaps( @@ -9028,7 +9143,7 @@ static void VULKAN_GenerateMipmaps( ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; - VulkanTexture *vulkanTexture = ((VulkanTextureHandle*) texture)->vulkanTexture; + VulkanTexture *vulkanTexture = ((VulkanTextureContainer*) texture)->activeTextureHandle->vulkanTexture; VulkanResourceAccessType *levelAccessType; VkImageBlit blit; uint32_t level; @@ -9586,7 +9701,7 @@ static Refresh_Texture* VULKAN_AcquireSwapchainTexture( WindowData *windowData; VulkanSwapchainData *swapchainData; VkResult acquireResult = VK_SUCCESS; - VulkanTextureHandle *swapchainTextureContainer = NULL; + VulkanTextureContainer *swapchainTextureContainer = NULL; VulkanPresentData *presentData; windowData = VULKAN_INTERNAL_FetchWindowData(windowHandle); @@ -9666,8 +9781,8 @@ static Refresh_Texture* VULKAN_AcquireSwapchainTexture( 0, 1, 0, - swapchainTextureContainer->vulkanTexture->image, - &swapchainTextureContainer->vulkanTexture->resourceAccessType + swapchainTextureContainer->activeTextureHandle->vulkanTexture->image, + &swapchainTextureContainer->activeTextureHandle->vulkanTexture->resourceAccessType ); /* Set up present struct */ @@ -10335,8 +10450,7 @@ static uint8_t VULKAN_INTERNAL_DefragmentMemory( currentRegion->vulkanBuffer->requireHostVisible, currentRegion->vulkanBuffer->preferHostLocal, currentRegion->vulkanBuffer->preferDeviceLocal, - 0, - currentRegion->vulkanBuffer->preserveContentsOnDefrag + 0 ); if (newBuffer == NULL) @@ -10348,10 +10462,8 @@ static uint8_t VULKAN_INTERNAL_DefragmentMemory( originalResourceAccessType = currentRegion->vulkanBuffer->resourceAccessType; /* Copy buffer contents if necessary */ - if ( - originalResourceAccessType != RESOURCE_ACCESS_NONE && - currentRegion->vulkanBuffer->preserveContentsOnDefrag - ) { + if (originalResourceAccessType != RESOURCE_ACCESS_NONE) + { VULKAN_INTERNAL_BufferMemoryBarrier( renderer, commandBuffer->commandBuffer, @@ -10413,7 +10525,8 @@ static uint8_t VULKAN_INTERNAL_DefragmentMemory( currentRegion->vulkanTexture->sampleCount, currentRegion->vulkanTexture->format, currentRegion->vulkanTexture->aspectFlags, - currentRegion->vulkanTexture->usageFlags + currentRegion->vulkanTexture->usageFlags, + 0 ); if (newTexture == NULL)