summaryrefslogtreecommitdiff
path: root/tools/gfx-unit-test/format-test-shaders.slang
diff options
context:
space:
mode:
authorlucy96chen <47800040+lucy96chen@users.noreply.github.com>2021-10-26 16:30:59 -0700
committerGitHub <noreply@github.com>2021-10-26 16:30:59 -0700
commitdcc2b854a64b3e4e890215ff21cf4b219724f524 (patch)
treefe958a184f46f4a1bbf10f6c7174d31283df76dc /tools/gfx-unit-test/format-test-shaders.slang
parentfe6d5f1cf8865567e08cf210a2639ffde2886fc3 (diff)
Expanded gfx::Format to include additional formats (#1982)
* Format list updated with additional formats supported by both D3D and Vulkan; D3DUtil::getMapFormat() and VkUtil::getVkFormat() updated to include additional formats; GFX_FORMAT() updated with all additional formats (BC compression unfinished) * Finished updating GFX_FORMAT with newly added formats and sizes; Pixel size is now tracked using the FormatPixelSize struct containing the values for bytes per block and pixels per block to accomodate BC formats; Updated gfxGetFormatSize and associated sub-calls to return FormatPixelSize instead of uint8_t; Most calls to gfxGetFormatSize() updated to reflect changes, a couple calls still unupdated * Changes to accommodate new formats finished, debugging slang-literal unit test * First format unit test working * One test added for BC1Unorm and RGBA8Unorm_SRGB, both passing * Refactored format testing code to merge BC1Unorm and RGBA8Unorm SRGB into a single file * All unit tests added for BC and Srgb formats * Most tests added and working; Added five additional formats (still need tests) and made the appropriate changes to support these; createTextureView() modified for D3D11, D3D12, and Vulkan to take into account the format specified in the texture view desc when the texture's format is typeless * Format enums renamed to more closely match their D3D counterparts; Added a universal float and uint buffer and buffer view for use across all Format tests * Remaining tests added; D3D12 tests pass, but Vulkan crashes in BC1_UNORM and D3D11 spits out a bunch of D3D11 Errors (but supposedly passes) * re-run premake * Added Sint versions of test shaders; Vulkan and D3D11 tests also pass * Size struct for format unit tests no longer use initializer lists * Fixed a Size struct missed in the previous pass * Fixed minor bugs causing tests to fail * Added documentation detailing all currently unsupported formats * Skip tests causing unsupported format warnings due to swiftshader * updated several test using old Format enum names * Revert change to compareComputeResult() that was added for debugging purposes * DEBUGGING: Added prints to identify which formats are failing on CI * Reverted attempted debugging changes; Fixed texture2d-gather.hlsl to use updated Format enums * Fixed incorrect array sizes in d3d11 _initSrvDesc() * Commented out further tests that produce unexpected results when tested for Vulkan with swiftshader * Revert "Merge branch 'expanded-format-support' of https://github.com/lucy96chen/slang into expanded-format-support" This reverts commit 20008f0d3ecc3b1405ecac8c138edaa3cd37ed6b, reversing changes made to 6081e95827315fee50e18409394d5abd62fac787. * Added a fuzzy comparison function for use with floats * submodule update * Revert messed up changes caused by previous revert after automatically merging on github
Diffstat (limited to 'tools/gfx-unit-test/format-test-shaders.slang')
-rw-r--r--tools/gfx-unit-test/format-test-shaders.slang220
1 files changed, 220 insertions, 0 deletions
diff --git a/tools/gfx-unit-test/format-test-shaders.slang b/tools/gfx-unit-test/format-test-shaders.slang
new file mode 100644
index 000000000..49d4f6b69
--- /dev/null
+++ b/tools/gfx-unit-test/format-test-shaders.slang
@@ -0,0 +1,220 @@
+// format-test-shaders.slang - Shaders used by the unit tests in format-uint-tests.cpp
+
+// Copy the contents of "tex" into "buffer". These are for textures containing UINT data.
+[shader("compute")]
+[numthreads(4,1,1)]
+void copyTexUint4(
+ uint3 sv_dispatchThreadID : SV_DispatchThreadID,
+ uniform Texture2D<uint4> tex,
+ uniform RWStructuredBuffer<uint> buffer)
+{
+ uint width;
+ uint height;
+ tex.GetDimensions(width, height);
+ uint4 result = tex[uint2(sv_dispatchThreadID.x % width, sv_dispatchThreadID.x / width)];
+ buffer[sv_dispatchThreadID.x * 4] = result.r;
+ buffer[sv_dispatchThreadID.x * 4 + 1] = result.g;
+ buffer[sv_dispatchThreadID.x * 4 + 2] = result.b;
+ buffer[sv_dispatchThreadID.x * 4 + 3] = result.a;
+}
+
+[shader("compute")]
+[numthreads(4,1,1)]
+void copyTexUint3(
+ uint3 sv_dispatchThreadID : SV_DispatchThreadID,
+ uniform Texture2D<uint4> tex,
+ uniform RWStructuredBuffer<uint> buffer)
+{
+ uint width;
+ uint height;
+ tex.GetDimensions(width, height);
+ uint4 result = tex[uint2(sv_dispatchThreadID.x % width, sv_dispatchThreadID.x / width)];
+ buffer[sv_dispatchThreadID.x * 3] = result.r;
+ buffer[sv_dispatchThreadID.x * 3 + 1] = result.g;
+ buffer[sv_dispatchThreadID.x * 3 + 2] = result.b;
+}
+
+[shader("compute")]
+[numthreads(4,1,1)]
+void copyTexUint2(
+ uint3 sv_dispatchThreadID : SV_DispatchThreadID,
+ uniform Texture2D<uint2> tex,
+ uniform RWStructuredBuffer<uint> buffer)
+{
+ uint width;
+ uint height;
+ tex.GetDimensions(width, height);
+ uint2 result = tex[uint2(sv_dispatchThreadID.x % width, sv_dispatchThreadID.x / width)];
+ buffer[sv_dispatchThreadID.x * 2] = result.r;
+ buffer[sv_dispatchThreadID.x * 2 + 1] = result.g;
+}
+
+[shader("compute")]
+[numthreads(4,1,1)]
+void copyTexUint(
+ uint3 sv_dispatchThreadID : SV_DispatchThreadID,
+ uniform Texture2D<uint> tex,
+ uniform RWStructuredBuffer<uint> buffer)
+{
+ uint width;
+ uint height;
+ tex.GetDimensions(width, height);
+ buffer[sv_dispatchThreadID.x] = tex[uint2(sv_dispatchThreadID.x % width, sv_dispatchThreadID.x / width)];
+}
+
+// Copy the contents of "tex" into "buffer". These are for textures containing SINT data.
+[shader("compute")]
+[numthreads(4,1,1)]
+void copyTexInt4(
+ uint3 sv_dispatchThreadID : SV_DispatchThreadID,
+ uniform Texture2D<int4> tex,
+ uniform RWStructuredBuffer<int> buffer)
+{
+ uint width;
+ uint height;
+ tex.GetDimensions(width, height);
+ int4 result = tex[uint2(sv_dispatchThreadID.x % width, sv_dispatchThreadID.x / width)];
+ buffer[sv_dispatchThreadID.x * 4] = result.r;
+ buffer[sv_dispatchThreadID.x * 4 + 1] = result.g;
+ buffer[sv_dispatchThreadID.x * 4 + 2] = result.b;
+ buffer[sv_dispatchThreadID.x * 4 + 3] = result.a;
+}
+
+[shader("compute")]
+[numthreads(4,1,1)]
+void copyTexInt3(
+ uint3 sv_dispatchThreadID : SV_DispatchThreadID,
+ uniform Texture2D<int4> tex,
+ uniform RWStructuredBuffer<int> buffer)
+{
+ uint width;
+ uint height;
+ tex.GetDimensions(width, height);
+ int4 result = tex[uint2(sv_dispatchThreadID.x % width, sv_dispatchThreadID.x / width)];
+ buffer[sv_dispatchThreadID.x * 3] = result.r;
+ buffer[sv_dispatchThreadID.x * 3 + 1] = result.g;
+ buffer[sv_dispatchThreadID.x * 3 + 2] = result.b;
+}
+
+[shader("compute")]
+[numthreads(4,1,1)]
+void copyTexInt2(
+ uint3 sv_dispatchThreadID : SV_DispatchThreadID,
+ uniform Texture2D<int2> tex,
+ uniform RWStructuredBuffer<int> buffer)
+{
+ uint width;
+ uint height;
+ tex.GetDimensions(width, height);
+ int2 result = tex[uint2(sv_dispatchThreadID.x % width, sv_dispatchThreadID.x / width)];
+ buffer[sv_dispatchThreadID.x * 2] = result.r;
+ buffer[sv_dispatchThreadID.x * 2 + 1] = result.g;
+}
+
+[shader("compute")]
+[numthreads(4,1,1)]
+void copyTexInt(
+ uint3 sv_dispatchThreadID : SV_DispatchThreadID,
+ uniform Texture2D<int> tex,
+ uniform RWStructuredBuffer<int> buffer)
+{
+ uint width;
+ uint height;
+ tex.GetDimensions(width, height);
+ buffer[sv_dispatchThreadID.x] = tex[uint2(sv_dispatchThreadID.x % width, sv_dispatchThreadID.x / width)];
+}
+
+// Copy the contents of "tex" into "buffer". These are for textures containing FLOAT data.
+[shader("compute")]
+[numthreads(4,1,1)]
+void copyTexFloat4(
+ uint3 sv_dispatchThreadID : SV_DispatchThreadID,
+ uniform Texture2D<float4> tex,
+ uniform RWStructuredBuffer<float> buffer)
+{
+ uint width;
+ uint height;
+ tex.GetDimensions(width, height);
+ float4 result = tex[uint2(sv_dispatchThreadID.x % width, sv_dispatchThreadID.x / width)];
+ buffer[sv_dispatchThreadID.x * 4] = result.r;
+ buffer[sv_dispatchThreadID.x * 4 + 1] = result.g;
+ buffer[sv_dispatchThreadID.x * 4 + 2] = result.b;
+ buffer[sv_dispatchThreadID.x * 4 + 3] = result.a;
+}
+
+[shader("compute")]
+[numthreads(4,1,1)]
+void copyTexFloat3(
+ uint3 sv_dispatchThreadID : SV_DispatchThreadID,
+ uniform Texture2D<float4> tex,
+ uniform RWStructuredBuffer<float> buffer)
+{
+ uint width;
+ uint height;
+ tex.GetDimensions(width, height);
+ float4 result = tex[uint2(sv_dispatchThreadID.x % width, sv_dispatchThreadID.x / width)];
+ buffer[sv_dispatchThreadID.x * 3] = result.r;
+ buffer[sv_dispatchThreadID.x * 3 + 1] = result.g;
+ buffer[sv_dispatchThreadID.x * 3 + 2] = result.b;
+}
+
+[shader("compute")]
+[numthreads(4,1,1)]
+void copyTexFloat2(
+ uint3 sv_dispatchThreadID : SV_DispatchThreadID,
+ uniform Texture2D<float2> tex,
+ uniform RWStructuredBuffer<float> buffer)
+{
+ uint width;
+ uint height;
+ tex.GetDimensions(width, height);
+ float2 result = tex[uint2(sv_dispatchThreadID.x % width, sv_dispatchThreadID.x / width)];
+ buffer[sv_dispatchThreadID.x * 2] = result.r;
+ buffer[sv_dispatchThreadID.x * 2 + 1] = result.g;
+}
+
+[shader("compute")]
+[numthreads(4,1,1)]
+void copyTexFloat(
+ uint3 sv_dispatchThreadID : SV_DispatchThreadID,
+ uniform Texture2D<float> tex,
+ uniform RWStructuredBuffer<float> buffer)
+{
+ uint width;
+ uint height;
+ tex.GetDimensions(width, height);
+ buffer[sv_dispatchThreadID.x] = tex[uint2(sv_dispatchThreadID.x % width, sv_dispatchThreadID.x / width)];
+}
+
+// Sample from "tex" at texture coordinates (0.5, 0.5) and save the results in "buffer".
+[shader("compute")]
+[numthreads(4,1,1)]
+void sampleTex(
+ uint3 sv_dispatchThreadID : SV_DispatchThreadID,
+ uniform Texture2D<float4> tex,
+ uniform SamplerState sampler,
+ uniform RWStructuredBuffer<float> buffer)
+{
+ float4 result = tex.SampleLevel(sampler, float2(0.5, 0.5), 0);
+ buffer[sv_dispatchThreadID.x * 4] = result.r;
+ buffer[sv_dispatchThreadID.x * 4 + 1] = result.g;
+ buffer[sv_dispatchThreadID.x * 4 + 2] = result.b;
+ buffer[sv_dispatchThreadID.x * 4 + 3] = result.a;
+}
+
+// Sample from "tex" at texture coordinates (0.5, 0.5) and save the resuls in "buffer".
+// This should only be used with textures containing two mip levels.
+[shader("compute")]
+[numthreads(2,1,1)]
+void sampleMips(
+ uint3 sv_dispatchThreadID : SV_DispatchThreadID,
+ uniform Texture2D<float4> tex,
+ uniform SamplerState sampler,
+ uniform RWStructuredBuffer<float> buffer)
+{
+ float4 result = tex.SampleLevel(sampler, float2(0.5, 0.5), float(sv_dispatchThreadID.x));
+ buffer[sv_dispatchThreadID.x * 4] = result.r;
+ buffer[sv_dispatchThreadID.x * 4 + 1] = result.g;
+ buffer[sv_dispatchThreadID.x * 4 + 2] = result.b;
+ buffer[sv_dispatchThreadID.x * 4 + 3] = result.a;
+}