From 4a5760b28b356bdbeac18677d5bde772f3e46a32 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Fri, 25 Sep 2020 16:01:22 -0500 Subject: [PATCH] wined3d: Move the depth write enable state to wined3d_depth_stencil_state. Signed-off-by: Zebediah Figura Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/d3d11/device.c | 4 ---- dlls/d3d11/state.c | 1 + dlls/wined3d/adapter_vk.c | 29 ++++++++++++++--------------- dlls/wined3d/context_gl.c | 2 +- dlls/wined3d/context_vk.c | 5 +++-- dlls/wined3d/device.c | 2 ++ dlls/wined3d/directx.c | 1 - dlls/wined3d/state.c | 29 ++++++++++++----------------- dlls/wined3d/texture.c | 4 ++-- dlls/wined3d/wined3d_private.h | 5 +++-- include/wine/wined3d.h | 1 + 11 files changed, 39 insertions(+), 44 deletions(-) diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c index ca9975d6a22..a8cba49e039 100644 --- a/dlls/d3d11/device.c +++ b/dlls/d3d11/device.c @@ -726,7 +726,6 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetBlendState(ID3D11Devi static void set_default_depth_stencil_state(struct wined3d_device *wined3d_device) { - wined3d_device_set_render_state(wined3d_device, WINED3D_RS_ZWRITEENABLE, D3D11_DEPTH_WRITE_MASK_ALL); wined3d_device_set_render_state(wined3d_device, WINED3D_RS_ZFUNC, WINED3D_CMP_LESS); wined3d_device_set_render_state(wined3d_device, WINED3D_RS_STENCILENABLE, FALSE); } @@ -759,10 +758,7 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetDepthStencilState(ID3 back = &desc->BackFace; if (desc->DepthEnable) - { - wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZWRITEENABLE, desc->DepthWriteMask); wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZFUNC, desc->DepthFunc); - } wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILENABLE, desc->StencilEnable); if (desc->StencilEnable) diff --git a/dlls/d3d11/state.c b/dlls/d3d11/state.c index 5d4c3526595..d0513543c80 100644 --- a/dlls/d3d11/state.c +++ b/dlls/d3d11/state.c @@ -795,6 +795,7 @@ HRESULT d3d_depthstencil_state_create(struct d3d_device *device, const D3D11_DEP } wined3d_desc.depth = desc->DepthEnable; + wined3d_desc.depth_write = desc->DepthWriteMask; /* We cannot fail after creating a wined3d_depth_stencil_state object. It * would lead to double free. */ diff --git a/dlls/wined3d/adapter_vk.c b/dlls/wined3d/adapter_vk.c index 7b0c0c89897..2045cf181cb 100644 --- a/dlls/wined3d/adapter_vk.c +++ b/dlls/wined3d/adapter_vk.c @@ -106,9 +106,8 @@ static const struct wined3d_state_entry_template misc_state_template_vk[] = {STATE_RENDER(WINED3D_RS_MONOENABLE), {STATE_RENDER(WINED3D_RS_MONOENABLE), state_nop}}, {STATE_RENDER(WINED3D_RS_ROP2), {STATE_RENDER(WINED3D_RS_ROP2), state_nop}}, {STATE_RENDER(WINED3D_RS_PLANEMASK), {STATE_RENDER(WINED3D_RS_PLANEMASK), state_nop}}, - {STATE_RENDER(WINED3D_RS_ZWRITEENABLE), {STATE_RENDER(WINED3D_RS_ZWRITEENABLE), state_nop}}, {STATE_RENDER(WINED3D_RS_LASTPIXEL), {STATE_RENDER(WINED3D_RS_LASTPIXEL), state_nop}}, - {STATE_RENDER(WINED3D_RS_ZFUNC), {STATE_RENDER(WINED3D_RS_ZWRITEENABLE)}}, + {STATE_RENDER(WINED3D_RS_ZFUNC), {STATE_RENDER(WINED3D_RS_ZFUNC), state_nop}}, {STATE_RENDER(WINED3D_RS_DITHERENABLE), {STATE_RENDER(WINED3D_RS_DITHERENABLE), state_nop}}, {STATE_RENDER(WINED3D_RS_SUBPIXEL), {STATE_RENDER(WINED3D_RS_SUBPIXEL), state_nop}}, {STATE_RENDER(WINED3D_RS_SUBPIXELX), {STATE_RENDER(WINED3D_RS_SUBPIXELX), state_nop}}, @@ -118,19 +117,19 @@ static const struct wined3d_state_entry_template misc_state_template_vk[] = {STATE_RENDER(WINED3D_RS_ANISOTROPY), {STATE_RENDER(WINED3D_RS_ANISOTROPY), state_nop}}, {STATE_RENDER(WINED3D_RS_FLUSHBATCH), {STATE_RENDER(WINED3D_RS_FLUSHBATCH), state_nop}}, {STATE_RENDER(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT), {STATE_RENDER(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT), state_nop}}, - {STATE_RENDER(WINED3D_RS_STENCILENABLE), {STATE_RENDER(WINED3D_RS_ZWRITEENABLE)}}, - {STATE_RENDER(WINED3D_RS_STENCILFAIL), {STATE_RENDER(WINED3D_RS_ZWRITEENABLE)}}, - {STATE_RENDER(WINED3D_RS_STENCILZFAIL), {STATE_RENDER(WINED3D_RS_ZWRITEENABLE)}}, - {STATE_RENDER(WINED3D_RS_STENCILPASS), {STATE_RENDER(WINED3D_RS_ZWRITEENABLE)}}, - {STATE_RENDER(WINED3D_RS_STENCILFUNC), {STATE_RENDER(WINED3D_RS_ZWRITEENABLE)}}, - {STATE_RENDER(WINED3D_RS_STENCILREF), {STATE_RENDER(WINED3D_RS_ZWRITEENABLE)}}, - {STATE_RENDER(WINED3D_RS_STENCILMASK), {STATE_RENDER(WINED3D_RS_ZWRITEENABLE)}}, - {STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), {STATE_RENDER(WINED3D_RS_ZWRITEENABLE)}}, - {STATE_RENDER(WINED3D_RS_TWOSIDEDSTENCILMODE), {STATE_RENDER(WINED3D_RS_ZWRITEENABLE)}}, - {STATE_RENDER(WINED3D_RS_BACK_STENCILFAIL), {STATE_RENDER(WINED3D_RS_ZWRITEENABLE)}}, - {STATE_RENDER(WINED3D_RS_BACK_STENCILZFAIL), {STATE_RENDER(WINED3D_RS_ZWRITEENABLE)}}, - {STATE_RENDER(WINED3D_RS_BACK_STENCILPASS), {STATE_RENDER(WINED3D_RS_ZWRITEENABLE)}}, - {STATE_RENDER(WINED3D_RS_BACK_STENCILFUNC), {STATE_RENDER(WINED3D_RS_ZWRITEENABLE)}}, + {STATE_RENDER(WINED3D_RS_STENCILENABLE), {STATE_RENDER(WINED3D_RS_ZFUNC)}}, + {STATE_RENDER(WINED3D_RS_STENCILFAIL), {STATE_RENDER(WINED3D_RS_ZFUNC)}}, + {STATE_RENDER(WINED3D_RS_STENCILZFAIL), {STATE_RENDER(WINED3D_RS_ZFUNC)}}, + {STATE_RENDER(WINED3D_RS_STENCILPASS), {STATE_RENDER(WINED3D_RS_ZFUNC)}}, + {STATE_RENDER(WINED3D_RS_STENCILFUNC), {STATE_RENDER(WINED3D_RS_ZFUNC)}}, + {STATE_RENDER(WINED3D_RS_STENCILREF), {STATE_RENDER(WINED3D_RS_ZFUNC)}}, + {STATE_RENDER(WINED3D_RS_STENCILMASK), {STATE_RENDER(WINED3D_RS_ZFUNC)}}, + {STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), {STATE_RENDER(WINED3D_RS_ZFUNC)}}, + {STATE_RENDER(WINED3D_RS_TWOSIDEDSTENCILMODE), {STATE_RENDER(WINED3D_RS_ZFUNC)}}, + {STATE_RENDER(WINED3D_RS_BACK_STENCILFAIL), {STATE_RENDER(WINED3D_RS_ZFUNC)}}, + {STATE_RENDER(WINED3D_RS_BACK_STENCILZFAIL), {STATE_RENDER(WINED3D_RS_ZFUNC)}}, + {STATE_RENDER(WINED3D_RS_BACK_STENCILPASS), {STATE_RENDER(WINED3D_RS_ZFUNC)}}, + {STATE_RENDER(WINED3D_RS_BACK_STENCILFUNC), {STATE_RENDER(WINED3D_RS_ZFUNC)}}, {STATE_RENDER(WINED3D_RS_WRAP0), {STATE_RENDER(WINED3D_RS_WRAP0), state_nop}}, {STATE_RENDER(WINED3D_RS_WRAP1), {STATE_RENDER(WINED3D_RS_WRAP0)}}, {STATE_RENDER(WINED3D_RS_WRAP2), {STATE_RENDER(WINED3D_RS_WRAP0)}}, diff --git a/dlls/wined3d/context_gl.c b/dlls/wined3d/context_gl.c index 186d70b45ad..8c247afa02a 100644 --- a/dlls/wined3d/context_gl.c +++ b/dlls/wined3d/context_gl.c @@ -4507,7 +4507,7 @@ void draw_primitive(struct wined3d_device *device, const struct wined3d_state *s return; } - if (dsv && state->render_states[WINED3D_RS_ZWRITEENABLE]) + if (dsv && (!state->depth_stencil_state || state->depth_stencil_state->desc.depth_write)) { DWORD location = context->render_offscreen ? dsv->resource->draw_binding : WINED3D_LOCATION_DRAWABLE; diff --git a/dlls/wined3d/context_vk.c b/dlls/wined3d/context_vk.c index 356fec27a78..4a646504b3e 100644 --- a/dlls/wined3d/context_vk.c +++ b/dlls/wined3d/context_vk.c @@ -2042,12 +2042,13 @@ static bool wined3d_context_vk_update_graphics_pipeline_key(struct wined3d_conte if (d) { key->ds_desc.depthTestEnable = d->desc.depth; + key->ds_desc.depthWriteEnable = d->desc.depth_write; } else { key->ds_desc.depthTestEnable = VK_TRUE; + key->ds_desc.depthWriteEnable = VK_TRUE; } - key->ds_desc.depthWriteEnable = !!state->render_states[WINED3D_RS_ZWRITEENABLE]; key->ds_desc.depthCompareOp = vk_compare_op_from_wined3d(state->render_states[WINED3D_RS_ZFUNC]); key->ds_desc.stencilTestEnable = state->fb.depth_stencil && state->render_states[WINED3D_RS_STENCILENABLE]; if (key->ds_desc.stencilTestEnable) @@ -2862,7 +2863,7 @@ VkCommandBuffer wined3d_context_vk_apply_draw_state(struct wined3d_context_vk *c wined3d_rendertarget_view_load_location(dsv, &context_vk->c, dsv->resource->draw_binding); else wined3d_rendertarget_view_prepare_location(dsv, &context_vk->c, dsv->resource->draw_binding); - if (state->render_states[WINED3D_RS_ZWRITEENABLE]) + if (!state->depth_stencil_state || state->depth_stencil_state->desc.depth_write) wined3d_rendertarget_view_invalidate_location(dsv, ~dsv->resource->draw_binding); sample_count = max(1, wined3d_resource_get_sample_count(dsv->resource)); diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 13d9057f3a8..5c94fae0a98 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -3686,6 +3686,7 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device, break; case WINED3D_RS_ZENABLE: + case WINED3D_RS_ZWRITEENABLE: set_depth_stencil_state = TRUE; break; @@ -3839,6 +3840,7 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device, default: FIXME("Unrecognized depth buffer type %#x.\n", state->rs[WINED3D_RS_ZENABLE]); } + desc.depth_write = state->rs[WINED3D_RS_ZWRITEENABLE]; if ((entry = wine_rb_get(&device->depth_stencil_states, &desc))) { diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index e56207f93d8..e2317b52099 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -2432,7 +2432,6 @@ static const struct wined3d_state_entry_template misc_state_template_no3d[] = {STATE_RENDER(WINED3D_RS_MONOENABLE), {STATE_VDECL}}, {STATE_RENDER(WINED3D_RS_ROP2), {STATE_VDECL}}, {STATE_RENDER(WINED3D_RS_PLANEMASK), {STATE_VDECL}}, - {STATE_RENDER(WINED3D_RS_ZWRITEENABLE), {STATE_VDECL}}, {STATE_RENDER(WINED3D_RS_LASTPIXEL), {STATE_VDECL}}, {STATE_RENDER(WINED3D_RS_ZFUNC), {STATE_VDECL}}, {STATE_RENDER(WINED3D_RS_DITHERENABLE), {STATE_VDECL}}, diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c index d77722c00d4..7a9e69f775c 100644 --- a/dlls/wined3d/state.c +++ b/dlls/wined3d/state.c @@ -359,22 +359,6 @@ static void state_ditherenable(struct wined3d_context *context, const struct win } } -static void state_zwriteenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) -{ - const struct wined3d_gl_info *gl_info = wined3d_context_gl(context)->gl_info; - - if (state->render_states[WINED3D_RS_ZWRITEENABLE]) - { - gl_info->gl_ops.gl.p_glDepthMask(1); - checkGLcall("glDepthMask(1)"); - } - else - { - gl_info->gl_ops.gl.p_glDepthMask(0); - checkGLcall("glDepthMask(0)"); - } -} - GLenum wined3d_gl_compare_func(enum wined3d_cmp_func f) { switch (f) @@ -1226,6 +1210,17 @@ static void depth_stencil(struct wined3d_context *context, const struct wined3d_ checkGLcall("glDisable GL_DEPTH_TEST"); } + if (!d || d->desc.depth_write) + { + gl_info->gl_ops.gl.p_glDepthMask(GL_TRUE); + checkGLcall("glDepthMask(GL_TRUE)"); + } + else + { + gl_info->gl_ops.gl.p_glDepthMask(GL_FALSE); + checkGLcall("glDepthMask(GL_FALSE)"); + } + if (context->last_was_rhw && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION))) context_apply_state(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION)); } @@ -4751,7 +4746,6 @@ const struct wined3d_state_entry_template misc_state_template_gl[] = { STATE_RENDER(WINED3D_RS_MONOENABLE), { STATE_RENDER(WINED3D_RS_MONOENABLE), state_monoenable }, WINED3D_GL_EXT_NONE }, { STATE_RENDER(WINED3D_RS_ROP2), { STATE_RENDER(WINED3D_RS_ROP2), state_rop2 }, WINED3D_GL_EXT_NONE }, { STATE_RENDER(WINED3D_RS_PLANEMASK), { STATE_RENDER(WINED3D_RS_PLANEMASK), state_planemask }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3D_RS_ZWRITEENABLE), { STATE_RENDER(WINED3D_RS_ZWRITEENABLE), state_zwriteenable }, WINED3D_GL_EXT_NONE }, { STATE_RENDER(WINED3D_RS_LASTPIXEL), { STATE_RENDER(WINED3D_RS_LASTPIXEL), state_lastpixel }, WINED3D_GL_EXT_NONE }, { STATE_RENDER(WINED3D_RS_ZFUNC), { STATE_RENDER(WINED3D_RS_ZFUNC), state_zfunc }, WINED3D_GL_EXT_NONE }, { STATE_RENDER(WINED3D_RS_DITHERENABLE), { STATE_RENDER(WINED3D_RS_DITHERENABLE), state_ditherenable }, WINED3D_GL_EXT_NONE }, @@ -5569,6 +5563,7 @@ static void validate_state_table(struct wined3d_state_entry *state_table) { 1, 1}, { 3, 3}, { 7, 8}, + { 14, 14}, { 17, 22}, { 27, 27}, { 40, 40}, diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index 8e05c6ae194..911ee0e6262 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -505,7 +505,7 @@ static void texture2d_depth_blt_fbo(const struct wined3d_device *device, struct if (gl_mask & GL_DEPTH_BUFFER_BIT) { gl_info->gl_ops.gl.p_glDepthMask(GL_TRUE); - context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ZWRITEENABLE)); + context_invalidate_state(context, STATE_DEPTH_STENCIL); } if (gl_mask & GL_STENCIL_BUFFER_BIT) { @@ -5403,7 +5403,7 @@ static void ffp_blitter_clear_rendertargets(struct wined3d_device *device, unsig if (flags & WINED3DCLEAR_ZBUFFER) { gl_info->gl_ops.gl.p_glDepthMask(GL_TRUE); - context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ZWRITEENABLE)); + context_invalidate_state(context, STATE_DEPTH_STENCIL); gl_info->gl_ops.gl.p_glClearDepth(depth); checkGLcall("glClearDepth"); clear_mask = clear_mask | GL_DEPTH_BUFFER_BIT; diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index da3974973a1..c44c4eac911 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -3643,8 +3643,9 @@ struct wined3d_state static inline bool wined3d_state_uses_depth_buffer(const struct wined3d_state *state) { - return state->render_states[WINED3D_RS_ZWRITEENABLE] - || !state->depth_stencil_state || state->depth_stencil_state->desc.depth; + if (!state->depth_stencil_state) + return true; + return state->depth_stencil_state->desc.depth || state->depth_stencil_state->desc.depth_write; } struct wined3d_dummy_textures diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index 77dbb775532..ef2a7de4580 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -2039,6 +2039,7 @@ struct wined3d_blend_state_desc struct wined3d_depth_stencil_state_desc { BOOL depth; + BOOL depth_write; }; struct wined3d_rasterizer_state_desc