Skip to content

Commit

Permalink
Revert "Vulkan: Feedback loop detection and barriers (#7226)"
Browse files Browse the repository at this point in the history
This reverts commit ca59c3f.
  • Loading branch information
KeatonTheBot committed Nov 20, 2024
1 parent c0a4d95 commit fd84e07
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 532 deletions.
24 changes: 2 additions & 22 deletions src/Ryujinx.Common/GraphicsDriver/DriverUtilities.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
using Ryujinx.Common.Utilities;
using System;

namespace Ryujinx.Common.GraphicsDriver
{
public static class DriverUtilities
{
private static void AddMesaFlags(string envVar, string newFlags)
{
string existingFlags = Environment.GetEnvironmentVariable(envVar);

string flags = existingFlags == null ? newFlags : $"{existingFlags},{newFlags}";

OsUtils.SetEnvironmentVariableNoCaching(envVar, flags);
}

public static void InitDriverConfig(bool oglThreading)
{
if (OperatingSystem.IsLinux())
{
AddMesaFlags("RADV_DEBUG", "nodcc");
}

ToggleOGLThreading(oglThreading);
}

public static void ToggleOGLThreading(bool enabled)
{
OsUtils.SetEnvironmentVariableNoCaching("mesa_glthread", enabled.ToString().ToLower());
OsUtils.SetEnvironmentVariableNoCaching("__GL_THREADED_OPTIMIZATIONS", enabled ? "1" : "0");
Environment.SetEnvironmentVariable("mesa_glthread", enabled.ToString().ToLower());
Environment.SetEnvironmentVariable("__GL_THREADED_OPTIMIZATIONS", enabled ? "1" : "0");

try
{
Expand Down
24 changes: 0 additions & 24 deletions src/Ryujinx.Common/Utilities/OsUtils.cs

This file was deleted.

39 changes: 13 additions & 26 deletions src/Ryujinx.Graphics.Vulkan/BarrierBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ private enum IncoherentBarrierType
CommandBuffer
}

private bool _feedbackLoopActive;
private PipelineStageFlags _incoherentBufferWriteStages;
private PipelineStageFlags _incoherentTextureWriteStages;
private PipelineStageFlags _extraStages;
private IncoherentBarrierType _queuedIncoherentBarrier;
private bool _queuedFeedbackLoopBarrier;

public BarrierBatch(VulkanRenderer gd)
{
Expand All @@ -55,6 +53,17 @@ public static (AccessFlags Access, PipelineStageFlags Stages) GetSubpassAccessSu
stages |= PipelineStageFlags.TransformFeedbackBitExt;
}

if (!gd.IsTBDR)
{
// Desktop GPUs can transform image barriers into memory barriers.

access |= AccessFlags.DepthStencilAttachmentWriteBit | AccessFlags.ColorAttachmentWriteBit;
access |= AccessFlags.DepthStencilAttachmentReadBit | AccessFlags.ColorAttachmentReadBit;

stages |= PipelineStageFlags.EarlyFragmentTestsBit | PipelineStageFlags.LateFragmentTestsBit;
stages |= PipelineStageFlags.ColorAttachmentOutputBit;
}

return (access, stages);
}

Expand Down Expand Up @@ -169,43 +178,23 @@ public unsafe void FlushMemoryBarrier(ShaderCollection program, bool inRenderPas
}

_queuedIncoherentBarrier = IncoherentBarrierType.None;
_queuedFeedbackLoopBarrier = false;
}
else if (_feedbackLoopActive && _queuedFeedbackLoopBarrier)
{
// Feedback loop barrier.

MemoryBarrier barrier = new MemoryBarrier()
{
SType = StructureType.MemoryBarrier,
SrcAccessMask = AccessFlags.ShaderWriteBit,
DstAccessMask = AccessFlags.ShaderReadBit
};

QueueBarrier(barrier, PipelineStageFlags.FragmentShaderBit, PipelineStageFlags.AllGraphicsBit);

_queuedFeedbackLoopBarrier = false;
}

_feedbackLoopActive = false;
}
}

public unsafe void Flush(CommandBufferScoped cbs, bool inRenderPass, RenderPassHolder rpHolder, Action endRenderPass)
{
Flush(cbs, null, false, inRenderPass, rpHolder, endRenderPass);
Flush(cbs, null, inRenderPass, rpHolder, endRenderPass);
}

public unsafe void Flush(CommandBufferScoped cbs, ShaderCollection program, bool feedbackLoopActive, bool inRenderPass, RenderPassHolder rpHolder, Action endRenderPass)
public unsafe void Flush(CommandBufferScoped cbs, ShaderCollection program, bool inRenderPass, RenderPassHolder rpHolder, Action endRenderPass)
{
if (program != null)
{
_incoherentBufferWriteStages |= program.IncoherentBufferWriteStages | _extraStages;
_incoherentTextureWriteStages |= program.IncoherentTextureWriteStages;
}

_feedbackLoopActive |= feedbackLoopActive;

FlushMemoryBarrier(program, inRenderPass);

if (!inRenderPass && rpHolder != null)
Expand Down Expand Up @@ -417,8 +406,6 @@ private void QueueIncoherentBarrier(IncoherentBarrierType type)
{
_queuedIncoherentBarrier = type;
}

_queuedFeedbackLoopBarrier = true;
}

public void QueueTextureBarrier()
Expand Down
65 changes: 19 additions & 46 deletions src/Ryujinx.Graphics.Vulkan/DescriptorSetUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Silk.NET.Vulkan;
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using CompareOp = Ryujinx.Graphics.GAL.CompareOp;
Expand Down Expand Up @@ -43,30 +42,30 @@ public BufferRef(Auto<DisposableBuffer> buffer, ref BufferRange range)
private record struct TextureRef
{
public ShaderStage Stage;
public TextureView View;
public Auto<DisposableImageView> ImageView;
public TextureStorage Storage;
public Auto<DisposableImageView> View;
public Auto<DisposableSampler> Sampler;

public TextureRef(ShaderStage stage, TextureView view, Auto<DisposableImageView> imageView, Auto<DisposableSampler> sampler)
public TextureRef(ShaderStage stage, TextureStorage storage, Auto<DisposableImageView> view, Auto<DisposableSampler> sampler)
{
Stage = stage;
Storage = storage;
View = view;
ImageView = imageView;
Sampler = sampler;
}
}

private record struct ImageRef
{
public ShaderStage Stage;
public TextureView View;
public Auto<DisposableImageView> ImageView;
public TextureStorage Storage;
public Auto<DisposableImageView> View;

public ImageRef(ShaderStage stage, TextureView view, Auto<DisposableImageView> imageView)
public ImageRef(ShaderStage stage, TextureStorage storage, Auto<DisposableImageView> view)
{
Stage = stage;
Storage = storage;
View = view;
ImageView = imageView;
}
}

Expand Down Expand Up @@ -124,8 +123,6 @@ private enum DirtyFlags
private readonly TextureView _dummyTexture;
private readonly SamplerHolder _dummySampler;

public List<TextureView> FeedbackLoopHazards { get; private set; }

public DescriptorSetUpdater(VulkanRenderer gd, Device device)
{
_gd = gd;
Expand Down Expand Up @@ -210,15 +207,10 @@ public DescriptorSetUpdater(VulkanRenderer gd, Device device)
_templateUpdater = new();
}

public void Initialize(bool isMainPipeline)
public void Initialize()
{
MemoryOwner<byte> dummyTextureData = MemoryOwner<byte>.RentCleared(4);
_dummyTexture.SetData(dummyTextureData);

if (isMainPipeline)
{
FeedbackLoopHazards = new();
}
}

private static bool BindingOverlaps(ref DescriptorBufferInfo info, int bindingOffset, int offset, int size)
Expand Down Expand Up @@ -281,18 +273,6 @@ internal void Rebind(Auto<DisposableBuffer> buffer, int offset, int size)

public void InsertBindingBarriers(CommandBufferScoped cbs)
{
if ((FeedbackLoopHazards?.Count ?? 0) > 0)
{
// Clear existing hazards - they will be rebuilt.

foreach (TextureView hazard in FeedbackLoopHazards)
{
hazard.DecrementHazardUses();
}

FeedbackLoopHazards.Clear();
}

foreach (ResourceBindingSegment segment in _program.BindingSegments[PipelineBase.TextureSetIndex])
{
if (segment.Type == ResourceType.TextureAndSampler)
Expand All @@ -302,7 +282,7 @@ public void InsertBindingBarriers(CommandBufferScoped cbs)
for (int i = 0; i < segment.Count; i++)
{
ref var texture = ref _textureRefs[segment.Binding + i];
texture.View?.PrepareForUsage(cbs, texture.Stage.ConvertToPipelineStageFlags(), FeedbackLoopHazards);
texture.Storage?.QueueWriteToReadBarrier(cbs, AccessFlags.ShaderReadBit, texture.Stage.ConvertToPipelineStageFlags());
}
}
else
Expand All @@ -323,7 +303,7 @@ public void InsertBindingBarriers(CommandBufferScoped cbs)
for (int i = 0; i < segment.Count; i++)
{
ref var image = ref _imageRefs[segment.Binding + i];
image.View?.PrepareForUsage(cbs, image.Stage.ConvertToPipelineStageFlags(), FeedbackLoopHazards);
image.Storage?.QueueWriteToReadBarrier(cbs, AccessFlags.ShaderReadBit, image.Stage.ConvertToPipelineStageFlags());
}
}
else
Expand Down Expand Up @@ -397,12 +377,8 @@ public void SetImage(CommandBufferScoped cbs, ShaderStage stage, int binding, IT
}
else if (image is TextureView view)
{
ref ImageRef iRef = ref _imageRefs[binding];

iRef.View?.ClearUsage(FeedbackLoopHazards);
view?.PrepareForUsage(cbs, stage.ConvertToPipelineStageFlags(), FeedbackLoopHazards);

iRef = new(stage, view, view.GetIdentityImageView());
view.Storage.QueueWriteToReadBarrier(cbs, AccessFlags.ShaderReadBit, stage.ConvertToPipelineStageFlags());
_imageRefs[binding] = new(stage, view.Storage, view.GetIdentityImageView());
}
else
{
Expand Down Expand Up @@ -500,12 +476,9 @@ public void SetTextureAndSampler(
}
else if (texture is TextureView view)
{
ref TextureRef iRef = ref _textureRefs[binding];

iRef.View?.ClearUsage(FeedbackLoopHazards);
view?.PrepareForUsage(cbs, stage.ConvertToPipelineStageFlags(), FeedbackLoopHazards);
view.Storage.QueueWriteToReadBarrier(cbs, AccessFlags.ShaderReadBit, stage.ConvertToPipelineStageFlags());

iRef = new(stage, view, view.GetImageView(), ((SamplerHolder)sampler)?.GetSampler());
_textureRefs[binding] = new(stage, view.Storage, view.GetImageView(), ((SamplerHolder)sampler)?.GetSampler());
}
else
{
Expand All @@ -527,7 +500,7 @@ public void SetTextureAndSamplerIdentitySwizzle(
{
view.Storage.QueueWriteToReadBarrier(cbs, AccessFlags.ShaderReadBit, stage.ConvertToPipelineStageFlags());

_textureRefs[binding] = new(stage, view, view.GetIdentityImageView(), ((SamplerHolder)sampler)?.GetSampler());
_textureRefs[binding] = new(stage, view.Storage, view.GetIdentityImageView(), ((SamplerHolder)sampler)?.GetSampler());

SignalDirty(DirtyFlags.Texture);
}
Expand Down Expand Up @@ -853,7 +826,7 @@ private void UpdateAndBind(CommandBufferScoped cbs, ShaderCollection program, in
ref var texture = ref textures[i];
ref var refs = ref _textureRefs[binding + i];

texture.ImageView = refs.ImageView?.Get(cbs).Value ?? default;
texture.ImageView = refs.View?.Get(cbs).Value ?? default;
texture.Sampler = refs.Sampler?.Get(cbs).Value ?? default;

if (texture.ImageView.Handle == 0)
Expand Down Expand Up @@ -903,7 +876,7 @@ private void UpdateAndBind(CommandBufferScoped cbs, ShaderCollection program, in

for (int i = 0; i < count; i++)
{
images[i].ImageView = _imageRefs[binding + i].ImageView?.Get(cbs).Value ?? default;
images[i].ImageView = _imageRefs[binding + i].View?.Get(cbs).Value ?? default;
}

tu.Push<DescriptorImageInfo>(images[..count]);
Expand Down Expand Up @@ -974,7 +947,7 @@ private void UpdateAndBindTexturesWithoutTemplate(CommandBufferScoped cbs, Shade
ref var texture = ref textures[i];
ref var refs = ref _textureRefs[binding + i];

texture.ImageView = refs.ImageView?.Get(cbs).Value ?? default;
texture.ImageView = refs.View?.Get(cbs).Value ?? default;
texture.Sampler = refs.Sampler?.Get(cbs).Value ?? default;

if (texture.ImageView.Handle == 0)
Expand Down
12 changes: 0 additions & 12 deletions src/Ryujinx.Graphics.Vulkan/FeedbackLoopAspects.cs

This file was deleted.

21 changes: 0 additions & 21 deletions src/Ryujinx.Graphics.Vulkan/FramebufferParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,27 +302,6 @@ public void AddStoreOpUsage()
_depthStencil?.Storage?.AddStoreOpUsage(true);
}

public void ClearBindings()
{
_depthStencil?.Storage.ClearBindings();

for (int i = 0; i < _colorsCanonical.Length; i++)
{
_colorsCanonical[i]?.Storage.ClearBindings();
}
}

public void AddBindings()
{
_depthStencil?.Storage.AddBinding(_depthStencil);

for (int i = 0; i < _colorsCanonical.Length; i++)
{
TextureView color = _colorsCanonical[i];
color?.Storage.AddBinding(color);
}
}

public (RenderPassHolder rpHolder, Auto<DisposableFramebuffer> framebuffer) GetPassAndFramebuffer(
VulkanRenderer gd,
Device device,
Expand Down
6 changes: 0 additions & 6 deletions src/Ryujinx.Graphics.Vulkan/HardwareCapabilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ readonly struct HardwareCapabilities
public readonly bool SupportsViewportArray2;
public readonly bool SupportsHostImportedMemory;
public readonly bool SupportsDepthClipControl;
public readonly bool SupportsAttachmentFeedbackLoop;
public readonly bool SupportsDynamicAttachmentFeedbackLoop;
public readonly uint SubgroupSize;
public readonly SampleCountFlags SupportedSampleCounts;
public readonly PortabilitySubsetFlags PortabilitySubset;
Expand Down Expand Up @@ -86,8 +84,6 @@ public HardwareCapabilities(
bool supportsViewportArray2,
bool supportsHostImportedMemory,
bool supportsDepthClipControl,
bool supportsAttachmentFeedbackLoop,
bool supportsDynamicAttachmentFeedbackLoop,
uint subgroupSize,
SampleCountFlags supportedSampleCounts,
PortabilitySubsetFlags portabilitySubset,
Expand Down Expand Up @@ -125,8 +121,6 @@ public HardwareCapabilities(
SupportsViewportArray2 = supportsViewportArray2;
SupportsHostImportedMemory = supportsHostImportedMemory;
SupportsDepthClipControl = supportsDepthClipControl;
SupportsAttachmentFeedbackLoop = supportsAttachmentFeedbackLoop;
SupportsDynamicAttachmentFeedbackLoop = supportsDynamicAttachmentFeedbackLoop;
SubgroupSize = subgroupSize;
SupportedSampleCounts = supportedSampleCounts;
PortabilitySubset = portabilitySubset;
Expand Down
Loading

0 comments on commit fd84e07

Please sign in to comment.