From 34fba7b5e726136c6eee8a318ab9a75381399c00 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 20 Apr 2021 13:17:29 -0700 Subject: Various fixes to make `model-viewer` example almost working. (#1801) * Fixing `PseudoPtr` legalization and `gfx` lifetime issues. * Fixing `model-viewer` example. This change contains various fixes to bring `model-viewer` example to fully functional. These fixes include: 1. Add `spReflectionTypeLayout_getSubObjectRangeSpaceOffset` function to return the space index for a sub object referenced through a `ParameterBlock` binding. 2. Make sure `D3D12Device` specifies column major matrix order creating a Slang session. 3. Fix `platform::Window::close()` and `platform::Application::quit()`. 4. Fix memory leak during `model-viewer''s model loading. 5. Fix command buffer recording in `model-viewer`. With these changes, model viewer can now produce an image with a gray cube. The lighting is still incorrect becuase the `gfx` shader object implementation still does not handle "pending layout" resulting from global existential parameters. * Fix d3d12 root signature creation. * Use row-major matrix layout in model-viewer --- tools/gfx/renderer-shared.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tools/gfx/renderer-shared.cpp') diff --git a/tools/gfx/renderer-shared.cpp b/tools/gfx/renderer-shared.cpp index 333f1df54..2a12b777c 100644 --- a/tools/gfx/renderer-shared.cpp +++ b/tools/gfx/renderer-shared.cpp @@ -183,6 +183,20 @@ IShaderProgram* gfx::ShaderProgramBase::getInterface(const Guid& guid) return nullptr; } +IInputLayout* gfx::InputLayoutBase::getInterface(const Guid& guid) +{ + if (guid == GfxGUID::IID_ISlangUnknown || guid == GfxGUID::IID_IInputLayout) + return static_cast(this); + return nullptr; +} + +IFramebufferLayout* gfx::FramebufferLayoutBase::getInterface(const Guid& guid) +{ + if (guid == GfxGUID::IID_ISlangUnknown || guid == GfxGUID::IID_IFramebufferLayout) + return static_cast(this); + return nullptr; +} + IPipelineState* gfx::PipelineStateBase::getInterface(const Guid& guid) { if (guid == GfxGUID::IID_ISlangUnknown || guid == GfxGUID::IID_IPipelineState) @@ -197,6 +211,14 @@ void PipelineStateBase::initializeBase(const PipelineStateDesc& inDesc) auto program = desc.getProgram(); m_program = program; isSpecializable = (program->slangProgram && program->slangProgram->getSpecializationParamCount() != 0); + + // Hold a strong reference to inputLayout and framebufferLayout objects to prevent it from + // destruction. + if (inDesc.type == PipelineType::Graphics) + { + inputLayout = static_cast(inDesc.graphics.inputLayout); + framebufferLayout = static_cast(inDesc.graphics.framebufferLayout); + } } IDevice* gfx::RendererBase::getInterface(const Guid& guid) -- cgit v1.2.3