Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/wined3d/device.c | 9 ++++----- dlls/wined3d/stateblock.c | 22 ++++++++++++++++------ dlls/wined3d/wined3d_private.h | 2 ++ 3 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index dee99dcde2..8467acf361 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -3431,7 +3431,6 @@ void CDECL wined3d_device_set_texture_stage_state(struct wined3d_device *device, UINT stage, enum wined3d_texture_stage_state state, DWORD value) { const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info; - DWORD old_value;
TRACE("device %p, stage %u, state %s, value %#x.\n", device, stage, debug_d3dtexturestate(state), value); @@ -3449,8 +3448,7 @@ void CDECL wined3d_device_set_texture_stage_state(struct wined3d_device *device, return; }
- old_value = device->update_state->texture_states[stage][state]; - device->update_state->texture_states[stage][state] = value; + device->update_stateblock_state->texture_states[stage][state] = value;
if (device->recording) { @@ -3459,13 +3457,14 @@ void CDECL wined3d_device_set_texture_stage_state(struct wined3d_device *device, return; }
- /* Checked after the assignments to allow proper stateblock recording. */ - if (old_value == value) + if (value == device->state.texture_states[stage][state]) { TRACE("Application is setting the old value over, nothing to do.\n"); return; }
+ device->state.texture_states[stage][state] = value; + wined3d_cs_emit_set_texture_state(device->cs, stage, state, value); }
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index 8117652192..61de76403e 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -925,12 +925,13 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock) for (i = 0; i < stateblock->num_contained_tss_states; ++i) { DWORD stage = stateblock->contained_tss_states[i].stage; - DWORD state = stateblock->contained_tss_states[i].state; + DWORD texture_state = stateblock->contained_tss_states[i].state;
- TRACE("Updating texturestage state %u, %u to %#x (was %#x).\n", stage, state, - src_state->texture_states[stage][state], stateblock->state.texture_states[stage][state]); + TRACE("Updating texturestage state %u, %u to %#x (was %#x).\n", stage, texture_state, + state->texture_states[stage][texture_state], + stateblock->stateblock_state.texture_states[stage][texture_state]);
- stateblock->state.texture_states[stage][state] = src_state->texture_states[stage][state]; + stateblock->stateblock_state.texture_states[stage][texture_state] = state->texture_states[stage][texture_state]; }
/* Samplers */ @@ -1075,9 +1076,11 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock) for (i = 0; i < stateblock->num_contained_tss_states; ++i) { DWORD stage = stateblock->contained_tss_states[i].stage; - DWORD state = stateblock->contained_tss_states[i].state; + DWORD texture_state = stateblock->contained_tss_states[i].state;
- wined3d_device_set_texture_stage_state(device, stage, state, stateblock->state.texture_states[stage][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]); }
/* Sampler states. */ @@ -1396,7 +1399,14 @@ void state_init(struct wined3d_state *state, struct wined3d_fb_state *fb, static void stateblock_state_init_default(struct wined3d_stateblock_state *state, const struct wined3d_d3d_info *d3d_info) { + unsigned int i; + init_default_render_states(state->rs, d3d_info); + + for (i = 0; i < MAX_TEXTURES; ++i) + { + init_default_texture_state(i, state->texture_states[i]); + } }
void wined3d_stateblock_state_init(struct wined3d_stateblock_state *state, diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 1e3ec28d6b..bfeb639ef3 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -2981,6 +2981,8 @@ struct wined3d_stateblock_state BOOL ps_consts_b[WINED3D_MAX_CONSTS_B];
DWORD rs[WINEHIGHEST_RENDER_STATE + 1]; + + DWORD texture_states[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1]; };
struct wined3d_device
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/wined3d/device.c | 20 ++++++++++++++------ dlls/wined3d/stateblock.c | 30 +++++++++++++++++++++++------- dlls/wined3d/wined3d_private.h | 1 + 3 files changed, 38 insertions(+), 13 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 8467acf361..043c89e129 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -3500,10 +3500,19 @@ HRESULT CDECL wined3d_device_set_texture(struct wined3d_device *device, return WINED3D_OK; }
+ if (texture) + wined3d_texture_incref(texture); + if (device->update_stateblock_state->textures[stage]) + wined3d_texture_decref(device->update_stateblock_state->textures[stage]); + device->update_stateblock_state->textures[stage] = texture; + if (device->recording) + { device->recording->changed.textures |= 1u << stage; + return WINED3D_OK; + }
- prev = device->update_state->textures[stage]; + prev = device->state.textures[stage]; TRACE("Previous texture %p.\n", prev);
if (texture == prev) @@ -3513,12 +3522,11 @@ HRESULT CDECL wined3d_device_set_texture(struct wined3d_device *device, }
TRACE("Setting new texture to %p.\n", texture); - device->update_state->textures[stage] = texture; + device->state.textures[stage] = texture;
if (texture) wined3d_texture_incref(texture); - if (!device->recording) - wined3d_cs_emit_set_texture(device->cs, stage, texture); + wined3d_cs_emit_set_texture(device->cs, stage, texture); if (prev) wined3d_texture_decref(prev);
@@ -5182,11 +5190,11 @@ void device_resource_released(struct wined3d_device *device, struct wined3d_reso device->state.textures[i] = NULL; }
- if (device->recording && &device->update_state->textures[i]->resource == resource) + if (device->recording && &device->update_stateblock_state->textures[i]->resource == resource) { ERR("Texture resource %p is still in use by recording stateblock %p, stage %u.\n", resource, device->recording, i); - device->update_state->textures[i] = NULL; + device->update_stateblock_state->textures[i] = NULL; } } break; diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index 61de76403e..121fcf9f96 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -523,7 +523,9 @@ void state_unbind_resources(struct wined3d_state *state)
void wined3d_stateblock_state_cleanup(struct wined3d_stateblock_state *state) { + struct wined3d_texture *texture; struct wined3d_shader *shader; + unsigned int i;
if ((shader = state->vs)) { @@ -536,6 +538,15 @@ void wined3d_stateblock_state_cleanup(struct wined3d_stateblock_state *state) state->ps = NULL; wined3d_shader_decref(shader); } + + for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i) + { + if ((texture = state->textures[i])) + { + state->textures[i] = NULL; + wined3d_texture_decref(texture); + } + } }
void state_cleanup(struct wined3d_state *state) @@ -941,13 +952,13 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock) if (!(map & 1)) continue;
TRACE("Updating texture %u to %p (was %p).\n", - i, src_state->textures[i], stateblock->state.textures[i]); + i, state->textures[i], stateblock->stateblock_state.textures[i]);
- if (src_state->textures[i]) - wined3d_texture_incref(src_state->textures[i]); - if (stateblock->state.textures[i]) - wined3d_texture_decref(stateblock->state.textures[i]); - stateblock->state.textures[i] = src_state->textures[i]; + if (state->textures[i]) + wined3d_texture_incref(state->textures[i]); + if (stateblock->stateblock_state.textures[i]) + wined3d_texture_decref(stateblock->stateblock_state.textures[i]); + stateblock->stateblock_state.textures[i] = state->textures[i]; }
for (i = 0; i < stateblock->num_contained_sampler_states; ++i) @@ -1149,7 +1160,12 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock) if (!(map & 1)) continue;
stage = i < MAX_FRAGMENT_SAMPLERS ? i : WINED3DVERTEXTEXTURESAMPLER0 + i - MAX_FRAGMENT_SAMPLERS; - wined3d_device_set_texture(device, stage, stateblock->state.textures[i]); + 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]); }
map = stateblock->changed.clipplane; diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index bfeb639ef3..269c095ab4 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -2982,6 +2982,7 @@ struct wined3d_stateblock_state
DWORD rs[WINEHIGHEST_RENDER_STATE + 1];
+ struct wined3d_texture *textures[MAX_COMBINED_SAMPLERS]; DWORD texture_states[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1]; };
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/wined3d/stateblock.c | 45 ++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 19 deletions(-)
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index 121fcf9f96..458e8b35d3 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -1340,6 +1340,31 @@ static void init_default_texture_state(unsigned int i, DWORD stage[WINED3D_HIGHE stage[WINED3D_TSS_RESULT_ARG] = WINED3DTA_CURRENT; }
+static void init_default_sampler_states(DWORD states[MAX_COMBINED_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1]) +{ + unsigned int i; + + for (i = 0 ; i < MAX_COMBINED_SAMPLERS; ++i) + { + TRACE("Setting up default samplers states for sampler %u.\n", i); + states[i][WINED3D_SAMP_ADDRESS_U] = WINED3D_TADDRESS_WRAP; + states[i][WINED3D_SAMP_ADDRESS_V] = WINED3D_TADDRESS_WRAP; + states[i][WINED3D_SAMP_ADDRESS_W] = WINED3D_TADDRESS_WRAP; + states[i][WINED3D_SAMP_BORDER_COLOR] = 0; + states[i][WINED3D_SAMP_MAG_FILTER] = WINED3D_TEXF_POINT; + states[i][WINED3D_SAMP_MIN_FILTER] = WINED3D_TEXF_POINT; + states[i][WINED3D_SAMP_MIP_FILTER] = WINED3D_TEXF_NONE; + states[i][WINED3D_SAMP_MIPMAP_LOD_BIAS] = 0; + states[i][WINED3D_SAMP_MAX_MIP_LEVEL] = 0; + states[i][WINED3D_SAMP_MAX_ANISOTROPY] = 1; + states[i][WINED3D_SAMP_SRGB_TEXTURE] = 0; + /* TODO: Indicates which element of a multielement texture to use. */ + states[i][WINED3D_SAMP_ELEMENT_INDEX] = 0; + /* TODO: Vertex offset in the presampled displacement map. */ + states[i][WINED3D_SAMP_DMAP_OFFSET] = 0; + } +} + static void state_init_default(struct wined3d_state *state, const struct wined3d_d3d_info *d3d_info) { unsigned int i; @@ -1369,25 +1394,7 @@ static void state_init_default(struct wined3d_state *state, const struct wined3d init_default_texture_state(i, state->texture_states[i]); }
- for (i = 0 ; i < MAX_COMBINED_SAMPLERS; ++i) - { - TRACE("Setting up default samplers states for sampler %u.\n", i); - state->sampler_states[i][WINED3D_SAMP_ADDRESS_U] = WINED3D_TADDRESS_WRAP; - state->sampler_states[i][WINED3D_SAMP_ADDRESS_V] = WINED3D_TADDRESS_WRAP; - state->sampler_states[i][WINED3D_SAMP_ADDRESS_W] = WINED3D_TADDRESS_WRAP; - state->sampler_states[i][WINED3D_SAMP_BORDER_COLOR] = 0; - state->sampler_states[i][WINED3D_SAMP_MAG_FILTER] = WINED3D_TEXF_POINT; - state->sampler_states[i][WINED3D_SAMP_MIN_FILTER] = WINED3D_TEXF_POINT; - state->sampler_states[i][WINED3D_SAMP_MIP_FILTER] = WINED3D_TEXF_NONE; - state->sampler_states[i][WINED3D_SAMP_MIPMAP_LOD_BIAS] = 0; - state->sampler_states[i][WINED3D_SAMP_MAX_MIP_LEVEL] = 0; - state->sampler_states[i][WINED3D_SAMP_MAX_ANISOTROPY] = 1; - state->sampler_states[i][WINED3D_SAMP_SRGB_TEXTURE] = 0; - /* TODO: Indicates which element of a multielement texture to use. */ - state->sampler_states[i][WINED3D_SAMP_ELEMENT_INDEX] = 0; - /* TODO: Vertex offset in the presampled displacement map. */ - state->sampler_states[i][WINED3D_SAMP_DMAP_OFFSET] = 0; - } + init_default_sampler_states(state->sampler_states);
state->blend_factor.r = 1.0f; state->blend_factor.g = 1.0f;
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- v3: correct stage fixup
dlls/wined3d/device.c | 8 +++----- dlls/wined3d/stateblock.c | 18 +++++++++++------- dlls/wined3d/wined3d_private.h | 1 + 3 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 043c89e129..72e328f630 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -2076,8 +2076,6 @@ DWORD CDECL wined3d_device_get_render_state(const struct wined3d_device *device, void CDECL wined3d_device_set_sampler_state(struct wined3d_device *device, UINT sampler_idx, enum wined3d_sampler_state state, DWORD value) { - DWORD old_value; - TRACE("device %p, sampler_idx %u, state %s, value %#x.\n", device, sampler_idx, debug_d3dsamplerstate(state), value);
@@ -2090,8 +2088,7 @@ void CDECL wined3d_device_set_sampler_state(struct wined3d_device *device, return; /* Windows accepts overflowing this array ... we do not. */ }
- old_value = device->state.sampler_states[sampler_idx][state]; - device->update_state->sampler_states[sampler_idx][state] = value; + device->update_stateblock_state->sampler_states[sampler_idx][state] = value;
/* Handle recording of state blocks. */ if (device->recording) @@ -2101,12 +2098,13 @@ void CDECL wined3d_device_set_sampler_state(struct wined3d_device *device, return; }
- if (old_value == value) + if (value == device->state.sampler_states[sampler_idx][state]) { TRACE("Application is setting the old value over, nothing to do.\n"); return; }
+ device->state.sampler_states[sampler_idx][state] = value; wined3d_cs_emit_set_sampler_state(device->cs, sampler_idx, state, value); }
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index 458e8b35d3..4c43beccc7 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -964,12 +964,13 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock) for (i = 0; i < stateblock->num_contained_sampler_states; ++i) { DWORD stage = stateblock->contained_sampler_states[i].stage; - DWORD state = stateblock->contained_sampler_states[i].state; + DWORD sampler_state = stateblock->contained_sampler_states[i].state;
- TRACE("Updating sampler state %u, %u to %#x (was %#x).\n", stage, state, - src_state->sampler_states[stage][state], stateblock->state.sampler_states[stage][state]); + TRACE("Updating sampler state %u, %u to %#x (was %#x).\n", stage, sampler_state, + state->sampler_states[stage][sampler_state], + stateblock->stateblock_state.sampler_states[stage][sampler_state]);
- stateblock->state.sampler_states[stage][state] = src_state->sampler_states[stage][state]; + stateblock->stateblock_state.sampler_states[stage][sampler_state] = state->sampler_states[stage][sampler_state]; }
if (stateblock->changed.pixelShader && stateblock->stateblock_state.ps != state->ps) @@ -1098,11 +1099,12 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock) for (i = 0; i < stateblock->num_contained_sampler_states; ++i) { DWORD stage = stateblock->contained_sampler_states[i].stage; - DWORD state = stateblock->contained_sampler_states[i].state; - DWORD value = stateblock->state.sampler_states[stage][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 >= MAX_FRAGMENT_SAMPLERS) stage += WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS; - wined3d_device_set_sampler_state(device, stage, state, value); + wined3d_device_set_sampler_state(device, stage, sampler_state, value); }
/* Transform states. */ @@ -1430,6 +1432,8 @@ static void stateblock_state_init_default(struct wined3d_stateblock_state *state { init_default_texture_state(i, state->texture_states[i]); } + + init_default_sampler_states(state->sampler_states); }
void wined3d_stateblock_state_init(struct wined3d_stateblock_state *state, diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 269c095ab4..1a461c0dec 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -2983,6 +2983,7 @@ struct wined3d_stateblock_state DWORD rs[WINEHIGHEST_RENDER_STATE + 1];
struct wined3d_texture *textures[MAX_COMBINED_SAMPLERS]; + DWORD sampler_states[MAX_COMBINED_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1]; DWORD texture_states[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1]; };
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com