Signed-off-by: Jan Sikorski jsikorski@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 6cdac34c0cd..944e4d2ef57 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -204,6 +204,12 @@ static void set_box(D3D11_BOX *box, UINT left, UINT top, UINT front, UINT right, box->back = back; }
+static BOOL is_inside_box(D3D11_BOX *box, UINT x, UINT y, UINT z) +{ + return x >= box->left && x < box->right && y >= box->top && y < box->bottom + && z >= box->front && z < box->back; +} + static ULONG get_refcount(void *iface) { IUnknown *unknown = iface; @@ -13832,6 +13838,121 @@ static void test_update_subresource(void) release_test_context(&test_context); }
+static void test_update_subresource_3d(void) +{ + int x, y, z, left, right, top, bottom, front, back, i; + struct d3d11_test_context test_context; + D3D11_TEXTURE3D_DESC texture_desc; + ID3D11DeviceContext *context; + struct resource_readback rb; + DWORD color, expected_color; + ID3D11Texture3D *texture; + D3D11_BOX box, clear_box; + ID3D11Device *device; + HRESULT hr; + + static const DWORD black_data[3 * 3 * 3] = {0}; + + static const DWORD color_data_packed[] = + { + 0xff000000, 0x0ff00000, 0x00ff0000, + 0x000ff000, 0x0000ff00, 0x00000ff0, + 0x000000ff, 0xf0000000, 0x0f000000, + + 0x00f00000, 0x000f0000, 0x0000f000, + 0x00000f00, 0x000000f0, 0x0000000f, + 0xfff00000, 0x0fff0000, 0x00fff000, + + 0x000fff00, 0x0000fff0, 0x00000fff, + 0xffff0000, 0x0ffff000, 0x00ffff00, + 0x000ffff0, 0x0000ffff, 0xfffff000, + }; + + static const DWORD color_data_with_junk[] = + { + 0xff000000, 0x0ff00000, 0x00ff0000, + 0x000ff000, 0x0000ff00, 0x00000ff0, + 0x000000ff, 0xf0000000, 0x0f000000, + 0xdead1111, /* Junk between slices */ + 0x00f00000, 0x000f0000, 0x0000f000, + 0x00000f00, 0x000000f0, 0x0000000f, + 0xfff00000, 0x0fff0000, 0x00fff000, + 0xdead2222, /* Junk between slices */ + 0x000fff00, 0x0000fff0, 0x00000fff, + 0xffff0000, 0x0ffff000, 0x00ffff00, + 0x000ffff0, 0x0000ffff, 0xfffff000, + }; + + static const DWORD *color_data_array[] = {color_data_packed, color_data_with_junk}; + static const unsigned int slice_pitches[] = {9, 10}; + + if (!init_test_context(&test_context, NULL)) + return; + + device = test_context.device; + context = test_context.immediate_context; + + texture_desc.Width = 3; + texture_desc.Height = 3; + texture_desc.Depth = 3; + texture_desc.MipLevels = 1; + texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + texture_desc.Usage = D3D11_USAGE_DEFAULT; + texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + texture_desc.CPUAccessFlags = 0; + texture_desc.MiscFlags = 0; + + set_box(&clear_box, 0, 0, 0, 3, 3, 3); + + hr = ID3D11Device_CreateTexture3D(device, &texture_desc, NULL, &texture); + ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(color_data_array); ++i) + { + const DWORD *color_data = color_data_array[i]; + unsigned int slice_pitch = slice_pitches[i]; + + for (left = 0; left < 3; ++left) + for (right = left + 1; right <= 3; ++right) + for (top = 0; top < 3; ++top) + for (bottom = top + 1; bottom <= 3; ++bottom) + for (front = 0; front < 3; ++front) + for (back = front + 1; back <= 3; ++back) + { + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &clear_box, + black_data, 0, 0); + + set_box(&box, left, top, front, right, bottom, back); + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box, + color_data + left + 3 * top + slice_pitch * front, 3 * sizeof(*color_data), + slice_pitch * sizeof(*color_data)); + + get_texture3d_readback(texture, 0, &rb); + + for (z = 0; z < 3; ++z) + { + for (y = 0; y < 3; ++y) + { + for (x = 0; x < 3; ++x) + { + color = get_readback_color(&rb, x, y, z); + expected_color = 0; + if (is_inside_box(&box, x, y, z)) + expected_color = color_data[x + 3 * y + slice_pitch * z]; + ok(compare_uint(color, expected_color, 0), "Box (%d,%d,%d)-(%d,%d,%d): Expected %x, got %x at %d %d %d.\n", + left, top, front, right, bottom, back, expected_color, color, x, y, z); + } + } + } + + release_resource_readback(&rb); + } + } + + ID3D11Texture3D_Release(texture); + release_test_context(&test_context); +} + static void test_copy_subresource_region(void) { ID3D11Texture2D *dst_texture, *src_texture; @@ -32197,6 +32318,7 @@ START_TEST(d3d11) queue_test(test_fragment_coords); queue_test(test_initial_texture_data); queue_test(test_update_subresource); + queue_test(test_update_subresource_3d); queue_test(test_copy_subresource_region); queue_test(test_copy_subresource_region_1d); queue_test(test_copy_subresource_region_3d);