Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/wined3d/utils.c | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c index f73968546fbf..cd0a8e15c908 100644 --- a/dlls/wined3d/utils.c +++ b/dlls/wined3d/utils.c @@ -268,6 +268,7 @@ static const struct wined3d_typed_format_info typed_formats[] = {WINED3DFMT_BC3_UNORM_SRGB, WINED3DFMT_BC3_TYPELESS, ""}, {WINED3DFMT_BC3_UNORM, WINED3DFMT_BC3_TYPELESS, ""}, {WINED3DFMT_BC4_UNORM, WINED3DFMT_BC4_TYPELESS, ""}, + {WINED3DFMT_BC4_SNORM, WINED3DFMT_BC4_TYPELESS, ""}, {WINED3DFMT_BC5_UNORM, WINED3DFMT_BC5_TYPELESS, ""}, {WINED3DFMT_BC5_SNORM, WINED3DFMT_BC5_TYPELESS, ""}, {WINED3DFMT_BC6H_UF16, WINED3DFMT_BC6H_TYPELESS, ""}, @@ -361,6 +362,7 @@ static const struct wined3d_format_block_info format_block_info[] = {WINED3DFMT_BC2_UNORM, 4, 4, 16, TRUE}, {WINED3DFMT_BC3_UNORM, 4, 4, 16, TRUE}, {WINED3DFMT_BC4_UNORM, 4, 4, 8, TRUE}, + {WINED3DFMT_BC4_SNORM, 4, 4, 8, TRUE}, {WINED3DFMT_BC5_UNORM, 4, 4, 16, TRUE}, {WINED3DFMT_BC5_SNORM, 4, 4, 16, TRUE}, {WINED3DFMT_BC6H_UF16, 4, 4, 16, TRUE}, @@ -1179,6 +1181,11 @@ static const struct wined3d_format_texture_info format_texture_info[] = WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_COMPRESSED, ARB_TEXTURE_COMPRESSION_RGTC, NULL}, + {WINED3DFMT_BC4_SNORM, GL_COMPRESSED_SIGNED_RED_RGTC1, GL_COMPRESSED_SIGNED_RED_RGTC1, 0, + GL_RED, GL_UNSIGNED_BYTE, 0, + WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING + | WINED3DFMT_FLAG_COMPRESSED, + ARB_TEXTURE_COMPRESSION_RGTC, NULL}, {WINED3DFMT_BC5_UNORM, GL_COMPRESSED_RG_RGTC2, GL_COMPRESSED_RG_RGTC2, 0, GL_RG, GL_UNSIGNED_BYTE, 0, WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING @@ -3434,6 +3441,8 @@ static void apply_format_fixups(struct wined3d_adapter *adapter, struct wined3d_ gl_info->formats[idx].flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE; idx = get_format_idx(WINED3DFMT_BC4_UNORM); gl_info->formats[idx].flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE; + idx = get_format_idx(WINED3DFMT_BC4_SNORM); + gl_info->formats[idx].flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE; idx = get_format_idx(WINED3DFMT_BC5_UNORM); gl_info->formats[idx].flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE; idx = get_format_idx(WINED3DFMT_BC5_SNORM);
From: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/wined3d/cs.c | 3 +- dlls/wined3d/directx.c | 4 --- dlls/wined3d/state.c | 5 +-- dlls/wined3d/utils.c | 76 ++++++++++++++++++++++++++---------------- dlls/wined3d/wined3d_private.h | 3 +- 5 files changed, 50 insertions(+), 41 deletions(-)
diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c index dbe9f42beb9d..78443d174a27 100644 --- a/dlls/wined3d/cs.c +++ b/dlls/wined3d/cs.c @@ -1032,8 +1032,7 @@ static void wined3d_cs_exec_set_depth_stencil_view(struct wined3d_cs *cs, const device_invalidate_state(device, STATE_RENDER(WINED3D_RS_STENCILWRITEMASK)); device_invalidate_state(device, STATE_RENDER(WINED3D_RS_DEPTHBIAS)); } - else if (prev && (prev->format_flags & WINED3DFMT_FLAG_FLOAT) - != (op->view->format_flags & WINED3DFMT_FLAG_FLOAT)) + else if (prev && prev->format->depth_bias_scale != op->view->format->depth_bias_scale) { device_invalidate_state(device, STATE_RENDER(WINED3D_RS_DEPTHBIAS)); } diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index 5058740464a2..ecb55bd11534 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -6634,10 +6634,6 @@ static BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, UINT ordinal, return FALSE; }
- gl_info->fixed_polyoffset_scale = wined3d_adapter_find_polyoffset_scale(&caps_gl_ctx, GL_DEPTH_COMPONENT); - if (gl_info->supported[ARB_DEPTH_BUFFER_FLOAT]) - gl_info->float_polyoffset_scale = wined3d_adapter_find_polyoffset_scale(&caps_gl_ctx, GL_DEPTH32F_STENCIL8); - adapter->vram_bytes = adapter->driver_info.vram_bytes; adapter->vram_bytes_used = 0; TRACE("Emulating 0x%s bytes of video ram.\n", wine_dbgstr_longlong(adapter->vram_bytes)); diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c index f3ec7df1863a..0b7c74747467 100644 --- a/dlls/wined3d/state.c +++ b/dlls/wined3d/state.c @@ -1716,10 +1716,7 @@ static void state_depthbias(struct wined3d_context *context, const struct wined3 { if (depth) { - if (depth->format_flags & WINED3DFMT_FLAG_FLOAT) - scale = gl_info->float_polyoffset_scale; - else - scale = gl_info->fixed_polyoffset_scale; + scale = depth->format->depth_bias_scale;
TRACE("Depth format %s, using depthbias scale of %.8e.\n", debug_d3dformat(depth->format->id), scale); diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c index cd0a8e15c908..1a75dd713920 100644 --- a/dlls/wined3d/utils.c +++ b/dlls/wined3d/utils.c @@ -3565,33 +3565,6 @@ static BOOL init_typeless_formats(struct wined3d_gl_info *gl_info) return TRUE; }
-/* Context activation is done by the caller. */ -BOOL wined3d_adapter_init_format_info(struct wined3d_adapter *adapter, struct wined3d_caps_gl_ctx *ctx) -{ - struct wined3d_gl_info *gl_info = &adapter->gl_info; - - if (!init_format_base_info(gl_info)) return FALSE; - if (!init_format_block_info(gl_info)) goto fail; - - if (!ctx) /* WINED3D_NO3D */ - return TRUE; - - if (!init_format_texture_info(adapter, gl_info)) goto fail; - if (!init_format_vertex_info(gl_info)) goto fail; - - apply_format_fixups(adapter, gl_info); - init_format_fbo_compat_info(ctx); - init_format_filter_info(gl_info, adapter->driver_info.vendor); - if (!init_typeless_formats(gl_info)) goto fail; - - return TRUE; - -fail: - HeapFree(GetProcessHeap(), 0, gl_info->formats); - gl_info->formats = NULL; - return FALSE; -} - BOOL wined3d_caps_gl_ctx_test_viewport_subpixel_bits(struct wined3d_caps_gl_ctx *ctx) { static const struct wined3d_color red = {1.0f, 0.0f, 0.0f, 1.0f}; @@ -3639,7 +3612,7 @@ BOOL wined3d_caps_gl_ctx_test_viewport_subpixel_bits(struct wined3d_caps_gl_ctx return TRUE; }
-float wined3d_adapter_find_polyoffset_scale(struct wined3d_caps_gl_ctx *ctx, GLenum format) +static float wined3d_adapter_find_polyoffset_scale(struct wined3d_caps_gl_ctx *ctx, GLenum format) { const struct wined3d_gl_info *gl_info = ctx->gl_info; static const struct wined3d_color blue = {0.0f, 0.0f, 1.0f, 1.0f}; @@ -3717,7 +3690,7 @@ float wined3d_adapter_find_polyoffset_scale(struct wined3d_caps_gl_ctx *ctx, GLe low = cur; else { - TRACE("Found scale factor 2^%u for format %x\n", cur, format); + TRACE("Found scale factor 2^%u for format %x.\n", cur, format); break; } } @@ -3733,6 +3706,51 @@ float wined3d_adapter_find_polyoffset_scale(struct wined3d_caps_gl_ctx *ctx, GLe return (float)(1u << cur); }
+static void init_format_depth_bias_scale(struct wined3d_caps_gl_ctx *ctx) +{ + const struct wined3d_gl_info *gl_info = ctx->gl_info; + unsigned int i; + + for (i = 0; i < gl_info->format_count; ++i) + { + struct wined3d_format *format = &gl_info->formats[i]; + + if (format->flags[WINED3D_GL_RES_TYPE_RB] & WINED3DFMT_FLAG_DEPTH) + { + 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); + } + } +} + +/* Context activation is done by the caller. */ +BOOL wined3d_adapter_init_format_info(struct wined3d_adapter *adapter, struct wined3d_caps_gl_ctx *ctx) +{ + struct wined3d_gl_info *gl_info = &adapter->gl_info; + + if (!init_format_base_info(gl_info)) return FALSE; + if (!init_format_block_info(gl_info)) goto fail; + + if (!ctx) /* WINED3D_NO3D */ + return TRUE; + + if (!init_format_texture_info(adapter, gl_info)) goto fail; + if (!init_format_vertex_info(gl_info)) goto fail; + + apply_format_fixups(adapter, gl_info); + 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); + + return TRUE; + +fail: + HeapFree(GetProcessHeap(), 0, gl_info->formats); + gl_info->formats = NULL; + return FALSE; +} + const struct wined3d_format *wined3d_get_format(const struct wined3d_gl_info *gl_info, enum wined3d_format_id format_id, unsigned int resource_usage) { diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 2321b41ad53f..4580983a1738 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -2558,7 +2558,6 @@ struct wined3d_gl_info DWORD quirks; BOOL supported[WINED3D_GL_EXT_COUNT]; GLint wrap_lookup[WINED3D_TADDRESS_MIRROR_ONCE - WINED3D_TADDRESS_WRAP + 1]; - float fixed_polyoffset_scale, float_polyoffset_scale;
HGLRC (WINAPI *p_wglCreateContextAttribsARB)(HDC dc, HGLRC share, const GLint *attribs); struct opengl_funcs gl_ops; @@ -2614,7 +2613,6 @@ struct wined3d_caps_gl_ctx GLuint test_program_id; };
-float wined3d_adapter_find_polyoffset_scale(struct wined3d_caps_gl_ctx *ctx, GLenum format) DECLSPEC_HIDDEN; BOOL wined3d_adapter_init_format_info(struct wined3d_adapter *adapter, struct wined3d_caps_gl_ctx *ctx) DECLSPEC_HIDDEN; UINT64 adapter_adjust_memory(struct wined3d_adapter *adapter, INT64 amount) DECLSPEC_HIDDEN; @@ -4235,6 +4233,7 @@ struct wined3d_format UINT conv_byte_count; DWORD multisample_types; unsigned int flags[WINED3D_GL_RES_TYPE_COUNT]; + float depth_bias_scale; struct wined3d_rational height_scale; struct color_fixup_desc color_fixup; void (*convert)(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
2017-12-06 11:00 GMT+01:00 Józef Kucia jkucia@codeweavers.com:
From: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Józef Kucia jkucia@codeweavers.com
Thank you for picking up my patch. Take also my blessing ;)
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
From: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Józef Kucia jkucia@codeweavers.com ---
Helpful to correctly implement D3D10+ depth bias.
--- dlls/wined3d/utils.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c index 1a75dd713920..76b1d8998acd 100644 --- a/dlls/wined3d/utils.c +++ b/dlls/wined3d/utils.c @@ -1567,7 +1567,7 @@ static const struct wined3d_format_texture_info format_texture_info[] = GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0, WINED3DFMT_FLAG_DEPTH, WINED3D_GL_EXT_NONE, NULL}, - {WINED3DFMT_D16_LOCKABLE, GL_DEPTH_COMPONENT24_ARB, GL_DEPTH_COMPONENT24_ARB, 0, + {WINED3DFMT_D16_LOCKABLE, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT16, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0, WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_SHADOW, ARB_DEPTH_TEXTURE, NULL}, @@ -1579,7 +1579,7 @@ static const struct wined3d_format_texture_info format_texture_info[] = GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0, WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_SHADOW, ARB_DEPTH_TEXTURE, NULL}, - {WINED3DFMT_S1_UINT_D15_UNORM, GL_DEPTH_COMPONENT24_ARB, GL_DEPTH_COMPONENT24_ARB, 0, + {WINED3DFMT_S1_UINT_D15_UNORM, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT16, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0, WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_SHADOW, ARB_DEPTH_TEXTURE, NULL}, @@ -1631,7 +1631,7 @@ static const struct wined3d_format_texture_info format_texture_info[] = GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0, WINED3DFMT_FLAG_DEPTH, WINED3D_GL_EXT_NONE, NULL}, - {WINED3DFMT_D16_UNORM, GL_DEPTH_COMPONENT24_ARB, GL_DEPTH_COMPONENT24_ARB, 0, + {WINED3DFMT_D16_UNORM, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT16, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0, WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_SHADOW,
2017-12-06 11:00 GMT+01:00 Józef Kucia jkucia@codeweavers.com:
From: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Józef Kucia jkucia@codeweavers.com
- {WINED3DFMT_D16_UNORM, GL_DEPTH_COMPONENT24_ARB, GL_DEPTH_COMPONENT24_ARB, 0,
- {WINED3DFMT_D16_UNORM, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT16, 0,
FTR this has always been "wrong" as far as git history goes. I suspect this was intentional and that the original reason is moot at this point. I can think of two possible motivations: working around depth buffer precision issues, probably due to the different depth range in d3d vs OpenGL, and avoiding color / depth buffer bit depth mismatch which was not supported in some old Nvidia GPUs. The former should be fixed by ARB_clip_control and the latter is something that d3d applications also have to take care of, which means that we shouldn't need to do anything special.
Anyway: Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
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 --- 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 fe7163fa88ac..08c3131614f2 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 0b7c74747467..db1711ef76c2 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 76b1d8998acd..b3003f130281 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 282e7338db4e..a519e94bb304 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
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/d3d11/device.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c index 52817929b0d5..7ae9073ffb11 100644 --- a/dlls/d3d11/device.c +++ b/dlls/d3d11/device.c @@ -907,6 +907,11 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetState(ID3D11DeviceCon struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface); struct d3d_rasterizer_state *rasterizer_state_impl; const D3D11_RASTERIZER_DESC *desc; + union + { + DWORD d; + float f; + } scale_bias, const_bias;
TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
@@ -916,6 +921,8 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetState(ID3D11DeviceCon wined3d_device_set_rasterizer_state(device->wined3d_device, NULL); wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, WINED3D_FILL_SOLID); wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, WINED3D_CULL_BACK); + wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SLOPESCALEDEPTHBIAS, 0); + wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DEPTHBIAS, 0); wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, FALSE); wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, FALSE); wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ANTIALIASEDLINEENABLE, FALSE); @@ -928,9 +935,10 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetState(ID3D11DeviceCon desc = &rasterizer_state_impl->desc; wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, desc->FillMode); wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, desc->CullMode); - /* OpenGL style depth bias. */ - if (desc->DepthBias || desc->SlopeScaledDepthBias) - FIXME("Ignoring depth bias.\n"); + scale_bias.f = desc->SlopeScaledDepthBias; + const_bias.f = desc->DepthBias; + wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SLOPESCALEDEPTHBIAS, scale_bias.d); + wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DEPTHBIAS, const_bias.d); /* GL_DEPTH_CLAMP */ if (!desc->DepthClipEnable) FIXME("Ignoring DepthClipEnable %#x.\n", desc->DepthClipEnable);
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
wined3d will not do this anymore
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/d3d8/device.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c index 8b6bd3f6ef69..f77fb27a5875 100644 --- a/dlls/d3d8/device.c +++ b/dlls/d3d8/device.c @@ -3271,8 +3271,7 @@ HRESULT device_init(struct d3d8_device *device, struct d3d8 *parent, struct wine return D3DERR_INVALIDCALL; }
- hr = wined3d_device_init_3d(device->wined3d_device, &swapchain_desc); - if (FAILED(hr)) + if (FAILED(hr = wined3d_device_init_3d(device->wined3d_device, &swapchain_desc))) { WARN("Failed to initialize 3D, hr %#x.\n", hr); wined3d_device_release_focus_window(device->wined3d_device); @@ -3282,6 +3281,8 @@ HRESULT device_init(struct d3d8_device *device, struct d3d8 *parent, struct wine return hr; }
+ wined3d_device_set_render_state(device->wined3d_device, + WINED3D_RS_ZENABLE, !!swapchain_desc.enable_auto_depth_stencil); wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_POINTSIZE_MIN, 0); wined3d_mutex_unlock();
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
wined3d will not do this anymore
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/d3d9/device.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index 655318eab5c6..20f73c0e212b 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -4092,8 +4092,7 @@ HRESULT device_init(struct d3d9_device *device, struct d3d9 *parent, struct wine } }
- hr = wined3d_device_init_3d(device->wined3d_device, swapchain_desc); - if (FAILED(hr)) + if (FAILED(hr = wined3d_device_init_3d(device->wined3d_device, swapchain_desc))) { WARN("Failed to initialize 3D, hr %#x.\n", hr); wined3d_device_release_focus_window(device->wined3d_device); @@ -4103,6 +4102,9 @@ HRESULT device_init(struct d3d9_device *device, struct d3d9 *parent, struct wine return hr; }
+ wined3d_device_set_render_state(device->wined3d_device, + WINED3D_RS_ZENABLE, !!swapchain_desc->enable_auto_depth_stencil); + if (FAILED(hr = d3d9_device_get_swapchains(device))) { wined3d_device_uninit_3d(device->wined3d_device);
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
We do not want to automagically disable depth test for D3D10+.
Signed-off-by: Józef Kucia jkucia@codeweavers.com ---
DDraw sets ZENABLE in d3d_device_init().
--- dlls/wined3d/device.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index d57758d32abd..26557029de27 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -949,7 +949,7 @@ void CDECL wined3d_device_release_focus_window(struct wined3d_device *device)
static void device_init_swapchain_state(struct wined3d_device *device, struct wined3d_swapchain *swapchain) { - BOOL ds_enable = !!swapchain->desc.enable_auto_depth_stencil; + BOOL ds_enable = swapchain->desc.enable_auto_depth_stencil; unsigned int i;
if (device->fb.render_targets) @@ -963,7 +963,6 @@ static void device_init_swapchain_state(struct wined3d_device *device, struct wi }
wined3d_device_set_depth_stencil_view(device, ds_enable ? device->auto_depth_stencil_view : NULL); - wined3d_device_set_render_state(device, WINED3D_RS_ZENABLE, ds_enable); }
static void wined3d_device_delete_opengl_contexts_cs(void *object) @@ -4881,6 +4880,8 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device, device->update_state = &device->state;
device_init_swapchain_state(device, swapchain); + wined3d_device_set_render_state(device, + WINED3D_RS_ZENABLE, !!swapchain->desc.enable_auto_depth_stencil); if (wined3d_settings.logo) device_load_logo(device, wined3d_settings.logo); }
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
The initial WINED3D_RS_ZFUNC state is different in wined3d.
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/d3d11/device.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c index 7ae9073ffb11..820463c27599 100644 --- a/dlls/d3d11/device.c +++ b/dlls/d3d11/device.c @@ -745,6 +745,14 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetBlendState(ID3D11Devi wined3d_mutex_unlock(); }
+static void set_default_depth_stencil_state(struct wined3d_device *wined3d_device) +{ + wined3d_device_set_render_state(wined3d_device, WINED3D_RS_ZENABLE, TRUE); + wined3d_device_set_render_state(wined3d_device, WINED3D_RS_ZWRITEENABLE, D3D11_DEPTH_WRITE_MASK_ALL); + wined3d_device_set_render_state(wined3d_device, WINED3D_RS_ZFUNC, WINED3D_CMP_LESS); + wined3d_device_set_render_state(wined3d_device, WINED3D_RS_STENCILENABLE, FALSE); +} + static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetDepthStencilState(ID3D11DeviceContext *iface, ID3D11DepthStencilState *depth_stencil_state, UINT stencil_ref) { @@ -759,10 +767,7 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetDepthStencilState(ID3 device->stencil_ref = stencil_ref; if (!(device->depth_stencil_state = unsafe_impl_from_ID3D11DepthStencilState(depth_stencil_state))) { - wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZENABLE, TRUE); - wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZWRITEENABLE, D3D11_DEPTH_WRITE_MASK_ALL); - wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZFUNC, D3D11_COMPARISON_LESS); - wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILENABLE, FALSE); + set_default_depth_stencil_state(device->wined3d_device); wined3d_mutex_unlock(); return; } @@ -5727,6 +5732,8 @@ static void CDECL device_parent_wined3d_device_created(struct wined3d_device_par
wined3d_device_incref(wined3d_device); device->wined3d_device = wined3d_device; + + set_default_depth_stencil_state(wined3d_device); }
static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/d3d11/tests/d3d11.c | 77 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 22 deletions(-)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index 330f20123b3f..705be4f66f0e 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -11788,10 +11788,61 @@ static void test_clear_buffer_unordered_access_view(void) ok(!refcount, "Device has %u references left.\n", refcount); }
+static void test_initial_depth_stencil_state(void) +{ + static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f}; + static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f}; + static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f}; + struct d3d11_test_context test_context; + D3D11_TEXTURE2D_DESC texture_desc; + ID3D11DeviceContext *context; + ID3D11DepthStencilView *dsv; + ID3D11Texture2D *texture; + ID3D11Device *device; + unsigned int count; + D3D11_VIEWPORT vp; + HRESULT hr; + + if (!init_test_context(&test_context, NULL)) + return; + + device = test_context.device; + context = test_context.immediate_context; + + ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc); + texture_desc.Format = DXGI_FORMAT_D32_FLOAT; + texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL; + hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture); + ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr); + + hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv); + ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr); + + ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv); + + count = 1; + ID3D11DeviceContext_RSGetViewports(context, &count, &vp); + + /* check if depth function is D3D11_COMPARISON_LESS */ + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white); + ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0); + vp.MinDepth = vp.MaxDepth = 0.4f; + ID3D11DeviceContext_RSSetViewports(context, 1, &vp); + draw_color_quad(&test_context, &green); + draw_color_quad(&test_context, &red); + vp.MinDepth = vp.MaxDepth = 0.6f; + ID3D11DeviceContext_RSSetViewports(context, 1, &vp); + draw_color_quad(&test_context, &red); + check_texture_color(test_context.backbuffer, 0xff00ff00, 1); + check_texture_float(texture, 0.4f, 1); + + ID3D11DepthStencilView_Release(dsv); + ID3D11Texture2D_Release(texture); + release_test_context(&test_context); +} + static void test_draw_depth_only(void) { - ID3D11DepthStencilState *depth_stencil_state; - D3D11_DEPTH_STENCIL_DESC depth_stencil_desc; struct d3d11_test_context test_context; ID3D11PixelShader *ps_color, *ps_depth; D3D11_TEXTURE2D_DESC texture_desc; @@ -11848,32 +11899,15 @@ static void test_draw_depth_only(void)
cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
- texture_desc.Width = 640; - texture_desc.Height = 480; - texture_desc.MipLevels = 1; - texture_desc.ArraySize = 1; + ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc); texture_desc.Format = DXGI_FORMAT_D32_FLOAT; - texture_desc.SampleDesc.Count = 1; - texture_desc.SampleDesc.Quality = 0; - texture_desc.Usage = D3D11_USAGE_DEFAULT; texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL; - texture_desc.CPUAccessFlags = 0; - texture_desc.MiscFlags = 0; - hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture); ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv); ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
- depth_stencil_desc.DepthEnable = TRUE; - depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; - depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS; - depth_stencil_desc.StencilEnable = FALSE; - - hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state); - ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr); - hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color); ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr); hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth); @@ -11882,7 +11916,6 @@ static void test_draw_depth_only(void) ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb); ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0); ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv); - ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0); check_texture_float(texture, 1.0f, 1); @@ -11947,7 +11980,6 @@ static void test_draw_depth_only(void) ID3D11PixelShader_Release(ps_color); ID3D11PixelShader_Release(ps_depth); ID3D11DepthStencilView_Release(dsv); - ID3D11DepthStencilState_Release(depth_stencil_state); ID3D11Texture2D_Release(texture); release_test_context(&test_context); } @@ -23384,6 +23416,7 @@ START_TEST(d3d11) test_clear_render_target_view(); test_clear_depth_stencil_view(); test_clear_buffer_unordered_access_view(); + test_initial_depth_stencil_state(); test_draw_depth_only(); test_draw_uav_only(); test_cb_relative_addressing();
Hi,
While running your changed tests on Windows, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check? Full results can be found at https://testbot.winehq.org/JobDetails.pl?Key=34627
Your paranoid android.
=== wvistau64 (32 bit d3d11) === d3d11.c:4997: Test failed: Got unexpected IAVertices count: 0. d3d11.c:4998: Test failed: Got unexpected IAPrimitives count: 0. d3d11.c:4999: Test failed: Got unexpected VSInvocations count: 0. d3d11.c:5002: Test failed: Got unexpected CInvocations count: 0. d3d11.c:5003: Test failed: Got unexpected CPrimitives count: 0.
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com