//this is a bit of a hack. //it relies on the fact that the DirectX shader compiler //marks up the disasembled shader with comments detailing the shader inputs. public static AsmTechnique[] ExtractTechniques(SourceShader shader, Platform platform) { //decompile the shader DecompiledEffect fx = new DecompiledEffect(shader, platform); //break it up into techniques Tokenizer assemblyTokens = new Tokenizer(fx.DecompiledAsm, false, true, true); List <AsmTechnique> techniqes = new List <AsmTechnique>(); while (assemblyTokens.NextToken()) { if (assemblyTokens.Token.Equals("technique", StringComparison.InvariantCultureIgnoreCase)) { //should be format: //technique NAME //{ //} assemblyTokens.NextToken(); string name = assemblyTokens.Token; assemblyTokens.NextToken(); //may be a line break if (assemblyTokens.Token.Trim().Length == 0) { assemblyTokens.NextToken(); } //should be a { if (assemblyTokens.Token != "{") { throw new CompileException("Unexpected token in assembly technique declaration, expected '{': " + assemblyTokens.Token); } // read the entire technique {} block if (!assemblyTokens.ReadBlock()) { throw new CompileException("Unexpected end of string in assembly technique pass declaration"); } AsmTechnique asm = new AsmTechnique(name, assemblyTokens.Token, fx.GetTechniqueDefaultValues(name)); if (!shader.SkipConstantValidation) { //do some extra validation to make sure pixel inputs match vertex outputs asm.ValidatePixleShaderInput(shader, platform); } techniqes.Add(asm); } } for (int i = 0; i < techniqes.Count; i++) { techniqes[i].MergeSemantics(fx.EffectRegisters); } return(techniqes.ToArray()); }
//this is a bit of a hack. //it relies on the fact that the DirectX shader compiler //marks up the disasembled shader with comments detailing the shader inputs. public static AsmTechnique[] ExtractTechniques(SourceShader shader, Platform platform, out DecompiledEffect fx, string generatedPrefix) { //decompile the shader fx = new DecompiledEffect(shader, platform); //break it up into techniques Tokenizer assemblyTokens = new Tokenizer(fx.DecompiledAsm, false, true, true); List<AsmTechnique> techniqes = new List<AsmTechnique>(); while (assemblyTokens.NextToken()) { if (assemblyTokens.Token.Equals("technique", StringComparison.InvariantCultureIgnoreCase)) { //should be format: //technique NAME //{ //} assemblyTokens.NextToken(); string name = assemblyTokens.Token; if (generatedPrefix != null) { //only include generated techniques if (name.EndsWith(generatedPrefix)) name = name.Substring(0, name.Length - generatedPrefix.Length); else continue; } assemblyTokens.NextToken(); //may be a line break if (assemblyTokens.Token.Trim().Length == 0) assemblyTokens.NextToken(); //should be a { if (assemblyTokens.Token != "{") throw new CompileException("Unexpected token in assembly technique declaration, expected '{': " + assemblyTokens.Token); // read the entire technique {} block if (!assemblyTokens.ReadBlock()) throw new CompileException("Unexpected end of string in assembly technique pass declaration"); AsmTechnique asm = new AsmTechnique(name, assemblyTokens.Token, fx.GetTechniqueDefaultValues(name)); if (!shader.SkipConstantValidation) { //do some extra validation to make sure pixel inputs match vertex outputs asm.ValidatePixleShaderInput(shader, platform); } techniqes.Add(asm); } } for (int i = 0; i < techniqes.Count; i++) { techniqes[i].MergeSemantics(fx.EffectRegisters); } return techniqes.ToArray(); }