From 5323042f7a2aa69c01bce8248a457bcc8533c61c Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Sat, 18 Feb 2023 15:45:58 -0600 Subject: [PATCH] wined3d: Add helpers to retrieve shader constants from a wined3d_stateblock. --- dlls/d3d8/device.c | 26 ++++-------- dlls/d3d9/device.c | 71 ++++++++------------------------ dlls/wined3d/stateblock.c | 86 +++++++++++++++++++++++++++++++++++++++ dlls/wined3d/wined3d.spec | 6 +++ include/wine/wined3d.h | 12 ++++++ 5 files changed, 129 insertions(+), 72 deletions(-) diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c index 7a95654d343..e13a1ad465a 100644 --- a/dlls/d3d8/device.c +++ b/dlls/d3d8/device.c @@ -3051,26 +3051,15 @@ static HRESULT WINAPI d3d8_device_GetVertexShaderConstant(IDirect3DDevice8 *ifac DWORD start_idx, void *constants, DWORD count) { struct d3d8_device *device = impl_from_IDirect3DDevice8(iface); - const struct wined3d_vec4 *src; + HRESULT hr; TRACE("iface %p, start_idx %lu, constants %p, count %lu.\n", iface, start_idx, constants, count); - if (!constants) - return D3DERR_INVALIDCALL; - - if (!wined3d_bound_range(start_idx, count, device->vs_uniform_count)) - { - WARN("Trying to access %lu constants, but d3d8 only supports %u.\n", - start_idx + count, device->vs_uniform_count); - return D3DERR_INVALIDCALL; - } - wined3d_mutex_lock(); - src = device->stateblock_state->vs_consts_f; - memcpy(constants, &src[start_idx], count * sizeof(*src)); + hr = wined3d_stateblock_get_vs_consts_f(device->state, start_idx, count, constants); wined3d_mutex_unlock(); - return D3D_OK; + return hr; } static HRESULT WINAPI d3d8_device_GetVertexShaderDeclaration(IDirect3DDevice8 *iface, @@ -3353,19 +3342,18 @@ static HRESULT WINAPI d3d8_device_GetPixelShaderConstant(IDirect3DDevice8 *iface DWORD start_idx, void *constants, DWORD count) { struct d3d8_device *device = impl_from_IDirect3DDevice8(iface); - const struct wined3d_vec4 *src; + HRESULT hr; TRACE("iface %p, start_idx %lu, constants %p, count %lu.\n", iface, start_idx, constants, count); - if (!constants || !wined3d_bound_range(start_idx, count, D3D8_MAX_PIXEL_SHADER_CONSTANTF)) + if (!wined3d_bound_range(start_idx, count, D3D8_MAX_PIXEL_SHADER_CONSTANTF)) return WINED3DERR_INVALIDCALL; wined3d_mutex_lock(); - src = device->stateblock_state->ps_consts_f; - memcpy(constants, &src[start_idx], count * sizeof(*src)); + hr = wined3d_stateblock_get_ps_consts_f(device->state, start_idx, count, constants); wined3d_mutex_unlock(); - return D3D_OK; + return hr; } static HRESULT WINAPI d3d8_device_GetPixelShaderFunction(IDirect3DDevice8 *iface, diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index b4bf51f9426..4351f005eb9 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -3678,26 +3678,15 @@ static HRESULT WINAPI d3d9_device_GetVertexShaderConstantF(IDirect3DDevice9Ex *i UINT start_idx, float *constants, UINT count) { struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface); - const struct wined3d_vec4 *src; + HRESULT hr; TRACE("iface %p, start_idx %u, constants %p, count %u.\n", iface, start_idx, constants, count); - if (!constants) - return D3DERR_INVALIDCALL; - - if (!wined3d_bound_range(start_idx, count, device->vs_uniform_count)) - { - WARN("Trying to access %u constants, but d3d9 only supports %u\n", - start_idx + count, device->vs_uniform_count); - return D3DERR_INVALIDCALL; - } - wined3d_mutex_lock(); - src = device->stateblock_state->vs_consts_f; - memcpy(constants, &src[start_idx], count * sizeof(*src)); + hr = wined3d_stateblock_get_vs_consts_f(device->state, start_idx, count, (struct wined3d_vec4 *)constants); wined3d_mutex_unlock(); - return D3D_OK; + return hr; } static HRESULT WINAPI d3d9_device_SetVertexShaderConstantI(IDirect3DDevice9Ex *iface, @@ -3720,21 +3709,15 @@ static HRESULT WINAPI d3d9_device_GetVertexShaderConstantI(IDirect3DDevice9Ex *i UINT start_idx, int *constants, UINT count) { struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface); - const struct wined3d_ivec4 *src; + HRESULT hr; TRACE("iface %p, start_idx %u, constants %p, count %u.\n", iface, start_idx, constants, count); - if (!constants || start_idx >= WINED3D_MAX_CONSTS_I) - return WINED3DERR_INVALIDCALL; - if (count > WINED3D_MAX_CONSTS_I - start_idx) - count = WINED3D_MAX_CONSTS_I - start_idx; - wined3d_mutex_lock(); - src = device->stateblock_state->vs_consts_i; - memcpy(constants, &src[start_idx], count * sizeof(*src)); + hr = wined3d_stateblock_get_vs_consts_i(device->state, start_idx, count, (struct wined3d_ivec4 *)constants); wined3d_mutex_unlock(); - return D3D_OK; + return hr; } static HRESULT WINAPI d3d9_device_SetVertexShaderConstantB(IDirect3DDevice9Ex *iface, @@ -3756,19 +3739,15 @@ static HRESULT WINAPI d3d9_device_GetVertexShaderConstantB(IDirect3DDevice9Ex *i UINT start_idx, BOOL *constants, UINT count) { struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface); + HRESULT hr; TRACE("iface %p, start_idx %u, constants %p, count %u.\n", iface, start_idx, constants, count); - if (!constants || start_idx >= WINED3D_MAX_CONSTS_B) - return WINED3DERR_INVALIDCALL; - if (count > WINED3D_MAX_CONSTS_B - start_idx) - count = WINED3D_MAX_CONSTS_B - start_idx; - wined3d_mutex_lock(); - memcpy(constants, &device->stateblock_state->vs_consts_b[start_idx], count * sizeof(*constants)); + hr = wined3d_stateblock_get_vs_consts_b(device->state, start_idx, count, constants); wined3d_mutex_unlock(); - return D3D_OK; + return hr; } static HRESULT WINAPI d3d9_device_SetStreamSource(IDirect3DDevice9Ex *iface, @@ -4028,19 +4007,15 @@ static HRESULT WINAPI d3d9_device_GetPixelShaderConstantF(IDirect3DDevice9Ex *if UINT start_idx, float *constants, UINT count) { struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface); - const struct wined3d_vec4 *src; + HRESULT hr; TRACE("iface %p, start_idx %u, constants %p, count %u.\n", iface, start_idx, constants, count); - if (!constants || !wined3d_bound_range(start_idx, count, WINED3D_MAX_PS_CONSTS_F)) - return WINED3DERR_INVALIDCALL; - wined3d_mutex_lock(); - src = device->stateblock_state->ps_consts_f; - memcpy(constants, &src[start_idx], count * sizeof(*src)); + hr = wined3d_stateblock_get_ps_consts_f(device->state, start_idx, count, (struct wined3d_vec4 *)constants); wined3d_mutex_unlock(); - return D3D_OK; + return hr; } static HRESULT WINAPI d3d9_device_SetPixelShaderConstantI(IDirect3DDevice9Ex *iface, @@ -4063,21 +4038,15 @@ static HRESULT WINAPI d3d9_device_GetPixelShaderConstantI(IDirect3DDevice9Ex *if UINT start_idx, int *constants, UINT count) { struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface); - const struct wined3d_ivec4 *src; + HRESULT hr; TRACE("iface %p, start_idx %u, constants %p, count %u.\n", iface, start_idx, constants, count); - if (!constants || start_idx >= WINED3D_MAX_CONSTS_I) - return WINED3DERR_INVALIDCALL; - if (count > WINED3D_MAX_CONSTS_I - start_idx) - count = WINED3D_MAX_CONSTS_I - start_idx; - wined3d_mutex_lock(); - src = device->stateblock_state->ps_consts_i; - memcpy(constants, &src[start_idx], count * sizeof(*src)); + hr = wined3d_stateblock_get_ps_consts_i(device->state, start_idx, count, (struct wined3d_ivec4 *)constants); wined3d_mutex_unlock(); - return D3D_OK; + return hr; } static HRESULT WINAPI d3d9_device_SetPixelShaderConstantB(IDirect3DDevice9Ex *iface, @@ -4099,19 +4068,15 @@ static HRESULT WINAPI d3d9_device_GetPixelShaderConstantB(IDirect3DDevice9Ex *if UINT start_idx, BOOL *constants, UINT count) { struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface); + HRESULT hr; TRACE("iface %p, start_idx %u, constants %p, count %u.\n", iface, start_idx, constants, count); - if (!constants || start_idx >= WINED3D_MAX_CONSTS_I) - return WINED3DERR_INVALIDCALL; - if (count > WINED3D_MAX_CONSTS_I - start_idx) - count = WINED3D_MAX_CONSTS_I - start_idx; - wined3d_mutex_lock(); - memcpy(constants, &device->stateblock_state->ps_consts_b[start_idx], count * sizeof(*constants)); + hr = wined3d_stateblock_get_ps_consts_b(device->state, start_idx, count, constants); wined3d_mutex_unlock(); - return D3D_OK; + return hr; } static HRESULT WINAPI d3d9_device_DrawRectPatch(IDirect3DDevice9Ex *iface, UINT handle, diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index b118daeba19..da5c79c7813 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -1245,6 +1245,50 @@ HRESULT CDECL wined3d_stateblock_set_vs_consts_b(struct wined3d_stateblock *stat return WINED3D_OK; } +HRESULT CDECL wined3d_stateblock_get_vs_consts_f(struct wined3d_stateblock *stateblock, + unsigned int start_idx, unsigned int count, struct wined3d_vec4 *constants) +{ + const struct wined3d_d3d_info *d3d_info = &stateblock->device->adapter->d3d_info; + + TRACE("stateblock %p, start_idx %u, count %u, constants %p.\n", stateblock, start_idx, count, constants); + + if (!constants || !wined3d_bound_range(start_idx, count, d3d_info->limits.vs_uniform_count)) + return WINED3DERR_INVALIDCALL; + + memcpy(constants, &stateblock->stateblock_state.vs_consts_f[start_idx], count * sizeof(*constants)); + return WINED3D_OK; +} + +HRESULT CDECL wined3d_stateblock_get_vs_consts_i(struct wined3d_stateblock *stateblock, + unsigned int start_idx, unsigned int count, struct wined3d_ivec4 *constants) +{ + TRACE("stateblock %p, start_idx %u, count %u, constants %p.\n", stateblock, start_idx, count, constants); + + if (!constants || start_idx >= WINED3D_MAX_CONSTS_I) + return WINED3DERR_INVALIDCALL; + + if (count > WINED3D_MAX_CONSTS_I - start_idx) + count = WINED3D_MAX_CONSTS_I - start_idx; + + memcpy(constants, &stateblock->stateblock_state.vs_consts_i[start_idx], count * sizeof(*constants)); + return WINED3D_OK; +} + +HRESULT CDECL wined3d_stateblock_get_vs_consts_b(struct wined3d_stateblock *stateblock, + unsigned int start_idx, unsigned int count, BOOL *constants) +{ + TRACE("stateblock %p, start_idx %u, count %u, constants %p.\n", stateblock, start_idx, count, constants); + + if (!constants || start_idx >= WINED3D_MAX_CONSTS_B) + return WINED3DERR_INVALIDCALL; + + if (count > WINED3D_MAX_CONSTS_B - start_idx) + count = WINED3D_MAX_CONSTS_B - start_idx; + + memcpy(constants, &stateblock->stateblock_state.vs_consts_b[start_idx], count * sizeof(*constants)); + return WINED3D_OK; +} + void CDECL wined3d_stateblock_set_pixel_shader(struct wined3d_stateblock *stateblock, struct wined3d_shader *shader) { TRACE("stateblock %p, shader %p.\n", stateblock, shader); @@ -1313,6 +1357,48 @@ HRESULT CDECL wined3d_stateblock_set_ps_consts_b(struct wined3d_stateblock *stat return WINED3D_OK; } +HRESULT CDECL wined3d_stateblock_get_ps_consts_f(struct wined3d_stateblock *stateblock, + unsigned int start_idx, unsigned int count, struct wined3d_vec4 *constants) +{ + TRACE("stateblock %p, start_idx %u, count %u, constants %p.\n", stateblock, start_idx, count, constants); + + if (!constants || !wined3d_bound_range(start_idx, count, WINED3D_MAX_PS_CONSTS_F)) + return WINED3DERR_INVALIDCALL; + + memcpy(constants, &stateblock->stateblock_state.ps_consts_f[start_idx], count * sizeof(*constants)); + return WINED3D_OK; +} + +HRESULT CDECL wined3d_stateblock_get_ps_consts_i(struct wined3d_stateblock *stateblock, + unsigned int start_idx, unsigned int count, struct wined3d_ivec4 *constants) +{ + TRACE("stateblock %p, start_idx %u, count %u, constants %p.\n", stateblock, start_idx, count, constants); + + if (!constants || start_idx >= WINED3D_MAX_CONSTS_I) + return WINED3DERR_INVALIDCALL; + + if (count > WINED3D_MAX_CONSTS_I - start_idx) + count = WINED3D_MAX_CONSTS_I - start_idx; + + memcpy(constants, &stateblock->stateblock_state.ps_consts_i[start_idx], count * sizeof(*constants)); + return WINED3D_OK; +} + +HRESULT CDECL wined3d_stateblock_get_ps_consts_b(struct wined3d_stateblock *stateblock, + unsigned int start_idx, unsigned int count, BOOL *constants) +{ + TRACE("stateblock %p, start_idx %u, count %u, constants %p.\n", stateblock, start_idx, count, constants); + + if (!constants || start_idx >= WINED3D_MAX_CONSTS_B) + return WINED3DERR_INVALIDCALL; + + if (count > WINED3D_MAX_CONSTS_B - start_idx) + count = WINED3D_MAX_CONSTS_B - start_idx; + + memcpy(constants, &stateblock->stateblock_state.ps_consts_b[start_idx], count * sizeof(*constants)); + return WINED3D_OK; +} + void CDECL wined3d_stateblock_set_vertex_declaration(struct wined3d_stateblock *stateblock, struct wined3d_vertex_declaration *declaration) { diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec index 8f75dffc142..39a0dd3a299 100644 --- a/dlls/wined3d/wined3d.spec +++ b/dlls/wined3d/wined3d.spec @@ -231,7 +231,13 @@ @ cdecl wined3d_stateblock_create(ptr ptr long ptr) @ cdecl wined3d_stateblock_decref(ptr) @ cdecl wined3d_stateblock_get_light(ptr long ptr ptr) +@ cdecl wined3d_stateblock_get_ps_consts_b(ptr long long ptr) +@ cdecl wined3d_stateblock_get_ps_consts_f(ptr long long ptr) +@ cdecl wined3d_stateblock_get_ps_consts_i(ptr long long ptr) @ cdecl wined3d_stateblock_get_state(ptr) +@ cdecl wined3d_stateblock_get_vs_consts_b(ptr long long ptr) +@ cdecl wined3d_stateblock_get_vs_consts_f(ptr long long ptr) +@ cdecl wined3d_stateblock_get_vs_consts_i(ptr long long ptr) @ cdecl wined3d_stateblock_incref(ptr) @ cdecl wined3d_stateblock_init_contained_states(ptr) @ cdecl wined3d_stateblock_multiply_transform(ptr long ptr) diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index c9790efccbb..2317dc17078 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -2753,7 +2753,19 @@ HRESULT __cdecl wined3d_stateblock_create(struct wined3d_device *device, const s ULONG __cdecl wined3d_stateblock_decref(struct wined3d_stateblock *stateblock); HRESULT __cdecl wined3d_stateblock_get_light(const struct wined3d_stateblock *stateblock, UINT light_idx, struct wined3d_light *light, BOOL *enabled); +HRESULT __cdecl wined3d_stateblock_get_ps_consts_b(struct wined3d_stateblock *stateblock, + unsigned int start_idx, unsigned int count, BOOL *constants); +HRESULT __cdecl wined3d_stateblock_get_ps_consts_f(struct wined3d_stateblock *stateblock, + unsigned int start_idx, unsigned int count, struct wined3d_vec4 *constants); +HRESULT __cdecl wined3d_stateblock_get_ps_consts_i(struct wined3d_stateblock *stateblock, + unsigned int start_idx, unsigned int count, struct wined3d_ivec4 *constants); const struct wined3d_stateblock_state * __cdecl wined3d_stateblock_get_state(const struct wined3d_stateblock *stateblock); +HRESULT __cdecl wined3d_stateblock_get_vs_consts_b(struct wined3d_stateblock *stateblock, + unsigned int start_idx, unsigned int count, BOOL *constants); +HRESULT __cdecl wined3d_stateblock_get_vs_consts_f(struct wined3d_stateblock *stateblock, + unsigned int start_idx, unsigned int count, struct wined3d_vec4 *constants); +HRESULT __cdecl wined3d_stateblock_get_vs_consts_i(struct wined3d_stateblock *stateblock, + unsigned int start_idx, unsigned int count, struct wined3d_ivec4 *constants); ULONG __cdecl wined3d_stateblock_incref(struct wined3d_stateblock *stateblock); void __cdecl wined3d_stateblock_init_contained_states(struct wined3d_stateblock *stateblock); void __cdecl wined3d_stateblock_multiply_transform(struct wined3d_stateblock *stateblock,