diff options
| author | lucy96chen <47800040+lucy96chen@users.noreply.github.com> | 2021-12-09 15:15:16 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-09 15:15:16 -0800 |
| commit | 62161b802a8efbf6820ba79f880c99e455ab3bf6 (patch) | |
| tree | ef242700b665abe3094ded3e21dcbfcf593ede14 /tools/gfx-unit-test/gfx-test-util.cpp | |
| parent | 1c99a986ae12a3f1ce4cee86191052183d37208a (diff) | |
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 <yhe@nvidia.com>
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tools/gfx-unit-test/gfx-test-util.cpp')
| -rw-r--r-- | tools/gfx-unit-test/gfx-test-util.cpp | 66 |
1 files changed, 63 insertions, 3 deletions
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<gfx::IShaderProgram>& outShaderProgram, + const char* shaderModuleName, + const char* vertexEntryPointName, + const char* fragmentEntryPointName, + slang::ProgramLayout*& slangReflection) + { + Slang::ComPtr<slang::ISession> slangSession; + SLANG_RETURN_ON_FAIL(device->getSlangSession(slangSession.writeRef())); + Slang::ComPtr<slang::IBlob> diagnosticsBlob; + slang::IModule* module = slangSession->loadModule(shaderModuleName, diagnosticsBlob.writeRef()); + diagnoseIfNeeded(diagnosticsBlob); + if (!module) + return SLANG_FAIL; + + ComPtr<slang::IEntryPoint> vertexEntryPoint; + SLANG_RETURN_ON_FAIL( + module->findEntryPointByName(vertexEntryPointName, vertexEntryPoint.writeRef())); + + ComPtr<slang::IEntryPoint> fragmentEntryPoint; + SLANG_RETURN_ON_FAIL( + module->findEntryPointByName(fragmentEntryPointName, fragmentEntryPoint.writeRef())); + + Slang::List<slang::IComponentType*> componentTypes; + componentTypes.add(module); + componentTypes.add(vertexEntryPoint); + componentTypes.add(fragmentEntryPoint); + + Slang::ComPtr<slang::IComponentType> 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<ISlangBlob> 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) |
