[PATCH 2/6] wined3d: Set both the stream source and frequency for a given index as a single CS operation.

Zebediah Figura zfigura at codeweavers.com
Wed Jul 7 18:10:32 CDT 2021


Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
 dlls/d3d11/device.c            | 20 ++++++++---
 dlls/wined3d/cs.c              | 54 ++++------------------------
 dlls/wined3d/device.c          | 64 +++++++++-------------------------
 dlls/wined3d/wined3d.spec      |  2 +-
 dlls/wined3d/wined3d_private.h |  4 +--
 include/wine/wined3d.h         |  2 +-
 6 files changed, 41 insertions(+), 105 deletions(-)

diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c
index ea7aa717c30..35b629b8d62 100644
--- a/dlls/d3d11/device.c
+++ b/dlls/d3d11/device.c
@@ -851,9 +851,15 @@ static void STDMETHODCALLTYPE d3d11_device_context_IASetVertexBuffers(ID3D11Devi
     for (i = 0; i < buffer_count; ++i)
     {
         struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
+        struct wined3d_stream_state stream;
 
-        wined3d_device_context_set_stream_source(context->wined3d_context, start_slot + i,
-                buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
+        stream.buffer = buffer ? buffer->wined3d_buffer : NULL;
+        stream.offset = offsets[i];
+        stream.stride = strides[i];
+        stream.frequency = 1;
+        stream.flags = 0;
+
+        wined3d_device_context_set_stream_source(context->wined3d_context, start_slot + i, &stream);
     }
     wined3d_mutex_unlock();
 }
@@ -4705,9 +4711,15 @@ static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *ifa
     for (i = 0; i < buffer_count; ++i)
     {
         struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
+        struct wined3d_stream_state stream;
 
-        wined3d_device_context_set_stream_source(device->immediate_context.wined3d_context, start_slot + i,
-                buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
+        stream.buffer = buffer ? buffer->wined3d_buffer : NULL;
+        stream.offset = offsets[i];
+        stream.stride = strides[i];
+        stream.frequency = 1;
+        stream.flags = 0;
+
+        wined3d_device_context_set_stream_source(device->immediate_context.wined3d_context, start_slot + i, &stream);
     }
     wined3d_mutex_unlock();
 }
diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c
index 49b4f529554..1cffd66d89a 100644
--- a/dlls/wined3d/cs.c
+++ b/dlls/wined3d/cs.c
@@ -117,7 +117,6 @@ enum wined3d_cs_op
     WINED3D_CS_OP_SET_DEPTH_STENCIL_VIEW,
     WINED3D_CS_OP_SET_VERTEX_DECLARATION,
     WINED3D_CS_OP_SET_STREAM_SOURCE,
-    WINED3D_CS_OP_SET_STREAM_SOURCE_FREQ,
     WINED3D_CS_OP_SET_STREAM_OUTPUTS,
     WINED3D_CS_OP_SET_INDEX_BUFFER,
     WINED3D_CS_OP_SET_CONSTANT_BUFFERS,
@@ -256,17 +255,7 @@ struct wined3d_cs_set_stream_source
 {
     enum wined3d_cs_op opcode;
     UINT stream_idx;
-    struct wined3d_buffer *buffer;
-    UINT offset;
-    UINT stride;
-};
-
-struct wined3d_cs_set_stream_source_freq
-{
-    enum wined3d_cs_op opcode;
-    UINT stream_idx;
-    UINT frequency;
-    UINT flags;
+    struct wined3d_stream_state state;
 };
 
 struct wined3d_cs_set_stream_outputs
@@ -600,7 +589,6 @@ static const char *debug_cs_op(enum wined3d_cs_op op)
         WINED3D_TO_STR(WINED3D_CS_OP_SET_DEPTH_STENCIL_VIEW);
         WINED3D_TO_STR(WINED3D_CS_OP_SET_VERTEX_DECLARATION);
         WINED3D_TO_STR(WINED3D_CS_OP_SET_STREAM_SOURCE);
-        WINED3D_TO_STR(WINED3D_CS_OP_SET_STREAM_SOURCE_FREQ);
         WINED3D_TO_STR(WINED3D_CS_OP_SET_STREAM_OUTPUTS);
         WINED3D_TO_STR(WINED3D_CS_OP_SET_INDEX_BUFFER);
         WINED3D_TO_STR(WINED3D_CS_OP_SET_CONSTANT_BUFFERS);
@@ -1417,12 +1405,10 @@ static void wined3d_cs_exec_set_stream_source(struct wined3d_cs *cs, const void
 
     stream = &cs->state.streams[op->stream_idx];
     prev = stream->buffer;
-    stream->buffer = op->buffer;
-    stream->offset = op->offset;
-    stream->stride = op->stride;
+    *stream = op->state;
 
-    if (op->buffer)
-        InterlockedIncrement(&op->buffer->resource.bind_count);
+    if (op->state.buffer)
+        InterlockedIncrement(&op->state.buffer->resource.bind_count);
     if (prev)
         InterlockedDecrement(&prev->resource.bind_count);
 
@@ -1430,45 +1416,18 @@ static void wined3d_cs_exec_set_stream_source(struct wined3d_cs *cs, const void
 }
 
 void wined3d_device_context_emit_set_stream_source(struct wined3d_device_context *context, unsigned int stream_idx,
-        struct wined3d_buffer *buffer, unsigned int offset, unsigned int stride)
+        const struct wined3d_stream_state *state)
 {
     struct wined3d_cs_set_stream_source *op;
 
     op = wined3d_device_context_require_space(context, sizeof(*op), WINED3D_CS_QUEUE_DEFAULT);
     op->opcode = WINED3D_CS_OP_SET_STREAM_SOURCE;
     op->stream_idx = stream_idx;
-    op->buffer = buffer;
-    op->offset = offset;
-    op->stride = stride;
+    op->state = *state;
 
     wined3d_device_context_submit(context, WINED3D_CS_QUEUE_DEFAULT);
 }
 
-static void wined3d_cs_exec_set_stream_source_freq(struct wined3d_cs *cs, const void *data)
-{
-    const struct wined3d_cs_set_stream_source_freq *op = data;
-    struct wined3d_stream_state *stream;
-
-    stream = &cs->state.streams[op->stream_idx];
-    stream->frequency = op->frequency;
-    stream->flags = op->flags;
-
-    device_invalidate_state(cs->c.device, STATE_STREAMSRC);
-}
-
-void wined3d_cs_emit_set_stream_source_freq(struct wined3d_cs *cs, UINT stream_idx, UINT frequency, UINT flags)
-{
-    struct wined3d_cs_set_stream_source_freq *op;
-
-    op = wined3d_device_context_require_space(&cs->c, sizeof(*op), WINED3D_CS_QUEUE_DEFAULT);
-    op->opcode = WINED3D_CS_OP_SET_STREAM_SOURCE_FREQ;
-    op->stream_idx = stream_idx;
-    op->frequency = frequency;
-    op->flags = flags;
-
-    wined3d_device_context_submit(&cs->c, WINED3D_CS_QUEUE_DEFAULT);
-}
-
 static void wined3d_cs_exec_set_stream_outputs(struct wined3d_cs *cs, const void *data)
 {
     const struct wined3d_cs_set_stream_outputs *op = data;
@@ -2924,7 +2883,6 @@ static void (* const wined3d_cs_op_handlers[])(struct wined3d_cs *cs, const void
     /* WINED3D_CS_OP_SET_DEPTH_STENCIL_VIEW      */ wined3d_cs_exec_set_depth_stencil_view,
     /* WINED3D_CS_OP_SET_VERTEX_DECLARATION      */ wined3d_cs_exec_set_vertex_declaration,
     /* WINED3D_CS_OP_SET_STREAM_SOURCE           */ wined3d_cs_exec_set_stream_source,
-    /* WINED3D_CS_OP_SET_STREAM_SOURCE_FREQ      */ wined3d_cs_exec_set_stream_source_freq,
     /* WINED3D_CS_OP_SET_STREAM_OUTPUTS          */ wined3d_cs_exec_set_stream_outputs,
     /* WINED3D_CS_OP_SET_INDEX_BUFFER            */ wined3d_cs_exec_set_index_buffer,
     /* WINED3D_CS_OP_SET_CONSTANT_BUFFERS        */ wined3d_cs_exec_set_constant_buffers,
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 7a78a271aa1..c8e81e923cc 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -1274,23 +1274,6 @@ HRESULT CDECL wined3d_device_context_get_stream_source(const struct wined3d_devi
     return WINED3D_OK;
 }
 
-static void wined3d_device_set_stream_source_freq(struct wined3d_device *device, UINT stream_idx, UINT divider)
-{
-    struct wined3d_stream_state *stream;
-    UINT old_flags, old_freq;
-
-    TRACE("device %p, stream_idx %u, divider %#x.\n", device, stream_idx, divider);
-
-    stream = &device->cs->c.state->streams[stream_idx];
-    old_flags = stream->flags;
-    old_freq = stream->frequency;
-
-    stream->flags = divider & (WINED3DSTREAMSOURCE_INSTANCEDATA | WINED3DSTREAMSOURCE_INDEXEDDATA);
-    stream->frequency = divider & 0x7fffff;
-    if (stream->frequency != old_freq || stream->flags != old_flags)
-        wined3d_cs_emit_set_stream_source_freq(device->cs, stream_idx, stream->frequency, stream->flags);
-}
-
 static void wined3d_device_set_transform(struct wined3d_device *device,
         enum wined3d_transform_state state, const struct wined3d_matrix *matrix)
 {
@@ -1679,10 +1662,7 @@ void CDECL wined3d_device_context_set_state(struct wined3d_device_context *conte
     wined3d_device_context_emit_set_stream_outputs(context, state->stream_output);
 
     for (i = 0; i < WINED3D_MAX_STREAMS; ++i)
-    {
-        wined3d_device_context_emit_set_stream_source(context, i, state->streams[i].buffer,
-                state->streams[i].offset, state->streams[i].stride);
-    }
+        wined3d_device_context_emit_set_stream_source(context, i, &state->streams[i]);
 
     wined3d_device_context_emit_set_index_buffer(context, state->index_buffer,
             state->index_format, state->index_offset);
@@ -2240,42 +2220,38 @@ void CDECL wined3d_device_context_set_predication(struct wined3d_device_context
 }
 
 HRESULT CDECL wined3d_device_context_set_stream_source(struct wined3d_device_context *context,
-        unsigned int stream_idx, struct wined3d_buffer *buffer, unsigned int offset, unsigned int stride)
+        unsigned int stream_idx, const struct wined3d_stream_state *src_stream)
 {
-    struct wined3d_stream_state *stream;
+    struct wined3d_buffer *buffer = src_stream->buffer;
+    struct wined3d_stream_state *dst_stream;
     struct wined3d_buffer *prev_buffer;
 
-    TRACE("context %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
-            context, stream_idx, buffer, offset, stride);
+    TRACE("context %p, stream_idx %u, src_stream %p.\n", context, stream_idx, src_stream);
 
     if (stream_idx >= WINED3D_MAX_STREAMS)
     {
         WARN("Stream index %u out of range.\n", stream_idx);
         return WINED3DERR_INVALIDCALL;
     }
-    else if (offset & 0x3)
+    else if (src_stream->offset & 0x3)
     {
-        WARN("Offset %u is not 4 byte aligned.\n", offset);
+        WARN("Offset %u is not 4 byte aligned.\n", src_stream->offset);
         return WINED3DERR_INVALIDCALL;
     }
 
-    stream = &context->state->streams[stream_idx];
-    prev_buffer = stream->buffer;
+    dst_stream = &context->state->streams[stream_idx];
+    prev_buffer = dst_stream->buffer;
 
-    if (prev_buffer == buffer
-            && stream->stride == stride
-            && stream->offset == offset)
+    if (!memcmp(src_stream, dst_stream, sizeof(*src_stream)))
     {
-       TRACE("Application is setting the old values over, nothing to do.\n");
-       return WINED3D_OK;
+        TRACE("Application is setting the old values over, nothing to do.\n");
+        return WINED3D_OK;
     }
 
-    stream->buffer = buffer;
-    stream->stride = stride;
-    stream->offset = offset;
+    *dst_stream = *src_stream;
     if (buffer)
         wined3d_buffer_incref(buffer);
-    wined3d_device_context_emit_set_stream_source(context, stream_idx, buffer, offset, stride);
+    wined3d_device_context_emit_set_stream_source(context, stream_idx, src_stream);
     if (prev_buffer)
         wined3d_buffer_decref(prev_buffer);
 
@@ -3932,19 +3908,11 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device,
     if (changed->scissorRect)
         wined3d_device_context_set_scissor_rects(context, 1, &state->scissor_rect);
 
-    map = changed->streamSource;
+    map = changed->streamSource | changed->streamFreq;
     while (map)
     {
         i = wined3d_bit_scan(&map);
-        wined3d_device_context_set_stream_source(context, i, state->streams[i].buffer,
-                state->streams[i].offset, state->streams[i].stride);
-    }
-    map = changed->streamFreq;
-    while (map)
-    {
-        i = wined3d_bit_scan(&map);
-        wined3d_device_set_stream_source_freq(device, i,
-                state->streams[i].frequency | state->streams[i].flags);
+        wined3d_device_context_set_stream_source(context, i, &state->streams[i]);
     }
 
     map = changed->textures;
diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec
index ccd941af7a7..1dac446a0e0 100644
--- a/dlls/wined3d/wined3d.spec
+++ b/dlls/wined3d/wined3d.spec
@@ -137,7 +137,7 @@
 @ cdecl wined3d_device_context_set_shader_resource_views(ptr long long long ptr)
 @ cdecl wined3d_device_context_set_state(ptr ptr)
 @ cdecl wined3d_device_context_set_stream_outputs(ptr ptr)
-@ cdecl wined3d_device_context_set_stream_source(ptr long ptr long long)
+@ cdecl wined3d_device_context_set_stream_source(ptr long ptr)
 @ cdecl wined3d_device_context_set_unordered_access_views(ptr long long long ptr ptr)
 @ cdecl wined3d_device_context_set_vertex_declaration(ptr ptr)
 @ cdecl wined3d_device_context_set_viewports(ptr long ptr)
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 2708d5c7f32..98b387b73c0 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -4760,8 +4760,6 @@ void wined3d_cs_emit_set_color_key(struct wined3d_cs *cs, struct wined3d_texture
         WORD flags, const struct wined3d_color_key *color_key) DECLSPEC_HIDDEN;
 void wined3d_cs_emit_set_render_state(struct wined3d_cs *cs,
         enum wined3d_render_state state, DWORD value) DECLSPEC_HIDDEN;
-void wined3d_cs_emit_set_stream_source_freq(struct wined3d_cs *cs, UINT stream_idx,
-        UINT frequency, UINT flags) DECLSPEC_HIDDEN;
 void wined3d_cs_emit_unload_resource(struct wined3d_cs *cs, struct wined3d_resource *resource) DECLSPEC_HIDDEN;
 void wined3d_cs_init_object(struct wined3d_cs *cs,
         void (*callback)(void *object), void *object) DECLSPEC_HIDDEN;
@@ -4843,7 +4841,7 @@ void wined3d_device_context_emit_set_shader_resource_views(struct wined3d_device
 void wined3d_device_context_emit_set_stream_outputs(struct wined3d_device_context *context,
         const struct wined3d_stream_output outputs[WINED3D_MAX_STREAM_OUTPUT_BUFFERS]) DECLSPEC_HIDDEN;
 void wined3d_device_context_emit_set_stream_source(struct wined3d_device_context *context, unsigned int stream_idx,
-        struct wined3d_buffer *buffer, unsigned int offset, unsigned int stride) DECLSPEC_HIDDEN;
+        const struct wined3d_stream_state *state) DECLSPEC_HIDDEN;
 void wined3d_device_context_emit_set_texture(struct wined3d_device_context *context, unsigned int stage,
         struct wined3d_texture *texture) DECLSPEC_HIDDEN;
 void wined3d_device_context_emit_set_texture_state(struct wined3d_device_context *context, unsigned int stage,
diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h
index 1369fffddf3..94bbb4061c4 100644
--- a/include/wine/wined3d.h
+++ b/include/wine/wined3d.h
@@ -2532,7 +2532,7 @@ void __cdecl wined3d_device_context_set_state(struct wined3d_device_context *con
 void __cdecl wined3d_device_context_set_stream_outputs(struct wined3d_device_context *context,
         const struct wined3d_stream_output outputs[WINED3D_MAX_STREAM_OUTPUT_BUFFERS]);
 HRESULT __cdecl wined3d_device_context_set_stream_source(struct wined3d_device_context *context,
-        unsigned int stream_idx, struct wined3d_buffer *buffer, unsigned int offset, unsigned int stride);
+        unsigned int stream_idx, const struct wined3d_stream_state *stream);
 void __cdecl wined3d_device_context_set_unordered_access_views(struct wined3d_device_context *context,
         enum wined3d_pipeline pipeline, unsigned int start_idx, unsigned int count,
         struct wined3d_unordered_access_view *const *uavs, const unsigned int *initial_counts);
-- 
2.30.2




More information about the wine-devel mailing list