diff --git a/tests/shader_runner.c b/tests/shader_runner.c index 383a61fb..f203e453 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -229,17 +229,17 @@ static void parse_sampler_directive(struct sampler *sampler, const char *line) } } -static void parse_texture_directive(struct texture_params *texture, const char *line) +static void parse_resource_directive(struct resource_params *resource, const char *line) { int ret; if (match_string(line, "format", &line)) { - texture->format = parse_format(line, &texture->data_type, &texture->texel_size, &line); + resource->format = parse_format(line, &resource->data_type, &resource->texel_size, &line); } else if (match_string(line, "size", &line)) { - ret = sscanf(line, "( %u , %u )", &texture->width, &texture->height); + ret = sscanf(line, "( %u , %u )", &resource->width, &resource->height); if (ret < 2) fatal_error("Malformed texture size '%s'.\n", line); } @@ -257,7 +257,7 @@ static void parse_texture_directive(struct texture_params *texture, const char * for (;;) { - switch (texture->data_type) + switch (resource->data_type) { case TEXTURE_DATA_FLOAT: u.f = strtof(line, &rest); @@ -275,9 +275,9 @@ static void parse_texture_directive(struct texture_params *texture, const char * if (rest == line) break; - vkd3d_array_reserve((void **)&texture->data, &texture->data_capacity, texture->data_size + sizeof(u), 1); - memcpy(texture->data + texture->data_size, &u, sizeof(u)); - texture->data_size += sizeof(u); + vkd3d_array_reserve((void **)&resource->data, &resource->data_capacity, resource->data_size + sizeof(u), 1); + memcpy(resource->data + resource->data_size, &u, sizeof(u)); + resource->data_size += sizeof(u); line = rest; } } @@ -460,29 +460,29 @@ static struct sampler *get_sampler(struct shader_runner *runner, unsigned int sl return NULL; } -static void set_texture(struct shader_runner *runner, struct texture *texture) +static void set_resource(struct shader_runner *runner, struct resource *resource) { size_t i; - for (i = 0; i < runner->texture_count; ++i) + for (i = 0; i < runner->resource_count; ++i) { - if (runner->textures[i]->slot == texture->slot) + if (runner->resources[i]->slot == resource->slot && runner->resources[i]->type == resource->type) { - runner->ops->destroy_texture(runner, runner->textures[i]); - runner->textures[i] = texture; + runner->ops->destroy_resource(runner, runner->resources[i]); + runner->resources[i] = resource; return; } } - runner->textures = realloc(runner->textures, (runner->texture_count + 1) * sizeof(*runner->textures)); - runner->textures[runner->texture_count++] = texture; + runner->resources = realloc(runner->resources, (runner->resource_count + 1) * sizeof(*runner->resources)); + runner->resources[runner->resource_count++] = resource; } void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const struct shader_runner_ops *ops) { size_t shader_source_size = 0, shader_source_len = 0; + struct resource_params current_resource; struct sampler *current_sampler = NULL; - struct texture_params current_texture; enum parse_state state = STATE_NONE; unsigned int i, line_number = 0; const char *filename = NULL; @@ -534,8 +534,8 @@ void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const break; case STATE_TEXTURE: - set_texture(runner, runner->ops->create_texture(runner, ¤t_texture)); - free(current_texture.data); + set_resource(runner, runner->ops->create_resource(runner, ¤t_resource)); + free(current_resource.data); break; case STATE_SHADER_PIXEL: @@ -673,12 +673,13 @@ void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const { state = STATE_TEXTURE; - memset(¤t_texture, 0, sizeof(current_texture)); + memset(¤t_resource, 0, sizeof(current_resource)); - current_texture.slot = index; - current_texture.format = DXGI_FORMAT_R32G32B32A32_FLOAT; - current_texture.data_type = TEXTURE_DATA_FLOAT; - current_texture.texel_size = 16; + current_resource.slot = index; + current_resource.type = RESOURCE_TYPE_TEXTURE; + current_resource.format = DXGI_FORMAT_R32G32B32A32_FLOAT; + current_resource.data_type = TEXTURE_DATA_FLOAT; + current_resource.texel_size = 16; } else if (!strcmp(line, "[test]\n")) { @@ -742,7 +743,7 @@ void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const break; case STATE_TEXTURE: - parse_texture_directive(¤t_texture, line); + parse_resource_directive(¤t_resource, line); break; case STATE_TEST: @@ -757,12 +758,12 @@ void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const free(runner->input_elements); free(runner->vs_source); free(runner->ps_source); - for (i = 0; i < runner->texture_count; ++i) + for (i = 0; i < runner->resource_count; ++i) { - if (runner->textures[i]) - runner->ops->destroy_texture(runner, runner->textures[i]); + if (runner->resources[i]) + runner->ops->destroy_resource(runner, runner->resources[i]); } - free(runner->textures); + free(runner->resources); fclose(f); diff --git a/tests/shader_runner.h b/tests/shader_runner.h index 8e2ca20e..67944fda 100644 --- a/tests/shader_runner.h +++ b/tests/shader_runner.h @@ -51,9 +51,15 @@ struct sampler D3D12_TEXTURE_ADDRESS_MODE u_address, v_address, w_address; }; -struct texture_params +enum resource_type +{ + RESOURCE_TYPE_TEXTURE, +}; + +struct resource_params { unsigned int slot; + enum resource_type type; DXGI_FORMAT format; enum texture_data_type data_type; @@ -63,9 +69,10 @@ struct texture_params size_t data_size, data_capacity; }; -struct texture +struct resource { unsigned int slot; + enum resource_type type; }; struct input_element @@ -88,8 +95,8 @@ struct shader_runner uint32_t *uniforms; size_t uniform_count, uniform_capacity; - struct texture **textures; - size_t texture_count; + struct resource **resources; + size_t resource_count; struct sampler *samplers; size_t sampler_count; @@ -100,8 +107,8 @@ struct shader_runner struct shader_runner_ops { - struct texture *(*create_texture)(struct shader_runner *runner, const struct texture_params *params); - void (*destroy_texture)(struct shader_runner *runner, struct texture *texture); + struct resource *(*create_resource)(struct shader_runner *runner, const struct resource_params *params); + void (*destroy_resource)(struct shader_runner *runner, struct resource *resource); void (*draw_quad)(struct shader_runner *runner); void (*probe_vec4)(struct shader_runner *runner, const RECT *rect, const struct vec4 *v, unsigned int ulps); }; diff --git a/tests/shader_runner_d3d11.c b/tests/shader_runner_d3d11.c index d419db2d..838e04ff 100644 --- a/tests/shader_runner_d3d11.c +++ b/tests/shader_runner_d3d11.c @@ -38,17 +38,17 @@ static HRESULT (WINAPI *pD3D11CreateDevice)(IDXGIAdapter *adapter, D3D_DRIVER_TY UINT sdk_version, ID3D11Device **device_out, D3D_FEATURE_LEVEL *obtained_feature_level, ID3D11DeviceContext **immediate_context); -struct d3d11_texture +struct d3d11_resource { - struct texture t; + struct resource r; ID3D11Texture2D *texture; ID3D11ShaderResourceView *srv; }; -static struct d3d11_texture *d3d11_texture(struct texture *t) +static struct d3d11_resource *d3d11_resource(struct resource *r) { - return CONTAINING_RECORD(t, struct d3d11_texture, t); + return CONTAINING_RECORD(r, struct d3d11_resource, r); } struct d3d11_shader_runner @@ -365,48 +365,56 @@ static ID3D11Buffer *create_buffer(ID3D11Device *device, unsigned int bind_flags return buffer; } -static struct texture *d3d11_runner_create_texture(struct shader_runner *r, const struct texture_params *params) +static struct resource *d3d11_runner_create_resource(struct shader_runner *r, const struct resource_params *params) { struct d3d11_shader_runner *runner = d3d11_shader_runner(r); ID3D11Device *device = runner->device; D3D11_SUBRESOURCE_DATA resource_data; - D3D11_TEXTURE2D_DESC desc = {0}; - struct d3d11_texture *texture; + struct d3d11_resource *resource; HRESULT hr; - texture = calloc(1, sizeof(*texture)); + resource = calloc(1, sizeof(*resource)); - texture->t.slot = params->slot; + resource->r.slot = params->slot; + resource->r.type = params->type; - desc.Width = params->width; - desc.Height = params->height; - desc.MipLevels = 1; - desc.ArraySize = 1; - desc.Format = params->format; - desc.SampleDesc.Count = 1; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + switch (params->type) + { + case RESOURCE_TYPE_TEXTURE: + { + D3D11_TEXTURE2D_DESC desc = {0}; - resource_data.pSysMem = params->data; - resource_data.SysMemPitch = params->width * params->texel_size; - resource_data.SysMemSlicePitch = params->height * resource_data.SysMemPitch; + desc.Width = params->width; + desc.Height = params->height; + desc.MipLevels = 1; + desc.ArraySize = 1; + desc.Format = params->format; + desc.SampleDesc.Count = 1; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - hr = ID3D11Device_CreateTexture2D(device, &desc, &resource_data, &texture->texture); - ok(hr == S_OK, "Failed to create texture, hr %#lx.\n", hr); - hr = ID3D11Device_CreateShaderResourceView(device, - (ID3D11Resource *)texture->texture, NULL, &texture->srv); - ok(hr == S_OK, "Failed to create shader resource view, hr %#lx.\n", hr); + resource_data.pSysMem = params->data; + resource_data.SysMemPitch = params->width * params->texel_size; + resource_data.SysMemSlicePitch = params->height * resource_data.SysMemPitch; - return &texture->t; + hr = ID3D11Device_CreateTexture2D(device, &desc, &resource_data, &resource->texture); + ok(hr == S_OK, "Failed to create texture, hr %#lx.\n", hr); + hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)resource->texture, NULL, &resource->srv); + ok(hr == S_OK, "Failed to create shader resource view, hr %#lx.\n", hr); + break; + } + } + + return &resource->r; } -static void d3d11_runner_destroy_texture(struct shader_runner *r, struct texture *t) +static void d3d11_runner_destroy_resource(struct shader_runner *r, struct resource *res) { - struct d3d11_texture *texture = d3d11_texture(t); + struct d3d11_resource *resource = d3d11_resource(res); - ID3D11Texture2D_Release(texture->texture); - ID3D11ShaderResourceView_Release(texture->srv); - free(texture); + ID3D11Texture2D_Release(resource->texture); + ID3D11ShaderResourceView_Release(resource->srv); + free(resource); } static void d3d11_runner_draw_quad(struct shader_runner *r) @@ -445,11 +453,16 @@ static void d3d11_runner_draw_quad(struct shader_runner *r) ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb); } - for (i = 0; i < runner->r.texture_count; ++i) + for (i = 0; i < runner->r.resource_count; ++i) { - struct d3d11_texture *texture = d3d11_texture(runner->r.textures[i]); + struct d3d11_resource *resource = d3d11_resource(runner->r.resources[i]); - ID3D11DeviceContext_PSSetShaderResources(context, texture->t.slot, 1, &texture->srv); + switch (resource->r.type) + { + case RESOURCE_TYPE_TEXTURE: + ID3D11DeviceContext_PSSetShaderResources(context, resource->r.slot, 1, &resource->srv); + break; + } } for (i = 0; i < runner->r.sampler_count; ++i) @@ -583,8 +596,8 @@ static void d3d11_runner_probe_vec4(struct shader_runner *r, const RECT *rect, c static const struct shader_runner_ops d3d11_runner_ops = { - .create_texture = d3d11_runner_create_texture, - .destroy_texture = d3d11_runner_destroy_texture, + .create_resource = d3d11_runner_create_resource, + .destroy_resource = d3d11_runner_destroy_resource, .draw_quad = d3d11_runner_draw_quad, .probe_vec4 = d3d11_runner_probe_vec4, }; diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index e442d16e..1d38ee90 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -24,18 +24,18 @@ #include "d3d12_crosstest.h" #include "shader_runner.h" -struct d3d12_texture +struct d3d12_resource { - struct texture t; + struct resource r; D3D12_DESCRIPTOR_RANGE descriptor_range; ID3D12Resource *resource; unsigned int root_index; }; -static struct d3d12_texture *d3d12_texture(struct texture *t) +static struct d3d12_resource *d3d12_resource(struct resource *r) { - return CONTAINING_RECORD(t, struct d3d12_texture, t); + return CONTAINING_RECORD(r, struct d3d12_resource, r); } struct d3d12_shader_runner @@ -81,45 +81,50 @@ static ID3D10Blob *compile_shader(const char *source, const char *type, enum sha #define MAX_RESOURCE_DESCRIPTORS 256 -static struct texture *d3d12_runner_create_texture(struct shader_runner *r, const struct texture_params *params) +static struct resource *d3d12_runner_create_resource(struct shader_runner *r, const struct resource_params *params) { struct d3d12_shader_runner *runner = d3d12_shader_runner(r); struct test_context *test_context = &runner->test_context; ID3D12Device *device = test_context->device; D3D12_SUBRESOURCE_DATA resource_data; - struct d3d12_texture *texture; + struct d3d12_resource *resource; - if (!runner->heap) - runner->heap = create_gpu_descriptor_heap(device, - D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, MAX_RESOURCE_DESCRIPTORS); + resource = calloc(1, sizeof(*resource)); + resource->r.slot = params->slot; + resource->r.type = params->type; - if (params->slot >= MAX_RESOURCE_DESCRIPTORS) - fatal_error("Resource slot %u is too high; please increase MAX_RESOURCE_DESCRIPTORS.\n", params->slot); + switch (params->type) + { + case RESOURCE_TYPE_TEXTURE: + if (!runner->heap) + runner->heap = create_gpu_descriptor_heap(device, + D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, MAX_RESOURCE_DESCRIPTORS); - texture = calloc(1, sizeof(*texture)); + if (params->slot >= MAX_RESOURCE_DESCRIPTORS) + fatal_error("Resource slot %u is too high; please increase MAX_RESOURCE_DESCRIPTORS.\n", params->slot); - texture->t.slot = params->slot; + resource->resource = create_default_texture(device, params->width, params->height, + params->format, 0, D3D12_RESOURCE_STATE_COPY_DEST); + resource_data.pData = params->data; + resource_data.SlicePitch = resource_data.RowPitch = params->width * params->texel_size; + upload_texture_data(resource->resource, &resource_data, 1, test_context->queue, test_context->list); + reset_command_list(test_context->list, test_context->allocator); + transition_resource_state(test_context->list, resource->resource, D3D12_RESOURCE_STATE_COPY_DEST, + D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); + ID3D12Device_CreateShaderResourceView(device, resource->resource, + NULL, get_cpu_descriptor_handle(test_context, runner->heap, resource->r.slot)); + break; + } - texture->resource = create_default_texture(device, params->width, params->height, - params->format, 0, D3D12_RESOURCE_STATE_COPY_DEST); - resource_data.pData = params->data; - resource_data.SlicePitch = resource_data.RowPitch = params->width * params->texel_size; - upload_texture_data(texture->resource, &resource_data, 1, test_context->queue, test_context->list); - reset_command_list(test_context->list, test_context->allocator); - transition_resource_state(test_context->list, texture->resource, D3D12_RESOURCE_STATE_COPY_DEST, - D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); - ID3D12Device_CreateShaderResourceView(device, texture->resource, - NULL, get_cpu_descriptor_handle(test_context, runner->heap, params->slot)); - - return &texture->t; + return &resource->r; } -static void d3d12_runner_destroy_texture(struct shader_runner *r, struct texture *t) +static void d3d12_runner_destroy_resource(struct shader_runner *r, struct resource *res) { - struct d3d12_texture *texture = d3d12_texture(t); + struct d3d12_resource *resource = d3d12_resource(res); - ID3D12Resource_Release(texture->resource); - free(texture); + ID3D12Resource_Release(resource->resource); + free(resource); } static void d3d12_runner_draw_quad(struct shader_runner *r) @@ -169,25 +174,30 @@ static void d3d12_runner_draw_quad(struct shader_runner *r) root_param->ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; } - for (i = 0; i < runner->r.texture_count; ++i) + for (i = 0; i < runner->r.resource_count; ++i) { - struct d3d12_texture *texture = d3d12_texture(runner->r.textures[i]); + struct d3d12_resource *resource = d3d12_resource(runner->r.resources[i]); D3D12_DESCRIPTOR_RANGE *range; - range = &texture->descriptor_range; + switch (resource->r.type) + { + case RESOURCE_TYPE_TEXTURE: + range = &resource->descriptor_range; - texture->root_index = root_signature_desc.NumParameters++; - root_param = &root_params[texture->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; + 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; - range->RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV; - range->NumDescriptors = 1; - range->BaseShaderRegister = texture->t.slot; - range->RegisterSpace = 0; - range->OffsetInDescriptorsFromTableStart = 0; + range->RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV; + range->NumDescriptors = 1; + range->BaseShaderRegister = resource->r.slot; + range->RegisterSpace = 0; + range->OffsetInDescriptorsFromTableStart = 0; + break; + } } assert(root_signature_desc.NumParameters <= ARRAY_SIZE(root_params)); @@ -248,12 +258,17 @@ static void d3d12_runner_draw_quad(struct shader_runner *r) if (runner->r.uniform_count) ID3D12GraphicsCommandList_SetGraphicsRoot32BitConstants(command_list, uniform_index, runner->r.uniform_count, runner->r.uniforms, 0); - for (i = 0; i < runner->r.texture_count; ++i) + for (i = 0; i < runner->r.resource_count; ++i) { - struct d3d12_texture *texture = d3d12_texture(runner->r.textures[i]); + struct d3d12_resource *resource = d3d12_resource(runner->r.resources[i]); - ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list, texture->root_index, - get_gpu_descriptor_handle(test_context, runner->heap, texture->t.slot)); + switch (resource->r.type) + { + case RESOURCE_TYPE_TEXTURE: + ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list, resource->root_index, + get_gpu_descriptor_handle(test_context, runner->heap, resource->r.slot)); + break; + } } ID3D12GraphicsCommandList_OMSetRenderTargets(command_list, 1, &test_context->rtv, false, NULL); @@ -290,8 +305,8 @@ static void d3d12_runner_probe_vec4(struct shader_runner *r, static const struct shader_runner_ops d3d12_runner_ops = { - .create_texture = d3d12_runner_create_texture, - .destroy_texture = d3d12_runner_destroy_texture, + .create_resource = d3d12_runner_create_resource, + .destroy_resource = d3d12_runner_destroy_resource, .draw_quad = d3d12_runner_draw_quad, .probe_vec4 = d3d12_runner_probe_vec4, };