Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/ddraw/device.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c index 32a2f1a6be50..542f23a0ef26 100644 --- a/dlls/ddraw/device.c +++ b/dlls/ddraw/device.c @@ -6469,11 +6469,14 @@ static HRESULT d3d_device7_SetClipPlane(IDirect3DDevice7 *iface, DWORD idx, D3DV
wined3d_mutex_lock(); hr = wined3d_device_set_clip_plane(device->wined3d_device, idx, wined3d_plane); - if (hr == WINED3DERR_INVALIDCALL && idx < ARRAY_SIZE(device->user_clip_planes)) + if (idx < ARRAY_SIZE(device->user_clip_planes)) { - WARN("Clip plane %u is not supported.\n", idx); device->user_clip_planes[idx] = *wined3d_plane; - hr = D3D_OK; + if (hr == WINED3DERR_INVALIDCALL) + { + WARN("Clip plane %u is not supported.\n", idx); + hr = D3D_OK; + } } wined3d_mutex_unlock();
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/d3d11/tests/d3d11.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index 705be4f66f0e..96b3b05adae1 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -12228,6 +12228,127 @@ float4 main(const ps_in v) : SV_TARGET release_test_context(&test_context); }
+static void test_vs_input_relative_addressing(void) +{ + struct d3d11_test_context test_context; + ID3D11DeviceContext *context; + unsigned int offset, stride; + unsigned int index[4] = {0}; + ID3D11PixelShader *ps; + ID3D11Buffer *vb, *cb; + ID3D11Device *device; + unsigned int i; + HRESULT hr; + + static const DWORD vs_code[] = + { +#if 0 + struct vertex + { + float4 position : POSITION; + float4 colors[4] : COLOR; + }; + + uint index; + + void main(vertex vin, out float4 position : SV_Position, + out float4 color : COLOR) + { + position = vin.position; + color = vin.colors[index]; + } +#endif + 0x43425844, 0x8623dd89, 0xe37fecf5, 0xea3fdfe1, 0xdf36e4e4, 0x00000001, 0x000001f4, 0x00000003, + 0x0000002c, 0x000000c4, 0x00000118, 0x4e475349, 0x00000090, 0x00000005, 0x00000008, 0x00000080, + 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000089, 0x00000000, 0x00000000, + 0x00000003, 0x00000001, 0x00000f0f, 0x00000089, 0x00000001, 0x00000000, 0x00000003, 0x00000002, + 0x00000f0f, 0x00000089, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000f0f, 0x00000089, + 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, + 0xab00524f, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, + 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, + 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000d4, + 0x00010040, 0x00000035, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010f2, + 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x0300005f, + 0x001010f2, 0x00000003, 0x0300005f, 0x001010f2, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, + 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x0400005b, 0x001010f2, + 0x00000001, 0x00000004, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x06000036, + 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x07000036, 0x001020f2, 0x00000001, + 0x00d01e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e, + }; + static const DWORD ps_code[] = + { +#if 0 + struct vs_out + { + float4 position : SV_POSITION; + float4 color : COLOR; + }; + + float4 main(struct vs_out i) : SV_TARGET + { + return i.color; + } +#endif + 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003, + 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, + 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, + 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, + 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, + 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, + 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, + 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e, + }; + static const D3D11_INPUT_ELEMENT_DESC layout_desc[] = + { + {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, + {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1}, + {"COLOR", 1, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 4, D3D11_INPUT_PER_INSTANCE_DATA, 1}, + {"COLOR", 2, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 8, D3D11_INPUT_PER_INSTANCE_DATA, 1}, + {"COLOR", 3, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 12, D3D11_INPUT_PER_INSTANCE_DATA, 1}, + }; + static const unsigned int colors[] = {0xff0000ff, 0xff00ff00, 0xffff0000, 0xff0f0f0f}; + static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f}; + + if (!init_test_context(&test_context, NULL)) + return; + device = test_context.device; + context = test_context.immediate_context; + + hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc), + vs_code, sizeof(vs_code), &test_context.input_layout); + ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr); + + cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL); + ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb); + + vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(colors), colors); + stride = sizeof(colors); + offset = 0; + ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset); + + hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs); + ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr); + + hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps); + ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr); + ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0); + + for (i = 0; i < ARRAY_SIZE(colors); ++i) + { + *index = i; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0); + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white); + draw_quad(&test_context); + todo_wine_if(i > 0) + check_texture_color(test_context.backbuffer, colors[i], 1); + } + + ID3D11Buffer_Release(cb); + ID3D11Buffer_Release(vb); + ID3D11PixelShader_Release(ps); + release_test_context(&test_context); +} + static void test_getdc(void) { static const struct @@ -23420,6 +23541,7 @@ START_TEST(d3d11) test_draw_depth_only(); test_draw_uav_only(); test_cb_relative_addressing(); + test_vs_input_relative_addressing(); test_getdc(); test_shader_stage_input_output_matching(); test_shader_interstage_interface();
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Relative addressing doesn't necessarily work for SM3.
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/d3d11/tests/d3d11.c | 1 - dlls/wined3d/glsl_shader.c | 24 +++++++++++++++++++++--- dlls/wined3d/shader.c | 4 ++++ dlls/wined3d/wined3d_private.h | 3 ++- 4 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index 96b3b05adae1..7d317dc1817c 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -12339,7 +12339,6 @@ static void test_vs_input_relative_addressing(void) ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0); ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white); draw_quad(&test_context); - todo_wine_if(i > 0) check_texture_color(test_context.backbuffer, colors[i], 1); }
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c index 18822c50dfc8..32a75bf56288 100644 --- a/dlls/wined3d/glsl_shader.c +++ b/dlls/wined3d/glsl_shader.c @@ -2854,10 +2854,18 @@ static void shader_glsl_get_register_name(const struct wined3d_shader_register * struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
if (reg->idx[0].rel_addr) - FIXME("VS3+ input registers relative addressing.\n"); + FIXME("VS3 input registers relative addressing.\n"); if (priv->cur_vs_args->swizzle_map & (1u << reg->idx[0].offset)) *is_color = TRUE; - sprintf(register_name, "%s_in%u", prefix, reg->idx[0].offset); + if (reg->idx[0].rel_addr) + { + sprintf(register_name, "%s_in[%s + %u]", + prefix, rel_param0.param_str, reg->idx[0].offset); + } + else + { + sprintf(register_name, "%s_in%u", prefix, reg->idx[0].offset); + } break; }
@@ -7850,7 +7858,17 @@ static GLuint shader_glsl_generate_vshader(const struct wined3d_context *context
shader_addline(buffer, "void main()\n{\n");
- /* Base Shader Body */ + if (reg_maps->input_rel_addressing) + { + unsigned int highest_input_register = wined3d_log2i(reg_maps->input_registers); + shader_addline(buffer, "vec4 vs_in[%u];\n", highest_input_register + 1); + for (i = 0; i < shader->input_signature.element_count; ++i) + { + const struct wined3d_shader_signature_element *e = &shader->input_signature.elements[i]; + shader_addline(buffer, "vs_in[%u] = vs_in%u;\n", e->register_idx, e->register_idx); + } + } + if (FAILED(shader_generate_code(shader, buffer, reg_maps, &priv_ctx, NULL, NULL))) return 0;
diff --git a/dlls/wined3d/shader.c b/dlls/wined3d/shader.c index d9765731abb1..04ced904481c 100644 --- a/dlls/wined3d/shader.c +++ b/dlls/wined3d/shader.c @@ -709,6 +709,8 @@ static BOOL shader_record_register_usage(struct wined3d_shader *shader, struct w break;
case WINED3DSPR_INPUT: + if (reg->idx[0].rel_addr) + reg_maps->input_rel_addressing = 1; if (shader_type == WINED3D_SHADER_TYPE_PIXEL) { /* If relative addressing is used, we must assume that all @@ -721,7 +723,9 @@ static BOOL shader_record_register_usage(struct wined3d_shader *shader, struct w shader->u.ps.input_reg_used |= 1u << reg->idx[0].offset; } else + { reg_maps->input_registers |= 1u << reg->idx[0].offset; + } break;
case WINED3DSPR_RASTOUT: diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index a79a68f1d0c2..3c6a347468ca 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -1024,7 +1024,8 @@ struct wined3d_shader_reg_maps DWORD usespow : 1; DWORD point_size : 1; DWORD vocp : 1; - DWORD padding : 17; + DWORD input_rel_addressing : 1; + DWORD padding : 16;
DWORD rt_mask; /* Used render targets, 32 max. */
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/d3d11/tests/d3d11.c | 316 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 299 insertions(+), 17 deletions(-)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index 7d317dc1817c..cf45f8acab24 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -19,12 +19,13 @@
#include <assert.h> #include <float.h> +#include <limits.h> +#include <math.h> #include <stdlib.h> #define COBJMACROS #include "initguid.h" #include "d3d11_1.h" #include "wine/test.h" -#include <limits.h>
#ifndef ARRAY_SIZE #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) @@ -1247,14 +1248,14 @@ static void draw_quad_vs(unsigned int line, struct d3d11_test_context *context, { static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] = { - {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, + {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, }; - static const struct vec2 quad[] = + static const struct vec3 quad[] = { - {-1.0f, -1.0f}, - {-1.0f, 1.0f}, - { 1.0f, -1.0f}, - { 1.0f, 1.0f}, + {-1.0f, -1.0f, 0.0f}, + {-1.0f, 1.0f, 0.0f}, + { 1.0f, -1.0f, 0.0f}, + { 1.0f, 1.0f, 0.0f}, };
ID3D11Device *device = context->device; @@ -15235,12 +15236,12 @@ static void test_face_culling(void) 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, }; - static const struct vec2 ccw_quad[] = + static const struct vec3 ccw_quad[] = { - {-1.0f, 1.0f}, - {-1.0f, -1.0f}, - { 1.0f, 1.0f}, - { 1.0f, -1.0f}, + {-1.0f, 1.0f, 0.0f}, + {-1.0f, -1.0f, 0.0f}, + { 1.0f, 1.0f, 0.0f}, + { 1.0f, -1.0f, 0.0f}, }; static const struct { @@ -16115,12 +16116,12 @@ static void test_stencil_separate(void)
static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f}; static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f}; - static const struct vec2 ccw_quad[] = + static const struct vec3 ccw_quad[] = { - {-1.0f, -1.0f}, - { 1.0f, -1.0f}, - {-1.0f, 1.0f}, - { 1.0f, 1.0f}, + {-1.0f, -1.0f, 0.0f}, + { 1.0f, -1.0f, 0.0f}, + {-1.0f, 1.0f, 0.0f}, + { 1.0f, 1.0f, 0.0f}, };
if (!init_test_context(&test_context, NULL)) @@ -22134,6 +22135,286 @@ static void test_gather_c(void) release_test_context(&test_context); }
+static void test_depth_bias(void) +{ + struct vec3 vertices[] = + { + {-1.0f, -1.0f, 0.5f}, + {-1.0f, 1.0f, 0.5f}, + { 1.0f, -1.0f, 0.5f}, + { 1.0f, 1.0f, 0.5f}, + }; + struct d3d11_test_context test_context; + D3D11_RASTERIZER_DESC rasterizer_desc; + D3D11_TEXTURE2D_DESC texture_desc; + double m, r, bias, depth, data; + ID3D11DeviceContext *context; + struct resource_readback rb; + ID3D11DepthStencilView *dsv; + unsigned int expected_value; + ID3D11RasterizerState *rs; + ID3D11Texture2D *texture; + float depth_values[480]; + unsigned int format_idx; + unsigned int x, y, i, j; + unsigned int shift = 0; + ID3D11Device *device; + DXGI_FORMAT format; + const UINT32 *u32; + const UINT16 *u16; + UINT32 u32_value; + HRESULT hr; + + static const struct + { + float z; + float exponent; + } + quads[] = + { + {0.125f, -3.0f}, + {0.250f, -2.0f}, + {0.500f, -1.0f}, + {1.000f, 0.0f}, + }; + static const unsigned int bias_tests[] = + { + -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 quad_slopes[] = + { + 0.0f, 0.5f, 1.0f + }; + static const float slope_scaled_bias_tests[] = + { + 0.0f, 0.5f, 1.0f, 2.0f, 128.0f, 1000.0f, 10000.0f, + }; + static const DXGI_FORMAT formats[] = + { + DXGI_FORMAT_D32_FLOAT, + DXGI_FORMAT_D24_UNORM_S8_UINT, + DXGI_FORMAT_D16_UNORM, + }; + + if (!init_test_context(&test_context, NULL)) + return; + + device = test_context.device; + context = test_context.immediate_context; + + memset(&rasterizer_desc, 0, sizeof(rasterizer_desc)); + rasterizer_desc.FillMode = D3D11_FILL_SOLID; + rasterizer_desc.CullMode = D3D11_CULL_NONE; + rasterizer_desc.FrontCounterClockwise = FALSE; + rasterizer_desc.DepthBias = 0; + rasterizer_desc.DepthBiasClamp = 0.0f; + rasterizer_desc.SlopeScaledDepthBias = 0.0f; + rasterizer_desc.DepthClipEnable = TRUE; + + for (format_idx = 0; format_idx < ARRAY_SIZE(formats); ++format_idx) + { + format = formats[format_idx]; + + ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc); + texture_desc.Format = format; + 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 render depth stencil view, hr %#x.\n", hr); + ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv); + ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); + draw_quad(&test_context); + switch (format) + { + case DXGI_FORMAT_D32_FLOAT: + check_texture_float(texture, 0.0f, 0); + break; + case DXGI_FORMAT_D24_UNORM_S8_UINT: + /* FIXME: Depth/stencil byte order is reversed in wined3d. */ + shift = get_texture_color(texture, 0, 0) == 0xffffff ? 0 : 8; + todo_wine + check_texture_color(texture, 0xffffff, 1); + break; + case DXGI_FORMAT_D16_UNORM: + get_texture_readback(texture, 0, &rb); + for (y = 0; y < texture_desc.Height; ++y) + { + for (x = 0; x < texture_desc.Width; ++x) + { + u16 = get_readback_data(&rb, x, y, sizeof(*u16)); + ok(*u16 == 0xffff, "Got unexpected value %#x.\n", *u16); + } + } + release_resource_readback(&rb); + break; + default: + trace("Unhandled format %#x.\n", format); + break; + } + + /* DepthBias */ + for (i = 0; i < ARRAY_SIZE(quads); ++i) + { + for (j = 0; j < ARRAY_SIZE(vertices); ++j) + vertices[j].z = quads[i].z; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)test_context.vb, + 0, NULL, vertices, 0, 0); + + for (j = 0; j < ARRAY_SIZE(bias_tests); ++j) + { + rasterizer_desc.DepthBias = bias_tests[j]; + ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rs); + ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr); + ID3D11DeviceContext_RSSetState(context, rs); + ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_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); + 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); + + 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) + { + 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); + + 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) + { + 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; + } + ID3D11RasterizerState_Release(rs); + } + } + + /* SlopeScaledDepthBias */ + rasterizer_desc.DepthBias = 0; + for (i = 0; i < ARRAY_SIZE(quad_slopes); ++i) + { + for (j = 0; j < ARRAY_SIZE(vertices); ++j) + vertices[j].z = j == 1 || j == 3 ? 0.0f : quad_slopes[i]; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)test_context.vb, + 0, NULL, vertices, 0, 0); + + ID3D11DeviceContext_RSSetState(context, NULL); + ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0); + draw_quad(&test_context); + get_texture_readback(texture, 0, &rb); + for (y = 0; y < texture_desc.Height; ++y) + { + switch (format) + { + case DXGI_FORMAT_D32_FLOAT: + depth_values[y] = get_readback_float(&rb, 0, y); + break; + case DXGI_FORMAT_D24_UNORM_S8_UINT: + u32 = get_readback_data(&rb, 0, y, sizeof(*u32)); + u32_value = *u32 >> shift; + depth_values[y] = u32_value / 16777215.0f; + break; + case DXGI_FORMAT_D16_UNORM: + u16 = get_readback_data(&rb, 0, y, sizeof(*u16)); + depth_values[y] = *u16 / 65535.0f; + break; + default: + break; + } + } + release_resource_readback(&rb); + + for (j = 0; j < ARRAY_SIZE(slope_scaled_bias_tests); ++j) + { + rasterizer_desc.SlopeScaledDepthBias = slope_scaled_bias_tests[j]; + ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rs); + ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr); + ID3D11DeviceContext_RSSetState(context, rs); + ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0); + draw_quad(&test_context); + + m = quad_slopes[i] / texture_desc.Height; + m = sqrtf(m * m); + bias = rasterizer_desc.SlopeScaledDepthBias * m; + get_texture_readback(texture, 0, &rb); + for (y = 0; y < texture_desc.Height; ++y) + { + depth = min(max(0.0f, depth_values[y] + bias), 1.0f); + switch (format) + { + case DXGI_FORMAT_D32_FLOAT: + data = get_readback_float(&rb, 0, y); + ok(compare_float(data, depth, 2), + "Got depth %.8e, expected %.8e.\n", data, depth); + break; + case DXGI_FORMAT_D24_UNORM_S8_UINT: + u32 = get_readback_data(&rb, 0, y, sizeof(*u32)); + u32_value = *u32 >> shift; + expected_value = depth * 16777215.0f + 0.5f; + ok(abs(u32_value - expected_value) <= 3, + "Got value %#x (%.8e), expected %#x (%.8e).\n", + u32_value, u32_value / 16777215.0f, + expected_value, expected_value / 16777215.0f); + break; + case DXGI_FORMAT_D16_UNORM: + u16 = get_readback_data(&rb, 0, y, sizeof(*u16)); + expected_value = depth * 65535.0f + 0.5f; + ok(abs(*u16 - expected_value) <= 1, + "Got value %#x (%.8e), expected %#x (%.8e).\n", + *u16, *u16 / 65535.0f, expected_value, expected_value / 65535.0f); + break; + default: + break; + } + } + release_resource_readback(&rb); + ID3D11RasterizerState_Release(rs); + } + } + + ID3D11Texture2D_Release(texture); + ID3D11DepthStencilView_Release(dsv); + } + + release_test_context(&test_context); +} + static void test_fractional_viewports(void) { struct d3d11_test_context test_context; @@ -23591,6 +23872,7 @@ START_TEST(d3d11) test_stream_output_components(); test_gather(); test_gather_c(); + test_depth_bias(); test_fractional_viewports(); test_early_depth_stencil(); test_conservative_depth_output();
On 7 December 2017 at 14:44, Józef Kucia jkucia@codeweavers.com wrote:
- static const unsigned int bias_tests[] =
- {
-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,
- };
I think it would be more appropriate for these to be signed integers.
- static const float quad_slopes[] =
- {
0.0f, 0.5f, 1.0f
- };
...
m = quad_slopes[i] / texture_desc.Height;
m = sqrtf(m * m);
sqrtf(m * m) = fabsf(m) = m
Right?
bias = rasterizer_desc.SlopeScaledDepthBias * m;
get_texture_readback(texture, 0, &rb);
for (y = 0; y < texture_desc.Height; ++y)
{
depth = min(max(0.0f, depth_values[y] + bias), 1.0f);
switch (format)
{
case DXGI_FORMAT_D32_FLOAT:
data = get_readback_float(&rb, 0, y);
ok(compare_float(data, depth, 2),
"Got depth %.8e, expected %.8e.\n", data, depth);
This needs a tolerance of 64 to pass here on Intel SKL.
On Thu, Dec 7, 2017 at 4:04 PM, Henri Verbeet hverbeet@gmail.com wrote:
On 7 December 2017 at 14:44, Józef Kucia jkucia@codeweavers.com wrote:
- static const unsigned int bias_tests[] =
- {
-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,
- };
I think it would be more appropriate for these to be signed integers.
- static const float quad_slopes[] =
- {
0.0f, 0.5f, 1.0f
- };
...
m = quad_slopes[i] / texture_desc.Height;
m = sqrtf(m * m);
sqrtf(m * m) = fabsf(m) = m
Right?
bias = rasterizer_desc.SlopeScaledDepthBias * m;
get_texture_readback(texture, 0, &rb);
for (y = 0; y < texture_desc.Height; ++y)
{
depth = min(max(0.0f, depth_values[y] + bias), 1.0f);
switch (format)
{
case DXGI_FORMAT_D32_FLOAT:
data = get_readback_float(&rb, 0, y);
ok(compare_float(data, depth, 2),
"Got depth %.8e, expected %.8e.\n", data, depth);
This needs a tolerance of 64 to pass here on Intel SKL.
On Thu, Dec 7, 2017 at 4:04 PM, Henri Verbeet hverbeet@gmail.com wrote:
- static const float quad_slopes[] =
- {
0.0f, 0.5f, 1.0f
- };
...
m = quad_slopes[i] / texture_desc.Height;
m = sqrtf(m * m);
sqrtf(m * m) = fabsf(m) = m
Right?
Right :D
Makes the test much faster.
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/d3d11/tests/d3d11.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index cf45f8acab24..6c058860588e 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -92,7 +92,8 @@ struct device_desc struct swapchain_desc { BOOL windowed; - UINT buffer_count; + unsigned buffer_count; + unsigned int width, height; DXGI_SWAP_EFFECT swap_effect; DWORD flags; }; @@ -1101,7 +1102,8 @@ static BOOL check_compute_shaders_via_sm4_support(ID3D11Device *device) return options.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x; }
-static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window, const struct swapchain_desc *swapchain_desc) +static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window, + const struct swapchain_desc *swapchain_desc) { DXGI_SWAP_CHAIN_DESC dxgi_desc; IDXGISwapChain *swapchain; @@ -1140,6 +1142,10 @@ static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window, const dxgi_desc.Windowed = swapchain_desc->windowed; dxgi_desc.SwapEffect = swapchain_desc->swap_effect; dxgi_desc.BufferCount = swapchain_desc->buffer_count; + if (swapchain_desc->width) + dxgi_desc.BufferDesc.Width = swapchain_desc->width; + if (swapchain_desc->height) + dxgi_desc.BufferDesc.Height = swapchain_desc->height;
if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT) dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT; @@ -1170,10 +1176,12 @@ struct d3d11_test_context ID3D11Buffer *ps_cb; };
-#define init_test_context(c, l) init_test_context_(__LINE__, c, l) +#define init_test_context(a, b) init_test_context_(__LINE__, a, b, NULL) +#define init_test_context_ext(a, b, c) init_test_context_(__LINE__, a, b, c) static BOOL init_test_context_(unsigned int line, struct d3d11_test_context *context, - const D3D_FEATURE_LEVEL *feature_level) + const D3D_FEATURE_LEVEL *feature_level, const struct swapchain_desc *swapchain_desc) { + unsigned int rt_width, rt_height; struct device_desc device_desc; D3D11_VIEWPORT vp; HRESULT hr; @@ -1188,11 +1196,14 @@ static BOOL init_test_context_(unsigned int line, struct d3d11_test_context *con skip_(__FILE__, line)("Failed to create device.\n"); return FALSE; } - SetRect(&rect, 0, 0, 640, 480); + + rt_width = swapchain_desc && swapchain_desc->width ? swapchain_desc->width : 640; + rt_height = swapchain_desc && swapchain_desc->height ? swapchain_desc->height : 480; + SetRect(&rect, 0, 0, rt_width, rt_height); AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE); context->window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL); - context->swapchain = create_swapchain(context->device, context->window, NULL); + context->swapchain = create_swapchain(context->device, context->window, swapchain_desc); hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D11Texture2D, (void **)&context->backbuffer); ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
@@ -1206,8 +1217,8 @@ static BOOL init_test_context_(unsigned int line, struct d3d11_test_context *con
vp.TopLeftX = 0.0f; vp.TopLeftY = 0.0f; - vp.Width = 640.0f; - vp.Height = 480.0f; + vp.Width = rt_width; + vp.Height = rt_height; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; ID3D11DeviceContext_RSSetViewports(context->immediate_context, 1, &vp); @@ -11106,6 +11117,7 @@ static void test_swapchain_flip(void) window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL); desc.buffer_count = 3; + desc.width = desc.height = 0; desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL; desc.windowed = TRUE; desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT; @@ -22146,6 +22158,7 @@ static void test_depth_bias(void) }; struct d3d11_test_context test_context; D3D11_RASTERIZER_DESC rasterizer_desc; + struct swapchain_desc swapchain_desc; D3D11_TEXTURE2D_DESC texture_desc; double m, r, bias, depth, data; ID3D11DeviceContext *context; @@ -22154,11 +22167,11 @@ static void test_depth_bias(void) unsigned int expected_value; ID3D11RasterizerState *rs; ID3D11Texture2D *texture; - float depth_values[480]; unsigned int format_idx; unsigned int x, y, i, j; unsigned int shift = 0; ID3D11Device *device; + float *depth_values; DXGI_FORMAT format; const UINT32 *u32; const UINT16 *u16; @@ -22197,7 +22210,13 @@ static void test_depth_bias(void) DXGI_FORMAT_D16_UNORM, };
- if (!init_test_context(&test_context, NULL)) + swapchain_desc.windowed = TRUE; + swapchain_desc.buffer_count = 1; + swapchain_desc.width = 200; + swapchain_desc.height = 200; + swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD; + swapchain_desc.flags = 0; + if (!init_test_context_ext(&test_context, NULL, &swapchain_desc)) return;
device = test_context.device; @@ -22212,6 +22231,9 @@ static void test_depth_bias(void) rasterizer_desc.SlopeScaledDepthBias = 0.0f; rasterizer_desc.DepthClipEnable = TRUE;
+ depth_values = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*depth_values) * swapchain_desc.height); + ok(!!depth_values, "Failed to allocate memory.\n"); + for (format_idx = 0; format_idx < ARRAY_SIZE(formats); ++format_idx) { format = formats[format_idx]; @@ -22412,6 +22434,7 @@ static void test_depth_bias(void) ID3D11DepthStencilView_Release(dsv); }
+ HeapFree(GetProcessHeap(), 0, depth_values); release_test_context(&test_context); }
wined3d will not do this anymore
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/d3d8/device.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c index f77fb27a5875..506961a215bd 100644 --- a/dlls/d3d8/device.c +++ b/dlls/d3d8/device.c @@ -747,6 +747,8 @@ static HRESULT WINAPI d3d8_device_Reset(IDirect3DDevice8 *iface, { present_parameters->BackBufferCount = swapchain_desc.backbuffer_count; wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_POINTSIZE_MIN, 0); + wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZENABLE, + !!swapchain_desc.enable_auto_depth_stencil); device->device_state = D3D8_DEVICE_STATE_OK; } else
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 | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index 20f73c0e212b..51b4896353d8 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -812,11 +812,13 @@ static HRESULT d3d9_device_get_swapchains(struct d3d9_device *device) static HRESULT d3d9_device_reset(struct d3d9_device *device, D3DPRESENT_PARAMETERS *present_parameters, D3DDISPLAYMODEEX *mode) { + BOOL extended = device->d3d_parent->extended; struct wined3d_swapchain_desc swapchain_desc; struct wined3d_display_mode wined3d_mode; HRESULT hr;
- if (!device->d3d_parent->extended && device->device_state == D3D9_DEVICE_STATE_LOST) + + if (!extended && device->device_state == D3D9_DEVICE_STATE_LOST) { WARN("App not active, returning D3DERR_DEVICELOST.\n"); return D3DERR_DEVICELOST; @@ -831,8 +833,7 @@ static HRESULT d3d9_device_reset(struct d3d9_device *device, wined3d_mode.scanline_ordering = mode->ScanLineOrdering; }
- if (!wined3d_swapchain_desc_from_present_parameters(&swapchain_desc, present_parameters, - device->d3d_parent->extended)) + if (!wined3d_swapchain_desc_from_present_parameters(&swapchain_desc, present_parameters, extended)) return D3DERR_INVALIDCALL;
wined3d_mutex_lock(); @@ -852,10 +853,16 @@ static HRESULT d3d9_device_reset(struct d3d9_device *device, }
if (SUCCEEDED(hr = wined3d_device_reset(device->wined3d_device, &swapchain_desc, - mode ? &wined3d_mode : NULL, reset_enum_callback, !device->d3d_parent->extended))) + mode ? &wined3d_mode : NULL, reset_enum_callback, !extended))) { HeapFree(GetProcessHeap(), 0, device->implicit_swapchains);
+ if (!extended) + { + 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))) { device->device_state = D3D9_DEVICE_STATE_NOT_RESET; @@ -871,7 +878,7 @@ static HRESULT d3d9_device_reset(struct d3d9_device *device, device->device_state = D3D9_DEVICE_STATE_OK; } } - else if (!device->d3d_parent->extended) + else if (!extended) { device->device_state = D3D9_DEVICE_STATE_NOT_RESET; }
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
wined3d will not do this anymore
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/ddraw/surface.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c index 394e915e2cd1..26d83cd709f1 100644 --- a/dlls/ddraw/surface.c +++ b/dlls/ddraw/surface.c @@ -6002,6 +6002,9 @@ HRESULT ddraw_surface_create(struct ddraw *ddraw, const DDSURFACEDESC2 *surface_ HeapFree(GetProcessHeap(), 0, texture); return hr_ddraw_from_wined3d(hr); } + + wined3d_device_set_render_state(ddraw->wined3d_device, WINED3D_RS_ZENABLE, + !!swapchain_desc.enable_auto_depth_stencil); } }
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
For consistency with wined3d_device_init_3d().
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/wined3d/device.c | 2 -- 1 file changed, 2 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 26557029de27..a25b98d74964 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -4880,8 +4880,6 @@ 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