public GlslProgram Decompile(int[] Code, GalShaderType ShaderType) { ShaderIrBlock Block = ShaderDecoder.DecodeBasicBlock(Code, 0); ShaderIrNode[] Nodes = Block.GetNodes(); Decl = new GlslDecl(Nodes, ShaderType); SB = new StringBuilder(); SB.AppendLine("#version 410 core"); PrintDeclTextures(); PrintDeclUniforms(); PrintDeclInAttributes(); PrintDeclOutAttributes(); PrintDeclGprs(); PrintDeclPreds(); PrintBlockScope("void main()", 1, Nodes); string GlslCode = SB.ToString(); return(new GlslProgram( GlslCode, Decl.Textures.Values, Decl.Uniforms.Values)); }
public static GlslDecl Merge(GlslDecl VpA, GlslDecl VpB) { GlslDecl Combined = new GlslDecl(GalShaderType.Vertex); Merge(Combined.m_Textures, VpA.m_Textures, VpB.m_Textures); Merge(Combined.m_Uniforms, VpA.m_Uniforms, VpB.m_Uniforms); Merge(Combined.m_Attributes, VpA.m_Attributes, VpB.m_Attributes); Merge(Combined.m_OutAttributes, VpA.m_OutAttributes, VpB.m_OutAttributes); Merge(Combined.m_Gprs, VpA.m_Gprs, VpB.m_Gprs); Merge(Combined.m_Preds, VpA.m_Preds, VpB.m_Preds); //Merge input attributes. foreach (KeyValuePair <int, ShaderDeclInfo> KV in VpA.m_InAttributes) { Combined.m_InAttributes.TryAdd(KV.Key, KV.Value); } foreach (KeyValuePair <int, ShaderDeclInfo> KV in VpB.m_InAttributes) { //If Vertex Program A already writes to this attribute, //then we don't need to add it as an input attribute since //Vertex Program A will already have written to it anyway, //and there's no guarantee that there is an input attribute //for this slot. if (!VpA.m_OutAttributes.ContainsKey(KV.Key)) { Combined.m_InAttributes.TryAdd(KV.Key, KV.Value); } } return(Combined); }
public GlslProgram Decompile(IGalMemory Memory, long Position, GalShaderType ShaderType) { Blocks = ShaderDecoder.Decode(Memory, Position); Decl = new GlslDecl(Blocks, ShaderType); SB = new StringBuilder(); SB.AppendLine("#version 410 core"); PrintDeclTextures(); PrintDeclUniforms(); PrintDeclInAttributes(); PrintDeclOutAttributes(); PrintDeclGprs(); PrintDeclPreds(); PrintBlockScope(Blocks[0], null, null, "void main()", IdentationStr); string GlslCode = SB.ToString(); return(new GlslProgram( GlslCode, Decl.Textures.Values, Decl.Uniforms.Values)); }
public GlslProgram Decompile(IGalMemory Memory, long Position, GalShaderType ShaderType) { Blocks = ShaderDecoder.Decode(Memory, Position); BlocksB = null; Decl = new GlslDecl(Blocks, ShaderType); return(Decompile()); }
public GlslProgram Decompile(byte[] Binary, GalShaderType ShaderType) { Header = new ShaderHeader(Binary); HeaderB = null; Blocks = ShaderDecoder.Decode(Binary); BlocksB = null; Decl = new GlslDecl(Blocks, ShaderType, Header); return(Decompile()); }
public GlslProgram Decompile( IGalMemory Memory, long VpAPosition, long VpBPosition, GalShaderType ShaderType) { Blocks = ShaderDecoder.Decode(Memory, VpAPosition); BlocksB = ShaderDecoder.Decode(Memory, VpBPosition); GlslDecl DeclVpA = new GlslDecl(Blocks, ShaderType); GlslDecl DeclVpB = new GlslDecl(BlocksB, ShaderType); Decl = GlslDecl.Merge(DeclVpA, DeclVpB); return(Decompile()); }
public GlslProgram Decompile( byte[] BinaryA, byte[] BinaryB, GalShaderType ShaderType) { Header = new ShaderHeader(BinaryA); HeaderB = new ShaderHeader(BinaryB); Blocks = ShaderDecoder.Decode(BinaryA); BlocksB = ShaderDecoder.Decode(BinaryB); GlslDecl DeclVpA = new GlslDecl(Blocks, ShaderType, Header); GlslDecl DeclVpB = new GlslDecl(BlocksB, ShaderType, HeaderB); Decl = GlslDecl.Merge(DeclVpA, DeclVpB); return(Decompile()); }
private void PrintMain() { SB.AppendLine("void main() {"); foreach (KeyValuePair <int, ShaderDeclInfo> KV in Decl.InAttributes) { if (!Decl.Attributes.TryGetValue(KV.Key, out ShaderDeclInfo Attr)) { continue; } ShaderDeclInfo DeclInfo = KV.Value; if (Decl.ShaderType == GalShaderType.Geometry) { for (int Vertex = 0; Vertex < MaxVertexInput; Vertex++) { string Dst = Attr.Name + "[" + Vertex + "]"; string Src = "block_in[" + Vertex + "]." + DeclInfo.Name; SB.AppendLine(IdentationStr + Dst + " = " + Src + ";"); } } else { SB.AppendLine(IdentationStr + Attr.Name + " = " + DeclInfo.Name + ";"); } } SB.AppendLine(IdentationStr + "uint pc;"); if (BlocksB != null) { PrintProgram(Blocks, GlslDecl.BasicBlockAName); PrintProgram(BlocksB, GlslDecl.BasicBlockBName); } else { PrintProgram(Blocks, GlslDecl.BasicBlockName); } if (Decl.ShaderType != GalShaderType.Geometry) { PrintAttrToOutput(); } if (Decl.ShaderType == GalShaderType.Fragment) { if (Header.OmapDepth) { SB.AppendLine(IdentationStr + "gl_FragDepth = " + GlslDecl.GetGprName(Header.DepthRegister) + ";"); } int GprIndex = 0; for (int Attachment = 0; Attachment < 8; Attachment++) { string Output = GlslDecl.FragmentOutputName + Attachment; OmapTarget Target = Header.OmapTargets[Attachment]; for (int Component = 0; Component < 4; Component++) { if (Target.ComponentEnabled(Component)) { SB.AppendLine(IdentationStr + Output + "[" + Component + "] = " + GlslDecl.GetGprName(GprIndex) + ";"); GprIndex++; } } } } SB.AppendLine("}"); }