[PATCH 2/6] d3d10core/tests: Add tests for 2D texture RTVs.
Józef Kucia
jkucia at codeweavers.com
Fri May 13 06:55:27 CDT 2016
Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
dlls/d3d10core/tests/device.c | 187 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 187 insertions(+)
diff --git a/dlls/d3d10core/tests/device.c b/dlls/d3d10core/tests/device.c
index a4fa401..7c66fe2 100644
--- a/dlls/d3d10core/tests/device.c
+++ b/dlls/d3d10core/tests/device.c
@@ -16,6 +16,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
+#include <assert.h>
#define COBJMACROS
#include "initguid.h"
#include "d3d11.h"
@@ -356,6 +357,9 @@ struct d3d10core_test_context
ID3D10InputLayout *input_layout;
ID3D10VertexShader *vs;
ID3D10Buffer *vb;
+
+ ID3D10PixelShader *ps;
+ ID3D10Buffer *ps_cb;
};
#define init_test_context(c) init_test_context_(__LINE__, c)
@@ -405,6 +409,10 @@ static void release_test_context_(unsigned int line, struct d3d10core_test_conte
ID3D10VertexShader_Release(context->vs);
if (context->vb)
ID3D10Buffer_Release(context->vb);
+ if (context->ps)
+ ID3D10PixelShader_Release(context->ps);
+ if (context->ps_cb)
+ ID3D10Buffer_Release(context->ps_cb);
ID3D10RenderTargetView_Release(context->backbuffer_rtv);
ID3D10Texture2D_Release(context->backbuffer);
@@ -490,6 +498,57 @@ static void draw_quad_(unsigned int line, struct d3d10core_test_context *context
ID3D10Device_Draw(context->device, 4, 0);
}
+#define draw_color_quad(c, color) draw_color_quad_(__LINE__, c, color)
+static void draw_color_quad_(unsigned int line, struct d3d10core_test_context *context, const struct vec4 *color)
+{
+ static const DWORD ps_color_code[] =
+ {
+#if 0
+ float4 color;
+
+ float4 main() : SV_TARGET
+ {
+ return color;
+ }
+#endif
+ 0x43425844, 0x80f1c810, 0xdacbbc8b, 0xe07b133e, 0x3059cbfa, 0x00000001, 0x000000b8, 0x00000003,
+ 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
+ 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
+ 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000040, 0x00000040, 0x00000010,
+ 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036,
+ 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
+ };
+
+ ID3D10Device *device = context->device;
+ D3D10_BUFFER_DESC buffer_desc;
+ HRESULT hr;
+
+ if (!context->ps)
+ {
+ hr = ID3D10Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), &context->ps);
+ ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
+ }
+
+ if (!context->ps_cb)
+ {
+ buffer_desc.ByteWidth = sizeof(*color);
+ buffer_desc.Usage = D3D10_USAGE_DEFAULT;
+ buffer_desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
+ buffer_desc.CPUAccessFlags = 0;
+ buffer_desc.MiscFlags = 0;
+
+ hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &context->ps_cb);
+ ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
+ }
+
+ ID3D10Device_PSSetShader(device, context->ps);
+ ID3D10Device_PSSetConstantBuffers(device, 0, 1, &context->ps_cb);
+
+ ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)context->ps_cb, 0, NULL, color, 0, 0);
+
+ draw_quad_(line, context);
+}
+
static void test_feature_level(void)
{
D3D_FEATURE_LEVEL feature_level;
@@ -1469,6 +1528,133 @@ static void test_create_rendertarget_view(void)
ok(!refcount, "Device has %u references left.\n", refcount);
}
+static void test_render_target_views(void)
+{
+ struct texture
+ {
+ UINT miplevel_count;
+ UINT array_size;
+ };
+ struct rtv
+ {
+ DXGI_FORMAT format;
+ D3D10_RTV_DIMENSION dimension;
+ unsigned int miplevel_idx;
+ unsigned int layer_idx;
+ unsigned int layer_count;
+ };
+
+ static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
+ static struct test
+ {
+ struct texture texture;
+ struct rtv rtv;
+ DWORD expected_colors[4];
+ }
+ tests[] =
+ {
+ {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
+ {0xff0000ff, 0x00000000}},
+ {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 1},
+ {0x00000000, 0xff0000ff}},
+ {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
+ {0xff0000ff, 0x00000000}},
+ {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
+ {0x00000000, 0xff0000ff}},
+ {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
+ {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
+ {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
+ {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
+ {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
+ {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
+ {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
+ {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
+ {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
+ {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
+ {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
+ {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
+ {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
+ {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
+ {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
+ {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
+ {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
+ {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
+ {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
+ {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
+ {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
+ {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
+ };
+
+ struct d3d10core_test_context test_context;
+ D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
+ D3D10_TEXTURE2D_DESC texture_desc;
+ ID3D10RenderTargetView *rtv;
+ ID3D10Texture2D *texture;
+ ID3D10Device *device;
+ unsigned int i, j;
+ HRESULT hr;
+
+ if (!init_test_context(&test_context))
+ return;
+
+ device = test_context.device;
+
+ texture_desc.Width = 32;
+ texture_desc.Height = 32;
+ texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+ texture_desc.SampleDesc.Count = 1;
+ texture_desc.SampleDesc.Quality = 0;
+ texture_desc.Usage = D3D10_USAGE_DEFAULT;
+ texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
+ texture_desc.CPUAccessFlags = 0;
+ texture_desc.MiscFlags = 0;
+
+ for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
+ {
+ const struct test *test = &tests[i];
+ unsigned int sub_resource_count;
+
+ texture_desc.MipLevels = test->texture.miplevel_count;
+ texture_desc.ArraySize = test->texture.array_size;
+
+ hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
+ ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
+
+ rtv_desc.Format = texture_desc.Format;
+ rtv_desc.ViewDimension = test->rtv.dimension;
+ if (test->rtv.dimension == D3D10_RTV_DIMENSION_TEXTURE2D)
+ {
+ U(rtv_desc).Texture2D.MipSlice = test->rtv.miplevel_idx;
+ }
+ else if (test->rtv.dimension == D3D10_RTV_DIMENSION_TEXTURE2DARRAY)
+ {
+ U(rtv_desc).Texture2DArray.MipSlice = test->rtv.miplevel_idx;
+ U(rtv_desc).Texture2DArray.FirstArraySlice = test->rtv.layer_idx;
+ U(rtv_desc).Texture2DArray.ArraySize = test->rtv.layer_count;
+ }
+ else
+ {
+ trace("Test %u: Unhandled view dimension %#x.\n", i, test->rtv.dimension);
+ }
+
+ hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
+ ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
+
+ ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
+ draw_color_quad(&test_context, &red);
+
+ sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
+ assert(sub_resource_count <= sizeof(test->expected_colors) / sizeof(*test->expected_colors));
+ for (j = 0; j < sub_resource_count; ++j)
+ check_texture_sub_resource_color(texture, j, test->expected_colors[j], 1);
+
+ ID3D10RenderTargetView_Release(rtv);
+ ID3D10Texture2D_Release(texture);
+ }
+
+ release_test_context(&test_context);
+}
+
static void test_create_shader_resource_view(void)
{
D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
@@ -6471,6 +6657,7 @@ START_TEST(device)
test_create_depthstencil_view();
test_depthstencil_view_interfaces();
test_create_rendertarget_view();
+ test_render_target_views();
test_create_shader_resource_view();
test_create_shader();
test_create_sampler_state();
--
2.7.3
More information about the wine-patches
mailing list