// most types should be added via the ShaderType.* functions. // this function is used to ensure the shader type belongs to this container internal FoundryHandle AddShaderType(ShaderType shaderType, bool convertNonexistantToVoid) { if (shaderType.Exists) { if (shaderType.Container == this) { return(shaderType.handle); } else { // TODO: have to deep copy the definition from another container return(FoundryHandle.Invalid()); } } else { // invalid shader type... if (convertNonexistantToVoid) { return(ShaderTypeInternal.Void(this)); } else { return(FoundryHandle.Invalid()); } } }
IEnumerable <BlockVariable> GetVariableEnumerable(FoundryHandle listHandle) { var localContainer = Container; var list = new FixedHandleListInternal(listHandle); return(list.Select <BlockVariable>(localContainer, (handle) => (new BlockVariable(localContainer, handle)))); }
IEnumerable <TemplatePassStageElement> GetStageElements(FoundryHandle stageElementListHandle) { var localContainer = Container; var list = new FixedHandleListInternal(stageElementListHandle); return(list.Select(localContainer, (handle) => (new TemplatePassStageElement(localContainer, handle)))); }
internal Builder(ShaderContainer container, string name, ShaderType returnType, ShaderFoundry.Block.Builder parentBlockBuilder) { this.container = container; this.name = name; this.returnType = returnType; functionHandle = container.CreateFunctionInternal(); this.parentBlockBuilder = parentBlockBuilder; }
internal Builder(ShaderContainer container, string name, FoundryHandle passParentHandle, FoundryHandle templateParentHandle) { this.container = container; this.name = name; this.passParentHandle = passParentHandle; this.templateParentHandle = templateParentHandle; blockHandle = container.CreateBlockInternal(); }
internal ITemplateLinker GetTemplateLinker(FoundryHandle linkerHandle) { if (linkerHandle.IsValid && (linkerHandle.Handle < m_TemplateLinkers.Count)) { return(m_TemplateLinkers[(int)linkerHandle.Handle]); } return(null); }
void ProcessToken(string str, int startOffsetInclusive, int endOffsetExclusive, ShaderContainer container) { int length = endOffsetExclusive - startOffsetInclusive; if (length <= 2) { return; // can't possibly be a valid token } // Special tokens are used to done ids that are to be replaced with actual identifiers later: // - "$T:{id}$": Replaces the string with the type name with the given id. // - "$F:{id}$": Replaces the string with the function name with the given id. // - "$V:{id},{varName}$": Replaces the string with the variable declaration with the given id. // Variable declarations also need the variable name due to how arrays have to be declared: "type name[size]". // This may go away if we ever add a variable instance object. int offset = startOffsetInclusive; switch (str[offset]) { case 'V': // variable declaration { ParseTokenWithName(str, startOffsetInclusive, endOffsetExclusive, 'V', out int shaderTypeIndex, out string varName); // declare it! FoundryHandle shaderTypeHandle = new FoundryHandle(); shaderTypeHandle.Handle = (uint)shaderTypeIndex; var shaderType = new ShaderType(container, shaderTypeHandle); VariableDeclarationInternal(shaderType, varName, DeclarationMode.NoSemicolon); break; } case 'F': // function call - function name { int tokenId = ParseSimpleToken(str, startOffsetInclusive, endOffsetExclusive, 'F'); FoundryHandle shaderFunctionHandle = new FoundryHandle(); shaderFunctionHandle.Handle = (uint)tokenId; var shaderFunction = new ShaderFunction(container, shaderFunctionHandle); AddFunctionNameInternal(shaderFunction); break; } case 'T': // type name { int typeId = ParseSimpleToken(str, startOffsetInclusive, endOffsetExclusive, 'T'); FoundryHandle shaderTypeHandle = new FoundryHandle(); shaderTypeHandle.Handle = (uint)typeId; var shaderType = new ShaderType(container, shaderTypeHandle); AddNonArrayTypeNameInternal(shaderType); break; } default: { var tokenSubStr = str.Substring(startOffsetInclusive, endOffsetExclusive - startOffsetInclusive); throw new Exception($"Malformed token found when parsing '{tokenSubStr}'. Identifier {str[offset]} was unexpected."); } } }
public static FoundryHandle Build(ShaderContainer container, List <FoundryHandle> values) { if ((values == null) || (values.Count <= 0)) { return(FoundryHandle.Invalid()); } var listHandle = container.AddHandleBlob((uint)values.Count); for (var i = 0; i < values.Count; ++i) { container.SetHandleBlobElement(listHandle, (uint)i, values[i]); } return(listHandle); }
public static FoundryHandle Build <T>(ShaderContainer container, List <T> items, Func <T, FoundryHandle> indexFunc) { if ((items == null) || (items.Count <= 0)) { return(FoundryHandle.Invalid()); } var listHandle = container.AddHandleBlob((uint)items.Count); for (var i = 0; i < items.Count; ++i) { container.SetHandleBlobElement(listHandle, (uint)i, indexFunc(items[i])); } return(listHandle); }
// only for use by the Builder ShaderFunction(ShaderContainer container, FoundryHandle functionHandle, string name, string body, FoundryHandle returnTypeHandle, List <FunctionParameter> parameters, FoundryHandle parentBlockHandle) { this.container = container; if (container != null) { FoundryHandle parametersList = FixedHandleListInternal.Build(container, parameters, (p) => (p.handle)); handle = functionHandle; container.SetFunction(functionHandle, name, body, returnTypeHandle, parametersList, parentBlockHandle); function = container.GetFunction(handle); return; } // failure this = Invalid; }
public ShaderFunction Build() { if (finalized) { return(new ShaderFunction(Container, functionHandle)); } finalized = true; FoundryHandle parentBlockHandle = parentBlockBuilder?.blockHandle ?? FoundryHandle.Invalid(); var returnTypeHandle = container.AddShaderType(returnType, true); var builtFunction = new ShaderFunction(container, functionHandle, name, ConvertToString(), returnTypeHandle, parameters, parentBlockHandle); if (parentBlockBuilder != null) { // Register the new function with the parent block parentBlockBuilder.AddFunction(builtFunction); } return(builtFunction); }
internal FoundryHandle AddTemplateLinker(ITemplateLinker linker) { // If the linker is either null, or has already been added, we return an invalid handle if (linker == null) { throw new Exception("Registering a null template linker is not valid."); } var existingLinkerIndex = m_TemplateLinkers.FindIndex((l) => (l == linker)); if (existingLinkerIndex != -1) { throw new Exception($"Template linker '{linker}' has already been registered."); } FoundryHandle handle = new FoundryHandle(); handle.Handle = (uint)m_TemplateLinkers.Count; m_TemplateLinkers.Add(linker); return(handle); }
internal extern PragmaDescriptorInternal GetPragmaDescriptor(FoundryHandle pragmaDescriptorHandle);
// private internal TemplateInstance(ShaderContainer container, FoundryHandle handle) { this.container = container; this.handle = handle; this.templateInstance = container?.GetTemplateInstance(handle) ?? TemplateInstanceInternal.Invalid(); }
public bool Equals(FoundryHandle other) => this.ReferenceEquals(other);
internal bool ReferenceEquals(FoundryHandle other) { return(m_Handle == other.m_Handle); }
// private internal CustomizationPoint(ShaderContainer container, FoundryHandle handle) { this.container = container; this.handle = handle; this.customizationPoint = container?.GetCustomizationPoint(handle) ?? CustomizationPointInternal.Invalid(); }
internal extern FunctionParameterInternal GetFunctionParameter(FoundryHandle functionParameterHandle);
internal extern CommandDescriptorInternal GetCommandDescriptor(FoundryHandle commandDescriptorHandle);
internal extern ShaderFunctionInternal GetFunction(FoundryHandle functionHandle);
internal extern FoundryHandle AddFunctionParameter(string name, FoundryHandle typeHandle, UInt32 flags);
internal extern DefineDescriptorInternal GetDefineDescriptor(FoundryHandle defineDescriptorHandle);
// private internal StructField(ShaderContainer container, FoundryHandle handle) { this.container = container; this.handle = handle; this.field = container?.GetStructField(handle) ?? StructFieldInternal.Invalid(); }
// private internal TemplatePass(ShaderContainer container, FoundryHandle handle) { this.container = container; this.handle = handle; this.templatePass = container?.GetTemplatePass(handle) ?? TemplatePassInternal.Invalid(); }
internal extern KeywordDescriptorInternal GetKeywordDescriptor(FoundryHandle keywordDescriptorHandle);
internal extern IncludeDescriptorInternal GetIncludeDescriptor(FoundryHandle includeDescriptorHandle);
internal extern static bool ValueEquals(ShaderContainer aContainer, FoundryHandle aHandle, ShaderContainer bContainer, FoundryHandle bHandle);
internal extern TagDescriptorInternal GetTagDescriptor(FoundryHandle tagDescriptorHandle);
// private internal TagDescriptor(ShaderContainer container, FoundryHandle handle) { this.container = container; this.handle = handle; this.descriptor = container?.GetTagDescriptor(handle) ?? TagDescriptorInternal.Invalid(); }
internal extern bool SetFunction(FoundryHandle functionHandle, string name, string body, FoundryHandle returnTypeHandle, FoundryHandle parameterListHandle, FoundryHandle parentBlockHandle);