[PATCH 3/6] d3d11/tests: Add test for SM4 sample_l instruction.
Józef Kucia
jkucia at codeweavers.com
Fri Jan 1 11:08:02 CST 2016
Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
dlls/d3d11/tests/d3d11.c | 346 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 346 insertions(+)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c
index 6c8f0f7..2ab4241 100644
--- a/dlls/d3d11/tests/d3d11.c
+++ b/dlls/d3d11/tests/d3d11.c
@@ -4150,6 +4150,351 @@ done:
ok(!refcount, "Device has %u references left.\n", refcount);
}
+static void test_sample_l(void)
+{
+ D3D11_SUBRESOURCE_DATA resource_data[3];
+ D3D11_TEXTURE2D_DESC texture_desc;
+ D3D11_SAMPLER_DESC sampler_desc;
+ ID3D11InputLayout *input_layout;
+ ID3D11ShaderResourceView *srv;
+ D3D11_BUFFER_DESC buffer_desc;
+ ID3D11DeviceContext *context;
+ ID3D11Texture2D *backbuffer;
+ ID3D11RenderTargetView *rtv;
+ ID3D11SamplerState *sampler;
+ unsigned int stride, offset;
+ DWORD color, expected_color;
+ struct texture_readback rb;
+ IDXGISwapChain *swapchain;
+ ID3D11Texture2D *texture;
+ ID3D11VertexShader *vs;
+ ID3D11PixelShader *ps;
+ ID3D11Buffer *vb, *cb;
+ ID3D11Device *device;
+ unsigned int i, x, y;
+ D3D11_VIEWPORT vp;
+ ULONG refcount;
+ HWND window;
+ HRESULT hr;
+
+ static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
+ {
+ {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
+ };
+ static const DWORD vs_code[] =
+ {
+#if 0
+ float4 main(float4 position : POSITION) : SV_POSITION
+ {
+ return position;
+ }
+#endif
+ 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
+ 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
+ 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
+ 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
+ 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
+ 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
+ 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
+ };
+ static const DWORD ps_code[] =
+ {
+#if 0
+ Texture2D t;
+ SamplerState s;
+
+ float level;
+
+ float4 main(float4 position : SV_POSITION) : SV_Target
+ {
+ float2 p;
+
+ p.x = position.x / 640.0f;
+ p.y = position.y / 480.0f;
+ return t.SampleLevel(s, p, level);
+ }
+#endif
+ 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
+ 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
+ 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
+ 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
+ 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
+ 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
+ 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
+ 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
+ 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
+ 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
+ };
+ static const struct
+ {
+ struct vec2 position;
+ }
+ quad[] =
+ {
+ {{-1.0f, -1.0f}},
+ {{-1.0f, 1.0f}},
+ {{ 1.0f, -1.0f}},
+ {{ 1.0f, 1.0f}},
+ };
+ static const DWORD bitmap_level_0[] =
+ {
+ 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
+ 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
+ 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
+ 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
+ };
+ static const DWORD bitmap_level_1[] =
+ {
+ 0xffffffff, 0xff0000ff,
+ 0xff000000, 0xff00ff00,
+ };
+ static const DWORD bitmap_level_2[] =
+ {
+ 0xffff0000,
+ };
+ static const DWORD bitmap_lerp_1_2[] =
+ {
+ 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
+ 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
+ 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
+ 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
+ };
+ static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
+ float miplevel[4] = {0};
+
+ static const struct test
+ {
+ D3D11_FILTER filter;
+ float lod_bias;
+ float min_lod;
+ float max_lod;
+ float miplevel;
+ enum
+ {
+ level_0,
+ level_1,
+ level_2,
+ lerp_1_2,
+ }
+ expected_bitmap;
+ }
+ tests[] =
+ {
+ {D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, -1.0f, level_0},
+ {D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, level_0},
+ {D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.4f, level_0},
+ {D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 0.5f, level_1},
+ {D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 1.0f, level_1},
+ {D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 1.4f, level_1},
+ {D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 1.5f, level_2},
+ {D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 2.0f, level_2},
+ {D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 3.0f, level_2},
+ {D3D11_FILTER_MIN_MAG_MIP_POINT, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 4.0f, level_2},
+ {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 0.0f, 0.0f, D3D11_FLOAT32_MAX, 1.5f, lerp_1_2},
+ {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, -2.0f, level_0},
+ {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, -1.0f, level_1},
+ {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, 0.0f, level_2},
+ {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, 1.0f, level_2},
+ {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 0.0f, D3D11_FLOAT32_MAX, 1.5f, level_2},
+ {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2},
+ {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2},
+ {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2},
+ {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2},
+ {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2},
+ {D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2},
+ {D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2},
+ {D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2},
+ {D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2},
+ {D3D11_FILTER_MIN_MAG_MIP_POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2},
+ };
+
+ if (!(device = create_device(NULL)))
+ {
+ skip("Failed to create device.\n");
+ return;
+ }
+ window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
+ 0, 0, 640, 480, NULL, NULL, NULL, NULL);
+ swapchain = create_swapchain(device, window, TRUE);
+ hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer);
+ ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
+
+ hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
+ vs_code, sizeof(vs_code), &input_layout);
+ ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
+
+ buffer_desc.ByteWidth = sizeof(quad);
+ buffer_desc.Usage = D3D11_USAGE_DEFAULT;
+ buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
+ buffer_desc.CPUAccessFlags = 0;
+ buffer_desc.MiscFlags = 0;
+ buffer_desc.StructureByteStride = 0;
+
+ resource_data[0].pSysMem = quad;
+ resource_data[0].SysMemPitch = 0;
+ resource_data[0].SysMemSlicePitch = 0;
+
+ hr = ID3D11Device_CreateBuffer(device, &buffer_desc, resource_data, &vb);
+ ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
+
+ buffer_desc.ByteWidth = sizeof(miplevel);
+ buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
+
+ resource_data[0].pSysMem = &miplevel;
+
+ hr = ID3D11Device_CreateBuffer(device, &buffer_desc, resource_data, &cb);
+ ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
+
+ hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
+ ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
+ hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
+ ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
+
+ texture_desc.Width = 4;
+ texture_desc.Height = 4;
+ texture_desc.MipLevels = 3;
+ texture_desc.ArraySize = 1;
+ texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+ texture_desc.SampleDesc.Count = 1;
+ texture_desc.SampleDesc.Quality = 0;
+ texture_desc.Usage = D3D11_USAGE_DEFAULT;
+ texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
+ texture_desc.CPUAccessFlags = 0;
+ texture_desc.MiscFlags = 0;
+
+ resource_data[0].pSysMem = bitmap_level_0;
+ resource_data[0].SysMemPitch = 4 * sizeof(*bitmap_level_0);
+ resource_data[1].pSysMem = bitmap_level_1;
+ resource_data[1].SysMemPitch = 2 * sizeof(*bitmap_level_1);
+ resource_data[1].SysMemSlicePitch = 0;
+ resource_data[2].pSysMem = bitmap_level_2;
+ resource_data[2].SysMemPitch = sizeof(*bitmap_level_2);
+ resource_data[2].SysMemSlicePitch = 0;
+
+ hr = ID3D11Device_CreateTexture2D(device, &texture_desc, resource_data, &texture);
+ ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
+
+ hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
+ ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
+
+ hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer, NULL, &rtv);
+ ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
+
+ ID3D11Device_GetImmediateContext(device, &context);
+
+ ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
+ ID3D11DeviceContext_IASetInputLayout(context, input_layout);
+ ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
+ stride = sizeof(*quad);
+ offset = 0;
+ ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
+ ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
+ ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
+ ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
+ ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
+
+ vp.TopLeftX = 0.0f;
+ vp.TopLeftY = 0.0f;
+ vp.Width = 640.0f;
+ vp.Height = 480.0f;
+ vp.MinDepth = 0.0f;
+ vp.MaxDepth = 1.0f;
+ ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
+
+ sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
+ sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
+ sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
+ sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
+ sampler_desc.MipLODBias = 0.0f;
+ sampler_desc.MaxAnisotropy = 0;
+ sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
+ sampler_desc.BorderColor[0] = 0.0f;
+ sampler_desc.BorderColor[1] = 0.0f;
+ sampler_desc.BorderColor[2] = 0.0f;
+ sampler_desc.BorderColor[3] = 0.0f;
+ sampler_desc.MinLOD = 0.0f;
+ sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
+
+ sampler = NULL;
+ for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
+ {
+ const struct test *test = &tests[i];
+
+ if (!sampler || (sampler_desc.Filter != test[i].filter
+ || sampler_desc.MipLODBias != test->lod_bias
+ || sampler_desc.MinLOD != test->min_lod
+ || sampler_desc.MaxLOD != test->max_lod))
+ {
+ if (sampler)
+ ID3D11SamplerState_Release(sampler);
+
+ sampler_desc.Filter = test->filter;
+ sampler_desc.MipLODBias = test->lod_bias;
+ sampler_desc.MinLOD = test->min_lod;
+ sampler_desc.MaxLOD = test->max_lod;
+
+ hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
+ ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
+
+ ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
+ }
+
+ *miplevel = test->miplevel;
+ ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, miplevel, 0, 0);
+
+ ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
+ ID3D11DeviceContext_Draw(context, 4, 0);
+
+ get_texture_readback(backbuffer, &rb);
+ for (x = 0; x < 4; ++x)
+ {
+ for (y = 0; y < 4; ++y)
+ {
+ color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
+ switch (test->expected_bitmap)
+ {
+ case level_0:
+ expected_color = bitmap_level_0[y * 4 + x];
+ break;
+ case level_1:
+ expected_color = bitmap_level_1[y / 2 * 2 + x / 2];
+ break;
+ case level_2:
+ expected_color = *bitmap_level_2;
+ break;
+ case lerp_1_2:
+ expected_color = bitmap_lerp_1_2[y * 4 + x];
+ break;
+ default:
+ expected_color = 0xdeadbeef;
+ break;
+ }
+
+ ok(compare_color(color, expected_color, 1),
+ "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
+ }
+ }
+ release_texture_readback(&rb);
+ }
+ ID3D11SamplerState_Release(sampler);
+
+ ID3D11ShaderResourceView_Release(srv);
+ ID3D11Texture2D_Release(texture);
+ ID3D11Buffer_Release(cb);
+ ID3D11PixelShader_Release(ps);
+ ID3D11VertexShader_Release(vs);
+ ID3D11Buffer_Release(vb);
+ ID3D11InputLayout_Release(input_layout);
+ ID3D11RenderTargetView_Release(rtv);
+ ID3D11Texture2D_Release(backbuffer);
+ ID3D11DeviceContext_Release(context);
+ IDXGISwapChain_Release(swapchain);
+ refcount = ID3D11Device_Release(device);
+ ok(!refcount, "Device has %u references left.\n", refcount);
+ DestroyWindow(window);
+}
+
START_TEST(d3d11)
{
test_create_device();
@@ -4179,4 +4524,5 @@ START_TEST(d3d11)
test_fragment_coords();
test_update_subresource();
test_resource_map();
+ test_sample_l();
}
--
2.4.10
More information about the wine-patches
mailing list