Skip to content

Commit d4d5e75

Browse files
committed
fix: Vulkan: transition IOSurface-imported textures to shader resource at creation
1 parent de9c179 commit d4d5e75

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

sources/engine/Stride.Graphics/Vulkan/Texture.Apple.Vulkan.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ partial void TryInitializeImportedImage()
2626
GetViewSliceBounds(ViewType, ref arraySlice, ref mipLevel, out var arrayOrDepthCount, out var mipCount);
2727
NativeResourceRange = new VkImageSubresourceRange(NativeImageAspect, (uint)mipLevel, (uint)mipCount, (uint)arraySlice, (uint)arrayOrDepthCount);
2828

29-
// Image starts Undefined per vkCreateImage; Stride will emit the transition to
30-
// ShaderReadOnlyOptimal on first sampler bind (CommandList barrier path).
31-
NativeLayout = VkImageLayout.Undefined;
32-
NativeAccessMask = VkAccessFlags.None;
33-
NativePipelineStageMask = VkPipelineStageFlags.TopOfPipe;
34-
LayoutTracker.Initialize(BarrierLayout.Undefined, ArraySize * MipLevelCount);
29+
// Transition to the shader-resource resting layout right away; nothing else will
30+
// transition this texture before it is sampled. The Undefined source layout is safe
31+
// here: MoltenVK maps layout transitions to no-ops and keeps the IOSurface contents.
32+
NativeLayout = VkImageLayout.ShaderReadOnlyOptimal;
33+
NativeAccessMask = VkAccessFlags.ShaderRead;
34+
NativePipelineStageMask = VkPipelineStageFlags.VertexInput | VkPipelineStageFlags.FragmentShader | VkPipelineStageFlags.ComputeShader;
35+
LayoutTracker.Initialize(BarrierLayout.ShaderResource, ArraySize * MipLevelCount);
36+
InitializeData(null);
3537
IsInitialized = true;
3638
importedImageHandled = true;
3739
}

0 commit comments

Comments
 (0)