Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- So that applications not using the fixed-function pipeline get to skip the lights checks entirely.
dlls/wined3d/device.c | 15 +++++++++------ dlls/wined3d/stateblock.c | 31 ++++++++++++++++++++----------- dlls/wined3d/wined3d_private.h | 3 ++- 3 files changed, 31 insertions(+), 18 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 660ba777efc..639e94a624b 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -3904,14 +3904,17 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device, wined3d_device_set_ps_consts_b(device, range.offset, range.size, &state->ps_consts_b[range.offset]); }
- for (i = 0; i < ARRAY_SIZE(state->light_state->light_map); ++i) + if (changed->lights) { - const struct wined3d_light_info *light; - - LIST_FOR_EACH_ENTRY(light, &state->light_state->light_map[i], struct wined3d_light_info, entry) + for (i = 0; i < ARRAY_SIZE(state->light_state->light_map); ++i) { - wined3d_device_set_light(device, light->OriginalIndex, &light->OriginalParms); - wined3d_device_set_light_enable(device, light->OriginalIndex, light->glIndex != -1); + const struct wined3d_light_info *light; + + LIST_FOR_EACH_ENTRY(light, &state->light_state->light_map[i], struct wined3d_light_info, entry) + { + wined3d_device_set_light(device, light->OriginalIndex, &light->OriginalParms); + wined3d_device_set_light_enable(device, light->OriginalIndex, light->glIndex != -1); + } } }
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index 69210e1fba2..c47a7323b14 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -209,6 +209,7 @@ static void stateblock_savedstates_set_all(struct wined3d_saved_states *states, states->vertexShader = 1; states->scissorRect = 1; states->blend_state = 1; + states->lights = 1;
states->streamSource = 0xffff; states->streamFreq = 0xffff; @@ -262,6 +263,7 @@ static void stateblock_savedstates_set_vertex(struct wined3d_saved_states *state states->vertexDecl = 1; states->vertexShader = 1; states->blend_state = 1; + states->lights = 1;
for (i = 0; i < ARRAY_SIZE(vertex_states_render); ++i) { @@ -982,7 +984,8 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock, stateblock->stateblock_state.ps = state->ps; }
- wined3d_state_record_lights(stateblock->stateblock_state.light_state, state->light_state); + if (stateblock->changed.lights) + wined3d_state_record_lights(stateblock->stateblock_state.light_state, state->light_state);
if (stateblock->changed.blend_state && stateblock->stateblock_state.blend_state != state->blend_state) { @@ -1050,20 +1053,23 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock, wined3d_device_set_vs_consts_b(device, idx, 1, &stateblock->stateblock_state.vs_consts_b[idx]); }
- for (i = 0; i < ARRAY_SIZE(stateblock->stateblock_state.light_state->light_map); ++i) + if (stateblock->changed.lights) { - const struct wined3d_light_info *light; - struct wined3d_light_info *new_light; - - LIST_FOR_EACH_ENTRY(light, &stateblock->stateblock_state.light_state->light_map[i], struct wined3d_light_info, entry) + for (i = 0; i < ARRAY_SIZE(stateblock->stateblock_state.light_state->light_map); ++i) { - if (SUCCEEDED(wined3d_light_state_set_light(state->light_state, light->OriginalIndex, - &light->OriginalParms, &new_light))) + const struct wined3d_light_info *light; + struct wined3d_light_info *new_light; + + LIST_FOR_EACH_ENTRY(light, &stateblock->stateblock_state.light_state->light_map[i], struct wined3d_light_info, entry) { - wined3d_light_state_enable_light(state->light_state, &device->adapter->d3d_info, new_light, light->glIndex != -1); + if (SUCCEEDED(wined3d_light_state_set_light(state->light_state, light->OriginalIndex, + &light->OriginalParms, &new_light))) + { + wined3d_light_state_enable_light(state->light_state, &device->adapter->d3d_info, new_light, light->glIndex != -1); + } + wined3d_device_set_light(device, light->OriginalIndex, &light->OriginalParms); + wined3d_device_set_light_enable(device, light->OriginalIndex, light->glIndex != -1); } - wined3d_device_set_light(device, light->OriginalIndex, &light->OriginalParms); - wined3d_device_set_light_enable(device, light->OriginalIndex, light->glIndex != -1); } }
@@ -1708,6 +1714,7 @@ HRESULT CDECL wined3d_stateblock_set_stream_source_freq(struct wined3d_statebloc stateblock->changed.streamFreq |= 1u << stream_idx; return WINED3D_OK; } + HRESULT CDECL wined3d_stateblock_set_light(struct wined3d_stateblock *stateblock, UINT light_idx, const struct wined3d_light *light) { @@ -1744,6 +1751,7 @@ HRESULT CDECL wined3d_stateblock_set_light(struct wined3d_stateblock *stateblock return WINED3DERR_INVALIDCALL; }
+ stateblock->changed.lights = 1; return wined3d_light_state_set_light(stateblock->stateblock_state.light_state, light_idx, light, &object); }
@@ -1761,6 +1769,7 @@ HRESULT CDECL wined3d_stateblock_set_light_enable(struct wined3d_stateblock *sta return hr; } wined3d_light_state_enable_light(light_state, &stateblock->device->adapter->d3d_info, light_info, enable); + stateblock->changed.lights = 1; return S_OK; }
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 744e647008e..c658f5104c7 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -3937,7 +3937,8 @@ struct wined3d_saved_states DWORD scissorRect : 1; DWORD store_stream_offset : 1; DWORD blend_state : 1; - DWORD padding : 3; + DWORD lights : 1; + DWORD padding : 2; };
struct StageState {
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- dlls/wined3d/device.c | 15 +++++++++------ dlls/wined3d/stateblock.c | 26 ++++++++++++++++---------- dlls/wined3d/wined3d_private.h | 3 ++- 3 files changed, 27 insertions(+), 17 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 639e94a624b..99fbf21ada2 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -3977,14 +3977,17 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device, } }
- for (i = 0; i < ARRAY_SIZE(changed->transform); ++i) + if (changed->transforms) { - map = changed->transform[i]; - while (map) + for (i = 0; i < ARRAY_SIZE(changed->transform); ++i) { - j = wined3d_bit_scan(&map); - idx = i * word_bit_count + j; - wined3d_device_set_transform(device, idx, &state->transforms[idx]); + map = changed->transform[i]; + while (map) + { + j = wined3d_bit_scan(&map); + idx = i * word_bit_count + j; + wined3d_device_set_transform(device, idx, &state->transforms[idx]); + } } }
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index c47a7323b14..6e3a4737828 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -210,6 +210,7 @@ static void stateblock_savedstates_set_all(struct wined3d_saved_states *states, states->scissorRect = 1; states->blend_state = 1; states->lights = 1; + states->transforms = 1;
states->streamSource = 0xffff; states->streamFreq = 0xffff; @@ -807,14 +808,16 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock, stateblock->stateblock_state.ps_consts_b[idx] = state->ps_consts_b[idx]; }
- /* Others + Render & Texture */ - for (i = 0; i < stateblock->num_contained_transform_states; ++i) + if (stateblock->changed.transforms) { - enum wined3d_transform_state transform = stateblock->contained_transform_states[i]; + for (i = 0; i < stateblock->num_contained_transform_states; ++i) + { + enum wined3d_transform_state transform = stateblock->contained_transform_states[i];
- TRACE("Updating transform %#x.\n", transform); + TRACE("Updating transform %#x.\n", transform);
- stateblock->stateblock_state.transforms[transform] = state->transforms[transform]; + stateblock->stateblock_state.transforms[transform] = state->transforms[transform]; + } }
if (stateblock->changed.indices @@ -1177,13 +1180,15 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock, wined3d_device_set_sampler_state(device, stage, sampler_state, value); }
- /* Transform states. */ - for (i = 0; i < stateblock->num_contained_transform_states; ++i) + if (stateblock->changed.transforms) { - enum wined3d_transform_state transform = stateblock->contained_transform_states[i]; + for (i = 0; i < stateblock->num_contained_transform_states; ++i) + { + enum wined3d_transform_state transform = stateblock->contained_transform_states[i];
- state->transforms[transform] = stateblock->stateblock_state.transforms[transform]; - wined3d_device_set_transform(device, transform, &stateblock->stateblock_state.transforms[transform]); + state->transforms[transform] = stateblock->stateblock_state.transforms[transform]; + wined3d_device_set_transform(device, transform, &stateblock->stateblock_state.transforms[transform]); + } }
if (stateblock->changed.indices) @@ -1579,6 +1584,7 @@ void CDECL wined3d_stateblock_set_transform(struct wined3d_stateblock *statebloc
stateblock->stateblock_state.transforms[d3dts] = *matrix; stateblock->changed.transform[d3dts >> 5] |= 1u << (d3dts & 0x1f); + stateblock->changed.transforms = 1; }
void CDECL wined3d_stateblock_multiply_transform(struct wined3d_stateblock *stateblock, diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index c658f5104c7..f266d2a6901 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -3938,7 +3938,8 @@ struct wined3d_saved_states DWORD store_stream_offset : 1; DWORD blend_state : 1; DWORD lights : 1; - DWORD padding : 2; + DWORD transforms : 1; + DWORD padding : 1; };
struct StageState {
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- dlls/wined3d/stateblock.c | 82 +++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 38 deletions(-)
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index 6e3a4737828..2c3ff65222d 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -1005,12 +1005,12 @@ 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; struct wined3d_blend_state *blend_state; struct wined3d_color colour; - unsigned int i, j, idx; + struct wined3d_range range; + unsigned int i, start; BOOL set_blend_state; DWORD map;
@@ -1026,34 +1026,37 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock, wined3d_device_set_vertex_shader(device, stateblock->stateblock_state.vs); }
- for (i = 0; i < ARRAY_SIZE(stateblock->changed.vs_consts_f); ++i) + for (start = 0; ; start = range.offset + range.size) { - map = stateblock->changed.vs_consts_f[i]; - - while (map) - { - j = wined3d_bit_scan(&map); - idx = i * word_bit_count + j; + if (!wined3d_bitmap_get_range(stateblock->changed.vs_consts_f, WINED3D_MAX_VS_CONSTS_F, start, &range)) + break;
- 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]); - } + memcpy(&state->vs_consts_f[range.offset], &stateblock->stateblock_state.vs_consts_f[range.offset], + sizeof(*state->vs_consts_f) * range.size); + wined3d_device_set_vs_consts_f(device, range.offset, range.size, + &stateblock->stateblock_state.vs_consts_f[range.offset]); } map = stateblock->changed.vertexShaderConstantsI; - while (map) + for (start = 0; ; start = range.offset + range.size) { - idx = wined3d_bit_scan(&map); + if (!wined3d_bitmap_get_range(&map, WINED3D_MAX_CONSTS_I, start, &range)) + break;
- 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]); + memcpy(&state->vs_consts_i[range.offset], &stateblock->stateblock_state.vs_consts_i[range.offset], + sizeof(*state->vs_consts_i) * range.size); + wined3d_device_set_vs_consts_i(device, range.offset, range.size, + &stateblock->stateblock_state.vs_consts_i[range.offset]); } map = stateblock->changed.vertexShaderConstantsB; - while (map) + for (start = 0; ; start = range.offset + range.size) { - idx = wined3d_bit_scan(&map); + if (!wined3d_bitmap_get_range(&map, WINED3D_MAX_CONSTS_B, start, &range)) + break;
- 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]); + memcpy(&state->vs_consts_b[range.offset], &stateblock->stateblock_state.vs_consts_b[range.offset], + sizeof(*state->vs_consts_b) * range.size); + wined3d_device_set_vs_consts_b(device, range.offset, range.size, + &stateblock->stateblock_state.vs_consts_b[range.offset]); }
if (stateblock->changed.lights) @@ -1086,34 +1089,37 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock, wined3d_device_set_pixel_shader(device, stateblock->stateblock_state.ps); }
- for (i = 0; i < ARRAY_SIZE(stateblock->changed.ps_consts_f); ++i) + for (start = 0; ; start = range.offset + range.size) { - map = stateblock->changed.ps_consts_f[i]; - - while (map) - { - j = wined3d_bit_scan(&map); - idx = i * word_bit_count + j; + if (!wined3d_bitmap_get_range(stateblock->changed.ps_consts_f, WINED3D_MAX_PS_CONSTS_F, start, &range)) + break;
- 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]); - } + memcpy(&state->ps_consts_f[range.offset], &stateblock->stateblock_state.ps_consts_f[range.offset], + sizeof(*state->ps_consts_f) * range.size); + wined3d_device_set_ps_consts_f(device, range.offset, range.size, + &stateblock->stateblock_state.ps_consts_f[range.offset]); } map = stateblock->changed.pixelShaderConstantsI; - while (map) + for (start = 0; ; start = range.offset + range.size) { - idx = wined3d_bit_scan(&map); + if (!wined3d_bitmap_get_range(&map, WINED3D_MAX_CONSTS_I, start, &range)) + break;
- 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]); + memcpy(&state->ps_consts_i[range.offset], &stateblock->stateblock_state.ps_consts_i[range.offset], + sizeof(*state->ps_consts_i) * range.size); + wined3d_device_set_ps_consts_i(device, range.offset, range.size, + &stateblock->stateblock_state.ps_consts_i[range.offset]); } map = stateblock->changed.pixelShaderConstantsB; - while (map) + for (start = 0; ; start = range.offset + range.size) { - idx = wined3d_bit_scan(&map); + if (!wined3d_bitmap_get_range(&map, WINED3D_MAX_CONSTS_B, start, &range)) + break;
- 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]); + memcpy(&state->ps_consts_b[range.offset], &stateblock->stateblock_state.ps_consts_b[range.offset], + sizeof(*state->ps_consts_b) * range.size); + wined3d_device_set_ps_consts_b(device, range.offset, range.size, + &stateblock->stateblock_state.ps_consts_b[range.offset]); }
if ((set_blend_state = stateblock->changed.blend_state
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- dlls/wined3d/stateblock.c | 80 ++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 48 deletions(-)
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index 2c3ff65222d..208a1f06067 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -720,9 +720,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, j, idx; + struct wined3d_range range; + unsigned int i, start; DWORD map;
TRACE("stateblock %p, device_state %p.\n", stateblock, device_state); @@ -738,74 +738,58 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock, stateblock->stateblock_state.vs = state->vs; }
- for (i = 0; i < ARRAY_SIZE(stateblock->changed.vs_consts_f); ++i) + for (start = 0; ; start = range.offset + range.size) { - map = stateblock->changed.vs_consts_f[i]; - - while (map) - { - j = wined3d_bit_scan(&map); - idx = i * word_bit_count + j; + if (!wined3d_bitmap_get_range(stateblock->changed.vs_consts_f, WINED3D_MAX_VS_CONSTS_F, start, &range)) + break;
- 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]; - } + memcpy(&stateblock->stateblock_state.vs_consts_f[range.offset], &state->vs_consts_f[range.offset], + sizeof(*state->vs_consts_f) * range.size); } - map = stateblock->changed.vertexShaderConstantsI; - while (map) + for (start = 0; ; start = range.offset + range.size) { - idx = wined3d_bit_scan(&map); - - TRACE("Setting vs_consts_i[%u] to %s.\n", idx, debug_ivec4(&state->vs_consts_i[idx])); + if (!wined3d_bitmap_get_range(&map, WINED3D_MAX_CONSTS_I, start, &range)) + break;
- stateblock->stateblock_state.vs_consts_i[idx] = state->vs_consts_i[idx]; + memcpy(&stateblock->stateblock_state.vs_consts_i[range.offset], &state->vs_consts_i[range.offset], + sizeof(*state->vs_consts_i) * range.size); } - map = stateblock->changed.vertexShaderConstantsB; - while (map) + for (start = 0; ; start = range.offset + range.size) { - idx = wined3d_bit_scan(&map); - - TRACE("Setting vs_consts_b[%u] to %s.\n", - idx, state->vs_consts_b[idx] ? "TRUE" : "FALSE"); + if (!wined3d_bitmap_get_range(&map, WINED3D_MAX_CONSTS_B, start, &range)) + break;
- stateblock->stateblock_state.vs_consts_b[idx] = state->vs_consts_b[idx]; + memcpy(&stateblock->stateblock_state.vs_consts_b[range.offset], &state->vs_consts_b[range.offset], + sizeof(*state->vs_consts_b) * range.size); }
- for (i = 0; i < ARRAY_SIZE(stateblock->changed.ps_consts_f); ++i) + for (start = 0; ; start = range.offset + range.size) { - map = stateblock->changed.ps_consts_f[i]; - - while (map) - { - j = wined3d_bit_scan(&map); - idx = i * word_bit_count + j; + if (!wined3d_bitmap_get_range(stateblock->changed.ps_consts_f, WINED3D_MAX_PS_CONSTS_F, start, &range)) + break;
- 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]; - } + memcpy(&stateblock->stateblock_state.ps_consts_f[range.offset], &state->ps_consts_f[range.offset], + sizeof(*state->ps_consts_f) * range.size); } - map = stateblock->changed.pixelShaderConstantsI; - while (map) + for (start = 0; ; start = range.offset + range.size) { - idx = wined3d_bit_scan(&map); - - TRACE("Setting ps_consts_i[%u] to %s.\n", idx, debug_ivec4(&state->ps_consts_i[idx])); + if (!wined3d_bitmap_get_range(&map, WINED3D_MAX_CONSTS_I, start, &range)) + break;
- stateblock->stateblock_state.ps_consts_i[idx] = state->ps_consts_i[idx]; + memcpy(&stateblock->stateblock_state.ps_consts_i[range.offset], &state->ps_consts_i[range.offset], + sizeof(*state->ps_consts_i) * range.size); } - map = stateblock->changed.pixelShaderConstantsB; - while (map) + for (start = 0; ; start = range.offset + range.size) { - idx = wined3d_bit_scan(&map); - - TRACE("Setting ps_consts_b[%u] to %s.\n", - idx, state->ps_consts_b[idx] ? "TRUE" : "FALSE"); + if (!wined3d_bitmap_get_range(&map, WINED3D_MAX_CONSTS_B, start, &range)) + break;
- stateblock->stateblock_state.ps_consts_b[idx] = state->ps_consts_b[idx]; + memcpy(&stateblock->stateblock_state.ps_consts_b[range.offset], &state->ps_consts_b[range.offset], + sizeof(*state->ps_consts_b) * range.size); }
if (stateblock->changed.transforms)
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- Calling into wined3d every time probably has a very small overhead but I think "wasting" 4 / 8 bytes is still preferable.
dlls/d3d9/d3d9_private.h | 1 + dlls/d3d9/device.c | 66 +++++++++++++++++++--------------------- dlls/d3d9/stateblock.c | 2 +- 3 files changed, 34 insertions(+), 35 deletions(-)
diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h index bc9a3b98b2e..79fbb1ea1dd 100644 --- a/dlls/d3d9/d3d9_private.h +++ b/dlls/d3d9/d3d9_private.h @@ -120,6 +120,7 @@ struct d3d9_device struct wined3d_swapchain **implicit_swapchains;
struct wined3d_stateblock *recording, *state, *update_state; + const struct wined3d_stateblock_state *stateblock_state; };
HRESULT device_init(struct d3d9_device *device, struct d3d9 *parent, struct wined3d *wined3d, diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index 8d85a43523c..b6bd5e77356 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -1042,7 +1042,7 @@ static HRESULT d3d9_device_reset(struct d3d9_device *device,
if (extended) { - const struct wined3d_viewport *current = &wined3d_stateblock_get_state(device->state)->viewport; + const struct wined3d_viewport *current = &device->stateblock_state->viewport; struct wined3d_viewport vp; RECT rect;
@@ -2121,7 +2121,7 @@ static HRESULT WINAPI d3d9_device_GetTransform(IDirect3DDevice9Ex *iface,
/* Note: D3DMATRIX is compatible with struct wined3d_matrix. */ wined3d_mutex_lock(); - memcpy(matrix, &wined3d_stateblock_get_state(device->state)->transforms[state], sizeof(*matrix)); + memcpy(matrix, &device->stateblock_state->transforms[state], sizeof(*matrix)); wined3d_mutex_unlock();
return D3D_OK; @@ -2171,7 +2171,7 @@ static HRESULT WINAPI d3d9_device_GetViewport(IDirect3DDevice9Ex *iface, D3DVIEW TRACE("iface %p, viewport %p.\n", iface, viewport);
wined3d_mutex_lock(); - wined3d_viewport = wined3d_stateblock_get_state(device->state)->viewport; + wined3d_viewport = device->stateblock_state->viewport; wined3d_mutex_unlock();
viewport->X = wined3d_viewport.x; @@ -2206,7 +2206,7 @@ static HRESULT WINAPI d3d9_device_GetMaterial(IDirect3DDevice9Ex *iface, D3DMATE
/* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */ wined3d_mutex_lock(); - memcpy(material, &wined3d_stateblock_get_state(device->state)->material, sizeof(*material)); + memcpy(material, &device->stateblock_state->material, sizeof(*material)); wined3d_mutex_unlock();
return D3D_OK; @@ -2297,7 +2297,7 @@ static HRESULT WINAPI d3d9_device_GetClipPlane(IDirect3DDevice9Ex *iface, DWORD index = min(index, device->max_user_clip_planes - 1);
wined3d_mutex_lock(); - memcpy(plane, &wined3d_stateblock_get_state(device->state)->clip_planes[index], sizeof(struct wined3d_vec4)); + memcpy(plane, &device->stateblock_state->clip_planes[index], sizeof(struct wined3d_vec4)); wined3d_mutex_unlock();
return D3D_OK; @@ -2305,7 +2305,7 @@ static HRESULT WINAPI d3d9_device_GetClipPlane(IDirect3DDevice9Ex *iface, DWORD
static void resolve_depth_buffer(struct d3d9_device *device) { - const struct wined3d_stateblock_state *state = wined3d_stateblock_get_state(device->state); + const struct wined3d_stateblock_state *state = device->stateblock_state; struct wined3d_rendertarget_view *wined3d_dsv; struct wined3d_resource *dst_resource; struct wined3d_texture *dst_texture; @@ -2356,7 +2356,7 @@ static HRESULT WINAPI d3d9_device_GetRenderState(IDirect3DDevice9Ex *iface, TRACE("iface %p, state %#x, value %p.\n", iface, state, value);
wined3d_mutex_lock(); - device_state = wined3d_stateblock_get_state(device->state); + device_state = device->stateblock_state; *value = device_state->rs[state]; wined3d_mutex_unlock();
@@ -2525,7 +2525,7 @@ static HRESULT WINAPI d3d9_device_GetTexture(IDirect3DDevice9Ex *iface, DWORD st }
wined3d_mutex_lock(); - state = wined3d_stateblock_get_state(device->state); + state = device->stateblock_state; if ((wined3d_texture = state->textures[stage])) { texture_impl = wined3d_texture_get_parent(wined3d_texture); @@ -2622,7 +2622,7 @@ static HRESULT WINAPI d3d9_device_GetTextureStageState(IDirect3DDevice9Ex *iface }
wined3d_mutex_lock(); - *value = wined3d_stateblock_get_state(device->state)->texture_states[stage][tss_lookup[state]]; + *value = device->stateblock_state->texture_states[stage][tss_lookup[state]]; wined3d_mutex_unlock();
return D3D_OK; @@ -2667,7 +2667,7 @@ static HRESULT WINAPI d3d9_device_GetSamplerState(IDirect3DDevice9Ex *iface, }
wined3d_mutex_lock(); - device_state = wined3d_stateblock_get_state(device->state); + device_state = device->stateblock_state; *value = device_state->sampler_states[sampler_idx][state]; wined3d_mutex_unlock();
@@ -2758,7 +2758,7 @@ static HRESULT WINAPI d3d9_device_GetScissorRect(IDirect3DDevice9Ex *iface, RECT TRACE("iface %p, rect %p.\n", iface, rect);
wined3d_mutex_lock(); - *rect = wined3d_stateblock_get_state(device->state)->scissor_rect; + *rect = device->stateblock_state->scissor_rect; wined3d_mutex_unlock();
return D3D_OK; @@ -2822,7 +2822,7 @@ 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); + const struct wined3d_stateblock_state *state = device->stateblock_state; struct wined3d_texture *texture; unsigned int i, map;
@@ -2838,7 +2838,7 @@ static void d3d9_generate_auto_mipmaps(struct d3d9_device *device) static void d3d9_device_upload_sysmem_vertex_buffers(struct d3d9_device *device, int base_vertex, unsigned int start_vertex, unsigned int vertex_count) { - const struct wined3d_stateblock_state *state = wined3d_stateblock_get_state(device->state); + const struct wined3d_stateblock_state *state = device->stateblock_state; struct wined3d_vertex_declaration *wined3d_decl; struct wined3d_box box = {0, 0, 0, 1, 0, 1}; const struct wined3d_stream_state *stream; @@ -2884,7 +2884,7 @@ static void d3d9_device_upload_sysmem_vertex_buffers(struct d3d9_device *device, static void d3d9_device_upload_sysmem_index_buffer(struct d3d9_device *device, unsigned int start_idx, unsigned int idx_count) { - const struct wined3d_stateblock_state *state = wined3d_stateblock_get_state(device->state); + const struct wined3d_stateblock_state *state = device->stateblock_state; struct wined3d_box box = {0, 0, 0, 1, 0, 1}; struct wined3d_resource *dst_resource; struct d3d9_indexbuffer *d3d9_buffer; @@ -3250,7 +3250,7 @@ static HRESULT WINAPI d3d9_device_ProcessVertices(IDirect3DDevice9Ex *iface, iface, src_start_idx, dst_idx, vertex_count, dst_buffer, declaration, flags);
wined3d_mutex_lock(); - state = wined3d_stateblock_get_state(device->state); + state = device->stateblock_state;
/* Note that an alternative approach would be to simply create these * buffers with WINED3D_RESOURCE_ACCESS_MAP_R and update them here like we @@ -3341,7 +3341,7 @@ static HRESULT WINAPI d3d9_device_GetVertexDeclaration(IDirect3DDevice9Ex *iface if (!declaration) return D3DERR_INVALIDCALL;
wined3d_mutex_lock(); - if ((wined3d_declaration = wined3d_stateblock_get_state(device->state)->vertex_declaration)) + if ((wined3d_declaration = device->stateblock_state->vertex_declaration)) { declaration_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration); *declaration = &declaration_impl->IDirect3DVertexDeclaration9_iface; @@ -3461,7 +3461,7 @@ static HRESULT WINAPI d3d9_device_GetFVF(IDirect3DDevice9Ex *iface, DWORD *fvf) TRACE("iface %p, fvf %p.\n", iface, fvf);
wined3d_mutex_lock(); - if ((wined3d_declaration = wined3d_stateblock_get_state(device->state)->vertex_declaration)) + if ((wined3d_declaration = device->stateblock_state->vertex_declaration)) { d3d9_declaration = wined3d_vertex_declaration_get_parent(wined3d_declaration); *fvf = d3d9_declaration->fvf; @@ -3527,7 +3527,7 @@ static HRESULT WINAPI d3d9_device_GetVertexShader(IDirect3DDevice9Ex *iface, IDi TRACE("iface %p, shader %p.\n", iface, shader);
wined3d_mutex_lock(); - if ((wined3d_shader = wined3d_stateblock_get_state(device->state)->vs)) + if ((wined3d_shader = device->stateblock_state->vs)) { shader_impl = wined3d_shader_get_parent(wined3d_shader); *shader = &shader_impl->IDirect3DVertexShader9_iface; @@ -3586,7 +3586,7 @@ static HRESULT WINAPI d3d9_device_GetVertexShaderConstantF(IDirect3DDevice9Ex *i }
wined3d_mutex_lock(); - src = wined3d_stateblock_get_state(device->state)->vs_consts_f; + src = device->stateblock_state->vs_consts_f; memcpy(constants, &src[start_idx], count * sizeof(*src)); wined3d_mutex_unlock();
@@ -3623,7 +3623,7 @@ static HRESULT WINAPI d3d9_device_GetVertexShaderConstantI(IDirect3DDevice9Ex *i count = WINED3D_MAX_CONSTS_I - start_idx;
wined3d_mutex_lock(); - src = wined3d_stateblock_get_state(device->state)->vs_consts_i; + src = device->stateblock_state->vs_consts_i; memcpy(constants, &src[start_idx], count * sizeof(*src)); wined3d_mutex_unlock();
@@ -3658,7 +3658,7 @@ static HRESULT WINAPI d3d9_device_GetVertexShaderConstantB(IDirect3DDevice9Ex *i count = WINED3D_MAX_CONSTS_B - start_idx;
wined3d_mutex_lock(); - memcpy(constants, &wined3d_stateblock_get_state(device->state)->vs_consts_b[start_idx], count * sizeof(*constants)); + memcpy(constants, &device->stateblock_state->vs_consts_b[start_idx], count * sizeof(*constants)); wined3d_mutex_unlock();
return D3D_OK; @@ -3669,14 +3669,13 @@ static HRESULT WINAPI d3d9_device_SetStreamSource(IDirect3DDevice9Ex *iface, { struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface); struct d3d9_vertexbuffer *buffer_impl = unsafe_impl_from_IDirect3DVertexBuffer9(buffer); - const struct wined3d_stateblock_state *state; struct wined3d_buffer *wined3d_buffer; HRESULT hr;
TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n", iface, stream_idx, buffer, offset, stride);
- if (stream_idx >= ARRAY_SIZE(state->streams)) + if (stream_idx >= ARRAY_SIZE(device->stateblock_state->streams)) { WARN("Stream index %u out of range.\n", stream_idx); return WINED3DERR_INVALIDCALL; @@ -3685,9 +3684,8 @@ static HRESULT WINAPI d3d9_device_SetStreamSource(IDirect3DDevice9Ex *iface, wined3d_mutex_lock(); if (!buffer_impl) { - const struct wined3d_stream_state *stream; - state = wined3d_stateblock_get_state(device->state); - stream = &state->streams[stream_idx]; + const struct wined3d_stream_state *stream = &device->stateblock_state->streams[stream_idx]; + wined3d_buffer = stream->buffer; offset = stream->offset; stride = stream->stride; @@ -3735,8 +3733,7 @@ static HRESULT WINAPI d3d9_device_GetStreamSource(IDirect3DDevice9Ex *iface, }
wined3d_mutex_lock(); - state = wined3d_stateblock_get_state(device->state); - stream = &state->streams[stream_idx]; + stream = &device->stateblock_state->streams[stream_idx]; if (stream->buffer) { buffer_impl = wined3d_buffer_get_parent(stream->buffer); @@ -3775,7 +3772,7 @@ static HRESULT WINAPI d3d9_device_GetStreamSourceFreq(IDirect3DDevice9Ex *iface, TRACE("iface %p, stream_idx %u, freq %p.\n", iface, stream_idx, freq);
wined3d_mutex_lock(); - stream = &wined3d_stateblock_get_state(device->state)->streams[stream_idx]; + stream = &device->stateblock_state->streams[stream_idx]; *freq = stream->flags | stream->frequency; wined3d_mutex_unlock();
@@ -3818,7 +3815,7 @@ static HRESULT WINAPI d3d9_device_GetIndices(IDirect3DDevice9Ex *iface, IDirect3 return D3DERR_INVALIDCALL;
wined3d_mutex_lock(); - if ((wined3d_buffer = wined3d_stateblock_get_state(device->state)->index_buffer)) + if ((wined3d_buffer = device->stateblock_state->index_buffer)) { buffer_impl = wined3d_buffer_get_parent(wined3d_buffer); *buffer = &buffer_impl->IDirect3DIndexBuffer9_iface; @@ -3888,7 +3885,7 @@ static HRESULT WINAPI d3d9_device_GetPixelShader(IDirect3DDevice9Ex *iface, IDir if (!shader) return D3DERR_INVALIDCALL;
wined3d_mutex_lock(); - if ((wined3d_shader = wined3d_stateblock_get_state(device->state)->ps)) + if ((wined3d_shader = device->stateblock_state->ps)) { shader_impl = wined3d_shader_get_parent(wined3d_shader); *shader = &shader_impl->IDirect3DPixelShader9_iface; @@ -3933,7 +3930,7 @@ static HRESULT WINAPI d3d9_device_GetPixelShaderConstantF(IDirect3DDevice9Ex *if return WINED3DERR_INVALIDCALL;
wined3d_mutex_lock(); - src = wined3d_stateblock_get_state(device->state)->ps_consts_f; + src = device->stateblock_state->ps_consts_f; memcpy(constants, &src[start_idx], count * sizeof(*src)); wined3d_mutex_unlock();
@@ -3970,7 +3967,7 @@ static HRESULT WINAPI d3d9_device_GetPixelShaderConstantI(IDirect3DDevice9Ex *if count = WINED3D_MAX_CONSTS_I - start_idx;
wined3d_mutex_lock(); - src = wined3d_stateblock_get_state(device->state)->ps_consts_i; + src = device->stateblock_state->ps_consts_i; memcpy(constants, &src[start_idx], count * sizeof(*src)); wined3d_mutex_unlock();
@@ -4005,7 +4002,7 @@ static HRESULT WINAPI d3d9_device_GetPixelShaderConstantB(IDirect3DDevice9Ex *if count = WINED3D_MAX_CONSTS_I - start_idx;
wined3d_mutex_lock(); - memcpy(constants, &wined3d_stateblock_get_state(device->state)->ps_consts_b[start_idx], count * sizeof(*constants)); + memcpy(constants, &device->stateblock_state->ps_consts_b[start_idx], count * sizeof(*constants)); wined3d_mutex_unlock();
return D3D_OK; @@ -4640,6 +4637,7 @@ HRESULT device_init(struct d3d9_device *device, struct d3d9 *parent, struct wine wined3d_mutex_unlock(); return hr; } + device->stateblock_state = wined3d_stateblock_get_state(device->state); device->update_state = device->state;
if (flags & D3DCREATE_MULTITHREADED) diff --git a/dlls/d3d9/stateblock.c b/dlls/d3d9/stateblock.c index a65fa1cd8d4..a1ce3d5856c 100644 --- a/dlls/d3d9/stateblock.c +++ b/dlls/d3d9/stateblock.c @@ -151,7 +151,7 @@ static HRESULT WINAPI d3d9_stateblock_Apply(IDirect3DStateBlock9 *iface) device->auto_mipmaps = 0; for (i = 0; i < D3D9_MAX_TEXTURE_UNITS; ++i) { - if ((wined3d_texture = wined3d_stateblock_get_state(device->state)->textures[i]) + if ((wined3d_texture = device->stateblock_state->textures[i]) && (texture = wined3d_texture_get_parent(wined3d_texture)) && texture->usage & D3DUSAGE_AUTOGENMIPMAP) device->auto_mipmaps |= 1u << i;
On Mon, Mar 2, 2020 at 5:40 PM Matteo Bruni mbruni@codeweavers.com wrote:
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Calling into wined3d every time probably has a very small overhead but I think "wasting" 4 / 8 bytes is still preferable.
Do I just need to resend for the conflict or are there objections?
I should probably get some data regardless. I'll have a look.
On Wed, 4 Mar 2020 at 14:57, Matteo Bruni matteo.mystral@gmail.com wrote:
On Mon, Mar 2, 2020 at 5:40 PM Matteo Bruni mbruni@codeweavers.com wrote:
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Calling into wined3d every time probably has a very small overhead but I think "wasting" 4 / 8 bytes is still preferable.
Do I just need to resend for the conflict or are there objections?
Just the conflicts.