From 62161b802a8efbf6820ba79f880c99e455ab3bf6 Mon Sep 17 00:00:00 2001 From: lucy96chen <47800040+lucy96chen@users.noreply.github.com> Date: Thu, 9 Dec 2021 15:15:16 -0800 Subject: Implement instanced and indirect draw calls (#2053) * Added implementations of drawInstanced, drawIndexedInstanced, drawIndirect, and drawIndexedIndirect to both render-d3d12 and render-vk * drawInstanced test WIP * Draw calls implemented, working on debugging test * Added new test and accompanying shader file * Fixes. * Fixes. Co-authored-by: Yong He Co-authored-by: Yong He --- tools/gfx-unit-test/gfx-test-util.cpp | 66 +++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 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 e1da919d8..619d2feb0 100644 --- a/tools/gfx-unit-test/gfx-test-util.cpp +++ b/tools/gfx-unit-test/gfx-test-util.cpp @@ -65,7 +65,61 @@ namespace gfx_test return SLANG_OK; } - void compareComputeResult(gfx::IDevice* device, gfx::ITextureResource* texture, gfx::ResourceState state, float* expectedResult, size_t expectedBufferSize) + Slang::Result loadGraphicsProgram( + gfx::IDevice* device, + Slang::ComPtr& outShaderProgram, + const char* shaderModuleName, + const char* vertexEntryPointName, + const char* fragmentEntryPointName, + slang::ProgramLayout*& slangReflection) + { + Slang::ComPtr slangSession; + SLANG_RETURN_ON_FAIL(device->getSlangSession(slangSession.writeRef())); + Slang::ComPtr diagnosticsBlob; + slang::IModule* module = slangSession->loadModule(shaderModuleName, diagnosticsBlob.writeRef()); + diagnoseIfNeeded(diagnosticsBlob); + if (!module) + return SLANG_FAIL; + + ComPtr vertexEntryPoint; + SLANG_RETURN_ON_FAIL( + module->findEntryPointByName(vertexEntryPointName, vertexEntryPoint.writeRef())); + + ComPtr fragmentEntryPoint; + SLANG_RETURN_ON_FAIL( + module->findEntryPointByName(fragmentEntryPointName, fragmentEntryPoint.writeRef())); + + Slang::List componentTypes; + componentTypes.add(module); + componentTypes.add(vertexEntryPoint); + componentTypes.add(fragmentEntryPoint); + + Slang::ComPtr composedProgram; + SlangResult result = slangSession->createCompositeComponentType( + componentTypes.getBuffer(), + componentTypes.getCount(), + composedProgram.writeRef(), + diagnosticsBlob.writeRef()); + diagnoseIfNeeded(diagnosticsBlob); + SLANG_RETURN_ON_FAIL(result); + slangReflection = composedProgram->getLayout(); + + gfx::IShaderProgram::Desc programDesc = {}; + programDesc.slangProgram = composedProgram.get(); + + auto shaderProgram = device->createProgram(programDesc); + + outShaderProgram = shaderProgram; + return SLANG_OK; + } + + void compareComputeResult( + gfx::IDevice* device, + gfx::ITextureResource* texture, + gfx::ResourceState state, + float* expectedResult, + size_t expectedResultRowPitch, + size_t rowCount) { // Read back the results. ComPtr resultBlob; @@ -73,10 +127,16 @@ namespace gfx_test size_t pixelSize = 0; GFX_CHECK_CALL_ABORT(device->readTextureResource( texture, state, resultBlob.writeRef(), &rowPitch, &pixelSize)); - SLANG_CHECK(resultBlob->getBufferSize() == expectedBufferSize); auto result = (float*)resultBlob->getBufferPointer(); // Compare results. - SLANG_CHECK(memcmp(resultBlob->getBufferPointer(), expectedResult, expectedBufferSize) == 0); + for (size_t row = 0; row < rowCount; row++) + { + SLANG_CHECK( + memcmp( + (uint8_t*)resultBlob->getBufferPointer() + rowPitch * row, + (uint8_t*)expectedResult + expectedResultRowPitch * row, + expectedResultRowPitch) == 0); + } } void compareComputeResult(gfx::IDevice* device, gfx::IBufferResource* buffer, uint8_t* expectedResult, size_t expectedBufferSize) -- cgit v1.2.3