Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- dlls/wined3d/stateblock.c | 178 ++++++++++++++------------------- dlls/wined3d/wined3d_private.h | 12 --- 2 files changed, 75 insertions(+), 115 deletions(-)
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index 6d1562cc60e..c4927d53d36 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -281,7 +281,6 @@ static void stateblock_savedstates_set_vertex(struct wined3d_saved_states *state
void CDECL wined3d_stateblock_init_contained_states(struct wined3d_stateblock *stateblock) { - const unsigned int word_bit_count = sizeof(*stateblock->changed.vs_consts_f) * CHAR_BIT; unsigned int i, j;
for (i = 0; i <= WINEHIGHEST_RENDER_STATE >> 5; ++i) @@ -308,66 +307,6 @@ void CDECL wined3d_stateblock_init_contained_states(struct wined3d_stateblock *s } }
- for (i = 0; i < ARRAY_SIZE(stateblock->changed.vs_consts_f); ++i) - { - DWORD bitmask = stateblock->changed.vs_consts_f[i]; - - while (bitmask) - { - j = wined3d_bit_scan(&bitmask); - stateblock->contained_vs_consts_f[stateblock->num_contained_vs_consts_f] = i * word_bit_count + j; - ++stateblock->num_contained_vs_consts_f; - } - } - - for (i = 0; i < WINED3D_MAX_CONSTS_I; ++i) - { - if (stateblock->changed.vertexShaderConstantsI & (1u << i)) - { - stateblock->contained_vs_consts_i[stateblock->num_contained_vs_consts_i] = i; - ++stateblock->num_contained_vs_consts_i; - } - } - - for (i = 0; i < WINED3D_MAX_CONSTS_B; ++i) - { - if (stateblock->changed.vertexShaderConstantsB & (1u << i)) - { - stateblock->contained_vs_consts_b[stateblock->num_contained_vs_consts_b] = i; - ++stateblock->num_contained_vs_consts_b; - } - } - - for (i = 0; i < ARRAY_SIZE(stateblock->changed.ps_consts_f); ++i) - { - DWORD bitmask = stateblock->changed.ps_consts_f[i]; - - while (bitmask) - { - j = wined3d_bit_scan(&bitmask); - stateblock->contained_ps_consts_f[stateblock->num_contained_ps_consts_f] = i * word_bit_count + j; - ++stateblock->num_contained_ps_consts_f; - } - } - - for (i = 0; i < WINED3D_MAX_CONSTS_I; ++i) - { - if (stateblock->changed.pixelShaderConstantsI & (1u << i)) - { - stateblock->contained_ps_consts_i[stateblock->num_contained_ps_consts_i] = i; - ++stateblock->num_contained_ps_consts_i; - } - } - - for (i = 0; i < WINED3D_MAX_CONSTS_B; ++i) - { - if (stateblock->changed.pixelShaderConstantsB & (1u << i)) - { - stateblock->contained_ps_consts_b[stateblock->num_contained_ps_consts_b] = i; - ++stateblock->num_contained_ps_consts_b; - } - } - for (i = 0; i < WINED3D_MAX_TEXTURES; ++i) { DWORD map = stateblock->changed.textureState[i]; @@ -762,8 +701,9 @@ static void wined3d_state_record_lights(struct wined3d_light_state *dst_state, void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock, const struct wined3d_stateblock *device_state) { + const unsigned int word_bit_count = sizeof(*stateblock->changed.vs_consts_f) * CHAR_BIT; const struct wined3d_stateblock_state *state = &device_state->stateblock_state; - unsigned int i; + unsigned int i, j, idx; DWORD map;
TRACE("stateblock %p, device_state %p.\n", stateblock, device_state); @@ -779,30 +719,34 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock, stateblock->stateblock_state.vs = state->vs; }
- /* Vertex shader float constants. */ - for (i = 0; i < stateblock->num_contained_vs_consts_f; ++i) + for (i = 0; i < ARRAY_SIZE(stateblock->changed.vs_consts_f); ++i) { - unsigned int idx = stateblock->contained_vs_consts_f[i]; + map = stateblock->changed.vs_consts_f[i];
- TRACE("Setting vs_consts_f[%u] to %s.\n", idx, debug_vec4(&state->vs_consts_f[idx])); + while (map) + { + j = wined3d_bit_scan(&map); + idx = i * word_bit_count + j;
- stateblock->stateblock_state.vs_consts_f[idx] = state->vs_consts_f[idx]; + TRACE("Setting vs_consts_f[%u] to %s.\n", idx, debug_vec4(&state->vs_consts_f[idx])); + stateblock->stateblock_state.vs_consts_f[idx] = state->vs_consts_f[idx]; + } }
- /* Vertex shader integer constants. */ - for (i = 0; i < stateblock->num_contained_vs_consts_i; ++i) + map = stateblock->changed.vertexShaderConstantsI; + while (map) { - unsigned int idx = stateblock->contained_vs_consts_i[i]; + idx = wined3d_bit_scan(&map);
TRACE("Setting vs_consts_i[%u] to %s.\n", idx, debug_ivec4(&state->vs_consts_i[idx]));
stateblock->stateblock_state.vs_consts_i[idx] = state->vs_consts_i[idx]; }
- /* Vertex shader boolean constants. */ - for (i = 0; i < stateblock->num_contained_vs_consts_b; ++i) + map = stateblock->changed.vertexShaderConstantsB; + while (map) { - unsigned int idx = stateblock->contained_vs_consts_b[i]; + idx = wined3d_bit_scan(&map);
TRACE("Setting vs_consts_b[%u] to %s.\n", idx, state->vs_consts_b[idx] ? "TRUE" : "FALSE"); @@ -810,30 +754,34 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock, stateblock->stateblock_state.vs_consts_b[idx] = state->vs_consts_b[idx]; }
- /* Pixel shader float constants. */ - for (i = 0; i < stateblock->num_contained_ps_consts_f; ++i) + for (i = 0; i < ARRAY_SIZE(stateblock->changed.ps_consts_f); ++i) { - unsigned int idx = stateblock->contained_ps_consts_f[i]; + map = stateblock->changed.ps_consts_f[i];
- TRACE("Setting ps_consts_f[%u] to %s.\n", idx, debug_vec4(&state->ps_consts_f[idx])); + while (map) + { + j = wined3d_bit_scan(&map); + idx = i * word_bit_count + j;
- stateblock->stateblock_state.ps_consts_f[idx] = state->ps_consts_f[idx]; + TRACE("Setting ps_consts_f[%u] to %s.\n", idx, debug_vec4(&state->ps_consts_f[idx])); + stateblock->stateblock_state.ps_consts_f[idx] = state->ps_consts_f[idx]; + } }
- /* Pixel shader integer constants. */ - for (i = 0; i < stateblock->num_contained_ps_consts_i; ++i) + map = stateblock->changed.pixelShaderConstantsI; + while (map) { - unsigned int idx = stateblock->contained_ps_consts_i[i]; + idx = wined3d_bit_scan(&map);
TRACE("Setting ps_consts_i[%u] to %s.\n", idx, debug_ivec4(&state->ps_consts_i[idx]));
stateblock->stateblock_state.ps_consts_i[idx] = state->ps_consts_i[idx]; }
- /* Pixel shader boolean constants. */ - for (i = 0; i < stateblock->num_contained_ps_consts_b; ++i) + map = stateblock->changed.pixelShaderConstantsB; + while (map) { - unsigned int idx = stateblock->contained_ps_consts_b[i]; + idx = wined3d_bit_scan(&map);
TRACE("Setting ps_consts_b[%u] to %s.\n", idx, state->ps_consts_b[idx] ? "TRUE" : "FALSE"); @@ -1026,9 +974,11 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock, void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock, struct wined3d_stateblock *device_state) { + const unsigned int word_bit_count = sizeof(*stateblock->changed.vs_consts_f) * CHAR_BIT; struct wined3d_stateblock_state *state = &device_state->stateblock_state; struct wined3d_device *device = stateblock->device; - unsigned int i; + const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info; + unsigned int i, j, idx; DWORD map;
TRACE("stateblock %p, device_state %p.\n", stateblock, device_state); @@ -1044,23 +994,31 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock, }
/* Vertex Shader Constants. */ - for (i = 0; i < stateblock->num_contained_vs_consts_f; ++i) + for (i = 0; i < d3d_info->limits.vs_uniform_count / word_bit_count; ++i) { - unsigned int idx = stateblock->contained_vs_consts_f[i]; + map = stateblock->changed.vs_consts_f[i]; + + while (map) + { + j = wined3d_bit_scan(&map); + idx = i * word_bit_count + j;
- state->vs_consts_f[idx] = stateblock->stateblock_state.vs_consts_f[idx]; - wined3d_device_set_vs_consts_f(device, idx, 1, &stateblock->stateblock_state.vs_consts_f[idx]); + state->vs_consts_f[idx] = stateblock->stateblock_state.vs_consts_f[idx]; + wined3d_device_set_vs_consts_f(device, idx, 1, &stateblock->stateblock_state.vs_consts_f[idx]); + } } - for (i = 0; i < stateblock->num_contained_vs_consts_i; ++i) + map = stateblock->changed.vertexShaderConstantsI; + while (map) { - unsigned int idx = stateblock->contained_vs_consts_i[i]; + idx = wined3d_bit_scan(&map);
state->vs_consts_i[idx] = stateblock->stateblock_state.vs_consts_i[idx]; wined3d_device_set_vs_consts_i(device, idx, 1, &stateblock->stateblock_state.vs_consts_i[idx]); } - for (i = 0; i < stateblock->num_contained_vs_consts_b; ++i) + map = stateblock->changed.vertexShaderConstantsB; + while (map) { - unsigned int idx = stateblock->contained_vs_consts_b[i]; + idx = wined3d_bit_scan(&map);
state->vs_consts_b[idx] = stateblock->stateblock_state.vs_consts_b[idx]; wined3d_device_set_vs_consts_b(device, idx, 1, &stateblock->stateblock_state.vs_consts_b[idx]); @@ -1094,23 +1052,31 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock, }
/* Pixel Shader Constants. */ - for (i = 0; i < stateblock->num_contained_ps_consts_f; ++i) + for (i = 0; i < d3d_info->limits.ps_uniform_count / word_bit_count; ++i) { - unsigned int idx = stateblock->contained_ps_consts_f[i]; + map = stateblock->changed.ps_consts_f[i]; + + while (map) + { + j = wined3d_bit_scan(&map); + idx = i * word_bit_count + j;
- state->ps_consts_f[idx] = stateblock->stateblock_state.ps_consts_f[idx]; - wined3d_device_set_ps_consts_f(device, idx, 1, &stateblock->stateblock_state.ps_consts_f[idx]); + state->ps_consts_f[idx] = stateblock->stateblock_state.ps_consts_f[idx]; + wined3d_device_set_ps_consts_f(device, idx, 1, &stateblock->stateblock_state.ps_consts_f[idx]); + } } - for (i = 0; i < stateblock->num_contained_ps_consts_i; ++i) + map = stateblock->changed.pixelShaderConstantsI; + while (map) { - unsigned int idx = stateblock->contained_ps_consts_i[i]; + idx = wined3d_bit_scan(&map);
state->ps_consts_i[idx] = stateblock->stateblock_state.ps_consts_i[idx]; wined3d_device_set_ps_consts_i(device, idx, 1, &stateblock->stateblock_state.ps_consts_i[idx]); } - for (i = 0; i < stateblock->num_contained_ps_consts_b; ++i) + map = stateblock->changed.pixelShaderConstantsB; + while (map) { - unsigned int idx = stateblock->contained_ps_consts_b[i]; + idx = wined3d_bit_scan(&map);
state->ps_consts_b[idx] = stateblock->stateblock_state.ps_consts_b[idx]; wined3d_device_set_ps_consts_b(device, idx, 1, &stateblock->stateblock_state.ps_consts_b[idx]); @@ -1308,10 +1274,13 @@ static void wined3d_bitmask_set_bits(DWORD *bitmask, unsigned int offset, unsign HRESULT CDECL wined3d_stateblock_set_vs_consts_f(struct wined3d_stateblock *stateblock, unsigned int start_idx, unsigned int count, const 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 || start_idx >= WINED3D_MAX_VS_CONSTS_F || count > WINED3D_MAX_VS_CONSTS_F - start_idx) + if (!constants || start_idx >= d3d_info->limits.vs_uniform_count + || count > d3d_info->limits.vs_uniform_count - start_idx) return WINED3DERR_INVALIDCALL;
memcpy(&stateblock->stateblock_state.vs_consts_f[start_idx], constants, count * sizeof(*constants)); @@ -1374,10 +1343,13 @@ void CDECL wined3d_stateblock_set_pixel_shader(struct wined3d_stateblock *stateb HRESULT CDECL wined3d_stateblock_set_ps_consts_f(struct wined3d_stateblock *stateblock, unsigned int start_idx, unsigned int count, const 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 || start_idx >= WINED3D_MAX_PS_CONSTS_F || count > WINED3D_MAX_PS_CONSTS_F - start_idx) + if (!constants || start_idx >= d3d_info->limits.ps_uniform_count + || count > d3d_info->limits.ps_uniform_count - start_idx) return WINED3DERR_INVALIDCALL;
memcpy(&stateblock->stateblock_state.ps_consts_f[start_idx], constants, count * sizeof(*constants)); diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index c8b22832e65..41eaef86ab1 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -3956,18 +3956,6 @@ struct wined3d_stateblock unsigned int num_contained_render_states; DWORD contained_transform_states[WINED3D_HIGHEST_TRANSFORM_STATE + 1]; unsigned int num_contained_transform_states; - DWORD contained_vs_consts_i[WINED3D_MAX_CONSTS_I]; - unsigned int num_contained_vs_consts_i; - DWORD contained_vs_consts_b[WINED3D_MAX_CONSTS_B]; - unsigned int num_contained_vs_consts_b; - DWORD contained_vs_consts_f[WINED3D_MAX_VS_CONSTS_F]; - unsigned int num_contained_vs_consts_f; - DWORD contained_ps_consts_i[WINED3D_MAX_CONSTS_I]; - unsigned int num_contained_ps_consts_i; - DWORD contained_ps_consts_b[WINED3D_MAX_CONSTS_B]; - unsigned int num_contained_ps_consts_b; - DWORD contained_ps_consts_f[WINED3D_MAX_PS_CONSTS_F]; - unsigned int num_contained_ps_consts_f; struct StageState contained_tss_states[WINED3D_MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1)]; unsigned int num_contained_tss_states; struct StageState contained_sampler_states[WINED3D_MAX_COMBINED_SAMPLERS * WINED3D_HIGHEST_SAMPLER_STATE];