Esempio n. 1
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 TestAllSharedPixelShaders(List <ShaderStage> stageOverrides)
        {
            bool success = true;

            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 (ReferenceGenerator.IsSharedPixelShaderUsingMethods(stage))
                    {
                        for (int i = 0; i < ReferenceGenerator.GetMethodCount(); i++)
                        {
                            for (int j = 0; j < ReferenceGenerator.GetMethodOptionCount(i); j++)
                            {
                                if (ReferenceGenerator.IsMethodSharedInEntryPoint(stage, i))
                                {
                                    string filePath = GetTestSharedPixelShader(stage, i, j);
                                    var    file     = new FileInfo(filePath);

                                    if (file.Exists == false)
                                    {
                                        Console.WriteLine($"No reference shader for {stage}_{i}_{j} at {stage.ToString().ToLower()}");
                                        success = false;
                                        continue;
                                    }
                                    bool equal = CompareShaders(GenerateSharedPixelShader(stage, i, j), filePath, "ps_3_0", out bool usesD3DX);
                                    success &= equal;
                                    DisplaySharedPixelShaderTestResults(equal, i, j, stage, usesD3DX);
                                }
                            }
                        }
                    }
                    else
                    {
                        string filePath = GetTestSharedPixelShader(stage, -1, -1);
                        var    file     = new FileInfo(filePath);

                        if (file.Exists == false)
                        {
                            Console.WriteLine($"No reference shader for {stage} at {stage.ToString().ToLower()}");
                            success = false;
                            continue;
                        }
                        bool equal = CompareShaders(GenerateSharedPixelShader(stage, -1, -1), filePath, "ps_3_0", out bool usesD3DX);
                        success &= equal;
                        DisplaySharedPixelShaderTestResults(equal, -1, -1, stage, usesD3DX);
                    }
                }
            }

            if (success)
            {
                Console.WriteLine("All unit tests passed sucessfully!");
            }
            else
            {
                Console.WriteLine("Failed unit tests. See above for more details.");
            }

            return(success);
        }