From 653de0c0767213734a60145aedcf562680784cfa Mon Sep 17 00:00:00 2001 From: Giovanni Mascellani Date: Thu, 6 Nov 2025 22:33:27 +0100 Subject: [PATCH] tests/shader_runner: Generate a default descriptor mapping when none is provided. --- tests/shader_runner.c | 67 ++++++++++++++++++++++++++ tests/shader_runner.h | 1 + tests/shader_runner_d3d12.c | 93 ++----------------------------------- 3 files changed, 73 insertions(+), 88 deletions(-) diff --git a/tests/shader_runner.c b/tests/shader_runner.c index 266ff89e4..510a8bb21 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -1777,6 +1777,8 @@ static void parse_descriptors_directive(struct shader_runner *runner, const char char type_chr; int pos; + runner->default_descriptors = false; + if (runner->descriptor_count == ARRAY_SIZE(runner->descriptors)) fatal_error("Too many descriptors (%u).\n", runner->descriptor_count); @@ -2407,6 +2409,67 @@ bool test_skipping_execution(const char *executor, const char *compiler, return false; } +static int compare_resources(const void *ptr1, const void *ptr2) +{ + const struct resource *resource1 = *(const struct resource **)ptr1; + const struct resource *resource2 = *(const struct resource **)ptr2; + int ret; + + if ((ret = vkd3d_u32_compare(resource1->desc.type, resource2->desc.type))) + return ret; + + return vkd3d_u32_compare(resource1->desc.slot, resource2->desc.slot); +} + +static void set_default_descriptor_mapping(struct shader_runner *runner) +{ + struct descriptor_mapping *mapping, *base_mapping = NULL; + bool is_buffer = false; + size_t i; + + qsort(runner->resources, runner->resource_count, sizeof(*runner->resources), compare_resources); + + runner->descriptor_count = 0; + + for (i = 0; i < runner->resource_count; ++i) + { + const struct resource *resource = runner->resources[i]; + + switch (resource->desc.type) + { + case RESOURCE_TYPE_TEXTURE: + case RESOURCE_TYPE_UAV: + mapping = &runner->descriptors[runner->descriptor_count]; + if (resource->desc.type == RESOURCE_TYPE_UAV) + mapping->type = VKD3D_SHADER_DESCRIPTOR_TYPE_UAV; + else + mapping->type = VKD3D_SHADER_DESCRIPTOR_TYPE_SRV; + mapping->register_idx = resource->desc.slot; + mapping->register_space = 0; + mapping->count = 1; + mapping->target_idx = resource->desc.slot; + + if (base_mapping && base_mapping->type == mapping->type + && is_buffer == (resource->desc.dimension == RESOURCE_DIMENSION_BUFFER) + && base_mapping->register_idx + base_mapping->count == resource->desc.slot) + { + ++base_mapping->count; + break; + } + + base_mapping = mapping; + is_buffer = resource->desc.dimension == RESOURCE_DIMENSION_BUFFER; + ++runner->descriptor_count; + break; + + case RESOURCE_TYPE_RENDER_TARGET: + case RESOURCE_TYPE_DEPTH_STENCIL: + case RESOURCE_TYPE_VERTEX_BUFFER: + break; + } + } +} + void run_shader_tests(struct shader_runner *runner, const struct shader_runner_caps *caps, const struct shader_runner_ops *ops, void *dxc_compiler) { @@ -2446,6 +2509,7 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_c runner->dxc_compiler = dxc_compiler; runner->minimum_shader_model = minimum_shader_model; runner->maximum_shader_model = maximum_shader_model; + runner->default_descriptors = true; runner->alpha_test_func = VKD3D_SHADER_COMPARISON_FUNC_ALWAYS; runner->point_size = 1.0f; runner->point_size_min = 1.0f; @@ -2737,6 +2801,8 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_c else if (!strcmp(line, "[test]\n")) { state = STATE_TEST; + if (runner->default_descriptors) + set_default_descriptor_mapping(runner); } else if (!strcmp(line, "[preproc]\n")) { @@ -2783,6 +2849,7 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_c { state = STATE_DESCRIPTORS; runner->descriptor_count = 0; + runner->default_descriptors = true; } else { diff --git a/tests/shader_runner.h b/tests/shader_runner.h index 85eadf742..6c0cd7e43 100644 --- a/tests/shader_runner.h +++ b/tests/shader_runner.h @@ -311,6 +311,7 @@ struct shader_runner struct descriptor_mapping descriptors[MAX_DESCRIPTORS]; unsigned int descriptor_count; + bool default_descriptors; }; struct shader_runner_ops diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index cf6055fce..bac214513 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -312,9 +312,7 @@ static ID3D12RootSignature *d3d12_runner_create_root_signature(struct d3d12_shad D3D12_DESCRIPTOR_RANGE root_ranges[MAX_DESCRIPTORS]; D3D12_ROOT_PARAMETER root_params[17], *root_param; D3D12_STATIC_SAMPLER_DESC static_samplers[7]; - struct d3d12_resource *base_resource = NULL; ID3D12RootSignature *root_signature; - unsigned int slot; HRESULT hr; size_t i; @@ -324,6 +322,7 @@ static ID3D12RootSignature *d3d12_runner_create_root_signature(struct d3d12_shad root_signature_desc.pStaticSamplers = static_samplers; root_signature_desc.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT; + /* Native d3d12 doesn't like an empty root descriptor table. */ if (runner->r.descriptor_count) { root_param = &root_params[root_signature_desc.NumParameters++]; @@ -348,55 +347,6 @@ static ID3D12RootSignature *d3d12_runner_create_root_signature(struct d3d12_shad range->OffsetInDescriptorsFromTableStart += MAX_RESOURCES; } } - else - { - for (i = 0; i < runner->r.resource_count; ++i) - { - struct d3d12_resource *resource = d3d12_resource(runner->r.resources[i]); - D3D12_DESCRIPTOR_RANGE *range; - - switch (resource->r.desc.type) - { - case RESOURCE_TYPE_TEXTURE: - case RESOURCE_TYPE_UAV: - range = &resource->descriptor_range; - - if (base_resource && resource->r.desc.type == base_resource->r.desc.type - && resource->r.desc.slot == slot + 1) - { - ++base_resource->descriptor_range.NumDescriptors; - resource->descriptor_range.NumDescriptors = 0; - ++slot; - continue; - } - - resource->root_index = root_signature_desc.NumParameters++; - root_param = &root_params[resource->root_index]; - root_param->ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; - root_param->DescriptorTable.NumDescriptorRanges = 1; - root_param->DescriptorTable.pDescriptorRanges = range; - root_param->ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; - - if (resource->r.desc.type == RESOURCE_TYPE_UAV) - range->RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_UAV; - else - range->RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV; - range->NumDescriptors = 1; - range->BaseShaderRegister = resource->r.desc.slot; - range->RegisterSpace = 0; - range->OffsetInDescriptorsFromTableStart = 0; - - base_resource = resource; - slot = resource->r.desc.slot; - break; - - case RESOURCE_TYPE_RENDER_TARGET: - case RESOURCE_TYPE_DEPTH_STENCIL: - case RESOURCE_TYPE_VERTEX_BUFFER: - break; - } - } - } if (runner->r.uniform_count) { @@ -455,7 +405,6 @@ static bool d3d12_runner_dispatch(struct shader_runner *r, unsigned int x, unsig D3D12_SHADER_BYTECODE cs; ID3D10Blob *cs_code; HRESULT hr; - size_t i; cs_code = compile_hlsl(&runner->r, SHADER_TYPE_CS); todo_if(runner->r.is_todo && runner->r.minimum_shader_model < SHADER_MODEL_6_0) ok(cs_code, "Failed to compile shader.\n"); @@ -483,30 +432,6 @@ static bool d3d12_runner_dispatch(struct shader_runner *r, unsigned int x, unsig if (runner->r.uniform_count) ID3D12GraphicsCommandList_SetComputeRoot32BitConstants(command_list, uniform_index, runner->r.uniform_count, runner->r.uniforms, 0); - for (i = 0; i < runner->r.resource_count; ++i) - { - struct d3d12_resource *resource = d3d12_resource(runner->r.resources[i]); - - switch (resource->r.desc.type) - { - case RESOURCE_TYPE_TEXTURE: - if (resource->descriptor_range.NumDescriptors && !r->descriptor_count) - ID3D12GraphicsCommandList_SetComputeRootDescriptorTable(command_list, resource->root_index, - get_gpu_descriptor_handle(test_context, runner->heap, resource->r.desc.slot)); - break; - - case RESOURCE_TYPE_UAV: - if (resource->descriptor_range.NumDescriptors && !r->descriptor_count) - ID3D12GraphicsCommandList_SetComputeRootDescriptorTable(command_list, resource->root_index, - get_gpu_descriptor_handle(test_context, runner->heap, resource->r.desc.slot + MAX_RESOURCES)); - break; - - case RESOURCE_TYPE_RENDER_TARGET: - case RESOURCE_TYPE_DEPTH_STENCIL: - case RESOURCE_TYPE_VERTEX_BUFFER: - break; - } - } if (r->descriptor_count) ID3D12GraphicsCommandList_SetComputeRootDescriptorTable(command_list, 0, @@ -952,18 +877,6 @@ static bool d3d12_runner_draw(struct shader_runner *r, D3D_PRIMITIVE_TOPOLOGY pr fb_height = resource->r.desc.height; break; - case RESOURCE_TYPE_TEXTURE: - if (resource->descriptor_range.NumDescriptors && !r->descriptor_count) - ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list, resource->root_index, - get_gpu_descriptor_handle(test_context, runner->heap, resource->r.desc.slot)); - break; - - case RESOURCE_TYPE_UAV: - if (resource->descriptor_range.NumDescriptors && !r->descriptor_count) - ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list, resource->root_index, - get_gpu_descriptor_handle(test_context, runner->heap, resource->r.desc.slot + MAX_RESOURCES)); - break; - case RESOURCE_TYPE_VERTEX_BUFFER: vbv.BufferLocation = ID3D12Resource_GetGPUVirtualAddress(resource->resource); vbv.StrideInBytes = get_vb_stride(&runner->r, resource->r.desc.slot); @@ -971,6 +884,10 @@ static bool d3d12_runner_draw(struct shader_runner *r, D3D_PRIMITIVE_TOPOLOGY pr ID3D12GraphicsCommandList_IASetVertexBuffers(command_list, resource->r.desc.slot, 1, &vbv); break; + + case RESOURCE_TYPE_TEXTURE: + case RESOURCE_TYPE_UAV: + break; } }