diff --git a/Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs b/Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs
index d109f1cd6..1ec4ab74c 100644
--- a/Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs
+++ b/Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs
@@ -280,7 +280,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache
}
}
- // Transformation feedback
+ // Transform feedback
if (tfd != null)
{
foreach (TransformFeedbackDescriptor transform in tfd)
@@ -311,7 +311,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache
/// The raw guest transform feedback descriptors
/// The guest shader program header
/// The transform feedback descriptors read from guest
- public static TransformFeedbackDescriptor[] ReadTransformationFeedbackInformations(ref ReadOnlySpan data, GuestShaderCacheHeader header)
+ public static TransformFeedbackDescriptor[] ReadTransformFeedbackInformation(ref ReadOnlySpan data, GuestShaderCacheHeader header)
{
if (header.TransformFeedbackCount != 0)
{
@@ -376,9 +376,11 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache
/// Guest shader cahe entries from the runtime contexts
public static GuestShaderCacheEntry[] CreateShaderCacheEntries(MemoryManager memoryManager, ReadOnlySpan shaderContexts)
{
- GuestShaderCacheEntry[] entries = new GuestShaderCacheEntry[shaderContexts.Length];
+ int startIndex = shaderContexts.Length > 1 ? 1 : 0;
- for (int i = 0; i < shaderContexts.Length; i++)
+ GuestShaderCacheEntry[] entries = new GuestShaderCacheEntry[shaderContexts.Length - startIndex];
+
+ for (int i = startIndex; i < shaderContexts.Length; i++)
{
TranslatorContext context = shaderContexts[i];
@@ -387,15 +389,17 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache
continue;
}
- int sizeA = context.AddressA == 0 ? 0 : context.SizeA;
+ TranslatorContext translatorContext2 = i == 1 ? shaderContexts[0] : null;
+
+ int sizeA = translatorContext2 != null ? translatorContext2.Size : 0;
byte[] code = new byte[context.Size + sizeA];
memoryManager.GetSpan(context.Address, context.Size).CopyTo(code);
- if (context.AddressA != 0)
+ if (translatorContext2 != null)
{
- memoryManager.GetSpan(context.AddressA, context.SizeA).CopyTo(code.AsSpan().Slice(context.Size, context.SizeA));
+ memoryManager.GetSpan(translatorContext2.Address, sizeA).CopyTo(code.AsSpan().Slice(context.Size, sizeA));
}
GuestGpuAccessorHeader gpuAccessorHeader = CreateGuestGpuAccessorCache(context.GpuAccessor);
@@ -421,7 +425,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache
}
}
- entries[i] = entry;
+ entries[i - startIndex] = entry;
}
return entries;
diff --git a/Ryujinx.Graphics.Gpu/Shader/Cache/CacheMigration.cs b/Ryujinx.Graphics.Gpu/Shader/Cache/CacheMigration.cs
index 839853c07..e726bc2c0 100644
--- a/Ryujinx.Graphics.Gpu/Shader/Cache/CacheMigration.cs
+++ b/Ryujinx.Graphics.Gpu/Shader/Cache/CacheMigration.cs
@@ -103,7 +103,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache
ReadOnlySpan cachedShaderEntries = GuestShaderCacheEntry.Parse(ref guestProgramReadOnlySpan, out GuestShaderCacheHeader fileHeader);
- TransformFeedbackDescriptor[] tfd = CacheHelper.ReadTransformationFeedbackInformations(ref guestProgramReadOnlySpan, fileHeader);
+ TransformFeedbackDescriptor[] tfd = CacheHelper.ReadTransformFeedbackInformation(ref guestProgramReadOnlySpan, fileHeader);
Hash128 newHash = CacheHelper.ComputeGuestHashFromCache(cachedShaderEntries, tfd);
diff --git a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs
index f266bbb44..6a3971df2 100644
--- a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs
+++ b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs
@@ -128,7 +128,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
// Reconstruct code holder.
if (isHostProgramValid)
{
- program = new ShaderProgram(entry.Header.Stage, "", entry.Header.Size, entry.Header.SizeA);
+ program = new ShaderProgram(entry.Header.Stage, "");
shaderProgramInfo = hostShaderEntries[0].ToShaderProgramInfo();
}
else
@@ -176,7 +176,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
ShaderCodeHolder[] shaders = new ShaderCodeHolder[cachedShaderEntries.Length];
List shaderPrograms = new List();
- TransformFeedbackDescriptor[] tfd = CacheHelper.ReadTransformationFeedbackInformations(ref guestProgramReadOnlySpan, fileHeader);
+ TransformFeedbackDescriptor[] tfd = CacheHelper.ReadTransformFeedbackInformation(ref guestProgramReadOnlySpan, fileHeader);
TranslationFlags flags = DefaultFlags;
@@ -217,14 +217,17 @@ namespace Ryujinx.Graphics.Gpu.Shader
if (isHostProgramValid)
{
- program = new ShaderProgram(entry.Header.Stage, "", entry.Header.Size, entry.Header.SizeA);
+ program = new ShaderProgram(entry.Header.Stage, "");
shaderProgramInfo = hostShaderEntries[i].ToShaderProgramInfo();
}
else
{
IGpuAccessor gpuAccessor = new CachedGpuAccessor(_context, entry.Code, entry.Header.GpuAccessorHeader, entry.TextureDescriptors);
- program = Translator.CreateContext((ulong)entry.Header.Size, 0, gpuAccessor, flags, counts).Translate(out shaderProgramInfo);
+ TranslatorContext translatorContext = Translator.CreateContext(0, gpuAccessor, flags, counts);
+ TranslatorContext translatorContext2 = Translator.CreateContext((ulong)entry.Header.Size, gpuAccessor, flags | TranslationFlags.VertexA, counts);
+
+ program = translatorContext.Translate(out shaderProgramInfo, translatorContext2);
}
// NOTE: Vertex B comes first in the shader cache.
@@ -239,7 +242,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
if (isHostProgramValid)
{
- program = new ShaderProgram(entry.Header.Stage, "", entry.Header.Size, entry.Header.SizeA);
+ program = new ShaderProgram(entry.Header.Stage, "");
shaderProgramInfo = hostShaderEntries[i].ToShaderProgramInfo();
}
else
@@ -446,7 +449,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
}
}
- TranslatorContext[] shaderContexts = new TranslatorContext[Constants.ShaderStages];
+ TranslatorContext[] shaderContexts = new TranslatorContext[Constants.ShaderStages + 1];
TransformFeedbackDescriptor[] tfd = GetTransformFeedbackDescriptors(state);
@@ -461,17 +464,14 @@ namespace Ryujinx.Graphics.Gpu.Shader
if (addresses.VertexA != 0)
{
- shaderContexts[0] = DecodeGraphicsShader(state, counts, flags, ShaderStage.Vertex, addresses.Vertex, addresses.VertexA);
- }
- else
- {
- shaderContexts[0] = DecodeGraphicsShader(state, counts, flags, ShaderStage.Vertex, addresses.Vertex);
+ shaderContexts[0] = DecodeGraphicsShader(state, counts, flags | TranslationFlags.VertexA, ShaderStage.Vertex, addresses.VertexA);
}
- shaderContexts[1] = DecodeGraphicsShader(state, counts, flags, ShaderStage.TessellationControl, addresses.TessControl);
- shaderContexts[2] = DecodeGraphicsShader(state, counts, flags, ShaderStage.TessellationEvaluation, addresses.TessEvaluation);
- shaderContexts[3] = DecodeGraphicsShader(state, counts, flags, ShaderStage.Geometry, addresses.Geometry);
- shaderContexts[4] = DecodeGraphicsShader(state, counts, flags, ShaderStage.Fragment, addresses.Fragment);
+ shaderContexts[1] = DecodeGraphicsShader(state, counts, flags, ShaderStage.Vertex, addresses.Vertex);
+ shaderContexts[2] = DecodeGraphicsShader(state, counts, flags, ShaderStage.TessellationControl, addresses.TessControl);
+ shaderContexts[3] = DecodeGraphicsShader(state, counts, flags, ShaderStage.TessellationEvaluation, addresses.TessEvaluation);
+ shaderContexts[4] = DecodeGraphicsShader(state, counts, flags, ShaderStage.Geometry, addresses.Geometry);
+ shaderContexts[5] = DecodeGraphicsShader(state, counts, flags, ShaderStage.Fragment, addresses.Fragment);
bool isShaderCacheEnabled = _cacheManager != null;
bool isShaderCacheReadOnly = false;
@@ -501,11 +501,11 @@ namespace Ryujinx.Graphics.Gpu.Shader
// The shader isn't currently cached, translate it and compile it.
ShaderCodeHolder[] shaders = new ShaderCodeHolder[Constants.ShaderStages];
- shaders[0] = TranslateShader(shaderContexts[0]);
- shaders[1] = TranslateShader(shaderContexts[1]);
- shaders[2] = TranslateShader(shaderContexts[2]);
- shaders[3] = TranslateShader(shaderContexts[3]);
- shaders[4] = TranslateShader(shaderContexts[4]);
+ shaders[0] = TranslateShader(shaderContexts[1], shaderContexts[0]);
+ shaders[1] = TranslateShader(shaderContexts[2]);
+ shaders[2] = TranslateShader(shaderContexts[3]);
+ shaders[3] = TranslateShader(shaderContexts[4]);
+ shaders[4] = TranslateShader(shaderContexts[5]);
List hostShaders = new List();
@@ -696,15 +696,13 @@ namespace Ryujinx.Graphics.Gpu.Shader
/// Flags that controls shader translation
/// Shader stage
/// GPU virtual address of the shader code
- /// Optional GPU virtual address of the "Vertex A" shader code
/// The generated translator context
private TranslatorContext DecodeGraphicsShader(
GpuState state,
TranslationCounts counts,
TranslationFlags flags,
ShaderStage stage,
- ulong gpuVa,
- ulong gpuVaA = 0)
+ ulong gpuVa)
{
if (gpuVa == 0)
{
@@ -713,37 +711,31 @@ namespace Ryujinx.Graphics.Gpu.Shader
GpuAccessor gpuAccessor = new GpuAccessor(_context, state, (int)stage - 1);
- if (gpuVaA != 0)
- {
- return Translator.CreateContext(gpuVaA, gpuVa, gpuAccessor, flags, counts);
- }
- else
- {
- return Translator.CreateContext(gpuVa, gpuAccessor, flags, counts);
- }
+ return Translator.CreateContext(gpuVa, gpuAccessor, flags, counts);
}
///
/// Translates a previously generated translator context to something that the host API accepts.
///
/// Current translator context to translate
+ /// Optional translator context of the shader that should be combined
/// Compiled graphics shader code
- private ShaderCodeHolder TranslateShader(TranslatorContext translatorContext)
+ private ShaderCodeHolder TranslateShader(TranslatorContext translatorContext, TranslatorContext translatorContext2 = null)
{
if (translatorContext == null)
{
return null;
}
- if (translatorContext.AddressA != 0)
+ if (translatorContext2 != null)
{
- byte[] codeA = _context.MemoryManager.GetSpan(translatorContext.AddressA, translatorContext.SizeA).ToArray();
+ byte[] codeA = _context.MemoryManager.GetSpan(translatorContext2.Address, translatorContext2.Size).ToArray();
byte[] codeB = _context.MemoryManager.GetSpan(translatorContext.Address, translatorContext.Size).ToArray();
_dumper.Dump(codeA, compute: false, out string fullPathA, out string codePathA);
_dumper.Dump(codeB, compute: false, out string fullPathB, out string codePathB);
- ShaderProgram program = translatorContext.Translate(out ShaderProgramInfo shaderProgramInfo);
+ ShaderProgram program = translatorContext.Translate(out ShaderProgramInfo shaderProgramInfo, translatorContext2);
if (fullPathA != null && fullPathB != null && codePathA != null && codePathB != null)
{
diff --git a/Ryujinx.Graphics.Shader/ShaderProgram.cs b/Ryujinx.Graphics.Shader/ShaderProgram.cs
index 0e037fc9c..4a6bfea9f 100644
--- a/Ryujinx.Graphics.Shader/ShaderProgram.cs
+++ b/Ryujinx.Graphics.Shader/ShaderProgram.cs
@@ -8,15 +8,10 @@ namespace Ryujinx.Graphics.Shader
public string Code { get; private set; }
- public int SizeA { get; }
- public int Size { get; }
-
- public ShaderProgram(ShaderStage stage, string code, int size, int sizeA)
+ public ShaderProgram(ShaderStage stage, string code)
{
Stage = stage;
Code = code;
- SizeA = sizeA;
- Size = size;
}
public void Prepend(string line)
diff --git a/Ryujinx.Graphics.Shader/Translation/Translator.cs b/Ryujinx.Graphics.Shader/Translation/Translator.cs
index e52c1ccf4..0d64bccc4 100644
--- a/Ryujinx.Graphics.Shader/Translation/Translator.cs
+++ b/Ryujinx.Graphics.Shader/Translation/Translator.cs
@@ -36,22 +36,7 @@ namespace Ryujinx.Graphics.Shader.Translation
return new TranslatorContext(address, cfg, config);
}
- public static TranslatorContext CreateContext(
- ulong addressA,
- ulong addressB,
- IGpuAccessor gpuAccessor,
- TranslationFlags flags,
- TranslationCounts counts = null)
- {
- counts ??= new TranslationCounts();
-
- Block[][] cfgA = DecodeShader(addressA, gpuAccessor, flags | TranslationFlags.VertexA, counts, out ShaderConfig configA);
- Block[][] cfgB = DecodeShader(addressB, gpuAccessor, flags, counts, out ShaderConfig configB);
-
- return new TranslatorContext(addressA, addressB, cfgA, cfgB, configA, configB);
- }
-
- internal static ShaderProgram Translate(FunctionCode[] functions, ShaderConfig config, out ShaderProgramInfo shaderProgramInfo, int sizeA = 0)
+ internal static ShaderProgram Translate(FunctionCode[] functions, ShaderConfig config, out ShaderProgramInfo shaderProgramInfo)
{
var cfgs = new ControlFlowGraph[functions.Length];
var frus = new RegisterUsage.FunctionRegisterUsage[functions.Length];
@@ -113,7 +98,7 @@ namespace Ryujinx.Graphics.Shader.Translation
string glslCode = program.Code;
- return new ShaderProgram(config.Stage, glslCode, config.Size, sizeA);
+ return new ShaderProgram(config.Stage, glslCode);
}
private static Block[][] DecodeShader(
diff --git a/Ryujinx.Graphics.Shader/Translation/TranslatorContext.cs b/Ryujinx.Graphics.Shader/Translation/TranslatorContext.cs
index 3092e0776..501f78807 100644
--- a/Ryujinx.Graphics.Shader/Translation/TranslatorContext.cs
+++ b/Ryujinx.Graphics.Shader/Translation/TranslatorContext.cs
@@ -10,16 +10,12 @@ namespace Ryujinx.Graphics.Shader.Translation
public class TranslatorContext
{
private readonly Block[][] _cfg;
- private readonly Block[][] _cfgA;
private ShaderConfig _config;
- private ShaderConfig _configA;
public ulong Address { get; }
- public ulong AddressA { get; }
public ShaderStage Stage => _config.Stage;
public int Size => _config.Size;
- public int SizeA => _configA != null ? _configA.Size : 0;
public HashSet TextureHandlesForCache => _config.TextureHandlesForCache;
@@ -27,22 +23,9 @@ namespace Ryujinx.Graphics.Shader.Translation
internal TranslatorContext(ulong address, Block[][] cfg, ShaderConfig config)
{
- Address = address;
- AddressA = 0;
- _config = config;
- _configA = null;
- _cfg = cfg;
- _cfgA = null;
- }
-
- internal TranslatorContext(ulong addressA, ulong addressB, Block[][] cfgA, Block[][] cfgB, ShaderConfig configA, ShaderConfig configB)
- {
- Address = addressB;
- AddressA = addressA;
- _config = configB;
- _configA = configA;
- _cfg = cfgB;
- _cfgA = cfgA;
+ Address = address;
+ _config = config;
+ _cfg = cfg;
}
private static bool IsUserAttribute(Operand operand)
@@ -141,20 +124,19 @@ namespace Ryujinx.Graphics.Shader.Translation
return output;
}
- public ShaderProgram Translate(out ShaderProgramInfo shaderProgramInfo)
+ public ShaderProgram Translate(out ShaderProgramInfo shaderProgramInfo, TranslatorContext other = null)
{
FunctionCode[] code = EmitShader(_cfg, _config);
- if (_configA != null)
+ if (other != null)
{
- FunctionCode[] codeA = EmitShader(_cfgA, _configA);
+ _config.SetUsedFeature(other._config.UsedFeatures);
+ TextureHandlesForCache.UnionWith(other.TextureHandlesForCache);
- _config.SetUsedFeature(_configA.UsedFeatures);
-
- code = Combine(codeA, code);
+ code = Combine(EmitShader(other._cfg, other._config), code);
}
- return Translator.Translate(code, _config, out shaderProgramInfo, SizeA);
+ return Translator.Translate(code, _config, out shaderProgramInfo);
}
}
}