From b9d7569b8cdba8b5a01cfabe58a284eb9c3babae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Thu, 13 Sep 2018 11:26:01 +0200 Subject: [PATCH] vkd3d: Partially implement clears for texture UAVs. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the long term, we may want to use shaders to clear UAVs. Signed-off-by: Józef Kucia Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- libs/vkd3d/command.c | 41 +++++++++++++++++++++++++++----------- libs/vkd3d/resource.c | 8 ++++++-- libs/vkd3d/vkd3d_private.h | 16 +++++++++++++-- 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 5e67e667..decff143 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -3881,6 +3881,8 @@ static void STDMETHODCALLTYPE d3d12_command_list_ClearUnorderedAccessViewUint(ID const struct vkd3d_vk_device_procs *vk_procs; const struct d3d12_desc *cpu_descriptor; struct d3d12_resource *resource_impl; + VkImageSubresourceRange range; + VkClearColorValue color; TRACE("iface %p, gpu_handle %#"PRIx64", cpu_handle %lx, resource %p, values %p, rect_count %u, rects %p.\n", iface, gpu_handle.ptr, cpu_handle.ptr, resource, values, rect_count, rects); @@ -3891,11 +3893,6 @@ static void STDMETHODCALLTYPE d3d12_command_list_ClearUnorderedAccessViewUint(ID d3d12_command_list_track_resource_usage(list, resource_impl); - if (d3d12_resource_is_texture(resource_impl)) - { - FIXME("Not implemented for textures.\n"); - return; - } if (rect_count) { FIXME("Clear rects not supported.\n"); @@ -3905,14 +3902,34 @@ static void STDMETHODCALLTYPE d3d12_command_list_ClearUnorderedAccessViewUint(ID d3d12_command_list_end_current_render_pass(list); cpu_descriptor = d3d12_desc_from_cpu_handle(cpu_handle); - if (!cpu_descriptor->view_size) - { - FIXME("Not supported for UAV descriptor %p.\n", cpu_descriptor); - return; - } - VK_CALL(vkCmdFillBuffer(list->vk_command_buffer, resource_impl->u.vk_buffer, - cpu_descriptor->view_offset, cpu_descriptor->view_size, values[0])); + if (d3d12_resource_is_buffer(resource_impl)) + { + if (!cpu_descriptor->uav.buffer.size) + { + FIXME("Not supported for UAV descriptor %p.\n", cpu_descriptor); + return; + } + + VK_CALL(vkCmdFillBuffer(list->vk_command_buffer, resource_impl->u.vk_buffer, + cpu_descriptor->uav.buffer.offset, cpu_descriptor->uav.buffer.size, values[0])); + } + else + { + color.uint32[0] = values[0]; + color.uint32[1] = values[1]; + color.uint32[2] = values[2]; + color.uint32[3] = values[3]; + + range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + range.baseMipLevel = cpu_descriptor->uav.texture.miplevel_idx; + range.levelCount = 1; + range.baseArrayLayer = cpu_descriptor->uav.texture.layer_idx; + range.layerCount = cpu_descriptor->uav.texture.layer_count; + + VK_CALL(vkCmdClearColorImage(list->vk_command_buffer, + resource_impl->u.vk_image, VK_IMAGE_LAYOUT_GENERAL, &color, 1, &range)); + } } static void STDMETHODCALLTYPE d3d12_command_list_ClearUnorderedAccessViewFloat(ID3D12GraphicsCommandList *iface, diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index 88ab6455..4490ae23 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -1635,8 +1635,8 @@ static void vkd3d_create_buffer_uav(struct d3d12_desc *descriptor, struct d3d12_ { const struct vkd3d_format *format = vkd3d_get_format(DXGI_FORMAT_R32_UINT, false); - descriptor->view_offset = desc->u.Buffer.FirstElement * format->byte_count; - descriptor->view_size = desc->u.Buffer.NumElements * format->byte_count; + descriptor->uav.buffer.offset = desc->u.Buffer.FirstElement * format->byte_count; + descriptor->uav.buffer.size = desc->u.Buffer.NumElements * format->byte_count; } } @@ -1691,6 +1691,10 @@ static void vkd3d_create_texture_uav(struct d3d12_desc *descriptor, descriptor->magic = VKD3D_DESCRIPTOR_MAGIC_UAV; descriptor->vk_descriptor_type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; descriptor->u.view = view; + + descriptor->uav.texture.miplevel_idx = vkd3d_desc.miplevel_idx; + descriptor->uav.texture.layer_idx = vkd3d_desc.layer_idx; + descriptor->uav.texture.layer_count = vkd3d_desc.layer_count; } void d3d12_desc_create_uav(struct d3d12_desc *descriptor, struct d3d12_device *device, diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 5461cc3d..6ba12f9c 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -272,8 +272,20 @@ struct d3d12_desc struct vkd3d_view *view; } u; - VkDeviceSize view_offset; - VkDeviceSize view_size; + union + { + struct + { + VkDeviceSize offset; + VkDeviceSize size; + } buffer; + struct + { + unsigned int miplevel_idx; + unsigned int layer_idx; + unsigned int layer_count; + } texture; + } uav; }; static inline struct d3d12_desc *d3d12_desc_from_cpu_handle(D3D12_CPU_DESCRIPTOR_HANDLE cpu_handle)