void FShaderResource::Release() { // We need to lock the resource map so that no resource gets acquired by // FindShaderResourceById while we (potentially) remove this resource FScopeLock ShaderResourceIdMapLock(&ShaderResourceIdMapCritical); check(NumRefs != 0); if(--NumRefs == 0) { ShaderResourceIdMap.Remove(GetId()); // Send a release message to the rendering thread when the shader loses its last reference. BeginReleaseResource(this); Canary = FShader::ShaderMagic_CleaningUp; BeginCleanup(this); } }
FShaderResource::FShaderResource(const FShaderCompilerOutput& Output, FShaderType* InSpecificType) : SpecificType(InSpecificType) , NumInstructions(Output.NumInstructions) , NumTextureSamplers(Output.NumTextureSamplers) , NumRefs(0) , Canary(FShader::ShaderMagic_Initialized) { Target = Output.Target; Code = Output.Code; check(Code.Num() > 0); OutputHash = Output.OutputHash; checkSlow(OutputHash != FSHAHash()); { FScopeLock ShaderResourceIdMapLock(&ShaderResourceIdMapCritical); ShaderResourceIdMap.Add(GetId(), this); } INC_DWORD_STAT_BY_FName(GetMemoryStatType((EShaderFrequency)Target.Frequency).GetName(), Code.Num()); INC_DWORD_STAT_BY(STAT_Shaders_ShaderResourceMemory, GetSizeBytes()); INC_DWORD_STAT_BY(STAT_Shaders_NumShaderResourcesLoaded, 1); }
void FShaderResource::GetAllShaderResourceId(TArray<FShaderResourceId>& Ids) { FScopeLock ShaderResourceIdMapLock(&ShaderResourceIdMapCritical); ShaderResourceIdMap.GetKeys(Ids); }
TRefCountPtr<FShaderResource> FShaderResource::FindShaderResourceById(const FShaderResourceId& Id) { FScopeLock ShaderResourceIdMapLock(&ShaderResourceIdMapCritical); TRefCountPtr<FShaderResource> Result = ShaderResourceIdMap.FindRef(Id); return Result; }
void FShaderResource::Register() { FScopeLock ShaderResourceIdMapLock(&ShaderResourceIdMapCritical); ShaderResourceIdMap.Add(GetId(), this); }