wined3d: Move the stencil enable state to wined3d_depth_stencil_state.

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-09-25 16:01:23 -05:00 committed by Alexandre Julliard
parent 4a5760b28b
commit 94becf6fc6
10 changed files with 63 additions and 66 deletions

View File

@ -727,7 +727,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_ZFUNC, WINED3D_CMP_LESS);
wined3d_device_set_render_state(wined3d_device, WINED3D_RS_STENCILENABLE, FALSE);
}
static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetDepthStencilState(ID3D11DeviceContext1 *iface,
@ -760,7 +759,6 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetDepthStencilState(ID3
if (desc->DepthEnable)
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)
{
wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILMASK, desc->StencilReadMask);

View File

@ -796,6 +796,7 @@ HRESULT d3d_depthstencil_state_create(struct d3d_device *device, const D3D11_DEP
wined3d_desc.depth = desc->DepthEnable;
wined3d_desc.depth_write = desc->DepthWriteMask;
wined3d_desc.stencil = desc->StencilEnable;
/* We cannot fail after creating a wined3d_depth_stencil_state object. It
* would lead to double free. */

View File

@ -117,7 +117,6 @@ 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_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)}},

View File

@ -2817,16 +2817,15 @@ void wined3d_context_gl_apply_blit_state(struct wined3d_context_gl *context_gl,
gl_info->gl_ops.gl.p_glDisable(GL_ALPHA_TEST);
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ALPHATESTENABLE));
}
gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_TEST);
context_invalidate_state(context, STATE_DEPTH_STENCIL);
gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
gl_info->gl_ops.gl.p_glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
context_invalidate_state(context, STATE_BLEND);
gl_info->gl_ops.gl.p_glDisable(GL_CULL_FACE);
gl_info->gl_ops.gl.p_glDisable(GL_SCISSOR_TEST);
context_invalidate_state(context, STATE_RASTERIZER);
gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_TEST);
gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST);
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_STENCILENABLE));
context_invalidate_state(context, STATE_DEPTH_STENCIL);
if (gl_info->supported[ARB_POINT_SPRITE])
{
gl_info->gl_ops.gl.p_glDisable(GL_POINT_SPRITE_ARB);

View File

@ -2043,19 +2043,13 @@ static bool wined3d_context_vk_update_graphics_pipeline_key(struct wined3d_conte
{
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.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];
key->ds_desc.stencilTestEnable = state->fb.depth_stencil && d->desc.stencil;
if (key->ds_desc.stencilTestEnable)
{
key->ds_desc.front.failOp = vk_stencil_op_from_wined3d(state->render_states[WINED3D_RS_STENCILFAIL]);
key->ds_desc.front.passOp = vk_stencil_op_from_wined3d(state->render_states[WINED3D_RS_STENCILPASS]);
key->ds_desc.front.depthFailOp = vk_stencil_op_from_wined3d(state->render_states[WINED3D_RS_STENCILZFAIL]);
key->ds_desc.front.depthFailOp = vk_stencil_op_from_wined3d(
state->render_states[WINED3D_RS_STENCILZFAIL]);
key->ds_desc.front.compareOp = vk_compare_op_from_wined3d(state->render_states[WINED3D_RS_STENCILFUNC]);
key->ds_desc.front.compareMask = state->render_states[WINED3D_RS_STENCILMASK];
key->ds_desc.front.writeMask = state->render_states[WINED3D_RS_STENCILWRITEMASK];
@ -2082,6 +2076,14 @@ static bool wined3d_context_vk_update_graphics_pipeline_key(struct wined3d_conte
key->ds_desc.back = key->ds_desc.front;
}
}
}
else
{
key->ds_desc.depthTestEnable = VK_TRUE;
key->ds_desc.depthWriteEnable = VK_TRUE;
key->ds_desc.stencilTestEnable = VK_FALSE;
}
key->ds_desc.depthCompareOp = vk_compare_op_from_wined3d(state->render_states[WINED3D_RS_ZFUNC]);
update = true;
}

View File

@ -1227,7 +1227,6 @@ static void wined3d_cs_exec_set_depth_stencil_view(struct wined3d_cs *cs, const
{
/* Swapping NULL / non NULL depth stencil affects the depth and tests */
device_invalidate_state(device, STATE_DEPTH_STENCIL);
device_invalidate_state(device, STATE_RENDER(WINED3D_RS_STENCILENABLE));
device_invalidate_state(device, STATE_RENDER(WINED3D_RS_STENCILWRITEMASK));
device_invalidate_state(device, STATE_RASTERIZER);
}

View File

@ -3685,6 +3685,7 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device,
set_blend_state = TRUE;
break;
case WINED3D_RS_STENCILENABLE:
case WINED3D_RS_ZENABLE:
case WINED3D_RS_ZWRITEENABLE:
set_depth_stencil_state = TRUE;
@ -3841,6 +3842,7 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device,
FIXME("Unrecognized depth buffer type %#x.\n", state->rs[WINED3D_RS_ZENABLE]);
}
desc.depth_write = state->rs[WINED3D_RS_ZWRITEENABLE];
desc.stencil = state->rs[WINED3D_RS_STENCILENABLE];
if ((entry = wine_rb_get(&device->depth_stencil_states, &desc)))
{
@ -4360,7 +4362,8 @@ HRESULT CDECL wined3d_device_validate_device(const struct wined3d_device *device
}
}
if (wined3d_state_uses_depth_buffer(state) || state->render_states[WINED3D_RS_STENCILENABLE])
if (wined3d_state_uses_depth_buffer(state)
|| (state->depth_stencil_state && state->depth_stencil_state->desc.stencil))
{
struct wined3d_rendertarget_view *rt = device->state.fb.render_targets[0];
struct wined3d_rendertarget_view *ds = device->state.fb.depth_stencil;

View File

@ -2443,7 +2443,6 @@ static const struct wined3d_state_entry_template misc_state_template_no3d[] =
{STATE_RENDER(WINED3D_RS_ANISOTROPY), {STATE_VDECL}},
{STATE_RENDER(WINED3D_RS_FLUSHBATCH), {STATE_VDECL}},
{STATE_RENDER(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT), {STATE_VDECL}},
{STATE_RENDER(WINED3D_RS_STENCILENABLE), {STATE_VDECL}},
{STATE_RENDER(WINED3D_RS_STENCILFAIL), {STATE_VDECL}},
{STATE_RENDER(WINED3D_RS_STENCILZFAIL), {STATE_VDECL}},
{STATE_RENDER(WINED3D_RS_STENCILPASS), {STATE_VDECL}},

View File

@ -1053,10 +1053,10 @@ static GLenum gl_stencil_op(enum wined3d_stencil_op op)
}
}
static void state_stencil(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
static void state_stencil(struct wined3d_context *context, const struct wined3d_state *state)
{
const struct wined3d_gl_info *gl_info = wined3d_context_gl(context)->gl_info;
DWORD onesided_enable;
const struct wined3d_depth_stencil_state *d = state->depth_stencil_state;
DWORD twosided_enable;
GLint func;
GLint func_back;
@ -1070,14 +1070,13 @@ static void state_stencil(struct wined3d_context *context, const struct wined3d_
GLint depthFail_back;
/* No stencil test without a stencil buffer. */
if (!state->fb.depth_stencil)
if (!state->fb.depth_stencil || !d || !d->desc.stencil)
{
gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST);
checkGLcall("glDisable GL_STENCIL_TEST");
return;
}
onesided_enable = state->render_states[WINED3D_RS_STENCILENABLE];
twosided_enable = state->render_states[WINED3D_RS_TWOSIDEDSTENCILMODE];
if (!(func = wined3d_gl_compare_func(state->render_states[WINED3D_RS_STENCILFUNC])))
func = GL_ALWAYS;
@ -1092,14 +1091,14 @@ static void state_stencil(struct wined3d_context *context, const struct wined3d_
depthFail_back = gl_stencil_op(state->render_states[WINED3D_RS_BACK_STENCILZFAIL]);
stencilPass_back = gl_stencil_op(state->render_states[WINED3D_RS_BACK_STENCILPASS]);
TRACE("(onesided %d, twosided %d, ref %x, mask %x, "
TRACE("(twosided %d, ref %x, mask %x, "
"GL_FRONT: func: %x, fail %x, zfail %x, zpass %x "
"GL_BACK: func: %x, fail %x, zfail %x, zpass %x)\n",
onesided_enable, twosided_enable, ref, mask,
twosided_enable, ref, mask,
func, stencilFail, depthFail, stencilPass,
func_back, stencilFail_back, depthFail_back, stencilPass_back);
if (twosided_enable && onesided_enable)
if (twosided_enable)
{
gl_info->gl_ops.gl.p_glEnable(GL_STENCIL_TEST);
checkGLcall("glEnable GL_STENCIL_TEST");
@ -1139,7 +1138,7 @@ static void state_stencil(struct wined3d_context *context, const struct wined3d_
FIXME("Separate (two sided) stencil not supported on this version of OpenGL. Caps weren't honored?\n");
}
}
else if(onesided_enable)
else
{
if (gl_info->supported[EXT_STENCIL_TWO_SIDE])
{
@ -1157,11 +1156,6 @@ static void state_stencil(struct wined3d_context *context, const struct wined3d_
gl_info->gl_ops.gl.p_glStencilOp(stencilFail, depthFail, stencilPass);
checkGLcall("glStencilOp(...)");
}
else
{
gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST);
checkGLcall("glDisable GL_STENCIL_TEST");
}
}
static void state_stencilwrite2s_ext(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
@ -1221,6 +1215,8 @@ static void depth_stencil(struct wined3d_context *context, const struct wined3d_
checkGLcall("glDepthMask(GL_FALSE)");
}
state_stencil(context, state);
if (context->last_was_rhw && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION)))
context_apply_state(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
}
@ -4757,20 +4753,19 @@ const struct wined3d_state_entry_template misc_state_template_gl[] =
{ STATE_RENDER(WINED3D_RS_ANISOTROPY), { STATE_RENDER(WINED3D_RS_ANISOTROPY), state_anisotropy }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_FLUSHBATCH), { STATE_RENDER(WINED3D_RS_FLUSHBATCH), state_flushbatch }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT),{ STATE_RENDER(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT),state_translucentsi }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_STENCILENABLE), { STATE_RENDER(WINED3D_RS_STENCILENABLE), state_stencil }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_STENCILFAIL), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_STENCILZFAIL), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_STENCILPASS), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_STENCILFUNC), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_STENCILREF), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_STENCILMASK), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_STENCILFAIL), { STATE_DEPTH_STENCIL, NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_STENCILZFAIL), { STATE_DEPTH_STENCIL, NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_STENCILPASS), { STATE_DEPTH_STENCIL, NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_STENCILFUNC), { STATE_DEPTH_STENCIL, NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_STENCILREF), { STATE_DEPTH_STENCIL, NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_STENCILMASK), { STATE_DEPTH_STENCIL, NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), state_stencilwrite2s_ext}, EXT_STENCIL_TWO_SIDE },
{ STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK), state_stencilwrite }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_TWOSIDEDSTENCILMODE), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_BACK_STENCILFAIL), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_BACK_STENCILZFAIL), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_BACK_STENCILPASS), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_BACK_STENCILFUNC), { STATE_RENDER(WINED3D_RS_STENCILENABLE), NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_TWOSIDEDSTENCILMODE), { STATE_DEPTH_STENCIL, NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_BACK_STENCILFAIL), { STATE_DEPTH_STENCIL, NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_BACK_STENCILZFAIL), { STATE_DEPTH_STENCIL, NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_BACK_STENCILPASS), { STATE_DEPTH_STENCIL, NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_BACK_STENCILFUNC), { STATE_DEPTH_STENCIL, NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_WRAP0), { STATE_RENDER(WINED3D_RS_WRAP0), state_wrap }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_WRAP1), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_WRAP2), { STATE_RENDER(WINED3D_RS_WRAP0), NULL }, WINED3D_GL_EXT_NONE },
@ -5569,6 +5564,7 @@ static void validate_state_table(struct wined3d_state_entry *state_table)
{ 40, 40},
{ 42, 45},
{ 47, 47},
{ 52, 52},
{ 61, 127},
{149, 150},
{162, 162},

View File

@ -2040,6 +2040,7 @@ struct wined3d_depth_stencil_state_desc
{
BOOL depth;
BOOL depth_write;
BOOL stencil;
};
struct wined3d_rasterizer_state_desc