This commit is contained in:
Marco Carvalho 2024-05-17 20:18:41 -03:00 committed by GitHub
commit 5e06bae7d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 29 additions and 19 deletions

View File

@ -8,7 +8,9 @@ using Ryujinx.Graphics.Gpu.Synchronization;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Ryujinx.Graphics.Gpu
{
@ -274,14 +276,11 @@ namespace Ryujinx.Graphics.Gpu
/// <summary>
/// Initialize the GPU shader cache.
/// </summary>
public void InitializeShaderCache(CancellationToken cancellationToken)
public async Task InitializeShaderCache(CancellationToken cancellationToken)
{
HostInitalized.WaitOne();
foreach (var physicalMemory in PhysicalMemoryRegistry.Values)
{
physicalMemory.ShaderCache.Initialize(cancellationToken);
}
await Task.WhenAll(PhysicalMemoryRegistry.Values.Select(pm => pm.ShaderCache.Initialize(cancellationToken)));
_gpuReadyEvent.Set();
}

View File

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
{
@ -194,7 +195,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
/// <param name="dataFileStream">Guest data file stream</param>
/// <param name="index">Guest shader index</param>
/// <returns>Guest code and constant buffer 1 data</returns>
public GuestCodeAndCbData LoadShader(Stream tocFileStream, Stream dataFileStream, int index)
public async Task<GuestCodeAndCbData> LoadShader(Stream tocFileStream, Stream dataFileStream, int index)
{
if (_cache == null || index >= _cache.Length)
{
@ -220,7 +221,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
}
dataFileStream.Seek((long)entry.Offset, SeekOrigin.Begin);
dataFileStream.Read(cb1Data);
await dataFileStream.ReadAsync(cb1Data);
BinarySerializer.ReadCompressed(dataFileStream, guestCode);
_cache[index] = (guestCode, cb1Data);

View File

@ -5,6 +5,7 @@ using System;
using System.IO;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
{
@ -289,7 +290,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
/// </summary>
/// <param name="context">GPU context</param>
/// <param name="loader">Parallel disk cache loader</param>
public void LoadShaders(GpuContext context, ParallelDiskCacheLoader loader)
public async Task LoadShaders(GpuContext context, ParallelDiskCacheLoader loader)
{
if (!CacheExists())
{
@ -301,11 +302,11 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
try
{
using var tocFileStream = DiskCacheCommon.OpenFile(_basePath, SharedTocFileName, writable: false);
using var dataFileStream = DiskCacheCommon.OpenFile(_basePath, SharedDataFileName, writable: false);
await using var tocFileStream = DiskCacheCommon.OpenFile(_basePath, SharedTocFileName, writable: false);
await using var dataFileStream = DiskCacheCommon.OpenFile(_basePath, SharedDataFileName, writable: false);
using var guestTocFileStream = _guestStorage.OpenTocFileStream();
using var guestDataFileStream = _guestStorage.OpenDataFileStream();
await using var guestTocFileStream = _guestStorage.OpenTocFileStream();
await using var guestDataFileStream = _guestStorage.OpenDataFileStream();
BinarySerializer tocReader = new(tocFileStream);
BinarySerializer dataReader = new(dataFileStream);
@ -365,7 +366,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
dataReader.Read(ref stageEntry);
guestShaders[stageIndex] = _guestStorage.LoadShader(
guestShaders[stageIndex] = await _guestStorage.LoadShader(
guestTocFileStream,
guestDataFileStream,
stageEntry.GuestCodeIndex);
@ -432,8 +433,15 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
{
_guestStorage.ClearMemoryCache();
hostTocFileStream?.Dispose();
hostDataFileStream?.Dispose();
if (hostTocFileStream != null)
{
await hostTocFileStream.DisposeAsync();
}
if (hostDataFileStream != null)
{
await hostDataFileStream.DisposeAsync();
}
}
}

View File

@ -7,6 +7,7 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using static Ryujinx.Graphics.Gpu.Shader.ShaderCache;
namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
@ -226,7 +227,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
/// <summary>
/// Loads all shaders from the cache.
/// </summary>
public void LoadShaders()
public async Task LoadShaders()
{
Thread[] workThreads = new Thread[ThreadCount];
@ -254,7 +255,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
try
{
_hostStorage.LoadShaders(_context, this);
await _hostStorage.LoadShaders(_context, this);
}
catch (DiskCacheLoadException diskCacheLoadException)
{

View File

@ -12,6 +12,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace Ryujinx.Graphics.Gpu.Shader
{
@ -152,7 +153,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
/// Initialize the cache.
/// </summary>
/// <param name="cancellationToken">Cancellation token to cancel the shader cache initialization process</param>
internal void Initialize(CancellationToken cancellationToken)
internal async Task Initialize(CancellationToken cancellationToken)
{
if (_diskCacheHostStorage.CacheEnabled)
{
@ -164,7 +165,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
ShaderCacheStateUpdate,
cancellationToken);
loader.LoadShaders();
await loader.LoadShaders();
int errorCount = loader.ErrorCount;
if (errorCount != 0)