diff --git a/include/shader-debug/debug_channel.h b/include/shader-debug/debug_channel.h index 7e76c852..97e3b2ab 100644 --- a/include/shader-debug/debug_channel.h +++ b/include/shader-debug/debug_channel.h @@ -51,6 +51,7 @@ const uint DEBUG_CHANNEL_FMT_F32 = 2; const uint DEBUG_CHANNEL_FMT_HEX_ALL = DEBUG_CHANNEL_FMT_HEX * 0x55555555u; const uint DEBUG_CHANNEL_FMT_I32_ALL = DEBUG_CHANNEL_FMT_I32 * 0x55555555u; const uint DEBUG_CHANNEL_FMT_F32_ALL = DEBUG_CHANNEL_FMT_F32 * 0x55555555u; +const uint DEBUG_CHANNEL_WORD_COOKIE = 0xdeadca70u; /* Let host fish for this cookie in device lost scenarios. */ uint DEBUG_CHANNEL_INSTANCE_COUNTER; uvec3 DEBUG_CHANNEL_ID; @@ -103,7 +104,7 @@ void DEBUG_CHANNEL_UNLOCK_MESSAGE(RingBuffer buf, uint offset, uint num_words) * If the host thread observed a num_word of 0, we know a message was allocated, but we don't necessarily * have a complete write yet. * In a device lost scenario, we can try to fish for valid messages. */ - buf.data[(offset + 0) & DEBUG_SHADER_RING_MASK] = num_words; + buf.data[(offset + 0) & DEBUG_SHADER_RING_MASK] = num_words | DEBUG_CHANNEL_WORD_COOKIE; memoryBarrierBuffer(); } diff --git a/libs/vkd3d/debug_ring.c b/libs/vkd3d/debug_ring.c index c63b0092..53848d0e 100644 --- a/libs/vkd3d/debug_ring.c +++ b/libs/vkd3d/debug_ring.c @@ -104,6 +104,8 @@ void *vkd3d_shader_debug_ring_thread_main(void *arg) /* The debug ring shader has "release" semantics for the word count write, * so just make sure the reads don't get reordered here. */ message_word_count = READ_RING_WORD_ACQUIRE(0); +#define DEBUG_CHANNEL_WORD_COOKIE 0xdeadca70u +#define DEBUG_CHANNEL_WORD_MASK 0xfffffff0u if (message_word_count == 0) { @@ -114,6 +116,15 @@ void *vkd3d_shader_debug_ring_thread_main(void *arg) break; } + /* If something is written here, it must be a cookie. */ + if ((message_word_count & DEBUG_CHANNEL_WORD_MASK) != DEBUG_CHANNEL_WORD_COOKIE) + { + ERR("Invalid message work cookie detected, 0x%x.\n", message_word_count); + break; + } + + message_word_count &= ~DEBUG_CHANNEL_WORD_MASK; + if (i + message_word_count > count) { ERR("Message word count %u is out of bounds (i = %u, count = %u).\n", @@ -121,7 +132,7 @@ void *vkd3d_shader_debug_ring_thread_main(void *arg) break; } - if (message_word_count < 8 || message_word_count > 16 + 8) + if (message_word_count < 8) { ERR("Message word count %u is invalid.\n", message_word_count); break;