From 70b3a2624ae188ff4f015d7d526aa0b04cbfbc60 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Tue, 3 Mar 2020 17:50:02 -0600 Subject: [PATCH] wined3d: Stop setting the device state in wined3d_stateblock_apply(). Signed-off-by: Zebediah Figura Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/wined3d/stateblock.c | 215 ++++++++------------------------------ 1 file changed, 45 insertions(+), 170 deletions(-) diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index 208a1f06067..70943afddaa 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -989,142 +989,83 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock, void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock, struct wined3d_stateblock *device_state) { - 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; + const struct wined3d_stateblock_state *state = &stateblock->stateblock_state; struct wined3d_range range; unsigned int i, start; - BOOL set_blend_state; DWORD map; TRACE("stateblock %p, device_state %p.\n", stateblock, device_state); if (stateblock->changed.vertexShader) - { - if (stateblock->stateblock_state.vs) - wined3d_shader_incref(stateblock->stateblock_state.vs); - if (state->vs) - wined3d_shader_decref(state->vs); - state->vs = stateblock->stateblock_state.vs; - wined3d_device_set_vertex_shader(device, stateblock->stateblock_state.vs); - } + wined3d_stateblock_set_vertex_shader(device_state, state->vs); for (start = 0; ; start = range.offset + range.size) { if (!wined3d_bitmap_get_range(stateblock->changed.vs_consts_f, WINED3D_MAX_VS_CONSTS_F, start, &range)) break; - - 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]); + wined3d_stateblock_set_vs_consts_f(device_state, range.offset, range.size, &state->vs_consts_f[range.offset]); } map = stateblock->changed.vertexShaderConstantsI; for (start = 0; ; start = range.offset + range.size) { if (!wined3d_bitmap_get_range(&map, WINED3D_MAX_CONSTS_I, start, &range)) break; - - 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]); + wined3d_stateblock_set_vs_consts_i(device_state, range.offset, range.size, &state->vs_consts_i[range.offset]); } map = stateblock->changed.vertexShaderConstantsB; for (start = 0; ; start = range.offset + range.size) { if (!wined3d_bitmap_get_range(&map, WINED3D_MAX_CONSTS_B, start, &range)) break; - - 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]); + wined3d_stateblock_set_vs_consts_b(device_state, range.offset, range.size, &state->vs_consts_b[range.offset]); } if (stateblock->changed.lights) { - for (i = 0; i < ARRAY_SIZE(stateblock->stateblock_state.light_state->light_map); ++i) + for (i = 0; i < ARRAY_SIZE(state->light_state->light_map); ++i) { 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) + LIST_FOR_EACH_ENTRY(light, &state->light_state->light_map[i], struct wined3d_light_info, entry) { - 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_stateblock_set_light(device_state, light->OriginalIndex, &light->OriginalParms); + wined3d_stateblock_set_light_enable(device_state, light->OriginalIndex, light->glIndex != -1); } } } if (stateblock->changed.pixelShader) - { - if (stateblock->stateblock_state.ps) - wined3d_shader_incref(stateblock->stateblock_state.ps); - if (state->ps) - wined3d_shader_decref(state->ps); - state->ps = stateblock->stateblock_state.ps; - wined3d_device_set_pixel_shader(device, stateblock->stateblock_state.ps); - } + wined3d_stateblock_set_pixel_shader(device_state, state->ps); for (start = 0; ; start = range.offset + range.size) { if (!wined3d_bitmap_get_range(stateblock->changed.ps_consts_f, WINED3D_MAX_PS_CONSTS_F, start, &range)) break; - - 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]); + wined3d_stateblock_set_ps_consts_f(device_state, range.offset, range.size, &state->ps_consts_f[range.offset]); } map = stateblock->changed.pixelShaderConstantsI; for (start = 0; ; start = range.offset + range.size) { if (!wined3d_bitmap_get_range(&map, WINED3D_MAX_CONSTS_I, start, &range)) break; - - 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]); + wined3d_stateblock_set_ps_consts_i(device_state, range.offset, range.size, &state->ps_consts_i[range.offset]); } map = stateblock->changed.pixelShaderConstantsB; for (start = 0; ; start = range.offset + range.size) { if (!wined3d_bitmap_get_range(&map, WINED3D_MAX_CONSTS_B, start, &range)) break; - - 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]); + wined3d_stateblock_set_ps_consts_b(device_state, range.offset, range.size, &state->ps_consts_b[range.offset]); } - if ((set_blend_state = stateblock->changed.blend_state - || wined3d_bitmap_is_set(stateblock->changed.renderState, WINED3D_RS_ADAPTIVETESS_Y))) + if (stateblock->changed.blend_state) { - blend_state = stateblock->stateblock_state.rs[WINED3D_RS_ADAPTIVETESS_Y] == WINED3DFMT_ATOC - ? device->blend_state_atoc_enabled : stateblock->stateblock_state.blend_state; - - if (blend_state) - wined3d_blend_state_incref(blend_state); if (state->blend_state) - wined3d_blend_state_decref(state->blend_state); - - state->blend_state = blend_state; - - if (wined3d_bitmap_is_set(stateblock->changed.renderState, WINED3D_RS_BLENDFACTOR)) - wined3d_color_from_d3dcolor(&colour, stateblock->stateblock_state.rs[WINED3D_RS_BLENDFACTOR]); - else - wined3d_device_get_blend_state(device, &colour); - - wined3d_device_set_blend_state(device, blend_state, &colour); + wined3d_blend_state_incref(state->blend_state); + if (device_state->stateblock_state.blend_state) + wined3d_blend_state_decref(device_state->stateblock_state.blend_state); + device_state->stateblock_state.blend_state = state->blend_state; + device_state->changed.blend_state = 1; } /* Render states. */ @@ -1132,19 +1073,7 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock, { enum wined3d_render_state rs = stateblock->contained_render_states[i]; - state->rs[rs] = stateblock->stateblock_state.rs[rs]; - if (rs != WINED3D_RS_BLENDFACTOR) - { - wined3d_device_set_render_state(device, rs, stateblock->stateblock_state.rs[rs]); - continue; - } - - if (!set_blend_state) - { - blend_state = wined3d_device_get_blend_state(device, &colour); - wined3d_color_from_d3dcolor(&colour, stateblock->stateblock_state.rs[rs]); - wined3d_device_set_blend_state(device, blend_state, &colour); - } + wined3d_stateblock_set_render_state(device_state, rs, state->rs[rs]); } /* Texture states. */ @@ -1153,9 +1082,8 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock, DWORD stage = stateblock->contained_tss_states[i].stage; DWORD texture_state = stateblock->contained_tss_states[i].state; - state->texture_states[stage][texture_state] = stateblock->stateblock_state.texture_states[stage][texture_state]; - wined3d_device_set_texture_stage_state(device, stage, texture_state, - stateblock->stateblock_state.texture_states[stage][texture_state]); + wined3d_stateblock_set_texture_stage_state(device_state, stage, texture_state, + state->texture_states[stage][texture_state]); } /* Sampler states. */ @@ -1163,11 +1091,10 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock, { DWORD stage = stateblock->contained_sampler_states[i].stage; DWORD sampler_state = stateblock->contained_sampler_states[i].state; - DWORD value = stateblock->stateblock_state.sampler_states[stage][sampler_state]; - state->sampler_states[stage][sampler_state] = value; if (stage >= WINED3D_MAX_FRAGMENT_SAMPLERS) stage += WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS; - wined3d_device_set_sampler_state(device, stage, sampler_state, value); + wined3d_stateblock_set_sampler_state(device_state, stage, sampler_state, + state->sampler_states[stage][sampler_state]); } if (stateblock->changed.transforms) @@ -1176,113 +1103,61 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock, { 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]); + wined3d_stateblock_set_transform(device_state, transform, &state->transforms[transform]); } } if (stateblock->changed.indices) { - if (stateblock->stateblock_state.index_buffer) - wined3d_buffer_incref(stateblock->stateblock_state.index_buffer); - if (state->index_buffer) - wined3d_buffer_decref(state->index_buffer); - state->index_buffer = stateblock->stateblock_state.index_buffer; - state->index_format = stateblock->stateblock_state.index_format; - state->base_vertex_index = stateblock->stateblock_state.base_vertex_index; - - wined3d_device_set_index_buffer(device, stateblock->stateblock_state.index_buffer, - stateblock->stateblock_state.index_format, 0); - wined3d_device_set_base_vertex_index(device, stateblock->stateblock_state.base_vertex_index); + wined3d_stateblock_set_index_buffer(device_state, state->index_buffer, state->index_format); + wined3d_stateblock_set_base_vertex_index(device_state, state->base_vertex_index); } - if (stateblock->changed.vertexDecl && stateblock->stateblock_state.vertex_declaration) - { - if (stateblock->stateblock_state.vertex_declaration) - wined3d_vertex_declaration_incref(stateblock->stateblock_state.vertex_declaration); - if (state->vertex_declaration) - wined3d_vertex_declaration_decref(state->vertex_declaration); - state->vertex_declaration = stateblock->stateblock_state.vertex_declaration; - wined3d_device_set_vertex_declaration(device, stateblock->stateblock_state.vertex_declaration); - } + if (stateblock->changed.vertexDecl && state->vertex_declaration) + wined3d_stateblock_set_vertex_declaration(device_state, state->vertex_declaration); if (stateblock->changed.material) - { - state->material = stateblock->stateblock_state.material; - wined3d_device_set_material(device, &stateblock->stateblock_state.material); - } + wined3d_stateblock_set_material(device_state, &state->material); if (stateblock->changed.viewport) - { - state->viewport = stateblock->stateblock_state.viewport; - - wined3d_device_set_viewports(device, 1, &stateblock->stateblock_state.viewport); - } + wined3d_stateblock_set_viewport(device_state, &state->viewport); if (stateblock->changed.scissorRect) - { - state->scissor_rect = stateblock->stateblock_state.scissor_rect; - - wined3d_device_set_scissor_rects(device, 1, &stateblock->stateblock_state.scissor_rect); - } + wined3d_stateblock_set_scissor_rect(device_state, &state->scissor_rect); map = stateblock->changed.streamSource; for (i = 0; map; map >>= 1, ++i) { - unsigned int offset, stride; - - if (!(map & 1)) continue; - - if (stateblock->stateblock_state.streams[i].buffer) - wined3d_buffer_incref(stateblock->stateblock_state.streams[i].buffer); - if (state->streams[i].buffer) - wined3d_buffer_decref(state->streams[i].buffer); - state->streams[i].buffer = stateblock->stateblock_state.streams[i].buffer; - - offset = stateblock->stateblock_state.streams[i].offset; - stride = stateblock->stateblock_state.streams[i].stride; - - state->streams[i].stride = stride; - state->streams[i].offset = offset; - wined3d_device_set_stream_source(device, i, - stateblock->stateblock_state.streams[i].buffer, offset, stride); + if (map & 1) + wined3d_stateblock_set_stream_source(device_state, i, state->streams[i].buffer, + state->streams[i].offset, state->streams[i].stride); } map = stateblock->changed.streamFreq; for (i = 0; map; map >>= 1, ++i) { - if (!(map & 1)) continue; - - state->streams[i].frequency = stateblock->stateblock_state.streams[i].frequency; - state->streams[i].flags = stateblock->stateblock_state.streams[i].flags; - - wined3d_device_set_stream_source_freq(device, i, - stateblock->stateblock_state.streams[i].frequency | stateblock->stateblock_state.streams[i].flags); + if (map & 1) + wined3d_stateblock_set_stream_source_freq(device_state, i, + state->streams[i].frequency | state->streams[i].flags); } map = stateblock->changed.textures; for (i = 0; map; map >>= 1, ++i) { - DWORD stage; + DWORD stage = i; - if (!(map & 1)) continue; + if (stage >= WINED3D_MAX_FRAGMENT_SAMPLERS) + stage += WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS; - stage = i < WINED3D_MAX_FRAGMENT_SAMPLERS ? i : WINED3DVERTEXTEXTURESAMPLER0 + i - WINED3D_MAX_FRAGMENT_SAMPLERS; - if (stateblock->stateblock_state.textures[i]) - wined3d_texture_incref(stateblock->stateblock_state.textures[i]); - if (state->textures[i]) - wined3d_texture_decref(state->textures[i]); - state->textures[i] = stateblock->stateblock_state.textures[i]; - wined3d_device_set_texture(device, stage, stateblock->stateblock_state.textures[i]); + if (map & 1) + wined3d_stateblock_set_texture(device_state, stage, state->textures[i]); } map = stateblock->changed.clipplane; for (i = 0; map; map >>= 1, ++i) { - if (!(map & 1)) continue; - - state->clip_planes[i] = stateblock->stateblock_state.clip_planes[i]; - wined3d_device_set_clip_plane(device, i, &stateblock->stateblock_state.clip_planes[i]); + if (map & 1) + wined3d_stateblock_set_clip_plane(device_state, i, &state->clip_planes[i]); } TRACE("Applied stateblock %p.\n", stateblock);