From: Józef Kucia jkucia@codeweavers.com
In the long term, we may want to use shaders to clear UAVs.
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- libs/vkd3d/command.c | 37 +++++++++++++++++++++++++++---------- libs/vkd3d/resource.c | 8 ++++++-- libs/vkd3d/vkd3d_private.h | 16 ++++++++++++++-- 3 files changed, 47 insertions(+), 14 deletions(-)
diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 5e67e6674e95..decff143d0a3 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) + + if (d3d12_resource_is_buffer(resource_impl)) { - FIXME("Not supported for UAV descriptor %p.\n", cpu_descriptor); - return; + 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(vkCmdFillBuffer(list->vk_command_buffer, resource_impl->u.vk_buffer, - cpu_descriptor->view_offset, cpu_descriptor->view_size, values[0])); + 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 88ab64552bb5..4490ae23dab9 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 5461cc3d36e1..6ba12f9ca1d2 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)