diff options
| author | lucy96chen <47800040+lucy96chen@users.noreply.github.com> | 2021-10-26 16:30:59 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-26 16:30:59 -0700 |
| commit | dcc2b854a64b3e4e890215ff21cf4b219724f524 (patch) | |
| tree | fe958a184f46f4a1bbf10f6c7174d31283df76dc /tools/gfx-unit-test | |
| parent | fe6d5f1cf8865567e08cf210a2639ffde2886fc3 (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')
| -rw-r--r-- | tools/gfx-unit-test/format-test-shaders.slang | 220 | ||||
| -rw-r--r-- | tools/gfx-unit-test/format-unit-tests.cpp | 1110 | ||||
| -rw-r--r-- | tools/gfx-unit-test/get-texture-resource-handle-test.cpp | 2 | ||||
| -rw-r--r-- | tools/gfx-unit-test/gfx-test-util.cpp | 15 | ||||
| -rw-r--r-- | tools/gfx-unit-test/gfx-test-util.h | 8 |
5 files changed, 1354 insertions, 1 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; +} diff --git a/tools/gfx-unit-test/format-unit-tests.cpp b/tools/gfx-unit-test/format-unit-tests.cpp new file mode 100644 index 000000000..0498bc670 --- /dev/null +++ b/tools/gfx-unit-test/format-unit-tests.cpp @@ -0,0 +1,1110 @@ +#include "tools/unit-test/slang-unit-test.h" + +#include "slang-gfx.h" +#include "gfx-test-util.h" +#include "tools/gfx-util/shader-cursor.h" +#include "source/core/slang-basic.h" + +using namespace gfx; + +namespace gfx_test +{ + gfx::Format convertTypelessFormat(gfx::Format format) + { + switch (format) + { + case gfx::Format::R32G32B32A32_TYPELESS: + return gfx::Format::R32G32B32A32_FLOAT; + case gfx::Format::R32G32B32_TYPELESS: + return gfx::Format::R32G32B32_FLOAT; + case gfx::Format::R32G32_TYPELESS: + return gfx::Format::R32G32_FLOAT; + case gfx::Format::R32_TYPELESS: + return gfx::Format::R32_FLOAT; + case gfx::Format::R16G16B16A16_TYPELESS: + return gfx::Format::R16G16B16A16_FLOAT; + case gfx::Format::R16G16_TYPELESS: + return gfx::Format::R16G16_FLOAT; + case gfx::Format::R16_TYPELESS: + return gfx::Format::R16_FLOAT; + case gfx::Format::R8G8B8A8_TYPELESS: + return gfx::Format::R8G8B8A8_UNORM; + case gfx::Format::R8G8_TYPELESS: + return gfx::Format::R8G8_UNORM; + case gfx::Format::R8_TYPELESS: + return gfx::Format::R8_UNORM; + case gfx::Format::B8G8R8A8_TYPELESS: + return gfx::Format::B8G8R8A8_UNORM; + case gfx::Format::R10G10B10A2_TYPELESS: + return gfx::Format::R10G10B10A2_UINT; + default: + return gfx::Format::Unknown; + } + } + + void setUpAndRunTest( + IDevice* device, + ComPtr<IResourceView> texView, + ComPtr<IResourceView> bufferView, + const char* entryPoint, + ComPtr<ISamplerState> sampler = nullptr) + { + Slang::ComPtr<ITransientResourceHeap> transientHeap; + ITransientResourceHeap::Desc transientHeapDesc = {}; + transientHeapDesc.constantBufferSize = 4096; + GFX_CHECK_CALL_ABORT( + device->createTransientResourceHeap(transientHeapDesc, transientHeap.writeRef())); + + ComPtr<IShaderProgram> shaderProgram; + slang::ProgramLayout* slangReflection; + GFX_CHECK_CALL_ABORT(loadComputeProgram(device, shaderProgram, "format-test-shaders", entryPoint, slangReflection)); + + ComputePipelineStateDesc pipelineDesc = {}; + pipelineDesc.program = shaderProgram.get(); + ComPtr<gfx::IPipelineState> pipelineState; + GFX_CHECK_CALL_ABORT( + device->createComputePipelineState(pipelineDesc, pipelineState.writeRef())); + + // We have done all the set up work, now it is time to start recording a command buffer for + // GPU execution. + { + ICommandQueue::Desc queueDesc = { ICommandQueue::QueueType::Graphics }; + auto queue = device->createCommandQueue(queueDesc); + + auto commandBuffer = transientHeap->createCommandBuffer(); + auto encoder = commandBuffer->encodeComputeCommands(); + + auto rootObject = encoder->bindPipeline(pipelineState); + + ShaderCursor entryPointCursor( + rootObject->getEntryPoint(0)); // get a cursor the the first entry-point. + + // Bind texture view to the entry point + entryPointCursor.getPath("tex").setResource(texView); + + if (sampler) entryPointCursor.getPath("sampler").setSampler(sampler); + + // Bind buffer view to the entry point. + entryPointCursor.getPath("buffer").setResource(bufferView); + + encoder->dispatchCompute(1, 1, 1); + encoder->endEncoding(); + commandBuffer->close(); + queue->executeCommandBuffer(commandBuffer); + queue->wait(); + } + } + + ComPtr<IResourceView> createTexView( + IDevice* device, + ITextureResource::Size size, + gfx::Format format, + ITextureResource::SubresourceData* data, + int mips = 1) + { + ITextureResource::Desc texDesc = {}; + texDesc.type = IResource::Type::Texture2D; + texDesc.numMipLevels = mips; + texDesc.arraySize = 1; + texDesc.size = size; + texDesc.defaultState = ResourceState::ShaderResource; + texDesc.format = format; + + ComPtr<ITextureResource> inTex; + GFX_CHECK_CALL_ABORT(device->createTextureResource( + texDesc, + data, + inTex.writeRef())); + + ComPtr<IResourceView> texView; + IResourceView::Desc texViewDesc = {}; + texViewDesc.type = IResourceView::Type::ShaderResource; + texViewDesc.format = gfxIsTypelessFormat(format) ? convertTypelessFormat(format) : format; + GFX_CHECK_CALL_ABORT(device->createTextureView(inTex, texViewDesc, texView.writeRef())); + return texView; + } + + template <typename T> + ComPtr<IBufferResource> createBuffer(IDevice* device, int size, void* initialData) + { + IBufferResource::Desc bufferDesc = {}; + bufferDesc.sizeInBytes = size * sizeof(T); + bufferDesc.format = gfx::Format::Unknown; + bufferDesc.elementSize = sizeof(T); + bufferDesc.allowedStates = ResourceStateSet( + ResourceState::ShaderResource, + ResourceState::UnorderedAccess, + ResourceState::CopyDestination, + ResourceState::CopySource); + bufferDesc.defaultState = ResourceState::UnorderedAccess; + bufferDesc.cpuAccessFlags = AccessFlag::Write | AccessFlag::Read; + + ComPtr<IBufferResource> outBuffer; + GFX_CHECK_CALL_ABORT(device->createBufferResource( + bufferDesc, + initialData, + outBuffer.writeRef())); + return outBuffer; + } + + ComPtr<IResourceView> createBufferView(IDevice* device, ComPtr<IBufferResource> outBuffer) + { + ComPtr<IResourceView> bufferView; + IResourceView::Desc viewDesc = {}; + viewDesc.type = IResourceView::Type::UnorderedAccess; + viewDesc.format = Format::Unknown; + GFX_CHECK_CALL_ABORT(device->createBufferView(outBuffer, viewDesc, bufferView.writeRef())); + return bufferView; + } + + void formatTestsImpl(IDevice* device, UnitTestContext* context) + { + ISamplerState::Desc samplerDesc; + auto sampler = device->createSamplerState(samplerDesc); + + float initFloatData[16] = { 0.0f }; + auto floatResults = createBuffer<float>(device, 16, initFloatData); + auto floatBufferView = createBufferView(device, floatResults); + + uint32_t initUintData[16] = { 0u }; + auto uintResults = createBuffer<uint32_t>(device, 16, initUintData); + auto uintBufferView = createBufferView(device, uintResults); + + int32_t initIntData[16] = { 0 }; + auto intResults = createBuffer<uint32_t>(device, 16, initIntData); + auto intBufferView = createBufferView(device, intResults); + + ITextureResource::Size size = {}; + size.width = 2; + size.height = 2; + size.depth = 1; + + ITextureResource::Size bcSize = {}; + bcSize.width = 4; + bcSize.height = 4; + bcSize.depth = 1; + + // Note: D32_FLOAT and D16_UNORM are not directly tested as they are only used for raster. These + // are the same as R32_FLOAT and R16_UNORM, respectively, when passed to a shader. + { + float texData[] = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 1.0f, 1.0f, 0.5f, 0.5f, 0.5f, 1.0f }; + ITextureResource::SubresourceData subData = { (void*)texData, 32, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R32G32B32A32_FLOAT, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 1.0f, 1.0f, 0.5f, 0.5f, 0.5f, 1.0f)); + + texView = createTexView(device, size, gfx::Format::R32G32B32A32_TYPELESS, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 1.0f, 1.0f, 0.5f, 0.5f, 0.5f, 1.0f)); + } + + // Ignore this test on swiftshader. Swiftshader produces unsupported format warnings for this test. + if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader")) + { + float texData[] = { 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.5f, 0.5f, 0.5f }; + ITextureResource::SubresourceData subData = { (void*)texData, 24, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R32G32B32_FLOAT, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat3"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.5f, 0.5f, 0.5f)); + + texView = createTexView(device, size, gfx::Format::R32G32B32_TYPELESS, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat3"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.5f, 0.5f, 0.5f)); + } + + { + float texData[] = { 1.0f, 0.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.5f, 0.5f }; + ITextureResource::SubresourceData subData = { (void*)texData, 16, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R32G32_FLOAT, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.5f, 0.5f)); + + texView = createTexView(device, size, gfx::Format::R32G32_TYPELESS, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.5f, 0.5f)); + } + + { + float texData[] = { 1.0f, 0.0f, 0.5f, 0.25f }; + ITextureResource::SubresourceData subData = { (void*)texData, 8, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R32_FLOAT, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.5f, 0.25f)); + + texView = createTexView(device, size, gfx::Format::R32_TYPELESS, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.5f, 0.25f)); + } + + { + uint16_t texData[] = { 15360u, 0u, 0u, 15360u, 0u, 15360u, 0u, 15360u, + 0u, 0u, 15360u, 15360u, 14336u, 14336u, 14336u, 15360u }; + ITextureResource::SubresourceData subData = { (void*)texData, 16, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R16G16B16A16_FLOAT, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 1.0f, 1.0f, 0.5f, 0.5f, 0.5f, 1.0f)); + + texView = createTexView(device, size, gfx::Format::R16G16B16A16_TYPELESS, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 1.0f, 1.0f, 0.5f, 0.5f, 0.5f, 1.0f)); + } + + { + uint16_t texData[] = { 15360u, 0u, 0u, 15360u, + 15360u, 15360u, 14336u, 14336u }; + ITextureResource::SubresourceData subData = { (void*)texData, 8, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R16G16_FLOAT, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.5f, 0.5f)); + + texView = createTexView(device, size, gfx::Format::R16G16_TYPELESS, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.5f, 0.5f)); + } + + { + uint16_t texData[] = { 15360u, 0u, 14336u, 13312u }; + ITextureResource::SubresourceData subData = { (void*)texData, 4, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R16_FLOAT, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.5f, 0.25f)); + + texView = createTexView(device, size, gfx::Format::R16_TYPELESS, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.5f, 0.25f)); + } + + { + uint32_t texData[] = { 255u, 0u, 0u, 255u, 0u, 255u, 0u, 255u, + 0u, 0u, 255u, 255u, 127u, 127u, 127u, 255u }; + ITextureResource::SubresourceData subData = { (void*)texData, 32, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R32G32B32A32_UINT, &subData); + setUpAndRunTest(device, texView, uintBufferView, "copyTexUint4"); + compareComputeResult( + device, + uintResults, + Slang::makeArray<uint32_t>(255u, 0u, 0u, 255u, 0u, 255u, 0u, 255u, + 0u, 0u, 255u, 255u, 127u, 127u, 127u, 255u)); + } + + // Ignore this test on swiftshader. Swiftshader produces unsupported format warnings for this test. + if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader")) + { + uint32_t texData[] = { 255u, 0u, 0u, 0u, 255u, 0u, + 0u, 0u, 255u, 127u, 127u, 127u }; + ITextureResource::SubresourceData subData = { (void*)texData, 24, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R32G32B32_UINT, &subData); + setUpAndRunTest(device, texView, uintBufferView, "copyTexUint3"); + compareComputeResult( + device, + uintResults, + Slang::makeArray<uint32_t>(255u, 0u, 0u, 0u, 255u, 0u, + 0u, 0u, 255u, 127u, 127u, 127u)); + } + + { + uint32_t texData[] = { 255u, 0u, 0u, 255u, + 255u, 255u, 127u, 127u }; + ITextureResource::SubresourceData subData = { (void*)texData, 16, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R32G32_UINT, &subData); + setUpAndRunTest(device, texView, uintBufferView, "copyTexUint2"); + compareComputeResult( + device, + uintResults, + Slang::makeArray<uint32_t>(255u, 0u, 0u, 255u, + 255u, 255u, 127u, 127u)); + } + + { + uint32_t texData[] = { 255u, 0u, 127u, 73u }; + ITextureResource::SubresourceData subData = { (void*)texData, 8, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R32_UINT, &subData); + setUpAndRunTest(device, texView, uintBufferView, "copyTexUint"); + compareComputeResult( + device, + uintResults, + Slang::makeArray<uint32_t>(255u, 0u, 127u, 73u)); + } + + { + uint16_t texData[] = { 255u, 0u, 0u, 255u, 0u, 255u, 0u, 255u, + 0u, 0u, 255u, 255u, 127u, 127u, 127u, 255u }; + ITextureResource::SubresourceData subData = { (void*)texData, 16, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R16G16B16A16_UINT, &subData); + setUpAndRunTest(device, texView, uintBufferView, "copyTexUint4"); + compareComputeResult( + device, + uintResults, + Slang::makeArray<uint32_t>(255u, 0u, 0u, 255u, 0u, 255u, 0u, 255u, + 0u, 0u, 255u, 255u, 127u, 127u, 127u, 255u)); + } + + { + uint16_t texData[] = { 255u, 0u, 0u, 255u, + 255u, 255u, 127u, 127u }; + ITextureResource::SubresourceData subData = { (void*)texData, 8, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R16G16_UINT, &subData); + setUpAndRunTest(device, texView, uintBufferView, "copyTexUint2"); + compareComputeResult( + device, + uintResults, + Slang::makeArray<uint32_t>(255u, 0u, 0u, 255u, + 255u, 255u, 127u, 127u)); + } + + { + uint16_t texData[] = { 255u, 0u, 127u, 73u }; + ITextureResource::SubresourceData subData = { (void*)texData, 4, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R16_UINT, &subData); + setUpAndRunTest(device, texView, uintBufferView, "copyTexUint"); + compareComputeResult( + device, + uintResults, + Slang::makeArray<uint32_t>(255u, 0u, 127u, 73u)); + } + + { + uint8_t texData[] = { 255u, 0u, 0u, 255u, 0u, 255u, 0u, 255u, + 0u, 0u, 255u, 255u, 127u, 127u, 127u, 255u }; + ITextureResource::SubresourceData subData = { (void*)texData, 8, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R8G8B8A8_UINT, &subData); + setUpAndRunTest(device, texView, uintBufferView, "copyTexUint4"); + compareComputeResult( + device, + uintResults, + Slang::makeArray<uint32_t>(255u, 0u, 0u, 255u, 0u, 255u, 0u, 255u, + 0u, 0u, 255u, 255u, 127u, 127u, 127u, 255u)); + } + + { + uint8_t texData[] = { 255u, 0u, 0u, 255u, + 255u, 255u, 127u, 127u }; + ITextureResource::SubresourceData subData = { (void*)texData, 4, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R8G8_UINT, &subData); + setUpAndRunTest(device, texView, uintBufferView, "copyTexUint2"); + compareComputeResult( + device, + uintResults, + Slang::makeArray<uint32_t>(255u, 0u, 0u, 255u, + 255u, 255u, 127u, 127u)); + } + + { + uint8_t texData[] = { 255u, 0u, 127u, 73u }; + ITextureResource::SubresourceData subData = { (void*)texData, 2, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R8_UINT, &subData); + setUpAndRunTest(device, texView, uintBufferView, "copyTexUint"); + compareComputeResult( + device, + uintResults, + Slang::makeArray<uint32_t>(255u, 0u, 127u, 73u)); + } + + { + int32_t texData[] = { 255, 0, 0, 255, 0, 255, 0, 255, + 0, 0, 255, 255, 127, 127, 127, 255 }; + ITextureResource::SubresourceData subData = { (void*)texData, 32, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R32G32B32A32_SINT, &subData); + setUpAndRunTest(device, texView, intBufferView, "copyTexInt4"); + compareComputeResult( + device, + intResults, + Slang::makeArray<int32_t>(255, 0, 0, 255, 0, 255, 0, 255, + 0, 0, 255, 255, 127, 127, 127, 255)); + } + + // Ignore this test on swiftshader. Swiftshader produces unsupported format warnings for this test. + if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader")) + { + int32_t texData[] = { 255, 0, 0, 0, 255, 0, + 0, 0, 255, 127, 127, 127 }; + ITextureResource::SubresourceData subData = { (void*)texData, 24, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R32G32B32_SINT, &subData); + setUpAndRunTest(device, texView, intBufferView, "copyTexInt3"); + compareComputeResult( + device, + intResults, + Slang::makeArray<int32_t>(255, 0, 0, 0, 255, 0, + 0, 0, 255, 127, 127, 127)); + } + + { + int32_t texData[] = { 255, 0, 0, 255, + 255, 255, 127, 127 }; + ITextureResource::SubresourceData subData = { (void*)texData, 16, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R32G32_SINT, &subData); + setUpAndRunTest(device, texView, intBufferView, "copyTexInt2"); + compareComputeResult( + device, + intResults, + Slang::makeArray<int32_t>(255, 0, 0, 255, + 255, 255, 127, 127)); + } + + { + int32_t texData[] = { 255, 0, 127, 73 }; + ITextureResource::SubresourceData subData = { (void*)texData, 8, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R32_SINT, &subData); + setUpAndRunTest(device, texView, intBufferView, "copyTexInt"); + compareComputeResult( + device, + intResults, + Slang::makeArray<int32_t>(255, 0, 127, 73)); + } + + { + int16_t texData[] = { 255, 0, 0, 255, 0, 255, 0, 255, + 0, 0, 255, 255, 127, 127, 127, 255 }; + ITextureResource::SubresourceData subData = { (void*)texData, 16, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R16G16B16A16_SINT, &subData); + setUpAndRunTest(device, texView, intBufferView, "copyTexInt4"); + compareComputeResult( + device, + intResults, + Slang::makeArray<int32_t>(255, 0, 0, 255, 0, 255, 0, 255, + 0, 0, 255, 255, 127, 127, 127, 255)); + } + + { + int16_t texData[] = { 255, 0, 0, 255, + 255, 255, 127, 127 }; + ITextureResource::SubresourceData subData = { (void*)texData, 8, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R16G16_SINT, &subData); + setUpAndRunTest(device, texView, intBufferView, "copyTexInt2"); + compareComputeResult( + device, + intResults, + Slang::makeArray<int32_t>(255, 0, 0, 255, + 255, 255, 127, 127)); + } + + { + int16_t texData[] = { 255, 0, 127, 73 }; + ITextureResource::SubresourceData subData = { (void*)texData, 4, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R16_SINT, &subData); + setUpAndRunTest(device, texView, intBufferView, "copyTexInt"); + compareComputeResult( + device, + intResults, + Slang::makeArray<int32_t>(255, 0, 127, 73)); + } + + { + int8_t texData[] = { 127, 0, 0, 127, 0, 127, 0, 127, + 0, 0, 127, 127, 0, 0, 0, 127 }; + ITextureResource::SubresourceData subData = { (void*)texData, 8, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R8G8B8A8_SINT, &subData); + setUpAndRunTest(device, texView, intBufferView, "copyTexInt4"); + compareComputeResult( + device, + intResults, + Slang::makeArray<int32_t>(127, 0, 0, 127, 0, 127, 0, 127, + 0, 0, 127, 127, 0, 0, 0, 127)); + } + + { + int8_t texData[] = { 127, 0, 0, 127, + 127, 127, 73, 73 }; + ITextureResource::SubresourceData subData = { (void*)texData, 4, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R8G8_SINT, &subData); + setUpAndRunTest(device, texView, intBufferView, "copyTexInt2"); + compareComputeResult( + device, + intResults, + Slang::makeArray<int32_t>(127, 0, 0, 127, + 127, 127, 73, 73)); + } + + { + int8_t texData[] = { 127, 0, 73, 25 }; + ITextureResource::SubresourceData subData = { (void*)texData, 2, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R8_SINT, &subData); + setUpAndRunTest(device, texView, intBufferView, "copyTexInt"); + compareComputeResult( + device, + intResults, + Slang::makeArray<int32_t>(127, 0, 73, 25)); + } + + { + uint16_t texData[] = { 65535u, 0u, 0u, 65535u, 0u, 65535u, 0u, 65535u, + 0u, 0u, 65535u, 65535u, 32767u, 32767u, 32767u, 32767u }; + ITextureResource::SubresourceData subData = { (void*)texData, 16, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R16G16B16A16_UNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 1.0f, 1.0f, 0.499992371f, 0.499992371f, 0.499992371f, 0.499992371f)); + } + + { + uint16_t texData[] = { 65535u, 0u, 0u, 65535u, + 65535u, 65535u, 32767u, 32767u }; + ITextureResource::SubresourceData subData = { (void*)texData, 8, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R16G16_UNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.499992371f, 0.499992371f)); + } + + { + uint16_t texData[] = { 65535u, 0u, 32767u, 16383u }; + ITextureResource::SubresourceData subData = { (void*)texData, 4, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R16_UNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.499992371f, 0.249988556f)); + } + + // Ignore this test on swiftshader. Swiftshader produces different results than expected. + if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader")) + { + uint8_t texData[] = { 0u, 0u, 0u, 255u, 127u, 127u, 127u, 255u, + 255u, 255u, 255u, 255u, 0u, 0u, 0u, 0u }; + ITextureResource::SubresourceData subData = { (void*)texData, 8, 0}; + + auto texView = createTexView(device, size, gfx::Format::R8G8B8A8_TYPELESS, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(0.0f, 0.0f, 0.0f, 1.0f, 0.498039216f, 0.498039216f, 0.498039216f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f)); + + texView = createTexView(device, size, gfx::Format::R8G8B8A8_UNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(0.0f, 0.0f, 0.0f, 1.0f, 0.498039216f, 0.498039216f, 0.498039216f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f)); + + texView = createTexView(device, size, gfx::Format::R8G8B8A8_UNORM_SRGB, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(0.0f, 0.0f, 0.0f, 1.0f, 0.211914062f, 0.211914062f, 0.211914062f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f)); + } + + // Ignore this test on swiftshader. Swiftshader produces different results than expected. + if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader")) + { + uint8_t texData[] = { 255u, 0u, 0u, 255u, 255u, 255u, 127u, 127u }; + ITextureResource::SubresourceData subData = { (void*)texData, 4, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R8G8_TYPELESS, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.498039216f, 0.498039216f)); + + texView = createTexView(device, size, gfx::Format::R8G8_UNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.498039216f, 0.498039216f)); + } + + // Ignore this test on swiftshader. Swiftshader produces different results than expected. + if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader")) + { + uint8_t texData[] = { 255u, 0u, 127u, 63u }; + ITextureResource::SubresourceData subData = { (void*)texData, 2, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R8_TYPELESS, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.498039216f, 0.247058824f)); + + texView = createTexView(device, size, gfx::Format::R8_UNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.498039216f, 0.247058824f)); + } + + // Ignore this test on swiftshader. Swiftshader produces different results than expected. + if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader")) + { + uint8_t texData[] = { 0u, 0u, 0u, 255u, 127u, 127u, 127u, 255u, + 255u, 255u, 255u, 255u, 0u, 0u, 0u, 0u }; + ITextureResource::SubresourceData subData = { (void*)texData, 8, 0 }; + + auto texView = createTexView(device, size, gfx::Format::B8G8R8A8_TYPELESS, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(0.0f, 0.0f, 0.0f, 1.0f, 0.498039216f, 0.498039216f, 0.498039216f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f)); + + texView = createTexView(device, size, gfx::Format::B8G8R8A8_UNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(0.0f, 0.0f, 0.0f, 1.0f, 0.498039216f, 0.498039216f, 0.498039216f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f)); + } + + { + int16_t texData[] = { 32767, 0, 0, 32767, 0, 32767, 0, 32767, + 0, 0, 32767, 32767, -32768, -32768, 0, 32767 }; + ITextureResource::SubresourceData subData = { (void*)texData, 16, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R16G16B16A16_SNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f)); + } + + { + int16_t texData[] = { 32767, 0, 0, 32767, + 32767, 32767, -32768, -32768 }; + ITextureResource::SubresourceData subData = { (void*)texData, 8, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R16G16_SNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f)); + } + + { + int16_t texData[] = { 32767, 0, -32768, 0}; + ITextureResource::SubresourceData subData = { (void*)texData, 4, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R16_SNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, -1.0f, 0.0f)); + } + + { + int8_t texData[] = { 127, 0, 0, 127, 0, 127, 0, 127, + 0, 0, 127, 127, -128, -128, 0, 127 }; + ITextureResource::SubresourceData subData = { (void*)texData, 8, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R8G8B8A8_SNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f)); + } + + { + int8_t texData[] = { 127, 0, 0, 127, + 127, 127, -128, -128 }; + ITextureResource::SubresourceData subData = { (void*)texData, 4, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R8G8_SNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f)); + } + + { + int8_t texData[] = { 127, 0, -128, 0 }; + ITextureResource::SubresourceData subData = { (void*)texData, 2, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R8_SNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, -1.0f, 0.0f)); + } + + // Ignore this test on swiftshader. Swiftshader produces unsupported format warnings for this test. + if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader")) + { + uint8_t texData[] = { 15u, 240u, 240u, 240u, 0u, 255u, 119u, 119u }; + ITextureResource::SubresourceData subData = { (void*)texData, 4, 0 }; + + auto texView = createTexView(device, size, gfx::Format::B4G4R4A4_UNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, + 1.0f, 0.0f, 0.0f, 1.0f, 0.466666669f, 0.466666669f, 0.466666669f, 0.466666669f)); + } + + // Ignore this test on swiftshader. Swiftshader produces different results than expected. + if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader")) + { + uint16_t texData[] = { 31u, 2016u, 63488u, 31727u }; + ITextureResource::SubresourceData subData = { (void*)texData, 4, 0 }; + + auto texView = createTexView(device, size, gfx::Format::B5G6R5_UNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat3"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 0.482352942f, 0.490196079f, 0.482352942f)); + + texView = createTexView(device, size, gfx::Format::B5G5R5A1_UNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(0.0f, 0.0f, 1.0f, 0.0f, 0.0313725509f, 1.0f, 0.0f, 0.0f, + 0.968627453f, 0.0f, 0.0f, 1.0f, 0.968627453f, 1.0f, 0.482352942f, 0.0f)); + } + + { + uint32_t texData[] = { 2950951416u, 2013265920u, 3086219772u, 3087007228u }; + ITextureResource::SubresourceData subData = { (void*)texData, 8, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R9G9B9E5_SHAREDEXP, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat3"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(63.0f, 63.0f, 63.0f, 0.0f, 0.0f, 0.0f, + 127.0f, 127.0f, 127.0f, 127.0f, 127.5f, 127.75f)); + } + + // Ignore this test on swiftshader. Swiftshader produces different results than expected. + if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader")) + { + uint32_t texData[] = { 4294967295u, 0u, 2683829759u, 1193046471u }; + ITextureResource::SubresourceData subData = { (void*)texData, 8, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R10G10B10A2_TYPELESS, &subData); + setUpAndRunTest(device, texView, uintBufferView, "copyTexUint4"); + compareComputeResult( + device, + uintResults, + Slang::makeArray<uint32_t>(1023u, 1023u, 1023u, 3u, 0u, 0u, 0u, 0u, + 511u, 511u, 511u, 2u, 455u, 796u, 113u, 1u)); + + texView = createTexView(device, size, gfx::Format::R10G10B10A2_UNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.499511242f, 0.499511242f, 0.499511242f, 0.666666687f, + 0.444770277f, 0.778103590f, 0.110459432f, 0.333333343f)); + + texView = createTexView(device, size, gfx::Format::R10G10B10A2_UINT, &subData); + setUpAndRunTest(device, texView, uintBufferView, "copyTexUint4"); + compareComputeResult( + device, + uintResults, + Slang::makeArray<uint32_t>(1023u, 1023u, 1023u, 3u, 0u, 0u, 0u, 0u, + 511u, 511u, 511u, 2u, 455u, 796u, 113u, 1u)); + } + + { + uint32_t texData[] = { 3085827519u, 0u, 2951478655u, 1880884096u }; + ITextureResource::SubresourceData subData = { (void*)texData, 8, 0 }; + + auto texView = createTexView(device, size, gfx::Format::R11G11B10_FLOAT, &subData); + setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat3"); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(254.0f, 254.0f, 252.0f, 0.0f, 0.0f, 0.0f, 127.0f, 127.0f, 126.0f, 0.5f, 0.5f, 0.5f)); + } + + // These BC1 tests also check that mipmaps are working correctly for compressed formats. + // Ignore this test on swiftshader. Swiftshader produces different results than expected. + if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader")) + { + uint8_t texData[] = { 16u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 16u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 16u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 16u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, + 255u, 255u, 255u, 255u, 0u, 0u, 0u, 0u }; + ITextureResource::SubresourceData subData[] = { + ITextureResource::SubresourceData {(void*)texData, 16, 32}, + ITextureResource::SubresourceData {(void*)(texData + 32), 8, 0} + }; + ITextureResource::Size size = {}; + size.width = 8; + size.height = 8; + size.depth = 1; + + auto texView = createTexView(device, size, gfx::Format::BC1_UNORM, subData, 2); + setUpAndRunTest(device, texView, floatBufferView, "sampleMips", sampler); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(0.0f, 0.0f, 0.517647088f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f)); + + texView = createTexView(device, size, gfx::Format::BC1_UNORM_SRGB, subData, 2); + setUpAndRunTest(device, texView, floatBufferView, "sampleMips", sampler); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(0.0f, 0.0f, 0.230468750f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f)); + } + + // Ignore this test on swiftshader. Swiftshader produces different results than expected. + if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader")) + { + uint8_t texData[] = { 255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 16u, 0u, 0u, 0u, 0u, 0u, 0u, 0u }; + ITextureResource::SubresourceData subData = { (void*)texData, 16, 0 }; + + auto texView = createTexView(device, bcSize, gfx::Format::BC2_UNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(0.0f, 0.0f, 0.517647088f, 1.0f)); + + texView = createTexView(device, bcSize, gfx::Format::BC2_UNORM_SRGB, &subData); + setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(0.0f, 0.0f, 0.230468750f, 1.0f)); + } + + // Ignore this test on swiftshader. Swiftshader produces different results than expected. + if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader")) + { + uint8_t texData[] = { 0u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, + 16u, 0u, 0u, 0u, 0u, 0u, 0u, 0u }; + ITextureResource::SubresourceData subData = { (void*)texData, 16, 0 }; + + auto texView = createTexView(device, bcSize, gfx::Format::BC3_UNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(0.0f, 0.0f, 0.517647088f, 1.0f)); + + texView = createTexView(device, bcSize, gfx::Format::BC3_UNORM_SRGB, &subData); + setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(0.0f, 0.0f, 0.230468750f, 1.0f)); + } + + // Ignore this test on swiftshader. Swiftshader produces different results than expected. + if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader")) + { + uint8_t texData[] = { 127u, 0u, 0u, 0u, 0u, 0u, 0u, 0u }; + ITextureResource::SubresourceData subData = { (void*)texData, 8, 0 }; + + auto texView = createTexView(device, bcSize, gfx::Format::BC4_UNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(0.498039216f, 0.0f, 0.0f, 1.0f)); + + texView = createTexView(device, bcSize, gfx::Format::BC4_SNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f)); + } + + // Ignore this test on swiftshader. Swiftshader produces different results than expected. + if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader")) + { + uint8_t texData[] = { 127u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 127u, 0u, 0u, 0u, 0u, 0u, 0u, 0u }; + ITextureResource::SubresourceData subData = { (void*)texData, 16, 0 }; + + auto texView = createTexView(device, bcSize, gfx::Format::BC5_UNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(0.498039216f, 0.498039216f, 0.0f, 1.0f, 0.498039216f, 0.498039216f, 0.0f, 1.0f)); + + texView = createTexView(device, bcSize, gfx::Format::BC5_SNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f)); + } + + // BC6H_UF16 and BC6H_SF16 are tested separately due to requiring different texture data. + // Ignore this test on swiftshader. Swiftshader produces different results than expected. + if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader")) + { + uint8_t texData[] = { 98u, 238u, 232u, 77u, 240u, 66u, 148u, 31u, + 124u, 95u, 2u, 224u, 255u, 107u, 77u, 250u }; + ITextureResource::SubresourceData subData = { (void*)texData, 16, 0 }; + + auto texView = createTexView(device, bcSize, gfx::Format::BC6H_UF16, &subData); + setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(0.336669922f, 0.911132812f, 2.13867188f, 1.0f)); + } + + // Ignore this test on swiftshader. Swiftshader produces different results than expected. + if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader")) + { + uint8_t texData[] = { 107u, 238u, 232u, 77u, 240u, 71u, 128u, 127u, + 1u, 0u, 255u, 255u, 170u, 218u, 221u, 254u }; + ITextureResource::SubresourceData subData = { (void*)texData, 16, 0 }; + + auto texView = createTexView(device, bcSize, gfx::Format::BC6H_SF16, &subData); + setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(0.336914062f, 0.910644531f, 2.14062500f, 1.0f)); + } + + // Ignore this test on swiftshader. Swiftshader produces different results than expected. + if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader")) + { + uint8_t texData[] = { 104u, 0u, 0u, 0u, 64u, 163u, 209u, 104u, + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u }; + ITextureResource::SubresourceData subData = { (void*)texData, 16, 0 }; + + auto texView = createTexView(device, bcSize, gfx::Format::BC7_UNORM, &subData); + setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(0.0f, 0.101960786f, 0.0f, 1.0f)); + + texView = createTexView(device, bcSize, gfx::Format::BC7_UNORM_SRGB, &subData); + setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + compareComputeResult( + device, + floatResults, + Slang::makeArray<float>(0.0f, 0.0103149414f, 0.0f, 1.0f)); + } + } + + SLANG_UNIT_TEST(FormatTestsD3D11) + { + runTestImpl(formatTestsImpl, unitTestContext, Slang::RenderApiFlag::D3D11); + } + +#if SLANG_WINDOWS_FAMILY + SLANG_UNIT_TEST(FormatTestsD3D12) + { + runTestImpl(formatTestsImpl, unitTestContext, Slang::RenderApiFlag::D3D12); + } +#endif + + SLANG_UNIT_TEST(FormatTestsVulkan) + { + runTestImpl(formatTestsImpl, unitTestContext, Slang::RenderApiFlag::Vulkan); + } + +} diff --git a/tools/gfx-unit-test/get-texture-resource-handle-test.cpp b/tools/gfx-unit-test/get-texture-resource-handle-test.cpp index 4677bd97b..537585f2a 100644 --- a/tools/gfx-unit-test/get-texture-resource-handle-test.cpp +++ b/tools/gfx-unit-test/get-texture-resource-handle-test.cpp @@ -22,7 +22,7 @@ namespace gfx_test desc.size.height = 1; desc.size.depth = 1; desc.defaultState = ResourceState::UnorderedAccess; - desc.format = Format::RGBA_Float16; + desc.format = Format::R16G16B16A16_FLOAT; Slang::ComPtr<ITextureResource> buffer; buffer = device->createTextureResource(desc); diff --git a/tools/gfx-unit-test/gfx-test-util.cpp b/tools/gfx-unit-test/gfx-test-util.cpp index f1dd6be58..aafa3fc59 100644 --- a/tools/gfx-unit-test/gfx-test-util.cpp +++ b/tools/gfx-unit-test/gfx-test-util.cpp @@ -77,6 +77,21 @@ namespace gfx_test SLANG_CHECK(memcmp(resultBlob->getBufferPointer(), expectedResult, expectedBufferSize) == 0); } + void compareComputeResultFuzzy(gfx::IDevice* device, gfx::IBufferResource* buffer, float* expectedResult, size_t expectedBufferSize) + { + // Read back the results. + ComPtr<ISlangBlob> resultBlob; + GFX_CHECK_CALL_ABORT(device->readBufferResource( + buffer, 0, expectedBufferSize, resultBlob.writeRef())); + SLANG_CHECK(resultBlob->getBufferSize() == expectedBufferSize); + // Compare results with a tolerance of 0.01. + auto result = (float*)resultBlob->getBufferPointer(); + for (int i = 0; i < expectedBufferSize / sizeof(float); ++i) + { + SLANG_CHECK(abs(result[i] - expectedResult[i]) <= 0.01); + } + } + Slang::ComPtr<gfx::IDevice> createTestingDevice(UnitTestContext* context, Slang::RenderApiFlag::Enum api) { Slang::ComPtr<gfx::IDevice> device; diff --git a/tools/gfx-unit-test/gfx-test-util.h b/tools/gfx-unit-test/gfx-test-util.h index b357a310a..01a367915 100644 --- a/tools/gfx-unit-test/gfx-test-util.h +++ b/tools/gfx-unit-test/gfx-test-util.h @@ -25,6 +25,13 @@ namespace gfx_test uint8_t* expectedResult, size_t expectedBufferSize); + /// Reads back the content of `buffer` and compares it against `expectedResult` with a set tolerance. + void compareComputeResultFuzzy( + gfx::IDevice* device, + gfx::IBufferResource* buffer, + float* expectedResult, + size_t expectedBufferSize); + template<typename T, Slang::Index count> void compareComputeResult( gfx::IDevice* device, @@ -35,6 +42,7 @@ namespace gfx_test size_t bufferSize = sizeof(T) * count; expectedBuffer.setCount(bufferSize); memcpy(expectedBuffer.getBuffer(), expectedResult.begin(), bufferSize); + if (std::is_same<T, float>::value) return compareComputeResultFuzzy(device, buffer, (float*)expectedBuffer.getBuffer(), bufferSize); return compareComputeResult(device, buffer, expectedBuffer.getBuffer(), bufferSize); } |
