Skip to content

Commit

Permalink
vkd3d: Add hash range for QA checks as well.
Browse files Browse the repository at this point in the history
Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
  • Loading branch information
HansKristian-Work committed Sep 24, 2024
1 parent 3657d00 commit 66d0fc6
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 7 deletions.
21 changes: 21 additions & 0 deletions libs/vkd3d/debug_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,27 @@ void vkd3d_shader_hash_range_parse(FILE *file, struct vkd3d_shader_hash_range **
(*ranges)[new_count].lo,
(*ranges)[new_count].hi);
}
else if (kind == VKD3D_SHADER_HASH_RANGE_KIND_QA)
{
if (*end_ptr == '\0')
{
(*ranges)[new_count].flags = VKD3D_SHADER_HASH_RANGE_QA_FLAG_ALLOW;
end_ptr = "allow (default)";
}
else if (strcmp(end_ptr, "allow") == 0)
(*ranges)[new_count].flags = VKD3D_SHADER_HASH_RANGE_QA_FLAG_ALLOW;
else if (strcmp(end_ptr, "disallow") == 0)
(*ranges)[new_count].flags = VKD3D_SHADER_HASH_RANGE_QA_FLAG_DISALLOW;
else if (strcmp(end_ptr, "full") == 0)
(*ranges)[new_count].flags = VKD3D_SHADER_HASH_RANGE_QA_FLAG_FULL_QA;
else
end_ptr = "N/A";

INFO("Inserting %s QA check for %016"PRIx64" - %016"PRIx64".\n",
end_ptr,
(*ranges)[new_count].lo,
(*ranges)[new_count].hi);
}

new_count++;
}
Expand Down
84 changes: 84 additions & 0 deletions libs/vkd3d/descriptor_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ struct vkd3d_descriptor_qa_global_info
pthread_mutex_t ring_lock;
pthread_cond_t ring_cond;
bool active;

struct vkd3d_shader_hash_range *qa_ranges;
size_t qa_range_size;
size_t qa_range_count;
};

static const char *debug_descriptor_type(vkd3d_descriptor_qa_flags type_flags)
Expand Down Expand Up @@ -265,6 +269,25 @@ const VkDescriptorBufferInfo *vkd3d_descriptor_debug_get_control_info_descriptor
return NULL;
}

static void vkd3d_descriptor_debug_parse_shader_ranges(
struct vkd3d_descriptor_qa_global_info *global_info,
enum vkd3d_shader_hash_range_kind kind)
{
char env[VKD3D_PATH_MAX];
FILE *file;

if (vkd3d_get_env_var("VKD3D_QA_HASHES", env, sizeof(env)))
{
file = fopen(env, "r");
if (file)
{
vkd3d_shader_hash_range_parse(file, &global_info->qa_ranges, &global_info->qa_range_size,
&global_info->qa_range_count, kind);
fclose(file);
}
}
}

static HRESULT vkd3d_descriptor_debug_alloc_global_info_instructions(
struct vkd3d_descriptor_qa_global_info **out_global_info,
struct d3d12_device *device)
Expand Down Expand Up @@ -374,10 +397,67 @@ static HRESULT vkd3d_descriptor_debug_alloc_global_info_instructions(
return E_OUTOFMEMORY;
}

vkd3d_descriptor_debug_parse_shader_ranges(global_info, VKD3D_SHADER_HASH_RANGE_KIND_QA);

*out_global_info = global_info;
return S_OK;
}

uint32_t vkd3d_descriptor_debug_get_shader_interface_flags(
struct vkd3d_descriptor_qa_global_info *global_info,
const void *code, size_t size)
{
struct vkd3d_shader_code dxbc;
vkd3d_shader_hash_t hash;
uint32_t flags = 0;
size_t i;

if (!global_info || !global_info->active)
return 0;

dxbc.code = code;
dxbc.size = size;
hash = vkd3d_shader_hash(&dxbc);

if (global_info->qa_range_count)
{
for (i = 0; i < global_info->qa_range_count; i++)
if (global_info->qa_ranges[i].lo <= hash && hash <= global_info->qa_ranges[i].hi)
flags |= global_info->qa_ranges[i].flags;
}
else
{
flags = VKD3D_SHADER_HASH_RANGE_QA_FLAG_ALLOW;
}

if (flags & VKD3D_SHADER_HASH_RANGE_QA_FLAG_FULL_QA)
flags |= VKD3D_SHADER_HASH_RANGE_QA_FLAG_ALLOW;
if (flags & VKD3D_SHADER_HASH_RANGE_QA_FLAG_DISALLOW)
flags = 0;

if (descriptor_debug_active_descriptor_checks)
{
if (flags & VKD3D_SHADER_HASH_RANGE_QA_FLAG_ALLOW)
flags = VKD3D_SHADER_INTERFACE_DESCRIPTOR_QA_BUFFER;
}
else if (descriptor_debug_active_instruction_checks)
{
if (flags & VKD3D_SHADER_HASH_RANGE_QA_FLAG_FULL_QA)
{
flags = VKD3D_SHADER_INTERFACE_INSTRUCTION_QA_BUFFER_FULL |
VKD3D_SHADER_INTERFACE_INSTRUCTION_QA_BUFFER;
}
else if (flags & VKD3D_SHADER_HASH_RANGE_QA_FLAG_ALLOW)
flags = VKD3D_SHADER_INTERFACE_INSTRUCTION_QA_BUFFER;
}
else
{
flags = 0;
}

return flags;
}

static HRESULT vkd3d_descriptor_debug_alloc_global_info_descriptors(
struct vkd3d_descriptor_qa_global_info **out_global_info, unsigned int num_cookies,
struct d3d12_device *device)
Expand Down Expand Up @@ -453,6 +533,8 @@ static HRESULT vkd3d_descriptor_debug_alloc_global_info_descriptors(
return E_OUTOFMEMORY;
}

vkd3d_descriptor_debug_parse_shader_ranges(global_info, VKD3D_SHADER_HASH_RANGE_KIND_QA);

*out_global_info = global_info;
return S_OK;
}
Expand Down Expand Up @@ -494,6 +576,8 @@ void vkd3d_descriptor_debug_free_global_info(

vkd3d_free_device_memory(device, &global_info->payload_device_allocation);
VK_CALL(vkDestroyBuffer(device->vk_device, global_info->vk_payload_buffer, NULL));

vkd3d_free(global_info->qa_ranges);
vkd3d_free(global_info);
}

Expand Down
5 changes: 5 additions & 0 deletions libs/vkd3d/raytracing_pipeline.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define VKD3D_DBG_CHANNEL VKD3D_DBG_CHANNEL_API
#include "vkd3d_private.h"
#include "vkd3d_string.h"
#include "vkd3d_descriptor_debug.h"

#define RT_TRACE TRACE

Expand Down Expand Up @@ -2339,6 +2340,10 @@ static HRESULT d3d12_state_object_compile_pipeline_variant(struct d3d12_state_ob
dxil.code = data->dxil_libraries[entry->identifier]->DXILLibrary.pShaderBytecode;
dxil.size = data->dxil_libraries[entry->identifier]->DXILLibrary.BytecodeLength;

shader_interface_info.flags |= vkd3d_descriptor_debug_get_shader_interface_flags(
object->device->descriptor_qa_global_info,
dxil.code, dxil.size);

if (vkd3d_shader_compile_dxil_export(&dxil, entry->real_entry_point, entry->debug_entry_point,
&spirv, NULL,
&shader_interface_info, &shader_interface_local_info, &compile_args) != VKD3D_OK)
Expand Down
9 changes: 4 additions & 5 deletions libs/vkd3d/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -1707,11 +1707,6 @@ unsigned int d3d12_root_signature_get_shader_interface_flags(const struct d3d12_
if (d3d12_device_use_embedded_mutable_descriptors(root_signature->device))
flags |= VKD3D_SHADER_INTERFACE_RAW_VA_ALIAS_DESCRIPTOR_BUFFER;

if (vkd3d_descriptor_debug_active_descriptor_qa_checks())
flags |= VKD3D_SHADER_INTERFACE_DESCRIPTOR_QA_BUFFER;
if (vkd3d_descriptor_debug_active_instruction_qa_checks())
flags |= VKD3D_SHADER_INTERFACE_INSTRUCTION_QA_BUFFER;

return flags;
}

Expand Down Expand Up @@ -2660,6 +2655,8 @@ static HRESULT vkd3d_compile_shader_stage(struct d3d12_pipeline_state *state, st
TRACE("Calling vkd3d_shader_compile_dxbc.\n");

d3d12_pipeline_state_init_shader_interface(state, device, stage, &shader_interface);
shader_interface.flags |= vkd3d_descriptor_debug_get_shader_interface_flags(
device->descriptor_qa_global_info, dxbc.code, dxbc.size);
d3d12_pipeline_state_init_compile_arguments(state, device, stage, &compile_args);

if ((ret = vkd3d_shader_compile_dxbc(&dxbc, spirv_code, spirv_code_debug,
Expand Down Expand Up @@ -2973,6 +2970,8 @@ static HRESULT d3d12_pipeline_state_init_compute(struct d3d12_pipeline_state *st
state->pipeline_type = VKD3D_PIPELINE_TYPE_COMPUTE;
d3d12_pipeline_state_init_shader_interface(state, device,
VK_SHADER_STAGE_COMPUTE_BIT, &shader_interface);
shader_interface.flags |= vkd3d_descriptor_debug_get_shader_interface_flags(
device->descriptor_qa_global_info, desc->cs.pShaderBytecode, desc->cs.BytecodeLength);

vkd3d_load_spirv_from_cached_state(device, cached_pso,
VK_SHADER_STAGE_COMPUTE_BIT, &state->compute.code,
Expand Down
5 changes: 5 additions & 0 deletions libs/vkd3d/vkd3d_descriptor_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const VkDescriptorBufferInfo *vkd3d_descriptor_debug_get_payload_info_descriptor
const VkDescriptorBufferInfo *vkd3d_descriptor_debug_get_control_info_descriptor(
struct vkd3d_descriptor_qa_global_info *global_info);

uint32_t vkd3d_descriptor_debug_get_shader_interface_flags(
struct vkd3d_descriptor_qa_global_info *global_info,
const void *code, size_t size);

void vkd3d_descriptor_debug_init(void);
bool vkd3d_descriptor_debug_active_log(void);
bool vkd3d_descriptor_debug_active_instruction_qa_checks(void);
Expand Down Expand Up @@ -98,6 +102,7 @@ VkDeviceSize vkd3d_descriptor_debug_heap_info_size(unsigned int num_descriptors)
#define vkd3d_descriptor_debug_write_descriptor(heap, heap_cookie, offset, type_flags, cookie) ((void)0)
#define vkd3d_descriptor_debug_copy_descriptor(dst_heap, dst_heap_cookie, dst_offset, src_heap, src_heap_cookie, src_offset, cookie) ((void)0)
#define vkd3d_descriptor_debug_heap_info_size(num_descriptors) 0
#define vkd3d_descriptor_debug_get_shader_interface_flags(global_info, code, size) 0
#endif

#endif
13 changes: 11 additions & 2 deletions libs/vkd3d/vkd3d_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -3455,16 +3455,25 @@ enum vkd3d_breadcrumb_command_type
};

#if defined(VKD3D_ENABLE_BREADCRUMBS) || defined(VKD3D_ENABLE_DESCRIPTOR_QA)

enum vkd3d_shader_hash_range_qa_flags
{
VKD3D_SHADER_HASH_RANGE_QA_FLAG_ALLOW = 1 << 0,
VKD3D_SHADER_HASH_RANGE_QA_FLAG_DISALLOW = 1 << 1,
VKD3D_SHADER_HASH_RANGE_QA_FLAG_FULL_QA = 1 << 2
};

struct vkd3d_shader_hash_range
{
vkd3d_shader_hash_t lo;
vkd3d_shader_hash_t hi;
uint32_t flags;
uint32_t flags; /* interpretation of this depends on the kind. */
};

enum vkd3d_shader_hash_range_kind
{
VKD3D_SHADER_HASH_RANGE_KIND_BARRIERS = 0
VKD3D_SHADER_HASH_RANGE_KIND_BARRIERS = 0,
VKD3D_SHADER_HASH_RANGE_KIND_QA,
};

void vkd3d_shader_hash_range_parse(FILE *file, struct vkd3d_shader_hash_range **ranges,
Expand Down

0 comments on commit 66d0fc6

Please sign in to comment.