aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2020-01-05 13:40:21 -0300
committerThog <thog@protonmail.com>2020-01-09 02:13:00 +0100
commit383452f5cf2a81d50ef1a5e630fba45c6fb97647 (patch)
tree44d3f4a2603a0d7521a40e3d26811b027fcc5dd8 /Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs
parenta11f6f52350e2cd1ba80fb45a3e69194cdc605b5 (diff)
Fix some shader disposal issues
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs')
-rw-r--r--Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs30
1 files changed, 14 insertions, 16 deletions
diff --git a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs
index 9f0c1c13..548a7e07 100644
--- a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs
+++ b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs
@@ -73,11 +73,9 @@ namespace Ryujinx.Graphics.Gpu.Shader
CachedShader shader = TranslateComputeShader(gpuVa, sharedMemorySize, localSizeX, localSizeY, localSizeZ);
- IShader hostShader = _context.Renderer.CompileShader(shader.Program);
+ shader.HostShader = _context.Renderer.CompileShader(shader.Program);
- IProgram hostProgram = _context.Renderer.CreateProgram(new IShader[] { hostShader });
-
- ulong address = _context.MemoryManager.Translate(gpuVa);
+ IProgram hostProgram = _context.Renderer.CreateProgram(new IShader[] { shader.HostShader });
ComputeShader cpShader = new ComputeShader(hostProgram, shader);
@@ -140,7 +138,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
for (int stage = 0; stage < gpShaders.Shaders.Length; stage++)
{
- ShaderProgram program = gpShaders.Shaders[stage].Program;
+ ShaderProgram program = gpShaders.Shaders[stage]?.Program;
if (program == null)
{
@@ -191,11 +189,6 @@ namespace Ryujinx.Graphics.Gpu.Shader
{
CachedShader shader = gpShaders.Shaders[stage];
- if (shader.Code == null)
- {
- continue;
- }
-
ulong gpuVa = 0;
switch (stage)
@@ -224,6 +217,11 @@ namespace Ryujinx.Graphics.Gpu.Shader
/// <returns>True if the code is different, false otherwise</returns>
private bool IsShaderDifferent(CachedShader shader, ulong gpuVa)
{
+ if (shader == null)
+ {
+ return false;
+ }
+
for (int index = 0; index < shader.Code.Length; index++)
{
if (_context.MemoryAccessor.ReadInt32(gpuVa + (ulong)index * 4) != shader.Code[index])
@@ -299,7 +297,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
{
if (gpuVa == 0)
{
- return new CachedShader(null, null);
+ return null;
}
int QueryInfo(QueryInfoName info, int index)
@@ -370,13 +368,13 @@ namespace Ryujinx.Graphics.Gpu.Shader
/// <param name="program">Graphics shader cached code</param>
private void BackpropQualifiers(GraphicsShader program)
{
- ShaderProgram fragmentShader = program.Shaders[4].Program;
+ ShaderProgram fragmentShader = program.Shaders[4]?.Program;
bool isFirst = true;
for (int stage = 3; stage >= 0; stage--)
{
- if (program.Shaders[stage].Program == null)
+ if (program.Shaders[stage] == null)
{
continue;
}
@@ -387,7 +385,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
{
string iq = fragmentShader?.Info.InterpolationQualifiers[attr].ToGlslQualifier() ?? string.Empty;
- if (isFirst && iq != string.Empty)
+ if (isFirst && !string.IsNullOrEmpty(iq))
{
program.Shaders[stage].Program.Replace($"{DefineNames.OutQualifierPrefixName}{attr}", iq);
}
@@ -513,7 +511,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
foreach (ComputeShader shader in list)
{
shader.HostProgram.Dispose();
- shader.Shader.HostShader.Dispose();
+ shader.Shader?.HostShader.Dispose();
}
}
@@ -525,7 +523,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
foreach (CachedShader cachedShader in shader.Shaders)
{
- cachedShader.HostShader?.Dispose();
+ cachedShader?.HostShader.Dispose();
}
}
}