From bdfa14d219c68aab54a3a8a5ddcb8a99698332e7 Mon Sep 17 00:00:00 2001 From: Conor McCarthy Date: Thu, 21 Mar 2024 11:21:12 +1000 Subject: [PATCH] tests/hlsl: Add tests for CalculateLevelOfDetail(). Includes improvements made by Giovanni Mascellani. --- Makefile.am | 1 + tests/hlsl/calculate-lod.shader_test | 84 ++++++++++++++++++++++++++++ tests/shader_runner_d3d11.c | 2 +- tests/shader_runner_d3d12.c | 2 +- 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 tests/hlsl/calculate-lod.shader_test diff --git a/Makefile.am b/Makefile.am index ead3c1f5..995f70b2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -65,6 +65,7 @@ vkd3d_shader_tests = \ tests/hlsl/bitwise.shader_test \ tests/hlsl/bool-cast.shader_test \ tests/hlsl/bool-semantics.shader_test \ + tests/hlsl/calculate-lod.shader_test \ tests/hlsl/cast-64-bit.shader_test \ tests/hlsl/cast-broadcast.shader_test \ tests/hlsl/cast-componentwise-compatible.shader_test \ diff --git a/tests/hlsl/calculate-lod.shader_test b/tests/hlsl/calculate-lod.shader_test new file mode 100644 index 00000000..807776ee --- /dev/null +++ b/tests/hlsl/calculate-lod.shader_test @@ -0,0 +1,84 @@ +[require] +shader model >= 4.1 + + +[sampler 0] +filter linear linear linear +address clamp clamp clamp + +[srv 0] +size (2d, 4, 4) +levels 3 + +0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 +0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 +0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 +0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 + + +[pixel shader todo] +sampler s; +Texture2D t; + +float4 main(float4 pos : sv_position) : sv_target +{ + return float4(t.CalculateLevelOfDetail(s, pos.xy), + t.CalculateLevelOfDetail(s, float2(0.5 * pos.x, 0.5 * pos.y)), + t.CalculateLevelOfDetail(s, float2(0.25 * pos.x, 0.25 * pos.y)), + floor(10.0 * t.CalculateLevelOfDetail(s, float2(0.1 * pos.x, 0.7 * pos.y)))); +} + +[test] +todo draw quad +probe all rgba (2.0, 1.0, 0.0, 14.0) + + +[pixel shader todo] +sampler s; +Texture2D t; + +float4 main(float4 pos : sv_position) : sv_target +{ + return float4(t.CalculateLevelOfDetail(s, float2(3.0 * pos.x, 5.0 * pos.y)), + t.CalculateLevelOfDetail(s, float2(10.0 * pos.x, 10.0 * pos.y)), + t.CalculateLevelOfDetail(s, float2(0.1 * pos.x, 0.02 * pos.y)), + t.CalculateLevelOfDetail(s, float2(0.01 * pos.x, 0.01 * pos.y))); +} + +[test] +todo draw quad +probe all rgba (2.0, 2.0, 0.0, 0.0) + + +[pixel shader todo] +sampler s; +Texture2D t; + +float4 main(float4 pos : sv_position) : sv_target +{ + return float4(t.CalculateLevelOfDetailUnclamped(s, pos.xy), + t.CalculateLevelOfDetailUnclamped(s, float2(0.5 * pos.x, 0.5 * pos.y)), + t.CalculateLevelOfDetailUnclamped(s, float2(0.25 * pos.x, 0.25 * pos.y)), + floor(10.0 * t.CalculateLevelOfDetailUnclamped(s, float2(0.1 * pos.x, 0.7 * pos.y)))); +} + +[test] +todo draw quad +probe all rgba (2.0, 1.0, 0.0, 14.0) + + +[pixel shader todo] +sampler s; +Texture2D t; + +float4 main(float4 pos : sv_position) : sv_target +{ + return float4(floor(10.0 * t.CalculateLevelOfDetailUnclamped(s, float2(3.0 * pos.x, 6.0 * pos.y))), + floor(10.0 * t.CalculateLevelOfDetailUnclamped(s, float2(8.0 * pos.x, 8.0 * pos.y))), + floor(10.0 * t.CalculateLevelOfDetailUnclamped(s, float2(0.1 * pos.x, 0.02 * pos.y))), + floor(10.0 * t.CalculateLevelOfDetailUnclamped(s, float2(0.01 * pos.x, 0.01 * pos.y)))); +} + +[test] +todo draw quad +probe all rgba (45.0, 50.0, -14.0, -47.0) diff --git a/tests/shader_runner_d3d11.c b/tests/shader_runner_d3d11.c index 1285ca41..b26d6a36 100644 --- a/tests/shader_runner_d3d11.c +++ b/tests/shader_runner_d3d11.c @@ -358,7 +358,7 @@ static ID3D11Buffer *create_buffer(ID3D11Device *device, unsigned int bind_flags static void init_resource_2d(struct d3d11_shader_runner *runner, struct d3d11_resource *resource, const struct resource_params *params) { - D3D11_SUBRESOURCE_DATA resource_data[2]; + D3D11_SUBRESOURCE_DATA resource_data[3]; ID3D11Device *device = runner->device; D3D11_TEXTURE2D_DESC desc = {0}; HRESULT hr; diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index 9bf7bb24..56844ae3 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -104,7 +104,7 @@ static struct resource *d3d12_runner_create_resource(struct shader_runner *r, co struct d3d12_shader_runner *runner = d3d12_shader_runner(r); struct test_context *test_context = &runner->test_context; ID3D12Device *device = test_context->device; - D3D12_SUBRESOURCE_DATA resource_data[2] = {0}; + D3D12_SUBRESOURCE_DATA resource_data[3] = {0}; struct d3d12_resource *resource; unsigned int buffer_offset = 0; D3D12_RESOURCE_STATES state;