-- v2: d3d9: Do not apply the stateblock when clearing. d3d8: Do not apply the stateblock when clearing. ddraw: Do not apply the entire stateblock when clearing. wined3d: Move rasterizer state invalidation to wined3d_stateblock_set_render_state().
From: Elizabeth Figura zfigura@codeweavers.com
Alongside e.g. ffp_ps_settings. --- dlls/wined3d/stateblock.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index 8126cc655c1..966091f9533 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -66,6 +66,7 @@ struct wined3d_saved_states uint32_t point_scale : 1; uint32_t ffp_vs_settings : 1; uint32_t ffp_ps_settings : 1; + uint32_t rasterizer_state : 1; };
struct stage_state @@ -1643,6 +1644,15 @@ void CDECL wined3d_stateblock_set_render_state(struct wined3d_stateblock *stateb stateblock->changed.ffp_ps_constants = 1; break;
+ case WINED3D_RS_FILLMODE: + case WINED3D_RS_CULLMODE: + case WINED3D_RS_SLOPESCALEDEPTHBIAS: + case WINED3D_RS_DEPTHBIAS: + case WINED3D_RS_SCISSORTESTENABLE: + case WINED3D_RS_ANTIALIASEDLINEENABLE: + stateblock->changed.rasterizer_state = 1; + break; + default: break; } @@ -2854,7 +2864,7 @@ static void sampler_desc_from_sampler_states(struct wined3d_sampler_desc *desc, void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device, struct wined3d_stateblock *stateblock) { - bool set_blend_state = false, set_depth_stencil_state = false, set_rasterizer_state = false; + bool set_blend_state = false, set_depth_stencil_state = false;
const struct wined3d_stateblock_state *state = &stateblock->stateblock_state; const unsigned int word_bit_count = sizeof(DWORD) * CHAR_BIT; @@ -2975,15 +2985,6 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device, set_depth_stencil_state = true; break;
- case WINED3D_RS_FILLMODE: - case WINED3D_RS_CULLMODE: - case WINED3D_RS_SLOPESCALEDEPTHBIAS: - case WINED3D_RS_DEPTHBIAS: - case WINED3D_RS_SCISSORTESTENABLE: - case WINED3D_RS_ANTIALIASEDLINEENABLE: - set_rasterizer_state = true; - break; - case WINED3D_RS_ADAPTIVETESS_X: case WINED3D_RS_ADAPTIVETESS_Z: case WINED3D_RS_ADAPTIVETESS_W: @@ -2994,6 +2995,12 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device, changed->lights = 1; break;
+ case WINED3D_RS_FILLMODE: + case WINED3D_RS_CULLMODE: + case WINED3D_RS_SLOPESCALEDEPTHBIAS: + case WINED3D_RS_DEPTHBIAS: + case WINED3D_RS_SCISSORTESTENABLE: + case WINED3D_RS_ANTIALIASEDLINEENABLE: case WINED3D_RS_ADAPTIVETESS_Y: case WINED3D_RS_POINTSCALEENABLE: case WINED3D_RS_POINTSCALE_A: @@ -3204,7 +3211,7 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device, } }
- if (set_rasterizer_state) + if (changed->rasterizer_state) { struct wined3d_rasterizer_state *rasterizer_state; struct wined3d_rasterizer_state_desc desc;
From: Elizabeth Figura zfigura@codeweavers.com
--- dlls/ddraw/device.c | 2 +- dlls/wined3d/stateblock.c | 93 +++++++++++++++++++++------------------ dlls/wined3d/wined3d.spec | 1 + include/wine/wined3d.h | 1 + 4 files changed, 53 insertions(+), 44 deletions(-)
diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c index 896eea68f14..65e0715b5e7 100644 --- a/dlls/ddraw/device.c +++ b/dlls/ddraw/device.c @@ -5173,7 +5173,7 @@ static HRESULT d3d_device7_Clear(IDirect3DDevice7 *iface, DWORD count, }
wined3d_mutex_lock(); - wined3d_device_apply_stateblock(device->wined3d_device, device->state); + wined3d_stateblock_apply_clear_state(device->state, device->wined3d_device); d3d_device_sync_rendertarget(device); hr = wined3d_device_clear(device->wined3d_device, count, (RECT *)rects, flags, &c, z, stencil); wined3d_mutex_unlock(); diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index 966091f9533..f2307b97e08 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -2861,6 +2861,54 @@ static void sampler_desc_from_sampler_states(struct wined3d_sampler_desc *desc, } }
+void CDECL wined3d_stateblock_apply_clear_state(struct wined3d_stateblock *stateblock, struct wined3d_device *device) +{ + const struct wined3d_stateblock_state *state = &stateblock->stateblock_state; + struct wined3d_device_context *context = &device->cs->c; + + /* Clear state depends on the viewport, scissor rect, and scissor enable. */ + + if (stateblock->changed.viewport) + wined3d_device_context_set_viewports(context, 1, &state->viewport); + if (stateblock->changed.scissorRect) + wined3d_device_context_set_scissor_rects(context, 1, &state->scissor_rect); + + if (stateblock->changed.rasterizer_state) + { + struct wined3d_rasterizer_state *rasterizer_state; + struct wined3d_rasterizer_state_desc desc; + struct wine_rb_entry *entry; + + memset(&desc, 0, sizeof(desc)); + desc.fill_mode = state->rs[WINED3D_RS_FILLMODE]; + desc.cull_mode = state->rs[WINED3D_RS_CULLMODE]; + desc.depth_bias = int_to_float(state->rs[WINED3D_RS_DEPTHBIAS]); + desc.scale_bias = int_to_float(state->rs[WINED3D_RS_SLOPESCALEDEPTHBIAS]); + desc.depth_clip = TRUE; + desc.scissor = state->rs[WINED3D_RS_SCISSORTESTENABLE]; + desc.line_antialias = state->rs[WINED3D_RS_ANTIALIASEDLINEENABLE]; + + if ((entry = wine_rb_get(&device->rasterizer_states, &desc))) + { + rasterizer_state = WINE_RB_ENTRY_VALUE(entry, struct wined3d_rasterizer_state, entry); + wined3d_device_context_set_rasterizer_state(context, rasterizer_state); + } + else if (SUCCEEDED(wined3d_rasterizer_state_create(device, &desc, NULL, + &wined3d_null_parent_ops, &rasterizer_state))) + { + wined3d_device_context_set_rasterizer_state(context, rasterizer_state); + if (wine_rb_put(&device->rasterizer_states, &desc, &rasterizer_state->entry) == -1) + { + ERR("Failed to insert rasterizer state.\n"); + wined3d_rasterizer_state_decref(rasterizer_state); + } + } + } + + if (wined3d_bitmap_is_set(stateblock->changed.renderState, WINED3D_RS_SRGBWRITEENABLE)) + wined3d_device_set_render_state(device, WINED3D_RS_SRGBWRITEENABLE, state->rs[WINED3D_RS_SRGBWRITEENABLE]); +} + void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device, struct wined3d_stateblock *stateblock) { @@ -2877,6 +2925,8 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device,
TRACE("device %p, stateblock %p.\n", device, stateblock);
+ wined3d_stateblock_apply_clear_state(stateblock, device); + if (changed->vertexShader) { wined3d_device_context_set_shader(context, WINED3D_SHADER_TYPE_VERTEX, state->vs); @@ -3211,45 +3261,6 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device, } }
- if (changed->rasterizer_state) - { - struct wined3d_rasterizer_state *rasterizer_state; - struct wined3d_rasterizer_state_desc desc; - struct wine_rb_entry *entry; - union - { - DWORD d; - float f; - } bias; - - memset(&desc, 0, sizeof(desc)); - desc.fill_mode = state->rs[WINED3D_RS_FILLMODE]; - desc.cull_mode = state->rs[WINED3D_RS_CULLMODE]; - bias.d = state->rs[WINED3D_RS_DEPTHBIAS]; - desc.depth_bias = bias.f; - bias.d = state->rs[WINED3D_RS_SLOPESCALEDEPTHBIAS]; - desc.scale_bias = bias.f; - desc.depth_clip = TRUE; - desc.scissor = state->rs[WINED3D_RS_SCISSORTESTENABLE]; - desc.line_antialias = state->rs[WINED3D_RS_ANTIALIASEDLINEENABLE]; - - if ((entry = wine_rb_get(&device->rasterizer_states, &desc))) - { - rasterizer_state = WINE_RB_ENTRY_VALUE(entry, struct wined3d_rasterizer_state, entry); - wined3d_device_context_set_rasterizer_state(context, rasterizer_state); - } - else if (SUCCEEDED(wined3d_rasterizer_state_create(device, &desc, NULL, - &wined3d_null_parent_ops, &rasterizer_state))) - { - wined3d_device_context_set_rasterizer_state(context, rasterizer_state); - if (wine_rb_put(&device->rasterizer_states, &desc, &rasterizer_state->entry) == -1) - { - ERR("Failed to insert rasterizer state.\n"); - wined3d_rasterizer_state_decref(rasterizer_state); - } - } - } - if (set_blend_state || changed->alpha_to_coverage || wined3d_bitmap_is_set(changed->renderState, WINED3D_RS_ADAPTIVETESS_Y)) { @@ -3498,10 +3509,6 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device, wined3d_device_set_base_vertex_index(device, state->base_vertex_index); if (changed->vertexDecl) wined3d_device_context_set_vertex_declaration(context, state->vertex_declaration); - if (changed->viewport) - wined3d_device_context_set_viewports(context, 1, &state->viewport); - if (changed->scissorRect) - wined3d_device_context_set_scissor_rects(context, 1, &state->scissor_rect);
map = changed->streamSource | changed->streamFreq; while (map) diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec index 3bfe6d2b200..4d19e6d975f 100644 --- a/dlls/wined3d/wined3d.spec +++ b/dlls/wined3d/wined3d.spec @@ -228,6 +228,7 @@ @ cdecl wined3d_state_get_feature_level(ptr)
@ cdecl wined3d_stateblock_apply(ptr ptr) +@ cdecl wined3d_stateblock_apply_clear_state(ptr ptr) @ cdecl wined3d_stateblock_capture(ptr ptr) @ cdecl wined3d_stateblock_create(ptr ptr long ptr) @ cdecl wined3d_stateblock_decref(ptr) diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index 2d2d097497e..73af1be484b 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -2754,6 +2754,7 @@ enum wined3d_feature_level __cdecl wined3d_state_get_feature_level(const struct
void __cdecl wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock, struct wined3d_stateblock *device_state); +void __cdecl wined3d_stateblock_apply_clear_state(struct wined3d_stateblock *stateblock, struct wined3d_device *device); void __cdecl wined3d_stateblock_capture(struct wined3d_stateblock *stateblock, const struct wined3d_stateblock *device_state); HRESULT __cdecl wined3d_stateblock_create(struct wined3d_device *device, const struct wined3d_stateblock *device_state,
From: Elizabeth Figura zfigura@codeweavers.com
--- dlls/d3d8/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c index e9cdfa9b4ff..8a1393909d3 100644 --- a/dlls/d3d8/device.c +++ b/dlls/d3d8/device.c @@ -1723,7 +1723,7 @@ static HRESULT WINAPI d3d8_device_Clear(IDirect3DDevice8 *iface, DWORD rect_coun }
wined3d_mutex_lock(); - wined3d_device_apply_stateblock(device->wined3d_device, device->state); + wined3d_stateblock_apply_clear_state(device->state, device->wined3d_device); hr = wined3d_device_clear(device->wined3d_device, rect_count, (const RECT *)rects, flags, &c, z, stencil); wined3d_mutex_unlock();
From: Elizabeth Figura zfigura@codeweavers.com
--- dlls/d3d9/device.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index b6a3e1f58ba..e9499a3be9b 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -2046,7 +2046,7 @@ static HRESULT WINAPI d3d9_device_ColorFill(IDirect3DDevice9Ex *iface, return D3DERR_INVALIDCALL; }
- wined3d_device_apply_stateblock(device->wined3d_device, device->state); + wined3d_stateblock_apply_clear_state(device->state, device->wined3d_device); rtv = d3d9_surface_acquire_rendertarget_view(surface_impl); hr = wined3d_device_context_clear_rendertarget_view(device->immediate_context, rtv, rect, WINED3DCLEAR_TARGET, &c, 0.0f, 0); @@ -2298,7 +2298,7 @@ static HRESULT WINAPI d3d9_device_Clear(IDirect3DDevice9Ex *iface, DWORD rect_co
wined3d_color_from_d3dcolor(&c, color); wined3d_mutex_lock(); - wined3d_device_apply_stateblock(device->wined3d_device, device->state); + wined3d_stateblock_apply_clear_state(device->state, device->wined3d_device); hr = wined3d_device_clear(device->wined3d_device, rect_count, (const RECT *)rects, flags, &c, z, stencil); if (SUCCEEDED(hr)) d3d9_rts_flag_auto_gen_mipmap(device);
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=148703
Your paranoid android.
=== debian11b (64 bit WoW report) ===
d3d9: d3d9ex.c:3236: Test failed: Got unexpected WINDOWPOS hwnd=0000000000000000, x=0, y=0, cx=0, cy=0, flags=0
Report validation errors: mshtml:script crashed (c0000005)
This merge request was approved by Jan Sikorski.