From 125bf74ef3937eff583998070516169c90d923eb Mon Sep 17 00:00:00 2001 From: Francisco Casas Date: Thu, 22 Aug 2024 21:10:29 -0400 Subject: [PATCH] tests: Test sampler_state keyword syntax. --- Makefile.am | 1 + tests/hlsl/sampler-state.shader_test | 234 +++++++++++++++++++++++++++ 2 files changed, 235 insertions(+) create mode 100644 tests/hlsl/sampler-state.shader_test diff --git a/Makefile.am b/Makefile.am index cf8b645d..a790243a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -207,6 +207,7 @@ vkd3d_shader_tests = \ tests/hlsl/sample-grad.shader_test \ tests/hlsl/sample-level.shader_test \ tests/hlsl/sampler-offset.shader_test \ + tests/hlsl/sampler-state.shader_test \ tests/hlsl/sampler.shader_test \ tests/hlsl/saturate.shader_test \ tests/hlsl/shade-mode.shader_test \ diff --git a/tests/hlsl/sampler-state.shader_test b/tests/hlsl/sampler-state.shader_test new file mode 100644 index 00000000..77a26d66 --- /dev/null +++ b/tests/hlsl/sampler-state.shader_test @@ -0,0 +1,234 @@ +[require] +options: backcompat + + +[pixel shader todo fail(sm>=6)] +sampler2D sam = sampler_state +{ + texture = NULL; + mipfilter = LINEAR; +}; + +float4 main(): sv_target +{ + return tex2D(sam, float2(0, 0)); +} + + +[pixel shader fail] +float4 main(): sv_target +{ + sampler2D sam = sampler_state // Not allowed inside a function. + { + texture = NULL; + mipfilter = LINEAR; + }; + + return 0; +} + +[pixel shader fail] +sampler sam; + +float4 main(): sv_target +{ + sampler_state + { + foo = BAR; + bar = FOO; + }; + return tex2D(sam, float2(0, 0)); +} + +[pixel shader fail(sm<6)] +// cannot implicitly convert. +float4 f = sampler_state +{ + texture = NULL; + mipfilter = LINEAR; +}; + +float4 main(): sv_target +{ + return 0; +} + + +[pixel shader todo fail(sm>=6)] +sampler sam[2] = +{ + sampler_state + { + texture = NULL; + mipfilter = LINEAR; + }, + sampler_state + { + texture = NULL; + mipfilter = LINEAR; + } +}; + +float4 main(): sv_target +{ + return tex2D(sam[1], float2(0, 0)); +} + + +[pixel shader fail] +sampler sam[2] = +{ + sampler_state + { + texture = NULL; + mipfilter = LINEAR; + }, +}; + +float4 main(): sv_target { return 0; } + + +[pixel shader todo] +sampler sam +{ + FOO = sampler_state {}; +}; + +float4 main(): sv_target { return 0; } + + +[pixel shader fail] +Texture2D tex; + +float4 main(): sv_target +{ + return tex.Sample(sampler_state {}, float2(0, 0)); +} + + +[pixel shader todo fail(sm>=6)] +sampler sam = sampler_state +{ + texture = NULL; + mipfilter = LINEAR; +}; + +float4 main(): sv_target +{ + sampler sam2 = sam; // pass around. + + return tex2D(sam2, float2(0, 0)); +} + + +[pixel shader todo fail(sm>=6)] +sampler sam = sampler_state +{ + foo = BAR; + bar = FOO; + mipfilter = PLACEHOLDER; +}; + +float4 main(): sv_target +{ + return tex2D(sam, float2(0, 0)); +} + + +[pixel shader todo fail(sm>=6)] +// default value initializers make it more permissive but if types don't match +// then the whole initializer is discarded. +float4 f = { + sampler_state + { + foo = BAR; + bar = FOO; + }, + 1, 2, 3 +}; + +float4 main(): sv_target +{ + return 0; +} + + +[pixel shader fail] +sampler sam {} = sampler_state {}; + +float4 main() : sv_target { return 0; } + + +% This fails because of invalid types. +[pixel shader fail] +sampler sam = 1 + sampler_state {}; + +float4 main() : sv_target { return 0; } + + +[pixel shader fail] +sampler sam; +sampler_state {} = sam; + +float4 main() : sv_target +{ + return 0; +} + +[pixel shader fail] +sampler_state {}; + +float4 main() : sv_target +{ + return 0; +} + + +[require] +shader model < 6.0 +options: backcompat + +[pixel shader fail] +// Cannot implicitly convert. +// Causes segfault in DXC +Texture2D tex = sampler_state +{ + foo = BAR; + bar = FOO; +}; +sampler sam; + +float4 main(): sv_target +{ + return tex2D(sam, float2(0, 0)); +} + + +[require] +shader model >= 5.0 +options: backcompat + +[pixel shader todo fail(sm>=6)] +// Default values and sample_state work. +// Requires sm5. + +struct +{ + float4 f; + sampler sam; + float2 g; +} apple = { + 1, 2, 3, 4, + sampler_state + { + texture = NULL; + mipfilter = LINEAR; + }, + 1, 1, +}; +Texture2D tex; + +float4 main(): sv_target +{ + return tex.Sample(apple.sam, apple.g); +}