[PATCH 1/5] wined3d: Introduce wined3d_device_apply_stateblock().

Zebediah Figura z.figura12 at gmail.com
Wed Jan 22 16:55:42 CST 2020


Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
v4: Use wined3d_device_apply_stateblock() in wined3d_stateblock_apply().

 dlls/wined3d/device.c     | 193 ++++++++++++++++++++++++++++++++++++++
 dlls/wined3d/stateblock.c |  64 +------------
 dlls/wined3d/wined3d.spec |   1 +
 include/wine/wined3d.h    |   1 +
 4 files changed, 200 insertions(+), 59 deletions(-)

diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 8913420724..8e20e31d3f 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -3829,6 +3829,199 @@ struct wined3d_texture * CDECL wined3d_device_get_texture(const struct wined3d_d
     return device->state.textures[stage];
 }
 
+void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device,
+        struct wined3d_stateblock *stateblock)
+{
+    const struct wined3d_d3d_info *d3d_info = &stateblock->device->adapter->d3d_info;
+    const struct wined3d_stateblock_state *state = &stateblock->stateblock_state;
+    unsigned int i, j, count;
+
+    TRACE("device %p, stateblock %p.\n", device, stateblock);
+
+    if (stateblock->changed.vertexShader)
+        wined3d_device_set_vertex_shader(device, state->vs);
+    if (stateblock->changed.pixelShader)
+        wined3d_device_set_pixel_shader(device, state->ps);
+
+    count = 0;
+    for (i = 0; i < d3d_info->limits.vs_uniform_count; ++i)
+    {
+        if (stateblock->changed.vs_consts_f[i])
+            ++count;
+        else if (count)
+        {
+            wined3d_device_set_vs_consts_f(device, i - count, count, state->vs_consts_f + i - count);
+            count = 0;
+        }
+    }
+    if (count)
+        wined3d_device_set_vs_consts_f(device, i - count, count, state->vs_consts_f + i - count);
+
+    count = 0;
+    for (i = 0; i < WINED3D_MAX_CONSTS_B; ++i)
+    {
+        if (stateblock->changed.vertexShaderConstantsB & (1u << i))
+            ++count;
+        else if (count)
+        {
+            wined3d_device_set_vs_consts_b(device, i - count, count, state->vs_consts_b + i - count);
+            count = 0;
+        }
+    }
+    if (count)
+        wined3d_device_set_vs_consts_b(device, i - count, count, state->vs_consts_b + i - count);
+
+    count = 0;
+    for (i = 0; i < WINED3D_MAX_CONSTS_I; ++i)
+    {
+        if (stateblock->changed.vertexShaderConstantsI & (1u << i))
+            ++count;
+        else if (count)
+        {
+            wined3d_device_set_vs_consts_i(device, i - count, count, state->vs_consts_i + i - count);
+            count = 0;
+        }
+    }
+    if (count)
+        wined3d_device_set_vs_consts_i(device, i - count, count, state->vs_consts_i + i - count);
+
+    count = 0;
+    for (i = 0; i < d3d_info->limits.ps_uniform_count; ++i)
+    {
+        if (stateblock->changed.ps_consts_f[i])
+            ++count;
+        else if (count)
+        {
+            wined3d_device_set_ps_consts_f(device, i - count, count, state->ps_consts_f + i - count);
+            count = 0;
+        }
+    }
+    if (count)
+        wined3d_device_set_ps_consts_f(device, i - count, count, state->ps_consts_f + i - count);
+
+    count = 0;
+    for (i = 0; i < WINED3D_MAX_CONSTS_B; ++i)
+    {
+        if (stateblock->changed.pixelShaderConstantsB & (1u << i))
+            ++count;
+        else if (count)
+        {
+            wined3d_device_set_ps_consts_b(device, i - count, count, state->ps_consts_b + i - count);
+            count = 0;
+        }
+    }
+    if (count)
+        wined3d_device_set_ps_consts_b(device, i - count, count, state->ps_consts_b + i - count);
+
+    count = 0;
+    for (i = 0; i < WINED3D_MAX_CONSTS_I; ++i)
+    {
+        if (stateblock->changed.pixelShaderConstantsI & (1u << i))
+            ++count;
+        else if (count)
+        {
+            wined3d_device_set_ps_consts_i(device, i - count, count, state->ps_consts_i + i - count);
+            count = 0;
+        }
+    }
+    if (count)
+        wined3d_device_set_ps_consts_i(device, i - count, count, state->ps_consts_i + i - count);
+
+    for (i = 0; i < ARRAY_SIZE(state->light_state->light_map); ++i)
+    {
+        const struct wined3d_light_info *light;
+
+        LIST_FOR_EACH_ENTRY(light, &state->light_state->light_map[i], struct wined3d_light_info, entry)
+        {
+            wined3d_device_set_light(device, light->OriginalIndex, &light->OriginalParms);
+            wined3d_device_set_light_enable(device, light->OriginalIndex, light->glIndex != -1);
+        }
+    }
+
+    for (i = 0; i < ARRAY_SIZE(state->rs); ++i)
+    {
+        if (stateblock->changed.renderState[i >> 5] & (1u << (i & 0x1f)))
+        {
+            if (i == WINED3D_RS_BLENDFACTOR)
+            {
+                struct wined3d_color color;
+                wined3d_color_from_d3dcolor(&color, state->rs[i]);
+                wined3d_device_set_blend_state(device, NULL, &color);
+            }
+            else
+                wined3d_device_set_render_state(device, i, state->rs[i]);
+        }
+    }
+
+    for (i = 0; i < ARRAY_SIZE(state->texture_states); ++i)
+    {
+        for (j = 0; j < ARRAY_SIZE(state->texture_states[i]); ++j)
+        {
+            if (stateblock->changed.textureState[i] & (1u << j))
+                wined3d_device_set_texture_stage_state(device, i, j, state->texture_states[i][j]);
+        }
+    }
+
+    for (i = 0; i < ARRAY_SIZE(state->sampler_states); ++i)
+    {
+        DWORD stage = i;
+        if (stage >= WINED3D_MAX_FRAGMENT_SAMPLERS)
+            stage += WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS;
+        for (j = 0; j < ARRAY_SIZE(state->sampler_states[j]); ++j)
+        {
+            if (stateblock->changed.samplerState[i] & (1 << j))
+                wined3d_device_set_sampler_state(device, stage, j, state->sampler_states[i][j]);
+        }
+    }
+
+    for (i = 0; i < ARRAY_SIZE(state->transforms); ++i)
+    {
+        if (stateblock->changed.transform[i >> 5] & (1u << (i & 0x1f)))
+            wined3d_device_set_transform(device, i, &state->transforms[i]);
+    }
+
+    if (stateblock->changed.indices)
+        wined3d_device_set_index_buffer(device, state->index_buffer, state->index_format, 0);
+    wined3d_device_set_base_vertex_index(device, state->base_vertex_index);
+    if (stateblock->changed.vertexDecl)
+        wined3d_device_set_vertex_declaration(device, state->vertex_declaration);
+    if (stateblock->changed.material)
+        wined3d_device_set_material(device, &state->material);
+    if (stateblock->changed.viewport)
+        wined3d_device_set_viewports(device, 1, &state->viewport);
+    if (stateblock->changed.scissorRect)
+        wined3d_device_set_scissor_rects(device, 1, &state->scissor_rect);
+
+    for (i = 0; i < ARRAY_SIZE(state->streams); ++i)
+    {
+        if (stateblock->changed.streamSource & (1u << i))
+            wined3d_device_set_stream_source(device, i, state->streams[i].buffer,
+                    state->streams[i].offset, state->streams[i].stride);
+        if (stateblock->changed.streamFreq & (1u << i))
+            wined3d_device_set_stream_source_freq(device, i,
+                    state->streams[i].frequency | state->streams[i].flags);
+    }
+
+    for (i = 0; i < ARRAY_SIZE(state->textures); ++i)
+    {
+        DWORD stage = i;
+        if (stage >= WINED3D_MAX_FRAGMENT_SAMPLERS)
+            stage += WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS;
+        if (stateblock->changed.textures & (1u << i))
+            wined3d_device_set_texture(device, stage, state->textures[i]);
+    }
+
+    for (i = 0; i < ARRAY_SIZE(state->clip_planes); ++i)
+    {
+        if (stateblock->changed.clipplane & (1u << i))
+            wined3d_device_set_clip_plane(device, i, &state->clip_planes[i]);
+    }
+
+    memset(&stateblock->changed, 0, sizeof(stateblock->changed));
+
+    TRACE("Applied stateblock %p.\n", stateblock);
+}
+
 HRESULT CDECL wined3d_device_get_device_caps(const struct wined3d_device *device, struct wined3d_caps *caps)
 {
     TRACE("device %p, caps %p.\n", device, caps);
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c
index f6d36f8c25..f21cd0f187 100644
--- a/dlls/wined3d/stateblock.c
+++ b/dlls/wined3d/stateblock.c
@@ -1037,7 +1037,6 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock,
         if (state->vs)
             wined3d_shader_decref(state->vs);
         state->vs = stateblock->stateblock_state.vs;
-        wined3d_device_set_vertex_shader(device, stateblock->stateblock_state.vs);
     }
 
     /* Vertex Shader Constants. */
@@ -1046,21 +1045,18 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock,
         unsigned int idx = stateblock->contained_vs_consts_f[i];
 
         state->vs_consts_f[idx] = stateblock->stateblock_state.vs_consts_f[idx];
-        wined3d_device_set_vs_consts_f(device, idx, 1, &stateblock->stateblock_state.vs_consts_f[idx]);
     }
     for (i = 0; i < stateblock->num_contained_vs_consts_i; ++i)
     {
         unsigned int idx = stateblock->contained_vs_consts_i[i];
 
         state->vs_consts_i[idx] = stateblock->stateblock_state.vs_consts_i[idx];
-        wined3d_device_set_vs_consts_i(device, idx, 1, &stateblock->stateblock_state.vs_consts_i[idx]);
     }
     for (i = 0; i < stateblock->num_contained_vs_consts_b; ++i)
     {
         unsigned int idx = stateblock->contained_vs_consts_b[i];
 
         state->vs_consts_b[idx] = stateblock->stateblock_state.vs_consts_b[idx];
-        wined3d_device_set_vs_consts_b(device, idx, 1, &stateblock->stateblock_state.vs_consts_b[idx]);
     }
 
     for (i = 0; i < ARRAY_SIZE(stateblock->stateblock_state.light_state->light_map); ++i)
@@ -1075,8 +1071,6 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock,
             {
                 wined3d_light_state_enable_light(state->light_state, &device->adapter->d3d_info, new_light, light->glIndex != -1);
             }
-            wined3d_device_set_light(device, light->OriginalIndex, &light->OriginalParms);
-            wined3d_device_set_light_enable(device, light->OriginalIndex, light->glIndex != -1);
         }
     }
 
@@ -1087,7 +1081,6 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock,
         if (state->ps)
             wined3d_shader_decref(state->ps);
         state->ps = stateblock->stateblock_state.ps;
-        wined3d_device_set_pixel_shader(device, stateblock->stateblock_state.ps);
     }
 
     /* Pixel Shader Constants. */
@@ -1096,21 +1089,18 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock,
         unsigned int idx = stateblock->contained_ps_consts_f[i];
 
         state->ps_consts_f[idx] = stateblock->stateblock_state.ps_consts_f[idx];
-        wined3d_device_set_ps_consts_f(device, idx, 1, &stateblock->stateblock_state.ps_consts_f[idx]);
     }
     for (i = 0; i < stateblock->num_contained_ps_consts_i; ++i)
     {
         unsigned int idx = stateblock->contained_ps_consts_i[i];
 
         state->ps_consts_i[idx] = stateblock->stateblock_state.ps_consts_i[idx];
-        wined3d_device_set_ps_consts_i(device, idx, 1, &stateblock->stateblock_state.ps_consts_i[idx]);
     }
     for (i = 0; i < stateblock->num_contained_ps_consts_b; ++i)
     {
         unsigned int idx = stateblock->contained_ps_consts_b[i];
 
         state->ps_consts_b[idx] = stateblock->stateblock_state.ps_consts_b[idx];
-        wined3d_device_set_ps_consts_b(device, idx, 1, &stateblock->stateblock_state.ps_consts_b[idx]);
     }
 
     /* Render states. */
@@ -1119,14 +1109,6 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock,
         enum wined3d_render_state rs = stateblock->contained_render_states[i];
 
         state->rs[rs] = stateblock->stateblock_state.rs[rs];
-        if (rs == WINED3D_RS_BLENDFACTOR)
-        {
-            struct wined3d_color color;
-            wined3d_color_from_d3dcolor(&color, stateblock->stateblock_state.rs[rs]);
-            wined3d_device_set_blend_state(device, NULL, &color);
-        }
-        else
-            wined3d_device_set_render_state(device, rs, stateblock->stateblock_state.rs[rs]);
     }
 
     /* Texture states. */
@@ -1136,8 +1118,6 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock,
         DWORD texture_state = stateblock->contained_tss_states[i].state;
 
         state->texture_states[stage][texture_state] = stateblock->stateblock_state.texture_states[stage][texture_state];
-        wined3d_device_set_texture_stage_state(device, stage, texture_state,
-                stateblock->stateblock_state.texture_states[stage][texture_state]);
     }
 
     /* Sampler states. */
@@ -1145,11 +1125,8 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock,
     {
         DWORD stage = stateblock->contained_sampler_states[i].stage;
         DWORD sampler_state = stateblock->contained_sampler_states[i].state;
-        DWORD value = stateblock->stateblock_state.sampler_states[stage][sampler_state];
 
-        state->sampler_states[stage][sampler_state] = value;
-        if (stage >= WINED3D_MAX_FRAGMENT_SAMPLERS) stage += WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS;
-        wined3d_device_set_sampler_state(device, stage, sampler_state, value);
+        state->sampler_states[stage][sampler_state] = stateblock->stateblock_state.sampler_states[stage][sampler_state];
     }
 
     /* Transform states. */
@@ -1158,7 +1135,6 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock,
         enum wined3d_transform_state transform = stateblock->contained_transform_states[i];
 
         state->transforms[transform] = stateblock->stateblock_state.transforms[transform];
-        wined3d_device_set_transform(device, transform, &stateblock->stateblock_state.transforms[transform]);
     }
 
     if (stateblock->changed.indices)
@@ -1170,10 +1146,6 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock,
         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->stateblock_state.vertex_declaration)
@@ -1183,34 +1155,20 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock,
         if (state->vertex_declaration)
             wined3d_vertex_declaration_decref(state->vertex_declaration);
         state->vertex_declaration = stateblock->stateblock_state.vertex_declaration;
-        wined3d_device_set_vertex_declaration(device, stateblock->stateblock_state.vertex_declaration);
     }
 
     if (stateblock->changed.material)
-    {
         state->material = stateblock->stateblock_state.material;
-        wined3d_device_set_material(device, &stateblock->stateblock_state.material);
-    }
 
     if (stateblock->changed.viewport)
-    {
         state->viewport = stateblock->stateblock_state.viewport;
 
-        wined3d_device_set_viewports(device, 1, &stateblock->stateblock_state.viewport);
-    }
-
     if (stateblock->changed.scissorRect)
-    {
         state->scissor_rect = stateblock->stateblock_state.scissor_rect;
 
-        wined3d_device_set_scissor_rects(device, 1, &stateblock->stateblock_state.scissor_rect);
-    }
-
     map = stateblock->changed.streamSource;
     for (i = 0; map; map >>= 1, ++i)
     {
-        unsigned int offset, stride;
-
         if (!(map & 1)) continue;
 
         if (stateblock->stateblock_state.streams[i].buffer)
@@ -1218,14 +1176,8 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock,
         if (state->streams[i].buffer)
                 wined3d_buffer_decref(state->streams[i].buffer);
         state->streams[i].buffer = stateblock->stateblock_state.streams[i].buffer;
-
-        offset = stateblock->stateblock_state.streams[i].offset;
-        stride = stateblock->stateblock_state.streams[i].stride;
-
-        state->streams[i].stride = stride;
-        state->streams[i].offset = offset;
-        wined3d_device_set_stream_source(device, i,
-                stateblock->stateblock_state.streams[i].buffer, offset, stride);
+        state->streams[i].offset = stateblock->stateblock_state.streams[i].offset;
+        state->streams[i].stride = stateblock->stateblock_state.streams[i].stride;
     }
 
     map = stateblock->changed.streamFreq;
@@ -1235,25 +1187,18 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock,
 
         state->streams[i].frequency = stateblock->stateblock_state.streams[i].frequency;
         state->streams[i].flags = stateblock->stateblock_state.streams[i].flags;
-
-        wined3d_device_set_stream_source_freq(device, i,
-                stateblock->stateblock_state.streams[i].frequency | stateblock->stateblock_state.streams[i].flags);
     }
 
     map = stateblock->changed.textures;
     for (i = 0; map; map >>= 1, ++i)
     {
-        DWORD stage;
-
         if (!(map & 1)) continue;
 
-        stage = i < WINED3D_MAX_FRAGMENT_SAMPLERS ? i : WINED3DVERTEXTEXTURESAMPLER0 + i - WINED3D_MAX_FRAGMENT_SAMPLERS;
         if (stateblock->stateblock_state.textures[i])
             wined3d_texture_incref(stateblock->stateblock_state.textures[i]);
         if (state->textures[i])
             wined3d_texture_decref(state->textures[i]);
         state->textures[i] = stateblock->stateblock_state.textures[i];
-        wined3d_device_set_texture(device, stage, stateblock->stateblock_state.textures[i]);
     }
 
     map = stateblock->changed.clipplane;
@@ -1262,9 +1207,10 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock,
         if (!(map & 1)) continue;
 
         state->clip_planes[i] = stateblock->stateblock_state.clip_planes[i];
-        wined3d_device_set_clip_plane(device, i, &stateblock->stateblock_state.clip_planes[i]);
     }
 
+    wined3d_device_apply_stateblock(device, device_state);
+
     TRACE("Applied stateblock %p.\n", stateblock);
 }
 
diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec
index e03c57055b..c8ef442c72 100644
--- a/dlls/wined3d/wined3d.spec
+++ b/dlls/wined3d/wined3d.spec
@@ -37,6 +37,7 @@
 @ cdecl wined3d_buffer_incref(ptr)
 
 @ cdecl wined3d_device_acquire_focus_window(ptr ptr)
+@ cdecl wined3d_device_apply_stateblock(ptr ptr)
 @ cdecl wined3d_device_begin_scene(ptr)
 @ cdecl wined3d_device_clear(ptr long ptr long ptr float long)
 @ cdecl wined3d_device_clear_rendertarget_view(ptr ptr ptr long ptr float long)
diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h
index 9cdf18633c..4306f5ae21 100644
--- a/include/wine/wined3d.h
+++ b/include/wine/wined3d.h
@@ -2289,6 +2289,7 @@ struct wined3d_resource * __cdecl wined3d_buffer_get_resource(struct wined3d_buf
 ULONG __cdecl wined3d_buffer_incref(struct wined3d_buffer *buffer);
 
 HRESULT __cdecl wined3d_device_acquire_focus_window(struct wined3d_device *device, HWND window);
+void __cdecl wined3d_device_apply_stateblock(struct wined3d_device *device, struct wined3d_stateblock *stateblock);
 HRESULT __cdecl wined3d_device_begin_scene(struct wined3d_device *device);
 HRESULT __cdecl wined3d_device_clear(struct wined3d_device *device, DWORD rect_count, const RECT *rects, DWORD flags,
         const struct wined3d_color *color, float z, DWORD stencil);
-- 
2.25.0




More information about the wine-devel mailing list