Zebediah Figura : d3d9: Retrieve textures from the primary stateblock.

Alexandre Julliard julliard at winehq.org
Thu Feb 13 15:36:31 CST 2020


Module: wine
Branch: master
Commit: aa18b69a66d12098cc0647ef58adacc431a2cce2
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=aa18b69a66d12098cc0647ef58adacc431a2cce2

Author: Zebediah Figura <z.figura12 at gmail.com>
Date:   Wed Feb 12 09:21:49 2020 -0600

d3d9: Retrieve textures from the primary stateblock.

Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/d3d9/device.c     | 21 ++++++++++++++++-----
 dlls/d3d9/stateblock.c |  6 ++----
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index 1ff178881c..cfa1d14cce 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -2516,6 +2516,7 @@ static HRESULT WINAPI d3d9_device_GetTexture(IDirect3DDevice9Ex *iface, DWORD st
 {
     struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
     struct wined3d_texture *wined3d_texture = NULL;
+    const struct wined3d_stateblock_state *state;
     struct d3d9_texture *texture_impl;
 
     TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
@@ -2523,8 +2524,19 @@ static HRESULT WINAPI d3d9_device_GetTexture(IDirect3DDevice9Ex *iface, DWORD st
     if (!texture)
         return D3DERR_INVALIDCALL;
 
+    if (stage >= WINED3DVERTEXTEXTURESAMPLER0 && stage <= WINED3DVERTEXTEXTURESAMPLER3)
+        stage -= (WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS);
+
+    if (stage >= ARRAY_SIZE(state->textures))
+    {
+        WARN("Ignoring invalid stage %u.\n", stage);
+        *texture = NULL;
+        return D3D_OK;
+    }
+
     wined3d_mutex_lock();
-    if ((wined3d_texture = wined3d_device_get_texture(device->wined3d_device, stage)))
+    state = wined3d_stateblock_get_state(device->state);
+    if ((wined3d_texture = state->textures[stage]))
     {
         texture_impl = wined3d_texture_get_parent(wined3d_texture);
         *texture = &texture_impl->IDirect3DBaseTexture9_iface;
@@ -2815,16 +2827,15 @@ static float WINAPI d3d9_device_GetNPatchMode(IDirect3DDevice9Ex *iface)
 /* wined3d critical section must be taken by the caller. */
 static void d3d9_generate_auto_mipmaps(struct d3d9_device *device)
 {
+    const struct wined3d_stateblock_state *state = wined3d_stateblock_get_state(device->state);
     struct wined3d_texture *texture;
-    unsigned int i, stage, map;
+    unsigned int i, map;
 
     map = device->auto_mipmaps;
     while (map)
     {
         i = wined3d_bit_scan(&map);
-
-        stage = i >= 16 ? i - 16 + D3DVERTEXTEXTURESAMPLER0 : i;
-        if ((texture = wined3d_device_get_texture(device->wined3d_device, stage)))
+        if ((texture = state->textures[i]))
             d3d9_texture_gen_auto_mipmap(wined3d_texture_get_parent(texture));
     }
 }
diff --git a/dlls/d3d9/stateblock.c b/dlls/d3d9/stateblock.c
index dfb8d8d755..a65fa1cd8d 100644
--- a/dlls/d3d9/stateblock.c
+++ b/dlls/d3d9/stateblock.c
@@ -116,9 +116,9 @@ static HRESULT WINAPI d3d9_stateblock_Apply(IDirect3DStateBlock9 *iface)
 {
     struct d3d9_stateblock *stateblock = impl_from_IDirect3DStateBlock9(iface);
     struct wined3d_texture *wined3d_texture;
-    unsigned int i, offset, stride, stage;
     struct wined3d_buffer *wined3d_buffer;
     struct d3d9_vertexbuffer *buffer;
+    unsigned int i, offset, stride;
     enum wined3d_format_id format;
     struct d3d9_texture *texture;
     struct d3d9_device *device;
@@ -151,9 +151,7 @@ static HRESULT WINAPI d3d9_stateblock_Apply(IDirect3DStateBlock9 *iface)
     device->auto_mipmaps = 0;
     for (i = 0; i < D3D9_MAX_TEXTURE_UNITS; ++i)
     {
-        stage = i >= 16 ? i - 16 + D3DVERTEXTEXTURESAMPLER0 : i;
-
-        if ((wined3d_texture = wined3d_device_get_texture(device->wined3d_device, stage))
+        if ((wined3d_texture = wined3d_stateblock_get_state(device->state)->textures[i])
                 && (texture = wined3d_texture_get_parent(wined3d_texture))
                 && texture->usage & D3DUSAGE_AUTOGENMIPMAP)
             device->auto_mipmaps |= 1u << i;




More information about the wine-cvs mailing list