automatic draw/dispatch markers indicating pipeline name

This commit is contained in:
jacob 2026-03-07 00:52:06 -08:00
parent 3707db9d94
commit 8ef409a4d8
4 changed files with 119 additions and 52 deletions

View File

@ -589,9 +589,12 @@ void G_SyncLayout(G_CommandListHandle cl, G_ResourceHandle resource, G_Layout la
//- Zone
void G_PushZone(G_CommandListHandle cl, char *name_lit_cstr);
void G_PopZone(G_CommandListHandle cl);
#define G_ZoneDF(cl, name_lit_cstr) DeferFor(G_PushZone((cl), (name_lit_cstr)), G_PopZone(cl))
void G_PushZoneEx(G_CommandListHandle cl, String name_lit);
void G_PopZoneEx(G_CommandListHandle cl);
#define G_PushZone(cl, name_lit) G_PushZoneEx((cl), Lit(name_lit))
#define G_PopZone(cl) G_PopZoneEx(cl)
#define G_ZoneDF(cl, name_lit) DeferFor(G_PushZone((cl), (name_lit)), G_PopZone(cl))
//- Cpu -> Gpu staged copy

View File

@ -772,7 +772,7 @@ G_D12_Pipeline *G_D12_PipelineFromDesc(G_D12_PipelineDesc desc)
String pipeline_name = Zi;
if (is_compute)
{
pipeline_name = NameFromResource(desc.cs.resource);
pipeline_name = TrimRight(NameFromResource(desc.cs.resource), Lit(".dxil"));
if (pipeline_name.len == 0)
{
pipeline_name = StringF(scratch.arena, "%F", FmtHandle(desc.cs.resource.v));
@ -780,8 +780,8 @@ G_D12_Pipeline *G_D12_PipelineFromDesc(G_D12_PipelineDesc desc)
}
else
{
String vs_name = NameFromResource(desc.vs.resource);
String ps_name = NameFromResource(desc.ps.resource);
String vs_name = TrimRight(NameFromResource(desc.vs.resource), Lit(".dxil"));
String ps_name = TrimRight(NameFromResource(desc.ps.resource), Lit(".dxil"));
if (vs_name.len == 0)
{
vs_name = StringF(scratch.arena, "%F", FmtHandle(desc.vs.resource.v));
@ -797,6 +797,7 @@ G_D12_Pipeline *G_D12_PipelineFromDesc(G_D12_PipelineDesc desc)
FmtString(ps_name)
);
}
pipeline_name.len = MinU64(pipeline_name.len, G_D12_MaxNameLen);
LogInfoF("Creating pipeline %F", FmtString(pipeline_name));
@ -957,11 +958,11 @@ G_D12_Pipeline *G_D12_PipelineFromDesc(G_D12_PipelineDesc desc)
if (ok)
{
if (GPU_NAMES)
{
pipeline->name_len = pipeline_name.len;
CopyBytes(pipeline->name_cstr, pipeline_name.text, pipeline->name_len);
pipeline->name_cstr[pipeline->name_len] = 0;
G_D12_SetObjectName((ID3D12Object *)pso, pipeline_name);
}
}
else
{
// TOOD: Don't panic
@ -1231,7 +1232,7 @@ G_ResourceHandle G_PushResource(G_ArenaHandle arena_handle, G_CommandListHandle
is_texture ? desc.texture.name :
desc.sampler.name
);
new_name.len = MinU64(new_name.len, countof(resource->name_text));
new_name.len = MinU64(new_name.len, G_D12_MaxNameLen);
//////////////////////////////
//- Initialize heap info
@ -1378,12 +1379,6 @@ G_ResourceHandle G_PushResource(G_ArenaHandle arena_handle, G_CommandListHandle
ZeroStruct(release);
SllQueuePush(cl->releases.first, cl->releases.last, release);
release->d3d_resource = resource->d3d_resource;
if (GPU_NAMES)
{
StaticAssert(countof(release->name_text) == countof(resource->name_text));
release->name_len = resource->name_len;
CopyBytes(release->name_text, resource->name_text, resource->name_len);
}
}
ZeroStruct(resource);
}
@ -1505,12 +1500,13 @@ G_ResourceHandle G_PushResource(G_ArenaHandle arena_handle, G_CommandListHandle
//////////////////////////////
//- Set debug information
String old_name = STRING(resource->name_len, resource->name_text);
String old_name = STRING(resource->name_len, (u8 *)resource->name_cstr);
if (!MatchString(old_name, new_name))
{
resource->name_len = new_name.len;
CopyBytes(resource->name_text, new_name.text, new_name.len);
if (GPU_NAMES && resource->d3d_resource)
CopyBytes(resource->name_cstr, new_name.text, new_name.len);
resource->name_cstr[new_name.len] = 0;
if (resource->d3d_resource)
{
G_D12_SetObjectName((ID3D12Object *)resource->d3d_resource, new_name);
}
@ -2078,6 +2074,70 @@ G_D12_StagingRegionNode *G_D12_PushStagingRegion(G_D12_CmdList *cl, u64 size)
return result;
}
////////////////////////////////////////////////////////////
//~ Instrumentation
void G_D12_InsertEvent(ID3D12GraphicsCommandList7 *d3d_cl, G_D12_EventKind kind, String data)
{
b32 pix = G_D12.pix_enabled;
b32 ags = G_D12.ags_enabled;
if (pix || ags)
{
TempArena scratch = BeginScratchNoConflict();
char *data_cstr = 0;
if (data.len > 0)
{
if (data.text[data.len] == '\0')
{
// Fast path: data is already null terminated, don't need to copy
data_cstr = (char *)data.text;
}
else
{
data_cstr = CstrFromString(scratch.arena, data);
}
}
u64 color = 0x7F7F7F7F;
switch (kind)
{
case G_D12_EventKind_Marker:
{
if (pix)
{
PIXSetMarkerOnCommandList((ID3D12GraphicsCommandList *)d3d_cl, color, data_cstr);
}
if (ags)
{
agsDriverExtensionsDX12_SetMarker(G_D12.ags_ctx, (ID3D12GraphicsCommandList *)d3d_cl, data_cstr);
}
} break;
case G_D12_EventKind_PushZone:
{
if (pix)
{
PIXBeginEventOnCommandList((ID3D12GraphicsCommandList *)d3d_cl, color, data_cstr);
}
if (ags)
{
agsDriverExtensionsDX12_PushMarker(G_D12.ags_ctx, (ID3D12GraphicsCommandList *)d3d_cl, data_cstr);
}
} break;
case G_D12_EventKind_PopZone:
{
if (pix)
{
PIXEndEventOnCommandList((ID3D12GraphicsCommandList *)d3d_cl);
}
if (ags)
{
agsDriverExtensionsDX12_PopMarker(G_D12.ags_ctx, (ID3D12GraphicsCommandList *)d3d_cl);
}
} break;
}
EndScratch(scratch);
}
}
////////////////////////////////////////////////////////////
//~ Tracking
@ -2668,26 +2728,11 @@ i64 G_CommitCommandList(G_CommandListHandle cl_handle)
{
if (cmd->zone.push)
{
if (G_D12.pix_enabled)
{
u64 color = (u64)cmd->zone.name_lit_cstr;
PIXBeginEventOnCommandList((ID3D12GraphicsCommandList *)d3d_cl, color, cmd->zone.name_lit_cstr);
}
if (G_D12.ags_enabled)
{
agsDriverExtensionsDX12_PushMarker(G_D12.ags_ctx, (ID3D12GraphicsCommandList *)d3d_cl, cmd->zone.name_lit_cstr);
}
G_D12_InsertEvent(d3d_cl, G_D12_EventKind_PushZone, cmd->zone.name_lit);
}
else
{
if (G_D12.pix_enabled)
{
PIXEndEventOnCommandList((ID3D12GraphicsCommandList *)d3d_cl);
}
if (G_D12.ags_enabled)
{
agsDriverExtensionsDX12_PopMarker(G_D12.ags_ctx, (ID3D12GraphicsCommandList *)d3d_cl);
}
G_D12_InsertEvent(d3d_cl, G_D12_EventKind_PopZone, cmd->zone.name_lit);
}
} break;
@ -2792,6 +2837,7 @@ i64 G_CommitCommandList(G_CommandListHandle cl_handle)
}
// Dispatch
G_D12_InsertEvent(d3d_cl, G_D12_EventKind_Marker, STRING(pipeline->name_len, (u8 *)pipeline->name_cstr));
ID3D12GraphicsCommandList_Dispatch(d3d_cl, cmd->compute.groups.x, cmd->compute.groups.y, cmd->compute.groups.z);
}
} break;
@ -3003,6 +3049,7 @@ i64 G_CommitCommandList(G_CommandListHandle cl_handle)
}
// Dispatch
G_D12_InsertEvent(d3d_cl, G_D12_EventKind_Marker, STRING(pipeline->name_len, (u8 *)pipeline->name_cstr));
ID3D12GraphicsCommandList_DrawIndexedInstanced(d3d_cl, indices_count, cmd->draw.instances_count, 0, 0, 0);
}
} break;
@ -3011,7 +3058,7 @@ i64 G_CommitCommandList(G_CommandListHandle cl_handle)
case G_D12_CmdKind_ClearRtv:
{
G_D12_Resource *rt = cmd->clear_rtv.resource;
G_D12_Resource *resource = cmd->clear_rtv.resource;
f32 clear_color[4] = Zi;
{
clear_color[0] = cmd->clear_rtv.color.x;
@ -3020,11 +3067,12 @@ i64 G_CommitCommandList(G_CommandListHandle cl_handle)
clear_color[3] = cmd->clear_rtv.color.w;
}
D3D12_CPU_DESCRIPTOR_HANDLE rtv_handle = rcl->rtv_clear_descriptor->first_handle;
if (bound_render_clear_target_uid != rt->uid + cmd->clear_rtv.mip)
if (bound_render_clear_target_uid != resource->uid + cmd->clear_rtv.mip)
{
G_D12_InitRtv(rt, rtv_handle, cmd->clear_rtv.mip);
bound_render_clear_target_uid = rt->uid + cmd->clear_rtv.mip;
G_D12_InitRtv(resource, rtv_handle, cmd->clear_rtv.mip);
bound_render_clear_target_uid = resource->uid + cmd->clear_rtv.mip;
}
G_D12_InsertEvent(d3d_cl, G_D12_EventKind_Marker, STRING(resource->name_len, (u8 *)resource->name_cstr));
ID3D12GraphicsCommandList_ClearRenderTargetView(d3d_cl, rtv_handle, clear_color, 0, 0);
} break;
@ -3036,6 +3084,7 @@ i64 G_CommitCommandList(G_CommandListHandle cl_handle)
D3D12_DISCARD_REGION region = Zi;
region.FirstSubresource = 0;
region.NumSubresources = resource->texture_mips;
G_D12_InsertEvent(d3d_cl, G_D12_EventKind_Marker, STRING(resource->name_len, (u8 *)resource->name_cstr));
ID3D12GraphicsCommandList_DiscardResource(d3d_cl, resource->d3d_resource, 0);
} break;
}
@ -3169,16 +3218,16 @@ void G_SyncLayout(G_CommandListHandle cl_handle, G_ResourceHandle resource_handl
//- Zone
void G_PushZone(G_CommandListHandle cl_handle, char *name_lit_cstr)
void G_PushZoneEx(G_CommandListHandle cl_handle, String name_lit)
{
G_D12_CmdList *cl = G_D12_CmdListFromHandle(cl_handle);
G_D12_Cmd *cmd = G_D12_PushCmd(cl);
cmd->kind = G_D12_CmdKind_Zone;
cmd->zone.name_lit_cstr = name_lit_cstr;
cmd->zone.name_lit = name_lit;
cmd->zone.push = 1;
}
void G_PopZone(G_CommandListHandle cl_handle)
void G_PopZoneEx(G_CommandListHandle cl_handle)
{
G_D12_CmdList *cl = G_D12_CmdListFromHandle(cl_handle);
G_D12_Cmd *cmd = G_D12_PushCmd(cl);

View File

@ -53,6 +53,9 @@ Struct(G_D12_Pipeline)
b32 ok;
String error;
u64 name_len;
char name_cstr[G_D12_MaxNameLen];
};
Struct(G_D12_PipelineBin)
@ -95,7 +98,7 @@ Struct(G_D12_Resource)
struct G_D12_Swapchain *swapchain;
u64 name_len;
u8 name_text[G_D12_MaxNameLen];
char name_cstr[G_D12_MaxNameLen];
};
Struct(G_D12_ResourceList)
@ -281,9 +284,6 @@ Struct(G_D12_Releasable)
i64 completion_queue_target;
ID3D12Resource *d3d_resource;
u64 name_len;
u8 name_text[G_D12_MaxNameLen];
};
Struct(G_D12_ReleasableList)
@ -292,6 +292,16 @@ Struct(G_D12_ReleasableList)
G_D12_Releasable *last;
};
////////////////////////////////////////////////////////////
//~ Event types
Enum(G_D12_EventKind)
{
G_D12_EventKind_Marker,
G_D12_EventKind_PushZone,
G_D12_EventKind_PopZone,
};
////////////////////////////////////////////////////////////
//~ Command list types
@ -328,7 +338,7 @@ Struct(G_D12_Cmd)
struct
{
char *name_lit_cstr;
String name_lit;
b32 push;
} zone;
@ -406,7 +416,7 @@ Struct(G_D12_CmdList)
};
////////////////////////////////////////////////////////////
//~ Command batching types
//~ Tracking types
// TODO: Use a dynamic bin count, since the maximum number of tracked resources in the list is known at command list creation time
#define G_D12_TrackedResourceBinsCount 64
@ -715,6 +725,11 @@ G_D12_Descriptor *G_D12_PushDescriptor(G_D12_Arena *gpu_arena, G_D12_DescriptorH
G_D12_Cmd *G_D12_PushCmd(G_D12_CmdList *cl);
G_D12_StagingRegionNode *G_D12_PushStagingRegion(G_D12_CmdList *cl, u64 size);
////////////////////////////////////////////////////////////
//~ Instrumentation
void G_D12_InsertEvent(ID3D12GraphicsCommandList7 *d3d_cl, G_D12_EventKind kind, String data);
////////////////////////////////////////////////////////////
//~ Tracking

View File

@ -5397,7 +5397,7 @@ void V_TickForever(WaveLaneCtx *lane)
// the first mip index in the bloom mip chain
//- Downsample
G_ZoneDF(cl, "Bloom up")
G_ZoneDF(cl, "Bloom down")
for (i32 mip_idx = 1; mip_idx < mips_count; ++mip_idx)
{
Vec2I32 down_dims = G_DimsFromMip2D(G_Count2D(screen_target), mip_idx);
@ -5409,7 +5409,7 @@ void V_TickForever(WaveLaneCtx *lane)
}
//- Upsample passes
G_ZoneDF(cl, "Bloom down")
G_ZoneDF(cl, "Bloom up")
for (i32 mip_idx = mips_count - 2; mip_idx >= 0; --mip_idx)
{
Vec2I32 up_dims = G_DimsFromMip2D(G_Count2D(screen_target), mip_idx);