diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2023-08-16 08:57:47 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-16 08:57:47 +0800 |
| commit | 45d9961a6a86d184248ef84f6a07125b0c224f97 (patch) | |
| tree | c91d9b9aa722ceb727f7f1c8c2041d7d2bb13466 /source/slang/slang-type-layout.cpp | |
| parent | e34b005c47d265105e7bba509cadaa3e225237af (diff) | |
Use ankerl/unordered_dense as a hashmap implementation (#3036)
* Correct namespace for getClockFrequency
* missing const
* Add missing assignment operator
* Remove unused variables
* Return correct modified variable
* Use stable hash code for file system identity
* terse static_assert
* Structured binding for map iteration
* Make (==) and getHashCode const on many structs
* Add ConstIterator for LinkedList
* Replace uses of ItemProxy::getValue with Dictionary::at
* Extract list of loads from gradientsMap before updating it
* Const correctness in type layout
* Add unordered_dense hashmap submodule
* Use wyhash or getHashCode in slang-hash.h
* refactor slang-hash.h
* Use ankerl/unordered_dense as a hashmap implementation
Notable changes:
- The subscript operator returns a reference directly to the value,
rather than a lazy ItemProxy (pair of dict pointer and key)
slang-profile time (95% over 10 runs):
- Before: 6.3913906 (±0.0746)
- After: 5.9276123 (±0.0964)
* 64 bit hash for strings
So they have the same hash as char buffers with the same contents
* Narrowing warnings for gcc to match msvc
* revert back to c++17
* Correct c++ version for msvc
* Use path to unordered_dense which keeps tests happy
* Do not assign to and read from map in same expression
* Remove redundant map operations in primal-hoist
* Split out stable hash functions into slang-stable-hash.h
* 64 bit hash by default
* regenerate vs projects
* Correct return type from HashSetBase::getCount()
* correct width for call to Dictionary::reserve
* Use stable hash for obfuscated module ids
* Signed int for reserve
* clearer variable naming
* Parameterize Dictionary on hash and equality functors
* Allow heterogenous lookup for Dictionary
* missing const
* Use set over operator[] in some places
* Remove unused function
* s/at/getValue
Diffstat (limited to 'source/slang/slang-type-layout.cpp')
| -rw-r--r-- | source/slang/slang-type-layout.cpp | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp index bf3df4adc..cdf1f3694 100644 --- a/source/slang/slang-type-layout.cpp +++ b/source/slang/slang-type-layout.cpp @@ -1986,12 +1986,12 @@ RefPtr<TypeLayout> applyOffsetToTypeLayout( mapOldFieldToNew.add(oldField.Ptr(), newField.Ptr()); } - for (auto entry : oldStructTypeLayout->mapVarToLayout) + for (const auto& [entryKey, entryValue] : oldStructTypeLayout->mapVarToLayout) { VarLayout* newFieldLayout = nullptr; - if (mapOldFieldToNew.tryGetValue(entry.value.Ptr(), newFieldLayout)) + if (mapOldFieldToNew.tryGetValue(entryValue.Ptr(), newFieldLayout)) { - newStructTypeLayout->mapVarToLayout.add(entry.key, newFieldLayout); + newStructTypeLayout->mapVarToLayout.add(entryKey, newFieldLayout); } } @@ -2705,8 +2705,9 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout( // We will first compute a layout for the element type of // the parameter group. // - auto elementTypeLayout = createTypeLayout( - context.with(elementTypeRules), + auto elementTypeLayout = createTypeLayoutWith( + context, + elementTypeRules, elementType); // Now we delegate to a routine that does the meat of @@ -2830,8 +2831,9 @@ createStructuredBufferTypeLayout( auto structuredBufferLayoutRules = context.getRulesFamily()->getStructuredBufferRules(context.targetReq); // Create and save type layout for the buffer contents. - auto elementTypeLayout = createTypeLayout( - context.with(structuredBufferLayoutRules), + auto elementTypeLayout = createTypeLayoutWith( + context, + structuredBufferLayoutRules, elementType); return createStructuredBufferTypeLayout( @@ -2849,7 +2851,7 @@ createStructuredBufferTypeLayout( /// together as a `TypeLayoutResult`. /// static TypeLayoutResult _createTypeLayout( - TypeLayoutContext const& context, + TypeLayoutContext& context, Type* type); /// Create layout information for the given `type`, obeying any layout modifiers on the given declaration. @@ -3131,10 +3133,8 @@ static RefPtr<TypeLayout> maybeAdjustLayoutForArrayElementType( mapOriginalFieldToAdjusted.add(originalField, adjustedField); } - for( auto p : originalStructTypeLayout->mapVarToLayout ) + for( auto [key, originalVal] : originalStructTypeLayout->mapVarToLayout ) { - VarDeclBase* key = p.key; - RefPtr<VarLayout> originalVal = p.value; RefPtr<VarLayout> adjustedVal; if( mapOriginalFieldToAdjusted.tryGetValue(originalVal, adjustedVal) ) { @@ -3436,7 +3436,7 @@ static bool _isDescriptorSlotLike( } static TypeLayoutResult createArrayLikeTypeLayout( - TypeLayoutContext const& context, + TypeLayoutContext& context, Type* type, Type* baseType, IntVal* arrayLength @@ -3607,23 +3607,23 @@ static TypeLayoutResult createArrayLikeTypeLayout( return TypeLayoutResult(typeLayout, arrayUniformInfo); } -static void _addLayout(TypeLayoutContext const& context, +static void _addLayout(TypeLayoutContext& context, Type* type, TypeLayout* layout) { // Add it *without info*. // The info can be added with _updateLayout - context.layoutMap[type] = TypeLayoutResult(layout, SimpleLayoutInfo()); + context.layoutMap.set(type, TypeLayoutResult(layout, SimpleLayoutInfo())); } -static void _addLayout(TypeLayoutContext const& context, +static void _addLayout(TypeLayoutContext& context, Type* type, const TypeLayoutResult& result) { context.layoutMap[type] = result; } -static TypeLayoutResult _updateLayout(TypeLayoutContext const& context, +static TypeLayoutResult _updateLayout(TypeLayoutContext& context, Type* type, const TypeLayoutResult& result) { @@ -3641,7 +3641,7 @@ static TypeLayoutResult _updateLayout(TypeLayoutContext const& context, } static TypeLayoutResult _createTypeLayout( - TypeLayoutContext const& context, + TypeLayoutContext& context, Type* type) { if (auto layoutResultPtr = context.layoutMap.tryGetValue(type)) @@ -4226,7 +4226,7 @@ static TypeLayoutResult _createTypeLayout( // auto anyValueRules = context.getRulesFamily()->getAnyValueRules(); RefPtr<TypeLayout> concreteTypeAnyValueLayout = - createTypeLayout(context.with(anyValueRules), concreteType); + createTypeLayoutWith(context, anyValueRules, concreteType); // We will look at the resource usage of the concrete type // to determine if it "fits" in the reserved space. @@ -4547,12 +4547,22 @@ RefPtr<TypeLayout> getSimpleVaryingParameterTypeLayout( } RefPtr<TypeLayout> createTypeLayout( - TypeLayoutContext const& context, + TypeLayoutContext& context, Type* type) { return _createTypeLayout(context, type).layout; } +RefPtr<TypeLayout> createTypeLayoutWith( + const TypeLayoutContext& context, + LayoutRulesImpl* rules, + Type* type) +{ + auto c = context.with(rules); + return createTypeLayout(c, type); +} + + void TypeLayout::removeResourceUsage(LayoutResourceKind kind) { Int infoCount = resourceInfos.getCount(); |
