mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-12-29 15:46:07 +00:00
Handle indirect draw counts with non-zero draw starts properly (#2593)
This commit is contained in:
parent
15e7fe3ac9
commit
82cefc8dd3
|
@ -8,6 +8,14 @@ namespace Ryujinx.Cpu
|
|||
{
|
||||
public interface IVirtualMemoryManagerTracked : IVirtualMemoryManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Reads data from CPU mapped memory, with read tracking
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the data being read</typeparam>
|
||||
/// <param name="va">Virtual address of the data in memory</param>
|
||||
/// <returns>The data</returns>
|
||||
T ReadTracked<T>(ulong va) where T : unmanaged;
|
||||
|
||||
/// <summary>
|
||||
/// Writes data to CPU mapped memory, without write tracking.
|
||||
/// </summary>
|
||||
|
|
|
@ -117,7 +117,7 @@ namespace Ryujinx.Cpu
|
|||
/// <inheritdoc/>
|
||||
public T Read<T>(ulong va) where T : unmanaged
|
||||
{
|
||||
return MemoryMarshal.Cast<byte, T>(GetSpan(va, Unsafe.SizeOf<T>(), true))[0];
|
||||
return MemoryMarshal.Cast<byte, T>(GetSpan(va, Unsafe.SizeOf<T>()))[0];
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
|
|
@ -2,8 +2,6 @@ using Ryujinx.Common.Logging;
|
|||
using Ryujinx.Graphics.Device;
|
||||
using Ryujinx.Graphics.GAL;
|
||||
using Ryujinx.Graphics.Gpu.Engine.GPFifo;
|
||||
using Ryujinx.Graphics.Gpu.Engine.Threed;
|
||||
using Ryujinx.Graphics.Gpu.Memory;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
@ -66,17 +64,42 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
|
|||
int arg2 = FetchParam().Word;
|
||||
int arg3 = FetchParam().Word;
|
||||
|
||||
int startOffset = arg0;
|
||||
int endOffset = arg1;
|
||||
int startDraw = arg0;
|
||||
int endDraw = arg1;
|
||||
var topology = (PrimitiveTopology)arg2;
|
||||
int paddingWords = arg3;
|
||||
int maxDrawCount = endOffset - startOffset;
|
||||
int stride = paddingWords * 4 + 0x14;
|
||||
int indirectBufferSize = maxDrawCount * stride;
|
||||
|
||||
ulong parameterBufferGpuVa = FetchParam().GpuVa;
|
||||
ulong indirectBufferGpuVa = 0;
|
||||
|
||||
int maxDrawCount = endDraw - startDraw;
|
||||
|
||||
if (startDraw != 0)
|
||||
{
|
||||
int drawCount = _processor.MemoryManager.Read<int>(parameterBufferGpuVa, tracked: true);
|
||||
|
||||
// Calculate maximum draw count based on the previous draw count and current draw count.
|
||||
if ((uint)drawCount <= (uint)startDraw)
|
||||
{
|
||||
// The start draw is past our total draw count, so all draws were already performed.
|
||||
maxDrawCount = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Perform just the missing number of draws.
|
||||
maxDrawCount = (int)Math.Min((uint)maxDrawCount, (uint)(drawCount - startDraw));
|
||||
}
|
||||
}
|
||||
|
||||
if (maxDrawCount == 0)
|
||||
{
|
||||
Fifo.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
int indirectBufferSize = maxDrawCount * stride;
|
||||
|
||||
ulong indirectBufferGpuVa = 0;
|
||||
int indexCount = 0;
|
||||
|
||||
for (int i = 0; i < maxDrawCount; i++)
|
||||
|
@ -106,8 +129,10 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
|
|||
// It should be empty at this point, but clear it just to be safe.
|
||||
Fifo.Clear();
|
||||
|
||||
var parameterBuffer = _processor.MemoryManager.Physical.BufferCache.GetGpuBufferRange(_processor.MemoryManager, parameterBufferGpuVa, 4);
|
||||
var indirectBuffer = _processor.MemoryManager.Physical.BufferCache.GetGpuBufferRange(_processor.MemoryManager, indirectBufferGpuVa, (ulong)indirectBufferSize);
|
||||
var bufferCache = _processor.MemoryManager.Physical.BufferCache;
|
||||
|
||||
var parameterBuffer = bufferCache.GetGpuBufferRange(_processor.MemoryManager, parameterBufferGpuVa, 4);
|
||||
var indirectBuffer = bufferCache.GetGpuBufferRange(_processor.MemoryManager, indirectBufferGpuVa, (ulong)indirectBufferSize);
|
||||
|
||||
_processor.ThreedClass.MultiDrawIndirectCount(indexCount, topology, indirectBuffer, parameterBuffer, maxDrawCount, stride);
|
||||
}
|
||||
|
|
|
@ -63,10 +63,33 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||
/// </summary>
|
||||
/// <typeparam name="T">Type of the data</typeparam>
|
||||
/// <param name="va">GPU virtual address where the data is located</param>
|
||||
/// <param name="tracked">True if read tracking is triggered on the memory region</param>
|
||||
/// <returns>The data at the specified memory location</returns>
|
||||
public T Read<T>(ulong va) where T : unmanaged
|
||||
public T Read<T>(ulong va, bool tracked = false) where T : unmanaged
|
||||
{
|
||||
return MemoryMarshal.Cast<byte, T>(GetSpan(va, Unsafe.SizeOf<T>()))[0];
|
||||
int size = Unsafe.SizeOf<T>();
|
||||
|
||||
if (IsContiguous(va, size))
|
||||
{
|
||||
ulong address = Translate(va);
|
||||
|
||||
if (tracked)
|
||||
{
|
||||
return Physical.ReadTracked<T>(address);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Physical.Read<T>(address);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Span<byte> data = new byte[size];
|
||||
|
||||
ReadImpl(va, data, tracked);
|
||||
|
||||
return MemoryMarshal.Cast<byte, T>(data)[0];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -139,11 +139,22 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||
/// Reads data from the application process.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the structure</typeparam>
|
||||
/// <param name="gpuVa">Address to read from</param>
|
||||
/// <param name="address">Address to read from</param>
|
||||
/// <returns>The data at the specified memory location</returns>
|
||||
public T Read<T>(ulong address) where T : unmanaged
|
||||
{
|
||||
return MemoryMarshal.Cast<byte, T>(GetSpan(address, Unsafe.SizeOf<T>()))[0];
|
||||
return _cpuMemory.Read<T>(address);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads data from the application process, with write tracking.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the structure</typeparam>
|
||||
/// <param name="address">Address to read from</param>
|
||||
/// <returns>The data at the specified memory location</returns>
|
||||
public T ReadTracked<T>(ulong address) where T : unmanaged
|
||||
{
|
||||
return _cpuMemory.ReadTracked<T>(address);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in a new issue