[PATCH 3/5] d3d9: Retrieve vertex shader constants from the primary stateblock.

Zebediah Figura z.figura12 at gmail.com
Fri Feb 7 22:07:10 CST 2020


Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
 dlls/d3d9/d3d9_private.h |  2 +-
 dlls/d3d9/device.c       | 35 ++++++++++++++++++++++-------------
 2 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h
index a7072162d5..bc9a3b98b2 100644
--- a/dlls/d3d9/d3d9_private.h
+++ b/dlls/d3d9/d3d9_private.h
@@ -114,7 +114,7 @@ struct d3d9_device
 
     DWORD auto_mipmaps; /* D3D9_MAX_TEXTURE_UNITS */
 
-    unsigned int max_user_clip_planes;
+    unsigned int max_user_clip_planes, vs_uniform_count;
 
     UINT implicit_swapchain_count;
     struct wined3d_swapchain **implicit_swapchains;
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index 6f35b3caab..ad2f04dd04 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -3570,23 +3570,24 @@ static HRESULT WINAPI d3d9_device_GetVertexShaderConstantF(IDirect3DDevice9Ex *i
         UINT reg_idx, float *data, UINT count)
 {
     struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
-    HRESULT hr;
 
     TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
 
-    if (reg_idx + count > D3D9_MAX_VERTEX_SHADER_CONSTANTF)
+    if (!data)
+        return D3DERR_INVALIDCALL;
+
+    if (reg_idx >= device->vs_uniform_count || reg_idx + count > device->vs_uniform_count)
     {
         WARN("Trying to access %u constants, but d3d9 only supports %u\n",
-             reg_idx + count, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
+             reg_idx + count, device->vs_uniform_count);
         return D3DERR_INVALIDCALL;
     }
 
     wined3d_mutex_lock();
-    hr = wined3d_device_get_vs_consts_f(device->wined3d_device,
-            reg_idx, count, (struct wined3d_vec4 *)data);
+    memcpy(data, &wined3d_stateblock_get_state(device->state)->vs_consts_f[reg_idx], count * sizeof(struct wined3d_vec4));
     wined3d_mutex_unlock();
 
-    return hr;
+    return D3D_OK;
 }
 
 static HRESULT WINAPI d3d9_device_SetVertexShaderConstantI(IDirect3DDevice9Ex *iface,
@@ -3612,16 +3613,19 @@ static HRESULT WINAPI d3d9_device_GetVertexShaderConstantI(IDirect3DDevice9Ex *i
         UINT reg_idx, int *data, UINT count)
 {
     struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
-    HRESULT hr;
 
     TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
 
+    if (!data || reg_idx >= WINED3D_MAX_CONSTS_I)
+        return WINED3DERR_INVALIDCALL;
+    if (count > WINED3D_MAX_CONSTS_I - reg_idx)
+        count = WINED3D_MAX_CONSTS_I - reg_idx;
+
     wined3d_mutex_lock();
-    hr = wined3d_device_get_vs_consts_i(device->wined3d_device,
-            reg_idx, count, (struct wined3d_ivec4 *)data);
+    memcpy(data, &wined3d_stateblock_get_state(device->state)->vs_consts_i[reg_idx], count * sizeof(struct wined3d_ivec4));
     wined3d_mutex_unlock();
 
-    return hr;
+    return D3D_OK;
 }
 
 static HRESULT WINAPI d3d9_device_SetVertexShaderConstantB(IDirect3DDevice9Ex *iface,
@@ -3645,15 +3649,19 @@ static HRESULT WINAPI d3d9_device_GetVertexShaderConstantB(IDirect3DDevice9Ex *i
         UINT reg_idx, BOOL *data, UINT count)
 {
     struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
-    HRESULT hr;
 
     TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
 
+    if (!data || reg_idx >= WINED3D_MAX_CONSTS_B)
+        return WINED3DERR_INVALIDCALL;
+    if (count > WINED3D_MAX_CONSTS_B - reg_idx)
+        count = WINED3D_MAX_CONSTS_B - reg_idx;
+
     wined3d_mutex_lock();
-    hr = wined3d_device_get_vs_consts_b(device->wined3d_device, reg_idx, count, data);
+    memcpy(data, &wined3d_stateblock_get_state(device->state)->vs_consts_b[reg_idx], count * sizeof(*data));
     wined3d_mutex_unlock();
 
-    return hr;
+    return D3D_OK;
 }
 
 static HRESULT WINAPI d3d9_device_SetStreamSource(IDirect3DDevice9Ex *iface,
@@ -4609,6 +4617,7 @@ HRESULT device_init(struct d3d9_device *device, struct d3d9 *parent, struct wine
 
     wined3d_get_device_caps(wined3d, adapter, device_type, &caps);
     device->max_user_clip_planes = caps.MaxUserClipPlanes;
+    device->vs_uniform_count = caps.MaxVertexShaderConst;
     if (flags & D3DCREATE_ADAPTERGROUP_DEVICE)
         count = caps.NumberOfAdaptersInGroup;
 
-- 
2.25.0




More information about the wine-devel mailing list