FShader* FGlobalShaderType::FinishCompileShader(const FShaderCompileJob& CurrentJob) { if (CurrentJob.bSucceeded) { // Reuse an existing resource with the same key or create a new one based on the compile output // This allows FShaders to share compiled bytecode and RHI shader references FShaderResource* Resource = FShaderResource::FindOrCreateShaderResource(CurrentJob.Output); check(Resource); // Find a shader with the same key in memory FShader* Shader = CurrentJob.ShaderType->FindShaderById(FShaderId(GGlobalShaderMapHash, NULL, CurrentJob.ShaderType, CurrentJob.Input.Target)); // There was no shader with the same key so create a new one with the compile output, which will bind shader parameters if (!Shader) { Shader = (*ConstructCompiledRef)(CompiledShaderInitializerType(this, CurrentJob.Output, Resource, GGlobalShaderMapHash, NULL)); CurrentJob.Output.ParameterMap.VerifyBindingsAreComplete(GetName(), (EShaderFrequency)CurrentJob.Output.Target.Frequency, CurrentJob.VFType); } return Shader; } else { return NULL; } }
/** * Either creates a new instance of this type or returns an equivalent existing shader. * @param Material - The material to link the shader with. * @param CurrentJob - Compile job that was enqueued by BeginCompileShader. */ FShader* FMeshMaterialShaderType::FinishCompileShader( const FUniformExpressionSet& UniformExpressionSet, const FSHAHash& MaterialShaderMapHash, const FShaderCompileJob& CurrentJob, const FShaderPipelineType* ShaderPipelineType, const FString& InDebugDescription) { check(CurrentJob.bSucceeded); check(CurrentJob.VFType); FShaderType* SpecificType = CurrentJob.ShaderType->LimitShaderResourceToThisType() ? CurrentJob.ShaderType : NULL; // Reuse an existing resource with the same key or create a new one based on the compile output // This allows FShaders to share compiled bytecode and RHI shader references FShaderResource* Resource = FShaderResource::FindOrCreateShaderResource(CurrentJob.Output, SpecificType); if (ShaderPipelineType && !ShaderPipelineType->ShouldOptimizeUnusedOutputs()) { // If sharing shaders in this pipeline, remove it from the type/id so it uses the one in the shared shadermap list ShaderPipelineType = nullptr; } // Find a shader with the same key in memory FShader* Shader = CurrentJob.ShaderType->FindShaderById(FShaderId(MaterialShaderMapHash, ShaderPipelineType, CurrentJob.VFType, CurrentJob.ShaderType, CurrentJob.Input.Target)); // There was no shader with the same key so create a new one with the compile output, which will bind shader parameters if (!Shader) { Shader = (*ConstructCompiledRef)(CompiledShaderInitializerType(this, CurrentJob.Output, Resource, UniformExpressionSet, MaterialShaderMapHash, InDebugDescription, ShaderPipelineType, CurrentJob.VFType)); CurrentJob.Output.ParameterMap.VerifyBindingsAreComplete(GetName(), (EShaderFrequency)CurrentJob.Output.Target.Frequency, CurrentJob.VFType); } return Shader; }