wined3d: Introduce a depth/stencil state object.

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-24 22:43:11 -05:00 committed by Alexandre Julliard
parent 8db14f4e18
commit 2612381273
8 changed files with 218 additions and 2 deletions

View File

@ -42,6 +42,7 @@ static const struct wined3d_state_entry_template misc_state_template_vk[] =
{STATE_SAMPLE_MASK, {STATE_SAMPLE_MASK, state_nop}},
{STATE_STREAMSRC, {STATE_STREAMSRC, state_nop}},
{STATE_VDECL, {STATE_VDECL, state_nop}},
{STATE_DEPTH_STENCIL, {STATE_DEPTH_STENCIL, state_nop}},
{STATE_RASTERIZER, {STATE_RASTERIZER, state_nop}},
{STATE_SCISSORRECT, {STATE_SCISSORRECT, state_nop}},
{STATE_POINTSPRITECOORDORIGIN, {STATE_POINTSPRITECOORDORIGIN, state_nop}},

View File

@ -50,6 +50,7 @@ enum wined3d_cs_op
WINED3D_CS_OP_SET_SAMPLER,
WINED3D_CS_OP_SET_SHADER,
WINED3D_CS_OP_SET_BLEND_STATE,
WINED3D_CS_OP_SET_DEPTH_STENCIL_STATE,
WINED3D_CS_OP_SET_RASTERIZER_STATE,
WINED3D_CS_OP_SET_RENDER_STATE,
WINED3D_CS_OP_SET_TEXTURE_STATE,
@ -269,6 +270,12 @@ struct wined3d_cs_set_blend_state
unsigned int sample_mask;
};
struct wined3d_cs_set_depth_stencil_state
{
enum wined3d_cs_op opcode;
struct wined3d_depth_stencil_state *state;
};
struct wined3d_cs_set_rasterizer_state
{
enum wined3d_cs_op opcode;
@ -485,6 +492,7 @@ static const char *debug_cs_op(enum wined3d_cs_op op)
WINED3D_TO_STR(WINED3D_CS_OP_SET_SAMPLER);
WINED3D_TO_STR(WINED3D_CS_OP_SET_SHADER);
WINED3D_TO_STR(WINED3D_CS_OP_SET_BLEND_STATE);
WINED3D_TO_STR(WINED3D_CS_OP_SET_DEPTH_STENCIL_STATE);
WINED3D_TO_STR(WINED3D_CS_OP_SET_RASTERIZER_STATE);
WINED3D_TO_STR(WINED3D_CS_OP_SET_RENDER_STATE);
WINED3D_TO_STR(WINED3D_CS_OP_SET_TEXTURE_STATE);
@ -1655,6 +1663,26 @@ void wined3d_cs_emit_set_blend_state(struct wined3d_cs *cs, struct wined3d_blend
wined3d_cs_submit(cs, WINED3D_CS_QUEUE_DEFAULT);
}
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;
cs->state.depth_stencil_state = op->state;
device_invalidate_state(cs->device, STATE_DEPTH_STENCIL);
}
void wined3d_cs_emit_set_depth_stencil_state(struct wined3d_cs *cs,
struct wined3d_depth_stencil_state *state)
{
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;
wined3d_cs_submit(cs, WINED3D_CS_QUEUE_DEFAULT);
}
static void wined3d_cs_exec_set_rasterizer_state(struct wined3d_cs *cs, const void *data)
{
const struct wined3d_cs_set_rasterizer_state *op = data;
@ -2606,6 +2634,7 @@ static void (* const wined3d_cs_op_handlers[])(struct wined3d_cs *cs, const void
/* WINED3D_CS_OP_SET_SAMPLER */ wined3d_cs_exec_set_sampler,
/* WINED3D_CS_OP_SET_SHADER */ wined3d_cs_exec_set_shader,
/* WINED3D_CS_OP_SET_BLEND_STATE */ wined3d_cs_exec_set_blend_state,
/* WINED3D_CS_OP_SET_DEPTH_STENCIL_STATE */ wined3d_cs_exec_set_depth_stencil_state,
/* WINED3D_CS_OP_SET_RASTERIZER_STATE */ wined3d_cs_exec_set_rasterizer_state,
/* WINED3D_CS_OP_SET_RENDER_STATE */ wined3d_cs_exec_set_render_state,
/* WINED3D_CS_OP_SET_TEXTURE_STATE */ wined3d_cs_exec_set_texture_state,

View File

@ -197,6 +197,13 @@ static void device_leftover_blend_state(struct wine_rb_entry *entry, void *conte
ERR("Leftover blend state %p.\n", blend_state);
}
static void device_leftover_depth_stencil_state(struct wine_rb_entry *entry, void *context)
{
struct wined3d_depth_stencil_state *state = WINE_RB_ENTRY_VALUE(entry, struct wined3d_depth_stencil_state, entry);
ERR("Leftover depth/stencil state %p.\n", state);
}
void wined3d_device_cleanup(struct wined3d_device *device)
{
unsigned int i;
@ -234,6 +241,7 @@ void wined3d_device_cleanup(struct wined3d_device *device)
wine_rb_destroy(&device->samplers, device_leftover_sampler, NULL);
wine_rb_destroy(&device->rasterizer_states, device_leftover_rasterizer_state, NULL);
wine_rb_destroy(&device->blend_states, device_leftover_blend_state, NULL);
wine_rb_destroy(&device->depth_stencil_states, device_leftover_depth_stencil_state, NULL);
wined3d_decref(device->wined3d);
device->wined3d = NULL;
@ -1157,6 +1165,13 @@ static void device_free_blend_state(struct wine_rb_entry *entry, void *context)
wined3d_blend_state_decref(blend_state);
}
static void device_free_depth_stencil_state(struct wine_rb_entry *entry, void *context)
{
struct wined3d_depth_stencil_state *state = WINE_RB_ENTRY_VALUE(entry, struct wined3d_depth_stencil_state, entry);
wined3d_depth_stencil_state_decref(state);
}
void wined3d_device_uninit_3d(struct wined3d_device *device)
{
struct wined3d_resource *resource, *cursor;
@ -1745,6 +1760,32 @@ struct wined3d_blend_state * CDECL wined3d_device_get_blend_state(const struct w
return state->blend_state;
}
void CDECL wined3d_device_set_depth_stencil_state(struct wined3d_device *device,
struct wined3d_depth_stencil_state *state)
{
struct wined3d_depth_stencil_state *prev;
TRACE("device %p, state %p.\n", device, state);
prev = device->state.depth_stencil_state;
if (prev == state)
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);
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)
{
TRACE("device %p.\n", device);
return device->state.depth_stencil_state;
}
void CDECL wined3d_device_set_rasterizer_state(struct wined3d_device *device,
struct wined3d_rasterizer_state *rasterizer_state)
{
@ -5391,6 +5432,7 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
wine_rb_clear(&device->samplers, device_free_sampler, NULL);
wine_rb_clear(&device->rasterizer_states, device_free_rasterizer_state, NULL);
wine_rb_clear(&device->blend_states, device_free_blend_state, NULL);
wine_rb_clear(&device->depth_stencil_states, device_free_depth_stencil_state, NULL);
if (reset_state)
{
@ -5584,6 +5626,14 @@ static int wined3d_blend_state_compare(const void *key, const struct wine_rb_ent
return memcmp(&state->desc, key, sizeof(state->desc));
}
static int wined3d_depth_stencil_state_compare(const void *key, const struct wine_rb_entry *entry)
{
const struct wined3d_depth_stencil_state *state
= WINE_RB_ENTRY_VALUE(entry, struct wined3d_depth_stencil_state, entry);
return memcmp(&state->desc, key, sizeof(state->desc));
}
static BOOL wined3d_select_feature_level(const struct wined3d_adapter *adapter,
const enum wined3d_feature_level *levels, unsigned int level_count,
enum wined3d_feature_level *selected_level)
@ -5645,6 +5695,7 @@ HRESULT wined3d_device_init(struct wined3d_device *device, struct wined3d *wined
wine_rb_init(&device->samplers, wined3d_sampler_compare);
wine_rb_init(&device->rasterizer_states, wined3d_rasterizer_state_compare);
wine_rb_init(&device->blend_states, wined3d_blend_state_compare);
wine_rb_init(&device->depth_stencil_states, wined3d_depth_stencil_state_compare);
if (vertex_pipeline->vp_states && fragment_pipeline->states
&& FAILED(hr = compile_state_table(device->state_table, device->multistate_funcs,
@ -5655,6 +5706,7 @@ HRESULT wined3d_device_init(struct wined3d_device *device, struct wined3d *wined
wine_rb_destroy(&device->samplers, NULL, NULL);
wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
wine_rb_destroy(&device->blend_states, NULL, NULL);
wine_rb_destroy(&device->depth_stencil_states, NULL, NULL);
wined3d_decref(device->wined3d);
return hr;
}
@ -5681,6 +5733,7 @@ err:
wine_rb_destroy(&device->samplers, NULL, NULL);
wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
wine_rb_destroy(&device->blend_states, NULL, NULL);
wine_rb_destroy(&device->depth_stencil_states, NULL, NULL);
wined3d_decref(device->wined3d);
return hr;
}

View File

@ -2366,6 +2366,7 @@ static const struct wined3d_state_entry_template misc_state_template_no3d[] =
{STATE_BLEND, {STATE_VDECL}},
{STATE_BLEND_FACTOR, {STATE_VDECL}},
{STATE_SAMPLE_MASK, {STATE_VDECL}},
{STATE_DEPTH_STENCIL, {STATE_VDECL}},
{STATE_STREAMSRC, {STATE_VDECL}},
{STATE_VDECL, {STATE_VDECL, state_nop}},
{STATE_RASTERIZER, {STATE_VDECL}},

View File

@ -109,6 +109,67 @@ HRESULT CDECL wined3d_blend_state_create(struct wined3d_device *device,
return WINED3D_OK;
}
ULONG CDECL wined3d_depth_stencil_state_incref(struct wined3d_depth_stencil_state *state)
{
ULONG refcount = InterlockedIncrement(&state->refcount);
TRACE("%p increasing refcount to %u.\n", state, refcount);
return refcount;
}
static void wined3d_depth_stencil_state_destroy_object(void *object)
{
heap_free(object);
}
ULONG CDECL wined3d_depth_stencil_state_decref(struct wined3d_depth_stencil_state *state)
{
ULONG refcount = InterlockedDecrement(&state->refcount);
struct wined3d_device *device = state->device;
TRACE("%p decreasing refcount to %u.\n", state, refcount);
if (!refcount)
{
state->parent_ops->wined3d_object_destroyed(state->parent);
wined3d_cs_destroy_object(device->cs, wined3d_depth_stencil_state_destroy_object, state);
}
return refcount;
}
void * CDECL wined3d_depth_stencil_state_get_parent(const struct wined3d_depth_stencil_state *state)
{
TRACE("state %p.\n", state);
return state->parent;
}
HRESULT CDECL wined3d_depth_stencil_state_create(struct wined3d_device *device,
const struct wined3d_depth_stencil_state_desc *desc, void *parent,
const struct wined3d_parent_ops *parent_ops, struct wined3d_depth_stencil_state **state)
{
struct wined3d_depth_stencil_state *object;
TRACE("device %p, desc %p, parent %p, parent_ops %p, state %p.\n",
device, desc, parent, parent_ops, state);
if (!(object = heap_alloc_zero(sizeof(*object))))
return E_OUTOFMEMORY;
object->refcount = 1;
object->desc = *desc;
object->parent = parent;
object->parent_ops = parent_ops;
object->device = device;
TRACE("Created depth/stencil state %p.\n", object);
*state = object;
return WINED3D_OK;
}
ULONG CDECL wined3d_rasterizer_state_incref(struct wined3d_rasterizer_state *state)
{
ULONG refcount = InterlockedIncrement(&state->refcount);
@ -1178,6 +1239,33 @@ static void state_stencilwrite(struct wined3d_context *context, const struct win
checkGLcall("glStencilMask");
}
static void depth_stencil(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;
const struct wined3d_depth_stencil_state *d = state->depth_stencil_state;
BOOL enable_depth = d ? d->desc.depth : TRUE;
if (!state->fb.depth_stencil)
{
TRACE("No depth/stencil buffer is attached; disabling depth test.\n");
enable_depth = FALSE;
}
if (enable_depth)
{
gl_info->gl_ops.gl.p_glEnable(GL_DEPTH_TEST);
checkGLcall("glEnable GL_DEPTH_TEST");
}
else
{
gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_TEST);
checkGLcall("glDisable GL_DEPTH_TEST");
}
if (context->last_was_rhw && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION)))
context_apply_state(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
}
static void state_fog_vertexpart(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;
@ -4624,6 +4712,7 @@ const struct wined3d_state_entry_template misc_state_template_gl[] =
{ STATE_BLEND_FACTOR, { STATE_BLEND_FACTOR, state_blend_factor_w}, WINED3D_GL_EXT_NONE },
{ STATE_SAMPLE_MASK, { STATE_SAMPLE_MASK, state_sample_mask }, ARB_TEXTURE_MULTISAMPLE },
{ STATE_SAMPLE_MASK, { STATE_SAMPLE_MASK, state_sample_mask_w }, WINED3D_GL_EXT_NONE },
{ STATE_DEPTH_STENCIL, { STATE_DEPTH_STENCIL, depth_stencil }, 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 },
@ -5566,6 +5655,7 @@ static void validate_state_table(struct wined3d_state_entry *state_table)
STATE_COLOR_KEY,
STATE_BLEND,
STATE_BLEND_FACTOR,
STATE_DEPTH_STENCIL,
};
unsigned int i, current;

View File

@ -32,6 +32,11 @@
@ cdecl wined3d_buffer_get_resource(ptr)
@ cdecl wined3d_buffer_incref(ptr)
@ cdecl wined3d_depth_stencil_state_create(ptr ptr ptr ptr ptr)
@ cdecl wined3d_depth_stencil_state_decref(ptr)
@ cdecl wined3d_depth_stencil_state_get_parent(ptr)
@ cdecl wined3d_depth_stencil_state_incref(ptr)
@ cdecl wined3d_device_acquire_focus_window(ptr ptr)
@ cdecl wined3d_device_apply_stateblock(ptr ptr)
@ cdecl wined3d_device_begin_scene(ptr)
@ -63,6 +68,7 @@
@ cdecl wined3d_device_get_cs_resource_view(ptr long)
@ cdecl wined3d_device_get_cs_sampler(ptr long)
@ cdecl wined3d_device_get_cs_uav(ptr long)
@ cdecl wined3d_device_get_depth_stencil_state(ptr)
@ cdecl wined3d_device_get_depth_stencil_view(ptr)
@ cdecl wined3d_device_get_device_caps(ptr ptr)
@ cdecl wined3d_device_get_display_mode(ptr long ptr ptr)
@ -117,6 +123,7 @@
@ cdecl wined3d_device_set_cs_uav(ptr long ptr long)
@ cdecl wined3d_device_set_cursor_position(ptr long long long)
@ cdecl wined3d_device_set_cursor_properties(ptr long long ptr long)
@ cdecl wined3d_device_set_depth_stencil_state(ptr ptr)
@ cdecl wined3d_device_set_depth_stencil_view(ptr ptr)
@ cdecl wined3d_device_set_dialog_box_mode(ptr long)
@ cdecl wined3d_device_set_domain_shader(ptr ptr)

View File

@ -1779,7 +1779,10 @@ enum wined3d_pipeline
#define STATE_SAMPLE_MASK (STATE_BLEND_FACTOR + 1)
#define STATE_IS_SAMPLE_MASK(a) ((a) == STATE_SAMPLE_MASK)
#define STATE_COMPUTE_OFFSET (STATE_SAMPLE_MASK + 1)
#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_COMPUTE_SHADER (STATE_COMPUTE_OFFSET)
#define STATE_IS_COMPUTE_SHADER(a) ((a) == STATE_COMPUTE_SHADER)
@ -3541,6 +3544,18 @@ static inline unsigned int wined3d_blend_state_get_writemask(const struct wined3
return state->desc.rt[index].writemask;
}
struct wined3d_depth_stencil_state
{
LONG refcount;
struct wined3d_depth_stencil_state_desc desc;
void *parent;
const struct wined3d_parent_ops *parent_ops;
struct wined3d_device *device;
struct wine_rb_entry entry;
};
struct wined3d_rasterizer_state
{
LONG refcount;
@ -3622,6 +3637,7 @@ struct wined3d_state
struct wined3d_blend_state *blend_state;
struct wined3d_color blend_factor;
unsigned int sample_mask;
struct wined3d_depth_stencil_state *depth_stencil_state;
struct wined3d_rasterizer_state *rasterizer_state;
};
@ -3695,7 +3711,7 @@ struct wined3d_device
struct list resources; /* a linked list to track resources created by the device */
struct list shaders; /* a linked list to track shaders (pixel and vertex) */
struct wine_rb_tree samplers, rasterizer_states, blend_states;
struct wine_rb_tree samplers, rasterizer_states, blend_states, depth_stencil_states;
/* Render Target Support */
struct wined3d_rendertarget_view *auto_depth_stencil_view;
@ -4641,6 +4657,8 @@ void wined3d_cs_emit_set_color_key(struct wined3d_cs *cs, struct wined3d_texture
WORD flags, const struct wined3d_color_key *color_key) DECLSPEC_HIDDEN;
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;
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

@ -2036,6 +2036,11 @@ struct wined3d_blend_state_desc
} rt[WINED3D_MAX_RENDER_TARGETS];
};
struct wined3d_depth_stencil_state_desc
{
BOOL depth;
};
struct wined3d_rasterizer_state_desc
{
enum wined3d_fill_mode fill_mode;
@ -2193,6 +2198,7 @@ struct wined3d;
struct wined3d_adapter;
struct wined3d_blend_state;
struct wined3d_buffer;
struct wined3d_depth_stencil_state;
struct wined3d_device;
struct wined3d_output;
struct wined3d_palette;
@ -2297,6 +2303,13 @@ void * __cdecl wined3d_buffer_get_parent(const struct wined3d_buffer *buffer);
struct wined3d_resource * __cdecl wined3d_buffer_get_resource(struct wined3d_buffer *buffer);
ULONG __cdecl wined3d_buffer_incref(struct wined3d_buffer *buffer);
HRESULT __cdecl wined3d_depth_stencil_state_create(struct wined3d_device *device,
const struct wined3d_depth_stencil_state_desc *desc, void *parent,
const struct wined3d_parent_ops *parent_ops, struct wined3d_depth_stencil_state **state);
ULONG __cdecl wined3d_depth_stencil_state_decref(struct wined3d_depth_stencil_state *state);
void * __cdecl wined3d_depth_stencil_state_get_parent(const struct wined3d_depth_stencil_state *state);
ULONG __cdecl wined3d_depth_stencil_state_incref(struct wined3d_depth_stencil_state *state);
HRESULT __cdecl wined3d_device_acquire_focus_window(struct wined3d_device *device, HWND window);
void __cdecl wined3d_device_apply_stateblock(struct wined3d_device *device, struct wined3d_stateblock *stateblock);
HRESULT __cdecl wined3d_device_begin_scene(struct wined3d_device *device);
@ -2352,6 +2365,8 @@ struct wined3d_shader_resource_view * __cdecl wined3d_device_get_cs_resource_vie
struct wined3d_sampler * __cdecl wined3d_device_get_cs_sampler(const struct wined3d_device *device, unsigned int idx);
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);
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,
@ -2438,6 +2453,8 @@ void __cdecl wined3d_device_set_cursor_position(struct wined3d_device *device,
int x_screen_space, int y_screen_space, DWORD flags);
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);
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);