diff --git a/dlls/d3d10core/tests/device.c b/dlls/d3d10core/tests/device.c index e2893290637..fda0c64b644 100644 --- a/dlls/d3d10core/tests/device.c +++ b/dlls/d3d10core/tests/device.c @@ -6110,6 +6110,206 @@ static void test_texture(void) release_test_context(&test_context); } +static void test_cube_maps(void) +{ + unsigned int i, j, sub_resource_idx, sub_resource_count; + struct d3d10core_test_context test_context; + D3D10_TEXTURE2D_DESC texture_desc; + ID3D10ShaderResourceView *srv; + ID3D10Texture2D *rtv_texture; + ID3D10RenderTargetView *rtv; + struct vec4 expected_result; + ID3D10Resource *texture; + ID3D10PixelShader *ps; + ID3D10Device *device; + float data[64 * 64]; + ID3D10Buffer *cb; + HRESULT hr; + RECT rect; + struct + { + unsigned int face; + unsigned int level; + unsigned int padding[2]; + } constant; + + static const DWORD ps_cube_code[] = + { +#if 0 + TextureCube t; + SamplerState s; + + uint face; + uint level; + + float4 main(float4 position : SV_POSITION) : SV_Target + { + float2 p; + p.x = position.x / 640.0f; + p.y = position.y / 480.0f; + + float3 coord; + switch (face) + { + case 0: + coord = float3(1.0f, p.x, p.y); + break; + case 1: + coord = float3(-1.0f, p.x, p.y); + break; + case 2: + coord = float3(p.x, 1.0f, p.y); + break; + case 3: + coord = float3(p.x, -1.0f, p.y); + break; + case 4: + coord = float3(p.x, p.y, 1.0f); + break; + case 5: + default: + coord = float3(p.x, p.y, -1.0f); + break; + } + return t.SampleLevel(s, coord, level); + } +#endif + 0x43425844, 0x039aee18, 0xfd630453, 0xb884cf0f, 0x10100744, 0x00000001, 0x00000310, 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, 0x00000274, 0x00000040, + 0x0000009d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000, + 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, + 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400004c, 0x0020800a, 0x00000000, + 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001, + 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000, + 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036, + 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, + 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, + 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002, + 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, + 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000, + 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, + 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004, + 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, + 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002, + 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, + 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000, + 0x01000002, 0x01000017, 0x06000056, 0x00100082, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, + 0x0b000048, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, + 0x00000000, 0x0010003a, 0x00000000, 0x0100003e, + }; + static const struct test + { + unsigned int miplevel_count; + unsigned int array_size; + } + tests[] = + { + {1, 6}, + {2, 6}, + {3, 6}, + {0, 0}, + }; + + if (!init_test_context(&test_context)) + return; + + device = test_context.device; + + ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc); + texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; + hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture); + ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr); + hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rtv_texture, NULL, &rtv); + ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr); + + memset(&constant, 0, sizeof(constant)); + cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant); + + ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL); + ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb); + + hr = ID3D10Device_CreatePixelShader(device, ps_cube_code, sizeof(ps_cube_code), &ps); + ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr); + ID3D10Device_PSSetShader(device, ps); + + for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i) + { + const struct test *test = &tests[i]; + + if (!test->miplevel_count) + { + srv = NULL; + ID3D10Device_PSSetShaderResources(device, 0, 1, &srv); + + memset(&expected_result, 0, sizeof(expected_result)); + + memset(&constant, 0, sizeof(constant)); + ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0); + draw_quad(&test_context); + check_texture_vec4(rtv_texture, &expected_result, 0); + constant.level = 1; + ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0); + draw_quad(&test_context); + check_texture_vec4(rtv_texture, &expected_result, 0); + continue; + } + + texture_desc.Width = 64; + texture_desc.Height = 64; + texture_desc.MipLevels = test->miplevel_count; + texture_desc.ArraySize = test->array_size; + texture_desc.Format = DXGI_FORMAT_R32_FLOAT; + texture_desc.SampleDesc.Count = 1; + texture_desc.SampleDesc.Quality = 0; + texture_desc.Usage = D3D10_USAGE_DEFAULT; + texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE; + texture_desc.CPUAccessFlags = 0; + texture_desc.MiscFlags = D3D10_RESOURCE_MISC_TEXTURECUBE; + hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D10Texture2D **)&texture); + ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr); + + hr = ID3D10Device_CreateShaderResourceView(device, texture, NULL, &srv); + ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr); + ID3D10Device_PSSetShaderResources(device, 0, 1, &srv); + + sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize; + for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx) + { + for (j = 0; j < sizeof(data) / sizeof(*data); ++j) + data[j] = sub_resource_idx; + ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, sub_resource_idx, NULL, + data, texture_desc.Width * sizeof(*data), 0); + } + + expected_result.y = expected_result.z = 0.0f; + expected_result.w = 1.0f; + for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx) + { + constant.face = (sub_resource_idx / texture_desc.MipLevels) % 6; + constant.level = sub_resource_idx % texture_desc.MipLevels; + ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0); + + draw_quad(&test_context); + expected_result.x = sub_resource_idx; + /* Avoid testing values affected by seamless cube map filtering. */ + SetRect(&rect, 100, 100, 540, 380); + check_texture_sub_resource_vec4(rtv_texture, 0, &rect, &expected_result, 0); + } + + ID3D10Resource_Release(texture); + ID3D10ShaderResourceView_Release(srv); + } + + ID3D10Buffer_Release(cb); + ID3D10PixelShader_Release(ps); + ID3D10RenderTargetView_Release(rtv); + ID3D10Texture2D_Release(rtv_texture); + release_test_context(&test_context); +} + static void test_depth_stencil_sampling(void) { ID3D10PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil; @@ -11296,6 +11496,7 @@ START_TEST(device) test_clear_state(); test_blend(); test_texture(); + test_cube_maps(); test_depth_stencil_sampling(); test_multiple_render_targets(); test_private_data();