mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-10-01 12:30:00 +02:00
Fix some shader disposal issues
This commit is contained in:
parent
a11f6f5235
commit
383452f5cf
3 changed files with 17 additions and 19 deletions
|
@ -737,11 +737,11 @@ namespace Ryujinx.Graphics.Gpu.Engine
|
|||
|
||||
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++)
|
||||
{
|
||||
ShaderProgramInfo info = gs.Shaders[stage].Program?.Info;
|
||||
ShaderProgramInfo info = gs.Shaders[stage]?.Program.Info;
|
||||
|
||||
_currentProgramInfo[stage] = info;
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
/// <summary>
|
||||
/// Host shader program object.
|
||||
/// </summary>
|
||||
public IProgram HostProgram { get; set; }
|
||||
public IProgram HostProgram { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Cached shader.
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue