d3d11/tests: Add test for buffer data initialization.
Signed-off-by: Józef Kucia <jkucia@codeweavers.com> Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
9efe66a83a
commit
e25f79f578
|
@ -607,16 +607,59 @@ static ID3D11Buffer *create_buffer_(unsigned int line, ID3D11Device *device,
|
|||
return buffer;
|
||||
}
|
||||
|
||||
struct texture_readback
|
||||
struct resource_readback
|
||||
{
|
||||
ID3D11Resource *texture;
|
||||
ID3D11Resource *resource;
|
||||
D3D11_MAPPED_SUBRESOURCE map_desc;
|
||||
ID3D11DeviceContext *immediate_context;
|
||||
unsigned int width, height, sub_resource_idx;
|
||||
};
|
||||
|
||||
static void get_buffer_readback(ID3D11Buffer *buffer, struct resource_readback *rb)
|
||||
{
|
||||
D3D11_BUFFER_DESC buffer_desc;
|
||||
ID3D11Device *device;
|
||||
HRESULT hr;
|
||||
|
||||
memset(rb, 0, sizeof(*rb));
|
||||
|
||||
ID3D11Buffer_GetDevice(buffer, &device);
|
||||
|
||||
ID3D11Buffer_GetDesc(buffer, &buffer_desc);
|
||||
buffer_desc.Usage = D3D11_USAGE_STAGING;
|
||||
buffer_desc.BindFlags = 0;
|
||||
buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||
buffer_desc.MiscFlags = 0;
|
||||
buffer_desc.StructureByteStride = 0;
|
||||
if (FAILED(hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, (ID3D11Buffer **)&rb->resource)))
|
||||
{
|
||||
trace("Failed to create staging buffer, hr %#x.\n", hr);
|
||||
ID3D11Device_Release(device);
|
||||
return;
|
||||
}
|
||||
|
||||
rb->width = buffer_desc.ByteWidth;
|
||||
rb->height = 1;
|
||||
rb->sub_resource_idx = 0;
|
||||
|
||||
ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
|
||||
|
||||
ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, (ID3D11Resource *)buffer);
|
||||
if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->resource, 0,
|
||||
D3D11_MAP_READ, 0, &rb->map_desc)))
|
||||
{
|
||||
trace("Failed to map buffer, hr %#x.\n", hr);
|
||||
ID3D11Resource_Release(rb->resource);
|
||||
rb->resource = NULL;
|
||||
ID3D11DeviceContext_Release(rb->immediate_context);
|
||||
rb->immediate_context = NULL;
|
||||
}
|
||||
|
||||
ID3D11Device_Release(device);
|
||||
}
|
||||
|
||||
static void get_texture_readback(ID3D11Texture2D *texture, unsigned int sub_resource_idx,
|
||||
struct texture_readback *rb)
|
||||
struct resource_readback *rb)
|
||||
{
|
||||
D3D11_TEXTURE2D_DESC texture_desc;
|
||||
unsigned int miplevel;
|
||||
|
@ -632,7 +675,7 @@ static void get_texture_readback(ID3D11Texture2D *texture, unsigned int sub_reso
|
|||
texture_desc.BindFlags = 0;
|
||||
texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||
texture_desc.MiscFlags = 0;
|
||||
if (FAILED(hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&rb->texture)))
|
||||
if (FAILED(hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&rb->resource)))
|
||||
{
|
||||
trace("Failed to create texture, hr %#x.\n", hr);
|
||||
ID3D11Device_Release(device);
|
||||
|
@ -646,13 +689,13 @@ static void get_texture_readback(ID3D11Texture2D *texture, unsigned int sub_reso
|
|||
|
||||
ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
|
||||
|
||||
ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->texture, (ID3D11Resource *)texture);
|
||||
if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->texture, sub_resource_idx,
|
||||
ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, (ID3D11Resource *)texture);
|
||||
if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->resource, sub_resource_idx,
|
||||
D3D11_MAP_READ, 0, &rb->map_desc)))
|
||||
{
|
||||
trace("Failed to map sub-resource %u, hr %#x.\n", sub_resource_idx, hr);
|
||||
ID3D11Resource_Release(rb->texture);
|
||||
rb->texture = NULL;
|
||||
ID3D11Resource_Release(rb->resource);
|
||||
rb->resource = NULL;
|
||||
ID3D11DeviceContext_Release(rb->immediate_context);
|
||||
rb->immediate_context = NULL;
|
||||
}
|
||||
|
@ -660,41 +703,41 @@ static void get_texture_readback(ID3D11Texture2D *texture, unsigned int sub_reso
|
|||
ID3D11Device_Release(device);
|
||||
}
|
||||
|
||||
static DWORD get_readback_color(struct texture_readback *rb, unsigned int x, unsigned int y)
|
||||
static DWORD get_readback_color(struct resource_readback *rb, unsigned int x, unsigned int y)
|
||||
{
|
||||
return ((DWORD *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(DWORD) + x];
|
||||
}
|
||||
|
||||
static float get_readback_float(struct texture_readback *rb, unsigned int x, unsigned int y)
|
||||
static float get_readback_float(struct resource_readback *rb, unsigned int x, unsigned int y)
|
||||
{
|
||||
return ((float *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(float) + x];
|
||||
}
|
||||
|
||||
static const struct vec4 *get_readback_vec4(struct texture_readback *rb, unsigned int x, unsigned int y)
|
||||
static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y)
|
||||
{
|
||||
return &((const struct vec4 *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(struct vec4) + x];
|
||||
}
|
||||
|
||||
static const struct uvec4 *get_readback_uvec4(struct texture_readback *rb, unsigned int x, unsigned int y)
|
||||
static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y)
|
||||
{
|
||||
return &((const struct uvec4 *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(struct uvec4) + x];
|
||||
}
|
||||
|
||||
static void release_texture_readback(struct texture_readback *rb)
|
||||
static void release_resource_readback(struct resource_readback *rb)
|
||||
{
|
||||
ID3D11DeviceContext_Unmap(rb->immediate_context, rb->texture, rb->sub_resource_idx);
|
||||
ID3D11Resource_Release(rb->texture);
|
||||
ID3D11DeviceContext_Unmap(rb->immediate_context, rb->resource, rb->sub_resource_idx);
|
||||
ID3D11Resource_Release(rb->resource);
|
||||
ID3D11DeviceContext_Release(rb->immediate_context);
|
||||
}
|
||||
|
||||
static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigned int y)
|
||||
{
|
||||
struct texture_readback rb;
|
||||
struct resource_readback rb;
|
||||
DWORD color;
|
||||
|
||||
get_texture_readback(texture, 0, &rb);
|
||||
color = get_readback_color(&rb, x, y);
|
||||
release_texture_readback(&rb);
|
||||
release_resource_readback(&rb);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
@ -703,7 +746,7 @@ static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigne
|
|||
static void check_texture_sub_resource_color_(unsigned int line, ID3D11Texture2D *texture,
|
||||
unsigned int sub_resource_idx, DWORD expected_color, BYTE max_diff)
|
||||
{
|
||||
struct texture_readback rb;
|
||||
struct resource_readback rb;
|
||||
unsigned int x = 0, y = 0;
|
||||
BOOL all_match = TRUE;
|
||||
DWORD color = 0;
|
||||
|
@ -723,7 +766,7 @@ static void check_texture_sub_resource_color_(unsigned int line, ID3D11Texture2D
|
|||
if (!all_match)
|
||||
break;
|
||||
}
|
||||
release_texture_readback(&rb);
|
||||
release_resource_readback(&rb);
|
||||
ok_(__FILE__, line)(all_match,
|
||||
"Got unexpected color 0x%08x at (%u, %u), sub-resource %u.\n",
|
||||
color, x, y, sub_resource_idx);
|
||||
|
@ -746,7 +789,7 @@ static void check_texture_color_(unsigned int line, ID3D11Texture2D *texture,
|
|||
static void check_texture_sub_resource_float_(unsigned int line, ID3D11Texture2D *texture,
|
||||
unsigned int sub_resource_idx, float expected_value, BYTE max_diff)
|
||||
{
|
||||
struct texture_readback rb;
|
||||
struct resource_readback rb;
|
||||
unsigned int x = 0, y = 0;
|
||||
BOOL all_match = TRUE;
|
||||
float value = 0.0f;
|
||||
|
@ -766,7 +809,7 @@ static void check_texture_sub_resource_float_(unsigned int line, ID3D11Texture2D
|
|||
if (!all_match)
|
||||
break;
|
||||
}
|
||||
release_texture_readback(&rb);
|
||||
release_resource_readback(&rb);
|
||||
ok_(__FILE__, line)(all_match,
|
||||
"Got unexpected value %.8e at (%u, %u), sub-resource %u.\n",
|
||||
value, x, y, sub_resource_idx);
|
||||
|
@ -789,7 +832,7 @@ static void check_texture_float_(unsigned int line, ID3D11Texture2D *texture,
|
|||
static void check_texture_sub_resource_vec4_(unsigned int line, ID3D11Texture2D *texture,
|
||||
unsigned int sub_resource_idx, const struct vec4 *expected_value, BYTE max_diff)
|
||||
{
|
||||
struct texture_readback rb;
|
||||
struct resource_readback rb;
|
||||
unsigned int x = 0, y = 0;
|
||||
struct vec4 value = {0};
|
||||
BOOL all_match = TRUE;
|
||||
|
@ -809,7 +852,7 @@ static void check_texture_sub_resource_vec4_(unsigned int line, ID3D11Texture2D
|
|||
if (!all_match)
|
||||
break;
|
||||
}
|
||||
release_texture_readback(&rb);
|
||||
release_resource_readback(&rb);
|
||||
ok_(__FILE__, line)(all_match,
|
||||
"Got unexpected value {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
|
||||
value.x, value.y, value.z, value.w, x, y, sub_resource_idx);
|
||||
|
@ -832,7 +875,7 @@ static void check_texture_vec4_(unsigned int line, ID3D11Texture2D *texture,
|
|||
static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D11Texture2D *texture,
|
||||
unsigned int sub_resource_idx, const struct uvec4 *expected_value)
|
||||
{
|
||||
struct texture_readback rb;
|
||||
struct resource_readback rb;
|
||||
unsigned int x = 0, y = 0;
|
||||
struct uvec4 value = {0};
|
||||
BOOL all_match = TRUE;
|
||||
|
@ -852,7 +895,7 @@ static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D11Texture2D
|
|||
if (!all_match)
|
||||
break;
|
||||
}
|
||||
release_texture_readback(&rb);
|
||||
release_resource_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",
|
||||
|
@ -5175,7 +5218,7 @@ static void test_texture(void)
|
|||
ID3D11ShaderResourceView *srv;
|
||||
ID3D11DeviceContext *context;
|
||||
ID3D11SamplerState *sampler;
|
||||
struct texture_readback rb;
|
||||
struct resource_readback rb;
|
||||
ID3D11Texture2D *texture;
|
||||
struct vec4 ps_constant;
|
||||
ID3D11PixelShader *ps;
|
||||
|
@ -5896,7 +5939,7 @@ static void test_texture(void)
|
|||
"Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
|
||||
}
|
||||
}
|
||||
release_texture_readback(&rb);
|
||||
release_resource_readback(&rb);
|
||||
}
|
||||
if (srv)
|
||||
ID3D11ShaderResourceView_Release(srv);
|
||||
|
@ -5988,7 +6031,7 @@ static void test_texture(void)
|
|||
"Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
|
||||
}
|
||||
}
|
||||
release_texture_readback(&rb);
|
||||
release_resource_readback(&rb);
|
||||
}
|
||||
ID3D11PixelShader_Release(ps);
|
||||
ID3D11Texture2D_Release(texture);
|
||||
|
@ -6677,7 +6720,7 @@ static void test_update_subresource(void)
|
|||
ID3D11ShaderResourceView *ps_srv;
|
||||
D3D11_SAMPLER_DESC sampler_desc;
|
||||
ID3D11DeviceContext *context;
|
||||
struct texture_readback rb;
|
||||
struct resource_readback rb;
|
||||
ID3D11Texture2D *texture;
|
||||
ID3D11PixelShader *ps;
|
||||
ID3D11Device *device;
|
||||
|
@ -6812,7 +6855,7 @@ static void test_update_subresource(void)
|
|||
color, j, i, expected_colors[j + i * 4]);
|
||||
}
|
||||
}
|
||||
release_texture_readback(&rb);
|
||||
release_resource_readback(&rb);
|
||||
|
||||
ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
|
||||
bitmap_data, 4 * sizeof(*bitmap_data), 0);
|
||||
|
@ -6828,7 +6871,7 @@ static void test_update_subresource(void)
|
|||
color, j, i, bitmap_data[j + i * 4]);
|
||||
}
|
||||
}
|
||||
release_texture_readback(&rb);
|
||||
release_resource_readback(&rb);
|
||||
|
||||
ID3D11PixelShader_Release(ps);
|
||||
ID3D11SamplerState_Release(sampler_state);
|
||||
|
@ -6849,7 +6892,7 @@ static void test_copy_subresource_region(void)
|
|||
D3D11_SAMPLER_DESC sampler_desc;
|
||||
ID3D11DeviceContext *context;
|
||||
struct vec4 float_colors[16];
|
||||
struct texture_readback rb;
|
||||
struct resource_readback rb;
|
||||
ID3D11PixelShader *ps;
|
||||
ID3D11Device *device;
|
||||
unsigned int i, j;
|
||||
|
@ -7013,7 +7056,7 @@ static void test_copy_subresource_region(void)
|
|||
color, j, i, expected_colors[j + i * 4]);
|
||||
}
|
||||
}
|
||||
release_texture_readback(&rb);
|
||||
release_resource_readback(&rb);
|
||||
|
||||
ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
|
||||
0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
|
||||
|
@ -7029,7 +7072,7 @@ static void test_copy_subresource_region(void)
|
|||
color, j, i, bitmap_data[j + i * 4]);
|
||||
}
|
||||
}
|
||||
release_texture_readback(&rb);
|
||||
release_resource_readback(&rb);
|
||||
|
||||
ID3D11PixelShader_Release(ps);
|
||||
hr = ID3D11Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), NULL, &ps);
|
||||
|
@ -7099,7 +7142,7 @@ static void test_copy_subresource_region(void)
|
|||
color, j, i, bitmap_data[j + i * 4]);
|
||||
}
|
||||
}
|
||||
release_texture_readback(&rb);
|
||||
release_resource_readback(&rb);
|
||||
|
||||
ID3D11Buffer_Release(dst_buffer);
|
||||
ID3D11Buffer_Release(src_buffer);
|
||||
|
@ -7249,6 +7292,33 @@ done:
|
|||
ok(!refcount, "Device has %u references left.\n", refcount);
|
||||
}
|
||||
|
||||
static void test_buffer_data_init(void)
|
||||
{
|
||||
struct resource_readback rb;
|
||||
ID3D11Buffer *buffer;
|
||||
ID3D11Device *device;
|
||||
unsigned int i;
|
||||
|
||||
if (!(device = create_device(NULL)))
|
||||
{
|
||||
skip("Failed to create device.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
buffer = create_buffer(device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
|
||||
|
||||
get_buffer_readback(buffer, &rb);
|
||||
for (i = 0; i < rb.width; ++i)
|
||||
{
|
||||
DWORD r = get_readback_color(&rb, i / sizeof(DWORD), 0);
|
||||
ok(!r, "Got unexpected result %#x at offset %u.\n", r, i);
|
||||
}
|
||||
release_resource_readback(&rb);
|
||||
|
||||
ID3D11Buffer_Release(buffer);
|
||||
ID3D11Device_Release(device);
|
||||
}
|
||||
|
||||
static void test_texture_data_init(void)
|
||||
{
|
||||
static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
|
@ -7863,7 +7933,7 @@ static void test_draw_depth_only(void)
|
|||
D3D11_TEXTURE2D_DESC texture_desc;
|
||||
ID3D11DeviceContext *context;
|
||||
ID3D11DepthStencilView *dsv;
|
||||
struct texture_readback rb;
|
||||
struct resource_readback rb;
|
||||
ID3D11Texture2D *texture;
|
||||
ID3D11Device *device;
|
||||
unsigned int i, j;
|
||||
|
@ -8008,7 +8078,7 @@ static void test_draw_depth_only(void)
|
|||
obtained_depth, j, i, expected_depth);
|
||||
}
|
||||
}
|
||||
release_texture_readback(&rb);
|
||||
release_resource_readback(&rb);
|
||||
|
||||
ID3D11Buffer_Release(cb);
|
||||
ID3D11PixelShader_Release(ps_color);
|
||||
|
@ -9789,6 +9859,7 @@ START_TEST(d3d11)
|
|||
test_update_subresource();
|
||||
test_copy_subresource_region();
|
||||
test_resource_map();
|
||||
test_buffer_data_init();
|
||||
test_texture_data_init();
|
||||
test_check_multisample_quality_levels();
|
||||
test_swapchain_flip();
|
||||
|
|
Loading…
Reference in New Issue