Пример #1
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);
        }