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: Józef Kucia <jkucia@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
oldstable
Józef Kucia 2017-12-06 11:00:34 +01:00 committed by Alexandre Julliard
parent 592a03afe7
commit 5d2a3ad310
4 changed files with 28 additions and 15 deletions

View File

@ -580,7 +580,8 @@ BOOL d3d9_init(struct d3d9 *d3d9, BOOL extended)
{
DWORD flags = WINED3D_PRESENT_CONVERSION | WINED3D_HANDLE_RESTORE | WINED3D_PIXEL_CENTER_INTEGER
| 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)
flags |= WINED3D_VIDMEM_ACCOUNTING;

View File

@ -1692,7 +1692,7 @@ static void state_depthbias(struct wined3d_context *context, const struct wined3
|| state->render_states[WINED3D_RS_DEPTHBIAS])
{
const struct wined3d_rendertarget_view *depth = state->fb->depth_stencil;
float scale;
float factor, units, scale;
union
{
@ -1703,14 +1703,9 @@ static void state_depthbias(struct wined3d_context *context, const struct wined3
scale_bias.d = state->render_states[WINED3D_RS_SLOPESCALEDEPTHBIAS];
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)
{
float bias = -(float)const_bias.d;
gl_info->gl_ops.gl.p_glPolygonOffset(bias, bias);
checkGLcall("glPolygonOffset");
factor = units = -(float)const_bias.d;
}
else
{
@ -1719,24 +1714,28 @@ static void state_depthbias(struct wined3d_context *context, const struct wined3
scale = depth->format->depth_bias_scale;
TRACE("Depth format %s, using depthbias scale of %.8e.\n",
debug_d3dformat(depth->format->id), scale);
debug_d3dformat(depth->format->id), scale);
}
else
{
/* 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;
}
gl_info->gl_ops.gl.p_glPolygonOffset(scale_bias.f, const_bias.f * scale);
checkGLcall("glPolygonOffset(...)");
factor = scale_bias.f;
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
{
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)

View File

@ -3706,7 +3706,8 @@ static float wined3d_adapter_find_polyoffset_scale(struct wined3d_caps_gl_ctx *c
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;
unsigned int i;
@ -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));
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
init_format_fbo_compat_info(ctx);
init_format_filter_info(gl_info, adapter->driver_info.vendor);
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;

View File

@ -1306,6 +1306,7 @@ enum wined3d_shader_byte_code_format
#define WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR 0x00000400
#define WINED3D_NO_PRIMITIVE_RESTART 0x00000800
#define WINED3D_LEGACY_CUBEMAP_FILTERING 0x00001000
#define WINED3D_NORMALIZED_DEPTH_BIAS 0x00002000
#define WINED3D_RESZ_CODE 0x7fa05000