[PATCH 4/9] d3d11/tests: Add test for sample_c_lz instruction.
Józef Kucia
joseph.kucia at gmail.com
Mon Nov 6 03:55:23 CST 2017
From: Józef Kucia <jkucia at codeweavers.com>
Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
dlls/d3d11/tests/d3d11.c | 312 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 312 insertions(+)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c
index 900f4893071f..75bff6433633 100644
--- a/dlls/d3d11/tests/d3d11.c
+++ b/dlls/d3d11/tests/d3d11.c
@@ -7459,6 +7459,317 @@ static void test_depth_stencil_sampling(void)
release_test_context(&test_context);
}
+static void test_sample_c_lz(void)
+{
+ D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
+ D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
+ struct d3d11_test_context test_context;
+ ID3D11Texture2D *texture, *rt_texture;
+ D3D11_TEXTURE2D_DESC texture_desc;
+ D3D11_SAMPLER_DESC sampler_desc;
+ ID3D11ShaderResourceView *srv;
+ ID3D11DeviceContext *context;
+ ID3D11DepthStencilView *dsv;
+ ID3D11RenderTargetView *rtv;
+ ID3D11SamplerState *sampler;
+ struct vec4 ps_constant;
+ ID3D11PixelShader *ps;
+ ID3D11Device *device;
+ ID3D11Buffer *cb;
+ unsigned int i;
+ HRESULT hr;
+ RECT rect;
+
+ static const float clear_color[] = {0.5f, 0.5f, 0.5f, 0.5f};
+ static const DWORD ps_array_code[] =
+ {
+#if 0
+ Texture2DArray t;
+ SamplerComparisonState s;
+
+ float ref;
+ float layer;
+
+ float4 main(float4 position : SV_Position) : SV_Target
+ {
+ return t.SampleCmpLevelZero(s, float3(position.x / 640.0f, position.y / 480.0f, layer), ref);
+ }
+#endif
+ 0x43425844, 0xfe28b3c3, 0xdd7ef404, 0x8d5874a1, 0x984ff182, 0x00000001, 0x00000180, 0x00000003,
+ 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
+ 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
+ 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000e4, 0x00000041,
+ 0x00000039, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000,
+ 0x00000000, 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
+ 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
+ 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
+ 0x06000036, 0x00100042, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0c000047, 0x00100012,
+ 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000, 0x0020800a,
+ 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
+ };
+ static const DWORD ps_cube_code[] =
+ {
+#if 0
+ TextureCube t;
+ SamplerComparisonState s;
+
+ float ref;
+ float face;
+
+ float4 main(float4 position : SV_Position) : SV_Target
+ {
+ float2 p;
+ p.x = position.x / 640.0f;
+ p.y = position.y / 480.0f;
+
+ float3 coord;
+ switch ((uint)face)
+ {
+ case 0:
+ coord = float3(1.0f, p.x, p.y);
+ break;
+ case 1:
+ coord = float3(-1.0f, p.x, p.y);
+ break;
+ case 2:
+ coord = float3(p.x, 1.0f, p.y);
+ break;
+ case 3:
+ coord = float3(p.x, -1.0f, p.y);
+ break;
+ case 4:
+ coord = float3(p.x, p.y, 1.0f);
+ break;
+ case 5:
+ default:
+ coord = float3(p.x, p.y, -1.0f);
+ break;
+ }
+
+ return t.SampleCmpLevelZero(s, coord, ref);
+ }
+#endif
+ 0x43425844, 0xde5655e5, 0x1b116fa1, 0xfce9e757, 0x41c28aac, 0x00000001, 0x00000328, 0x00000003,
+ 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
+ 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
+ 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
+ 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000,
+ 0x00000000, 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
+ 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600001c, 0x00100012,
+ 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0300004c, 0x0010000a, 0x00000000, 0x03000006,
+ 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x3f800000, 0x0a000038,
+ 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889,
+ 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036, 0x00100012, 0x00000000,
+ 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
+ 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000002,
+ 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000,
+ 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
+ 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
+ 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
+ 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004, 0x0a000038, 0x00100032,
+ 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
+ 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002, 0x0100000a, 0x0a000038,
+ 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000,
+ 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x01000017,
+ 0x0c000047, 0x00100012, 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000,
+ 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006,
+ 0x00000000, 0x0100003e,
+ };
+ static const float depth_values[] = {1.0f, 0.0f, 0.5f, 0.6f, 0.4f, 0.1f};
+ static const struct
+ {
+ unsigned int layer;
+ float d_ref;
+ float expected;
+ }
+ tests[] =
+ {
+ {0, 0.5f, 0.0f},
+ {1, 0.5f, 1.0f},
+ {2, 0.5f, 0.0f},
+ {3, 0.5f, 0.0f},
+ {4, 0.5f, 1.0f},
+ {5, 0.5f, 1.0f},
+
+ {0, 0.0f, 0.0f},
+ {1, 0.0f, 0.0f},
+ {2, 0.0f, 0.0f},
+ {3, 0.0f, 0.0f},
+ {4, 0.0f, 0.0f},
+ {5, 0.0f, 0.0f},
+
+ {0, 1.0f, 0.0f},
+ {1, 1.0f, 1.0f},
+ {2, 1.0f, 1.0f},
+ {3, 1.0f, 1.0f},
+ {4, 1.0f, 1.0f},
+ {5, 1.0f, 1.0f},
+ };
+
+ if (!init_test_context(&test_context, NULL))
+ return;
+
+ device = test_context.device;
+ context = test_context.immediate_context;
+
+ sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR;
+ 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_GREATER;
+ 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 = 10.0f;
+ hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
+ ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
+
+ ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
+ texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
+ hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
+ ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
+ hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
+ ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
+ ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
+
+ memset(&ps_constant, 0, sizeof(ps_constant));
+ cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
+
+ /* 2D array texture */
+ texture_desc.Width = 32;
+ texture_desc.Height = 32;
+ texture_desc.MipLevels = 2;
+ texture_desc.ArraySize = ARRAY_SIZE(depth_values);
+ texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
+ texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
+ texture_desc.MiscFlags = 0;
+ hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
+ ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
+
+ for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
+ {
+ dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
+ dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
+ dsv_desc.Flags = 0;
+ U(dsv_desc).Texture2DArray.MipSlice = 0;
+ U(dsv_desc).Texture2DArray.FirstArraySlice = i;
+ U(dsv_desc).Texture2DArray.ArraySize = 1;
+
+ hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
+ ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
+ ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, depth_values[i], 0);
+ ID3D11DepthStencilView_Release(dsv);
+
+ U(dsv_desc).Texture2DArray.MipSlice = 1;
+ hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
+ ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
+ ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
+ ID3D11DepthStencilView_Release(dsv);
+ }
+
+ srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
+ srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
+ U(srv_desc).Texture2DArray.MostDetailedMip = 0;
+ U(srv_desc).Texture2DArray.MipLevels = ~0u;
+ U(srv_desc).Texture2DArray.FirstArraySlice = 0;
+ U(srv_desc).Texture2DArray.ArraySize = ~0u;
+ hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
+ ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
+
+ hr = ID3D11Device_CreatePixelShader(device, ps_array_code, sizeof(ps_array_code), NULL, &ps);
+ ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
+
+ ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
+ ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
+ ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
+ ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
+
+ for (i = 0; i < ARRAY_SIZE(tests); ++i)
+ {
+ ps_constant.x = tests[i].d_ref;
+ ps_constant.y = tests[i].layer;
+ ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
+ NULL, &ps_constant, 0, 0);
+ ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
+ draw_quad(&test_context);
+ check_texture_float(rt_texture, tests[i].expected, 2);
+ }
+
+ ID3D11Texture2D_Release(texture);
+ ID3D11ShaderResourceView_Release(srv);
+ ID3D11PixelShader_Release(ps);
+
+ /* cube texture */
+ texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
+ hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
+ ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
+
+ for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
+ {
+ dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
+ dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
+ dsv_desc.Flags = 0;
+ U(dsv_desc).Texture2DArray.MipSlice = 0;
+ U(dsv_desc).Texture2DArray.FirstArraySlice = i;
+ U(dsv_desc).Texture2DArray.ArraySize = 1;
+
+ hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
+ ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
+ ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, depth_values[i], 0);
+ ID3D11DepthStencilView_Release(dsv);
+
+ U(dsv_desc).Texture2DArray.MipSlice = 1;
+ hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
+ ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
+ ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
+ ID3D11DepthStencilView_Release(dsv);
+ }
+
+ srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
+ srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
+ U(srv_desc).TextureCube.MostDetailedMip = 0;
+ U(srv_desc).TextureCube.MipLevels = ~0u;
+ hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
+ ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
+
+ hr = ID3D11Device_CreatePixelShader(device, ps_cube_code, sizeof(ps_cube_code), NULL, &ps);
+ ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
+
+ ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
+ ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
+ ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
+ ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
+
+ for (i = 0; i < ARRAY_SIZE(tests); ++i)
+ {
+ ps_constant.x = tests[i].d_ref;
+ ps_constant.y = tests[i].layer;
+ ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
+ NULL, &ps_constant, 0, 0);
+ ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
+ draw_quad(&test_context);
+ /* Avoid testing values affected by seamless cube map filtering. */
+ SetRect(&rect, 100, 100, 540, 380);
+ check_texture_sub_resource_float(rt_texture, 0, &rect, tests[i].expected, 2);
+ }
+
+ ID3D11Texture2D_Release(texture);
+ ID3D11ShaderResourceView_Release(srv);
+
+ ID3D11Buffer_Release(cb);
+ ID3D11PixelShader_Release(ps);
+ ID3D11RenderTargetView_Release(rtv);
+ ID3D11SamplerState_Release(sampler);
+ ID3D11Texture2D_Release(rt_texture);
+ release_test_context(&test_context);
+}
+
static void test_multiple_render_targets(void)
{
D3D11_TEXTURE2D_DESC texture_desc;
@@ -21756,6 +22067,7 @@ START_TEST(d3d11)
test_texture();
test_cube_maps();
test_depth_stencil_sampling();
+ test_sample_c_lz();
test_multiple_render_targets();
test_render_target_views();
test_layered_rendering();
--
2.13.6
More information about the wine-patches
mailing list