[Diagnostics] Report the GPU writers of synchronized DCC metadata

This commit is contained in:
ParantezTech 2026-10-11 06:11:55 +03:00
parent d4276d89f8
commit b26c59460d
5 changed files with 59 additions and 0 deletions

View File

@ -28,6 +28,42 @@ internal static class DccWriterTrace
private static readonly HashSet<(ulong Address, ulong Size, ulong Program)> _reported = new(); private static readonly HashSet<(ulong Address, ulong Size, ulong Program)> _reported = new();
private static readonly HashSet<(ulong Hash, string Reason)> _refusals = new(); private static readonly HashSet<(ulong Hash, string Reason)> _refusals = new();
private static readonly System.Collections.Concurrent.ConcurrentDictionary<ulong, (ulong Size, ulong Program, string Kind)> _writes = new();
private static readonly HashSet<ulong> _syncReported = new();
[ThreadStatic]
public static string? CurrentKind;
public static void RecordWrite(ulong address, ulong size)
{
if (DccEnabled)
{
_writes[address] = (size, CurrentProgram, CurrentKind ?? "?");
}
}
public static void ReportSync(ulong metadataAddress, ulong size)
{
if (!DccEnabled)
{
return;
}
lock (_syncReported)
{
if (_syncReported.Count >= 64 || !_syncReported.Add(metadataAddress))
{
return;
}
}
var writers = _writes
.Where(pair => pair.Key < metadataAddress + size && metadataAddress < pair.Key + pair.Value.Size)
.Take(8)
.Select(pair => $"0x{pair.Key:X}+0x{pair.Value.Size:X}:{pair.Value.Kind}:0x{pair.Value.Program:X16}");
Console.Error.WriteLine(
$"[GPU][DCC_SYNC_WRITER] metadata=0x{metadataAddress:X16} size=0x{size:X} writers={string.Join(" ", writers)}");
}
private static ulong ParseAddress(string? value) private static ulong ParseAddress(string? value)
{ {

View File

@ -244,6 +244,7 @@ public sealed unsafe class GuestBufferCache : IGuestBufferStore, IDisposable
if (Diagnostics.DccWriterTrace.Enabled) if (Diagnostics.DccWriterTrace.Enabled)
{ {
Diagnostics.DccWriterTrace.Record(RequireImageCache(), guestAddress, size); Diagnostics.DccWriterTrace.Record(RequireImageCache(), guestAddress, size);
Diagnostics.DccWriterTrace.RecordWrite(guestAddress, size);
} }
if (!_gpuModifiedRanges.Contains(guestAddress, size)) if (!_gpuModifiedRanges.Contains(guestAddress, size))
@ -412,6 +413,11 @@ public sealed unsafe class GuestBufferCache : IGuestBufferStore, IDisposable
var (destination, destinationOffset) = ObtainBuffer(guestAddress, size, true, true, bufferIdentifier); var (destination, destinationOffset) = ObtainBuffer(guestAddress, size, true, true, bufferIdentifier);
destination.Fill(destinationOffset, size, value); destination.Fill(destinationOffset, size, value);
if (images.OverlapsDccMetadata(guestAddress, size) && TryWriteFillToBacking(guestAddress, size, value)) if (images.OverlapsDccMetadata(guestAddress, size) && TryWriteFillToBacking(guestAddress, size, value))
if (Diagnostics.DccWriterTrace.Enabled)
{
Diagnostics.DccWriterTrace.CurrentKind = "fill";
}
{ {
_gpuModifiedRanges.Remove(guestAddress, size); _gpuModifiedRanges.Remove(guestAddress, size);
Interlocked.Increment(ref _gpuModifiedVersion); Interlocked.Increment(ref _gpuModifiedVersion);
@ -642,6 +648,11 @@ public sealed unsafe class GuestBufferCache : IGuestBufferStore, IDisposable
var (dst, dstOffset) = dstMemory ? ObtainBuffer(dstVaddr, size, true, true, dstId) : (_gds, dstVaddr); var (dst, dstOffset) = dstMemory ? ObtainBuffer(dstVaddr, size, true, true, dstId) : (_gds, dstVaddr);
if (ReferenceEquals(src, dst) && srcOffset < dstOffset + size && dstOffset < srcOffset + size) if (ReferenceEquals(src, dst) && srcOffset < dstOffset + size && dstOffset < srcOffset + size)
{ {
if (Diagnostics.DccWriterTrace.Enabled)
{
Diagnostics.DccWriterTrace.CurrentKind = $"copy_from_0x{srcVaddr:X}";
}
throw SubmissionScheduler.Fatal("The resolved Vulkan copy ranges overlap."); throw SubmissionScheduler.Fatal("The resolved Vulkan copy ranges overlap.");
} }

View File

@ -436,6 +436,11 @@ public sealed partial class GuestImageCache
if (IsValidRange(address, size) && _bufferCache.HasGpuDirtyBytes(address, size)) if (IsValidRange(address, size) && _bufferCache.HasGpuDirtyBytes(address, size))
{ {
Interlocked.Increment(ref _dccSyncs); Interlocked.Increment(ref _dccSyncs);
if (Diagnostics.DccWriterTrace.Enabled)
{
Diagnostics.DccWriterTrace.ReportSync(address, size);
}
_ = _bufferCache.TrySynchronizeCpuRead(address, size); _ = _bufferCache.TrySynchronizeCpuRead(address, size);
} }
} }

View File

@ -72,6 +72,7 @@ public sealed partial class RenderExecutor
if (Diagnostics.DccWriterTrace.Enabled) if (Diagnostics.DccWriterTrace.Enabled)
{ {
Diagnostics.DccWriterTrace.CurrentProgram = program.Hash; Diagnostics.DccWriterTrace.CurrentProgram = program.Hash;
Diagnostics.DccWriterTrace.CurrentKind = "compute";
} }
if (RenderTrace.Enabled) if (RenderTrace.Enabled)

View File

@ -17,6 +17,12 @@ public sealed partial class RenderExecutor
private bool TryResolveDrawTargets(RegisterBanks banks, in DrawCall draw, ref DrawState state) private bool TryResolveDrawTargets(RegisterBanks banks, in DrawCall draw, ref DrawState state)
{ {
using var profileScope = RenderPhaseProfile.MeasureDetail(RenderPhaseProfile.Phase.DrawTargetResolution); using var profileScope = RenderPhaseProfile.MeasureDetail(RenderPhaseProfile.Phase.DrawTargetResolution);
if (Diagnostics.DccWriterTrace.Enabled)
{
Diagnostics.DccWriterTrace.CurrentKind = "draw";
Diagnostics.DccWriterTrace.CurrentProgram = 0;
}
var context = banks.Context; var context = banks.Context;
if (TryResolveMultisampleColor(context)) if (TryResolveMultisampleColor(context))
{ {