diff --git a/include/shader-debug/debug_channel.h b/include/shader-debug/debug_channel.h index 97e3b2ab..aa54fa76 100644 --- a/include/shader-debug/debug_channel.h +++ b/include/shader-debug/debug_channel.h @@ -97,6 +97,14 @@ void DEBUG_CHANNEL_INIT(uvec3 id) #endif } +void DEBUG_CHANNEL_INIT_IMPLICIT_INSTANCE(uvec3 id, uint inst) +{ + if (!DEBUG_SHADER_RING_ACTIVE) + return; + DEBUG_CHANNEL_ID = id; + DEBUG_CHANNEL_INSTANCE_COUNTER = inst; +} + void DEBUG_CHANNEL_UNLOCK_MESSAGE(RingBuffer buf, uint offset, uint num_words) { memoryBarrierBuffer(); diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index e1404d17..15a21da6 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -9707,6 +9707,15 @@ static void d3d12_command_list_execute_indirect_state_template( patch_args.dst_indirect_count_va = count_buffer ? count_allocation.va : 0; patch_args.api_buffer_word_stride = signature->desc.ByteStride / sizeof(uint32_t); patch_args.device_generated_commands_word_stride = signature->state_template.stride / sizeof(uint32_t); + patch_args.debug_tag = 0; /* Modify to non-zero value as desired when debugging. */ + + if (patch_args.debug_tag != 0) + { + /* Makes log easier to understand since a sorted log will appear in-order. */ + static uint32_t vkd3d_implicit_instance_count; + patch_args.implicit_instance = vkd3d_atomic_uint32_increment( + &vkd3d_implicit_instance_count, vkd3d_memory_order_relaxed) - 1; + } barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; barrier.pNext = NULL; diff --git a/libs/vkd3d/debug_ring.c b/libs/vkd3d/debug_ring.c index 7d486f96..2d67ee88 100644 --- a/libs/vkd3d/debug_ring.c +++ b/libs/vkd3d/debug_ring.c @@ -130,9 +130,10 @@ static bool vkd3d_shader_debug_ring_print_message(struct vkd3d_shader_debug_ring if (shader_hash == 0) { /* We got this from our internal debug shaders. Pretty-print. + * Make sure the log is sortable for easier debug. * TODO: Might consider a callback system that listeners from different subsystems can listen to and print their own messages, * but that is overengineering at this time ... */ - snprintf(message_buffer, sizeof(message_buffer), "ExecuteIndirect: Instance %010u, Debug tag %u, DrawID %u (ThreadID %u): ", + snprintf(message_buffer, sizeof(message_buffer), "ExecuteIndirect: GlobalCommandIndex %010u, Debug tag %010u, DrawID %04u (ThreadID %04u): ", debug_instance, debug_thread_id[0], debug_thread_id[1], debug_thread_id[2]); if (message_word_count == 2) diff --git a/libs/vkd3d/shaders/cs_execute_indirect_patch_debug_ring.comp b/libs/vkd3d/shaders/cs_execute_indirect_patch_debug_ring.comp index 64615006..6a63a445 100644 --- a/libs/vkd3d/shaders/cs_execute_indirect_patch_debug_ring.comp +++ b/libs/vkd3d/shaders/cs_execute_indirect_patch_debug_ring.comp @@ -51,12 +51,13 @@ layout(push_constant) uniform Registers // Debug metadata here uint debug_tag; + uint implicit_instance; }; void main() { if (debug_tag != 0u) - DEBUG_CHANNEL_INIT(uvec3(debug_tag, gl_WorkGroupID.x, gl_LocalInvocationIndex)); + DEBUG_CHANNEL_INIT_IMPLICIT_INSTANCE(uvec3(debug_tag, gl_WorkGroupID.x, gl_LocalInvocationIndex), implicit_instance); Command cmd = commands_va.commands[gl_LocalInvocationIndex]; diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index ea0dad3e..6b79aaab 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -3081,6 +3081,7 @@ struct vkd3d_execute_indirect_args /* Arbitrary tag used for debug version of state patcher. Debug messages from tag 0 are ignored. */ uint32_t debug_tag; + uint32_t implicit_instance; }; struct vkd3d_execute_indirect_pipeline