diff options
| author | Yong He <yonghe@outlook.com> | 2023-02-27 15:18:07 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-27 15:18:07 -0800 |
| commit | a3ba22b51c371d5a20d61aa4e35233ba4f4f68db (patch) | |
| tree | 704f8e9575fdd888d01137054b4c3887aaac9360 /tests | |
| parent | b1b76f06ca5bdfc4b688d99095dfb7d561a04d80 (diff) | |
Detect and deduplicate read-only resource access. (#2680)
* Detect and deduplicate read-only resource access.
* Fix tests.
* Fix tests.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/autodiff/global-param-hoisting.slang | 42 | ||||
| -rw-r--r-- | tests/autodiff/global-param-hoisting.slang.expected.txt | 6 | ||||
| -rw-r--r-- | tests/bindings/glsl-parameter-blocks.slang.glsl | 51 | ||||
| -rw-r--r-- | tests/bindings/multiple-parameter-blocks.slang | 9 | ||||
| -rw-r--r-- | tests/bugs/texture2d-ms.hlsl | 4 | ||||
| -rw-r--r-- | tests/bugs/texture2d-ms.hlsl.glsl | 15 | ||||
| -rw-r--r-- | tests/cross-compile/array-of-buffers.slang.glsl | 10 | ||||
| -rw-r--r-- | tests/cross-compile/array-of-buffers.slang.hlsl | 10 |
8 files changed, 87 insertions, 60 deletions
diff --git a/tests/autodiff/global-param-hoisting.slang b/tests/autodiff/global-param-hoisting.slang new file mode 100644 index 000000000..72a9494fe --- /dev/null +++ b/tests/autodiff/global-param-hoisting.slang @@ -0,0 +1,42 @@ +// Test that the compiler can hoist the texture sample out of the loop. +// We currently have no way to verify the hoist actually take place, but this test +// allows us to manually inspect the generated code to see that happen. +// TODO: use a pattern checker on the resulting code to make sure there is only +// one call to `SampleLevel`. + +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -shaderobj + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<float> outputBuffer; + +struct Params : IDifferentiable +{ + Texture2D tex; + SamplerState sampler; +} + +//TEST_INPUT:set gParams = new Params{Texture2D(size=4, content=one), Sampler} +ParameterBlock<Params> gParams; + +[BackwardDifferentiable] +float f(float x) +{ + float sum = 0.0; + for (int i = 0; i < 3; i++) + { + float t = (no_diff gParams.tex.SampleLevel(gParams.sampler, float2(0.0), 0)).x; + sum += t * x * x; + } + return sum; +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + var dpa = diffPair(3.0); + + __bwd_diff(f)(dpa, 1.0); + outputBuffer[0] = dpa.d.x; // Expect: 18 +} diff --git a/tests/autodiff/global-param-hoisting.slang.expected.txt b/tests/autodiff/global-param-hoisting.slang.expected.txt new file mode 100644 index 000000000..05d0a2ffd --- /dev/null +++ b/tests/autodiff/global-param-hoisting.slang.expected.txt @@ -0,0 +1,6 @@ +type: float +18.000000 +0.000000 +0.000000 +0.000000 +0.000000 diff --git a/tests/bindings/glsl-parameter-blocks.slang.glsl b/tests/bindings/glsl-parameter-blocks.slang.glsl index a27fbb3db..03e4e8774 100644 --- a/tests/bindings/glsl-parameter-blocks.slang.glsl +++ b/tests/bindings/glsl-parameter-blocks.slang.glsl @@ -1,52 +1,31 @@ -//TEST_IGNORE_FILE: -#version 450 core - -#define Test Test_0 -#define a a_0 - -#define gTest gTest_0 -#define gTest_t gTest_t_0 -#define gTest_s gTest_s_0 - -#define ParameterBlock_gTest _S1 - -#define main_result _S2 -#define uv _S3 - -#define temp_a _S4 -#define temp_sample _S5 -#define temp_add _S2 - -struct Test +#version 450 +layout(row_major) uniform; +layout(row_major) buffer; +struct Test_0 { - vec4 a; + vec4 a_0; }; layout(binding = 0) -uniform ParameterBlock_gTest +layout(std140) uniform _S1 { - Test _data; -} gTest; - + Test_0 _data; +} gTest_0; layout(binding = 1) -uniform texture2D gTest_t; +uniform texture2D gTest_t_0; layout(binding = 2) -uniform sampler gTest_s; +uniform sampler gTest_s_0; layout(location = 0) -out vec4 main_result; +out vec4 _S2; layout(location = 0) -in vec2 uv; +in vec2 _S3; void main() { - vec4 temp_a = gTest._data.a; - - vec4 temp_sample = texture(sampler2D(gTest_t, gTest_s), uv); - - main_result = temp_a + temp_sample; - - return; + vec4 _S4 = (texture(sampler2D(gTest_t_0,gTest_s_0), (_S3))); + _S2 = gTest_0._data.a_0 + _S4; + return; } diff --git a/tests/bindings/multiple-parameter-blocks.slang b/tests/bindings/multiple-parameter-blocks.slang index 29eea6766..0f247319d 100644 --- a/tests/bindings/multiple-parameter-blocks.slang +++ b/tests/bindings/multiple-parameter-blocks.slang @@ -39,10 +39,11 @@ SamplerState p1_s_0 : register(s0, space1); float4 main(float v : V) : SV_TARGET { - return use(p_t_0, p_s_0) - + use(p_ta_0[int(v)], p_s_0) - + use(p1_t_0, p1_s_0) - + use(p1_ta_0[int(v)], p1_s_0); + int _S2 = int(v); + return use(p_t_0, p_s_0) + + use(p_ta_0[_S2], p_s_0) + + use(p1_t_0, p1_s_0) + + use(p1_ta_0[_S2], p1_s_0); } #endif diff --git a/tests/bugs/texture2d-ms.hlsl b/tests/bugs/texture2d-ms.hlsl index 1d8293937..3fb84f72d 100644 --- a/tests/bugs/texture2d-ms.hlsl +++ b/tests/bugs/texture2d-ms.hlsl @@ -3,8 +3,10 @@ [[vk::binding(0, 0)]] Texture2DMS tex : register(t1); +RWStructuredBuffer<float4> outBuffer; + [numthreads(4, 4, 1)] void main(uint3 groupId : SV_GroupID) { - tex.Load(int2(groupId.xy), 0); + outBuffer[0] = tex.Load(int2(groupId.xy), 0); } diff --git a/tests/bugs/texture2d-ms.hlsl.glsl b/tests/bugs/texture2d-ms.hlsl.glsl index ba0d571dd..40ce5f9de 100644 --- a/tests/bugs/texture2d-ms.hlsl.glsl +++ b/tests/bugs/texture2d-ms.hlsl.glsl @@ -1,16 +1,17 @@ -// texture2d-ms.hlsl.glsl -//TEST_IGNORE_FILE: - #version 450 +#extension GL_EXT_samplerless_texture_functions : require layout(row_major) uniform; layout(row_major) buffer; -#extension GL_EXT_samplerless_texture_functions : require layout(binding = 0) uniform texture2DMS tex_0; -layout(local_size_x = 4, local_size_y = 4, local_size_z = 1) in;void main() +layout(std430, binding = 1) buffer _S1 { + vec4 _data[]; +} outBuffer_0; +layout(local_size_x = 4, local_size_y = 4, local_size_z = 1) in; +void main() { - vec4 _S1 = (texelFetch((tex_0), (ivec2(gl_WorkGroupID.xy)), (0))); + vec4 _S2 = (texelFetch((tex_0), (ivec2(gl_WorkGroupID.xy)), (0))); + ((outBuffer_0)._data[(0U)]) = _S2; return; } - diff --git a/tests/cross-compile/array-of-buffers.slang.glsl b/tests/cross-compile/array-of-buffers.slang.glsl index 21961afd1..4ff86f36e 100644 --- a/tests/cross-compile/array-of-buffers.slang.glsl +++ b/tests/cross-compile/array-of-buffers.slang.glsl @@ -36,11 +36,9 @@ out vec4 _S6; void main() { - vec4 _S7 = cb_0[C_0._data.index_0]._data.f_0; - S_0 _S8 = ((sb1_0[C_0._data.index_0])._data[(C_0._data.index_0)]); - vec4 _S9 = _S7 + _S8.f_0; - vec4 _S10 = _S9 + ((sb2_0[C_0._data.index_0])._data[(C_0._data.index_0)]); - uint _S11 = ((bb_0[C_0._data.index_0])._data[(int(C_0._data.index_0 * 4U))/4]); - _S6 = _S10 + vec4(float(_S11)); + S_0 _S7 = ((sb1_0[C_0._data.index_0])._data[(C_0._data.index_0)]); + vec4 _S8 = cb_0[C_0._data.index_0]._data.f_0 + _S7.f_0; + uint _S9 = ((bb_0[C_0._data.index_0])._data[(int(C_0._data.index_0 * 4U))/4]); + _S6 = _S8 + ((sb2_0[C_0._data.index_0])._data[(C_0._data.index_0)]) + vec4(float(_S9)); return; } diff --git a/tests/cross-compile/array-of-buffers.slang.hlsl b/tests/cross-compile/array-of-buffers.slang.hlsl index 960957789..e709d323a 100644 --- a/tests/cross-compile/array-of-buffers.slang.hlsl +++ b/tests/cross-compile/array-of-buffers.slang.hlsl @@ -27,10 +27,8 @@ RWStructuredBuffer<float4 > sb2_0[int(5)] : register(u0); ByteAddressBuffer bb_0[int(6)] : register(t4); float4 main() : SV_TARGET { - float4 _S1 = cb_0[C_0.index_0].f_0; - S_0 _S2 = sb1_0[C_0.index_0][C_0.index_0]; - float4 _S3 = _S1 + _S2.f_0; - float4 _S4 = _S3 + sb2_0[C_0.index_0][C_0.index_0]; - uint _S5 = bb_0[C_0.index_0].Load(int(C_0.index_0 * 4U)); - return _S4 + (float4)float(_S5); + S_0 _S1 = sb1_0[C_0.index_0][C_0.index_0]; + float4 _S2 = cb_0[C_0.index_0].f_0 + _S1.f_0; + uint _S3 = bb_0[C_0.index_0].Load(int(C_0.index_0 * 4U)); + return _S2 + sb2_0[C_0.index_0][C_0.index_0] + (float4)float(_S3); } |
