From ac88374136ae0c9e83d3350ca3113f4bce893911 Mon Sep 17 00:00:00 2001 From: lucy96chen <47800040+lucy96chen@users.noreply.github.com> Date: Thu, 16 Dec 2021 14:48:04 -0800 Subject: gfx: Add tests for instanced, indexed instanced, and indirect draw calls (#2060) * Implemented instancing for the drawInstanced test and confirmed that test values taken at specific pixel location match expected values * Removed writeImage() helper function as this is for debugging only * Factored out shared test code and wrapped tests inside a base class with derived structs for each individual draw call variant; Added a test for indexed, instanced draws but test is currently not working correctly * Indexed instancing test finish and working; Further refactor to move code that fills the test result array and creates the vertex and color buffers to the base test class * Commented out image dump helper function at the top as it may still be needed for the remaining draw tests * Added a new struct derived from the base test class for testing indirect but non-indexed draws; Moved required command signatures for indirect draws into D3D12Device to ensure they continue to exist outside of their respective draw calls; Moved command signature creation into D3D12Device::initialize(); Small consistency cleanup changes * Added working indexed indirect draw call test * Moved expectedResult and compareComputeResult() call into getTestResults() and renamed to checkTestResults() * Rerun tests --- tools/gfx-unit-test/gfx-test-util.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'tools/gfx-unit-test/gfx-test-util.cpp') diff --git a/tools/gfx-unit-test/gfx-test-util.cpp b/tools/gfx-unit-test/gfx-test-util.cpp index 619d2feb0..7514f22cf 100644 --- a/tools/gfx-unit-test/gfx-test-util.cpp +++ b/tools/gfx-unit-test/gfx-test-util.cpp @@ -150,6 +150,14 @@ namespace gfx_test SLANG_CHECK(memcmp(resultBlob->getBufferPointer(), expectedResult, expectedBufferSize) == 0); } + void compareComputeResultFuzzy(const float* result, float* expectedResult, size_t expectedBufferSize) + { + for (int i = 0; i < expectedBufferSize / sizeof(float); ++i) + { + SLANG_CHECK(abs(result[i] - expectedResult[i]) <= 0.01); + } + } + void compareComputeResultFuzzy(gfx::IDevice* device, gfx::IBufferResource* buffer, float* expectedResult, size_t expectedBufferSize) { // Read back the results. @@ -159,10 +167,7 @@ namespace gfx_test 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); - } + compareComputeResultFuzzy(result, expectedResult, expectedBufferSize); } Slang::ComPtr createTestingDevice(UnitTestContext* context, Slang::RenderApiFlag::Enum api) -- cgit v1.2.3