コード例 #1
0
 // 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());
         }
     }
 }
コード例 #2
0
        IEnumerable <BlockVariable> GetVariableEnumerable(FoundryHandle listHandle)
        {
            var localContainer = Container;
            var list           = new FixedHandleListInternal(listHandle);

            return(list.Select <BlockVariable>(localContainer, (handle) => (new BlockVariable(localContainer, handle))));
        }
コード例 #3
0
        IEnumerable <TemplatePassStageElement> GetStageElements(FoundryHandle stageElementListHandle)
        {
            var localContainer = Container;
            var list           = new FixedHandleListInternal(stageElementListHandle);

            return(list.Select(localContainer, (handle) => (new TemplatePassStageElement(localContainer, handle))));
        }
コード例 #4
0
 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;
 }
コード例 #5
0
 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();
 }
コード例 #6
0
        internal ITemplateLinker GetTemplateLinker(FoundryHandle linkerHandle)
        {
            if (linkerHandle.IsValid && (linkerHandle.Handle < m_TemplateLinkers.Count))
            {
                return(m_TemplateLinkers[(int)linkerHandle.Handle]);
            }

            return(null);
        }
コード例 #7
0
        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.");
            }
            }
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        // 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;
        }
コード例 #11
0
            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);
            }
コード例 #12
0
        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);
        }
コード例 #13
0
 internal extern PragmaDescriptorInternal GetPragmaDescriptor(FoundryHandle pragmaDescriptorHandle);
コード例 #14
0
 // private
 internal TemplateInstance(ShaderContainer container, FoundryHandle handle)
 {
     this.container        = container;
     this.handle           = handle;
     this.templateInstance = container?.GetTemplateInstance(handle) ?? TemplateInstanceInternal.Invalid();
 }
コード例 #15
0
 public bool Equals(FoundryHandle other) => this.ReferenceEquals(other);
コード例 #16
0
 internal bool ReferenceEquals(FoundryHandle other)
 {
     return(m_Handle == other.m_Handle);
 }
コード例 #17
0
 // private
 internal CustomizationPoint(ShaderContainer container, FoundryHandle handle)
 {
     this.container          = container;
     this.handle             = handle;
     this.customizationPoint = container?.GetCustomizationPoint(handle) ?? CustomizationPointInternal.Invalid();
 }
コード例 #18
0
 internal extern FunctionParameterInternal GetFunctionParameter(FoundryHandle functionParameterHandle);
コード例 #19
0
 internal extern CommandDescriptorInternal GetCommandDescriptor(FoundryHandle commandDescriptorHandle);
コード例 #20
0
 internal extern ShaderFunctionInternal GetFunction(FoundryHandle functionHandle);
コード例 #21
0
 internal extern FoundryHandle AddFunctionParameter(string name, FoundryHandle typeHandle, UInt32 flags);
コード例 #22
0
 internal extern DefineDescriptorInternal GetDefineDescriptor(FoundryHandle defineDescriptorHandle);
コード例 #23
0
 // private
 internal StructField(ShaderContainer container, FoundryHandle handle)
 {
     this.container = container;
     this.handle    = handle;
     this.field     = container?.GetStructField(handle) ?? StructFieldInternal.Invalid();
 }
コード例 #24
0
 // private
 internal TemplatePass(ShaderContainer container, FoundryHandle handle)
 {
     this.container    = container;
     this.handle       = handle;
     this.templatePass = container?.GetTemplatePass(handle) ?? TemplatePassInternal.Invalid();
 }
コード例 #25
0
 internal extern KeywordDescriptorInternal GetKeywordDescriptor(FoundryHandle keywordDescriptorHandle);
コード例 #26
0
 internal extern IncludeDescriptorInternal GetIncludeDescriptor(FoundryHandle includeDescriptorHandle);
コード例 #27
0
 internal extern static bool ValueEquals(ShaderContainer aContainer, FoundryHandle aHandle, ShaderContainer bContainer, FoundryHandle bHandle);
コード例 #28
0
 internal extern TagDescriptorInternal GetTagDescriptor(FoundryHandle tagDescriptorHandle);
コード例 #29
0
 // private
 internal TagDescriptor(ShaderContainer container, FoundryHandle handle)
 {
     this.container  = container;
     this.handle     = handle;
     this.descriptor = container?.GetTagDescriptor(handle) ?? TagDescriptorInternal.Invalid();
 }
コード例 #30
0
 internal extern bool SetFunction(FoundryHandle functionHandle, string name, string body, FoundryHandle returnTypeHandle, FoundryHandle parameterListHandle, FoundryHandle parentBlockHandle);