Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc debug ring improvements #1860

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/private/vkd3d_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ enum vkd3d_dbg_level vkd3d_dbg_get_level(enum vkd3d_dbg_channel channel);

void vkd3d_dbg_printf(enum vkd3d_dbg_channel channel, enum vkd3d_dbg_level level, const char *function,
const char *fmt, ...) VKD3D_PRINTF_FUNC(4, 5);
void vkd3d_dbg_flush(void);

const char *vkd3d_dbg_sprintf(const char *fmt, ...) VKD3D_PRINTF_FUNC(1, 2);
const char *vkd3d_dbg_vsprintf(const char *fmt, va_list args);
Expand Down
12 changes: 12 additions & 0 deletions include/shader-debug/debug_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,72 +267,84 @@ void DEBUG_CHANNEL_MSG_UNIFORM(uint v0)
{
if (DEBUG_CHANNEL_ELECT())
DEBUG_CHANNEL_MSG(v0);
subgroupBarrier();
}

void DEBUG_CHANNEL_MSG_UNIFORM(uint v0, uint v1)
{
if (DEBUG_CHANNEL_ELECT())
DEBUG_CHANNEL_MSG(v0, v1);
subgroupBarrier();
}

void DEBUG_CHANNEL_MSG_UNIFORM(uint v0, uint v1, uint v2)
{
if (DEBUG_CHANNEL_ELECT())
DEBUG_CHANNEL_MSG(v0, v1, v2);
subgroupBarrier();
}

void DEBUG_CHANNEL_MSG_UNIFORM(uint v0, uint v1, uint v2, uint v3)
{
if (DEBUG_CHANNEL_ELECT())
DEBUG_CHANNEL_MSG(v0, v1, v2, v3);
subgroupBarrier();
}

void DEBUG_CHANNEL_MSG_UNIFORM(int v0)
{
if (DEBUG_CHANNEL_ELECT())
DEBUG_CHANNEL_MSG(v0);
subgroupBarrier();
}

void DEBUG_CHANNEL_MSG_UNIFORM(int v0, int v1)
{
if (DEBUG_CHANNEL_ELECT())
DEBUG_CHANNEL_MSG(v0, v1);
subgroupBarrier();
}

void DEBUG_CHANNEL_MSG_UNIFORM(int v0, int v1, int v2)
{
if (DEBUG_CHANNEL_ELECT())
DEBUG_CHANNEL_MSG(v0, v1, v2);
subgroupBarrier();
}

void DEBUG_CHANNEL_MSG_UNIFORM(int v0, int v1, int v2, int v3)
{
if (DEBUG_CHANNEL_ELECT())
DEBUG_CHANNEL_MSG(v0, v1, v2, v3);
subgroupBarrier();
}

void DEBUG_CHANNEL_MSG_UNIFORM(float v0)
{
if (DEBUG_CHANNEL_ELECT())
DEBUG_CHANNEL_MSG(v0);
subgroupBarrier();
}

void DEBUG_CHANNEL_MSG_UNIFORM(float v0, float v1)
{
if (DEBUG_CHANNEL_ELECT())
DEBUG_CHANNEL_MSG(v0, v1);
subgroupBarrier();
}

void DEBUG_CHANNEL_MSG_UNIFORM(float v0, float v1, float v2)
{
if (DEBUG_CHANNEL_ELECT())
DEBUG_CHANNEL_MSG(v0, v1, v2);
subgroupBarrier();
}

void DEBUG_CHANNEL_MSG_UNIFORM(float v0, float v1, float v2, float v3)
{
if (DEBUG_CHANNEL_ELECT())
DEBUG_CHANNEL_MSG(v0, v1, v2, v3);
subgroupBarrier();
}

#endif
36 changes: 31 additions & 5 deletions libs/vkd3d-common/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,35 @@ enum vkd3d_dbg_level vkd3d_dbg_get_level(enum vkd3d_dbg_channel channel)
return vkd3d_dbg_level[channel];
}

static spinlock_t vkd3d_debug_buffer_spin;

void vkd3d_dbg_flush(void)
{
if (vkd3d_dbg_buffer.buffer)
{
spinlock_acquire(&vkd3d_debug_buffer_spin);
if (vkd3d_dbg_buffer.offset)
{
if (vkd3d_log_file)
{
fwrite(vkd3d_dbg_buffer.buffer, 1, vkd3d_dbg_buffer.offset, vkd3d_log_file);
}
else
{
/* Binary vs text matters on Win32.
* Don't bother trying to be clever here reopening stdio files as O_BINARY, etc. */
fputs(vkd3d_dbg_buffer.buffer, stderr);
}

vkd3d_dbg_buffer.offset = 0;
fflush(vkd3d_log_file ? vkd3d_log_file : stderr);
}
spinlock_release(&vkd3d_debug_buffer_spin);
}
}

void vkd3d_dbg_printf(enum vkd3d_dbg_channel channel, enum vkd3d_dbg_level level, const char *function, const char *fmt, ...)
{
static spinlock_t spin;
unsigned int tid;
FILE *log_file;
va_list args;
Expand All @@ -175,7 +201,7 @@ void vkd3d_dbg_printf(enum vkd3d_dbg_channel channel, enum vkd3d_dbg_level level
local_buffer_count = vsnprintf(local_buffer, sizeof(local_buffer), fmt, args);
required_count = prefix_buffer_count + local_buffer_count;

spinlock_acquire(&spin);
spinlock_acquire(&vkd3d_debug_buffer_spin);
if (vkd3d_dbg_buffer.offset + required_count > vkd3d_dbg_buffer.size)
{
if (vkd3d_log_file)
Expand Down Expand Up @@ -206,7 +232,7 @@ void vkd3d_dbg_printf(enum vkd3d_dbg_channel channel, enum vkd3d_dbg_level level
fputs(prefix_buffer, log_file);
fputs(local_buffer, log_file);
}
spinlock_release(&spin);
spinlock_release(&vkd3d_debug_buffer_spin);
}
#ifdef _WIN32
else if (wine_log_output)
Expand All @@ -228,10 +254,10 @@ void vkd3d_dbg_printf(enum vkd3d_dbg_channel channel, enum vkd3d_dbg_level level
#endif
else
{
spinlock_acquire(&spin);
spinlock_acquire(&vkd3d_debug_buffer_spin);
fprintf(log_file, "%04x:%s:%s: ", tid, debug_level_names[level], function);
vfprintf(log_file, fmt, args);
spinlock_release(&spin);
spinlock_release(&vkd3d_debug_buffer_spin);
fflush(log_file);
}
va_end(args);
Expand Down
1 change: 1 addition & 0 deletions libs/vkd3d/breadcrumbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ void vkd3d_breadcrumb_tracer_report_device_lost(struct vkd3d_breadcrumb_tracer *
}

ERR("Done analyzing breadcrumbs ...\n");
vkd3d_dbg_flush();
pthread_mutex_unlock(&global_report_lock);
}

Expand Down
11 changes: 11 additions & 0 deletions libs/vkd3d/debug_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ void *vkd3d_shader_debug_ring_thread_main(void *arg)
}
}
INFO("Done fishing for clues ...\n");
vkd3d_dbg_flush();
}

return NULL;
Expand Down Expand Up @@ -437,7 +438,17 @@ HRESULT vkd3d_shader_debug_ring_init(struct vkd3d_shader_debug_ring *ring,
* We use coherent in the debug_channel.h header, but not necessarily guaranteed to be coherent with
* host reads, so make extra sure. */
if (device->device_info.device_coherent_memory_features_amd.deviceCoherentMemory)
{
memory_props |= VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD | VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD;
}
else if (device->device_info.vulkan_1_2_properties.driverID == VK_DRIVER_ID_NVIDIA_PROPRIETARY)
{
/* Writes to sysmem seem to be coherent, but not ReBAR. Very slow, but hey,
* we're desperate when we're doing breadcrumb + debug ring! */
memory_props = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_CACHED_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
}
}

if (FAILED(vkd3d_allocate_internal_buffer_memory(device, ring->device_atomic_buffer,
Expand Down
Loading