summaryrefslogtreecommitdiffstats
path: root/tools/gfx-unit-test/gfx-test-util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/gfx-unit-test/gfx-test-util.cpp')
-rw-r--r--tools/gfx-unit-test/gfx-test-util.cpp15
1 files changed, 15 insertions, 0 deletions
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;