Change 3D texture memory barrier sub-resource range to be maintenance9 compatible.

(cherry picked from commit 5d63a4cad2)
This commit is contained in:
Torbjorn Laedre
2026-04-10 15:56:06 +02:00
committed by Sam Lantinga
parent ef9963df0d
commit 1704eb5e2e

View File

@@ -2691,10 +2691,17 @@ static void VULKAN_INTERNAL_TextureSubresourceMemoryBarrier(
memoryBarrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
memoryBarrier.image = textureSubresource->parent->image;
memoryBarrier.subresourceRange.aspectMask = textureSubresource->parent->aspectFlags;
memoryBarrier.subresourceRange.baseArrayLayer = textureSubresource->layer;
memoryBarrier.subresourceRange.layerCount = 1;
memoryBarrier.subresourceRange.baseMipLevel = textureSubresource->level;
memoryBarrier.subresourceRange.levelCount = 1;
memoryBarrier.subresourceRange.baseArrayLayer = textureSubresource->layer;
memoryBarrier.subresourceRange.layerCount = 1;
// VK_KHR_maintenance9 adds the ability to independently transition arbitrary subsets of slices in a 3D texture,
// we need to extend the barrier layer count in order to preserve intended behaviour when that extension is enabled.
// See https://docs.vulkan.org/features/latest/features/proposals/VK_KHR_maintenance9.html#_barriers_with_2d_array_compatible_3d_images
if (textureSubresource->parent->container->header.info.type == SDL_GPU_TEXTURETYPE_3D) {
memoryBarrier.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
}
if (sourceUsageMode == VULKAN_TEXTURE_USAGE_MODE_UNINITIALIZED) {
srcStages = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
@@ -5955,12 +5962,6 @@ static void VULKAN_INTERNAL_CycleActiveTexture(
renderer,
&container->header.info);
VULKAN_INTERNAL_TextureTransitionToDefaultUsage(
renderer,
commandBuffer,
VULKAN_TEXTURE_USAGE_MODE_UNINITIALIZED,
texture);
if (!texture) {
return;
}
@@ -5978,6 +5979,13 @@ static void VULKAN_INTERNAL_CycleActiveTexture(
container->textureCount += 1;
container->activeTexture = texture;
// Transition texture after storing it as the memory barrier might need to read the texture's container info
VULKAN_INTERNAL_TextureTransitionToDefaultUsage(
renderer,
commandBuffer,
VULKAN_TEXTURE_USAGE_MODE_UNINITIALIZED,
texture);
}
static VulkanBuffer *VULKAN_INTERNAL_PrepareBufferForWrite(