Skip to content

Commit 942e707

Browse files
vkd3d: Add full tracing of every submitted command list.
Replays relevant commands in submission order. Signed-off-by: Hans-Kristian Arntzen <[email protected]>
1 parent a8e3b8c commit 942e707

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

include/vkd3d.h

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ extern "C" {
9292
#define VKD3D_CONFIG_FLAG_ALLOW_SBT_COLLECTION (1ull << 30)
9393
#define VKD3D_CONFIG_FLAG_FORCE_NATIVE_FP16 (1ull << 31)
9494
#define VKD3D_CONFIG_FLAG_USE_HOST_IMPORT_FALLBACK (1ull << 32)
95+
#define VKD3D_CONFIG_FLAG_BREADCRUMBS_TRACE (1ull << 33)
9596

9697
typedef HRESULT (*PFN_vkd3d_signal_event)(HANDLE event);
9798

libs/vkd3d/breadcrumbs.c

+16
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,11 @@ static void vkd3d_breadcrumb_tracer_report_command_list(
295295
const struct vkd3d_breadcrumb_command *cmd;
296296
bool observed_begin_cmd = false;
297297
bool observed_end_cmd = false;
298+
bool ignore_markers;
298299
unsigned int i;
299300

301+
ignore_markers = begin_marker == UINT32_MAX && end_marker == UINT32_MAX;
302+
300303
if (end_marker == 0)
301304
{
302305
ERR(" ===== Potential crash region BEGIN (make sure RADV_DEBUG=syncshaders is used for maximum accuracy) =====\n");
@@ -309,6 +312,12 @@ static void vkd3d_breadcrumb_tracer_report_command_list(
309312
{
310313
cmd = &context->commands[i];
311314

315+
if (ignore_markers && (cmd->type == VKD3D_BREADCRUMB_COMMAND_SET_TOP_MARKER ||
316+
cmd->type == VKD3D_BREADCRUMB_COMMAND_SET_BOTTOM_MARKER))
317+
{
318+
continue;
319+
}
320+
312321
/* If there is a command which sets TOP_OF_PIPE, but we haven't observed the marker yet,
313322
* the command processor hasn't gotten there yet (most likely ...), so that should be the
314323
* natural end-point. */
@@ -368,6 +377,13 @@ static void vkd3d_breadcrumb_tracer_report_command_list(
368377
}
369378
}
370379

380+
void vkd3d_breadcrumb_tracer_dump_command_list(struct vkd3d_breadcrumb_tracer *tracer,
381+
unsigned int index)
382+
{
383+
vkd3d_breadcrumb_tracer_report_command_list(&tracer->trace_contexts[index],
384+
UINT32_MAX, UINT32_MAX);
385+
}
386+
371387
static void vkd3d_breadcrumb_tracer_report_command_list_amd(struct vkd3d_breadcrumb_tracer *tracer,
372388
unsigned int context_index)
373389
{

libs/vkd3d/command.c

+40
Original file line numberDiff line numberDiff line change
@@ -11894,6 +11894,9 @@ static void STDMETHODCALLTYPE d3d12_command_queue_ExecuteCommandLists(ID3D12Comm
1189411894
size_t num_transitions, num_command_buffers;
1189511895
struct d3d12_command_queue_submission sub;
1189611896
struct d3d12_command_list *cmd_list;
11897+
#ifdef VKD3D_ENABLE_BREADCRUMBS
11898+
unsigned int *breadcrumb_indices;
11899+
#endif
1189711900
VkCommandBuffer *buffers;
1189811901
LONG **outstanding;
1189911902
unsigned int i, j;
@@ -11942,6 +11945,19 @@ static void STDMETHODCALLTYPE d3d12_command_queue_ExecuteCommandLists(ID3D12Comm
1194211945
return;
1194311946
}
1194411947

11948+
#ifdef VKD3D_ENABLE_BREADCRUMBS
11949+
if (vkd3d_config_flags & VKD3D_CONFIG_FLAG_BREADCRUMBS_TRACE)
11950+
{
11951+
if (!(breadcrumb_indices = vkd3d_malloc(sizeof(unsigned int) * command_list_count)))
11952+
{
11953+
vkd3d_free(outstanding);
11954+
vkd3d_free(buffers);
11955+
}
11956+
}
11957+
else
11958+
breadcrumb_indices = NULL;
11959+
#endif
11960+
1194511961
sub.execute.debug_capture = false;
1194611962

1194711963
num_transitions = 0;
@@ -11956,6 +11972,9 @@ static void STDMETHODCALLTYPE d3d12_command_queue_ExecuteCommandLists(ID3D12Comm
1195611972
"Command list %p is in recording state.\n", command_lists[i]);
1195711973
vkd3d_free(outstanding);
1195811974
vkd3d_free(buffers);
11975+
#ifdef VKD3D_ENABLE_BREADCRUMBS
11976+
vkd3d_free(breadcrumb_indices);
11977+
#endif
1195911978
return;
1196011979
}
1196111980

@@ -11969,6 +11988,11 @@ static void STDMETHODCALLTYPE d3d12_command_queue_ExecuteCommandLists(ID3D12Comm
1196911988
buffers[j++] = cmd_list->vk_command_buffer;
1197011989
if (cmd_list->debug_capture)
1197111990
sub.execute.debug_capture = true;
11991+
11992+
#ifdef VKD3D_ENABLE_BREADCRUMBS
11993+
if (breadcrumb_indices)
11994+
breadcrumb_indices[i] = cmd_list->breadcrumb_context_index;
11995+
#endif
1197211996
}
1197311997

1197411998
/* Append a full GPU barrier between submissions.
@@ -12009,6 +12033,10 @@ static void STDMETHODCALLTYPE d3d12_command_queue_ExecuteCommandLists(ID3D12Comm
1200912033
sub.execute.cmd_count = num_command_buffers;
1201012034
sub.execute.outstanding_submissions_counters = outstanding;
1201112035
sub.execute.outstanding_submissions_counter_count = command_list_count;
12036+
#ifdef VKD3D_ENABLE_BREADCRUMBS
12037+
sub.execute.breadcrumb_indices = breadcrumb_indices;
12038+
sub.execute.breadcrumb_indices_count = breadcrumb_indices ? command_list_count : 0;
12039+
#endif
1201212040
d3d12_command_queue_add_submission(command_queue, &sub);
1201312041
}
1201412042

@@ -13186,6 +13214,18 @@ static void *d3d12_command_queue_submission_worker_main(void *userdata)
1318613214
* On error, the counters are freed early, so there is no risk of leak. */
1318713215
vkd3d_free(submission.execute.cmd);
1318813216
vkd3d_free(submission.execute.transitions);
13217+
#ifdef VKD3D_ENABLE_BREADCRUMBS
13218+
for (i = 0; i < submission.execute.breadcrumb_indices_count; i++)
13219+
{
13220+
INFO("=== Executing command list context %u on VkQueue %p, queue family %u ===\n",
13221+
submission.execute.breadcrumb_indices[i],
13222+
(void*)queue->vkd3d_queue->vk_queue, queue->vkd3d_queue->vk_family_index);
13223+
vkd3d_breadcrumb_tracer_dump_command_list(&queue->device->breadcrumb_tracer,
13224+
submission.execute.breadcrumb_indices[i]);
13225+
INFO("============================\n");
13226+
}
13227+
vkd3d_free(submission.execute.breadcrumb_indices);
13228+
#endif
1318913229
VKD3D_REGION_END(queue_execute);
1319013230
break;
1319113231

libs/vkd3d/device.c

+1
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ static const struct vkd3d_debug_option vkd3d_config_options[] =
716716
{"force_raw_va_cbv", VKD3D_CONFIG_FLAG_FORCE_RAW_VA_CBV},
717717
{"allow_sbt_collection", VKD3D_CONFIG_FLAG_ALLOW_SBT_COLLECTION},
718718
{"host_import_fallback", VKD3D_CONFIG_FLAG_USE_HOST_IMPORT_FALLBACK},
719+
{"breadcrumbs_trace", VKD3D_CONFIG_FLAG_BREADCRUMBS | VKD3D_CONFIG_FLAG_BREADCRUMBS_TRACE},
719720
};
720721

721722
static void vkd3d_config_flags_init_once(void)

libs/vkd3d/vkd3d_private.h

+10
Original file line numberDiff line numberDiff line change
@@ -2528,6 +2528,12 @@ struct d3d12_command_queue_submission_execute
25282528
struct vkd3d_initial_transition *transitions;
25292529
size_t transition_count;
25302530

2531+
#ifdef VKD3D_ENABLE_BREADCRUMBS
2532+
/* Replays commands in submission order for heavy debug. */
2533+
unsigned int *breadcrumb_indices;
2534+
size_t breadcrumb_indices_count;
2535+
#endif
2536+
25312537
bool debug_capture;
25322538
};
25332539

@@ -2838,6 +2844,10 @@ void vkd3d_breadcrumb_tracer_register_placed_resource(struct d3d12_heap *heap, s
28382844
VkDeviceSize heap_offset, VkDeviceSize required_size);
28392845
void vkd3d_breadcrumb_tracer_unregister_placed_resource(struct d3d12_heap *heap, struct d3d12_resource *resource);
28402846

2847+
/* For heavy debug, replays the trace stream in submission order. */
2848+
void vkd3d_breadcrumb_tracer_dump_command_list(struct vkd3d_breadcrumb_tracer *tracer,
2849+
unsigned int index);
2850+
28412851
#define VKD3D_BREADCRUMB_COMMAND(cmd_type) do { \
28422852
if (vkd3d_config_flags & VKD3D_CONFIG_FLAG_BREADCRUMBS) { \
28432853
struct vkd3d_breadcrumb_command breadcrumb_cmd; \

0 commit comments

Comments
 (0)