[PATCH 1/6] d3d9: Retrieve textures from the primary stateblock.

Zebediah Figura z.figura12 at gmail.com
Tue Feb 11 19:19:13 CST 2020


Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
 dlls/d3d9/device.c     | 24 +++++++++++++++++-------
 dlls/d3d9/stateblock.c |  6 ++----
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index 1ff178881c..3d2dd38d9c 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -2512,19 +2512,30 @@ static HRESULT WINAPI d3d9_device_GetClipStatus(IDirect3DDevice9Ex *iface, D3DCL
     return hr;
 }
 
-static HRESULT WINAPI d3d9_device_GetTexture(IDirect3DDevice9Ex *iface, DWORD stage, IDirect3DBaseTexture9 **texture)
+static HRESULT WINAPI d3d9_device_GetTexture(IDirect3DDevice9Ex *iface,
+        DWORD sampler_idx, IDirect3DBaseTexture9 **texture)
 {
     struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
     struct wined3d_texture *wined3d_texture = NULL;
     struct d3d9_texture *texture_impl;
 
-    TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
+    TRACE("iface %p, sampler_idx %u, texture %p.\n", iface, sampler_idx, texture);
 
     if (!texture)
         return D3DERR_INVALIDCALL;
 
+    if (sampler_idx >= WINED3DVERTEXTEXTURESAMPLER0 && sampler_idx <= WINED3DVERTEXTEXTURESAMPLER3)
+        sampler_idx -= (WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS);
+
+    if (sampler_idx >= WINED3D_MAX_COMBINED_SAMPLERS)
+    {
+        WARN("Invalid sampler %u.\n", sampler_idx);
+        *texture = NULL;
+        return D3D_OK;
+    }
+
     wined3d_mutex_lock();
-    if ((wined3d_texture = wined3d_device_get_texture(device->wined3d_device, stage)))
+    if ((wined3d_texture = wined3d_stateblock_get_state(device->state)->textures[sampler_idx]))
     {
         texture_impl = wined3d_texture_get_parent(wined3d_texture);
         *texture = &texture_impl->IDirect3DBaseTexture9_iface;
@@ -2815,16 +2826,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;
-- 
2.25.0




More information about the wine-devel mailing list