Based on a patch by Michael Müller.
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/d3d11/state.c | 1 + dlls/wined3d/adapter_gl.c | 3 +++ dlls/wined3d/cs.c | 2 ++ dlls/wined3d/state.c | 16 ++++++++++++++-- dlls/wined3d/wined3d_gl.h | 1 + include/wine/wined3d.h | 1 + 6 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/dlls/d3d11/state.c b/dlls/d3d11/state.c index c36b87f..6de3502 100644 --- a/dlls/d3d11/state.c +++ b/dlls/d3d11/state.c @@ -1081,6 +1081,7 @@ static HRESULT d3d_rasterizer_state_init(struct d3d_rasterizer_state *state, str
wined3d_desc.front_ccw = desc->FrontCounterClockwise; wined3d_desc.depth_clip = desc->DepthClipEnable; + wined3d_desc.depth_bias_clamp = desc->DepthBiasClamp;
/* We cannot fail after creating a wined3d_rasterizer_state object. It * would lead to double free. */ diff --git a/dlls/wined3d/adapter_gl.c b/dlls/wined3d/adapter_gl.c index 2f2d09d..6240b88 100644 --- a/dlls/wined3d/adapter_gl.c +++ b/dlls/wined3d/adapter_gl.c @@ -183,6 +183,7 @@ static const struct wined3d_extension_map gl_extension_map[] = {"GL_EXT_packed_depth_stencil", EXT_PACKED_DEPTH_STENCIL }, {"GL_EXT_packed_float", EXT_PACKED_FLOAT }, {"GL_EXT_point_parameters", EXT_POINT_PARAMETERS }, + {"GL_EXT_polygon_offset_clamp", EXT_POLYGON_OFFSET_CLAMP }, {"GL_EXT_provoking_vertex", EXT_PROVOKING_VERTEX }, {"GL_EXT_secondary_color", EXT_SECONDARY_COLOR }, {"GL_EXT_stencil_two_side", EXT_STENCIL_TWO_SIDE }, @@ -2475,6 +2476,8 @@ static void load_gl_funcs(struct wined3d_gl_info *gl_info) /* GL_EXT_point_parameters */ USE_GL_FUNC(glPointParameterfEXT) USE_GL_FUNC(glPointParameterfvEXT) + /* GL_EXT_polgyon_offset_clamp */ + USE_GL_FUNC(glPolygonOffsetClampEXT) /* GL_EXT_provoking_vertex */ USE_GL_FUNC(glProvokingVertexEXT) /* GL_EXT_secondary_color */ diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c index af1dbef..030e80f 100644 --- a/dlls/wined3d/cs.c +++ b/dlls/wined3d/cs.c @@ -1135,6 +1135,7 @@ static void wined3d_cs_exec_set_depth_stencil_view(struct wined3d_cs *cs, const device_invalidate_state(device, STATE_RENDER(WINED3D_RS_STENCILENABLE)); device_invalidate_state(device, STATE_RENDER(WINED3D_RS_STENCILWRITEMASK)); device_invalidate_state(device, STATE_RENDER(WINED3D_RS_DEPTHBIAS)); + device_invalidate_state(device, STATE_RASTERIZER); } else if (prev && prev->format->depth_bias_scale != op->view->format->depth_bias_scale) { @@ -1561,6 +1562,7 @@ static void wined3d_cs_exec_set_rasterizer_state(struct wined3d_cs *cs, const vo
cs->state.rasterizer_state = op->state; device_invalidate_state(cs->device, STATE_RASTERIZER); + device_invalidate_state(cs->device, STATE_RENDER(WINED3D_RS_DEPTHBIAS)); }
void wined3d_cs_emit_set_rasterizer_state(struct wined3d_cs *cs, diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c index 3b2f845..dc29d54 100644 --- a/dlls/wined3d/state.c +++ b/dlls/wined3d/state.c @@ -1775,7 +1775,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 factor, units, scale; + float factor, units, scale, clamp;
union { @@ -1785,6 +1785,7 @@ 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]; + clamp = state->rasterizer_state->desc.depth_bias_clamp;
if (context->d3d_info->wined3d_creation_flags & WINED3D_LEGACY_DEPTH_BIAS) { @@ -1811,7 +1812,18 @@ static void state_depthbias(struct wined3d_context *context, const struct wined3 }
gl_info->gl_ops.gl.p_glEnable(GL_POLYGON_OFFSET_FILL); - gl_info->gl_ops.gl.p_glPolygonOffset(factor, units); + if (gl_info->supported[EXT_POLYGON_OFFSET_CLAMP]) + { + GL_EXTCALL(glPolygonOffsetClampEXT(factor, units, clamp)); + checkGLcall("glPolygonOffsetClampEXT(...)"); + } + else + { + if (clamp) + WARN("EXT_polygon_offset_clamp extension missing; no support for depth bias clamping.\n"); + + gl_info->gl_ops.gl.p_glPolygonOffset(factor, units); + } } else { diff --git a/dlls/wined3d/wined3d_gl.h b/dlls/wined3d/wined3d_gl.h index 2a985da..2f6ba64 100644 --- a/dlls/wined3d/wined3d_gl.h +++ b/dlls/wined3d/wined3d_gl.h @@ -167,6 +167,7 @@ enum wined3d_gl_extension EXT_PACKED_DEPTH_STENCIL, EXT_PACKED_FLOAT, EXT_POINT_PARAMETERS, + EXT_POLYGON_OFFSET_CLAMP, EXT_PROVOKING_VERTEX, EXT_SECONDARY_COLOR, EXT_STENCIL_TWO_SIDE, diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index 8197a86..efc2fde 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -2013,6 +2013,7 @@ struct wined3d_rasterizer_state_desc { BOOL front_ccw; BOOL depth_clip; + float depth_bias_clamp; };
struct wined3d_sampler_desc
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/d3d10core/tests/d3d10core.c | 120 +++++++++++++++++++++++---------------- 1 file changed, 71 insertions(+), 49 deletions(-)
diff --git a/dlls/d3d10core/tests/d3d10core.c b/dlls/d3d10core/tests/d3d10core.c index 158a3e3..35a7b54 100644 --- a/dlls/d3d10core/tests/d3d10core.c +++ b/dlls/d3d10core/tests/d3d10core.c @@ -14992,10 +14992,10 @@ static void test_depth_bias(void) struct resource_readback rb; ID3D10DepthStencilView *dsv; unsigned int expected_value; + unsigned int x, y, i, j, k; ID3D10RasterizerState *rs; ID3D10Texture2D *texture; unsigned int format_idx; - unsigned int x, y, i, j; unsigned int shift = 0; ID3D10Device *device; float *depth_values; @@ -15022,6 +15022,10 @@ static void test_depth_bias(void) -10000, -1000, -100, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 50, 100, 200, 500, 1000, 10000, }; + static const float bias_clamp_tests[] = + { + 0.0f, -0.00001f, 0.00001f + }; static const float quad_slopes[] = { 0.0f, 0.5f, 1.0f @@ -15114,68 +15118,86 @@ static void test_depth_bias(void) for (j = 0; j < ARRAY_SIZE(bias_tests); ++j) { rasterizer_desc.DepthBias = bias_tests[j]; - ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rs); - ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr); - ID3D10Device_RSSetState(device, rs); - ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0); - draw_quad(&test_context); - switch (format) + + for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k) { - case DXGI_FORMAT_D32_FLOAT: - bias = rasterizer_desc.DepthBias * pow(2.0f, quads[i].exponent - 23.0f); - depth = min(max(0.0f, quads[i].z + bias), 1.0f); + rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k]; + ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rs); + ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr); + ID3D10Device_RSSetState(device, rs); + ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0); + draw_quad(&test_context); + switch (format) + { + case DXGI_FORMAT_D32_FLOAT: + bias = rasterizer_desc.DepthBias * pow(2.0f, quads[i].exponent - 23.0f); + if (rasterizer_desc.DepthBiasClamp > 0) + bias = min(bias, rasterizer_desc.DepthBiasClamp); + if (rasterizer_desc.DepthBiasClamp < 0) + bias = max(bias, rasterizer_desc.DepthBiasClamp); + depth = min(max(0.0f, quads[i].z + bias), 1.0f);
- check_texture_float(texture, depth, 2); - break; - case DXGI_FORMAT_D24_UNORM_S8_UINT: - r = 1.0f / 16777215.0f; - bias = rasterizer_desc.DepthBias * r; - depth = min(max(0.0f, quads[i].z + bias), 1.0f); + check_texture_float(texture, depth, 2); + break; + case DXGI_FORMAT_D24_UNORM_S8_UINT: + r = 1.0f / 16777215.0f; + bias = rasterizer_desc.DepthBias * r; + if (rasterizer_desc.DepthBiasClamp > 0) + bias = min(bias, rasterizer_desc.DepthBiasClamp); + if (rasterizer_desc.DepthBiasClamp < 0) + bias = max(bias, rasterizer_desc.DepthBiasClamp); + depth = min(max(0.0f, quads[i].z + bias), 1.0f);
- get_texture_readback(texture, 0, &rb); - for (y = 0; y < texture_desc.Height; ++y) - { - expected_value = depth * 16777215.0f + 0.5f; - for (x = 0; x < texture_desc.Width; ++x) + get_texture_readback(texture, 0, &rb); + for (y = 0; y < texture_desc.Height; ++y) { - u32 = get_readback_data(&rb, x, y, sizeof(*u32)); - u32_value = *u32 >> shift; - ok(abs(u32_value - expected_value) <= 1, - "Got value %#x (%.8e), expected %#x (%.8e).\n", - u32_value, u32_value / 16777215.0f, - expected_value, expected_value / 16777215.0f); + expected_value = depth * 16777215.0f + 0.5f; + for (x = 0; x < texture_desc.Width; ++x) + { + u32 = get_readback_data(&rb, x, y, sizeof(*u32)); + u32_value = *u32 >> shift; + ok(abs(u32_value - expected_value) <= 1, + "Got value %#x (%.8e), expected %#x (%.8e).\n", + u32_value, u32_value / 16777215.0f, + expected_value, expected_value / 16777215.0f); + } } - } - release_resource_readback(&rb); - break; - case DXGI_FORMAT_D16_UNORM: - r = 1.0f / 65535.0f; - bias = rasterizer_desc.DepthBias * r; - depth = min(max(0.0f, quads[i].z + bias), 1.0f); + release_resource_readback(&rb); + break; + case DXGI_FORMAT_D16_UNORM: + r = 1.0f / 65535.0f; + bias = rasterizer_desc.DepthBias * r; + if (rasterizer_desc.DepthBiasClamp > 0) + bias = min(bias, rasterizer_desc.DepthBiasClamp); + if (rasterizer_desc.DepthBiasClamp < 0) + bias = max(bias, rasterizer_desc.DepthBiasClamp); + depth = min(max(0.0f, quads[i].z + bias), 1.0f);
- get_texture_readback(texture, 0, &rb); - for (y = 0; y < texture_desc.Height; ++y) - { - expected_value = depth * 65535.0f + 0.5f; - for (x = 0; x < texture_desc.Width; ++x) + get_texture_readback(texture, 0, &rb); + for (y = 0; y < texture_desc.Height; ++y) { - u16 = get_readback_data(&rb, x, y, sizeof(*u16)); - ok(abs(*u16 - expected_value) <= 1, - "Got value %#x (%.8e), expected %#x (%.8e).\n", - *u16, *u16 / 65535.0f, expected_value, expected_value / 65535.0f); + expected_value = depth * 65535.0f + 0.5f; + for (x = 0; x < texture_desc.Width; ++x) + { + u16 = get_readback_data(&rb, x, y, sizeof(*u16)); + ok(abs(*u16 - expected_value) <= 1, + "Got value %#x (%.8e), expected %#x (%.8e).\n", + *u16, *u16 / 65535.0f, expected_value, expected_value / 65535.0f); + } } - } - release_resource_readback(&rb); - break; - default: - break; + release_resource_readback(&rb); + break; + default: + break; + } + ID3D10RasterizerState_Release(rs); } - ID3D10RasterizerState_Release(rs); } }
/* SlopeScaledDepthBias */ rasterizer_desc.DepthBias = 0; + rasterizer_desc.DepthBiasClamp = 0.0f; for (i = 0; i < ARRAY_SIZE(quad_slopes); ++i) { for (j = 0; j < ARRAY_SIZE(vertices); ++j)
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=42932
Your paranoid android.
=== debian9 (build log) ===