[PATCH 2/5] d3d10core: Implement d3d10_device_CopyResource().

Henri Verbeet hverbeet at codeweavers.com
Mon Aug 4 05:17:24 CDT 2014


From: Henri Verbeet <hverbeet at freedesktop.org>

---
 dlls/d3d10core/d3d10core_private.h |    2 +
 dlls/d3d10core/device.c            |    9 ++++-
 dlls/d3d10core/texture.c           |    8 ++++
 dlls/d3d10core/utils.c             |   22 +++++++++++
 dlls/d3d10core/view.c              |   20 ----------
 dlls/wined3d/device.c              |   71 ++++++++++++++++++++++++++++++++++++
 dlls/wined3d/wined3d.spec          |    1 +
 include/wine/wined3d.h             |    2 +
 8 files changed, 114 insertions(+), 21 deletions(-)

diff --git a/dlls/d3d10core/d3d10core_private.h b/dlls/d3d10core/d3d10core_private.h
index 9241312..a697a0e 100644
--- a/dlls/d3d10core/d3d10core_private.h
+++ b/dlls/d3d10core/d3d10core_private.h
@@ -60,6 +60,7 @@ const char *debug_dxgi_format(DXGI_FORMAT format) DECLSPEC_HIDDEN;
 DXGI_FORMAT dxgi_format_from_wined3dformat(enum wined3d_format_id format) DECLSPEC_HIDDEN;
 enum wined3d_format_id wined3dformat_from_dxgi_format(DXGI_FORMAT format) DECLSPEC_HIDDEN;
 DWORD wined3d_usage_from_d3d10core(UINT bind_flags, enum D3D10_USAGE usage) DECLSPEC_HIDDEN;
+struct wined3d_resource *wined3d_resource_from_resource(ID3D10Resource *resource) DECLSPEC_HIDDEN;
 
 static inline void read_dword(const char **ptr, DWORD *d)
 {
@@ -86,6 +87,7 @@ struct d3d10_texture2d
 
 HRESULT d3d10_texture2d_init(struct d3d10_texture2d *texture, struct d3d10_device *device,
         const D3D10_TEXTURE2D_DESC *desc) DECLSPEC_HIDDEN;
+struct d3d10_texture2d *unsafe_impl_from_ID3D10Texture2D(ID3D10Texture2D *iface) DECLSPEC_HIDDEN;
 
 /* ID3D10Texture3D */
 struct d3d10_texture3d
diff --git a/dlls/d3d10core/device.c b/dlls/d3d10core/device.c
index db3f265..ac43ca6 100644
--- a/dlls/d3d10core/device.c
+++ b/dlls/d3d10core/device.c
@@ -514,7 +514,14 @@ static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *
 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
         ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
 {
-    FIXME("iface %p, dst_resource %p, src_resource %p stub!\n", iface, dst_resource, src_resource);
+    struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
+    struct d3d10_device *device = impl_from_ID3D10Device(iface);
+
+    TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
+
+    wined3d_dst_resource = wined3d_resource_from_resource(dst_resource);
+    wined3d_src_resource = wined3d_resource_from_resource(src_resource);
+    wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
 }
 
 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
diff --git a/dlls/d3d10core/texture.c b/dlls/d3d10core/texture.c
index 80ac899..b488f91 100644
--- a/dlls/d3d10core/texture.c
+++ b/dlls/d3d10core/texture.c
@@ -236,6 +236,14 @@ static const struct ID3D10Texture2DVtbl d3d10_texture2d_vtbl =
     d3d10_texture2d_GetDesc,
 };
 
+struct d3d10_texture2d *unsafe_impl_from_ID3D10Texture2D(ID3D10Texture2D *iface)
+{
+    if (!iface)
+        return NULL;
+    assert(iface->lpVtbl == &d3d10_texture2d_vtbl);
+    return CONTAINING_RECORD(iface, struct d3d10_texture2d, ID3D10Texture2D_iface);
+}
+
 static const struct wined3d_parent_ops d3d10_texture2d_wined3d_parent_ops =
 {
     d3d10_texture2d_wined3d_object_released,
diff --git a/dlls/d3d10core/utils.c b/dlls/d3d10core/utils.c
index e0c6014..d955fbb 100644
--- a/dlls/d3d10core/utils.c
+++ b/dlls/d3d10core/utils.c
@@ -367,6 +367,28 @@ DWORD wined3d_usage_from_d3d10core(UINT bind_flags, enum D3D10_USAGE usage)
     return wined3d_usage;
 }
 
+struct wined3d_resource *wined3d_resource_from_resource(ID3D10Resource *resource)
+{
+    D3D10_RESOURCE_DIMENSION dimension;
+
+    ID3D10Resource_GetType(resource, &dimension);
+
+    switch (dimension)
+    {
+        case D3D10_RESOURCE_DIMENSION_BUFFER:
+            return wined3d_buffer_get_resource(unsafe_impl_from_ID3D10Buffer(
+                    (ID3D10Buffer *)resource)->wined3d_buffer);
+
+        case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
+            return wined3d_texture_get_resource(unsafe_impl_from_ID3D10Texture2D(
+                    (ID3D10Texture2D *)resource)->wined3d_texture);
+
+        default:
+            FIXME("Unhandled resource dimension %#x.\n", dimension);
+            return NULL;
+    }
+}
+
 void skip_dword_unknown(const char **ptr, unsigned int count)
 {
     unsigned int i;
diff --git a/dlls/d3d10core/view.c b/dlls/d3d10core/view.c
index 4282f1a..e7aac3b 100644
--- a/dlls/d3d10core/view.c
+++ b/dlls/d3d10core/view.c
@@ -25,26 +25,6 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d10core);
 
-static struct wined3d_resource *wined3d_resource_from_resource(ID3D10Resource *resource)
-{
-    D3D10_RESOURCE_DIMENSION dimension;
-
-    ID3D10Resource_GetType(resource, &dimension);
-
-    switch(dimension)
-    {
-        case D3D10_RESOURCE_DIMENSION_BUFFER:
-            return wined3d_buffer_get_resource(((struct d3d10_buffer *)resource)->wined3d_buffer);
-
-        case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
-            return wined3d_texture_get_resource(((struct d3d10_texture2d *)resource)->wined3d_texture);
-
-        default:
-            FIXME("Unhandled resource dimension %#x.\n", dimension);
-            return NULL;
-    }
-}
-
 static HRESULT set_dsdesc_from_resource(D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10Resource *resource)
 {
     D3D10_RESOURCE_DIMENSION dimension;
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 4aacf1d..962a4a6 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -3664,6 +3664,77 @@ HRESULT CDECL wined3d_device_color_fill(struct wined3d_device *device,
     return surface_color_fill(surface, rect, color);
 }
 
+void CDECL wined3d_device_copy_resource(struct wined3d_device *device,
+        struct wined3d_resource *dst_resource, struct wined3d_resource *src_resource)
+{
+    struct wined3d_surface *dst_surface, *src_surface;
+    struct wined3d_texture *dst_texture, *src_texture;
+    unsigned int i, count;
+    HRESULT hr;
+
+    TRACE("device %p, dst_resource %p, src_resource %p.\n", device, dst_resource, src_resource);
+
+    if (src_resource == dst_resource)
+    {
+        WARN("Source and destination are the same resource.\n");
+        return;
+    }
+
+    if (src_resource->type != dst_resource->type)
+    {
+        WARN("Resource types (%s / %s) don't match.\n",
+                debug_d3dresourcetype(dst_resource->type),
+                debug_d3dresourcetype(src_resource->type));
+        return;
+    }
+
+    if (src_resource->width != dst_resource->width
+            || src_resource->height != dst_resource->height
+            || src_resource->depth != dst_resource->depth)
+    {
+        WARN("Resource dimensions (%ux%ux%u / %ux%ux%u) don't match.\n",
+                dst_resource->width, dst_resource->height, dst_resource->depth,
+                src_resource->width, src_resource->height, src_resource->depth);
+        return;
+    }
+
+    if (src_resource->format->id != dst_resource->format->id)
+    {
+        WARN("Resource formats (%s / %s) don't match.\n",
+                debug_d3dformat(dst_resource->format->id),
+                debug_d3dformat(src_resource->format->id));
+        return;
+    }
+
+    if (dst_resource->type != WINED3D_RTYPE_TEXTURE)
+    {
+        FIXME("Not implemented for %s resources.\n", debug_d3dresourcetype(dst_resource->type));
+        return;
+    }
+
+    dst_texture = wined3d_texture_from_resource(dst_resource);
+    src_texture = wined3d_texture_from_resource(src_resource);
+
+    if (src_texture->layer_count != dst_texture->layer_count
+            || src_texture->level_count != dst_texture->level_count)
+    {
+        WARN("Subresource layouts (%ux%u / %ux%u) don't match.\n",
+                dst_texture->layer_count, dst_texture->level_count,
+                src_texture->layer_count, src_texture->level_count);
+        return;
+    }
+
+    count = dst_texture->layer_count * dst_texture->level_count;
+    for (i = 0; i < count; ++i)
+    {
+        dst_surface = surface_from_resource(wined3d_texture_get_sub_resource(dst_texture, i));
+        src_surface = surface_from_resource(wined3d_texture_get_sub_resource(src_texture, i));
+
+        if (FAILED(hr = wined3d_surface_blt(dst_surface, NULL, src_surface, NULL, 0, NULL, WINED3D_TEXF_POINT)))
+            ERR("Failed to blit, subresource %u, hr %#x.\n", i, hr);
+    }
+}
+
 void CDECL wined3d_device_clear_rendertarget_view(struct wined3d_device *device,
         struct wined3d_rendertarget_view *rendertarget_view, const struct wined3d_color *color)
 {
diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec
index a53c74b..e3baac2 100644
--- a/dlls/wined3d/wined3d.spec
+++ b/dlls/wined3d/wined3d.spec
@@ -38,6 +38,7 @@
 @ cdecl wined3d_device_clear(ptr long ptr long ptr float long)
 @ cdecl wined3d_device_clear_rendertarget_view(ptr ptr ptr)
 @ cdecl wined3d_device_color_fill(ptr ptr ptr ptr)
+@ cdecl wined3d_device_copy_resource(ptr ptr ptr)
 @ cdecl wined3d_device_create(ptr long long ptr long long ptr ptr)
 @ cdecl wined3d_device_decref(ptr)
 @ cdecl wined3d_device_draw_indexed_primitive(ptr long long)
diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h
index 6309fe8..642f48f 100644
--- a/include/wine/wined3d.h
+++ b/include/wine/wined3d.h
@@ -2080,6 +2080,8 @@ void __cdecl wined3d_device_clear_rendertarget_view(struct wined3d_device *devic
         struct wined3d_rendertarget_view *rendertarget_view, const struct wined3d_color *color);
 HRESULT __cdecl wined3d_device_color_fill(struct wined3d_device *device, struct wined3d_surface *surface,
         const RECT *rect, const struct wined3d_color *color);
+void __cdecl wined3d_device_copy_resource(struct wined3d_device *device,
+        struct wined3d_resource *dst_resource, struct wined3d_resource *src_resource);
 HRESULT __cdecl wined3d_device_create(struct wined3d *wined3d, UINT adapter_idx,
         enum wined3d_device_type device_type, HWND focus_window, DWORD behaviour_flags, BYTE surface_alignment,
         struct wined3d_device_parent *device_parent, struct wined3d_device **device);
-- 
1.7.10.4




More information about the wine-patches mailing list