From 5d2a3ad3100490fd80d3ee26ba5874f326d6779f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Wed, 6 Dec 2017 11:00:34 +0100 Subject: [PATCH] wined3d: Add support for D3D10+ depth bias. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/d3d9/directx.c | 3 ++- dlls/wined3d/state.c | 23 +++++++++++------------ dlls/wined3d/utils.c | 16 ++++++++++++++-- include/wine/wined3d.h | 1 + 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/dlls/d3d9/directx.c b/dlls/d3d9/directx.c index fe7163fa88..08c3131614 100644 --- a/dlls/d3d9/directx.c +++ b/dlls/d3d9/directx.c @@ -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; diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c index 0b7c747474..db1711ef76 100644 --- a/dlls/wined3d/state.c +++ b/dlls/wined3d/state.c @@ -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) diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c index 76b1d8998a..b3003f1302 100644 --- a/dlls/wined3d/utils.c +++ b/dlls/wined3d/utils.c @@ -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; diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index 282e7338db..a519e94bb3 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -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