aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Gpu/Engine
diff options
context:
space:
mode:
authorriperiperi <rhy3756547@hotmail.com>2022-12-04 17:18:40 +0000
committerGitHub <noreply@github.com>2022-12-04 18:18:40 +0100
commit4965681e069eeedc5272030b131c2a45e6131e61 (patch)
tree050a6596728c6a040c5c17fd21339c913b97ee8f /Ryujinx.Graphics.Gpu/Engine
parent3868a0020611491e30db19e5b27d33a7559c7071 (diff)
GPU: Swap bindings array instead of copying (#4003)
* GPU: Swap bindings array instead of copying Reduces work on UpdateShaderState. Now the cost is a few reference moves for arrays, rather than copying data. Downside: bindings arrays are no longer readonly. * Micro optimisation * Add missing docs * Address Feedback
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Engine')
-rw-r--r--Ryujinx.Graphics.Gpu/Engine/Compute/ComputeClass.cs52
-rw-r--r--Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs80
2 files changed, 10 insertions, 122 deletions
diff --git a/Ryujinx.Graphics.Gpu/Engine/Compute/ComputeClass.cs b/Ryujinx.Graphics.Gpu/Engine/Compute/ComputeClass.cs
index cd509471..2ac738fd 100644
--- a/Ryujinx.Graphics.Gpu/Engine/Compute/ComputeClass.cs
+++ b/Ryujinx.Graphics.Gpu/Engine/Compute/ComputeClass.cs
@@ -202,57 +202,9 @@ namespace Ryujinx.Graphics.Gpu.Engine.Compute
_channel.BufferManager.SetComputeUniformBuffer(cb.Slot, cbDescriptor.PackAddress(), (uint)cbDescriptor.Size);
}
- _channel.BufferManager.SetComputeStorageBufferBindings(info.SBuffers);
- _channel.BufferManager.SetComputeUniformBufferBindings(info.CBuffers);
+ _channel.BufferManager.SetComputeBufferBindings(cs.Bindings);
- int maxTextureBinding = -1;
- int maxImageBinding = -1;
-
- TextureBindingInfo[] textureBindings = _channel.TextureManager.RentComputeTextureBindings(info.Textures.Count);
-
- for (int index = 0; index < info.Textures.Count; index++)
- {
- var descriptor = info.Textures[index];
-
- Target target = ShaderTexture.GetTarget(descriptor.Type);
-
- textureBindings[index] = new TextureBindingInfo(
- target,
- descriptor.Binding,
- descriptor.CbufSlot,
- descriptor.HandleIndex,
- descriptor.Flags);
-
- if (descriptor.Binding > maxTextureBinding)
- {
- maxTextureBinding = descriptor.Binding;
- }
- }
-
- TextureBindingInfo[] imageBindings = _channel.TextureManager.RentComputeImageBindings(info.Images.Count);
-
- for (int index = 0; index < info.Images.Count; index++)
- {
- var descriptor = info.Images[index];
-
- Target target = ShaderTexture.GetTarget(descriptor.Type);
- Format format = ShaderTexture.GetFormat(descriptor.Format);
-
- imageBindings[index] = new TextureBindingInfo(
- target,
- format,
- descriptor.Binding,
- descriptor.CbufSlot,
- descriptor.HandleIndex,
- descriptor.Flags);
-
- if (descriptor.Binding > maxImageBinding)
- {
- maxImageBinding = descriptor.Binding;
- }
- }
-
- _channel.TextureManager.SetComputeMaxBindings(maxTextureBinding, maxImageBinding);
+ _channel.TextureManager.SetComputeBindings(cs.Bindings);
// Should never return false for mismatching spec state, since the shader was fetched above.
_channel.TextureManager.CommitComputeBindings(cs.SpecializationState);
diff --git a/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs b/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs
index 8da5ea5e..fe7e0d09 100644
--- a/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs
+++ b/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs
@@ -1257,88 +1257,24 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
UpdateUserClipState();
}
+ UpdateShaderBindings(gs.Bindings);
+
for (int stageIndex = 0; stageIndex < Constants.ShaderStages; stageIndex++)
{
- UpdateStageBindings(stageIndex, gs.Shaders[stageIndex + 1]?.Info);
+ _currentProgramInfo[stageIndex] = gs.Shaders[stageIndex + 1]?.Info;
}
_context.Renderer.Pipeline.SetProgram(gs.HostProgram);
}
/// <summary>
- /// Updates bindings consumed by the shader stage on the texture and buffer managers.
+ /// Updates bindings consumed by the shader on the texture and buffer managers.
/// </summary>
- /// <param name="stage">Shader stage to have the bindings updated</param>
- /// <param name="info">Shader stage bindings info</param>
- private void UpdateStageBindings(int stage, ShaderProgramInfo info)
+ /// <param name="bindings">Bindings for the active shader</param>
+ private void UpdateShaderBindings(CachedShaderBindings bindings)
{
- _currentProgramInfo[stage] = info;
-
- if (info == null)
- {
- _channel.TextureManager.RentGraphicsTextureBindings(stage, 0);
- _channel.TextureManager.RentGraphicsImageBindings(stage, 0);
- _channel.BufferManager.SetGraphicsStorageBufferBindings(stage, null);
- _channel.BufferManager.SetGraphicsUniformBufferBindings(stage, null);
- return;
- }
-
- int maxTextureBinding = -1;
- int maxImageBinding = -1;
-
- Span<TextureBindingInfo> textureBindings = _channel.TextureManager.RentGraphicsTextureBindings(stage, info.Textures.Count);
-
- if (info.UsesRtLayer)
- {
- _vtgWritesRtLayer = true;
- }
-
- for (int index = 0; index < info.Textures.Count; index++)
- {
- var descriptor = info.Textures[index];
-
- Target target = ShaderTexture.GetTarget(descriptor.Type);
-
- textureBindings[index] = new TextureBindingInfo(
- target,
- descriptor.Binding,
- descriptor.CbufSlot,
- descriptor.HandleIndex,
- descriptor.Flags);
-
- if (descriptor.Binding > maxTextureBinding)
- {
- maxTextureBinding = descriptor.Binding;
- }
- }
-
- TextureBindingInfo[] imageBindings = _channel.TextureManager.RentGraphicsImageBindings(stage, info.Images.Count);
-
- for (int index = 0; index < info.Images.Count; index++)
- {
- var descriptor = info.Images[index];
-
- Target target = ShaderTexture.GetTarget(descriptor.Type);
- Format format = ShaderTexture.GetFormat(descriptor.Format);
-
- imageBindings[index] = new TextureBindingInfo(
- target,
- format,
- descriptor.Binding,
- descriptor.CbufSlot,
- descriptor.HandleIndex,
- descriptor.Flags);
-
- if (descriptor.Binding > maxImageBinding)
- {
- maxImageBinding = descriptor.Binding;
- }
- }
-
- _channel.TextureManager.SetGraphicsMaxBindings(maxTextureBinding, maxImageBinding);
-
- _channel.BufferManager.SetGraphicsStorageBufferBindings(stage, info.SBuffers);
- _channel.BufferManager.SetGraphicsUniformBufferBindings(stage, info.CBuffers);
+ _channel.TextureManager.SetGraphicsBindings(bindings);
+ _channel.BufferManager.SetGraphicsBufferBindings(bindings);
}
/// <summary>