void FShader::Register() { FShaderId ShaderId = GetId(); check(ShaderId.MaterialShaderMapHash != FSHAHash()); check(ShaderId.SourceHash != FSHAHash()); check(Resource); Type->AddToShaderIdMap(ShaderId, 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; // todo: can we avoid the memcpy? Code = Output.ShaderCode.GetReadAccess(); 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); }
FShaderResource::FShaderResource(const FShaderCompilerOutput& Output) : NumInstructions(Output.NumInstructions) , NumTextureSamplers(Output.NumTextureSamplers) , NumRefs(0) { Target = Output.Target; Code = Output.Code; check(Code.Num() > 0); OutputHash = Output.OutputHash; checkSlow(OutputHash != FSHAHash()); 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); }
/** * Construct a shader from shader compiler output. */ FShader::FShader(const CompiledShaderInitializerType& Initializer): MaterialShaderMapHash(Initializer.MaterialShaderMapHash), VFType(Initializer.VertexFactoryType), Type(Initializer.Type), Target(Initializer.Target), NumRefs(0), SetParametersId(0), Canary(ShaderMagic_Initialized) { OutputHash = Initializer.OutputHash; checkSlow(OutputHash != FSHAHash()); if (Type) { // Store off the source hash that this shader was compiled with // This will be used as part of the shader key in order to identify when shader files have been changed and a recompile is needed SourceHash = Type->GetSourceHash(); } if (VFType) { // Store off the VF source hash that this shader was compiled with VFSourceHash = VFType->GetSourceHash(); } // Bind uniform buffer parameters automatically for (TLinkedList<FUniformBufferStruct*>::TIterator StructIt(FUniformBufferStruct::GetStructList()); StructIt; StructIt.Next()) { if (Initializer.ParameterMap.ContainsParameterAllocation(StructIt->GetShaderVariableName())) { UniformBufferParameterStructs.Add(*StructIt); UniformBufferParameters.Add(StructIt->ConstructTypedParameter()); FShaderUniformBufferParameter* Parameter = UniformBufferParameters.Last(); Parameter->Bind(Initializer.ParameterMap, StructIt->GetShaderVariableName(), SPF_Mandatory); } } SetResource(Initializer.Resource); // Register the shader now that it is valid, so that it can be reused Register(); }