Signed-off-by: Henri Verbeet hverbeet@codeweavers.com --- dlls/d3d10core/tests/device.c | 136 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+)
diff --git a/dlls/d3d10core/tests/device.c b/dlls/d3d10core/tests/device.c index 4228773..cdac5ec 100644 --- a/dlls/d3d10core/tests/device.c +++ b/dlls/d3d10core/tests/device.c @@ -13021,6 +13021,141 @@ static void test_stream_output_resume(void) release_test_context(&test_context); }
+static void test_format_compatibility(void) +{ + ID3D10Texture2D *dst_texture, *src_texture; + D3D10_SUBRESOURCE_DATA resource_data; + D3D10_TEXTURE2D_DESC texture_desc; + struct resource_readback rb; + DWORD colour, expected; + ID3D10Device *device; + unsigned int i, j; + ULONG refcount; + HRESULT hr; + + static const struct + { + DXGI_FORMAT src_format; + DXGI_FORMAT dst_format; + size_t texel_size; + BOOL success; + } + test_data[] = + { + {DXGI_FORMAT_R8G8B8A8_TYPELESS, DXGI_FORMAT_R8G8B8A8_UNORM, 4, TRUE}, + {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 4, TRUE}, + {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UINT, 4, TRUE}, + {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_SNORM, 4, TRUE}, + {DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SINT, 4, TRUE}, + {DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, TRUE}, + {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, 4, FALSE}, + {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R16G16_UINT, 4, FALSE}, + {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R16G16_FLOAT, 4, TRUE}, + {DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_UNORM, 4, TRUE}, + {DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_UINT, 4, TRUE}, + {DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_SNORM, 4, TRUE}, + {DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_R16G16_SINT, 4, TRUE}, + {DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_TYPELESS, 4, TRUE}, + {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R32_TYPELESS, 4, FALSE}, + {DXGI_FORMAT_R32G32_TYPELESS, DXGI_FORMAT_R32G32_FLOAT, 8, TRUE}, + {DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_UINT, 8, TRUE}, + {DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_SINT, 8, TRUE}, + {DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_TYPELESS, 8, TRUE}, + }; + static const DWORD initial_data[16] = {0}; + static const DWORD bitmap_data[] = + { + 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00, + 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f, + 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000, + 0xffffffff, 0xff000000, 0xff000000, 0xff000000, + }; + + if (!(device = create_device())) + { + skip("Failed to create device.\n"); + return; + } + + texture_desc.Height = 4; + texture_desc.MipLevels = 1; + texture_desc.ArraySize = 1; + texture_desc.SampleDesc.Count = 1; + texture_desc.SampleDesc.Quality = 0; + texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE; + texture_desc.CPUAccessFlags = 0; + texture_desc.MiscFlags = 0; + + for (i = 0; i < ARRAY_SIZE(test_data); ++i) + { + unsigned int x, y, texel_dwords; + D3D10_BOX box; + + texture_desc.Width = sizeof(bitmap_data) / (texture_desc.Height * test_data[i].texel_size); + texture_desc.Format = test_data[i].src_format; + texture_desc.Usage = D3D10_USAGE_IMMUTABLE; + + resource_data.pSysMem = bitmap_data; + resource_data.SysMemPitch = texture_desc.Width * test_data[i].texel_size; + resource_data.SysMemSlicePitch = 0; + + hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture); + ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr); + + texture_desc.Format = test_data[i].dst_format; + texture_desc.Usage = D3D10_USAGE_DEFAULT; + + resource_data.pSysMem = initial_data; + + hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture); + if (FAILED(hr) && test_data[i].dst_format == DXGI_FORMAT_B8G8R8A8_UNORM) + { + skip("B8G8R8A8_UNORM not supported, skipping test.\n"); + ID3D10Texture2D_Release(src_texture); + continue; + } + ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr); + + set_box(&box, 0, 0, 0, texture_desc.Width - 1, texture_desc.Height - 1, 1); + ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0, 1, 1, 0, + (ID3D10Resource *)src_texture, 0, &box); + + texel_dwords = test_data[i].texel_size / sizeof(DWORD); + get_texture_readback(dst_texture, 0, &rb); + for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j) + { + x = j % 4; + y = j / 4; + colour = get_readback_color(&rb, x, y); + expected = test_data[i].success && x >= texel_dwords && y + ? bitmap_data[j - (4 + texel_dwords)] : initial_data[j]; + ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n", + i, colour, x, y, expected); + } + release_resource_readback(&rb); + + ID3D10Device_CopyResource(device, (ID3D10Resource *)dst_texture, (ID3D10Resource *)src_texture); + + get_texture_readback(dst_texture, 0, &rb); + for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j) + { + x = j % 4; + y = j / 4; + colour = get_readback_color(&rb, x, y); + expected = test_data[i].success ? bitmap_data[j] : initial_data[j]; + ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n", + i, colour, x, y, expected); + } + release_resource_readback(&rb); + + ID3D10Texture2D_Release(dst_texture); + ID3D10Texture2D_Release(src_texture); + } + + refcount = ID3D10Device_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); +} + START_TEST(device) { test_feature_level(); @@ -13094,4 +13229,5 @@ START_TEST(device) test_geometry_shader(); test_stream_output(); test_stream_output_resume(); + test_format_compatibility(); }