revert to lazy d3d12 access trakcing for now

This commit is contained in:
jacob 2026-03-09 17:15:21 -07:00
parent 05ef2b5d1f
commit df5902ca92
2 changed files with 43 additions and 254 deletions

View File

@ -2141,112 +2141,6 @@ void G_D12_InsertEvent(ID3D12GraphicsCommandList7 *d3d_cl, G_D12_EventKind kind,
////////////////////////////////////////////////////////////
//~ Tracking
// void G_D12_UpdateTrackedUsage(Arena *arena, G_D12_CmdBatch *batch, G_D12_Resource *resource, RngI32 mips, G_D12_TrackedUsageKind usage_kind)
// {
// b32 should_track = !AnyBit(resource->d3d_desc.Flags, D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS);
// if (should_track)
// {
// G_D12_CmdBatch *prev_batch = batch->prev;
// G_D12_TrackedResourceNode *trn = 0;
// G_D12_TrackedResourceNode *prev_trn = 0;
// {
// u64 hash = MixU64(resource->uid);
// // Fetch/create tracked resource in current batch
// {
// if (!batch->tracked_resource_bins)
// {
// batch->tracked_resource_bins = PushStructs(arena, G_D12_TrackedResourceBin, G_D12_TrackedResourceBinsCount);
// }
// G_D12_TrackedResourceBin *bin = &batch->tracked_resource_bins[hash % G_D12_TrackedResourceBinsCount];
// G_D12_TrackedResourceNode *tmp = bin->first;
// for (; tmp; tmp = tmp->next_in_bin)
// {
// if (tmp->hash == hash)
// {
// break;
// }
// }
// if (!tmp)
// {
// tmp = PushStruct(arena, G_D12_TrackedResourceNode);
// tmp->resource = resource;
// tmp->hash = hash;
// ++batch->tracked_resources_count;
// SllQueuePush(batch->first_tracked_resource, batch->last_tracked_resource, tmp);
// SllStackPushN(bin->first, tmp, next_in_bin);
// }
// trn = tmp;
// }
// // Fetch/create tracked resource in previous batch
// if (prev_batch)
// {
// if (!prev_batch->tracked_resource_bins)
// {
// prev_batch->tracked_resource_bins = PushStructs(arena, G_D12_TrackedResourceBin, G_D12_TrackedResourceBinsCount);
// }
// G_D12_TrackedResourceBin *bin = &prev_batch->tracked_resource_bins[hash % G_D12_TrackedResourceBinsCount];
// G_D12_TrackedResourceNode *tmp = bin->first;
// for (; tmp; tmp = tmp->next_in_bin)
// {
// if (tmp->hash == hash)
// {
// break;
// }
// }
// if (!tmp)
// {
// tmp = PushStruct(arena, G_D12_TrackedResourceNode);
// tmp->resource = resource;
// tmp->hash = hash;
// SllQueuePush(prev_batch->first_tracked_resource, prev_batch->last_tracked_resource, tmp);
// SllStackPushN(bin->first, tmp, next_in_bin);
// }
// prev_trn = tmp;
// }
// }
// for (i32 mip_idx = mips.min; mip_idx <= mips.max; ++mip_idx)
// {
// G_D12_TrackedMip *mip = &trn->mips[mip_idx];
// G_D12_TrackedMip *prev_mip = 0;
// if (prev_trn)
// {
// prev_mip = &prev_trn->mips[mip_idx];
// }
// if (usage_kind > mip->usage)
// {
// mip->usage = usage_kind;
// }
// if (usage_kind == G_D12_TrackedUsageKind_Acquire)
// {
// mip->prev_usage = G_D12_TrackedUsageKind_Release;
// }
// else
// {
// if (usage_kind == G_D12_TrackedUsageKind_Release)
// {
// mip->next_usage = G_D12_TrackedUsageKind_Release;
// }
// if (prev_mip)
// {
// mip->prev_usage = prev_mip->usage;
// }
// }
// if (prev_mip)
// {
// prev_mip->usage = mip->prev_usage;
// prev_mip->next_usage = mip->usage;
// }
// }
// }
// }
void G_D12_UpdateTrackedUsage(Arena *arena, G_D12_CmdBatch *batch, G_D12_Resource *resource, RngI32 mips, G_D12_TrackedUsageKind usage_kind)
{
b32 should_track = !AnyBit(resource->d3d_desc.Flags, D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS);
@ -2342,110 +2236,54 @@ void G_D12_UpdateTrackedUsage(Arena *arena, G_D12_CmdBatch *batch, G_D12_Resourc
}
}
G_D12_BarrierInfo G_D12_BarrierInfoFromBatch(G_D12_CmdBatch *batch, G_QueueKind queue_kind)
{
G_D12_BarrierInfo result = Zi;
// result.access = D3D12_BARRIER_ACCESS_NO_ACCESS;
// result.sync = D3D12_BARRIER_SYNC_ALL;
result.sync = D3D12_BARRIER_SYNC_NONE;
result.access = D3D12_BARRIER_ACCESS_COMMON;
// TODO: Granular access tracking for less flushing
{
if (batch->contains_compute_shader)
if (batch->contains_compute)
{
result.sync |= D3D12_BARRIER_SYNC_COMPUTE_SHADING;
// result.access |= D3D12_BARRIER_ACCESS_UNORDERED_ACCESS | D3D12_BARRIER_ACCESS_SHADER_RESOURCE;
}
if (batch->contains_draw_shader)
if (batch->contains_draw)
{
result.sync |= D3D12_BARRIER_SYNC_VERTEX_SHADING | D3D12_BARRIER_SYNC_PIXEL_SHADING;
// result.access |= D3D12_BARRIER_ACCESS_UNORDERED_ACCESS | D3D12_BARRIER_ACCESS_SHADER_RESOURCE;
result.sync |= D3D12_BARRIER_SYNC_DRAW;
}
if (batch->contains_indirect)
{
result.sync |= D3D12_BARRIER_SYNC_EXECUTE_INDIRECT;
// result.access |= D3D12_BARRIER_ACCESS_INDIRECT_ARGUMENT;
}
if (batch->contains_rtv)
{
result.sync |= D3D12_BARRIER_SYNC_RENDER_TARGET;
// result.access |= D3D12_BARRIER_ACCESS_RENDER_TARGET;
}
if (batch->contains_dsv_read)
{
result.sync |= D3D12_BARRIER_SYNC_DEPTH_STENCIL;
// result.access |= D3D12_BARRIER_ACCESS_DEPTH_STENCIL_READ;
}
if (batch->contains_dsv_write)
{
result.sync |= D3D12_BARRIER_SYNC_DEPTH_STENCIL;
// result.access |= D3D12_BARRIER_ACCESS_DEPTH_STENCIL_WRITE;
}
if (batch->contains_copy)
{
result.sync |= D3D12_BARRIER_SYNC_COPY;
// result.access |= D3D12_BARRIER_ACCESS_COPY_DEST | D3D12_BARRIER_ACCESS_COPY_SOURCE;
}
}
// {
// if (batch->contains_compute_shader)
// {
// result.sync |= D3D12_BARRIER_SYNC_COMPUTE_SHADING;
// result.access |= D3D12_BARRIER_ACCESS_UNORDERED_ACCESS | D3D12_BARRIER_ACCESS_SHADER_RESOURCE;
// }
// if (batch->contains_draw_shader)
// {
// result.sync |= D3D12_BARRIER_SYNC_VERTEX_SHADING | D3D12_BARRIER_SYNC_PIXEL_SHADING;
// result.access |= D3D12_BARRIER_ACCESS_UNORDERED_ACCESS | D3D12_BARRIER_ACCESS_SHADER_RESOURCE;
// }
// if (batch->contains_indirect)
// {
// result.sync |= D3D12_BARRIER_SYNC_EXECUTE_INDIRECT;
// result.access |= D3D12_BARRIER_ACCESS_INDIRECT_ARGUMENT;
// }
// if (batch->contains_rtv)
// {
// result.sync |= D3D12_BARRIER_SYNC_RENDER_TARGET;
// result.access |= D3D12_BARRIER_ACCESS_RENDER_TARGET;
// }
// if (batch->contains_dsv_read)
// {
// result.sync |= D3D12_BARRIER_SYNC_DEPTH_STENCIL;
// result.access |= D3D12_BARRIER_ACCESS_DEPTH_STENCIL_READ;
// }
// if (batch->contains_dsv_write)
// {
// result.sync |= D3D12_BARRIER_SYNC_DEPTH_STENCIL;
// result.access |= D3D12_BARRIER_ACCESS_DEPTH_STENCIL_WRITE;
// }
// if (batch->contains_copy)
// {
// result.sync |= D3D12_BARRIER_SYNC_COPY;
// result.access |= D3D12_BARRIER_ACCESS_COPY_DEST | D3D12_BARRIER_ACCESS_COPY_SOURCE;
// }
// }
// if (result.access != D3D12_BARRIER_ACCESS_NO_ACCESS)
// {
// result.access &= ~D3D12_BARRIER_ACCESS_NO_ACCESS;
// }
if (result.sync == D3D12_BARRIER_SYNC_NONE)
{
result.access = D3D12_BARRIER_ACCESS_NO_ACCESS;
}
if (result.access == D3D12_BARRIER_ACCESS_NO_ACCESS)
{
result.sync = D3D12_BARRIER_SYNC_NONE;
}
else
{
result.access &= ~D3D12_BARRIER_ACCESS_NO_ACCESS;
}
return result;
}
@ -2453,90 +2291,47 @@ G_D12_BarrierInfo G_D12_BarrierInfoFromUsageKind(G_D12_TrackedUsageKind usage_ki
{
G_D12_BarrierInfo result = Zi;
result.sync = global.sync;
result.access = global.access;
result.access = D3D12_BARRIER_ACCESS_COMMON;
// TODO: Granular access tracking for less flushing
{
if (usage_kind == G_D12_TrackedUsageKind_RenderTarget)
{
result.layout = D3D12_BARRIER_LAYOUT_RENDER_TARGET;
result.sync |= D3D12_BARRIER_SYNC_RENDER_TARGET;
}
else if (usage_kind == G_D12_TrackedUsageKind_DepthStencilRead)
{
result.layout = D3D12_BARRIER_LAYOUT_DIRECT_QUEUE_GENERIC_READ;
result.sync |= global.sync;
}
else if (usage_kind == G_D12_TrackedUsageKind_DepthStencilReadWrite)
{
result.layout = D3D12_BARRIER_LAYOUT_DEPTH_STENCIL_WRITE;
result.sync |= D3D12_BARRIER_SYNC_DEPTH_STENCIL;
}
else if (usage_kind == G_D12_TrackedUsageKind_Release)
{
result.layout = D3D12_BARRIER_LAYOUT_COMMON;
result.sync |= global.sync;
}
else
{
result.layout = G_D12_CommonLayoutFromQueueKind(queue_kind);
result.sync |= global.sync;
}
}
// {
// if (usage_kind == G_D12_TrackedUsageKind_RenderTarget)
// {
// result.layout = D3D12_BARRIER_LAYOUT_RENDER_TARGET;
// result.sync |= D3D12_BARRIER_SYNC_RENDER_TARGET;
// result.access |= D3D12_BARRIER_ACCESS_RENDER_TARGET;
// }
// else if (usage_kind == G_D12_TrackedUsageKind_DepthStencilRead)
// {
// result.layout = D3D12_BARRIER_LAYOUT_DIRECT_QUEUE_GENERIC_READ;
// result.sync |= D3D12_BARRIER_SYNC_DEPTH_STENCIL;
// result.sync |= (global.sync & D3D12_BARRIER_SYNC_COPY);
// result.sync |= (global.sync & D3D12_BARRIER_SYNC_VERTEX_SHADING);
// result.sync |= (global.sync & D3D12_BARRIER_SYNC_PIXEL_SHADING);
// result.sync |= (global.sync & D3D12_BARRIER_SYNC_COMPUTE_SHADING);
// result.access |= D3D12_BARRIER_ACCESS_DEPTH_STENCIL_READ;
// result.access |= (global.access & D3D12_BARRIER_ACCESS_COPY_SOURCE);
// result.access |= (global.access & D3D12_BARRIER_ACCESS_SHADER_RESOURCE);
// }
// else if (usage_kind == G_D12_TrackedUsageKind_DepthStencilReadWrite)
// {
// result.layout = D3D12_BARRIER_LAYOUT_DEPTH_STENCIL_WRITE;
// result.sync |= D3D12_BARRIER_SYNC_DEPTH_STENCIL;
// result.access |= D3D12_BARRIER_ACCESS_DEPTH_STENCIL_WRITE;
// }
// else if (usage_kind == G_D12_TrackedUsageKind_Release)
// {
// result.layout = D3D12_BARRIER_LAYOUT_COMMON;
// result.access = D3D12_BARRIER_ACCESS_COMMON;
// }
// else
// {
// result.layout = G_D12_CommonLayoutFromQueueKind(queue_kind);
// result.sync |= (global.sync & D3D12_BARRIER_SYNC_COPY);
// result.sync |= (global.sync & D3D12_BARRIER_SYNC_VERTEX_SHADING);
// result.sync |= (global.sync & D3D12_BARRIER_SYNC_PIXEL_SHADING);
// result.sync |= (global.sync & D3D12_BARRIER_SYNC_COMPUTE_SHADING);
// result.access |= (global.access & D3D12_BARRIER_ACCESS_COPY_SOURCE);
// result.access |= (global.access & D3D12_BARRIER_ACCESS_COPY_DEST);
// result.access |= (global.access & D3D12_BARRIER_ACCESS_SHADER_RESOURCE);
// if (resource->d3d_desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)
// {
// result.access |= (global.access & D3D12_BARRIER_ACCESS_UNORDERED_ACCESS);
// }
// }
// }
if (result.sync == D3D12_BARRIER_SYNC_NONE)
{
result.access = D3D12_BARRIER_ACCESS_NO_ACCESS;
}
if (result.access == D3D12_BARRIER_ACCESS_NO_ACCESS)
{
result.sync = D3D12_BARRIER_SYNC_NONE;
}
else
{
result.access &= ~D3D12_BARRIER_ACCESS_NO_ACCESS;
}
return result;
}
@ -2612,7 +2407,7 @@ i64 G_CommitCommandList(G_CommandListHandle cl_handle)
if (cmd_kind == G_D12_CmdKind_Compute)
{
batch->contains_compute_shader = 1;
batch->contains_compute = 1;
}
else if (cmd_kind == G_D12_CmdKind_Draw)
{
@ -2690,19 +2485,14 @@ i64 G_CommitCommandList(G_CommandListHandle cl_handle)
bcn->cmd = cmd;
SllQueuePush(batch->first_cmd, batch->last_cmd, bcn);
}
// TODO: Only perform tracking on batches containing draws/clear/discard
}
if (last_batch->first_cmd || last_batch->first_tracked_resource)
if (last_batch->first_tracked_resource)
{
// if (batch->first_tracked_resource && batch->contains_hazard)
// {
// // Final empty batch to implicitly decay tracked resources
// batch = PushStruct(scratch.arena, G_D12_CmdBatch);
// ++batches_count;
// DllQueuePush(first_batch, last_batch, batch);
// }
// Final empty batch to implicitly decay tracked resources
++batches_count;
batch = PushStruct(scratch.arena, G_D12_CmdBatch);
DllQueuePush(first_batch, last_batch, batch);
}
}
@ -2737,7 +2527,6 @@ i64 G_CommitCommandList(G_CommandListHandle cl_handle)
}
// Push decay transition to next batch
// if (next_batch && mip->usage != mip->next_usage)
if (next_batch && mip->next_usage == G_D12_TrackedUsageKind_Untracked)
{
++next_batch->transitions_count;

View File

@ -496,8 +496,8 @@ Struct(G_D12_CmdBatch)
// Stage hazards
b32 contains_hazard;
b32 contains_compute_shader;
b32 contains_draw_shader;
b32 contains_compute;
b32 contains_draw;
b32 contains_indirect;
b32 contains_copy;