Rémi Bernon : vkd3d: Introduce vkd3d_format_copy_data().

Alexandre Julliard julliard at winehq.org
Fri Oct 18 12:49:48 CDT 2019


Module: vkd3d
Branch: master
Commit: 7ec32ebfc59073b1f3df5b7a7a18bb51993a5efc
URL:    https://source.winehq.org/git/vkd3d.git/?a=commit;h=7ec32ebfc59073b1f3df5b7a7a18bb51993a5efc

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Fri Oct 18 17:46:55 2019 +0330

vkd3d: Introduce vkd3d_format_copy_data().

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 libs/vkd3d/resource.c      | 45 ++++++++++++++-------------------------------
 libs/vkd3d/utils.c         | 24 ++++++++++++++++++++++++
 libs/vkd3d/vkd3d_private.h |  4 ++++
 3 files changed, 42 insertions(+), 31 deletions(-)

diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c
index 27d6a02..db5e991 100644
--- a/libs/vkd3d/resource.c
+++ b/libs/vkd3d/resource.c
@@ -1306,11 +1306,8 @@ static HRESULT STDMETHODCALLTYPE d3d12_resource_WriteToSubresource(ID3D12Resourc
     const struct vkd3d_format *format;
     VkSubresourceLayout vk_layout;
     struct d3d12_device *device;
-    BYTE *dst_data, *dst;
-    BYTE const *src;
-    unsigned int y, z;
+    uint8_t *dst_data;
     D3D12_BOX box;
-    size_t size;
     HRESULT hr;
 
     TRACE("iface %p, src_data %p, src_row_pitch %u, src_slice_pitch %u, "
@@ -1381,18 +1378,12 @@ static HRESULT STDMETHODCALLTYPE d3d12_resource_WriteToSubresource(ID3D12Resourc
 
     dst_data += vk_layout.offset;
     dst_data += dst_box->left / format->block_width * format->byte_count * format->block_byte_count;
-    size = (dst_box->right - dst_box->left) / format->block_width * format->byte_count * format->block_byte_count;
-    for (z = dst_box->front; z < dst_box->back; ++z)
-    {
-        src = (uint8_t *)src_data + (z - dst_box->front) * src_slice_pitch;
-        dst = dst_data + z * vk_layout.depthPitch + dst_box->top / format->block_height * vk_layout.rowPitch;
-        for (y = dst_box->top; y < dst_box->bottom; y += format->block_height)
-        {
-            memcpy(dst, src, size);
-            src += src_row_pitch;
-            dst += vk_layout.rowPitch;
-        }
-    }
+    dst_data += dst_box->top / format->block_height * vk_layout.rowPitch;
+    dst_data += dst_box->front * vk_layout.depthPitch;
+
+    vkd3d_format_copy_data(format, src_data, src_row_pitch, src_slice_pitch,
+            dst_data, vk_layout.rowPitch, vk_layout.depthPitch, dst_box->right - dst_box->left,
+            dst_box->bottom - dst_box->top, dst_box->back - dst_box->front);
 
     d3d12_heap_unmap(resource->heap, resource);
 
@@ -1409,10 +1400,8 @@ static HRESULT STDMETHODCALLTYPE d3d12_resource_ReadFromSubresource(ID3D12Resour
     const struct vkd3d_format *format;
     VkSubresourceLayout vk_layout;
     struct d3d12_device *device;
-    BYTE *src_data, *src, *dst;
-    unsigned int y, z;
+    uint8_t *src_data;
     D3D12_BOX box;
-    size_t size;
     HRESULT hr;
 
     TRACE("iface %p, dst_data %p, dst_row_pitch %u, dst_slice_pitch %u, "
@@ -1483,18 +1472,12 @@ static HRESULT STDMETHODCALLTYPE d3d12_resource_ReadFromSubresource(ID3D12Resour
 
     src_data += vk_layout.offset;
     src_data += src_box->left / format->block_width * format->byte_count * format->block_byte_count;
-    size = (src_box->right - src_box->left) / format->block_width * format->byte_count * format->block_byte_count;
-    for (z = src_box->front; z < src_box->back; ++z)
-    {
-        dst = (uint8_t *)dst_data + (z - src_box->front) * dst_slice_pitch;
-        src = src_data + z * vk_layout.depthPitch + src_box->top / format->block_height * vk_layout.rowPitch;
-        for (y = src_box->top; y < src_box->bottom; y += format->block_height)
-        {
-            memcpy(dst, src, size);
-            dst += dst_row_pitch;
-            src += vk_layout.rowPitch;
-        }
-    }
+    src_data += src_box->top / format->block_height * vk_layout.rowPitch;
+    src_data += src_box->front * vk_layout.depthPitch;
+
+    vkd3d_format_copy_data(format, src_data, vk_layout.rowPitch, vk_layout.depthPitch,
+            dst_data, dst_row_pitch, dst_slice_pitch, src_box->right - src_box->left,
+            src_box->bottom - src_box->top, src_box->back - src_box->front);
 
     d3d12_heap_unmap(resource->heap, resource);
 
diff --git a/libs/vkd3d/utils.c b/libs/vkd3d/utils.c
index 6a910a7..1fc0e9d 100644
--- a/libs/vkd3d/utils.c
+++ b/libs/vkd3d/utils.c
@@ -451,6 +451,30 @@ const struct vkd3d_format *vkd3d_get_format(const struct d3d12_device *device,
     return NULL;
 }
 
+void vkd3d_format_copy_data(const struct vkd3d_format *format, const uint8_t *src,
+        unsigned int src_row_pitch, unsigned int src_slice_pitch, uint8_t *dst, unsigned int dst_row_pitch,
+        unsigned int dst_slice_pitch, unsigned int w, unsigned int h, unsigned int d)
+{
+    unsigned int row_block_count, row_count, row_size, slice, row;
+    unsigned int slice_count = d;
+    const uint8_t *src_row;
+    uint8_t *dst_row;
+
+    row_block_count = (w + format->block_width - 1) / format->block_width;
+    row_count = (h + format->block_height - 1) / format->block_height;
+    row_size = row_block_count * format->byte_count * format->block_byte_count;
+
+    for (slice = 0; slice < slice_count; ++slice)
+    {
+        for (row = 0; row < row_count; ++row)
+        {
+            src_row = &src[slice * src_slice_pitch + row * src_row_pitch];
+            dst_row = &dst[slice * dst_slice_pitch + row * dst_row_pitch];
+            memcpy(dst_row, src_row, row_size);
+        }
+    }
+}
+
 VkFormat vkd3d_get_vk_format(DXGI_FORMAT format)
 {
     const struct vkd3d_format *vkd3d_format;
diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h
index ee1c463..fd98463 100644
--- a/libs/vkd3d/vkd3d_private.h
+++ b/libs/vkd3d/vkd3d_private.h
@@ -1155,6 +1155,10 @@ static inline bool vkd3d_format_is_compressed(const struct vkd3d_format *format)
     return format->block_byte_count != 1;
 }
 
+void vkd3d_format_copy_data(const struct vkd3d_format *format, const uint8_t *src,
+        unsigned int src_row_pitch, unsigned int src_slice_pitch, uint8_t *dst, unsigned int dst_row_pitch,
+        unsigned int dst_slice_pitch, unsigned int w, unsigned int h, unsigned int d) DECLSPEC_HIDDEN;
+
 const struct vkd3d_format *vkd3d_get_format(const struct d3d12_device *device,
         DXGI_FORMAT dxgi_format, bool depth_stencil) DECLSPEC_HIDDEN;
 




More information about the wine-cvs mailing list