[PATCH v4 2/5] d3d8: Don't upload unused system memory vertex buffers.

Matteo Bruni mbruni at codeweavers.com
Tue Mar 5 11:47:20 CST 2019


Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
---
v2: Add a couple of small comments.
v3: Split the test out to a separate patch, remove comment again since
it doesn't apply anymore.
v4: Compute stream map at declaration creation time.

 dlls/d3d8/d3d8_private.h      |  1 +
 dlls/d3d8/device.c            | 12 +++++++++++-
 dlls/d3d8/vertexdeclaration.c |  9 +++++++--
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h
index 7c44f07c5ea..0f861658cf4 100644
--- a/dlls/d3d8/d3d8_private.h
+++ b/dlls/d3d8/d3d8_private.h
@@ -251,6 +251,7 @@ struct d3d8_vertex_declaration
 {
     DWORD *elements;
     DWORD elements_size; /* Size of elements, in bytes */
+    DWORD stream_map;
     struct wined3d_vertex_declaration *wined3d_vertex_declaration;
     DWORD shader_handle;
 };
diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c
index d367f4200cc..56c363cfd12 100644
--- a/dlls/d3d8/device.c
+++ b/dlls/d3d8/device.c
@@ -2269,15 +2269,25 @@ static HRESULT WINAPI d3d8_device_GetCurrentTexturePalette(IDirect3DDevice8 *ifa
 static void d3d8_device_upload_sysmem_vertex_buffers(struct d3d8_device *device,
         unsigned int start_vertex, unsigned int vertex_count)
 {
+    struct wined3d_vertex_declaration *wined3d_decl;
     struct wined3d_box box = {0, 0, 0, 1, 0, 1};
     struct d3d8_vertexbuffer *d3d8_buffer;
     struct wined3d_resource *dst_resource;
+    struct d3d8_vertex_declaration *decl;
     unsigned int i, offset, stride, map;
     struct wined3d_buffer *dst_buffer;
     struct wined3d_resource_desc desc;
     HRESULT hr;
 
-    map = device->sysmem_vb;
+    if (!device->sysmem_vb)
+        return;
+
+    wined3d_decl = wined3d_device_get_vertex_declaration(device->wined3d_device);
+    if (!wined3d_decl)
+        return;
+
+    decl = wined3d_vertex_declaration_get_parent(wined3d_decl);
+    map = decl->stream_map & device->sysmem_vb;
     while (map)
     {
         i = wined3d_bit_scan(&map);
diff --git a/dlls/d3d8/vertexdeclaration.c b/dlls/d3d8/vertexdeclaration.c
index 709e04bace4..c2d0b9f7535 100644
--- a/dlls/d3d8/vertexdeclaration.c
+++ b/dlls/d3d8/vertexdeclaration.c
@@ -250,7 +250,7 @@ wined3d_usage_lookup[] =
 
 /* TODO: find out where rhw (or positionT) is for declaration8 */
 static UINT convert_to_wined3d_declaration(const DWORD *d3d8_elements, DWORD *d3d8_elements_size,
-        struct wined3d_vertex_element **wined3d_elements)
+        struct wined3d_vertex_element **wined3d_elements, DWORD *stream_map)
 {
     struct wined3d_vertex_element *element;
     const DWORD *token = d3d8_elements;
@@ -261,6 +261,7 @@ static UINT convert_to_wined3d_declaration(const DWORD *d3d8_elements, DWORD *d3
 
     TRACE("d3d8_elements %p, d3d8_elements_size %p, wined3d_elements %p\n", d3d8_elements, d3d8_elements_size, wined3d_elements);
 
+    *stream_map = 0;
     /* 128 should be enough for anyone... */
     *wined3d_elements = heap_alloc_zero(128 * sizeof(**wined3d_elements));
     while (D3DVSD_END() != *token)
@@ -288,6 +289,8 @@ static UINT convert_to_wined3d_declaration(const DWORD *d3d8_elements, DWORD *d3
             element->usage = wined3d_usage_lookup[reg].usage;
             element->usage_idx = wined3d_usage_lookup[reg].usage_idx;
 
+            *stream_map |= 1u << stream;
+
             offset += wined3d_type_sizes[type];
         } else if (token_type == D3DVSD_TOKEN_STREAMDATA && (*token & D3DVSD_DATALOADTYPEMASK)) {
             TRACE(" 0x%08x SKIP(%u)\n", token_type, ((token_type & D3DVSD_SKIPCOUNTMASK) >> D3DVSD_SKIPCOUNTSHIFT));
@@ -337,7 +340,8 @@ HRESULT d3d8_vertex_declaration_init(struct d3d8_vertex_declaration *declaration
 
     declaration->shader_handle = shader_handle;
 
-    wined3d_element_count = convert_to_wined3d_declaration(elements, &declaration->elements_size, &wined3d_elements);
+    wined3d_element_count = convert_to_wined3d_declaration(elements, &declaration->elements_size,
+            &wined3d_elements, &declaration->stream_map);
     if (!(declaration->elements = heap_alloc(declaration->elements_size)))
     {
         ERR("Failed to allocate vertex declaration elements memory.\n");
@@ -369,6 +373,7 @@ HRESULT d3d8_vertex_declaration_init_fvf(struct d3d8_vertex_declaration *declara
 
     declaration->elements = NULL;
     declaration->elements_size = 0;
+    declaration->stream_map = 1;
     declaration->shader_handle = fvf;
 
     hr = wined3d_vertex_declaration_create_from_fvf(device->wined3d_device, fvf, declaration,
-- 
2.19.2




More information about the wine-devel mailing list