static void TestSharedVertexShader(ShaderType shaderType, VertexType vertexType, ShaderStage stage) { IShaderGenerator generator = GetShaderGenerator(shaderType); if (generator.IsEntryPointSupported(stage) && generator.IsVertexShaderShared(stage) && generator.IsVertexFormatSupported(vertexType)) { var bytecode = generator.GenerateSharedVertexShader(vertexType, stage).Bytecode; var disassembly = D3DCompiler.Disassemble(bytecode); WriteShaderFile($"generated_{stage.ToString().ToLower()}_{vertexType.ToString().ToLower()}.glvs", disassembly); } }
static void TestPixelShader(ShaderType shaderType, ShaderStage stage, List <int> methods) { IShaderGenerator generator = GetTemplateShaderGenerator(shaderType, methods); if (generator.IsEntryPointSupported(stage) && !generator.IsPixelShaderShared(stage)) { var bytecode = generator.GeneratePixelShader(stage).Bytecode; var parameters = generator.GetPixelShaderParameters(); var disassembly = D3DCompiler.Disassemble(bytecode); string filename = $"generated_{stage.ToString().ToLower()}_{string.Join("_", methods)}.pixl"; WriteShaderFile(filename, disassembly); } }
public bool TestAllPixelShaders(List <List <int> > shaderOverrides, List <ShaderStage> stageOverrides, List <List <int> > methodOverrides) { bool success = true; List <List <int> > shaders; if (shaderOverrides != null && shaderOverrides.Count > 0) { shaders = shaderOverrides; } else { shaders = GetAllTestPixelShaders(); } foreach (var testShader in shaders) { List <ShaderStage> stages; if (stageOverrides != null && stageOverrides.Count > 0) { stages = stageOverrides; } else { stages = GetAllShaderStages(); } foreach (var stage in stages) { if (ReferenceGenerator.IsEntryPointSupported(stage) && !ReferenceGenerator.IsPixelShaderShared(stage)) { if (methodOverrides != null && methodOverrides.Count == ReferenceGenerator.GetMethodCount()) { bool validOptions = true; for (int i = 0; i < ReferenceGenerator.GetMethodCount(); i++) { var optionOverrides = methodOverrides[i]; if (optionOverrides != null && optionOverrides.Count > 0) { validOptions &= optionOverrides.Contains(testShader[i]); } } if (!validOptions) { continue; } } string filePath = Path.Combine(Path.Combine(ReferencePath, $"{ShaderType.ToLower()}_templates"), BuildShaderName(testShader)); filePath = Path.Combine(filePath, BuildPixelShaderEntryPointName(stage)); var file = new FileInfo(filePath); if (file.Exists == false) { Console.WriteLine($"No reference shader for {BuildShaderName(testShader)} at {stage.ToString().ToLower()}"); success = false; continue; } var disassembly = GeneratePixelShader(stage, testShader); bool equal = CompareShaders(disassembly, filePath, "ps_3_0", out bool usesD3DX); success &= equal; DisplayPixelShaderTestResults(equal, BuildShaderName(testShader), stage, usesD3DX); if (Application.OutputAll && !equal) { string filename = $"generated_{stage.ToString().ToLower()}{BuildShaderName(testShader)}.pixl"; Application.WriteShaderFile(filename, disassembly); } } } } if (success) { Console.WriteLine("All unit tests passed sucessfully!"); } else { Console.WriteLine("Failed unit tests. See above for more details."); } return(success); }