[PATCH 1/4] wined3d: Store the index buffer in the wined3d_stateblock_state structure.

Zebediah Figura z.figura12 at gmail.com
Wed Feb 6 19:38:25 CST 2019


Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
 dlls/wined3d/device.c          | 32 +++++++++++++++---------
 dlls/wined3d/stateblock.c      | 45 ++++++++++++++++++++++------------
 dlls/wined3d/wined3d_private.h |  4 +++
 3 files changed, 54 insertions(+), 27 deletions(-)

diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index bce2a3519d..e7ad5441eb 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -1865,24 +1865,32 @@ void CDECL wined3d_device_set_index_buffer(struct wined3d_device *device,
     TRACE("device %p, buffer %p, format %s, offset %u.\n",
             device, buffer, debug_d3dformat(format_id), offset);
 
-    prev_buffer = device->update_state->index_buffer;
-    prev_format = device->update_state->index_format;
-    prev_offset = device->update_state->index_offset;
+    prev_buffer = device->state.index_buffer;
+    prev_format = device->state.index_format;
+    prev_offset = device->state.index_offset;
 
-    device->update_state->index_buffer = buffer;
-    device->update_state->index_format = format_id;
-    device->update_state->index_offset = offset;
+    if (buffer)
+        wined3d_buffer_incref(buffer);
+    if (device->update_stateblock_state->index_buffer)
+        wined3d_buffer_decref(device->update_stateblock_state->index_buffer);
+    device->update_stateblock_state->index_buffer = buffer;
+    device->update_stateblock_state->index_format = format_id;
 
     if (device->recording)
+    {
         device->recording->changed.indices = TRUE;
+        return;
+    }
 
     if (prev_buffer == buffer && prev_format == format_id && prev_offset == offset)
         return;
 
     if (buffer)
         wined3d_buffer_incref(buffer);
-    if (!device->recording)
-        wined3d_cs_emit_set_index_buffer(device->cs, buffer, format_id, offset);
+    device->state.index_buffer = buffer;
+    device->state.index_format = format_id;
+    device->state.index_offset = offset;
+    wined3d_cs_emit_set_index_buffer(device->cs, buffer, format_id, offset);
     if (prev_buffer)
         wined3d_buffer_decref(prev_buffer);
 }
@@ -1902,7 +1910,9 @@ void CDECL wined3d_device_set_base_vertex_index(struct wined3d_device *device, I
 {
     TRACE("device %p, base_index %d.\n", device, base_index);
 
-    device->update_state->base_vertex_index = base_index;
+    device->update_stateblock_state->base_vertex_index = base_index;
+    if (!device->recording)
+        device->state.base_vertex_index = base_index;
 }
 
 INT CDECL wined3d_device_get_base_vertex_index(const struct wined3d_device *device)
@@ -5219,11 +5229,11 @@ void device_resource_released(struct wined3d_device *device, struct wined3d_reso
                 device->state.index_buffer =  NULL;
             }
 
-            if (device->recording && &device->update_state->index_buffer->resource == resource)
+            if (device->recording && &device->update_stateblock_state->index_buffer->resource == resource)
             {
                 ERR("Buffer resource %p is still in use by stateblock %p as index buffer.\n",
                         resource, device->recording);
-                device->update_state->index_buffer =  NULL;
+                device->update_stateblock_state->index_buffer =  NULL;
             }
             break;
 
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c
index 037357c975..4b76b38326 100644
--- a/dlls/wined3d/stateblock.c
+++ b/dlls/wined3d/stateblock.c
@@ -524,9 +524,16 @@ void state_unbind_resources(struct wined3d_state *state)
 void wined3d_stateblock_state_cleanup(struct wined3d_stateblock_state *state)
 {
     struct wined3d_texture *texture;
+    struct wined3d_buffer *buffer;
     struct wined3d_shader *shader;
     unsigned int i;
 
+    if ((buffer = state->index_buffer))
+    {
+        state->index_buffer = NULL;
+        wined3d_buffer_decref(buffer);
+    }
+
     if ((shader = state->vs))
     {
         state->vs = NULL;
@@ -791,22 +798,20 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock)
     }
 
     if (stateblock->changed.indices
-            && ((stateblock->state.index_buffer != src_state->index_buffer)
-                || (stateblock->state.base_vertex_index != src_state->base_vertex_index)
-                || (stateblock->state.index_format != src_state->index_format)
-                || (stateblock->state.index_offset != src_state->index_offset)))
+            && ((stateblock->stateblock_state.index_buffer != state->index_buffer)
+                || (stateblock->stateblock_state.base_vertex_index != state->base_vertex_index)
+                || (stateblock->stateblock_state.index_format != state->index_format)))
     {
         TRACE("Updating index buffer to %p, base vertex index to %d.\n",
-                src_state->index_buffer, src_state->base_vertex_index);
+                state->index_buffer, state->base_vertex_index);
 
-        if (src_state->index_buffer)
-            wined3d_buffer_incref(src_state->index_buffer);
-        if (stateblock->state.index_buffer)
-            wined3d_buffer_decref(stateblock->state.index_buffer);
-        stateblock->state.index_buffer = src_state->index_buffer;
-        stateblock->state.base_vertex_index = src_state->base_vertex_index;
-        stateblock->state.index_format = src_state->index_format;
-        stateblock->state.index_offset = src_state->index_offset;
+        if (state->index_buffer)
+            wined3d_buffer_incref(state->index_buffer);
+        if (stateblock->stateblock_state.index_buffer)
+            wined3d_buffer_decref(stateblock->stateblock_state.index_buffer);
+        stateblock->stateblock_state.index_buffer = state->index_buffer;
+        stateblock->stateblock_state.base_vertex_index = state->base_vertex_index;
+        stateblock->stateblock_state.index_format = state->index_format;
     }
 
     if (stateblock->changed.vertexDecl && stateblock->state.vertex_declaration != src_state->vertex_declaration)
@@ -1106,9 +1111,17 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock)
 
     if (stateblock->changed.indices)
     {
-        wined3d_device_set_index_buffer(device, stateblock->state.index_buffer,
-                stateblock->state.index_format, stateblock->state.index_offset);
-        wined3d_device_set_base_vertex_index(device, stateblock->state.base_vertex_index);
+        if (stateblock->stateblock_state.index_buffer)
+            wined3d_buffer_incref(stateblock->stateblock_state.index_buffer);
+        if (state->index_buffer)
+            wined3d_buffer_decref(state->index_buffer);
+        state->index_buffer = stateblock->stateblock_state.index_buffer;
+        state->index_format = stateblock->stateblock_state.index_format;
+        state->base_vertex_index = stateblock->stateblock_state.base_vertex_index;
+
+        wined3d_device_set_index_buffer(device, stateblock->stateblock_state.index_buffer,
+                stateblock->stateblock_state.index_format, 0);
+        wined3d_device_set_base_vertex_index(device, stateblock->stateblock_state.base_vertex_index);
     }
 
     if (stateblock->changed.vertexDecl && stateblock->state.vertex_declaration)
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index df116cef1c..87e0b23596 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2967,6 +2967,10 @@ struct wined3d_dummy_textures
 
 struct wined3d_stateblock_state
 {
+    struct wined3d_buffer *index_buffer;
+    enum wined3d_format_id index_format;
+    int base_vertex_index;
+
     struct wined3d_shader *vs;
     struct wined3d_vec4 vs_consts_f[WINED3D_MAX_VS_CONSTS_F];
     struct wined3d_ivec4 vs_consts_i[WINED3D_MAX_CONSTS_I];
-- 
2.20.1




More information about the wine-devel mailing list