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

Allow breadcrumb to interact with QA ring better #2313

Merged
merged 3 commits into from
Jan 27, 2025
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
4 changes: 4 additions & 0 deletions libs/vkd3d/breadcrumbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "vkd3d_common.h"
#include <assert.h>
#include <stdio.h>
#include "vkd3d_descriptor_debug.h"

/* Just allocate everything up front. This only consumes host memory anyways. */
#define MAX_COMMAND_LISTS (32 * 1024)
Expand Down Expand Up @@ -593,6 +594,9 @@ void vkd3d_breadcrumb_tracer_report_device_lost(struct vkd3d_breadcrumb_tracer *
VkQueue vk_queue;
unsigned int i;

/* There may be latent information in the QA checker. */
vkd3d_descriptor_debug_kick_qa_check(device->descriptor_qa_global_info);

/* Avoid interleaved logs when multiple threads observe device lost. */
pthread_mutex_lock(&global_report_lock);
ERR("Device lost observed, analyzing breadcrumbs ...\n");
Expand Down
26 changes: 26 additions & 0 deletions libs/vkd3d/debug_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,29 @@ void vkd3d_shader_hash_range_parse(FILE *file, struct vkd3d_shader_hash_range **

*range_count = new_count;
}

VkMemoryPropertyFlags vkd3d_debug_buffer_memory_properties(struct d3d12_device *device, VkMemoryPropertyFlags flags)
{
if (vkd3d_config_flags & VKD3D_CONFIG_FLAG_BREADCRUMBS)
{
/* Expect crashes since we won't have time to flush caches.
* 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)
{
flags |= VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD | VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD;
INFO("Enabling uncached device memory for debug buffer.\n");
}
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! */
flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_CACHED_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
INFO("Forcing (implicitly-coherent) sysmem for debug buffer.\n");
}
}

return flags;
}
39 changes: 6 additions & 33 deletions libs/vkd3d/debug_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,21 +400,9 @@ HRESULT vkd3d_shader_debug_ring_init(struct vkd3d_shader_debug_ring *ring,
memory_props = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_CACHED_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;

/* If we're doing breadcrumb debugging, we also need to be able to read debug ring messages
* from a crash, so we cannot rely on being able to copy the device payload back to host.
* Use PCI-e BAR + UNCACHED + DEVICE_COHERENT if we must. */
if (vkd3d_config_flags & VKD3D_CONFIG_FLAG_BREADCRUMBS)
{
INFO("Using debug ring with breadcrumbs, opting in to device uncached payload buffer.\n");
/* 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;
INFO("Enabling uncached device memory for debug ring.\n");
}
}
#ifdef VKD3D_ENABLE_BREADCRUMBS
memory_props = vkd3d_debug_buffer_memory_properties(device, memory_props);
#endif

if (FAILED(vkd3d_allocate_internal_buffer_memory(device, ring->host_buffer,
memory_props, &ring->host_buffer_memory)))
Expand All @@ -432,24 +420,9 @@ HRESULT vkd3d_shader_debug_ring_init(struct vkd3d_shader_debug_ring *ring,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;

if (vkd3d_config_flags & VKD3D_CONFIG_FLAG_BREADCRUMBS)
{
/* Expect crashes since we won't have time to flush caches.
* 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;
}
}
#ifdef VKD3D_ENABLE_BREADCRUMBS
memory_props = vkd3d_debug_buffer_memory_properties(device, memory_props);
#endif

if (FAILED(vkd3d_allocate_internal_buffer_memory(device, ring->device_atomic_buffer,
memory_props, &ring->device_atomic_buffer_memory)))
Expand Down
29 changes: 22 additions & 7 deletions libs/vkd3d/descriptor_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ static HRESULT vkd3d_descriptor_debug_alloc_global_info_instructions(
{
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
struct vkd3d_descriptor_qa_global_info *global_info;
VkMemoryPropertyFlags memory_properties;
const uint32_t num_payloads = 4096;
D3D12_RESOURCE_DESC1 buffer_desc;
D3D12_HEAP_PROPERTIES heap_info;
Expand Down Expand Up @@ -328,9 +329,13 @@ static HRESULT vkd3d_descriptor_debug_alloc_global_info_instructions(
return hr;
}

memory_properties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
#ifdef VKD3D_ENABLE_BREADCRUMBS
memory_properties = vkd3d_debug_buffer_memory_properties(device, memory_properties);
#endif

if (FAILED(hr = vkd3d_allocate_internal_buffer_memory(device, global_info->vk_payload_buffer,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
&global_info->payload_device_allocation)))
memory_properties, &global_info->payload_device_allocation)))
{
vkd3d_descriptor_debug_free_global_info(global_info, device);
return hr;
Expand Down Expand Up @@ -362,11 +367,15 @@ static HRESULT vkd3d_descriptor_debug_alloc_global_info_instructions(
return hr;
}

memory_properties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
#ifdef VKD3D_ENABLE_BREADCRUMBS
memory_properties = vkd3d_debug_buffer_memory_properties(device, memory_properties);
#endif

if (FAILED(hr = vkd3d_allocate_internal_buffer_memory(device, global_info->vk_control_buffer,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
&global_info->control_device_allocation)))
memory_properties, &global_info->control_device_allocation)))
{
vkd3d_descriptor_debug_free_global_info(global_info, device);
return hr;
Expand Down Expand Up @@ -474,6 +483,7 @@ static HRESULT vkd3d_descriptor_debug_alloc_global_info_descriptors(
{
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
struct vkd3d_descriptor_qa_global_info *global_info;
VkMemoryPropertyFlags memory_properties;
D3D12_RESOURCE_DESC1 buffer_desc;
D3D12_HEAP_PROPERTIES heap_info;
D3D12_HEAP_FLAGS heap_flags;
Expand Down Expand Up @@ -508,8 +518,13 @@ static HRESULT vkd3d_descriptor_debug_alloc_global_info_descriptors(
return hr;
}

memory_properties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
#ifdef VKD3D_ENABLE_BREADCRUMBS
memory_properties = vkd3d_debug_buffer_memory_properties(device, memory_properties);
#endif

if (FAILED(hr = vkd3d_allocate_internal_buffer_memory(device, global_info->vk_payload_buffer,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
memory_properties,
&global_info->payload_device_allocation)))
{
vkd3d_descriptor_debug_free_global_info(global_info, device);
Expand Down
2 changes: 2 additions & 0 deletions libs/vkd3d/vkd3d_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -3614,6 +3614,8 @@ enum vkd3d_shader_hash_range_kind

void vkd3d_shader_hash_range_parse(FILE *file, struct vkd3d_shader_hash_range **ranges,
size_t *range_size, size_t *range_count, enum vkd3d_shader_hash_range_kind kind);

VkMemoryPropertyFlags vkd3d_debug_buffer_memory_properties(struct d3d12_device *device, VkMemoryPropertyFlags flags);
#endif

#ifdef VKD3D_ENABLE_BREADCRUMBS
Expand Down