コード例 #1
0
        static void Main(string[] args)
        {
            string source = File.ReadAllText("shader.hlsl");

            Wrapper.SourceDesc sourceDesc = new Wrapper.SourceDesc()
            {
                entryPoint = "PS",

                stage  = Wrapper.ShaderStage.PixelShader,
                source = source,
            };

            Wrapper.TargetDesc targetDesc = new Wrapper.TargetDesc()
            {
                language = Wrapper.ShadingLanguage.SpirV,
                version  = "460",
            };

            Wrapper.Compile(ref sourceDesc, ref targetDesc, out Wrapper.ResultDesc result);

            if (!result.isText)
            {
                Wrapper.DisassembleDesc disassembleDesc = new Wrapper.DisassembleDesc()
                {
                    language   = targetDesc.language,
                    binarySize = Wrapper.GetShaderConductorBlobSize(result.target),
                    binary     = Wrapper.GetShaderConductorBlobData(result.target),
                };

                Wrapper.Disassemble(ref disassembleDesc, out Wrapper.ResultDesc disassembleResult);
                Wrapper.DestroyShaderConductorBlob(result.target);
                Wrapper.DestroyShaderConductorBlob(result.errorWarningMsg);
                result = disassembleResult;
            }

            if (result.isText)
            {
                string translation = Marshal.PtrToStringAnsi(Wrapper.GetShaderConductorBlobData(result.target),
                                                             Wrapper.GetShaderConductorBlobSize(result.target));
                Console.WriteLine("*************************\n" +
                                  "**  Translation        **\n" +
                                  "*************************\n");
                Console.WriteLine(translation);
            }

            if (result.hasError)
            {
                string warning = Marshal.PtrToStringAnsi(Wrapper.GetShaderConductorBlobData(result.errorWarningMsg),
                                                         Wrapper.GetShaderConductorBlobSize(result.errorWarningMsg));
                Console.WriteLine("*************************\n" +
                                  "**  Error output       **\n" +
                                  "*************************\n");
                Console.WriteLine(warning);
            }

            Wrapper.DestroyShaderConductorBlob(result.target);
            Wrapper.DestroyShaderConductorBlob(result.errorWarningMsg);

            Console.Read();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: bamfbamf/ShaderConductor
        static void Main(string[] args)
        {
            string source = File.ReadAllText("shader.hlsl");

            Wrapper.SourceDesc sourceDesc = new Wrapper.SourceDesc()
            {
                entryPoint = "VS",
                stage      = Wrapper.ShaderStage.VertexShader,
                source     = source,
            };

            Wrapper.TargetDesc targetDesc = new Wrapper.TargetDesc()
            {
                language = Wrapper.ShadingLanguage.Glsl,
                version  = "450",
            };

            Wrapper.Compile(ref sourceDesc, ref targetDesc, out Wrapper.ResultDesc result);

            if (result.isText)
            {
                string translate = Marshal.PtrToStringAnsi(result.target);

                Console.WriteLine("*************************\n" +
                                  "**  GLSL translation   **\n" +
                                  "*************************\n");
                Console.WriteLine(translate);
            }

            if (result.hasError)
            {
                string warning = Marshal.PtrToStringAnsi(result.errorWarningMsg);
                Console.WriteLine("*************************\n" +
                                  "**  Error output       **\n" +
                                  "*************************\n");
                Console.WriteLine(warning);
            }

            Console.Read();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: snail9311/ShaderConductor
        static void Main(string[] args)
        {
            string source = File.ReadAllText("shader.hlsl");

            Wrapper.SourceDesc sourceDesc = new Wrapper.SourceDesc()
            {
                entryPoint = "PS",

                stage  = Wrapper.ShaderStage.PixelShader,
                source = source,
            };

            Wrapper.OptionsDesc optionsDesc = Wrapper.OptionsDesc.Default;
            //optionsDesc.packMatricesInRowMajor = true;
            //optionsDesc.enable16bitTypes = true;
            //optionsDesc.enableDebugInfo = true;
            //optionsDesc.disableOptimizations = true;
            //optionsDesc.optimizationLevel = 3;
            //optionsDesc.shaderModel = new Wrapper.ShaderModel(6, 2);
            //optionsDesc.shiftAllCBuffersBindings = 10;
            //optionsDesc.shiftAllTexturesBindings = 20;
            //optionsDesc.shiftAllSamplersBindings = 30;
            //optionsDesc.shiftAllUABuffersBindings = 40;

            Wrapper.TargetDesc targetDesc = new Wrapper.TargetDesc()
            {
                language = Wrapper.ShadingLanguage.Glsl,
                version  = "460",
            };

            Wrapper.Compile(ref sourceDesc, ref optionsDesc, ref targetDesc, out Wrapper.ResultDesc result);

            if (result.hasError)
            {
                string warning = Marshal.PtrToStringAnsi(Wrapper.GetShaderConductorBlobData(result.errorWarningMsg),
                                                         Wrapper.GetShaderConductorBlobSize(result.errorWarningMsg));
                Console.WriteLine("*************************\n" +
                                  "**  Error output       **\n" +
                                  "*************************\n");
                Console.WriteLine(warning);
            }
            else
            {
                if (!result.isText)
                {
                    Wrapper.DisassembleDesc disassembleDesc = new Wrapper.DisassembleDesc()
                    {
                        language   = targetDesc.language,
                        binarySize = Wrapper.GetShaderConductorBlobSize(result.target),
                        binary     = Wrapper.GetShaderConductorBlobData(result.target),
                    };

                    Wrapper.Disassemble(ref disassembleDesc, out Wrapper.ResultDesc disassembleResult);
                    Wrapper.DestroyShaderConductorBlob(result.target);
                    Wrapper.DestroyShaderConductorBlob(result.errorWarningMsg);
                    result = disassembleResult;
                }

                if (result.isText)
                {
                    string translation = Marshal.PtrToStringAnsi(Wrapper.GetShaderConductorBlobData(result.target),
                                                                 Wrapper.GetShaderConductorBlobSize(result.target));
                    Console.WriteLine("*************************\n" +
                                      "**  Translation        **\n" +
                                      "*************************\n");
                    Console.WriteLine(translation);
                }
            }

            Wrapper.DestroyShaderConductorBlob(result.target);
            Wrapper.DestroyShaderConductorBlob(result.errorWarningMsg);

            Console.Read();
        }