tests: Make the "texture" structure more generic.

Use it to hold any type of resource, regardless of type and binding.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2022-03-21 20:42:17 -05:00 committed by Alexandre Julliard
parent 3ed4c6fe23
commit f11f7032cd
4 changed files with 154 additions and 118 deletions

View File

@ -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, &current_texture));
free(current_texture.data);
set_resource(runner, runner->ops->create_resource(runner, &current_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(&current_texture, 0, sizeof(current_texture));
memset(&current_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(&current_texture, line);
parse_resource_directive(&current_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);

View File

@ -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);
};

View File

@ -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,18 +365,24 @@ 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;
switch (params->type)
{
case RESOURCE_TYPE_TEXTURE:
{
D3D11_TEXTURE2D_DESC desc = {0};
desc.Width = params->width;
desc.Height = params->height;
@ -391,22 +397,24 @@ static struct texture *d3d11_runner_create_texture(struct shader_runner *r, cons
resource_data.SysMemPitch = params->width * params->texel_size;
resource_data.SysMemSlicePitch = params->height * resource_data.SysMemPitch;
hr = ID3D11Device_CreateTexture2D(device, &desc, &resource_data, &texture->texture);
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 *)texture->texture, NULL, &texture->srv);
hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)resource->texture, NULL, &resource->srv);
ok(hr == S_OK, "Failed to create shader resource view, hr %#lx.\n", hr);
return &texture->t;
break;
}
}
static void d3d11_runner_destroy_texture(struct shader_runner *r, struct texture *t)
{
struct d3d11_texture *texture = d3d11_texture(t);
return &resource->r;
}
ID3D11Texture2D_Release(texture->texture);
ID3D11ShaderResourceView_Release(texture->srv);
free(texture);
static void d3d11_runner_destroy_resource(struct shader_runner *r, struct resource *res)
{
struct d3d11_resource *resource = d3d11_resource(res);
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,
};

View File

@ -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,14 +81,21 @@ 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;
resource = calloc(1, sizeof(*resource));
resource->r.slot = params->slot;
resource->r.type = params->type;
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);
@ -96,30 +103,28 @@ static struct texture *d3d12_runner_create_texture(struct shader_runner *r, cons
if (params->slot >= MAX_RESOURCE_DESCRIPTORS)
fatal_error("Resource slot %u is too high; please increase MAX_RESOURCE_DESCRIPTORS.\n", params->slot);
texture = calloc(1, sizeof(*texture));
texture->t.slot = params->slot;
texture->resource = create_default_texture(device, params->width, params->height,
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(texture->resource, &resource_data, 1, test_context->queue, test_context->list);
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, texture->resource, D3D12_RESOURCE_STATE_COPY_DEST,
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, texture->resource,
NULL, get_cpu_descriptor_handle(test_context, runner->heap, params->slot));
return &texture->t;
ID3D12Device_CreateShaderResourceView(device, resource->resource,
NULL, get_cpu_descriptor_handle(test_context, runner->heap, resource->r.slot));
break;
}
static void d3d12_runner_destroy_texture(struct shader_runner *r, struct texture *t)
{
struct d3d12_texture *texture = d3d12_texture(t);
return &resource->r;
}
ID3D12Resource_Release(texture->resource);
free(texture);
static void d3d12_runner_destroy_resource(struct shader_runner *r, struct resource *res)
{
struct d3d12_resource *resource = d3d12_resource(res);
ID3D12Resource_Release(resource->resource);
free(resource);
}
static void d3d12_runner_draw_quad(struct shader_runner *r)
@ -169,15 +174,18 @@ 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];
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;
@ -185,9 +193,11 @@ static void d3d12_runner_draw_quad(struct shader_runner *r)
range->RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
range->NumDescriptors = 1;
range->BaseShaderRegister = texture->t.slot;
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,
};