// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "NiagaraShared.h" #include "ShaderParameterMetadataBuilder.h" class FNiagaraShaderParametersBuilder { public: explicit FNiagaraShaderParametersBuilder(const FNiagaraDataInterfaceGPUParamInfo& InGPUParamInfo, TArray& InLooseNames, TArray& InStructIncludeInfos, FShaderParametersMetadataBuilder& InMetadataBuilder) : GPUParamInfo(InGPUParamInfo) , StructIncludeInfos(InStructIncludeInfos) , LooseNames(InLooseNames) , MetadataBuilder(InMetadataBuilder) { } // Adds a loose parameter that is scoped to the data interface // i.e. if the parameter was called "MyFloat" the shader variable would be "UniqueDataInterfaceName_MyFloat" template void AddLooseParam(const TCHAR* Name) { LooseNames.Emplace(FString::Printf(TEXT("%s_%s"), *GPUParamInfo.DataInterfaceHLSLSymbol, Name)); MetadataBuilder.AddParam(*LooseNames.Last()); } // Adds a loose array parameter that is scoped to the data interface // i.e. if the parameter was called "MyFloat" the shader variable would be "UniqueDataInterfaceName_MyFloat" template void AddLooseParamArray(const TCHAR* Name, int32 NumElements) { LooseNames.Emplace(FString::Printf(TEXT("%s_%s"), *GPUParamInfo.DataInterfaceHLSLSymbol, Name)); MetadataBuilder.AddParamArray(*LooseNames.Last(), NumElements); } // Adds a shader parameters structure that is scoped to the data interface // i.e. if the structured contained "MyFloat" the shader variable would be "UniqueDataInterfaceName_MyFloat" template void AddNestedStruct() { MetadataBuilder.AddNestedStruct(*GPUParamInfo.DataInterfaceHLSLSymbol); } // Adds a shader parameters structure that is global in scope // i.e. if the structure contained "MyFloat" the shader variable would be named "MyFloat" inline void AddIncludedStruct(const FShaderParametersMetadata* StructMetadata) { for (const FNiagaraDataInterfaceStructIncludeInfo& Existing : StructIncludeInfos) { if (Existing.StructMetadata == StructMetadata) { return; } } FNiagaraDataInterfaceStructIncludeInfo& NewInfo = StructIncludeInfos.AddDefaulted_GetRef(); NewInfo.StructMetadata = StructMetadata; NewInfo.ParamterOffset = Align(MetadataBuilder.GetNextMemberOffset(), SHADER_PARAMETER_STRUCT_ALIGNMENT); MetadataBuilder.AddIncludedStruct(StructMetadata); } // Adds a shader parameters structure that is global in scope // i.e. if the structure contained "MyFloat" the shader variable would be named "MyFloat" template void AddIncludedStruct() { AddIncludedStruct(TShaderParameterStructTypeInfo::GetStructMetadata()); } TConstArrayView GetGeneratedFunctions() const { return GPUParamInfo.GeneratedFunctions; } private: const FNiagaraDataInterfaceGPUParamInfo& GPUParamInfo; TArray& StructIncludeInfos; TArray& LooseNames; FShaderParametersMetadataBuilder& MetadataBuilder; };