Matteo Bruni : d3d9: Keep track of D3DUSAGE_AUTOGENMIPMAP textures in the d3d9 device.

Alexandre Julliard julliard at winehq.org
Tue Feb 12 16:36:37 CST 2019


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

Author: Matteo Bruni <mbruni at codeweavers.com>
Date:   Mon Feb 11 18:21:04 2019 +0100

d3d9: Keep track of D3DUSAGE_AUTOGENMIPMAP textures in the d3d9 device.

Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/d3d9/d3d9_private.h |  2 ++
 dlls/d3d9/device.c       | 21 +++++++++++++++++++--
 dlls/d3d9/stateblock.c   | 16 +++++++++++++++-
 3 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h
index 1032f8e..3fe0376 100644
--- a/dlls/d3d9/d3d9_private.h
+++ b/dlls/d3d9/d3d9_private.h
@@ -111,6 +111,8 @@ struct d3d9_device
     DWORD recording : 1;
     DWORD padding : 11;
 
+    DWORD auto_mipmaps; /* D3D9_MAX_TEXTURE_UNITS */
+
     unsigned int max_user_clip_planes;
 
     UINT implicit_swapchain_count;
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index 98ada03..6cc3f18 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -991,6 +991,7 @@ static HRESULT d3d9_device_reset(struct d3d9_device *device,
         if (!extended)
         {
             device->recording = FALSE;
+            device->auto_mipmaps = 0;
             wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZENABLE,
                     !!swapchain_desc.enable_auto_depth_stencil);
         }
@@ -2456,6 +2457,19 @@ static HRESULT WINAPI d3d9_device_SetTexture(IDirect3DDevice9Ex *iface, DWORD st
     wined3d_mutex_lock();
     hr = wined3d_device_set_texture(device->wined3d_device, stage,
             texture_impl ? texture_impl->wined3d_texture : NULL);
+    if (SUCCEEDED(hr) && !device->recording)
+    {
+        unsigned int i = stage < 16 || (stage >= D3DVERTEXTEXTURESAMPLER0 && stage <= D3DVERTEXTEXTURESAMPLER3)
+                ? stage < 16 ? stage : stage - D3DVERTEXTEXTURESAMPLER0 + 16 : ~0u;
+
+        if (i < D3D9_MAX_TEXTURE_UNITS)
+        {
+            if (texture_impl && texture_impl->usage & D3DUSAGE_AUTOGENMIPMAP)
+                device->auto_mipmaps |= 1u << i;
+            else
+                device->auto_mipmaps &= ~(1u << i);
+        }
+    }
     wined3d_mutex_unlock();
 
     return hr;
@@ -2700,10 +2714,13 @@ static float WINAPI d3d9_device_GetNPatchMode(IDirect3DDevice9Ex *iface)
 static void d3d9_generate_auto_mipmaps(struct d3d9_device *device)
 {
     struct wined3d_texture *texture;
-    unsigned int i, stage;
+    unsigned int i, stage, map;
 
-    for (i = 0; i < D3D9_MAX_TEXTURE_UNITS; ++i)
+    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)))
             d3d9_texture_gen_auto_mipmap(wined3d_texture_get_parent(texture));
diff --git a/dlls/d3d9/stateblock.c b/dlls/d3d9/stateblock.c
index 8431ef7..14f47d9 100644
--- a/dlls/d3d9/stateblock.c
+++ b/dlls/d3d9/stateblock.c
@@ -109,10 +109,12 @@ static HRESULT WINAPI d3d9_stateblock_Capture(IDirect3DStateBlock9 *iface)
 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;
     HRESULT hr;
 
@@ -134,6 +136,18 @@ static HRESULT WINAPI d3d9_stateblock_Apply(IDirect3DStateBlock9 *iface)
     }
     device->sysmem_ib = (wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &format, &offset))
             && (buffer = wined3d_buffer_get_parent(wined3d_buffer)) && buffer->draw_buffer;
+    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))
+                && (texture = wined3d_texture_get_parent(wined3d_texture))
+                && texture->usage & D3DUSAGE_AUTOGENMIPMAP)
+            device->auto_mipmaps |= 1u << i;
+        else
+            device->auto_mipmaps &= ~(1u << i);
+    }
     wined3d_mutex_unlock();
 
     return D3D_OK;




More information about the wine-cvs mailing list