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 --- source/slang/slang-legalize-types.cpp | 5 ----- source/slang/slang-reflection-api.cpp | 25 ++++++++++++++++++++++++- source/slang/slang-type-layout.h | 1 + 3 files changed, 25 insertions(+), 6 deletions(-) (limited to 'source') diff --git a/source/slang/slang-legalize-types.cpp b/source/slang/slang-legalize-types.cpp index 755f0f207..1b72b5c00 100644 --- a/source/slang/slang-legalize-types.cpp +++ b/source/slang/slang-legalize-types.cpp @@ -1201,11 +1201,6 @@ LegalType legalizeTypeImpl( // auto legalConcreteType = legalizeType(context, pseudoPtrType->getValueType()); - // If element type hasn't change, return original type. - if (legalConcreteType.flavor == LegalType::Flavor::simple && - legalConcreteType.getSimple() == pseudoPtrType->getValueType()) - return LegalType::simple(pseudoPtrType); - // TODO: If/when we change our generation of pseudo-pointers // so that use-site code emits a "pseudo-load" then we may // need to change the logic here so that we return diff --git a/source/slang/slang-reflection-api.cpp b/source/slang/slang-reflection-api.cpp index 6f022cc90..eb1514f4c 100644 --- a/source/slang/slang-reflection-api.cpp +++ b/source/slang/slang-reflection-api.cpp @@ -1396,7 +1396,12 @@ namespace Slang // TypeLayout::ExtendedInfo::SubObjectRangeInfo subObjectRange; subObjectRange.bindingRangeIndex = bindingRangeIndex; - + subObjectRange.spaceOffset = 0; + if (kind == LayoutResourceKind::RegisterSpace) + { + auto resInfo = path->var->FindResourceInfo(LayoutResourceKind::RegisterSpace); + subObjectRange.spaceOffset = resInfo->index; + } // It is possible that the sub-object has descriptor ranges // that will need to be exposed upward, into the parent. // @@ -2010,6 +2015,24 @@ SLANG_API SlangInt spReflectionTypeLayout_getSubObjectRangeBindingRangeIndex(Sla return extTypeLayout->m_subObjectRanges[subObjectRangeIndex].bindingRangeIndex; } +SLANG_API SlangInt spReflectionTypeLayout_getSubObjectRangeSpaceOffset( + SlangReflectionTypeLayout* inTypeLayout, + SlangInt subObjectRangeIndex) +{ + auto typeLayout = convert(inTypeLayout); + if (!typeLayout) + return 0; + + auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout); + + if (subObjectRangeIndex < 0) + return 0; + if (subObjectRangeIndex >= extTypeLayout->m_subObjectRanges.getCount()) + return 0; + + return extTypeLayout->m_subObjectRanges[subObjectRangeIndex].spaceOffset; +} + #if 0 SLANG_API SlangInt spReflectionTypeLayout_getBindingRangeSubObjectRangeIndex(SlangReflectionTypeLayout* inTypeLayout, SlangInt index) diff --git a/source/slang/slang-type-layout.h b/source/slang/slang-type-layout.h index c4df46fe0..88ba72003 100644 --- a/source/slang/slang-type-layout.h +++ b/source/slang/slang-type-layout.h @@ -437,6 +437,7 @@ public: struct SubObjectRangeInfo { Int bindingRangeIndex; + Int spaceOffset; }; List> m_descriptorSets; -- cgit v1.2.3