[PATCH 4/6] d3d10core/tests: Add test for texturing with custom shader resource views.
Józef Kucia
jkucia at codeweavers.com
Fri Jun 10 05:07:03 CDT 2016
Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
dlls/d3d10core/tests/device.c | 168 +++++++++++++++++++++++++++++++++++++++---
1 file changed, 158 insertions(+), 10 deletions(-)
diff --git a/dlls/d3d10core/tests/device.c b/dlls/d3d10core/tests/device.c
index 15c687c..cd25f69 100644
--- a/dlls/d3d10core/tests/device.c
+++ b/dlls/d3d10core/tests/device.c
@@ -23,8 +23,6 @@
#include "wine/test.h"
#include <limits.h>
-static BOOL d3d11_available;
-
struct vec2
{
float x, y;
@@ -558,6 +556,17 @@ static BOOL is_warp_device(ID3D10Device *device)
|| (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
}
+static BOOL is_d3d11_interface_available(ID3D10Device *device)
+{
+ ID3D11Device *d3d11_device;
+ HRESULT hr;
+
+ if (SUCCEEDED(hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device)))
+ ID3D11Device_Release(d3d11_device);
+
+ return SUCCEEDED(hr);
+}
+
#define SWAPCHAIN_FLAG_SHADER_INPUT 0x1
struct swapchain_desc
@@ -822,8 +831,6 @@ static void test_feature_level(void)
return;
}
- d3d11_available = TRUE;
-
/* Device was created by D3D10CreateDevice. */
feature_level = ID3D11Device_GetFeatureLevel(device11);
ok(feature_level == D3D_FEATURE_LEVEL_10_0, "Got unexpected feature level %#x.\n", feature_level);
@@ -4242,6 +4249,7 @@ static void test_texture(void)
};
struct d3d10core_test_context test_context;
+ D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
const struct texture *current_texture;
D3D10_TEXTURE2D_DESC texture_desc;
D3D10_SAMPLER_DESC sampler_desc;
@@ -4577,6 +4585,8 @@ static void test_texture(void)
};
static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
{{srgb_data, 4 * sizeof(*srgb_data)}}};
+ static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
+ {{srgb_data, 4 * sizeof(*srgb_data)}}};
static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
{{a8_data, 4 * sizeof(*a8_data)}}};
static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
@@ -4587,6 +4597,9 @@ static void test_texture(void)
static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
+ static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
+ static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
+ static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
{{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
@@ -4680,7 +4693,7 @@ static void test_texture(void)
static const DWORD zero_colors[4 * 4] = {0};
static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
- static const struct test
+ static const struct texture_test
{
const struct shader *ps;
const struct texture *texture;
@@ -4691,7 +4704,7 @@ static void test_texture(void)
float ps_constant;
const DWORD *expected_colors;
}
- tests[] =
+ texture_tests[] =
{
#define POINT D3D10_FILTER_MIN_MAG_MIP_POINT
#define POINT_LINEAR D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR
@@ -4795,6 +4808,51 @@ static void test_texture(void)
#undef POINT_LINEAR
#undef MIP_MAX
};
+ static const struct srv_test
+ {
+ const struct shader *ps;
+ const struct texture *texture;
+ struct srv_desc srv_desc;
+ float ps_constant;
+ const DWORD *expected_colors;
+ }
+ srv_tests[] =
+ {
+#define TEX_2D D3D10_SRV_DIMENSION_TEXTURE2D
+#define TEX_2D_ARRAY D3D10_SRV_DIMENSION_TEXTURE2DARRAY
+#define BC1_UNORM DXGI_FORMAT_BC1_UNORM
+#define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
+#define BC2_UNORM DXGI_FORMAT_BC2_UNORM
+#define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
+#define BC3_UNORM DXGI_FORMAT_BC3_UNORM
+#define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
+#define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
+#define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
+#define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
+ {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
+ {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
+ {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
+ {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
+ {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
+ {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
+ {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
+ {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
+ {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
+ {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
+ {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
+ {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
+#undef TEX_2D
+#undef TEX_2D_ARRAY
+#undef BC1_UNORM
+#undef BC1_UNORM_SRGB
+#undef BC2_UNORM
+#undef BC2_UNORM_SRGB
+#undef BC3_UNORM
+#undef BC3_UNORM_SRGB
+#undef R8G8B8A8_UNORM_SRGB
+#undef R8G8B8A8_UNORM
+#undef FMT_UNKNOWN
+ };
if (!init_test_context(&test_context))
return;
@@ -4832,9 +4890,9 @@ static void test_texture(void)
texture = NULL;
current_ps = NULL;
current_texture = NULL;
- for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
+ for (i = 0; i < sizeof(texture_tests) / sizeof(*texture_tests); ++i)
{
- const struct test *test = &tests[i];
+ const struct texture_test *test = &texture_tests[i];
if (current_ps != test->ps)
{
@@ -4926,6 +4984,96 @@ static void test_texture(void)
ID3D10Texture2D_Release(texture);
ID3D10PixelShader_Release(ps);
+ if (is_warp_device(device) && !is_d3d11_interface_available(device))
+ {
+ win_skip("SRV tests are broken on WARP.\n");
+ ID3D10Buffer_Release(cb);
+ release_test_context(&test_context);
+ return;
+ }
+
+ sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
+ sampler_desc.MipLODBias = 0.0f;
+ sampler_desc.MinLOD = 0.0f;
+ sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
+
+ hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
+ ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
+
+ ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
+
+ ps = NULL;
+ srv = NULL;
+ texture = NULL;
+ current_ps = NULL;
+ current_texture = NULL;
+ for (i = 0; i < sizeof(srv_tests) / sizeof(*srv_tests); ++i)
+ {
+ const struct srv_test *test = &srv_tests[i];
+
+ if (current_ps != test->ps)
+ {
+ if (ps)
+ ID3D10PixelShader_Release(ps);
+
+ current_ps = test->ps;
+
+ hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
+ ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
+
+ ID3D10Device_PSSetShader(device, ps);
+ }
+
+ if (current_texture != test->texture)
+ {
+ if (texture)
+ ID3D10Texture2D_Release(texture);
+
+ current_texture = test->texture;
+
+ texture_desc.Width = current_texture->width;
+ texture_desc.Height = current_texture->height;
+ texture_desc.MipLevels = current_texture->miplevel_count;
+ texture_desc.ArraySize = current_texture->array_size;
+ texture_desc.Format = current_texture->format;
+
+ hr = ID3D10Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
+ ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
+ }
+
+ if (srv)
+ ID3D10ShaderResourceView_Release(srv);
+
+ get_srv_desc(&srv_desc, &test->srv_desc);
+ hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &srv);
+ ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
+
+ ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
+
+ ps_constant.x = test->ps_constant;
+ ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
+
+ ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
+
+ draw_quad(&test_context);
+
+ get_texture_readback(test_context.backbuffer, 0, &rb);
+ for (y = 0; y < 4; ++y)
+ {
+ for (x = 0; x < 4; ++x)
+ {
+ color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
+ ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
+ "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
+ }
+ }
+ release_texture_readback(&rb);
+ }
+ ID3D10PixelShader_Release(ps);
+ ID3D10Texture2D_Release(texture);
+ ID3D10ShaderResourceView_Release(srv);
+ ID3D10SamplerState_Release(sampler);
+
ID3D10Buffer_Release(cb);
release_test_context(&test_context);
}
@@ -6682,7 +6830,7 @@ static void test_clear_render_target_view(void)
ID3D10Device_ClearRenderTargetView(device, rtv, color);
check_texture_color(texture, expected_color, 1);
- if (d3d11_available)
+ if (is_d3d11_interface_available(device))
{
ID3D10Device_ClearRenderTargetView(device, NULL, green);
check_texture_color(texture, expected_color, 1);
@@ -6793,7 +6941,7 @@ static void test_clear_depth_stencil_view(void)
ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0);
check_texture_color(depth_texture, 0x00000000, 0);
- if (d3d11_available)
+ if (is_d3d11_interface_available(device))
{
ID3D10Device_ClearDepthStencilView(device, NULL, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0xff);
check_texture_color(depth_texture, 0x00000000, 0);
--
2.7.3
More information about the wine-patches
mailing list