Skip to content

Commit

Permalink
[Vulkan] Fix a Veldrid validation issue when a shared Vulkan staging …
Browse files Browse the repository at this point in the history
…Texture is re-used as a different format.
  • Loading branch information
mellinoe committed Apr 11, 2018
1 parent 25db1e0 commit b1cbac3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Veldrid/Vk/VkGraphicsDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ private VkTexture GetFreeStagingTexture(uint width, uint height, uint depth, Pix
if (tex.Memory.Size >= totalSize)
{
_availableStagingTextures.RemoveAt(i);
tex.SetStagingDimensions(width, height, depth);
tex.SetStagingDimensions(width, height, depth, format);
return tex;
}
}
Expand All @@ -1078,7 +1078,7 @@ private VkTexture GetFreeStagingTexture(uint width, uint height, uint depth, Pix
uint texHeight = Math.Max(256, height);
VkTexture newTex = (VkTexture)ResourceFactory.CreateTexture(TextureDescription.Texture3D(
texWidth, texHeight, depth, 1, format, TextureUsage.Staging));
newTex.SetStagingDimensions(width, height, depth);
newTex.SetStagingDimensions(width, height, depth, format);

return newTex;
}
Expand Down
10 changes: 6 additions & 4 deletions src/Veldrid/Vk/VkTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal unsafe class VkTexture : Texture
private readonly VkImage _optimalImage;
private readonly VkMemoryBlock _memoryBlock;
private readonly Vulkan.VkBuffer _stagingBuffer;
private PixelFormat _format; // Static for regular images -- may change for shared staging images
private readonly uint _actualImageArrayLayers;
private bool _destroyed;

Expand All @@ -26,7 +27,7 @@ internal unsafe class VkTexture : Texture

public override uint Depth => _depth;

public override PixelFormat Format { get; }
public override PixelFormat Format => _format;

public override uint MipLevels { get; }

Expand Down Expand Up @@ -60,7 +61,7 @@ internal VkTexture(VkGraphicsDevice gd, ref TextureDescription description)
_actualImageArrayLayers = isCubemap
? 6 * ArrayLayers
: ArrayLayers;
Format = description.Format;
_format = description.Format;
Usage = description.Usage;
Type = description.Type;
SampleCount = description.SampleCount;
Expand Down Expand Up @@ -172,7 +173,7 @@ internal VkTexture(VkGraphicsDevice gd, ref TextureDescription description)
_height = height;
_depth = 1;
VkFormat = vkFormat;
Format = VkFormats.VkToVdPixelFormat(VkFormat);
_format = VkFormats.VkToVdPixelFormat(VkFormat);
ArrayLayers = arrayLayers;
Usage = usage;
SampleCount = sampleCount;
Expand Down Expand Up @@ -310,13 +311,14 @@ public override string Name
}
}

internal void SetStagingDimensions(uint width, uint height, uint depth)
internal void SetStagingDimensions(uint width, uint height, uint depth, PixelFormat format)
{
Debug.Assert(_stagingBuffer != Vulkan.VkBuffer.Null);
Debug.Assert(Usage == TextureUsage.Staging);
_width = width;
_height = height;
_depth = depth;
_format = format;
}

public override void Dispose()
Expand Down

0 comments on commit b1cbac3

Please sign in to comment.