aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Vulkan/VertexBufferState.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/VertexBufferState.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/VertexBufferState.cs')
-rw-r--r--Ryujinx.Graphics.Vulkan/VertexBufferState.cs49
1 files changed, 30 insertions, 19 deletions
diff --git a/Ryujinx.Graphics.Vulkan/VertexBufferState.cs b/Ryujinx.Graphics.Vulkan/VertexBufferState.cs
index 5710f0b1..661bb774 100644
--- a/Ryujinx.Graphics.Vulkan/VertexBufferState.cs
+++ b/Ryujinx.Graphics.Vulkan/VertexBufferState.cs
@@ -57,37 +57,48 @@ namespace Ryujinx.Graphics.Vulkan
if (gd.NeedsVertexBufferAlignment(AttributeScalarAlignment, out int alignment) && (_stride % alignment) != 0)
{
autoBuffer = gd.BufferManager.GetAlignedVertexBuffer(cbs, _handle, _offset, _size, _stride, alignment);
- int stride = (_stride + (alignment - 1)) & -alignment;
- var buffer = autoBuffer.Get(cbs, _offset, _size).Value;
-
- if (gd.Capabilities.SupportsExtendedDynamicState)
- {
- gd.ExtendedDynamicStateApi.CmdBindVertexBuffers2(
- cbs.CommandBuffer,
- binding,
- 1,
- buffer,
- 0,
- (ulong)(_size / _stride) * (ulong)stride,
- (ulong)stride);
- }
- else
+ if (autoBuffer != null)
{
- gd.Api.CmdBindVertexBuffers(cbs.CommandBuffer, binding, 1, buffer, 0);
+ int stride = (_stride + (alignment - 1)) & -alignment;
+ int newSize = (_size / _stride) * stride;
+
+ var buffer = autoBuffer.Get(cbs, 0, newSize).Value;
+
+ if (gd.Capabilities.SupportsExtendedDynamicState)
+ {
+ gd.ExtendedDynamicStateApi.CmdBindVertexBuffers2(
+ cbs.CommandBuffer,
+ binding,
+ 1,
+ buffer,
+ 0,
+ (ulong)newSize,
+ (ulong)stride);
+ }
+ else
+ {
+ gd.Api.CmdBindVertexBuffers(cbs.CommandBuffer, binding, 1, buffer, 0);
+ }
+
+ _buffer = autoBuffer;
}
- _buffer = autoBuffer;
- state.Internal.VertexBindingDescriptions[DescriptorIndex].Stride = (uint)stride;
+ state.Internal.VertexBindingDescriptions[DescriptorIndex].Stride = (uint)_stride;
return;
}
else
{
- autoBuffer = gd.BufferManager.GetBuffer(cbs.CommandBuffer, _handle, false, out int _);
+ autoBuffer = gd.BufferManager.GetBuffer(cbs.CommandBuffer, _handle, false, out int size);
// The original stride must be reapplied in case it was rewritten.
state.Internal.VertexBindingDescriptions[DescriptorIndex].Stride = (uint)_stride;
+
+ if (_offset >= size)
+ {
+ autoBuffer = null;
+ }
}
}