From 8a6607540ea8933ef9f1f0ff40d910d5bfc3b600 Mon Sep 17 00:00:00 2001 From: sharmander Date: Fri, 11 Dec 2020 00:05:53 -0500 Subject: [PATCH] GPU: Improve unnecessary return value in Map function. (#1799) * Implement VFNMA.F<32/64> * Update PTC Version * Update Implementation & Renames & Correct Order * Add Logging * Additional logging * Add additional check to restart loop from beginning if address goes beyond maximum allowed. * Additional Check that the total range required doesn't exceed capacity of allocator addresses. * Improve logging * Ensure hex output * Update Ryujinx.HLE/HOS/Services/Nv/NvMemoryAllocator.cs Co-authored-by: gdkchan * Remove extra page at end * Remove unnecessary return val in Map function. * Remove incorrect description Co-authored-by: gdkchan --- Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs | 5 +---- .../NvHostAsGpu/NvHostAsGpuDeviceFile.cs | 17 +++++++++++------ .../NvHostChannel/NvHostChannelDeviceFile.cs | 3 ++- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs b/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs index 2990fb52..b1b1a1a8 100644 --- a/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs +++ b/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs @@ -115,8 +115,7 @@ namespace Ryujinx.Graphics.Gpu.Memory /// CPU virtual address to map into /// GPU virtual address to be mapped /// Size in bytes of the mapping - /// GPU virtual address of the mapping - public ulong Map(ulong pa, ulong va, ulong size) + public void Map(ulong pa, ulong va, ulong size) { lock (_pageTable) { @@ -127,8 +126,6 @@ namespace Ryujinx.Graphics.Gpu.Memory SetPte(va + offset, pa + offset); } } - - return va; } /// diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs index fb973229..c2296775 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs @@ -223,8 +223,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu long virtualAddress = arguments.Offset + arguments.BufferOffset; physicalAddress += arguments.BufferOffset; + addressSpaceContext.Gmm.Map((ulong)physicalAddress, (ulong)virtualAddress, (ulong)arguments.MappingSize); - if ((long)addressSpaceContext.Gmm.Map((ulong)physicalAddress, (ulong)virtualAddress, (ulong)arguments.MappingSize) < 0) + if (virtualAddress < 0) { string message = string.Format(mapErrorMsg, virtualAddress, arguments.MappingSize, pageSize); @@ -265,7 +266,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu { if (addressSpaceContext.ValidateFixedBuffer(arguments.Offset, size, pageSize)) { - arguments.Offset = (long)addressSpaceContext.Gmm.Map((ulong)physicalAddress, (ulong)arguments.Offset, (ulong)size); + addressSpaceContext.Gmm.Map((ulong)physicalAddress, (ulong)arguments.Offset, (ulong)size); } else { @@ -283,7 +284,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu { _memoryAllocator.AllocateRange(va, (ulong)size, freeAddressStartPosition); } - arguments.Offset = (long)addressSpaceContext.Gmm.Map((ulong)physicalAddress, va, (ulong)size); + + addressSpaceContext.Gmm.Map((ulong)physicalAddress, va, (ulong)size); + arguments.Offset = (long)va; } if (arguments.Offset < 0) @@ -332,12 +335,14 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu return NvInternalResult.InvalidInput; } - long result = (long)gmm.Map( + long shiftedGpuOffset = (long)((ulong)arguments[index].GpuOffset << 16); + + gmm.Map( ((ulong)arguments[index].MapOffset << 16) + (ulong)map.Address, - (ulong)arguments[index].GpuOffset << 16, + (ulong)shiftedGpuOffset, (ulong)arguments[index].Pages << 16); - if (result < 0) + if (shiftedGpuOffset < 0) { Logger.Warning?.Print(LogClass.ServiceNv, $"Page 0x{arguments[index].GpuOffset:x16} size 0x{arguments[index].Pages:x16} not allocated!"); diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostChannelDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostChannelDeviceFile.cs index ca20aab5..4a532cd7 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostChannelDeviceFile.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostChannelDeviceFile.cs @@ -253,7 +253,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel if (va != NvMemoryAllocator.PteUnmapped && va <= uint.MaxValue && (va + (uint)map.Size) <= uint.MaxValue) { _memoryAllocator.AllocateRange(va, (uint)map.Size, freeAddressStartPosition); - map.DmaMapAddress = (long)gmm.Map((ulong)map.Address, va, (uint)map.Size); + gmm.Map((ulong)map.Address, va, (uint)map.Size); + map.DmaMapAddress = (long)va; } else {