Signed-off-by: Jan Sikorski jsikorski@codeweavers.com --- dlls/d3d10core/tests/d3d10core.c | 81 ++++++++++++++++++++++++++------ 1 file changed, 67 insertions(+), 14 deletions(-)
diff --git a/dlls/d3d10core/tests/d3d10core.c b/dlls/d3d10core/tests/d3d10core.c index b2a2e2028f2..09279f5fc62 100644 --- a/dlls/d3d10core/tests/d3d10core.c +++ b/dlls/d3d10core/tests/d3d10core.c @@ -594,8 +594,8 @@ struct resource_readback { D3D10_RESOURCE_DIMENSION dimension; ID3D10Resource *resource; - D3D10_MAPPED_TEXTURE2D map_desc; - unsigned int width, height, sub_resource_idx; + D3D10_MAPPED_TEXTURE3D map_desc; + unsigned int width, height, depth, sub_resource_idx; };
static void get_buffer_readback(ID3D10Buffer *buffer, struct resource_readback *rb) @@ -623,6 +623,7 @@ static void get_buffer_readback(ID3D10Buffer *buffer, struct resource_readback *
rb->width = buffer_desc.ByteWidth; rb->height = 1; + rb->depth = 1; rb->sub_resource_idx = 0;
ID3D10Device_CopyResource(device, rb->resource, (ID3D10Resource *)buffer); @@ -633,6 +634,7 @@ static void get_buffer_readback(ID3D10Buffer *buffer, struct resource_readback * rb->resource = NULL; } rb->map_desc.RowPitch = 0; + rb->map_desc.DepthPitch = 0;
ID3D10Device_Release(device); } @@ -665,6 +667,7 @@ static void get_texture1d_readback(ID3D10Texture1D *texture, unsigned int sub_re miplevel = sub_resource_idx % texture_desc.MipLevels; rb->width = max(1, texture_desc.Width >> miplevel); rb->height = 1; + rb->depth = 1; rb->sub_resource_idx = sub_resource_idx;
ID3D10Device_CopyResource(device, rb->resource, (ID3D10Resource *)texture); @@ -676,6 +679,7 @@ static void get_texture1d_readback(ID3D10Texture1D *texture, unsigned int sub_re rb->resource = NULL; } rb->map_desc.RowPitch = 0; + rb->map_desc.DepthPitch = 0;
ID3D10Device_Release(device); } @@ -708,10 +712,55 @@ static void get_texture_readback(ID3D10Texture2D *texture, unsigned int sub_reso miplevel = sub_resource_idx % texture_desc.MipLevels; rb->width = max(1, texture_desc.Width >> miplevel); rb->height = max(1, texture_desc.Height >> miplevel); + rb->depth = 1; rb->sub_resource_idx = sub_resource_idx;
ID3D10Device_CopyResource(device, rb->resource, (ID3D10Resource *)texture); if (FAILED(hr = ID3D10Texture2D_Map((ID3D10Texture2D *)rb->resource, sub_resource_idx, + D3D10_MAP_READ, 0, (D3D10_MAPPED_TEXTURE2D *)&rb->map_desc))) + { + trace("Failed to map sub-resource %u, hr %#x.\n", sub_resource_idx, hr); + ID3D10Resource_Release(rb->resource); + rb->resource = NULL; + } + rb->map_desc.DepthPitch = 0; + + ID3D10Device_Release(device); +} + +static void get_texture3d_readback(ID3D10Texture3D *texture, unsigned int sub_resource_idx, + struct resource_readback *rb) +{ + D3D10_TEXTURE3D_DESC texture_desc; + unsigned int miplevel; + ID3D10Device *device; + HRESULT hr; + + memset(rb, 0, sizeof(*rb)); + rb->dimension = D3D10_RESOURCE_DIMENSION_TEXTURE3D; + + ID3D10Texture3D_GetDevice(texture, &device); + + ID3D10Texture3D_GetDesc(texture, &texture_desc); + texture_desc.Usage = D3D10_USAGE_STAGING; + texture_desc.BindFlags = 0; + texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ; + texture_desc.MiscFlags = 0; + if (FAILED(hr = ID3D10Device_CreateTexture3D(device, &texture_desc, NULL, (ID3D10Texture3D **)&rb->resource))) + { + trace("Failed to create texture, hr %#x.\n", hr); + ID3D10Device_Release(device); + return; + } + + miplevel = sub_resource_idx % texture_desc.MipLevels; + rb->width = max(1, texture_desc.Width >> miplevel); + rb->height = max(1, texture_desc.Height >> miplevel); + rb->depth = max(1, texture_desc.Depth >> miplevel); + rb->sub_resource_idx = sub_resource_idx; + + ID3D10Device_CopyResource(device, rb->resource, (ID3D10Resource *)texture); + if (FAILED(hr = ID3D10Texture3D_Map((ID3D10Texture3D *)rb->resource, sub_resource_idx, D3D10_MAP_READ, 0, &rb->map_desc))) { trace("Failed to map sub-resource %u, hr %#x.\n", sub_resource_idx, hr); @@ -722,24 +771,25 @@ static void get_texture_readback(ID3D10Texture2D *texture, unsigned int sub_reso ID3D10Device_Release(device); }
-static void *get_readback_data(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned byte_width) +static void *get_readback_data(struct resource_readback *rb, + unsigned int x, unsigned int y, unsigned int z, unsigned byte_width) { - return (BYTE *)rb->map_desc.pData + y * rb->map_desc.RowPitch + x * byte_width; + return (BYTE *)rb->map_desc.pData + z * rb->map_desc.DepthPitch + y * rb->map_desc.RowPitch + x * byte_width; }
static BYTE get_readback_u8(struct resource_readback *rb, unsigned int x, unsigned int y) { - return *(BYTE *)get_readback_data(rb, x, y, sizeof(BYTE)); + return *(BYTE *)get_readback_data(rb, x, y, 0, sizeof(BYTE)); }
static WORD get_readback_u16(struct resource_readback *rb, unsigned int x, unsigned int y) { - return *(WORD *)get_readback_data(rb, x, y, sizeof(WORD)); + return *(WORD *)get_readback_data(rb, x, y, 0, sizeof(WORD)); }
static DWORD get_readback_u32(struct resource_readback *rb, unsigned int x, unsigned int y) { - return *(DWORD *)get_readback_data(rb, x, y, sizeof(DWORD)); + return *(DWORD *)get_readback_data(rb, x, y, 0, sizeof(DWORD)); }
static DWORD get_readback_color(struct resource_readback *rb, unsigned int x, unsigned int y) @@ -749,17 +799,17 @@ static DWORD get_readback_color(struct resource_readback *rb, unsigned int x, un
static float get_readback_float(struct resource_readback *rb, unsigned int x, unsigned int y) { - return *(float *)get_readback_data(rb, x, y, sizeof(float)); + return *(float *)get_readback_data(rb, x, y, 0, sizeof(float)); }
static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y) { - return get_readback_data(rb, x, y, sizeof(struct vec4)); + return get_readback_data(rb, x, y, 0, sizeof(struct vec4)); }
static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y) { - return get_readback_data(rb, x, y, sizeof(struct uvec4)); + return get_readback_data(rb, x, y, 0, sizeof(struct uvec4)); }
static void release_resource_readback(struct resource_readback *rb) @@ -775,6 +825,9 @@ static void release_resource_readback(struct resource_readback *rb) case D3D10_RESOURCE_DIMENSION_TEXTURE2D: ID3D10Texture2D_Unmap((ID3D10Texture2D *)rb->resource, rb->sub_resource_idx); break; + case D3D10_RESOURCE_DIMENSION_TEXTURE3D: + ID3D10Texture3D_Unmap((ID3D10Texture3D *)rb->resource, rb->sub_resource_idx); + break; default: trace("Unhandled resource dimension %#x.\n", rb->dimension); break; @@ -15970,12 +16023,12 @@ static void test_depth_bias(void) depth_values[y] = get_readback_float(&rb, 0, y); break; case DXGI_FORMAT_D24_UNORM_S8_UINT: - u32 = get_readback_data(&rb, 0, y, sizeof(*u32)); + u32 = get_readback_data(&rb, 0, y, 0, sizeof(*u32)); u32_value = *u32 >> shift; depth_values[y] = u32_value / 16777215.0f; break; case DXGI_FORMAT_D16_UNORM: - u16 = get_readback_data(&rb, 0, y, sizeof(*u16)); + u16 = get_readback_data(&rb, 0, y, 0, sizeof(*u16)); depth_values[y] = *u16 / 65535.0f; break; default: @@ -16013,7 +16066,7 @@ static void test_depth_bias(void) "Got depth %.8e, expected %.8e.\n", data, depth); break; case DXGI_FORMAT_D24_UNORM_S8_UINT: - u32 = get_readback_data(&rb, 0, y, sizeof(*u32)); + u32 = get_readback_data(&rb, 0, y, 0, sizeof(*u32)); u32_value = *u32 >> shift; expected_value = depth * 16777215.0f + 0.5f; all_match = compare_uint(u32_value, expected_value, 3); @@ -16023,7 +16076,7 @@ static void test_depth_bias(void) expected_value, expected_value / 16777215.0f); break; case DXGI_FORMAT_D16_UNORM: - u16 = get_readback_data(&rb, 0, y, sizeof(*u16)); + u16 = get_readback_data(&rb, 0, y, 0, sizeof(*u16)); expected_value = depth * 65535.0f + 0.5f; all_match = compare_uint(*u16, expected_value, 1); ok(all_match,