aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Vulkan/BufferHolder.cs
diff options
context:
space:
mode:
authorriperiperi <rhy3756547@hotmail.com>2022-10-16 23:38:58 +0100
committerGitHub <noreply@github.com>2022-10-16 19:38:58 -0300
commit0dbe45ae37a7aea1bf86787a638ddb68df97a50c (patch)
treeced41a7831a8ba175605a9a39e4da33bfd2c1141 /Ryujinx.Graphics.Vulkan/BufferHolder.cs
parent2b50e52e4815f5dc2306ebfec6b15625ff864839 (diff)
Fix various issues caused by Vertex/Index buffer conversions (#3762)1.1.304
* Fix various issues caused by #3679 - The arguments for the 0th dummy vertex buffer were incorrect - it was given an offset of 16 rather than a size of 16. - The wrong size was used when doing `autoBuffer.Get` on a converted vertex buffer. - The possibility of a vertex buffer being disposed and then rebound can rebindings to find a different buffer where the current range is out of bounds. Avoid binding when out of range to prevent validation errors. - The above also affects generation of converted buffers, which was a bit more fatal. Conversion functions now attempt to bound input offset/size. * Fix offset for converted buffer
Diffstat (limited to 'Ryujinx.Graphics.Vulkan/BufferHolder.cs')
-rw-r--r--Ryujinx.Graphics.Vulkan/BufferHolder.cs27
1 files changed, 27 insertions, 0 deletions
diff --git a/Ryujinx.Graphics.Vulkan/BufferHolder.cs b/Ryujinx.Graphics.Vulkan/BufferHolder.cs
index 20571253..fb133266 100644
--- a/Ryujinx.Graphics.Vulkan/BufferHolder.cs
+++ b/Ryujinx.Graphics.Vulkan/BufferHolder.cs
@@ -386,8 +386,25 @@ namespace Ryujinx.Graphics.Vulkan
_waitable.WaitForFences(_gd.Api, _device, offset, size);
}
+ private bool BoundToRange(int offset, ref int size)
+ {
+ if (offset >= Size)
+ {
+ return false;
+ }
+
+ size = Math.Min(Size - offset, size);
+
+ return true;
+ }
+
public Auto<DisposableBuffer> GetBufferI8ToI16(CommandBufferScoped cbs, int offset, int size)
{
+ if (!BoundToRange(offset, ref size))
+ {
+ return null;
+ }
+
var key = new I8ToI16CacheKey(_gd);
if (!_cachedConvertedBuffers.TryGetValue(offset, size, key, out var holder))
@@ -407,6 +424,11 @@ namespace Ryujinx.Graphics.Vulkan
public Auto<DisposableBuffer> GetAlignedVertexBuffer(CommandBufferScoped cbs, int offset, int size, int stride, int alignment)
{
+ if (!BoundToRange(offset, ref size))
+ {
+ return null;
+ }
+
var key = new AlignedVertexBufferCacheKey(_gd, stride, alignment);
if (!_cachedConvertedBuffers.TryGetValue(offset, size, key, out var holder))
@@ -428,6 +450,11 @@ namespace Ryujinx.Graphics.Vulkan
public Auto<DisposableBuffer> GetBufferTopologyConversion(CommandBufferScoped cbs, int offset, int size, IndexBufferPattern pattern, int indexSize)
{
+ if (!BoundToRange(offset, ref size))
+ {
+ return null;
+ }
+
var key = new TopologyConversionCacheKey(_gd, pattern, indexSize);
if (!_cachedConvertedBuffers.TryGetValue(offset, size, key, out var holder))