Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- v2: Undefine the new abbreviations.
dlls/d3d11/tests/d3d11.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index 8c9f66f27a..afcd4ae783 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -14103,6 +14103,8 @@ static void test_create_unordered_access_view(void)
#define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM +#define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB +#define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS #define DIM_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN #define TEX_1D D3D11_UAV_DIMENSION_TEXTURE1D @@ -14130,6 +14132,8 @@ static void test_create_unordered_access_view(void) {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}}, {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}}, {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}}, + {{ 1, 1, RGBA8_UINT}, {0}, {RGBA8_UINT, TEX_2D, 0, 0, 1}}, + {{ 1, 1, RGBA8_TL}, {RGBA8_UINT, TEX_2D, 0, 0, ~0u}, {RGBA8_UINT, TEX_2D, 0, 0, 1}}, {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}}, {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}}, {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}}, @@ -14184,6 +14188,10 @@ static void test_create_unordered_access_view(void) {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}}, {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}}, {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}}, + {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 0, 1}}, + {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}}, + {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 0, 1}}, + {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}}, {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}}, {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}}, {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}}, @@ -14207,6 +14215,8 @@ static void test_create_unordered_access_view(void) }; #undef FMT_UNKNOWN #undef RGBA8_UNORM +#undef RGBA8_SRGB +#undef RGBA8_UINT #undef RGBA8_TL #undef DIM_UNKNOWN #undef TEX_1D
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- v2: Add missing abbreviation define.
dlls/d3d11/tests/d3d11.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index afcd4ae783..169293556a 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -7986,13 +7986,89 @@ static void test_render_target_views(void) {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1}, {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}}, }; +#define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN +#define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM +#define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB +#define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT +#define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS +#define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN +#define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D +#define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY +#define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D +#define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY +#define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D + static const struct + { + struct + { + D3D11_RTV_DIMENSION dimension; + unsigned int miplevel_count; + unsigned int depth_or_array_size; + DXGI_FORMAT format; + } texture; + struct rtv_desc rtv_desc; + } + invalid_desc_tests[] = + { + {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}}, + {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}}, + {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}}, + {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}}, + {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}}, + {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}}, + {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}}, + {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}}, + {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}}, + {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}}, + {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}}, + {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}}, + {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}}, + {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 0, 1}}, + {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}}, + {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 0, 1}}, + {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}}, + {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}}, + {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}}, + {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}}, + {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}}, + {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}}, + {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}}, + {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}}, + {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}}, + {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}}, + {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}}, + {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}}, + {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}}, + {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}}, + {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}}, + {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}}, + {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}}, + {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}}, + {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}}, + {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}}, + {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}}, + }; +#undef FMT_UNKNOWN +#undef RGBA8_UNORM +#undef RGBA8_SRGB +#undef RGBA8_UINT +#undef RGBA8_TL +#undef DIM_UNKNOWN +#undef TEX_1D +#undef TEX_1D_ARRAY +#undef TEX_2D +#undef TEX_2D_ARRAY +#undef TEX_3D
struct d3d11_test_context test_context; D3D11_RENDER_TARGET_VIEW_DESC rtv_desc; + D3D11_TEXTURE3D_DESC texture3d_desc; D3D11_TEXTURE2D_DESC texture_desc; ID3D11DeviceContext *context; ID3D11RenderTargetView *rtv; + ID3D11Texture3D *texture3d; ID3D11Texture2D *texture; + ID3D11Resource *resource; ID3D11Device *device; unsigned int i, j, k; void *data; @@ -8055,6 +8131,49 @@ static void test_render_target_views(void) ID3D11Texture2D_Release(texture); }
+ texture3d_desc.Width = 32; + texture3d_desc.Height = 32; + texture3d_desc.Depth = 32; + texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + texture3d_desc.Usage = D3D11_USAGE_DEFAULT; + texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET; + texture3d_desc.CPUAccessFlags = 0; + texture3d_desc.MiscFlags = 0; + + for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i) + { + assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D + || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D); + + if (invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D) + { + texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count; + texture_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size; + texture_desc.Format = invalid_desc_tests[i].texture.format; + texture_desc.MiscFlags = 0; + + hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture); + ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr); + resource = (ID3D11Resource *)texture; + } + else + { + texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count; + texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size; + texture3d_desc.Format = invalid_desc_tests[i].texture.format; + + hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d); + ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr); + resource = (ID3D11Resource *)texture3d; + } + + get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc); + hr = ID3D11Device_CreateRenderTargetView(device, resource, &rtv_desc, &rtv); + ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr); + + ID3D11Resource_Release(resource); + } + HeapFree(GetProcessHeap(), 0, data); release_test_context(&test_context); }
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- v2: Undefine some missing abbreviations.
dlls/d3d11/tests/d3d11.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index 169293556a..eec756ee2e 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -3275,6 +3275,7 @@ static void test_create_shader_resource_view(void)
#define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM +#define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS #define DIM_UNKNOWN D3D11_SRV_DIMENSION_UNKNOWN @@ -3400,6 +3401,8 @@ static void test_create_shader_resource_view(void) {{TEX_2D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}}, {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 1}}, {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 1}}, + {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 1}}, + {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 1}}, {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}}, {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}}, {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}}, @@ -3419,6 +3422,9 @@ static void test_create_shader_resource_view(void) }; #undef FMT_UNKNOWN #undef RGBA8_UNORM +#undef RGBA8_SRGB +#undef RGBA8_UINT +#undef RGBA8_TL #undef DIM_UNKNOWN #undef TEX_1D #undef TEX_1D_ARRAY
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- v2: Workaround for the testbot crash, always initialize the texture level used for sampling, a few formatting fixes.
dlls/d3d11/tests/d3d11.c | 457 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 457 insertions(+)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index eec756ee2e..0d6e14f5ab 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -23621,6 +23621,462 @@ static void test_combined_clip_and_cull_distances(void) release_test_context(&test_context); }
+static void test_generate_mips(void) +{ + static const DWORD ps_code[] = + { +#if 0 + Texture2D t; + SamplerState s; + + float4 main(float4 position : SV_POSITION) : SV_Target + { + float2 p; + + p.x = position.x / 640.0f; + p.y = position.y / 480.0f; + return t.Sample(s, p); + } +#endif + 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003, + 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, + 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49, + 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, + 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040, + 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, + 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, + 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, + 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000, + 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e, + }; + static const DWORD ps_code_3d[] = + { +#if 0 + Texture3D t; + SamplerState s; + + float4 main(float4 position : SV_POSITION) : SV_Target + { + float3 p; + + p.x = position.x / 640.0f; + p.y = position.y / 480.0f; + p.z = 0.5f; + return t.Sample(s, p); + } +#endif + 0x43425844, 0xa1e26083, 0xeb45763e, 0x1e5a5089, 0xdfbbe0df, 0x00000001, 0x00000148, 0x00000003, + 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, + 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49, + 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, + 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ac, 0x00000040, + 0x0000002b, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555, + 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, + 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, + 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f000000, + 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, + 0x00000000, 0x0100003e, + }; + static const struct + { + D3D11_RESOURCE_DIMENSION dim; + D3D11_SRV_DIMENSION srv_dim; + unsigned int array_size; + } + resource_types[] = + { + {D3D11_RESOURCE_DIMENSION_BUFFER, D3D11_SRV_DIMENSION_BUFFER, 1}, + {D3D11_RESOURCE_DIMENSION_TEXTURE2D, D3D11_SRV_DIMENSION_TEXTURE2D, 1}, + {D3D11_RESOURCE_DIMENSION_TEXTURE2D, D3D11_SRV_DIMENSION_TEXTURE2DARRAY, 4}, + {D3D11_RESOURCE_DIMENSION_TEXTURE3D, D3D11_SRV_DIMENSION_TEXTURE3D, 1}, + }; + static const struct + { + DXGI_FORMAT texture_format; + UINT bind_flags; + UINT misc_flags; + BOOL null_srv; + UINT base_level; + BOOL expected_creation; + BOOL expected_mips; + } + tests[] = + { + {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, + 0, TRUE, FALSE}, + {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, 0, TRUE, + 0, TRUE, FALSE}, + {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, + 0, TRUE, FALSE}, + {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, 0, FALSE, + 0, TRUE, FALSE}, + {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE, + 0, FALSE, FALSE}, + {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE, + 0, FALSE, FALSE}, + {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE, + 0, TRUE, TRUE}, + {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE, + 1, TRUE, TRUE}, + {DXGI_FORMAT_R8G8B8A8_TYPELESS, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE, + 1, TRUE, TRUE}, + {DXGI_FORMAT_R8G8B8A8_UINT, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, TRUE, + 1, TRUE, FALSE}, + }; + static const struct + { + POINT pos; + DWORD color; + } + expected[] = + { + {{200, 200}, 0xffff0000}, + {{280, 200}, 0xffff0000}, + {{360, 200}, 0xff00ff00}, + {{440, 200}, 0xff00ff00}, + {{200, 270}, 0xff0000ff}, + {{280, 270}, 0xff0000ff}, + {{360, 270}, 0xff000000}, + {{440, 270}, 0xff000000}, + }; + static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f}; + static const RECT r1 = {8, 8, 16, 16}; + static const RECT r2 = {16, 8, 24, 16}; + static const RECT r3 = {8, 16, 16, 24}; + static const RECT r4 = {16, 16, 24, 24}; + DWORD *data, *zero_data, color, expected_color; + ID3D11ShaderResourceView *srv, *srv_sampling; + D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc; + struct d3d11_test_context test_context; + D3D11_TEXTURE2D_DESC texture2d_desc; + D3D11_TEXTURE3D_DESC texture3d_desc; + ID3D11SamplerState *sampler_state; + D3D11_SAMPLER_DESC sampler_desc; + D3D11_BUFFER_DESC buffer_desc; + unsigned int i, j, k, x, y, z; + ID3D11PixelShader *ps, *ps_3d; + ID3D11DeviceContext *context; + struct resource_readback rb; + ID3D11Resource *resource; + ID3D11Device *device; + HRESULT hr; + + if (!init_test_context(&test_context, NULL)) + return; + + device = test_context.device; + context = test_context.immediate_context; + + hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps); + ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr); + + hr = ID3D11Device_CreatePixelShader(device, ps_code_3d, sizeof(ps_code_3d), NULL, &ps_3d); + ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr); + + sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; + sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; + sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; + sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; + sampler_desc.MipLODBias = 0.0f; + sampler_desc.MaxAnisotropy = 0; + sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER; + sampler_desc.BorderColor[0] = 0.0f; + sampler_desc.BorderColor[1] = 0.0f; + sampler_desc.BorderColor[2] = 0.0f; + sampler_desc.BorderColor[3] = 0.0f; + sampler_desc.MinLOD = 0.0f; + sampler_desc.MaxLOD = D3D11_FLOAT32_MAX; + + hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state); + ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr); + ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state); + + data = HeapAlloc(GetProcessHeap(), 0, sizeof(*data) * 32 * 32 * 32); + + for (z = 0; z < 32; ++z) + { + for (y = 0; y < 32; ++y) + { + for (x = 0; x < 32; ++x) + { + DWORD *dst = &data[z * 32 * 32 + y * 32 + x]; + POINT pt; + + pt.x = x; + pt.y = y; + if (PtInRect(&r1, pt)) + *dst = 0xffff0000; + else if (PtInRect(&r2, pt)) + *dst = 0xff00ff00; + else if (PtInRect(&r3, pt)) + *dst = 0xff0000ff; + else if (PtInRect(&r4, pt)) + *dst = 0xff000000; + else + *dst = 0xffffffff; + } + } + } + + zero_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*zero_data) * 16 * 16 * 16); + + for (i = 0; i < ARRAY_SIZE(resource_types); ++i) + { + for (j = 0; j < ARRAY_SIZE(tests); ++j) + { + unsigned int base_multiplier = 1u << tests[j].base_level; + + if (is_warp_device(device) && tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT) + { + /* Testing this format seems to break the WARP device. */ + skip("Skipping test with DXGI_FORMAT_R8G8B8A8_UINT on WARP.\n"); + continue; + } + + switch (resource_types[i].dim) + { + case D3D11_RESOURCE_DIMENSION_BUFFER: + buffer_desc.ByteWidth = 32 * base_multiplier; + buffer_desc.Usage = D3D11_USAGE_DEFAULT; + buffer_desc.BindFlags = tests[j].bind_flags; + buffer_desc.CPUAccessFlags = 0; + buffer_desc.MiscFlags = tests[j].misc_flags; + buffer_desc.StructureByteStride = 0; + + hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, + (ID3D11Buffer **)&resource); + break; + case D3D11_RESOURCE_DIMENSION_TEXTURE2D: + texture2d_desc.Width = 32 * base_multiplier; + texture2d_desc.Height = 32 * base_multiplier; + texture2d_desc.MipLevels = 0; + texture2d_desc.ArraySize = resource_types[i].array_size; + texture2d_desc.Format = tests[j].texture_format; + texture2d_desc.SampleDesc.Count = 1; + texture2d_desc.SampleDesc.Quality = 0; + texture2d_desc.Usage = D3D11_USAGE_DEFAULT; + texture2d_desc.BindFlags = tests[j].bind_flags; + texture2d_desc.CPUAccessFlags = 0; + texture2d_desc.MiscFlags = tests[j].misc_flags; + + hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, + (ID3D11Texture2D **)&resource); + break; + case D3D11_RESOURCE_DIMENSION_TEXTURE3D: + texture3d_desc.Width = 32 * base_multiplier; + texture3d_desc.Height = 32 * base_multiplier; + texture3d_desc.Depth = 32 * base_multiplier; + texture3d_desc.MipLevels = 0; + texture3d_desc.Format = tests[j].texture_format; + texture3d_desc.Usage = D3D11_USAGE_DEFAULT; + texture3d_desc.BindFlags = tests[j].bind_flags; + texture3d_desc.CPUAccessFlags = 0; + texture3d_desc.MiscFlags = tests[j].misc_flags; + + hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, + (ID3D11Texture3D **)&resource); + break; + default: + break; + } + if (tests[j].expected_creation && (resource_types[i].dim != D3D11_RESOURCE_DIMENSION_BUFFER + || !(tests[j].misc_flags & D3D11_RESOURCE_MISC_GENERATE_MIPS))) + { + ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create resource, hr %#x.\n", i, j, hr); + } + else + { + ok(hr == E_INVALIDARG, "Resource type %u, test %u: unexpectedly succeeded " + "to create resource, hr %#x.\n", i, j, hr); + continue; + } + + if (tests[j].null_srv) + { + hr = ID3D11Device_CreateShaderResourceView(device, resource, NULL, &srv); + } + else + { + srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + srv_desc.ViewDimension = resource_types[i].srv_dim; + switch (resource_types[i].srv_dim) + { + case D3D11_SRV_DIMENSION_BUFFER: + srv_desc.Buffer.ElementOffset = 0; + srv_desc.Buffer.ElementWidth = 0; + break; + case D3D11_SRV_DIMENSION_TEXTURE2D: + srv_desc.Texture2D.MostDetailedMip = tests[j].base_level; + srv_desc.Texture2D.MipLevels = ~0u; + break; + case D3D11_SRV_DIMENSION_TEXTURE2DARRAY: + srv_desc.Texture2DArray.MostDetailedMip = tests[j].base_level; + srv_desc.Texture2DArray.MipLevels = ~0u; + srv_desc.Texture2DArray.FirstArraySlice = 0; + srv_desc.Texture2DArray.ArraySize = resource_types[i].array_size; + break; + case D3D11_SRV_DIMENSION_TEXTURE3D: + srv_desc.Texture3D.MostDetailedMip = tests[j].base_level; + srv_desc.Texture3D.MipLevels = ~0u; + break; + default: + break; + } + hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv); + } + if (resource_types[i].dim == D3D11_RESOURCE_DIMENSION_BUFFER) + { + ok(FAILED(hr), "Test %u: unexpectedly succeeded to create shader resource view, " + "hr %#x.\n", j, hr); + ID3D11Resource_Release(resource); + continue; + } + else + { + ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create " + "shader resource view, hr %#x.\n", i, j, hr); + } + + ID3D11DeviceContext_UpdateSubresource(context, resource, tests[j].base_level, + NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32); + ID3D11DeviceContext_UpdateSubresource(context, resource, tests[j].base_level + 1, + NULL, zero_data, sizeof(*zero_data) * 16, sizeof(*zero_data) * 16 * 16); + + ID3D11DeviceContext_GenerateMips(context, srv); + + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x); + + srv_desc.Format = tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT + ? DXGI_FORMAT_R8G8B8A8_UINT : DXGI_FORMAT_R8G8B8A8_UNORM; + srv_desc.ViewDimension = resource_types[i].dim == D3D11_RESOURCE_DIMENSION_TEXTURE3D + ? D3D11_SRV_DIMENSION_TEXTURE3D : D3D11_SRV_DIMENSION_TEXTURE2D; + srv_desc.Texture2D.MostDetailedMip = tests[j].base_level + 1; + srv_desc.Texture2D.MipLevels = ~0u; + hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling); + ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create shader resource view, " + "hr %#x.\n", i, j, hr); + ID3D11DeviceContext_PSSetShader(context, resource_types[i].dim + == D3D11_RESOURCE_DIMENSION_TEXTURE3D ? ps_3d : ps, NULL, 0); + ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling); + + draw_quad(&test_context); + + get_texture_readback(test_context.backbuffer, 0, &rb); + for (k = 0; k < ARRAY_SIZE(expected); ++k) + { + color = get_readback_color(&rb, expected[k].pos.x, expected[k].pos.y); + expected_color = tests[j].expected_mips ? expected[k].color : 0; + ok(color == expected_color, "Resource type %u, test %u: pixel (%u, %u) " + "has color %08x, expected %08x.\n", + i, j, expected[k].pos.x, expected[k].pos.y, color, expected_color); + } + release_resource_readback(&rb); + + ID3D11ShaderResourceView_Release(srv_sampling); + ID3D11ShaderResourceView_Release(srv); + ID3D11Resource_Release(resource); + } + } + + /* Test the effect of sRGB views. */ + for (y = 0; y < 32; ++y) + { + for (x = 0; x < 32; ++x) + { + DWORD *dst = &data[y * 32 + x]; + + *dst = (x + y) % 2 * 0xffffffff; + } + } + texture2d_desc.Width = 32; + texture2d_desc.Height = 32; + texture2d_desc.MipLevels = 0; + texture2d_desc.ArraySize = 1; + texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS; + texture2d_desc.SampleDesc.Count = 1; + texture2d_desc.SampleDesc.Quality = 0; + texture2d_desc.Usage = D3D11_USAGE_DEFAULT; + texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; + texture2d_desc.CPUAccessFlags = 0; + texture2d_desc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS; + + hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, (ID3D11Texture2D **)&resource); + ok(SUCCEEDED(hr), "Failed to create resource, hr %#x.\n", hr); + hr = ID3D11Device_CreateShaderResourceView(device, resource, NULL, &srv); + ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr); + srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; + srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + srv_desc.Texture2D.MostDetailedMip = 0; + srv_desc.Texture2D.MipLevels = ~0u; + hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv); + ID3D11DeviceContext_UpdateSubresource(context, resource, + 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32); + + ID3D11DeviceContext_GenerateMips(context, srv); + + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.w); + + srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + srv_desc.Texture2D.MostDetailedMip = 1; + srv_desc.Texture2D.MipLevels = ~0u; + hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling); + ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr); + ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0); + ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling); + + draw_quad(&test_context); + + get_texture_readback(test_context.backbuffer, 0, &rb); + color = get_readback_color(&rb, 320, 240); + ok(compare_color(color, 0x7fbcbcbc, 1) || broken(compare_color(color, 0x7f7f7f7f, 1)), /* AMD */ + "Unexpected color %08x.\n", color); + release_resource_readback(&rb); + + ID3D11ShaderResourceView_Release(srv_sampling); + ID3D11ShaderResourceView_Release(srv); + + srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + srv_desc.Texture2D.MostDetailedMip = 0; + srv_desc.Texture2D.MipLevels = ~0u; + hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv); + ID3D11DeviceContext_UpdateSubresource(context, resource, + 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32); + + ID3D11DeviceContext_GenerateMips(context, srv); + + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.w); + + srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + srv_desc.Texture2D.MostDetailedMip = 1; + srv_desc.Texture2D.MipLevels = ~0u; + hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling); + ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr); + ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0); + ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling); + + draw_quad(&test_context); + + get_texture_readback(test_context.backbuffer, 0, &rb); + check_readback_data_color(&rb, NULL, 0x7f7f7f7f, 1); + release_resource_readback(&rb); + + ID3D11ShaderResourceView_Release(srv_sampling); + ID3D11ShaderResourceView_Release(srv); + + ID3D11Resource_Release(resource); + + HeapFree(GetProcessHeap(), 0, zero_data); + HeapFree(GetProcessHeap(), 0, data); + + ID3D11SamplerState_Release(sampler_state); + ID3D11PixelShader_Release(ps_3d); + ID3D11PixelShader_Release(ps); + release_test_context(&test_context); +} + START_TEST(d3d11) { test_create_device(); @@ -23732,4 +24188,5 @@ START_TEST(d3d11) test_format_compatibility(); test_clip_distance(); test_combined_clip_and_cull_distances(); + test_generate_mips(); }
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- v2: Workaround for the testbot crash, always initialize the texture level used for sampling, a few formatting fixes.
dlls/d3d10core/tests/device.c | 453 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 453 insertions(+)
diff --git a/dlls/d3d10core/tests/device.c b/dlls/d3d10core/tests/device.c index 5221c0ea3a..48287796c1 100644 --- a/dlls/d3d10core/tests/device.c +++ b/dlls/d3d10core/tests/device.c @@ -13156,6 +13156,458 @@ static void test_format_compatibility(void) ok(!refcount, "Device has %u references left.\n", refcount); }
+static void test_generate_mips(void) +{ + static const DWORD ps_code[] = + { +#if 0 + Texture2D t; + SamplerState s; + + float4 main(float4 position : SV_POSITION) : SV_Target + { + float2 p; + + p.x = position.x / 640.0f; + p.y = position.y / 480.0f; + return t.Sample(s, p); + } +#endif + 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003, + 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, + 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49, + 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, + 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040, + 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, + 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, + 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, + 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000, + 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e, + }; + static const DWORD ps_code_3d[] = + { +#if 0 + Texture3D t; + SamplerState s; + + float4 main(float4 position : SV_POSITION) : SV_Target + { + float3 p; + + p.x = position.x / 640.0f; + p.y = position.y / 480.0f; + p.z = 0.5f; + return t.Sample(s, p); + } +#endif + 0x43425844, 0xa1e26083, 0xeb45763e, 0x1e5a5089, 0xdfbbe0df, 0x00000001, 0x00000148, 0x00000003, + 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, + 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49, + 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, + 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ac, 0x00000040, + 0x0000002b, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555, + 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, + 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, + 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f000000, + 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, + 0x00000000, 0x0100003e, + }; + static const struct + { + D3D10_RESOURCE_DIMENSION dim; + D3D10_SRV_DIMENSION srv_dim; + unsigned int array_size; + } + resource_types[] = + { + {D3D10_RESOURCE_DIMENSION_BUFFER, D3D10_SRV_DIMENSION_BUFFER, 1}, + {D3D10_RESOURCE_DIMENSION_TEXTURE2D, D3D10_SRV_DIMENSION_TEXTURE2D, 1}, + {D3D10_RESOURCE_DIMENSION_TEXTURE2D, D3D10_SRV_DIMENSION_TEXTURE2DARRAY, 4}, + {D3D10_RESOURCE_DIMENSION_TEXTURE3D, D3D10_SRV_DIMENSION_TEXTURE3D, 1}, + }; + static const struct + { + DXGI_FORMAT texture_format; + UINT bind_flags; + UINT misc_flags; + BOOL null_srv; + UINT base_level; + BOOL expected_creation; + BOOL expected_mips; + } + tests[] = + { + {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, + 0, TRUE, FALSE}, + {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, 0, TRUE, + 0, TRUE, FALSE}, + {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, + 0, TRUE, FALSE}, + {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, 0, FALSE, + 0, TRUE, FALSE}, + {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE, + 0, FALSE, FALSE}, + {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE, + 0, FALSE, FALSE}, + {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE, + 0, TRUE, TRUE}, + {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE, + 1, TRUE, TRUE}, + {DXGI_FORMAT_R8G8B8A8_TYPELESS, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE, + 1, TRUE, TRUE}, + {DXGI_FORMAT_R8G8B8A8_UINT, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, TRUE, + 1, TRUE, FALSE}, + }; + static const struct + { + POINT pos; + DWORD color; + } + expected[] = + { + {{200, 200}, 0xffff0000}, + {{280, 200}, 0xffff0000}, + {{360, 200}, 0xff00ff00}, + {{440, 200}, 0xff00ff00}, + {{200, 270}, 0xff0000ff}, + {{280, 270}, 0xff0000ff}, + {{360, 270}, 0xff000000}, + {{440, 270}, 0xff000000}, + }; + static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f}; + static const RECT r1 = {8, 8, 16, 16}; + static const RECT r2 = {16, 8, 24, 16}; + static const RECT r3 = {8, 16, 16, 24}; + static const RECT r4 = {16, 16, 24, 24}; + DWORD *data, *zero_data, color, expected_color; + ID3D10ShaderResourceView *srv, *srv_sampling; + struct d3d10core_test_context test_context; + D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc; + D3D10_TEXTURE2D_DESC texture2d_desc; + D3D10_TEXTURE3D_DESC texture3d_desc; + ID3D10SamplerState *sampler_state; + D3D10_SAMPLER_DESC sampler_desc; + D3D10_BUFFER_DESC buffer_desc; + unsigned int i, j, k, x, y, z; + ID3D10PixelShader *ps, *ps_3d; + struct resource_readback rb; + ID3D10Resource *resource; + ID3D10Device *device; + HRESULT hr; + + if (!init_test_context(&test_context)) + return; + + device = test_context.device; + + hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps); + ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr); + + hr = ID3D10Device_CreatePixelShader(device, ps_code_3d, sizeof(ps_code_3d), &ps_3d); + ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr); + + sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT; + sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP; + sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP; + sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP; + sampler_desc.MipLODBias = 0.0f; + sampler_desc.MaxAnisotropy = 0; + sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER; + sampler_desc.BorderColor[0] = 0.0f; + sampler_desc.BorderColor[1] = 0.0f; + sampler_desc.BorderColor[2] = 0.0f; + sampler_desc.BorderColor[3] = 0.0f; + sampler_desc.MinLOD = 0.0f; + sampler_desc.MaxLOD = D3D10_FLOAT32_MAX; + + hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state); + ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr); + ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state); + + data = HeapAlloc(GetProcessHeap(), 0, sizeof(*data) * 32 * 32 * 32); + + for (z = 0; z < 32; ++z) + { + for (y = 0; y < 32; ++y) + { + for (x = 0; x < 32; ++x) + { + DWORD *dst = &data[z * 32 * 32 + y * 32 + x]; + POINT pt; + + pt.x = x; + pt.y = y; + if (PtInRect(&r1, pt)) + *dst = 0xffff0000; + else if (PtInRect(&r2, pt)) + *dst = 0xff00ff00; + else if (PtInRect(&r3, pt)) + *dst = 0xff0000ff; + else if (PtInRect(&r4, pt)) + *dst = 0xff000000; + else + *dst = 0xffffffff; + } + } + } + + zero_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*zero_data) * 16 * 16 * 16); + + for (i = 0; i < ARRAY_SIZE(resource_types); ++i) + { + for (j = 0; j < ARRAY_SIZE(tests); ++j) + { + unsigned int base_multiplier = 1u << tests[j].base_level; + + if (is_warp_device(device) && tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT) + { + /* Testing this format seems to break the WARP device. */ + skip("Skipping test with DXGI_FORMAT_R8G8B8A8_UINT on WARP.\n"); + continue; + } + + switch (resource_types[i].dim) + { + case D3D10_RESOURCE_DIMENSION_BUFFER: + buffer_desc.ByteWidth = 32 * base_multiplier; + buffer_desc.Usage = D3D10_USAGE_DEFAULT; + buffer_desc.BindFlags = tests[j].bind_flags; + buffer_desc.CPUAccessFlags = 0; + buffer_desc.MiscFlags = tests[j].misc_flags; + + hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, + (ID3D10Buffer **)&resource); + break; + case D3D10_RESOURCE_DIMENSION_TEXTURE2D: + texture2d_desc.Width = 32 * base_multiplier; + texture2d_desc.Height = 32 * base_multiplier; + texture2d_desc.MipLevels = 0; + texture2d_desc.ArraySize = resource_types[i].array_size; + texture2d_desc.Format = tests[j].texture_format; + texture2d_desc.SampleDesc.Count = 1; + texture2d_desc.SampleDesc.Quality = 0; + texture2d_desc.Usage = D3D10_USAGE_DEFAULT; + texture2d_desc.BindFlags = tests[j].bind_flags; + texture2d_desc.CPUAccessFlags = 0; + texture2d_desc.MiscFlags = tests[j].misc_flags; + + hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, + (ID3D10Texture2D **)&resource); + break; + case D3D10_RESOURCE_DIMENSION_TEXTURE3D: + texture3d_desc.Width = 32 * base_multiplier; + texture3d_desc.Height = 32 * base_multiplier; + texture3d_desc.Depth = 32 * base_multiplier; + texture3d_desc.MipLevels = 0; + texture3d_desc.Format = tests[j].texture_format; + texture3d_desc.Usage = D3D10_USAGE_DEFAULT; + texture3d_desc.BindFlags = tests[j].bind_flags; + texture3d_desc.CPUAccessFlags = 0; + texture3d_desc.MiscFlags = tests[j].misc_flags; + + hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, + (ID3D10Texture3D **)&resource); + break; + default: + break; + } + if (tests[j].expected_creation && (resource_types[i].dim != D3D10_RESOURCE_DIMENSION_BUFFER + || !(tests[j].misc_flags & D3D10_RESOURCE_MISC_GENERATE_MIPS))) + { + ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create resource, hr %#x.\n", i, j, hr); + } + else + { + ok(hr == E_INVALIDARG, "Resource type %u, test %u: unexpectedly succeeded " + "to create resource, hr %#x.\n", i, j, hr); + continue; + } + + if (tests[j].null_srv) + { + hr = ID3D10Device_CreateShaderResourceView(device, resource, NULL, &srv); + } + else + { + srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + srv_desc.ViewDimension = resource_types[i].srv_dim; + switch (resource_types[i].srv_dim) + { + case D3D10_SRV_DIMENSION_BUFFER: + srv_desc.Buffer.ElementOffset = 0; + srv_desc.Buffer.ElementWidth = 0; + break; + case D3D10_SRV_DIMENSION_TEXTURE2D: + srv_desc.Texture2D.MostDetailedMip = tests[j].base_level; + srv_desc.Texture2D.MipLevels = ~0u; + break; + case D3D10_SRV_DIMENSION_TEXTURE2DARRAY: + srv_desc.Texture2DArray.MostDetailedMip = tests[j].base_level; + srv_desc.Texture2DArray.MipLevels = ~0u; + srv_desc.Texture2DArray.FirstArraySlice = 0; + srv_desc.Texture2DArray.ArraySize = resource_types[i].array_size; + break; + case D3D10_SRV_DIMENSION_TEXTURE3D: + srv_desc.Texture3D.MostDetailedMip = tests[j].base_level; + srv_desc.Texture3D.MipLevels = ~0u; + break; + default: + break; + } + hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv); + } + if (resource_types[i].dim == D3D10_RESOURCE_DIMENSION_BUFFER) + { + ok(FAILED(hr), "Test %u: unexpectedly succeeded to create shader resource view, " + "hr %#x.\n", j, hr); + ID3D10Resource_Release(resource); + continue; + } + else + { + ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create " + "shader resource view, hr %#x.\n", i, j, hr); + } + + ID3D10Device_UpdateSubresource(device, resource, tests[j].base_level, + NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32); + ID3D10Device_UpdateSubresource(device, resource, tests[j].base_level + 1, + NULL, zero_data, sizeof(*zero_data) * 16, sizeof(*zero_data) * 16 * 16); + + ID3D10Device_GenerateMips(device, srv); + + ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &white.x); + + srv_desc.Format = tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT + ? DXGI_FORMAT_R8G8B8A8_UINT : DXGI_FORMAT_R8G8B8A8_UNORM; + srv_desc.ViewDimension = resource_types[i].dim == D3D10_RESOURCE_DIMENSION_TEXTURE3D + ? D3D10_SRV_DIMENSION_TEXTURE3D : D3D10_SRV_DIMENSION_TEXTURE2D; + srv_desc.Texture2D.MostDetailedMip = tests[j].base_level + 1; + srv_desc.Texture2D.MipLevels = ~0u; + hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling); + ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create shader resource view, " + "hr %#x.\n", i, j, hr); + ID3D10Device_PSSetShader(device, resource_types[i].dim + == D3D10_RESOURCE_DIMENSION_TEXTURE3D ? ps_3d : ps); + ID3D10Device_PSSetShaderResources(device, 0, 1, &srv_sampling); + + draw_quad(&test_context); + + get_texture_readback(test_context.backbuffer, 0, &rb); + for (k = 0; k < ARRAY_SIZE(expected); ++k) + { + color = get_readback_color(&rb, expected[k].pos.x, expected[k].pos.y); + expected_color = tests[j].expected_mips ? expected[k].color : 0; + ok(color == expected_color, "Resource type %u, test %u: pixel (%u, %u) " + "has color %08x, expected %08x.\n", + i, j, expected[k].pos.x, expected[k].pos.y, color, expected_color); + } + release_resource_readback(&rb); + + ID3D10ShaderResourceView_Release(srv_sampling); + ID3D10ShaderResourceView_Release(srv); + ID3D10Resource_Release(resource); + } + } + + /* Test the effect of sRGB views. */ + for (y = 0; y < 32; ++y) + { + for (x = 0; x < 32; ++x) + { + DWORD *dst = &data[y * 32 + x]; + + *dst = (x + y) % 2 * 0xffffffff; + } + } + texture2d_desc.Width = 32; + texture2d_desc.Height = 32; + texture2d_desc.MipLevels = 0; + texture2d_desc.ArraySize = 1; + texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS; + texture2d_desc.SampleDesc.Count = 1; + texture2d_desc.SampleDesc.Quality = 0; + texture2d_desc.Usage = D3D10_USAGE_DEFAULT; + texture2d_desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE; + texture2d_desc.CPUAccessFlags = 0; + texture2d_desc.MiscFlags = D3D10_RESOURCE_MISC_GENERATE_MIPS; + + hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, (ID3D10Texture2D **)&resource); + ok(SUCCEEDED(hr), "Failed to create resource, hr %#x.\n", hr); + hr = ID3D10Device_CreateShaderResourceView(device, resource, NULL, &srv); + ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr); + srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; + srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; + srv_desc.Texture2D.MostDetailedMip = 0; + srv_desc.Texture2D.MipLevels = ~0u; + hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv); + ID3D10Device_UpdateSubresource(device, resource, + 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32); + + ID3D10Device_GenerateMips(device, srv); + + ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &white.w); + + srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; + srv_desc.Texture2D.MostDetailedMip = 1; + srv_desc.Texture2D.MipLevels = ~0u; + hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling); + ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr); + ID3D10Device_PSSetShader(device, ps); + ID3D10Device_PSSetShaderResources(device, 0, 1, &srv_sampling); + + draw_quad(&test_context); + + get_texture_readback(test_context.backbuffer, 0, &rb); + color = get_readback_color(&rb, 320, 240); + ok(compare_color(color, 0x7fbcbcbc, 1) || broken(compare_color(color, 0x7f7f7f7f, 1)), /* AMD */ + "Unexpected color %08x.\n", color); + release_resource_readback(&rb); + + ID3D10ShaderResourceView_Release(srv_sampling); + ID3D10ShaderResourceView_Release(srv); + + srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; + srv_desc.Texture2D.MostDetailedMip = 0; + srv_desc.Texture2D.MipLevels = ~0u; + hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv); + ID3D10Device_UpdateSubresource(device, resource, + 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32); + + ID3D10Device_GenerateMips(device, srv); + + ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &white.w); + + srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; + srv_desc.Texture2D.MostDetailedMip = 1; + srv_desc.Texture2D.MipLevels = ~0u; + hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling); + ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr); + ID3D10Device_PSSetShader(device, ps); + ID3D10Device_PSSetShaderResources(device, 0, 1, &srv_sampling); + + draw_quad(&test_context); + + get_texture_readback(test_context.backbuffer, 0, &rb); + check_readback_data_color(&rb, NULL, 0x7f7f7f7f, 1); + release_resource_readback(&rb); + + ID3D10ShaderResourceView_Release(srv_sampling); + ID3D10ShaderResourceView_Release(srv); + + ID3D10Resource_Release(resource); + + HeapFree(GetProcessHeap(), 0, data); + + ID3D10SamplerState_Release(sampler_state); + ID3D10PixelShader_Release(ps_3d); + ID3D10PixelShader_Release(ps); + release_test_context(&test_context); +} + START_TEST(device) { test_feature_level(); @@ -13230,4 +13682,5 @@ START_TEST(device) test_stream_output(); test_stream_output_resume(); test_format_compatibility(); + test_generate_mips(); }
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=34695
Your paranoid android.
=== wvistau64 (32 bit device) === 00c4:device: unhandled exception c0000005 at 73E3ECF4
=== w2008s64 (32 bit device) === 07ec:device: unhandled exception c0000005 at 747FECF4