Example #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);
            }
        }
Example #2
0
        public static ShaderEntryPointInfo GeneratePixel(FrontEndTranslator translator, ShaderType shaderType, ShaderFunction function)
        {
            var entryPoint = new ShaderEntryPointInfo();
            var context    = new FrontEndContext();

            context.mCurrentType = shaderType;

            var interfaceInfo = new EntryPointInterfaceInfo();

            EntryPointGenerationShared.CollectInterface(translator, shaderType, interfaceInfo);

            // Build inputs block
            EntryPointGenerationShared.GenerateHardwareBuiltIns(translator, interfaceInfo.HardwareBuiltInInputs, StorageClass.Input, entryPoint.mInterfaceVariables, entryPoint.mDecorations);
            InputDeclarations.GenerateInputStruct(translator, shaderType, interfaceInfo.StageInputs, entryPoint.mInterfaceVariables, entryPoint.mDecorations);
            EntryPointGenerationShared.GenerateHardwareBuiltIns(translator, interfaceInfo.HardwareBuiltInOutputs, StorageClass.Output, entryPoint.mInterfaceVariables, entryPoint.mDecorations);
            OutputDeclarations.GenerateOutputFields(translator, shaderType, interfaceInfo.StageOutputs, entryPoint.mInterfaceVariables, entryPoint.mDecorations);
            UniformDeclarations.DeclareUniformBuffers(translator, interfaceInfo.UniformBuffers, entryPoint.mInterfaceVariables, entryPoint.mDecorations);
            UniformDeclarations.DeclareUniformConstants(translator, interfaceInfo.ConstantUniforms, entryPoint.mDecorations);

            // Create the functions required to run an entry point
            string entryPointName = EntryPointGenerationShared.GenerateEntryPointFunctionName(translator, shaderType, function);

            CreateGlobalVariableInitializeFunction(translator, shaderType, entryPoint, interfaceInfo, context);
            InputDeclarations.GenerateCopyInputsFunction(translator, shaderType, entryPoint, interfaceInfo);
            OutputDeclarations.GenerateCopyOutputsFunction(translator, shaderType, entryPoint, interfaceInfo);
            var entryPointFunction = GenerateSpirVEntryPointFunction(translator, shaderType, entryPointName);

            // Generate the entry point function body
            translator.TryGenerateFunctionCall(entryPoint.mGlobalsInitializationFunction, null, null, entryPointFunction.Context);
            EntryPointGenerationShared.ConstructShaderType(translator, shaderType, entryPointFunction.Context);

            var entryPointThisOp = entryPointFunction.Context.mThisOp;

            translator.TryGenerateFunctionCall(interfaceInfo.CopyInputsFunction.ShaderFunction, entryPointThisOp, null, entryPointFunction.Context);
            translator.TryGenerateFunctionCall(function, entryPointThisOp, null, entryPointFunction.Context);
            translator.TryGenerateFunctionCall(interfaceInfo.CopyOutputsFunction.ShaderFunction, entryPointThisOp, null, entryPointFunction.Context);
            translator.FixupBlockTerminators(entryPointFunction.ShaderFunction);

            // Make sure all global variables are added to the interface of the entry point
            AddGlobalVariables(translator, entryPoint, interfaceInfo);

            entryPoint.mEntryPointFunction = entryPointFunction.ShaderFunction;
            entryPoint.mStageType          = shaderType.mFragmentType;
            shaderType.mEntryPoints.Add(entryPoint);

            EntryPointGenerationShared.AddExecutionMode(translator, entryPoint, entryPoint.mEntryPointFunction, Spv.ExecutionMode.ExecutionModeOriginUpperLeft);
            return(entryPoint);
        }