=?UTF-8?Q?J=C3=B3zef=20Kucia=20?=: wined3d: Add support for D3D10+ depth bias.

Alexandre Julliard julliard at winehq.org
Wed Dec 6 17:18:16 CST 2017


Module: wine
Branch: master
Commit: 5d2a3ad3100490fd80d3ee26ba5874f326d6779f
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=5d2a3ad3100490fd80d3ee26ba5874f326d6779f

Author: Józef Kucia <jkucia at codeweavers.com>
Date:   Wed Dec  6 11:00:34 2017 +0100

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 at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 fe7163f..08c3131 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 0b7c747..db1711e 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 76b1d89..b3003f1 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 282e733..a519e94 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
 




More information about the wine-cvs mailing list