diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2021-08-11 17:27:00 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-11 22:27:00 +0200 |
| commit | ed754af8d5046d2fd7218c742521e38ab17cbcfe (patch) | |
| tree | d47eda40349a7b4b3fc34d9db9ddeea8f2d0676a /Ryujinx.Graphics.Shader/Translation/TranslatorContext.cs | |
| parent | 10d649e6d3ad3e4af32d2b41e718bb0a2924da67 (diff) | |
Make sure attributes used on subsequent shader stages are initialized (#2538)
Diffstat (limited to 'Ryujinx.Graphics.Shader/Translation/TranslatorContext.cs')
| -rw-r--r-- | Ryujinx.Graphics.Shader/Translation/TranslatorContext.cs | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/Ryujinx.Graphics.Shader/Translation/TranslatorContext.cs b/Ryujinx.Graphics.Shader/Translation/TranslatorContext.cs index ab74d039..47cf0ac8 100644 --- a/Ryujinx.Graphics.Shader/Translation/TranslatorContext.cs +++ b/Ryujinx.Graphics.Shader/Translation/TranslatorContext.cs @@ -38,7 +38,7 @@ namespace Ryujinx.Graphics.Shader.Translation operand.Value < AttributeConsts.UserAttributeEnd; } - private static FunctionCode[] Combine(FunctionCode[] a, FunctionCode[] b) + private static FunctionCode[] Combine(FunctionCode[] a, FunctionCode[] b, int aStart) { // Here we combine two shaders. // For shader A: @@ -57,7 +57,7 @@ namespace Ryujinx.Graphics.Shader.Translation Operand lblB = Label(); - for (int index = 0; index < a[0].Code.Length; index++) + for (int index = aStart; index < a[0].Code.Length; index++) { Operation operation = a[0].Code[index]; @@ -103,7 +103,17 @@ namespace Ryujinx.Graphics.Shader.Translation if (temp != null) { - operation.SetSource(srcIndex, temp); + // TODO: LoadAttribute should accept any integer value as first argument, + // then we don't need special case here. Right now it expects the first + // operand to be of type "attribute". + if ((operation.Inst & Instruction.Mask) == Instruction.LoadAttribute) + { + operation.TurnIntoCopy(temp); + } + else + { + operation.SetSource(srcIndex, temp); + } } } } @@ -126,13 +136,25 @@ namespace Ryujinx.Graphics.Shader.Translation return output; } - public ShaderProgram Translate(out ShaderProgramInfo shaderProgramInfo, TranslatorContext other = null) + public ShaderProgram Translate( + out ShaderProgramInfo shaderProgramInfo, + TranslatorContext nextStage = null, + TranslatorContext other = null) { - FunctionCode[] code = EmitShader(_cfg, _config); + if (nextStage != null) + { + _config.MergeOutputUserAttributes(nextStage._config.UsedInputAttributes); + } + + FunctionCode[] code = EmitShader(_cfg, _config, initializeOutputs: other == null, out _); if (other != null) { - code = Combine(EmitShader(other._cfg, other._config), code); + other._config.MergeOutputUserAttributes(_config.UsedOutputAttributes); + + FunctionCode[] otherCode = EmitShader(other._cfg, other._config, initializeOutputs: true, out int aStart); + + code = Combine(otherCode, code, aStart); _config.InheritFrom(other._config); } |
