Move redundant bindings update checking to the backend

This commit is contained in:
Gabriel A 2024-03-25 13:49:05 -03:00
parent 70a6b7ea65
commit 596a1b1d88
2 changed files with 22 additions and 65 deletions

View file

@ -175,7 +175,6 @@ namespace Ryujinx.Graphics.Gpu.Image
private int[] _cachedTextureBuffer;
private int[] _cachedSamplerBuffer;
private int _lastBinding;
private int _lastSequenceNumber;
/// <summary>
@ -194,7 +193,6 @@ namespace Ryujinx.Graphics.Gpu.Image
_texturePool = texturePool;
_samplerPool = samplerPool;
_lastBinding = -1;
_lastSequenceNumber = -1;
}
@ -249,18 +247,6 @@ namespace Ryujinx.Graphics.Gpu.Image
SamplerIds.Clear();
}
/// <summary>
/// Invalidates the cached binding number if it equals to <paramref name="binding"/>.
/// </summary>
/// <param name="binding">Binding number to match</param>
public void ClearBindingIfEqual(int binding)
{
if (_lastBinding == binding)
{
_lastBinding = -1;
}
}
/// <summary>
/// Updates the cached constant buffer data.
/// </summary>
@ -290,35 +276,6 @@ namespace Ryujinx.Graphics.Gpu.Image
return true;
}
/// <summary>
/// Updates the cached binding number.
/// </summary>
/// <param name="parent">Cache instance</param>
/// <param name="newBinding">New binding number</param>
public void SetNewBinding(TextureBindingsArrayCache parent, int newBinding)
{
parent.ClearBindingsIfEqual(newBinding);
_lastBinding = newBinding;
}
/// <summary>
/// Checks if the binding number changed since the last call to this method.
/// </summary>
/// <param name="parent">Cache instance</param>
/// <param name="newBinding">New binding number</param>
/// <returns>True if the binding changed, false otherwise</returns>
public bool BindingChanged(TextureBindingsArrayCache parent, int newBinding)
{
if (_lastBinding != newBinding)
{
SetNewBinding(parent, newBinding);
return true;
}
return false;
}
/// <summary>
/// Checks if the cached texture or sampler pool has been modified since the last call to this method.
/// </summary>
@ -520,7 +477,11 @@ namespace Ryujinx.Graphics.Gpu.Image
{
entry.SynchronizeMemory(isStore);
if (entry.BindingChanged(this, bindingInfo.Binding))
if (isImage)
{
_context.Renderer.Pipeline.SetImageArray(stage, bindingInfo.Binding, entry.ImageArray);
}
else
{
_context.Renderer.Pipeline.SetTextureArray(stage, bindingInfo.Binding, entry.TextureArray);
}
@ -545,7 +506,11 @@ namespace Ryujinx.Graphics.Gpu.Image
{
entry.SynchronizeMemory(isStore);
if (entry.BindingChanged(this, bindingInfo.Binding))
if (isImage)
{
_context.Renderer.Pipeline.SetImageArray(stage, bindingInfo.Binding, entry.ImageArray);
}
else
{
_context.Renderer.Pipeline.SetTextureArray(stage, bindingInfo.Binding, entry.TextureArray);
}
@ -652,8 +617,6 @@ namespace Ryujinx.Graphics.Gpu.Image
}
}
entry.SetNewBinding(this, bindingInfo.Binding);
if (isImage)
{
entry.ImageArray.SetFormats(0, formats);
@ -743,17 +706,5 @@ namespace Ryujinx.Graphics.Gpu.Image
_lruCache.Remove(toRemove);
}
}
/// <summary>
/// Clears all cached bindings that are equal to <paramref name="binding"/>.
/// </summary>
/// <param name="binding">Binding number to clear</param>
private void ClearBindingsIfEqual(int binding)
{
foreach (CacheEntry entry in _cache.Values)
{
entry.ClearBindingIfEqual(binding);
}
}
}
}

View file

@ -499,10 +499,13 @@ namespace Ryujinx.Graphics.Vulkan
Array.Resize(ref _textureArrayRefs, binding + ArrayGrowthSize);
}
_textureArrayRefs[binding] = new ArrayRef<TextureArray>(stage, array as TextureArray);
_textureArrayRefs[binding].Array?.QueueWriteToReadBarriers(cbs, stage.ConvertToPipelineStageFlags());
if (_textureArrayRefs[binding].Stage != stage || _textureArrayRefs[binding].Array != array)
{
_textureArrayRefs[binding] = new ArrayRef<TextureArray>(stage, array as TextureArray);
_textureArrayRefs[binding].Array?.QueueWriteToReadBarriers(cbs, stage.ConvertToPipelineStageFlags());
SignalDirty(DirtyFlags.Texture);
SignalDirty(DirtyFlags.Texture);
}
}
public void SetImageArray(CommandBufferScoped cbs, ShaderStage stage, int binding, IImageArray array)
@ -512,10 +515,13 @@ namespace Ryujinx.Graphics.Vulkan
Array.Resize(ref _imageArrayRefs, binding + ArrayGrowthSize);
}
_imageArrayRefs[binding] = new ArrayRef<ImageArray>(stage, array as ImageArray);
_imageArrayRefs[binding].Array?.QueueWriteToReadBarriers(cbs, stage.ConvertToPipelineStageFlags());
if (_imageArrayRefs[binding].Stage != stage || _imageArrayRefs[binding].Array != array)
{
_imageArrayRefs[binding] = new ArrayRef<ImageArray>(stage, array as ImageArray);
_imageArrayRefs[binding].Array?.QueueWriteToReadBarriers(cbs, stage.ConvertToPipelineStageFlags());
SignalDirty(DirtyFlags.Image);
SignalDirty(DirtyFlags.Image);
}
}
public void SetUniformBuffers(CommandBuffer commandBuffer, ReadOnlySpan<BufferAssignment> buffers)