Fix some shader disposal issues

This commit is contained in:
gdkchan 2020-01-05 13:40:21 -03:00 committed by Thog
parent a11f6f5235
commit 383452f5cf
3 changed files with 17 additions and 19 deletions

View File

@ -737,11 +737,11 @@ namespace Ryujinx.Graphics.Gpu.Engine
GraphicsShader gs = ShaderCache.GetGraphicsShader(state, addresses); GraphicsShader gs = ShaderCache.GetGraphicsShader(state, addresses);
_vsUsesInstanceId = gs.Shaders[0].Program.Info.UsesInstanceId; _vsUsesInstanceId = gs.Shaders[0]?.Program.Info.UsesInstanceId ?? false;
for (int stage = 0; stage < Constants.ShaderStages; stage++) for (int stage = 0; stage < Constants.ShaderStages; stage++)
{ {
ShaderProgramInfo info = gs.Shaders[stage].Program?.Info; ShaderProgramInfo info = gs.Shaders[stage]?.Program.Info;
_currentProgramInfo[stage] = info; _currentProgramInfo[stage] = info;

View File

@ -10,7 +10,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
/// <summary> /// <summary>
/// Host shader program object. /// Host shader program object.
/// </summary> /// </summary>
public IProgram HostProgram { get; set; } public IProgram HostProgram { get; }
/// <summary> /// <summary>
/// Cached shader. /// Cached shader.

View File

@ -73,11 +73,9 @@ namespace Ryujinx.Graphics.Gpu.Shader
CachedShader shader = TranslateComputeShader(gpuVa, sharedMemorySize, localSizeX, localSizeY, localSizeZ); 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 }); IProgram hostProgram = _context.Renderer.CreateProgram(new IShader[] { shader.HostShader });
ulong address = _context.MemoryManager.Translate(gpuVa);
ComputeShader cpShader = new ComputeShader(hostProgram, shader); ComputeShader cpShader = new ComputeShader(hostProgram, shader);
@ -140,7 +138,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
for (int stage = 0; stage < gpShaders.Shaders.Length; stage++) for (int stage = 0; stage < gpShaders.Shaders.Length; stage++)
{ {
ShaderProgram program = gpShaders.Shaders[stage].Program; ShaderProgram program = gpShaders.Shaders[stage]?.Program;
if (program == null) if (program == null)
{ {
@ -191,11 +189,6 @@ namespace Ryujinx.Graphics.Gpu.Shader
{ {
CachedShader shader = gpShaders.Shaders[stage]; CachedShader shader = gpShaders.Shaders[stage];
if (shader.Code == null)
{
continue;
}
ulong gpuVa = 0; ulong gpuVa = 0;
switch (stage) switch (stage)
@ -224,6 +217,11 @@ namespace Ryujinx.Graphics.Gpu.Shader
/// <returns>True if the code is different, false otherwise</returns> /// <returns>True if the code is different, false otherwise</returns>
private bool IsShaderDifferent(CachedShader shader, ulong gpuVa) private bool IsShaderDifferent(CachedShader shader, ulong gpuVa)
{ {
if (shader == null)
{
return false;
}
for (int index = 0; index < shader.Code.Length; index++) for (int index = 0; index < shader.Code.Length; index++)
{ {
if (_context.MemoryAccessor.ReadInt32(gpuVa + (ulong)index * 4) != shader.Code[index]) if (_context.MemoryAccessor.ReadInt32(gpuVa + (ulong)index * 4) != shader.Code[index])
@ -299,7 +297,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
{ {
if (gpuVa == 0) if (gpuVa == 0)
{ {
return new CachedShader(null, null); return null;
} }
int QueryInfo(QueryInfoName info, int index) int QueryInfo(QueryInfoName info, int index)
@ -370,13 +368,13 @@ namespace Ryujinx.Graphics.Gpu.Shader
/// <param name="program">Graphics shader cached code</param> /// <param name="program">Graphics shader cached code</param>
private void BackpropQualifiers(GraphicsShader program) private void BackpropQualifiers(GraphicsShader program)
{ {
ShaderProgram fragmentShader = program.Shaders[4].Program; ShaderProgram fragmentShader = program.Shaders[4]?.Program;
bool isFirst = true; bool isFirst = true;
for (int stage = 3; stage >= 0; stage--) for (int stage = 3; stage >= 0; stage--)
{ {
if (program.Shaders[stage].Program == null) if (program.Shaders[stage] == null)
{ {
continue; continue;
} }
@ -387,7 +385,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
{ {
string iq = fragmentShader?.Info.InterpolationQualifiers[attr].ToGlslQualifier() ?? string.Empty; 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); program.Shaders[stage].Program.Replace($"{DefineNames.OutQualifierPrefixName}{attr}", iq);
} }
@ -513,7 +511,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
foreach (ComputeShader shader in list) foreach (ComputeShader shader in list)
{ {
shader.HostProgram.Dispose(); 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) foreach (CachedShader cachedShader in shader.Shaders)
{ {
cachedShader.HostShader?.Dispose(); cachedShader?.HostShader.Dispose();
} }
} }
} }