public ShaderFunction CreateFunction(CSharpSyntaxNode node, IMethodSymbol fnSymbol, string fnName, ShaderType returnType, List <ShaderType> paramTypes) { var owningType = mContext.mCurrentType; // Collect function return and parameter types from the syntax node var thisType = fnSymbol.IsStatic ? null : owningType.FindPointerType(StorageClass.Function); var shaderFunction = mFrontEnd.CreateFunctionAndType(owningType, returnType, fnName, thisType, paramTypes); ParseAttributes(shaderFunction.mMeta, fnSymbol); ExtractDebugInfo(shaderFunction, fnSymbol, node); mFrontEnd.mCurrentLibrary.AddFunction(new FunctionKey(fnSymbol), shaderFunction); return(shaderFunction); }
public static EntryPointFunction GenerateSpirVEntryPointFunction(FrontEndTranslator translator, ShaderType shaderType, string entryPointFnName) { EntryPointFunction entryPointFunction = new EntryPointFunction(); var library = translator.mCurrentLibrary; var voidType = library.FindType(new TypeKey(typeof(void))); entryPointFunction.ShaderFunction = translator.CreateFunctionAndType(shaderType, voidType, entryPointFnName, null, null); entryPointFunction.ShaderFunction.mBlocks.Add(new ShaderBlock()); entryPointFunction.Context = new FrontEndContext(); entryPointFunction.Context.mCurrentType = shaderType; entryPointFunction.Context.mCurrentFunction = entryPointFunction.ShaderFunction; entryPointFunction.Context.mCurrentBlock = entryPointFunction.ShaderFunction.mBlocks[0]; return(entryPointFunction); }
public static ShaderFunction GenerateFunction_ShaderTypeParam(FrontEndTranslator translator, ShaderType shaderType, string functionName, out ShaderOp thisOp) { var library = translator.mCurrentLibrary; var voidType = library.FindType(new TypeKey(typeof(void))); var thisType = shaderType.FindPointerType(StorageClass.Function); var fnArgsTypes = new List <ShaderType>() { thisType }; var function = translator.CreateFunctionAndType(shaderType, voidType, functionName, null, fnArgsTypes); thisOp = translator.CreateOp(function.mParametersBlock, OpInstructionType.OpFunctionParameter, thisType, null); thisOp.DebugInfo.Name = "self"; function.mBlocks.Add(new ShaderBlock()); return(function); }
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); }