From 45d9961a6a86d184248ef84f6a07125b0c224f97 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Wed, 16 Aug 2023 08:57:47 +0800 Subject: Use ankerl/unordered_dense as a hashmap implementation (#3036) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- source/slang/slang-parameter-binding.cpp | 48 +++++++++++++++++++------------- 1 file changed, 28 insertions(+), 20 deletions(-) (limited to 'source/slang/slang-parameter-binding.cpp') diff --git a/source/slang/slang-parameter-binding.cpp b/source/slang/slang-parameter-binding.cpp index c0389d1cd..f9e2433cf 100644 --- a/source/slang/slang-parameter-binding.cpp +++ b/source/slang/slang-parameter-binding.cpp @@ -676,8 +676,9 @@ RefPtr getTypeLayoutForGlobalShaderParameter( if(varDecl->hasModifier() && as(type)) { - return createTypeLayout( - layoutContext.with(rules->getShaderRecordConstantBufferRules()), + return createTypeLayoutWith( + layoutContext, + rules->getShaderRecordConstantBufferRules(), type); } @@ -686,8 +687,9 @@ RefPtr getTypeLayoutForGlobalShaderParameter( // qualifier before we move on to anything else. if( varDecl->hasModifier() && as(type) ) { - return createTypeLayout( - layoutContext.with(rules->getPushConstantBufferRules()), + return createTypeLayoutWith( + layoutContext, + rules->getPushConstantBufferRules(), type); } @@ -710,8 +712,9 @@ RefPtr getTypeLayoutForGlobalShaderParameter( // An "ordinary" global variable is implicitly a uniform // shader parameter. - return createTypeLayout( - layoutContext.with(rules->getConstantBufferRules(context->getTargetRequest())), + return createTypeLayoutWith( + layoutContext, + rules->getConstantBufferRules(context->getTargetRequest()), type); } @@ -1910,15 +1913,19 @@ static RefPtr processEntryPointVaryingParameter( case Stage::ClosestHit: case Stage::Miss: // `in out` or `out` parameter is payload - return createTypeLayout(context->layoutContext.with( - context->getRulesFamily()->getRayPayloadParameterRules()), - type); + return createTypeLayoutWith( + context->layoutContext, + context->getRulesFamily()->getRayPayloadParameterRules(), + type + ); case Stage::Callable: // `in out` or `out` parameter is payload - return createTypeLayout(context->layoutContext.with( - context->getRulesFamily()->getCallablePayloadParameterRules()), - type); + return createTypeLayoutWith( + context->layoutContext, + context->getRulesFamily()->getCallablePayloadParameterRules(), + type + ); } } @@ -1946,9 +1953,11 @@ static RefPtr processEntryPointVaryingParameter( case Stage::AnyHit: case Stage::ClosestHit: // `in` parameter is hit attributes - return createTypeLayout(context->layoutContext.with( - context->getRulesFamily()->getHitAttributesParameterRules()), - type); + return createTypeLayoutWith( + context->layoutContext, + context->getRulesFamily()->getHitAttributesParameterRules(), + type + ); } } @@ -2226,9 +2235,9 @@ static RefPtr computeEntryPointParameterTypeLayout( // a uniform shader parameter passed via the implicitly-defined // constant buffer (e.g., the `$Params` constant buffer seen in fxc/dxc output). // - return createTypeLayout( - context->layoutContext.with( - context->getRulesFamily()->getConstantBufferRules(context->getTargetRequest())), + return createTypeLayoutWith( + context->layoutContext, + context->getRulesFamily()->getConstantBufferRules(context->getTargetRequest()), paramType); } else @@ -3171,9 +3180,8 @@ void diagnoseGlobalUniform( static int _calcTotalNumUsedRegistersForLayoutResourceKind(ParameterBindingContext* bindingContext, LayoutResourceKind kind) { int numUsed = 0; - for (auto& pair : bindingContext->shared->globalSpaceUsedRangeSets) + for (auto& [_, rangeSet] : bindingContext->shared->globalSpaceUsedRangeSets) { - UsedRangeSet* rangeSet = pair.value; const auto& usedRanges = rangeSet->usedResourceRanges[kind]; for (const auto& usedRange : usedRanges.ranges) { -- cgit v1.2.3