Beispiel #1
0
        private void ApplyChangesButton_Click(object sender, EventArgs e)
        {
            // Turn the text into the expected encoding.
            IDxcBlobEncoding sourceBlob = EditorForm.CreateBlobForText(this.Library, this.CodeBox.Text);

            sourceBlob = this.Library.GetBlobAstUf8(sourceBlob);
            IDxcBlob bitcodeBlob = sourceBlob;

            List <string> passes = new List <string>();

            passes.Add("hlsl-passes-resume");
            for (int i = PassesListBox.SelectedIndex; i < PassesListBox.Items.Count; ++i)
            {
                passes.Add(((TextSection)PassesListBox.Items[i]).Title);
            }
            string[] options = EditorForm.CreatePassOptions(passes, false, true);
            EditorForm.OptimizeResult opt = EditorForm.RunOptimize(this.Library, options, bitcodeBlob);
            if (!opt.Succeeded)
            {
                MessageBox.Show("Failed to optimize: " + opt.ResultText);
                return;
            }

            OptEditorForm form = new OptEditorForm();

            form.CodeFont        = this.CodeBox.Font;
            form.Library         = this.Library;
            form.HighLevelSource = this.HighLevelSource;
            form.Sections        = TextSection.EnumerateSections(new string[] { "MODULE-PRINT", "Phase:" }, opt.ResultText).ToArray();
            form.StartPosition   = FormStartPosition.CenterParent;
            form.Show(this);
        }
Beispiel #2
0
        private void ApplyChangesButton_Click(object sender, EventArgs e)
        {
            // Turn the text into a container.
            IDxcBlobEncoding sourceBlob = EditorForm.CreateBlobForText(this.Library, this.CodeBox.Text);

            EditorForm.AssembleResult assembleResult = EditorForm.RunAssembly(this.Library, sourceBlob);
            if (assembleResult.Blob == null)
            {
                MessageBox.Show("Failed to assemble: " + assembleResult.ResultText);
                return;
            }

            // Extract the bitcode portion.
            const uint DxilKind = 0x4c495844; // 'LIXD' - DXIL
            uint       index;
            IDxcContainerReflection reflection = HlslDxcLib.CreateDxcContainerReflection();

            reflection.Load(assembleResult.Blob);
            reflection.FindFirstPartKind(DxilKind, out index);
            IDxcBlob bitcodeBlob = reflection.GetPartContent(index);

            List <string> passes = new List <string>();

            passes.Add("hlsl-passes-resume");
            for (int i = PassesListBox.SelectedIndex; i < PassesListBox.Items.Count; ++i)
            {
                passes.Add(((TextSection)PassesListBox.Items[i]).Title);
            }
            string[] options = EditorForm.CreatePassOptions(passes, false, true);
            EditorForm.OptimizeResult opt = EditorForm.RunOptimize(this.Library, options, bitcodeBlob);
            if (!opt.Succeeded)
            {
                MessageBox.Show("Failed to optimize: " + opt.ResultText);
                return;
            }

            OptEditorForm form = new OptEditorForm();

            form.CodeFont        = this.CodeBox.Font;
            form.Library         = this.Library;
            form.HighLevelSource = this.HighLevelSource;
            form.Sections        = TextSection.EnumerateSections(new string[] { "MODULE-PRINT", "Phase:" }, opt.ResultText).ToArray();
            form.StartPosition   = FormStartPosition.CenterParent;
            form.Show(this);
        }
Beispiel #3
0
        private static byte[] Compile(ShaderStage shaderStage, string source, string entryPoint, string sourceName, DxcCompilerOptions options)
        {
            //IDxcOperationResult result = DxcCompiler.Compile((DxcShaderStage)shaderStage, source, entryPoint, sourceName, options);

            string shaderProfile = GetShaderProfile(shaderStage, options.ShaderModel);

            List <string> arguments = new List <string>();

            if (options.PackMatrixInColumnMajor)
            {
                arguments.Add("-Zpc");
            }
            else if (options.PackMatrixInRowMajor)
            {
                arguments.Add("-Zpr");
            }

            IDxcLibrary        library        = Dxc.CreateDxcLibrary();
            IDxcBlobEncoding   sourceBlob     = Dxc.CreateBlobForText(library, source);
            IDxcIncludeHandler includeHandler = library.CreateIncludeHandler();

            IDxcCompiler        compiler = Dxc.CreateDxcCompiler();
            IDxcOperationResult result   = compiler.Compile(
                sourceBlob,
                sourceName,
                entryPoint,
                shaderProfile,
                arguments.ToArray(),
                arguments.Count,
                null,
                0,
                includeHandler);

            if (result.GetStatus() == 0)
            {
                IDxcBlob blob = result.GetResult();
                return(Dxc.GetBytesFromBlob(blob));
            }
            else
            {
                string resultText = Dxc.GetStringFromBlob(library, result.GetErrors());
                throw new Exception(resultText);
            }
        }