mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
tests: Add support for UAV buffers in Vulkan runner.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
parent
cf8cacd336
commit
a4ebde202a
Notes:
Alexandre Julliard
2023-05-22 23:19:48 +02:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Zebediah Figura (@zfigura) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/193
@ -567,6 +567,16 @@ static void parse_test_directive(struct shader_runner *runner, const char *line)
|
||||
|
||||
resource = get_resource(runner, RESOURCE_TYPE_UAV, slot);
|
||||
}
|
||||
else if (match_string(line, "buffer uav", &line))
|
||||
{
|
||||
slot = strtoul(line, &rest, 10);
|
||||
|
||||
if (rest == line)
|
||||
fatal_error("Malformed buffer UAV index '%s'.\n", line);
|
||||
line = rest;
|
||||
|
||||
resource = get_resource(runner, RESOURCE_TYPE_BUFFER_UAV, slot);
|
||||
}
|
||||
else if (match_string(line, "render target", &line))
|
||||
{
|
||||
slot = strtoul(line, &rest, 10);
|
||||
@ -1035,6 +1045,19 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_o
|
||||
current_resource.texel_size = 16;
|
||||
current_resource.level_count = 1;
|
||||
}
|
||||
else if (sscanf(line, "[buffer uav %u]\n", &index))
|
||||
{
|
||||
state = STATE_RESOURCE;
|
||||
|
||||
memset(¤t_resource, 0, sizeof(current_resource));
|
||||
|
||||
current_resource.slot = index;
|
||||
current_resource.type = RESOURCE_TYPE_BUFFER_UAV;
|
||||
current_resource.format = DXGI_FORMAT_R32G32B32A32_FLOAT;
|
||||
current_resource.data_type = TEXTURE_DATA_FLOAT;
|
||||
current_resource.texel_size = 16;
|
||||
current_resource.level_count = 1;
|
||||
}
|
||||
else if (sscanf(line, "[vertex buffer %u]\n", &index))
|
||||
{
|
||||
state = STATE_RESOURCE;
|
||||
|
@ -58,6 +58,7 @@ enum resource_type
|
||||
RESOURCE_TYPE_RENDER_TARGET,
|
||||
RESOURCE_TYPE_TEXTURE,
|
||||
RESOURCE_TYPE_UAV,
|
||||
RESOURCE_TYPE_BUFFER_UAV,
|
||||
RESOURCE_TYPE_VERTEX_BUFFER,
|
||||
};
|
||||
|
||||
|
@ -350,6 +350,7 @@ static struct resource *d3d11_runner_create_resource(struct shader_runner *r, co
|
||||
case RESOURCE_TYPE_RENDER_TARGET:
|
||||
case RESOURCE_TYPE_TEXTURE:
|
||||
case RESOURCE_TYPE_UAV:
|
||||
case RESOURCE_TYPE_BUFFER_UAV:
|
||||
{
|
||||
D3D11_SUBRESOURCE_DATA resource_data[2];
|
||||
D3D11_TEXTURE2D_DESC desc = {0};
|
||||
@ -364,7 +365,7 @@ static struct resource *d3d11_runner_create_resource(struct shader_runner *r, co
|
||||
desc.Format = params->format;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
if (params->type == RESOURCE_TYPE_UAV)
|
||||
if (params->type == RESOURCE_TYPE_UAV || params->type == RESOURCE_TYPE_BUFFER_UAV)
|
||||
desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
|
||||
else if (params->type == RESOURCE_TYPE_RENDER_TARGET)
|
||||
desc.BindFlags = D3D11_BIND_RENDER_TARGET;
|
||||
@ -394,7 +395,7 @@ static struct resource *d3d11_runner_create_resource(struct shader_runner *r, co
|
||||
ok(hr == S_OK, "Failed to create texture, hr %#lx.\n", hr);
|
||||
|
||||
resource->resource = (ID3D11Resource *)resource->texture;
|
||||
if (params->type == RESOURCE_TYPE_UAV)
|
||||
if (params->type == RESOURCE_TYPE_UAV || params->type == RESOURCE_TYPE_BUFFER_UAV)
|
||||
hr = ID3D11Device_CreateUnorderedAccessView(device, resource->resource, NULL, &resource->uav);
|
||||
else if (params->type == RESOURCE_TYPE_RENDER_TARGET)
|
||||
hr = ID3D11Device_CreateRenderTargetView(device, resource->resource, NULL, &resource->rtv);
|
||||
@ -485,6 +486,7 @@ static bool d3d11_runner_dispatch(struct shader_runner *r, unsigned int x, unsig
|
||||
break;
|
||||
|
||||
case RESOURCE_TYPE_UAV:
|
||||
case RESOURCE_TYPE_BUFFER_UAV:
|
||||
ID3D11DeviceContext_CSSetUnorderedAccessViews(context, resource->r.slot, 1, &resource->uav, NULL);
|
||||
break;
|
||||
|
||||
@ -571,6 +573,7 @@ static bool d3d11_runner_draw(struct shader_runner *r,
|
||||
break;
|
||||
|
||||
case RESOURCE_TYPE_UAV:
|
||||
case RESOURCE_TYPE_BUFFER_UAV:
|
||||
uavs[resource->r.slot] = resource->uav;
|
||||
min_uav_slot = min(min_uav_slot, resource->r.slot);
|
||||
break;
|
||||
|
@ -145,6 +145,7 @@ static struct resource *d3d12_runner_create_resource(struct shader_runner *r, co
|
||||
break;
|
||||
|
||||
case RESOURCE_TYPE_UAV:
|
||||
case RESOURCE_TYPE_BUFFER_UAV:
|
||||
if (!runner->heap)
|
||||
runner->heap = create_gpu_descriptor_heap(device,
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, MAX_RESOURCE_DESCRIPTORS);
|
||||
@ -213,6 +214,7 @@ static ID3D12RootSignature *d3d12_runner_create_root_signature(struct d3d12_shad
|
||||
{
|
||||
case RESOURCE_TYPE_TEXTURE:
|
||||
case RESOURCE_TYPE_UAV:
|
||||
case RESOURCE_TYPE_BUFFER_UAV:
|
||||
range = &resource->descriptor_range;
|
||||
|
||||
resource->root_index = root_signature_desc.NumParameters++;
|
||||
@ -314,6 +316,7 @@ static bool d3d12_runner_dispatch(struct shader_runner *r, unsigned int x, unsig
|
||||
break;
|
||||
|
||||
case RESOURCE_TYPE_UAV:
|
||||
case RESOURCE_TYPE_BUFFER_UAV:
|
||||
ID3D12GraphicsCommandList_SetComputeRootDescriptorTable(command_list, resource->root_index,
|
||||
get_gpu_descriptor_handle(test_context, runner->heap, resource->r.slot + MAX_RESOURCES));
|
||||
break;
|
||||
@ -447,6 +450,7 @@ static bool d3d12_runner_draw(struct shader_runner *r,
|
||||
break;
|
||||
|
||||
case RESOURCE_TYPE_UAV:
|
||||
case RESOURCE_TYPE_BUFFER_UAV:
|
||||
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list, resource->root_index,
|
||||
get_gpu_descriptor_handle(test_context, runner->heap, resource->r.slot + MAX_RESOURCES));
|
||||
break;
|
||||
|
@ -258,6 +258,7 @@ static struct resource *d3d9_runner_create_resource(struct shader_runner *r, con
|
||||
}
|
||||
|
||||
case RESOURCE_TYPE_UAV:
|
||||
case RESOURCE_TYPE_BUFFER_UAV:
|
||||
fatal_error("UAVs are not supported.\n");
|
||||
break;
|
||||
|
||||
@ -383,6 +384,7 @@ static bool d3d9_runner_draw(struct shader_runner *r,
|
||||
break;
|
||||
|
||||
case RESOURCE_TYPE_UAV:
|
||||
case RESOURCE_TYPE_BUFFER_UAV:
|
||||
vkd3d_unreachable();
|
||||
|
||||
case RESOURCE_TYPE_VERTEX_BUFFER:
|
||||
|
@ -34,8 +34,9 @@ struct vulkan_resource
|
||||
struct resource r;
|
||||
|
||||
VkBuffer buffer;
|
||||
VkBufferView buffer_view;
|
||||
VkImage image;
|
||||
VkImageView view;
|
||||
VkImageView image_view;
|
||||
VkDeviceMemory memory;
|
||||
|
||||
uint32_t binding;
|
||||
@ -177,6 +178,21 @@ static VkBuffer create_buffer(const struct vulkan_shader_runner *runner, VkDevic
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static VkBufferView create_buffer_view(const struct vulkan_shader_runner *runner, VkBuffer buffer,
|
||||
VkFormat format)
|
||||
{
|
||||
VkBufferViewCreateInfo view_info = {.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO};
|
||||
VkBufferView view;
|
||||
|
||||
view_info.buffer = buffer;
|
||||
view_info.format = format;
|
||||
view_info.range = VK_WHOLE_SIZE;
|
||||
|
||||
VK_CALL(vkCreateBufferView(runner->device, &view_info, NULL, &view));
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
static VkImage create_2d_image(const struct vulkan_shader_runner *runner, uint32_t width, uint32_t height,
|
||||
uint32_t level_count, VkImageUsageFlags usage, VkFormat format, VkDeviceMemory *memory)
|
||||
{
|
||||
@ -249,7 +265,7 @@ static struct resource *vulkan_runner_create_resource(struct shader_runner *r, c
|
||||
|
||||
resource->image = create_2d_image(runner, params->width, params->height, params->level_count,
|
||||
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, format, &resource->memory);
|
||||
resource->view = create_2d_image_view(runner, resource->image, format);
|
||||
resource->image_view = create_2d_image_view(runner, resource->image, format);
|
||||
|
||||
begin_command_buffer(runner);
|
||||
transition_image_layout(runner, resource->image,
|
||||
@ -274,7 +290,7 @@ static struct resource *vulkan_runner_create_resource(struct shader_runner *r, c
|
||||
|
||||
resource->image = create_2d_image(runner, params->width, params->height, params->level_count,
|
||||
usage, format, &resource->memory);
|
||||
resource->view = create_2d_image_view(runner, resource->image, format);
|
||||
resource->image_view = create_2d_image_view(runner, resource->image, format);
|
||||
|
||||
staging_buffer = create_buffer(runner, params->data_size,
|
||||
VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &staging_memory);
|
||||
@ -315,6 +331,18 @@ static struct resource *vulkan_runner_create_resource(struct shader_runner *r, c
|
||||
break;
|
||||
}
|
||||
|
||||
case RESOURCE_TYPE_BUFFER_UAV:
|
||||
format = vkd3d_get_vk_format(params->format);
|
||||
|
||||
resource->buffer = create_buffer(runner, params->data_size, VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &resource->memory);
|
||||
resource->buffer_view = create_buffer_view(runner, resource->buffer, format);
|
||||
|
||||
VK_CALL(vkMapMemory(device, resource->memory, 0, VK_WHOLE_SIZE, 0, &data));
|
||||
memcpy(data, params->data, params->data_size);
|
||||
VK_CALL(vkUnmapMemory(device, resource->memory));
|
||||
break;
|
||||
|
||||
case RESOURCE_TYPE_VERTEX_BUFFER:
|
||||
resource->buffer = create_buffer(runner, params->data_size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &resource->memory);
|
||||
@ -338,10 +366,12 @@ static void vulkan_runner_destroy_resource(struct shader_runner *r, struct resou
|
||||
VK_CALL(vkFreeMemory(device, resource->memory, NULL));
|
||||
if (resource->image)
|
||||
VK_CALL(vkDestroyImage(device, resource->image, NULL));
|
||||
if (resource->view)
|
||||
VK_CALL(vkDestroyImageView(device, resource->view, NULL));
|
||||
if (resource->image_view)
|
||||
VK_CALL(vkDestroyImageView(device, resource->image_view, NULL));
|
||||
if (resource->buffer)
|
||||
VK_CALL(vkDestroyBuffer(device, resource->buffer, NULL));
|
||||
if (resource->buffer_view)
|
||||
VK_CALL(vkDestroyBufferView(device, resource->buffer_view, NULL));
|
||||
|
||||
free(resource);
|
||||
}
|
||||
@ -415,14 +445,18 @@ static bool compile_shader(const struct vulkan_shader_runner *runner, const char
|
||||
|
||||
case RESOURCE_TYPE_TEXTURE:
|
||||
case RESOURCE_TYPE_UAV:
|
||||
case RESOURCE_TYPE_BUFFER_UAV:
|
||||
binding = &bindings[interface_info.binding_count++];
|
||||
if (resource->r.type == RESOURCE_TYPE_UAV)
|
||||
if (resource->r.type == RESOURCE_TYPE_UAV || resource->r.type == RESOURCE_TYPE_BUFFER_UAV)
|
||||
binding->type = VKD3D_SHADER_DESCRIPTOR_TYPE_UAV;
|
||||
else
|
||||
binding->type = VKD3D_SHADER_DESCRIPTOR_TYPE_SRV;
|
||||
binding->register_space = 0;
|
||||
binding->register_index = resource->r.slot;
|
||||
binding->shader_visibility = VKD3D_SHADER_VISIBILITY_ALL;
|
||||
if (resource->r.type == RESOURCE_TYPE_BUFFER_UAV)
|
||||
binding->flags = VKD3D_SHADER_BINDING_FLAG_BUFFER;
|
||||
else
|
||||
binding->flags = VKD3D_SHADER_BINDING_FLAG_IMAGE;
|
||||
binding->binding.set = 0;
|
||||
binding->binding.binding = resource->binding;
|
||||
@ -596,6 +630,7 @@ static VkPipeline create_graphics_pipeline(const struct vulkan_shader_runner *ru
|
||||
{
|
||||
case RESOURCE_TYPE_TEXTURE:
|
||||
case RESOURCE_TYPE_UAV:
|
||||
case RESOURCE_TYPE_BUFFER_UAV:
|
||||
break;
|
||||
|
||||
case RESOURCE_TYPE_RENDER_TARGET:
|
||||
@ -724,6 +759,7 @@ static VkDescriptorSetLayout create_descriptor_set_layout(struct vulkan_shader_r
|
||||
|
||||
case RESOURCE_TYPE_TEXTURE:
|
||||
case RESOURCE_TYPE_UAV:
|
||||
case RESOURCE_TYPE_BUFFER_UAV:
|
||||
binding = &bindings[set_desc.bindingCount++];
|
||||
|
||||
resource->binding = binding_index++;
|
||||
@ -731,6 +767,8 @@ static VkDescriptorSetLayout create_descriptor_set_layout(struct vulkan_shader_r
|
||||
binding->binding = resource->binding;
|
||||
if (resource->r.type == RESOURCE_TYPE_UAV)
|
||||
binding->descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
|
||||
else if (resource->r.type == RESOURCE_TYPE_BUFFER_UAV)
|
||||
binding->descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
|
||||
else
|
||||
binding->descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
|
||||
binding->descriptorCount = 1;
|
||||
@ -796,7 +834,7 @@ static void bind_resources(struct vulkan_shader_runner *runner, VkPipelineBindPo
|
||||
{
|
||||
case RESOURCE_TYPE_TEXTURE:
|
||||
case RESOURCE_TYPE_UAV:
|
||||
image_info.imageView = resource->view;
|
||||
image_info.imageView = resource->image_view;
|
||||
image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||
|
||||
write.dstSet = descriptor_set;
|
||||
@ -815,6 +853,17 @@ static void bind_resources(struct vulkan_shader_runner *runner, VkPipelineBindPo
|
||||
VK_CALL(vkUpdateDescriptorSets(runner->device, 1, &write, 0, NULL));
|
||||
break;
|
||||
|
||||
case RESOURCE_TYPE_BUFFER_UAV:
|
||||
write.dstSet = descriptor_set;
|
||||
write.dstBinding = resource->binding;
|
||||
write.dstArrayElement = 0;
|
||||
write.descriptorCount = 1;
|
||||
write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
|
||||
write.pTexelBufferView = &resource->buffer_view;
|
||||
|
||||
VK_CALL(vkUpdateDescriptorSets(runner->device, 1, &write, 0, NULL));
|
||||
break;
|
||||
|
||||
case RESOURCE_TYPE_VERTEX_BUFFER:
|
||||
if (bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS)
|
||||
VK_CALL(vkCmdBindVertexBuffers(cmd_buffer, resource->r.slot, 1, &resource->buffer, &zero_offset));
|
||||
@ -867,7 +916,7 @@ static void create_render_pass_and_framebuffer(struct vulkan_shader_runner *runn
|
||||
color_ref->attachment = rt_count;
|
||||
color_ref->layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
|
||||
rtvs[rt_count] = resource->view;
|
||||
rtvs[rt_count] = resource->image_view;
|
||||
|
||||
++rt_count;
|
||||
}
|
||||
@ -1011,11 +1060,6 @@ static struct resource_readback *vulkan_runner_get_resource_readback(struct shad
|
||||
VkBufferImageCopy region = {0};
|
||||
VkImageLayout layout;
|
||||
|
||||
if (resource->r.type == RESOURCE_TYPE_RENDER_TARGET)
|
||||
layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
else
|
||||
layout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
|
||||
rb->rb.width = resource->r.width;
|
||||
rb->rb.height = resource->r.height;
|
||||
rb->rb.depth = 1;
|
||||
@ -1025,6 +1069,22 @@ static struct resource_readback *vulkan_runner_get_resource_readback(struct shad
|
||||
rb->buffer = create_buffer(runner, rb->rb.row_pitch * rb->rb.height,
|
||||
VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &rb->memory);
|
||||
|
||||
if (resource->r.type == RESOURCE_TYPE_BUFFER_UAV)
|
||||
{
|
||||
void *data;
|
||||
|
||||
VK_CALL(vkMapMemory(device, resource->memory, 0, VK_WHOLE_SIZE, 0, &data));
|
||||
VK_CALL(vkMapMemory(device, rb->memory, 0, VK_WHOLE_SIZE, 0, &rb->rb.data));
|
||||
memcpy(rb->rb.data, data, rb->rb.row_pitch * rb->rb.height);
|
||||
VK_CALL(vkUnmapMemory(device, resource->memory));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (resource->r.type == RESOURCE_TYPE_RENDER_TARGET)
|
||||
layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
else
|
||||
layout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
|
||||
begin_command_buffer(runner);
|
||||
|
||||
transition_image_layout(runner, resource->image, layout, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
@ -1043,6 +1103,8 @@ static struct resource_readback *vulkan_runner_get_resource_readback(struct shad
|
||||
end_command_buffer(runner);
|
||||
|
||||
VK_CALL(vkMapMemory(device, rb->memory, 0, VK_WHOLE_SIZE, 0, &rb->rb.data));
|
||||
}
|
||||
|
||||
return &rb->rb;
|
||||
}
|
||||
|
||||
@ -1141,7 +1203,7 @@ static bool init_vulkan_runner(struct vulkan_shader_runner *runner)
|
||||
VkInstanceCreateInfo instance_desc = {.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO};
|
||||
VkDeviceCreateInfo device_desc = {.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO};
|
||||
VkPhysicalDeviceFeatures ret_features, features;
|
||||
VkDescriptorPoolSize descriptor_pool_sizes[3];
|
||||
VkDescriptorPoolSize descriptor_pool_sizes[4];
|
||||
static const float queue_priority = 1.0f;
|
||||
VkFormatProperties format_props;
|
||||
uint32_t count, graphics_index;
|
||||
@ -1253,6 +1315,8 @@ static bool init_vulkan_runner(struct vulkan_shader_runner *runner)
|
||||
descriptor_pool_sizes[1].descriptorCount = MAX_SAMPLERS;
|
||||
descriptor_pool_sizes[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
|
||||
descriptor_pool_sizes[2].descriptorCount = MAX_RESOURCES;
|
||||
descriptor_pool_sizes[3].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
|
||||
descriptor_pool_sizes[3].descriptorCount = MAX_RESOURCES;
|
||||
|
||||
descriptor_pool_desc.maxSets = 1;
|
||||
descriptor_pool_desc.poolSizeCount = ARRAY_SIZE(descriptor_pool_sizes);
|
||||
|
@ -65,6 +65,7 @@ VK_DEVICE_PFN(vkCmdFillBuffer)
|
||||
VK_DEVICE_PFN(vkCmdPipelineBarrier)
|
||||
VK_DEVICE_PFN(vkCmdPushConstants)
|
||||
VK_DEVICE_PFN(vkCreateBuffer)
|
||||
VK_DEVICE_PFN(vkCreateBufferView)
|
||||
VK_DEVICE_PFN(vkCreateCommandPool)
|
||||
VK_DEVICE_PFN(vkCreateComputePipelines)
|
||||
VK_DEVICE_PFN(vkCreateDescriptorPool)
|
||||
@ -78,6 +79,7 @@ VK_DEVICE_PFN(vkCreateRenderPass)
|
||||
VK_DEVICE_PFN(vkCreateSampler)
|
||||
VK_DEVICE_PFN(vkCreateShaderModule)
|
||||
VK_DEVICE_PFN(vkDestroyBuffer)
|
||||
VK_DEVICE_PFN(vkDestroyBufferView)
|
||||
VK_DEVICE_PFN(vkDestroyCommandPool)
|
||||
VK_DEVICE_PFN(vkDestroyDescriptorPool)
|
||||
VK_DEVICE_PFN(vkDestroyDescriptorSetLayout)
|
||||
|
Loading…
Reference in New Issue
Block a user