wined3d: Store stencil reference value in wined3d_state.

Signed-off-by: Jan Sikorski <jsikorski@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jan Sikorski 2021-02-03 14:12:47 +01:00 committed by Alexandre Julliard
parent dbb1ed4895
commit f3aceef725
10 changed files with 48 additions and 38 deletions

View file

@ -583,8 +583,6 @@ struct d3d_device
struct wine_rb_tree depthstencil_states;
struct wine_rb_tree rasterizer_states;
struct wine_rb_tree sampler_states;
UINT stencil_ref;
};
static inline struct d3d_device *impl_from_ID3D11Device(ID3D11Device *iface)

View file

@ -881,27 +881,19 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetDepthStencilState(ID3
{
struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
struct d3d_depthstencil_state *state_impl;
const D3D11_DEPTH_STENCIL_DESC *desc;
TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
iface, depth_stencil_state, stencil_ref);
wined3d_mutex_lock();
device->stencil_ref = stencil_ref;
if (!(state_impl = unsafe_impl_from_ID3D11DepthStencilState(depth_stencil_state)))
{
wined3d_device_set_depth_stencil_state(device->wined3d_device, NULL);
wined3d_device_set_depth_stencil_state(device->wined3d_device, NULL, stencil_ref);
wined3d_mutex_unlock();
return;
}
wined3d_device_set_depth_stencil_state(device->wined3d_device, state_impl->wined3d_state);
desc = &state_impl->desc;
if (desc->StencilEnable)
{
wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILREF, stencil_ref);
}
wined3d_device_set_depth_stencil_state(device->wined3d_device, state_impl->wined3d_state, stencil_ref);
wined3d_mutex_unlock();
}
@ -2022,7 +2014,7 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetDepthStencilState(ID3
iface, depth_stencil_state, stencil_ref);
wined3d_mutex_lock();
if ((wined3d_state = wined3d_device_get_depth_stencil_state(device->wined3d_device)))
if ((wined3d_state = wined3d_device_get_depth_stencil_state(device->wined3d_device, stencil_ref)))
{
state_impl = wined3d_depth_stencil_state_get_parent(wined3d_state);
ID3D11DepthStencilState_AddRef(*depth_stencil_state = &state_impl->ID3D11DepthStencilState_iface);
@ -2031,7 +2023,6 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetDepthStencilState(ID3
{
*depth_stencil_state = NULL;
}
*stencil_ref = device->stencil_ref;
wined3d_mutex_unlock();
}

View file

@ -43,6 +43,7 @@ static const struct wined3d_state_entry_template misc_state_template_vk[] =
{STATE_STREAMSRC, {STATE_STREAMSRC, state_nop}},
{STATE_VDECL, {STATE_VDECL, state_nop}},
{STATE_DEPTH_STENCIL, {STATE_DEPTH_STENCIL, state_nop}},
{STATE_STENCIL_REF, {STATE_STENCIL_REF, state_nop}},
{STATE_RASTERIZER, {STATE_RASTERIZER, state_nop}},
{STATE_SCISSORRECT, {STATE_SCISSORRECT, state_nop}},
{STATE_POINTSPRITECOORDORIGIN, {STATE_POINTSPRITECOORDORIGIN, state_nop}},
@ -116,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_STENCILREF), {STATE_RENDER(WINED3D_RS_STENCILREF), state_nop}},
{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)}},

View file

@ -2076,7 +2076,7 @@ static bool wined3d_context_vk_update_graphics_pipeline_key(struct wined3d_conte
key->ds_desc.front.compareOp = vk_compare_op_from_wined3d(d->desc.front.func);
key->ds_desc.front.compareMask = d->desc.stencil_read_mask;
key->ds_desc.front.writeMask = d->desc.stencil_write_mask;
key->ds_desc.front.reference = state->render_states[WINED3D_RS_STENCILREF]
key->ds_desc.front.reference = state->stencil_ref
& ((1 << state->fb.depth_stencil->format->stencil_size) - 1);
key->ds_desc.back.failOp = vk_stencil_op_from_wined3d(d->desc.back.fail_op);
@ -2085,7 +2085,7 @@ static bool wined3d_context_vk_update_graphics_pipeline_key(struct wined3d_conte
key->ds_desc.back.compareOp = vk_compare_op_from_wined3d(d->desc.back.func);
key->ds_desc.back.compareMask = d->desc.stencil_read_mask;
key->ds_desc.back.writeMask = d->desc.stencil_write_mask;
key->ds_desc.back.reference = state->render_states[WINED3D_RS_STENCILREF]
key->ds_desc.back.reference = state->stencil_ref
& ((1 << state->fb.depth_stencil->format->stencil_size) - 1);
}
else

View file

@ -275,6 +275,7 @@ struct wined3d_cs_set_depth_stencil_state
{
enum wined3d_cs_op opcode;
struct wined3d_depth_stencil_state *state;
unsigned int stencil_ref;
};
struct wined3d_cs_set_rasterizer_state
@ -1235,7 +1236,7 @@ static void wined3d_cs_exec_set_depth_stencil_view(struct wined3d_cs *cs, const
if (prev->format->depth_bias_scale != op->view->format->depth_bias_scale)
device_invalidate_state(device, STATE_RASTERIZER);
if (prev->format->stencil_size != op->view->format->stencil_size)
device_invalidate_state(device, STATE_RENDER(WINED3D_RS_STENCILREF));
device_invalidate_state(device, STATE_STENCIL_REF);
}
device_invalidate_state(device, STATE_FRAMEBUFFER);
@ -1665,19 +1666,26 @@ void wined3d_cs_emit_set_blend_state(struct wined3d_cs *cs, struct wined3d_blend
static void wined3d_cs_exec_set_depth_stencil_state(struct wined3d_cs *cs, const void *data)
{
const struct wined3d_cs_set_depth_stencil_state *op = data;
struct wined3d_state *state = &cs->state;
cs->state.depth_stencil_state = op->state;
device_invalidate_state(cs->device, STATE_DEPTH_STENCIL);
if (state->depth_stencil_state != op->state)
{
state->depth_stencil_state = op->state;
device_invalidate_state(cs->device, STATE_DEPTH_STENCIL);
}
state->stencil_ref = op->stencil_ref;
device_invalidate_state(cs->device, STATE_STENCIL_REF);
}
void wined3d_cs_emit_set_depth_stencil_state(struct wined3d_cs *cs,
struct wined3d_depth_stencil_state *state)
struct wined3d_depth_stencil_state *state, unsigned int stencil_ref)
{
struct wined3d_cs_set_depth_stencil_state *op;
op = wined3d_cs_require_space(cs, sizeof(*op), WINED3D_CS_QUEUE_DEFAULT);
op->opcode = WINED3D_CS_OP_SET_DEPTH_STENCIL_STATE;
op->state = state;
op->stencil_ref = stencil_ref;
wined3d_cs_submit(cs, WINED3D_CS_QUEUE_DEFAULT);
}

View file

@ -1774,28 +1774,30 @@ struct wined3d_blend_state * CDECL wined3d_device_get_blend_state(const struct w
}
void CDECL wined3d_device_set_depth_stencil_state(struct wined3d_device *device,
struct wined3d_depth_stencil_state *state)
struct wined3d_depth_stencil_state *state, unsigned int stencil_ref)
{
struct wined3d_depth_stencil_state *prev;
TRACE("device %p, state %p.\n", device, state);
TRACE("device %p, state %p, stencil_ref %u.\n", device, state, stencil_ref);
prev = device->state.depth_stencil_state;
if (prev == state)
if (prev == state && device->state.stencil_ref == stencil_ref)
return;
if (state)
wined3d_depth_stencil_state_incref(state);
device->state.depth_stencil_state = state;
wined3d_cs_emit_set_depth_stencil_state(device->cs, state);
device->state.stencil_ref = stencil_ref;
wined3d_cs_emit_set_depth_stencil_state(device->cs, state, stencil_ref);
if (prev)
wined3d_depth_stencil_state_decref(prev);
}
struct wined3d_depth_stencil_state * CDECL wined3d_device_get_depth_stencil_state(const struct wined3d_device *device)
struct wined3d_depth_stencil_state * CDECL wined3d_device_get_depth_stencil_state(const struct wined3d_device *device, unsigned int *stencil_ref)
{
TRACE("device %p.\n", device);
TRACE("device %p, stencil_ref %p.\n", device, stencil_ref);
*stencil_ref = device->state.stencil_ref;
return device->state.depth_stencil_state;
}
@ -3704,6 +3706,7 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device,
case WINED3D_RS_STENCILENABLE:
case WINED3D_RS_STENCILFAIL:
case WINED3D_RS_STENCILFUNC:
case WINED3D_RS_STENCILREF:
case WINED3D_RS_STENCILMASK:
case WINED3D_RS_STENCILPASS:
case WINED3D_RS_STENCILWRITEMASK:
@ -3848,6 +3851,7 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device,
struct wined3d_depth_stencil_state *depth_stencil_state;
struct wined3d_depth_stencil_state_desc desc;
struct wine_rb_entry *entry;
unsigned int stencil_ref;
memset(&desc, 0, sizeof(desc));
switch (state->rs[WINED3D_RS_ZENABLE])
@ -3887,15 +3891,20 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device,
desc.back = desc.front;
}
if (wined3d_bitmap_is_set(changed->renderState, WINED3D_RS_STENCILREF))
stencil_ref = state->rs[WINED3D_RS_STENCILREF];
else
wined3d_device_get_depth_stencil_state(device, &stencil_ref);
if ((entry = wine_rb_get(&device->depth_stencil_states, &desc)))
{
depth_stencil_state = WINE_RB_ENTRY_VALUE(entry, struct wined3d_depth_stencil_state, entry);
wined3d_device_set_depth_stencil_state(device, depth_stencil_state);
wined3d_device_set_depth_stencil_state(device, depth_stencil_state, stencil_ref);
}
else if (SUCCEEDED(wined3d_depth_stencil_state_create(device, &desc, NULL,
&wined3d_null_parent_ops, &depth_stencil_state)))
{
wined3d_device_set_depth_stencil_state(device, depth_stencil_state);
wined3d_device_set_depth_stencil_state(device, depth_stencil_state, stencil_ref);
if (wine_rb_put(&device->depth_stencil_states, &desc, &depth_stencil_state->entry) == -1)
{
ERR("Failed to insert depth/stencil state.\n");

View file

@ -2469,6 +2469,7 @@ static const struct wined3d_state_entry_template misc_state_template_no3d[] =
{STATE_BLEND_FACTOR, {STATE_VDECL}},
{STATE_SAMPLE_MASK, {STATE_VDECL}},
{STATE_DEPTH_STENCIL, {STATE_VDECL}},
{STATE_STENCIL_REF, {STATE_VDECL}},
{STATE_STREAMSRC, {STATE_VDECL}},
{STATE_VDECL, {STATE_VDECL, state_nop}},
{STATE_RASTERIZER, {STATE_VDECL}},
@ -2545,7 +2546,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_STENCILREF), {STATE_VDECL}},
{STATE_RENDER(WINED3D_RS_WRAP0), {STATE_VDECL}},
{STATE_RENDER(WINED3D_RS_WRAP1), {STATE_VDECL}},
{STATE_RENDER(WINED3D_RS_WRAP2), {STATE_VDECL}},

View file

@ -1070,7 +1070,7 @@ static void state_stencil(struct wined3d_context *context, const struct wined3d_
if (!(func_back = wined3d_gl_compare_func(d->desc.back.func)))
func_back = GL_ALWAYS;
mask = d->desc.stencil_read_mask;
ref = state->render_states[WINED3D_RS_STENCILREF] & ((1 << state->fb.depth_stencil->format->stencil_size) - 1);
ref = state->stencil_ref & ((1 << state->fb.depth_stencil->format->stencil_size) - 1);
stencilFail = gl_stencil_op(d->desc.front.fail_op);
depthFail = gl_stencil_op(d->desc.front.depth_fail_op);
stencilPass = gl_stencil_op(d->desc.front.pass_op);
@ -4691,6 +4691,7 @@ const struct wined3d_state_entry_template misc_state_template_gl[] =
{ STATE_SAMPLE_MASK, { STATE_SAMPLE_MASK, state_sample_mask_w }, WINED3D_GL_EXT_NONE },
{ STATE_DEPTH_STENCIL, { STATE_DEPTH_STENCIL, depth_stencil_2s }, EXT_STENCIL_TWO_SIDE },
{ STATE_DEPTH_STENCIL, { STATE_DEPTH_STENCIL, depth_stencil }, WINED3D_GL_EXT_NONE },
{ STATE_STENCIL_REF, { STATE_DEPTH_STENCIL, NULL }, WINED3D_GL_EXT_NONE },
{ STATE_STREAMSRC, { STATE_STREAMSRC, streamsrc }, WINED3D_GL_EXT_NONE },
{ STATE_VDECL, { STATE_VDECL, vdecl_miscpart }, WINED3D_GL_EXT_NONE },
{ STATE_RASTERIZER, { STATE_RASTERIZER, rasterizer_cc }, ARB_CLIP_CONTROL },
@ -4775,7 +4776,6 @@ 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_STENCILREF), { 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 },
@ -5574,8 +5574,7 @@ static void validate_state_table(struct wined3d_state_entry *state_table)
{ 40, 40},
{ 42, 45},
{ 47, 47},
{ 52, 56},
{ 58, 59},
{ 52, 59},
{ 61, 127},
{149, 150},
{162, 162},
@ -5621,6 +5620,7 @@ static void validate_state_table(struct wined3d_state_entry *state_table)
STATE_BLEND,
STATE_BLEND_FACTOR,
STATE_DEPTH_STENCIL,
STATE_STENCIL_REF,
};
unsigned int i, current;

View file

@ -1827,7 +1827,10 @@ enum wined3d_pipeline
#define STATE_DEPTH_STENCIL (STATE_SAMPLE_MASK + 1)
#define STATE_IS_DEPTH_STENCIL(a) ((a) == STATE_DEPTH_STENCIL)
#define STATE_COMPUTE_OFFSET (STATE_DEPTH_STENCIL + 1)
#define STATE_STENCIL_REF (STATE_DEPTH_STENCIL + 1)
#define STATE_IS_STENCIL_REF(a) ((a) == STATE_STENCIL_REF)
#define STATE_COMPUTE_OFFSET (STATE_STENCIL_REF + 1)
#define STATE_COMPUTE_SHADER (STATE_COMPUTE_OFFSET)
#define STATE_IS_COMPUTE_SHADER(a) ((a) == STATE_COMPUTE_SHADER)
@ -3701,6 +3704,7 @@ struct wined3d_state
struct wined3d_color blend_factor;
unsigned int sample_mask;
struct wined3d_depth_stencil_state *depth_stencil_state;
unsigned int stencil_ref;
struct wined3d_rasterizer_state *rasterizer_state;
};
@ -4740,7 +4744,7 @@ void wined3d_cs_emit_set_color_key(struct wined3d_cs *cs, struct wined3d_texture
void wined3d_cs_emit_set_constant_buffer(struct wined3d_cs *cs, enum wined3d_shader_type type,
UINT cb_idx, struct wined3d_buffer *buffer) DECLSPEC_HIDDEN;
void wined3d_cs_emit_set_depth_stencil_state(struct wined3d_cs *cs,
struct wined3d_depth_stencil_state *state) DECLSPEC_HIDDEN;
struct wined3d_depth_stencil_state *state, unsigned int stencil_ref) DECLSPEC_HIDDEN;
void wined3d_cs_emit_set_depth_stencil_view(struct wined3d_cs *cs,
struct wined3d_rendertarget_view *view) DECLSPEC_HIDDEN;
void wined3d_cs_emit_set_index_buffer(struct wined3d_cs *cs, struct wined3d_buffer *buffer,

View file

@ -2392,7 +2392,7 @@ struct wined3d_sampler * __cdecl wined3d_device_get_cs_sampler(const struct wine
struct wined3d_unordered_access_view * __cdecl wined3d_device_get_cs_uav(const struct wined3d_device *device,
unsigned int idx);
struct wined3d_depth_stencil_state * __cdecl wined3d_device_get_depth_stencil_state(
const struct wined3d_device *device);
const struct wined3d_device *device, unsigned int *stencil_ref);
struct wined3d_rendertarget_view * __cdecl wined3d_device_get_depth_stencil_view(const struct wined3d_device *device);
HRESULT __cdecl wined3d_device_get_device_caps(const struct wined3d_device *device, struct wined3d_caps *caps);
HRESULT __cdecl wined3d_device_get_display_mode(const struct wined3d_device *device, UINT swapchain_idx,
@ -2480,7 +2480,7 @@ void __cdecl wined3d_device_set_cursor_position(struct wined3d_device *device,
HRESULT __cdecl wined3d_device_set_cursor_properties(struct wined3d_device *device,
UINT x_hotspot, UINT y_hotspot, struct wined3d_texture *texture, unsigned int sub_resource_idx);
void __cdecl wined3d_device_set_depth_stencil_state(struct wined3d_device *device,
struct wined3d_depth_stencil_state *state);
struct wined3d_depth_stencil_state *state, unsigned int stencil_ref);
HRESULT __cdecl wined3d_device_set_depth_stencil_view(struct wined3d_device *device,
struct wined3d_rendertarget_view *view);
HRESULT __cdecl wined3d_device_set_dialog_box_mode(struct wined3d_device *device, BOOL enable_dialogs);