From: Józef Kucia Subject: [PATCH 2/7] d3d10core/tests: Add test for some shader instructions. Message-Id: <1469022584-26889-2-git-send-email-jkucia@codeweavers.com> Date: Wed, 20 Jul 2016 15:49:39 +0200 In-Reply-To: <1469022584-26889-1-git-send-email-jkucia@codeweavers.com> References: <1469022584-26889-1-git-send-email-jkucia@codeweavers.com> Signed-off-by: Józef Kucia --- dlls/d3d10core/tests/device.c | 183 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 171 insertions(+), 12 deletions(-) diff --git a/dlls/d3d10core/tests/device.c b/dlls/d3d10core/tests/device.c index 7e161f5..90f8797 100644 --- a/dlls/d3d10core/tests/device.c +++ b/dlls/d3d10core/tests/device.c @@ -23,6 +23,13 @@ #include "wine/test.h" #include +#define BITS_NNAN 0xffc00000 +#define BITS_NAN 0x7fc00000 +#define BITS_NINF 0xff800000 +#define BITS_INF 0x7f800000 +#define BITS_N1_0 0xbf800000 +#define BITS_1_0 0x3f800000 + struct vec2 { float x, y; @@ -670,6 +677,52 @@ static void check_texture_vec4_(unsigned int line, ID3D10Texture2D *texture, check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, expected_value, max_diff); } +#define check_texture_sub_resource_uvec4(a, b, c) check_texture_sub_resource_uvec4_(__LINE__, a, b, c) +static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D10Texture2D *texture, + unsigned int sub_resource_idx, const struct uvec4 *expected_value) +{ + struct texture_readback rb; + unsigned int x = 0, y = 0; + struct uvec4 value = {0}; + BOOL all_match = TRUE; + + get_texture_readback(texture, sub_resource_idx, &rb); + for (y = 0; y < rb.height; ++y) + { + for (x = 0; x < rb.width; ++x) + { + value = *get_readback_uvec4(&rb, x, y); + if (!compare_uvec4(&value, expected_value)) + { + all_match = FALSE; + break; + } + } + if (!all_match) + break; + } + release_texture_readback(&rb); + ok_(__FILE__, line)(all_match, + "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} " + "at (%u, %u), sub-resource %u.\n", + value.x, value.y, value.z, value.w, + expected_value->x, expected_value->y, expected_value->z, expected_value->w, + x, y, sub_resource_idx); +} + +#define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b) +static void check_texture_uvec4_(unsigned int line, ID3D10Texture2D *texture, + const struct uvec4 *expected_value) +{ + unsigned int sub_resource_idx, sub_resource_count; + D3D10_TEXTURE2D_DESC texture_desc; + + ID3D10Texture2D_GetDesc(texture, &texture_desc); + sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels; + for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx) + check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, expected_value); +} + static ID3D10Device *create_device(void) { ID3D10Device *device; @@ -8621,11 +8674,9 @@ static void test_fp_specials(void) struct d3d10core_test_context test_context; D3D10_TEXTURE2D_DESC texture_desc; ID3D10RenderTargetView *rtv; - struct texture_readback rb; ID3D10Texture2D *texture; ID3D10PixelShader *ps; ID3D10Device *device; - unsigned int x, y; HRESULT hr; static const DWORD ps_code[] = @@ -8643,7 +8694,7 @@ static void test_fp_specials(void) 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000, 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e, }; - const struct uvec4 expected_result = {0xffc00000, 0x7f800000, 0xff800000, 0x3f800000}; + static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0}; if (!init_test_context(&test_context)) return; @@ -8665,20 +8716,127 @@ static void test_fp_specials(void) ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL); draw_quad(&test_context); - get_texture_readback(texture, 0, &rb); - for (y = 0; y < texture_desc.Height; ++y) + check_texture_uvec4(texture, &expected_result); + + ID3D10PixelShader_Release(ps); + ID3D10Texture2D_Release(texture); + ID3D10RenderTargetView_Release(rtv); + release_test_context(&test_context); +} + +static void test_uint_shader_instructions(void) +{ + struct shader + { + const DWORD *code; + size_t size; + }; + + struct d3d10core_test_context test_context; + D3D10_TEXTURE2D_DESC texture_desc; + ID3D10RenderTargetView *rtv; + ID3D10Texture2D *texture; + ID3D10PixelShader *ps; + ID3D10Device *device; + ID3D10Buffer *cb; + unsigned int i; + HRESULT hr; + + static const DWORD ps_ftou_code[] = { - for (x = 0; x < texture_desc.Width; ++x) +#if 0 + float f; + + uint4 main() : SV_Target { - const struct uvec4 *value = get_readback_uvec4(&rb, x, y); - ok(compare_uvec4(value, &expected_result), - "Got unexpected value {0x%08x, 0x%08x, 0x%08x, 0x%08x} at (%u, %u).\n", - value->x, value->y, value->z, value->w, x, y); + return uint4(f, -f, 0, 0); } +#endif + 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003, + 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000, + 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f, + 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c, + 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000, + 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e, + }; + static const DWORD ps_not_code[] = + { +#if 0 + uint bits[2]; + + uint4 main() : SV_Target + { + return uint4(~bits[0], ~(bits[0] ^ ~0u), ~bits[1], ~(bits[1] ^ ~0u)); + } +#endif + 0x43425844, 0x1d56b429, 0xb5f4c0e1, 0x496a0bfd, 0xfc6f8e6f, 0x00000001, 0x00000140, 0x00000003, + 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000, + 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040, 0x00000032, + 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, + 0x00000001, 0x08000057, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, + 0xffffffff, 0x0500003b, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x08000057, 0x00100012, + 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x00004001, 0xffffffff, 0x0500003b, 0x00102082, + 0x00000000, 0x0010000a, 0x00000000, 0x0600003b, 0x00102012, 0x00000000, 0x0020800a, 0x00000000, + 0x00000000, 0x0600003b, 0x00102042, 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x0100003e, + }; + static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code)}; + static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code)}; + static const struct + { + const struct shader *ps; + unsigned int bits[4]; + struct uvec4 expected_result; + BOOL todo; } - release_texture_readback(&rb); + tests[] = + { + {&ps_ftou, {BITS_NNAN}, { 0, 0}}, + {&ps_ftou, {BITS_NAN}, { 0, 0}}, + {&ps_ftou, {BITS_NINF}, { 0, ~0u}}, + {&ps_ftou, {BITS_INF}, {~0u, 0}}, + {&ps_ftou, {BITS_N1_0}, { 0, 1}}, + {&ps_ftou, {BITS_1_0}, { 1, 0}}, + {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}}, + {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}}, + }; - ID3D10PixelShader_Release(ps); + if (!init_test_context(&test_context)) + return; + + device = test_context.device; + + cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, 4 * sizeof(tests[0].bits), NULL); + ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb); + + ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc); + texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT; + hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture); + ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr); + + hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv); + ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr); + + ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL); + + for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i) + { + hr = ID3D10Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, &ps); + ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr); + ID3D10Device_PSSetShader(device, ps); + + ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, tests[i].bits, 0, 0); + + draw_quad(&test_context); + todo_wine_if(tests[i].todo) + check_texture_uvec4(texture, &tests[i].expected_result); + + ID3D10PixelShader_Release(ps); + } + + ID3D10Buffer_Release(cb); ID3D10Texture2D_Release(texture); ID3D10RenderTargetView_Release(rtv); release_test_context(&test_context); @@ -8730,4 +8888,5 @@ START_TEST(device) test_null_sampler(); test_immediate_constant_buffer(); test_fp_specials(); + test_uint_shader_instructions(); } -- 2.7.3