Skip to content

Commit

Permalink
Fix some Vulkan validation errors (#4357)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdkchan authored Feb 8, 2023
1 parent 26bf13a commit f6d5499
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
7 changes: 4 additions & 3 deletions Ryujinx.Graphics.Vulkan/PipelineConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static unsafe DisposableRenderPass ToRenderPass(this ProgramPipelineState

int attachmentCount = 0;
int colorCount = 0;
int maxColorAttachmentIndex = -1;

for (int i = 0; i < state.AttachmentEnable.Length; i++)
{
Expand All @@ -36,6 +37,7 @@ public static unsafe DisposableRenderPass ToRenderPass(this ProgramPipelineState

attachmentIndices[attachmentCount++] = i;
colorCount++;
maxColorAttachmentIndex = i;
}
}

Expand Down Expand Up @@ -73,12 +75,11 @@ public static unsafe DisposableRenderPass ToRenderPass(this ProgramPipelineState

if (colorAttachmentsCount != 0)
{
int maxAttachmentIndex = Constants.MaxRenderTargets - 1;
subpass.ColorAttachmentCount = (uint)maxAttachmentIndex + 1;
subpass.ColorAttachmentCount = (uint)maxColorAttachmentIndex + 1;
subpass.PColorAttachments = &attachmentReferences[0];

// Fill with VK_ATTACHMENT_UNUSED to cover any gaps.
for (int i = 0; i <= maxAttachmentIndex; i++)
for (int i = 0; i <= maxColorAttachmentIndex; i++)
{
subpass.PColorAttachments[i] = new AttachmentReference(Vk.AttachmentUnused, ImageLayout.Undefined);
}
Expand Down
28 changes: 19 additions & 9 deletions Ryujinx.Graphics.Vulkan/PipelineFull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PipelineFull : PipelineBase, IPipeline
{
private const ulong MinByteWeightForFlush = 256 * 1024 * 1024; // MiB

private readonly List<QueryPool> _activeQueries;
private readonly List<(QueryPool, bool)> _activeQueries;
private CounterQueueEvent _activeConditionalRender;

private readonly List<BufferedQuery> _pendingQueryCopies;
Expand All @@ -19,7 +19,7 @@ class PipelineFull : PipelineBase, IPipeline

public PipelineFull(VulkanRenderer gd, Device device) : base(gd, device)
{
_activeQueries = new List<QueryPool>();
_activeQueries = new List<(QueryPool, bool)>();
_pendingQueryCopies = new();

CommandBuffer = (Cbs = gd.CommandBufferPool.Rent()).CommandBuffer;
Expand Down Expand Up @@ -202,7 +202,7 @@ public void FlushCommandsImpl()
AutoFlush.RegisterFlush(DrawCount);
EndRenderPass();

foreach (var queryPool in _activeQueries)
foreach ((var queryPool, _) in _activeQueries)
{
Gd.Api.CmdEndQuery(CommandBuffer, queryPool, 0);
}
Expand All @@ -220,18 +220,20 @@ public void FlushCommandsImpl()

// Restore per-command buffer state.

foreach (var queryPool in _activeQueries)
foreach ((var queryPool, var isOcclusion) in _activeQueries)
{
bool isPrecise = Gd.Capabilities.SupportsPreciseOcclusionQueries && isOcclusion;

Gd.Api.CmdResetQueryPool(CommandBuffer, queryPool, 0, 1);
Gd.Api.CmdBeginQuery(CommandBuffer, queryPool, 0, Gd.Capabilities.SupportsPreciseOcclusionQueries ? QueryControlFlags.PreciseBit : 0);
Gd.Api.CmdBeginQuery(CommandBuffer, queryPool, 0, isPrecise ? QueryControlFlags.PreciseBit : 0);
}

Gd.ResetCounterPool();

Restore();
}

public void BeginQuery(BufferedQuery query, QueryPool pool, bool needsReset, bool fromSamplePool)
public void BeginQuery(BufferedQuery query, QueryPool pool, bool needsReset, bool isOcclusion, bool fromSamplePool)
{
if (needsReset)
{
Expand All @@ -247,16 +249,24 @@ public void BeginQuery(BufferedQuery query, QueryPool pool, bool needsReset, boo
}
}

Gd.Api.CmdBeginQuery(CommandBuffer, pool, 0, Gd.Capabilities.SupportsPreciseOcclusionQueries ? QueryControlFlags.PreciseBit : 0);
bool isPrecise = Gd.Capabilities.SupportsPreciseOcclusionQueries && isOcclusion;
Gd.Api.CmdBeginQuery(CommandBuffer, pool, 0, isPrecise ? QueryControlFlags.PreciseBit : 0);

_activeQueries.Add(pool);
_activeQueries.Add((pool, isOcclusion));
}

public void EndQuery(QueryPool pool)
{
Gd.Api.CmdEndQuery(CommandBuffer, pool, 0);

_activeQueries.Remove(pool);
for (int i = 0; i < _activeQueries.Count; i++)
{
if (_activeQueries[i].Item1.Handle == pool.Handle)
{
_activeQueries.RemoveAt(i);
break;
}
}
}

public void CopyQueryResults(BufferedQuery query)
Expand Down
3 changes: 2 additions & 1 deletion Ryujinx.Graphics.Vulkan/Queries/BufferedQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public void Begin(int? resetSequence)
if (_isSupported)
{
bool needsReset = resetSequence == null || _resetSequence == null || resetSequence.Value != _resetSequence.Value;
_pipeline.BeginQuery(this, _queryPool, needsReset, _type == CounterType.SamplesPassed && resetSequence != null);
bool isOcclusion = _type == CounterType.SamplesPassed;
_pipeline.BeginQuery(this, _queryPool, needsReset, isOcclusion, isOcclusion && resetSequence != null);
}
_resetSequence = null;
}
Expand Down
2 changes: 1 addition & 1 deletion Ryujinx.Graphics.Vulkan/TextureView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public TextureView(
var componentMapping = new ComponentMapping(swizzleR, swizzleG, swizzleB, swizzleA);

var aspectFlags = info.Format.ConvertAspectFlags(info.DepthStencilMode);
var aspectFlagsDepth = info.Format.ConvertAspectFlags(DepthStencilMode.Depth);
var aspectFlagsDepth = info.Format.ConvertAspectFlags();

var subresourceRange = new ImageSubresourceRange(aspectFlags, (uint)firstLevel, levels, (uint)firstLayer, layers);
var subresourceRangeDepth = new ImageSubresourceRange(aspectFlagsDepth, (uint)firstLevel, levels, (uint)firstLayer, layers);
Expand Down

0 comments on commit f6d5499

Please sign in to comment.