static std::shared_ptr<RetainedFileRecord> GetRetainedFileRecord(StringSection<ResChar> filename) { // We should normalize to avoid problems related to // case insensitivity and slash differences ResolvedAssetFile assetName; MakeAssetName(assetName, filename); auto hash = Hash64(assetName._fn); { ScopedLock(RetainedRecordsLock); auto i = LowerBound(RetainedRecords, hash); if (i!=RetainedRecords.end() && i->first == hash) { return i->second; } // we should call "AttachFileSystemMonitor" before we query for the // file's current modification time auto newRecord = std::make_shared<RetainedFileRecord>(assetName._fn); RegisterFileDependency(newRecord, assetName._fn); newRecord->_state._timeMarker = GetFileModificationTime(assetName._fn); RetainedRecords.insert(i, std::make_pair(hash, newRecord)); return std::move(newRecord); } }
void NascentAnimationSet::Serialize(Serialization::NascentBlockSerializer& serializer) const { serializer.SerializeSubBlock(AsPointer(_animationDrivers.begin()), AsPointer(_animationDrivers.end())); serializer.SerializeValue(_animationDrivers.size()); serializer.SerializeSubBlock(AsPointer(_constantDrivers.begin()), AsPointer(_constantDrivers.end())); serializer.SerializeValue(_constantDrivers.size()); serializer.SerializeSubBlock(AsPointer(_constantData.begin()), AsPointer(_constantData.end())); // List of animations... auto outputAnimations = std::make_unique<AnimationDesc[]>(_animations.size()); for (size_t c=0; c<_animations.size(); ++c) { AnimationDesc&o = outputAnimations[c]; const Animation&i = _animations[c]; o._name = Hash64(AsPointer(i._name.begin()), AsPointer(i._name.end())); o._beginDriver = i._begin; o._endDriver = i._end; o._beginConstantDriver = i._constantBegin; o._endConstantDriver = i._constantEnd; o._beginTime = i._startTime; o._endTime = i._endTime; } std::sort(outputAnimations.get(), &outputAnimations[_animations.size()], CompareAnimationName()); serializer.SerializeSubBlock(outputAnimations.get(), &outputAnimations[_animations.size()]); serializer.SerializeValue(_animations.size()); // Output interface... ConsoleRig::DebuggerOnlyWarning("Animation set output interface:\n"); auto parameterNameHashes = std::make_unique<uint64[]>(_parameterInterfaceDefinition.size()); for (size_t c=0; c<_parameterInterfaceDefinition.size(); ++c) { ConsoleRig::DebuggerOnlyWarning(" [%i] %s\n", c, _parameterInterfaceDefinition[c].c_str()); parameterNameHashes[c] = Hash64(AsPointer(_parameterInterfaceDefinition[c].begin()), AsPointer(_parameterInterfaceDefinition[c].end())); } serializer.SerializeSubBlock(parameterNameHashes.get(), ¶meterNameHashes[_parameterInterfaceDefinition.size()]); serializer.SerializeValue(_parameterInterfaceDefinition.size()); }
void SetParameters( void* obj, const ClassAccessors& accessors, const ParameterBox& paramBox) { // we can choose to iterate through the parameters in either way: // either by iterating through the accessors in "accessors" and pulling // values from the parameter box... // or by iterating through the parameters in "paramBox" and pushing those // values in. // We have to consider array cases -- perhaps it easier to go through the // parameters in the parameter box for (auto i=paramBox.Begin(); !i.IsEnd(); ++i) { const auto nameStart = i.Name(); const auto nameEnd = XlStringEnd(nameStart); auto arrayBracket = std::find(nameStart, nameEnd, '['); if (arrayBracket == nameEnd) { accessors.TryOpaqueSet( obj, Hash64(nameStart, nameEnd), i.RawValue(), i.Type(), false); } else { auto arrayIndex = XlAtoUI32((const char*)(arrayBracket+1)); accessors.TryOpaqueSet( obj, Hash64(nameStart, arrayBracket), arrayIndex, i.RawValue(), i.Type(), false); } } }
static uint64 Hash(const Metal::InputElementDesc& desc) { // hash the semantic name and the scalar parameters // Note that sometimes there might be a chance of equivalent // elements producing different hash values // (for example, _alignedByteOffset can be ~unsigned(0x0) to // choose the default offset -- so if another desc explicitly // sets the offset, the values will be different) auto t = Hash64(desc._semanticName); t ^= Hash64(&desc._semanticIndex, PtrAdd(&desc._instanceDataStepRate, sizeof(unsigned))); return t; }
bool IsDXTNormalMap(const std::string& textureName) { if (textureName.empty()) return false; auto& cache = Techniques::FindCachedBox<CachedTextureFormats>( CachedTextureFormats::Desc()); typedef CachedTextureFormats::Header Hdr; typedef CachedTextureFormats::Entry Entry; auto* data = cache._cache->GetData(); auto& hdr = *(Hdr*)data; auto* start = (Entry*)PtrAdd(data, sizeof(Hdr)); auto* end = (Entry*)PtrAdd(data, sizeof(Hdr) + sizeof(Entry) * hdr._count); auto hashName = Hash64(textureName); auto* i = std::lower_bound(start, end, hashName, CompareFirst<uint64, uint32>()); if (i == end || i->first != hashName) { if ((hdr._count+1) > CachedTextureFormats::MaxCachedTextures) { assert(0); // cache has gotten too big return false; } std::move_backward(i, end, end+1); i->first = hashName; TRY { i->second = (uint32)DeferredShaderResource::LoadFormat(textureName.c_str()); } CATCH (const ::Assets::Exceptions::InvalidAsset&) { i->second = RenderCore::Metal::NativeFormat::Unknown; } CATCH_END ++hdr._count; return i->second >= RenderCore::Metal::NativeFormat::BC1_TYPELESS && i->second <= RenderCore::Metal::NativeFormat::BC1_UNORM_SRGB; }
std::vector<uint64> NascentModelCommandStream::GetInputInterface() const { std::vector<uint64> inputInterface(_transformationMachineOutputs.size()); unsigned c=0; for (auto i=_transformationMachineOutputs.begin(); i!=_transformationMachineOutputs.end(); ++i, ++c) inputInterface[c] = Hash64(AsPointer(i->_name.begin()), AsPointer(i->_name.end())); return std::move(inputInterface); }
std::vector<const ModelSupplementScaffold*> ModelCache::Pimpl::LoadSupplementScaffolds( const ResChar modelFilename[], const ResChar materialFilename[], IteratorRange<const SupplementGUID*> supplements) { std::vector<const ModelSupplementScaffold*> result; for (auto s=supplements.cbegin(); s!=supplements.cend(); ++s) { auto hashName = HashCombine(HashCombine(Hash64(modelFilename), Hash64(materialFilename)), *s); auto supp = _supplements.Get(hashName); if (!supp || supp->GetDependencyValidation()->GetValidationIndex() > 0) { supp = Internal::CreateSupplement(*s, modelFilename, materialFilename); if (supp) _supplements.Insert(hashName, supp); } if (supp) result.push_back(supp.get()); } return std::move(result); }
ModelScaffold* ModelCache::GetModelScaffold(const ResChar modelFilename[]) { auto hashedModelName = Hash64(modelFilename); auto* result = _pimpl->_modelScaffolds.Get(hashedModelName).get(); if (!result || result->GetDependencyValidation()->GetValidationIndex() > 0) { auto model = Internal::CreateModelScaffold(modelFilename, *_pimpl->_format); _pimpl->_modelScaffolds.Insert(hashedModelName, model); result = model.get(); } return result; }
void InvalidAssetManager::MarkValid(const ResChar name[]) { if (_pimpl->_active) { ScopedLock(_pimpl->_assetsLock); auto hashName = Hash64(name); auto i = LowerBound(_pimpl->_assets, hashName); if (i != _pimpl->_assets.end() && i->first == hashName) { _pimpl->_assets.erase(i); } } }
GlobalServices::GlobalServices(const StartupConfig& cfg) { _shortTaskPool = std::make_unique<CompletionThreadPool>(cfg._shortTaskThreadPoolCount); _longTaskPool = std::make_unique<CompletionThreadPool>(cfg._longTaskThreadPoolCount); MainRig_Startup(cfg, _crossModule._services); _crossModule.Publish(*this); // add "nsight" marker to global services when "-nsight" is on // the command line. This is an easy way to record a global (&cross-dll) // state to use the nsight configuration when the given flag is set. const auto* cmdLine = XlGetCommandLine(); if (cmdLine && XlFindString(cmdLine, "-nsight")) _crossModule._services.Add(Hash64("nsight"), []() { return true; }); }
void InvalidAssetManager::MarkInvalid(const rstring& name, const rstring& errorString) { if (_pimpl->_active) { ScopedLock(_pimpl->_assetsLock); auto hashName = Hash64(name); auto i = LowerBound(_pimpl->_assets, hashName); if (i != _pimpl->_assets.end() && i->first == hashName) { assert(i->second._name == name); i->second._errorString = errorString; } else { _pimpl->_assets.insert( i, std::make_pair(hashName, AssetRef { name, errorString })); } } }
void AccessorDeserialize( Formatter& formatter, void* obj, const ClassAccessors& props) { using Blob = Formatter::Blob; using CharType = Formatter::value_type; auto charTypeCat = ImpliedTyping::TypeOf<CharType>()._type; for (;;) { switch (formatter.PeekNext()) { case Blob::AttributeName: { typename Formatter::InteriorSection name, value; if (!formatter.TryAttribute(name, value)) Throw(FormatException("Error in begin element", formatter.GetLocation())); auto arrayBracket = std::find(name._start, name._end, '['); if (arrayBracket == name._end) { if (!props.TryOpaqueSet( obj, Hash64(name._start, name._end), value._start, ImpliedTyping::TypeDesc(charTypeCat, uint16(value._end - value._start)), true)) { LogWarning << "Failure while assigning property during deserialization -- " << Conversion::Convert<std::string>(std::basic_string<CharType>(name._start, name._end)); } } else { auto arrayIndex = XlAtoUI32((const char*)(arrayBracket+1)); if (!props.TryOpaqueSet( obj, Hash64(name._start, arrayBracket), arrayIndex, value._start, ImpliedTyping::TypeDesc(charTypeCat, uint16(value._end - value._start)), true)) { LogWarning << "Failure while assigning array property during deserialization -- " << Conversion::Convert<std::string>(std::basic_string<CharType>(name._start, name._end)); } } } break; case Blob::EndElement: case Blob::None: return; case Blob::BeginElement: { typename Formatter::InteriorSection eleName; if (!formatter.TryBeginElement(eleName)) Throw(FormatException("Error in begin element", formatter.GetLocation())); auto created = props.TryCreateChild(obj, Hash64(eleName._start, eleName._end)); if (created.first) { AccessorDeserialize(formatter, created.first, *created.second); } else { LogWarning << "Couldn't find a match for element name during deserialization -- " << Conversion::Convert<std::string>(std::basic_string<CharType>(eleName._start, eleName._end)); formatter.SkipElement(); } if (!formatter.TryEndElement()) Throw(FormatException("Expecting end element", formatter.GetLocation())); break; } } } }
static inline uint64_t Translate(std::string key) { return Hash64(key.c_str(), key.length()); }
static inline uint64_t Translate(const char* key) { return Hash64(key, strlen(key)); }
static inline HeadType Translate(KeyType key) { return Hash64((const char*)&key, sizeof(KeyType)); }
BlackBoard::IdType BlackBoard::registerValue(const int8_t* buffer, int len) { ObjectType element(buffer,len); IdType id(Hash64(element.begin(), element.size())); _body[id] = std::move(element); return id; }