Module: wine Branch: master Commit: 930d43be08d9d9bdc1092cf094c927494bd6d9a2 URL: http://source.winehq.org/git/wine.git/?a=commit;h=930d43be08d9d9bdc1092cf094...
Author: Stefan Dösinger stefan@codeweavers.com Date: Tue Aug 27 12:36:23 2013 +0200
d3d8/tests: Add UpdateTexture tests with volumes.
---
dlls/d3d8/tests/device.c | 157 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 157 insertions(+), 0 deletions(-)
diff --git a/dlls/d3d8/tests/device.c b/dlls/d3d8/tests/device.c index a48982e..bf83be2 100644 --- a/dlls/d3d8/tests/device.c +++ b/dlls/d3d8/tests/device.c @@ -4975,6 +4975,162 @@ out: DestroyWindow(window); }
+static void test_update_volumetexture(void) +{ + IDirect3DDevice8 *device; + IDirect3D8 *d3d8; + HWND window; + HRESULT hr; + IDirect3DVolumeTexture8 *src, *dst; + unsigned int i; + D3DLOCKED_BOX locked_box; + ULONG refcount; + D3DCAPS8 caps; + static const struct + { + D3DPOOL src_pool, dst_pool; + HRESULT hr; + } + tests[] = + { + { D3DPOOL_DEFAULT, D3DPOOL_DEFAULT, D3DERR_INVALIDCALL }, + { D3DPOOL_MANAGED, D3DPOOL_DEFAULT, D3DERR_INVALIDCALL }, + { D3DPOOL_SYSTEMMEM, D3DPOOL_DEFAULT, D3D_OK }, + { D3DPOOL_SCRATCH, D3DPOOL_DEFAULT, D3DERR_INVALIDCALL }, + + { D3DPOOL_DEFAULT, D3DPOOL_MANAGED, D3DERR_INVALIDCALL }, + { D3DPOOL_MANAGED, D3DPOOL_MANAGED, D3DERR_INVALIDCALL }, + { D3DPOOL_SYSTEMMEM, D3DPOOL_MANAGED, D3DERR_INVALIDCALL }, + { D3DPOOL_SCRATCH, D3DPOOL_MANAGED, D3DERR_INVALIDCALL }, + + { D3DPOOL_DEFAULT, D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL }, + { D3DPOOL_MANAGED, D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL }, + { D3DPOOL_SYSTEMMEM, D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL }, + { D3DPOOL_SCRATCH, D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL }, + + { D3DPOOL_DEFAULT, D3DPOOL_SCRATCH, D3DERR_INVALIDCALL }, + { D3DPOOL_MANAGED, D3DPOOL_SCRATCH, D3DERR_INVALIDCALL }, + { D3DPOOL_SYSTEMMEM, D3DPOOL_SCRATCH, D3DERR_INVALIDCALL }, + { D3DPOOL_SCRATCH, D3DPOOL_SCRATCH, D3DERR_INVALIDCALL }, + }; + static const struct + { + UINT src_size, dst_size; + UINT src_lvl, dst_lvl; + D3DFORMAT src_fmt, dst_fmt; + } + tests2[] = + { + { 8, 8, 0, 0, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, + { 8, 8, 4, 4, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, + { 8, 8, 2, 2, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, + { 8, 8, 1, 1, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, + { 8, 8, 4, 0, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, + { 8, 8, 1, 4, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, /* Different level count */ + { 4, 8, 1, 1, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, /* Different size */ + { 8, 8, 4, 4, D3DFMT_A8R8G8B8, D3DFMT_X8R8G8B8 }, /* Different format */ + }; + + if (!(d3d8 = pDirect3DCreate8(D3D_SDK_VERSION))) + { + skip("Failed to create IDirect3D8 object, skipping tests.\n"); + return; + } + + window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, 0, 0, 0, 0); + if (!(device = create_device(d3d8, window, window, TRUE))) + { + skip("Failed to create a D3D device, skipping tests.\n"); + IDirect3D8_Release(d3d8); + DestroyWindow(window); + return; + } + + hr = IDirect3DDevice8_GetDeviceCaps(device, &caps); + ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr); + if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)) + { + skip("Volume textures not supported, skipping test.\n"); + goto out; + } + + for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) + { + DWORD src_usage = tests[i].src_pool == D3DPOOL_DEFAULT ? D3DUSAGE_DYNAMIC : 0; + DWORD dst_usage = tests[i].dst_pool == D3DPOOL_DEFAULT ? D3DUSAGE_DYNAMIC : 0; + + hr = IDirect3DDevice8_CreateVolumeTexture(device, 1, 1, 1, 1, src_usage, + D3DFMT_A8R8G8B8, tests[i].src_pool, &src); + ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr); + hr = IDirect3DDevice8_CreateVolumeTexture(device, 1, 1, 1, 1, dst_usage, + D3DFMT_A8R8G8B8, tests[i].dst_pool, &dst); + ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr); + + hr = IDirect3DVolumeTexture8_LockBox(src, 0, &locked_box, NULL, 0); + ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr); + *((DWORD *)locked_box.pBits) = 0x11223344; + hr = IDirect3DVolumeTexture8_UnlockBox(src, 0); + ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr); + + hr = IDirect3DDevice8_UpdateTexture(device, (IDirect3DBaseTexture8 *)src, (IDirect3DBaseTexture8 *)dst); + ok(hr == tests[i].hr, "UpdateTexture returned %#x, expected %#x, src pool %x, dst pool %u.\n", + hr, tests[i].hr, tests[i].src_pool, tests[i].dst_pool); + + if (SUCCEEDED(hr)) + { + DWORD content = *((DWORD *)locked_box.pBits); + hr = IDirect3DVolumeTexture8_LockBox(dst, 0, &locked_box, NULL, 0); + ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr); + ok(content == 0x11223344, "Dest texture contained %#x, expected 0x11223344.\n", content); + hr = IDirect3DVolumeTexture8_UnlockBox(dst, 0); + ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr); + } + IDirect3DVolumeTexture8_Release(src); + IDirect3DVolumeTexture8_Release(dst); + } + + if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP)) + { + skip("Mipmapped volume maps not supported.\n"); + goto out; + } + + for (i = 0; i < sizeof(tests2) / sizeof(*tests2); i++) + { + hr = IDirect3DDevice8_CreateVolumeTexture(device, + tests2[i].src_size, tests2[i].src_size, tests2[i].src_size, + tests2[i].src_lvl, 0, tests2[i].src_fmt, D3DPOOL_SYSTEMMEM, &src); + ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x, case %u.\n", hr, i); + hr = IDirect3DDevice8_CreateVolumeTexture(device, + tests2[i].dst_size, tests2[i].dst_size, tests2[i].dst_size, + tests2[i].dst_lvl, 0, tests2[i].dst_fmt, D3DPOOL_DEFAULT, &dst); + ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x, case %u.\n", hr, i); + + hr = IDirect3DDevice8_UpdateTexture(device, (IDirect3DBaseTexture8 *)src, (IDirect3DBaseTexture8 *)dst); + if (FAILED(hr)) + todo_wine ok(SUCCEEDED(hr), "Failed to update texture, hr %#x, case %u.\n", hr, i); + else + ok(SUCCEEDED(hr), "Failed to update texture, hr %#x, case %u.\n", hr, i); + + IDirect3DVolumeTexture8_Release(src); + IDirect3DVolumeTexture8_Release(dst); + } + + /* As far as I can see, UpdateTexture on non-matching texture behaves like a memcpy. The raw data + * stays the same in a format change, a 2x2x1 texture is copied into the first row of a 4x4x1 texture, + * etc. I could not get it to segfault, but the nonexistent 5th pixel of a 2x2x1 texture is copied into + * pixel 1x2x1 of a 4x4x1 texture, demonstrating a read beyond the texture's end. I suspect any bad + * memory access is silently ignored by the runtime, in the kernel or on the GPU. + * + * I'm not adding tests for this behavior until an application needs it. */ + +out: + refcount = IDirect3DDevice8_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); + IDirect3D8_Release(d3d8); + DestroyWindow(window); +} START_TEST(device) { HMODULE d3d8_handle = LoadLibraryA( "d3d8.dll" ); @@ -5053,6 +5209,7 @@ START_TEST(device) test_rtpatch(); test_npot_textures(); test_volume_locking(); + test_update_volumetexture(); } UnregisterClassA("d3d8_test_wc", GetModuleHandleA(NULL)); }