aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2020-07-15 00:01:10 -0300
committerGitHub <noreply@github.com>2020-07-15 13:01:10 +1000
commit788ca6a411762035a6a7a88100c4b582b47ee82d (patch)
treed48bfb91aecaead2906ec2d390357546f8c0611f /Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs
parent16dafe63166d065f40b57a9b7cf8017a6ba0b1ef (diff)
Initial transform feedback support (#1370)
* Initial transform feedback support * Some nits and fixes * Update ReportCounterType and Write method * Can't change shader or TFB bindings while TFB is active * Fix geometry shader input names with new naming
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs')
-rw-r--r--Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs36
1 files changed, 34 insertions, 2 deletions
diff --git a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs
index 8a1abe32..d16f1057 100644
--- a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs
+++ b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs
@@ -82,7 +82,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
shader.HostShader = _context.Renderer.CompileShader(shader.Program);
- IProgram hostProgram = _context.Renderer.CreateProgram(new IShader[] { shader.HostShader });
+ IProgram hostProgram = _context.Renderer.CreateProgram(new IShader[] { shader.HostShader }, null);
ShaderBundle cpShader = new ShaderBundle(hostProgram, shader);
@@ -150,6 +150,8 @@ namespace Ryujinx.Graphics.Gpu.Shader
continue;
}
+ var tfd = GetTransformFeedbackDescriptors(state);
+
IShader hostShader = _context.Renderer.CompileShader(program);
shaders[stage].HostShader = hostShader;
@@ -157,7 +159,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
hostShaders.Add(hostShader);
}
- IProgram hostProgram = _context.Renderer.CreateProgram(hostShaders.ToArray());
+ IProgram hostProgram = _context.Renderer.CreateProgram(hostShaders.ToArray(), GetTransformFeedbackDescriptors(state));
ShaderBundle gpShaders = new ShaderBundle(hostProgram, shaders);
@@ -174,6 +176,36 @@ namespace Ryujinx.Graphics.Gpu.Shader
}
/// <summary>
+ /// Gets transform feedback state from the current GPU state.
+ /// </summary>
+ /// <param name="state">Current GPU state</param>
+ /// <returns>Four transform feedback descriptors for the enabled TFBs, or null if TFB is disabled</returns>
+ private TransformFeedbackDescriptor[] GetTransformFeedbackDescriptors(GpuState state)
+ {
+ bool tfEnable = state.Get<Boolean32>(MethodOffset.TfEnable);
+
+ if (!tfEnable)
+ {
+ return null;
+ }
+
+ TransformFeedbackDescriptor[] descs = new TransformFeedbackDescriptor[Constants.TotalTransformFeedbackBuffers];
+
+ for (int i = 0; i < Constants.TotalTransformFeedbackBuffers; i++)
+ {
+ var tf = state.Get<TfState>(MethodOffset.TfState, i);
+
+ int length = (int)Math.Min((uint)tf.VaryingsCount, 0x80);
+
+ var varyingLocations = state.GetSpan(MethodOffset.TfVaryingLocations + i * 0x80, length).ToArray();
+
+ descs[i] = new TransformFeedbackDescriptor(tf.BufferIndex, tf.Stride, varyingLocations);
+ }
+
+ return descs;
+ }
+
+ /// <summary>
/// Checks if compute shader code in memory is equal to the cached shader.
/// </summary>
/// <param name="cpShader">Cached compute shader</param>