wined3d: Stop setting the device state in wined3d_stateblock_apply().

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2020-03-03 17:50:02 -06:00 committed by Alexandre Julliard
parent 873e3d0691
commit 70b3a2624a
1 changed files with 45 additions and 170 deletions

View File

@ -989,142 +989,83 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock,
void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock, void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock,
struct wined3d_stateblock *device_state) struct wined3d_stateblock *device_state)
{ {
struct wined3d_stateblock_state *state = &device_state->stateblock_state; const struct wined3d_stateblock_state *state = &stateblock->stateblock_state;
struct wined3d_device *device = stateblock->device;
struct wined3d_blend_state *blend_state;
struct wined3d_color colour;
struct wined3d_range range; struct wined3d_range range;
unsigned int i, start; unsigned int i, start;
BOOL set_blend_state;
DWORD map; DWORD map;
TRACE("stateblock %p, device_state %p.\n", stateblock, device_state); TRACE("stateblock %p, device_state %p.\n", stateblock, device_state);
if (stateblock->changed.vertexShader) if (stateblock->changed.vertexShader)
{ wined3d_stateblock_set_vertex_shader(device_state, state->vs);
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);
}
for (start = 0; ; start = range.offset + range.size) 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)) if (!wined3d_bitmap_get_range(stateblock->changed.vs_consts_f, WINED3D_MAX_VS_CONSTS_F, start, &range))
break; break;
wined3d_stateblock_set_vs_consts_f(device_state, range.offset, range.size, &state->vs_consts_f[range.offset]);
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; map = stateblock->changed.vertexShaderConstantsI;
for (start = 0; ; start = range.offset + range.size) for (start = 0; ; start = range.offset + range.size)
{ {
if (!wined3d_bitmap_get_range(&map, WINED3D_MAX_CONSTS_I, start, &range)) if (!wined3d_bitmap_get_range(&map, WINED3D_MAX_CONSTS_I, start, &range))
break; break;
wined3d_stateblock_set_vs_consts_i(device_state, range.offset, range.size, &state->vs_consts_i[range.offset]);
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; map = stateblock->changed.vertexShaderConstantsB;
for (start = 0; ; start = range.offset + range.size) for (start = 0; ; start = range.offset + range.size)
{ {
if (!wined3d_bitmap_get_range(&map, WINED3D_MAX_CONSTS_B, start, &range)) if (!wined3d_bitmap_get_range(&map, WINED3D_MAX_CONSTS_B, start, &range))
break; break;
wined3d_stateblock_set_vs_consts_b(device_state, range.offset, range.size, &state->vs_consts_b[range.offset]);
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) 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; 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, wined3d_stateblock_set_light(device_state, light->OriginalIndex, &light->OriginalParms);
&light->OriginalParms, &new_light))) wined3d_stateblock_set_light_enable(device_state, light->OriginalIndex, light->glIndex != -1);
{
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);
} }
} }
} }
if (stateblock->changed.pixelShader) if (stateblock->changed.pixelShader)
{ wined3d_stateblock_set_pixel_shader(device_state, state->ps);
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);
}
for (start = 0; ; start = range.offset + range.size) 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)) if (!wined3d_bitmap_get_range(stateblock->changed.ps_consts_f, WINED3D_MAX_PS_CONSTS_F, start, &range))
break; break;
wined3d_stateblock_set_ps_consts_f(device_state, range.offset, range.size, &state->ps_consts_f[range.offset]);
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; map = stateblock->changed.pixelShaderConstantsI;
for (start = 0; ; start = range.offset + range.size) for (start = 0; ; start = range.offset + range.size)
{ {
if (!wined3d_bitmap_get_range(&map, WINED3D_MAX_CONSTS_I, start, &range)) if (!wined3d_bitmap_get_range(&map, WINED3D_MAX_CONSTS_I, start, &range))
break; break;
wined3d_stateblock_set_ps_consts_i(device_state, range.offset, range.size, &state->ps_consts_i[range.offset]);
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; map = stateblock->changed.pixelShaderConstantsB;
for (start = 0; ; start = range.offset + range.size) for (start = 0; ; start = range.offset + range.size)
{ {
if (!wined3d_bitmap_get_range(&map, WINED3D_MAX_CONSTS_B, start, &range)) if (!wined3d_bitmap_get_range(&map, WINED3D_MAX_CONSTS_B, start, &range))
break; break;
wined3d_stateblock_set_ps_consts_b(device_state, range.offset, range.size, &state->ps_consts_b[range.offset]);
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 if (stateblock->changed.blend_state)
|| wined3d_bitmap_is_set(stateblock->changed.renderState, WINED3D_RS_ADAPTIVETESS_Y)))
{ {
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) if (state->blend_state)
wined3d_blend_state_decref(state->blend_state); wined3d_blend_state_incref(state->blend_state);
if (device_state->stateblock_state.blend_state)
state->blend_state = blend_state; wined3d_blend_state_decref(device_state->stateblock_state.blend_state);
device_state->stateblock_state.blend_state = state->blend_state;
if (wined3d_bitmap_is_set(stateblock->changed.renderState, WINED3D_RS_BLENDFACTOR)) device_state->changed.blend_state = 1;
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);
} }
/* Render states. */ /* 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]; enum wined3d_render_state rs = stateblock->contained_render_states[i];
state->rs[rs] = stateblock->stateblock_state.rs[rs]; wined3d_stateblock_set_render_state(device_state, rs, 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);
}
} }
/* Texture states. */ /* 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 stage = stateblock->contained_tss_states[i].stage;
DWORD texture_state = stateblock->contained_tss_states[i].state; DWORD texture_state = stateblock->contained_tss_states[i].state;
state->texture_states[stage][texture_state] = stateblock->stateblock_state.texture_states[stage][texture_state]; wined3d_stateblock_set_texture_stage_state(device_state, stage, texture_state,
wined3d_device_set_texture_stage_state(device, stage, texture_state, state->texture_states[stage][texture_state]);
stateblock->stateblock_state.texture_states[stage][texture_state]);
} }
/* Sampler states. */ /* 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 stage = stateblock->contained_sampler_states[i].stage;
DWORD sampler_state = stateblock->contained_sampler_states[i].state; 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; 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) 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]; enum wined3d_transform_state transform = stateblock->contained_transform_states[i];
state->transforms[transform] = stateblock->stateblock_state.transforms[transform]; wined3d_stateblock_set_transform(device_state, transform, &state->transforms[transform]);
wined3d_device_set_transform(device, transform, &stateblock->stateblock_state.transforms[transform]);
} }
} }
if (stateblock->changed.indices) if (stateblock->changed.indices)
{ {
if (stateblock->stateblock_state.index_buffer) wined3d_stateblock_set_index_buffer(device_state, state->index_buffer, state->index_format);
wined3d_buffer_incref(stateblock->stateblock_state.index_buffer); wined3d_stateblock_set_base_vertex_index(device_state, state->base_vertex_index);
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);
} }
if (stateblock->changed.vertexDecl && stateblock->stateblock_state.vertex_declaration) if (stateblock->changed.vertexDecl && state->vertex_declaration)
{ wined3d_stateblock_set_vertex_declaration(device_state, 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.material) if (stateblock->changed.material)
{ wined3d_stateblock_set_material(device_state, &state->material);
state->material = stateblock->stateblock_state.material;
wined3d_device_set_material(device, &stateblock->stateblock_state.material);
}
if (stateblock->changed.viewport) if (stateblock->changed.viewport)
{ wined3d_stateblock_set_viewport(device_state, &state->viewport);
state->viewport = stateblock->stateblock_state.viewport;
wined3d_device_set_viewports(device, 1, &stateblock->stateblock_state.viewport);
}
if (stateblock->changed.scissorRect) if (stateblock->changed.scissorRect)
{ wined3d_stateblock_set_scissor_rect(device_state, &state->scissor_rect);
state->scissor_rect = stateblock->stateblock_state.scissor_rect;
wined3d_device_set_scissor_rects(device, 1, &stateblock->stateblock_state.scissor_rect);
}
map = stateblock->changed.streamSource; map = stateblock->changed.streamSource;
for (i = 0; map; map >>= 1, ++i) for (i = 0; map; map >>= 1, ++i)
{ {
unsigned int offset, stride; if (map & 1)
wined3d_stateblock_set_stream_source(device_state, i, state->streams[i].buffer,
if (!(map & 1)) continue; state->streams[i].offset, state->streams[i].stride);
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);
} }
map = stateblock->changed.streamFreq; map = stateblock->changed.streamFreq;
for (i = 0; map; map >>= 1, ++i) for (i = 0; map; map >>= 1, ++i)
{ {
if (!(map & 1)) continue; if (map & 1)
wined3d_stateblock_set_stream_source_freq(device_state, i,
state->streams[i].frequency = stateblock->stateblock_state.streams[i].frequency; state->streams[i].frequency | state->streams[i].flags);
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);
} }
map = stateblock->changed.textures; map = stateblock->changed.textures;
for (i = 0; map; map >>= 1, ++i) 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 (map & 1)
if (stateblock->stateblock_state.textures[i]) wined3d_stateblock_set_texture(device_state, stage, 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]);
} }
map = stateblock->changed.clipplane; map = stateblock->changed.clipplane;
for (i = 0; map; map >>= 1, ++i) for (i = 0; map; map >>= 1, ++i)
{ {
if (!(map & 1)) continue; if (map & 1)
wined3d_stateblock_set_clip_plane(device_state, i, &state->clip_planes[i]);
state->clip_planes[i] = stateblock->stateblock_state.clip_planes[i];
wined3d_device_set_clip_plane(device, i, &stateblock->stateblock_state.clip_planes[i]);
} }
TRACE("Applied stateblock %p.\n", stateblock); TRACE("Applied stateblock %p.\n", stateblock);