Ejemplo n.º 1
0
        public static void CollectInterface(FrontEndTranslator translator, ShaderType shaderType, EntryPointInterfaceInfo interfaceInfo)
        {
            CollectStageInputsOuputs(translator, shaderType, interfaceInfo);
            UniformDeclarations.GenerateUniforms(translator, shaderType, interfaceInfo);
            UniformDeclarations.GenerateConstantUniforms(translator, shaderType, interfaceInfo);

            // @JoshD: Hack for now, this should really check what's reachable. This also needs to walk all dependent libraries
            foreach (var globalStatic in translator.mCurrentLibrary.mStaticGlobals.Values)
            {
                interfaceInfo.GlobalFields.Add(globalStatic);
            }
        }
Ejemplo n.º 2
0
        public static void CreateGlobalVariableInitializeFunction(FrontEndTranslator translator, ShaderType shaderType, ShaderEntryPointInfo entryPoint, EntryPointInterfaceInfo interfaceInfo, FrontEndContext context)
        {
            // First check if any global variables that need the variable initialization function exist. If not then don't emit anything.
            bool globalVariablesExist = false;

            foreach (var globalField in interfaceInfo.GlobalFields)
            {
                if (globalField.InitialValue != null)
                {
                    globalVariablesExist = true;
                }
            }
            if (!globalVariablesExist)
            {
                return;
            }

            var library            = translator.mCurrentLibrary;
            var voidType           = library.FindType(new TypeKey(typeof(void)));
            var initGlobalFunction = translator.CreateFunctionAndType(shaderType, voidType, "InitGlobals", null, null);

            initGlobalFunction.mBlocks.Add(new ShaderBlock());
            entryPoint.mGlobalsInitializationFunction = initGlobalFunction;

            // Add the store op for each global variable
            context.mCurrentFunction = initGlobalFunction;
            context.mCurrentBlock    = initGlobalFunction.mBlocks[0];
            foreach (var globalField in interfaceInfo.GlobalFields)
            {
                if (globalField.InitialValue != null)
                {
                    translator.CreateStoreOp(context.mCurrentBlock, globalField.InstanceOp, globalField.InitialValue);
                }
            }
            translator.FixupBlockTerminators(context.mCurrentFunction);
        }
Ejemplo n.º 3
0
 public static void AddGlobalVariables(FrontEndTranslator translator, ShaderEntryPointInfo entryPoint, EntryPointInterfaceInfo interfaceInfo)
 {
     foreach (var globalShaderField in interfaceInfo.GlobalFields)
     {
         entryPoint.mGlobalVariablesBlock.mLocalVariables.Add(globalShaderField.InstanceOp);
     }
 }
Ejemplo n.º 4
0
        public static void GenerateUniforms(FrontEndTranslator translator, ShaderType shaderType, EntryPointInterfaceInfo interfaceInfo)
        {
            List <(ShaderField Field, Shader.UniformBuffer Attribute)> uniformBufferFieldsWithBindings    = new List <(ShaderField Field, Shader.UniformBuffer Attribute)>();
            List <(ShaderField Field, Shader.UniformBuffer Attribute)> uniformBufferFieldsWithoutBindings = new List <(ShaderField Field, Shader.UniformBuffer Attribute)>();
            List <(ShaderField Field, ShaderAttribute Attribute)>      uniformInputFields = new List <(ShaderField Field, ShaderAttribute Attribute)>();

            // Collect all UniformBuffers and Uniform Inputs
            foreach (var field in shaderType.mFields)
            {
                var attributes = field.mMeta.mAttributes;
                attributes.ForeachAttribute(typeof(Shader.UniformBufferField), (ShaderAttribute attribute) =>
                {
                    uniformInputFields.Add((Field: field, Attribute: attribute));
                });