Created
May 10, 2022 08:27
-
-
Save ykafia/db5fd54dc84f645f053a722d17aecd22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SPVByteCode | |
| { | |
| public Instructions[] instructions; | |
| } | |
| public class ShaderCode | |
| { | |
| public List<SPVByteCode> ByteCodePieces; | |
| public AST Tree; | |
| public String Code; | |
| public ShaderMixer Mixer; | |
| public void Process() | |
| { | |
| GeerateAST(); | |
| SyntaxAnalysis(); | |
| } | |
| public void TreeVisitor() | |
| { | |
| // Going through the ast nodes, this is just for the example | |
| foreach(Node n in AST) | |
| { | |
| if(n is StructDefinition) | |
| { | |
| // Here, we add a bytecode piece containing a list of instructions. | |
| // Once we create all those bytecode pieces, the idea is to patch those | |
| // bytecode pieces together to create the final shader program | |
| var bytecode = Mixer.AddStructDefinition(n); | |
| ByteCodePieces.Add(bytecode); | |
| } | |
| // etc. | |
| } | |
| } | |
| } | |
| public class ShaderMixer | |
| { | |
| public List<ShaderCode> Mixins; | |
| public Dictionary<string,int> TypeIdentifiers; | |
| public Dictionary<int,string> TypeIdentifierReverseLookup; | |
| // ... Or maybe the dictionary should contain an object containing more data than just a string | |
| public byte[] Generate() | |
| { | |
| // Compile each shader , storing data in our TypeIdentifier dictionary | |
| foreach(var shader in Mixins) | |
| { | |
| // shader.Analysis(); | |
| shader.TreeVisitor(); | |
| } | |
| // Complex function to patch bytecode pieces together depending order of mixins, staged variables and such | |
| return GatherByteCode(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment