Commit 5d2a3ad3 authored by Józef Kucia's avatar Józef Kucia Committed by Alexandre Julliard

wined3d: Add support for D3D10+ depth bias.

Direct3D seems to define exact depth bias scale factors per format. In order to make depth bias work reliably across OpenGL drivers we need to slightly adjust depth bias values passed to glPolygonOffset(). Signed-off-by: 's avatarJózef Kucia <jkucia@codeweavers.com> Signed-off-by: 's avatarHenri Verbeet <hverbeet@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 592a03af
...@@ -580,7 +580,8 @@ BOOL d3d9_init(struct d3d9 *d3d9, BOOL extended) ...@@ -580,7 +580,8 @@ BOOL d3d9_init(struct d3d9 *d3d9, BOOL extended)
{ {
DWORD flags = WINED3D_PRESENT_CONVERSION | WINED3D_HANDLE_RESTORE | WINED3D_PIXEL_CENTER_INTEGER DWORD flags = WINED3D_PRESENT_CONVERSION | WINED3D_HANDLE_RESTORE | WINED3D_PIXEL_CENTER_INTEGER
| WINED3D_SRGB_READ_WRITE_CONTROL | WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR | WINED3D_SRGB_READ_WRITE_CONTROL | WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR
| WINED3D_NO_PRIMITIVE_RESTART | WINED3D_LEGACY_CUBEMAP_FILTERING; | WINED3D_NO_PRIMITIVE_RESTART | WINED3D_LEGACY_CUBEMAP_FILTERING
| WINED3D_NORMALIZED_DEPTH_BIAS;
if (!extended) if (!extended)
flags |= WINED3D_VIDMEM_ACCOUNTING; flags |= WINED3D_VIDMEM_ACCOUNTING;
......
...@@ -1692,7 +1692,7 @@ static void state_depthbias(struct wined3d_context *context, const struct wined3 ...@@ -1692,7 +1692,7 @@ static void state_depthbias(struct wined3d_context *context, const struct wined3
|| state->render_states[WINED3D_RS_DEPTHBIAS]) || state->render_states[WINED3D_RS_DEPTHBIAS])
{ {
const struct wined3d_rendertarget_view *depth = state->fb->depth_stencil; const struct wined3d_rendertarget_view *depth = state->fb->depth_stencil;
float scale; float factor, units, scale;
union union
{ {
...@@ -1703,14 +1703,9 @@ static void state_depthbias(struct wined3d_context *context, const struct wined3 ...@@ -1703,14 +1703,9 @@ static void state_depthbias(struct wined3d_context *context, const struct wined3
scale_bias.d = state->render_states[WINED3D_RS_SLOPESCALEDEPTHBIAS]; scale_bias.d = state->render_states[WINED3D_RS_SLOPESCALEDEPTHBIAS];
const_bias.d = state->render_states[WINED3D_RS_DEPTHBIAS]; const_bias.d = state->render_states[WINED3D_RS_DEPTHBIAS];
gl_info->gl_ops.gl.p_glEnable(GL_POLYGON_OFFSET_FILL);
checkGLcall("glEnable(GL_POLYGON_OFFSET_FILL)");
if (context->d3d_info->wined3d_creation_flags & WINED3D_LEGACY_DEPTH_BIAS) if (context->d3d_info->wined3d_creation_flags & WINED3D_LEGACY_DEPTH_BIAS)
{ {
float bias = -(float)const_bias.d; factor = units = -(float)const_bias.d;
gl_info->gl_ops.gl.p_glPolygonOffset(bias, bias);
checkGLcall("glPolygonOffset");
} }
else else
{ {
...@@ -1719,24 +1714,28 @@ static void state_depthbias(struct wined3d_context *context, const struct wined3 ...@@ -1719,24 +1714,28 @@ static void state_depthbias(struct wined3d_context *context, const struct wined3
scale = depth->format->depth_bias_scale; scale = depth->format->depth_bias_scale;
TRACE("Depth format %s, using depthbias scale of %.8e.\n", TRACE("Depth format %s, using depthbias scale of %.8e.\n",
debug_d3dformat(depth->format->id), scale); debug_d3dformat(depth->format->id), scale);
} }
else else
{ {
/* The context manager will reapply this state on a depth stencil change */ /* The context manager will reapply this state on a depth stencil change */
TRACE("No depth stencil, using depthbias scale of 0.0.\n"); TRACE("No depth stencil, using depth bias scale of 0.0.\n");
scale = 0.0f; scale = 0.0f;
} }
gl_info->gl_ops.gl.p_glPolygonOffset(scale_bias.f, const_bias.f * scale); factor = scale_bias.f;
checkGLcall("glPolygonOffset(...)"); units = const_bias.f * scale;
} }
gl_info->gl_ops.gl.p_glEnable(GL_POLYGON_OFFSET_FILL);
gl_info->gl_ops.gl.p_glPolygonOffset(factor, units);
} }
else else
{ {
gl_info->gl_ops.gl.p_glDisable(GL_POLYGON_OFFSET_FILL); gl_info->gl_ops.gl.p_glDisable(GL_POLYGON_OFFSET_FILL);
checkGLcall("glDisable(GL_POLYGON_OFFSET_FILL)");
} }
checkGLcall("depth bias");
} }
static void state_zvisible(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) static void state_zvisible(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
......
...@@ -3706,7 +3706,8 @@ static float wined3d_adapter_find_polyoffset_scale(struct wined3d_caps_gl_ctx *c ...@@ -3706,7 +3706,8 @@ static float wined3d_adapter_find_polyoffset_scale(struct wined3d_caps_gl_ctx *c
return (float)(1u << cur); return (float)(1u << cur);
} }
static void init_format_depth_bias_scale(struct wined3d_caps_gl_ctx *ctx) static void init_format_depth_bias_scale(struct wined3d_caps_gl_ctx *ctx,
const struct wined3d_d3d_info *d3d_info)
{ {
const struct wined3d_gl_info *gl_info = ctx->gl_info; const struct wined3d_gl_info *gl_info = ctx->gl_info;
unsigned int i; unsigned int i;
...@@ -3719,6 +3720,17 @@ static void init_format_depth_bias_scale(struct wined3d_caps_gl_ctx *ctx) ...@@ -3719,6 +3720,17 @@ static void init_format_depth_bias_scale(struct wined3d_caps_gl_ctx *ctx)
{ {
TRACE("Testing depth bias scale for format %s.\n", debug_d3dformat(format->id)); TRACE("Testing depth bias scale for format %s.\n", debug_d3dformat(format->id));
format->depth_bias_scale = wined3d_adapter_find_polyoffset_scale(ctx, format->glInternal); format->depth_bias_scale = wined3d_adapter_find_polyoffset_scale(ctx, format->glInternal);
if (!(d3d_info->wined3d_creation_flags & WINED3D_NORMALIZED_DEPTH_BIAS))
{
/* The single-precision binary floating-point format has
* a significand precision of 24 bits.
*/
if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_FLOAT)
format->depth_bias_scale /= 1u << 24;
else
format->depth_bias_scale /= 1u << format->depth_size;
}
} }
} }
} }
...@@ -3741,7 +3753,7 @@ BOOL wined3d_adapter_init_format_info(struct wined3d_adapter *adapter, struct wi ...@@ -3741,7 +3753,7 @@ BOOL wined3d_adapter_init_format_info(struct wined3d_adapter *adapter, struct wi
init_format_fbo_compat_info(ctx); init_format_fbo_compat_info(ctx);
init_format_filter_info(gl_info, adapter->driver_info.vendor); init_format_filter_info(gl_info, adapter->driver_info.vendor);
if (!init_typeless_formats(gl_info)) goto fail; if (!init_typeless_formats(gl_info)) goto fail;
init_format_depth_bias_scale(ctx); init_format_depth_bias_scale(ctx, &adapter->d3d_info);
return TRUE; return TRUE;
......
...@@ -1306,6 +1306,7 @@ enum wined3d_shader_byte_code_format ...@@ -1306,6 +1306,7 @@ enum wined3d_shader_byte_code_format
#define WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR 0x00000400 #define WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR 0x00000400
#define WINED3D_NO_PRIMITIVE_RESTART 0x00000800 #define WINED3D_NO_PRIMITIVE_RESTART 0x00000800
#define WINED3D_LEGACY_CUBEMAP_FILTERING 0x00001000 #define WINED3D_LEGACY_CUBEMAP_FILTERING 0x00001000
#define WINED3D_NORMALIZED_DEPTH_BIAS 0x00002000
#define WINED3D_RESZ_CODE 0x7fa05000 #define WINED3D_RESZ_CODE 0x7fa05000
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment