Commit 076d6346 authored by Józef Kucia's avatar Józef Kucia Committed by Alexandre Julliard

d3d10core/tests: Add tests for buffer ranges.

parent 847ad743
...@@ -10990,7 +10990,8 @@ static void test_buffer_srv(void) ...@@ -10990,7 +10990,8 @@ static void test_buffer_srv(void)
{ {
struct buffer struct buffer
{ {
UINT byte_count; unsigned int byte_count;
unsigned int data_offset;
const void *data; const void *data;
}; };
...@@ -11000,13 +11001,13 @@ static void test_buffer_srv(void) ...@@ -11000,13 +11001,13 @@ static void test_buffer_srv(void)
const struct buffer *current_buffer; const struct buffer *current_buffer;
ID3D10ShaderResourceView *srv; ID3D10ShaderResourceView *srv;
D3D10_BUFFER_DESC buffer_desc; D3D10_BUFFER_DESC buffer_desc;
DWORD color, expected_color;
struct resource_readback rb; struct resource_readback rb;
ID3D10Buffer *cb, *buffer; ID3D10Buffer *cb, *buffer;
ID3D10PixelShader *ps; ID3D10PixelShader *ps;
ID3D10Device *device; ID3D10Device *device;
unsigned int i, x, y; unsigned int i, x, y;
struct vec4 cb_size; struct vec4 cb_size;
DWORD color;
HRESULT hr; HRESULT hr;
static const DWORD ps_float4_code[] = static const DWORD ps_float4_code[] =
...@@ -11052,8 +11053,30 @@ static void test_buffer_srv(void) ...@@ -11052,8 +11053,30 @@ static void test_buffer_srv(void)
0xffffffff, 0xff0000ff, 0xffffffff, 0xff0000ff,
0xff000000, 0xff00ff00, 0xff000000, 0xff00ff00,
}; };
static const struct buffer rgba16_buffer = {sizeof(rgba16), &rgba16}; static const BYTE r4[] =
static const struct buffer rgba4_buffer = {sizeof(rgba4), &rgba4}; {
0xde, 0xad,
0xba, 0xbe,
};
static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
static const DWORD rgba16_colors2x2[] =
{
0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
};
static const DWORD rgba16_colors1x1[] =
{
0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
};
static const DWORD rgba4_colors[] = static const DWORD rgba4_colors[] =
{ {
0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff, 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
...@@ -11061,6 +11084,13 @@ static void test_buffer_srv(void) ...@@ -11061,6 +11084,13 @@ static void test_buffer_srv(void)
0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00, 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00, 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
}; };
static const DWORD r4_colors[] =
{
0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
};
static const DWORD zero_colors[16] = {0}; static const DWORD zero_colors[16] = {0};
static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f}; static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
...@@ -11075,9 +11105,14 @@ static void test_buffer_srv(void) ...@@ -11075,9 +11105,14 @@ static void test_buffer_srv(void)
} }
tests[] = tests[] =
{ {
{&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16}, {&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
{&rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors}, {&rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
{NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors}, {&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
{&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
{&rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
{&r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
{&r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
{NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
}; };
if (!init_test_context(&test_context)) if (!init_test_context(&test_context))
...@@ -11104,12 +11139,12 @@ static void test_buffer_srv(void) ...@@ -11104,12 +11139,12 @@ static void test_buffer_srv(void)
{ {
if (buffer) if (buffer)
ID3D10Buffer_Release(buffer); ID3D10Buffer_Release(buffer);
if (srv)
ID3D10ShaderResourceView_Release(srv);
current_buffer = test->buffer; current_buffer = test->buffer;
if (current_buffer) if (current_buffer)
{ {
BYTE *data = NULL;
buffer_desc.ByteWidth = current_buffer->byte_count; buffer_desc.ByteWidth = current_buffer->byte_count;
buffer_desc.Usage = D3D10_USAGE_DEFAULT; buffer_desc.Usage = D3D10_USAGE_DEFAULT;
buffer_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE; buffer_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
...@@ -11117,25 +11152,44 @@ static void test_buffer_srv(void) ...@@ -11117,25 +11152,44 @@ static void test_buffer_srv(void)
buffer_desc.MiscFlags = 0; buffer_desc.MiscFlags = 0;
resource_data.SysMemPitch = 0; resource_data.SysMemPitch = 0;
resource_data.SysMemSlicePitch = 0; resource_data.SysMemSlicePitch = 0;
resource_data.pSysMem = current_buffer->data; if (current_buffer->data_offset)
{
data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, current_buffer->byte_count);
ok(!!data, "Failed to allocate memory.\n");
memcpy(data + current_buffer->data_offset, current_buffer->data,
current_buffer->byte_count - current_buffer->data_offset);
resource_data.pSysMem = data;
}
else
{
resource_data.pSysMem = current_buffer->data;
}
hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer); hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr); ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
HeapFree(GetProcessHeap(), 0, data);
srv_desc.Format = test->srv_format;
srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
U(srv_desc).Buffer.ElementOffset = test->srv_first_element;
U(srv_desc).Buffer.ElementWidth = test->srv_element_count;
hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srv);
ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
} }
else else
{ {
buffer = NULL; buffer = NULL;
srv = NULL;
} }
}
ID3D10Device_PSSetShaderResources(device, 0, 1, &srv); if (srv)
ID3D10ShaderResourceView_Release(srv);
if (current_buffer)
{
srv_desc.Format = test->srv_format;
srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
U(srv_desc).Buffer.ElementOffset = test->srv_first_element;
U(srv_desc).Buffer.ElementWidth = test->srv_element_count;
hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srv);
ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
}
else
{
srv = NULL;
} }
ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
cb_size.x = test->size.x; cb_size.x = test->size.x;
cb_size.y = test->size.y; cb_size.y = test->size.y;
...@@ -11150,8 +11204,10 @@ static void test_buffer_srv(void) ...@@ -11150,8 +11204,10 @@ static void test_buffer_srv(void)
for (x = 0; x < 4; ++x) for (x = 0; x < 4; ++x)
{ {
color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120); color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
ok(compare_color(color, test->expected_colors[y * 4 + x], 1), expected_color = test->expected_colors[y * 4 + x];
"Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y); ok(compare_color(color, expected_color, 1),
"Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
i, color, expected_color, x, y);
} }
} }
release_resource_readback(&rb); release_resource_readback(&rb);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment