Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        static void TestSharedPixelShader(ShaderType shaderType, ShaderStage stage, int methodIndex, int optionIndex)
        {
            IShaderGenerator generator = GetShaderGenerator(shaderType);

            byte[] bytecode;
            string disassembly;

            if (generator.IsSharedPixelShaderUsingMethods(stage))
            {
                if (methodIndex == -1 || optionIndex == -1)
                {
                    for (int i = 0; i < generator.GetMethodCount(); i++)
                    {
                        if (generator.IsMethodSharedInEntryPoint(stage, i) && generator.IsPixelShaderShared(stage))
                        {
                            for (int j = 0; j < generator.GetMethodOptionCount(i); j++)
                            {
                                var result = generator.GenerateSharedPixelShader(stage, i, j);
                                if (result != null)
                                {
                                    bytecode    = generator.GenerateSharedPixelShader(stage, i, j).Bytecode;
                                    disassembly = D3DCompiler.Disassemble(bytecode);
                                    WriteShaderFile($"generated_{stage.ToString().ToLower()}_{i}_{j}.glps", disassembly);
                                }
                            }
                        }
                    }
                }
                else
                {
                    var result = generator.GenerateSharedPixelShader(stage, -1, -1);
                    if (result != null)
                    {
                        bytecode    = result.Bytecode;
                        disassembly = D3DCompiler.Disassemble(bytecode);
                        WriteShaderFile($"generated_{stage.ToString().ToLower()}_{methodIndex}_{optionIndex}.glps", disassembly);
                    }
                }
            }
            else
            {
                var result = generator.GenerateSharedPixelShader(stage, -1, -1);
                if (result != null)
                {
                    bytecode    = result.Bytecode;
                    disassembly = D3DCompiler.Disassemble(bytecode);
                    WriteShaderFile($"generated_{stage.ToString().ToLower()}.glps", 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);
        }