Exemple #1
0
        private void RenderButtonBars(float width, BurstCompileTarget target, out bool doRefresh, out bool doCopy, out int fontIndex)
        {
            float remainingWidth = width;

            var contentDisasm         = new GUIContent("Enhanced Disassembly");
            var contentSafety         = new GUIContent("Safety Checks");
            var contentOptimizations  = new GUIContent("Optimizations");
            var contentFastMath       = new GUIContent("Fast Math");
            var contentCodeGenOptions = new GUIContent("Auto");
            var contentLabelFontSize  = new GUIContent("Font Size");
            var contentFontSize       = new GUIContent("99");
            var contentRefresh        = new GUIContent("Refresh Disassembly");
            var contentCopyToClip     = new GUIContent("Copy to Clipboard");

            GUILayout.BeginHorizontal();

            _enhancedDisassembly = GUILayout.Toggle(_enhancedDisassembly, contentDisasm, EditorStyles.toggle);
            FlowToNewLine(ref remainingWidth, width, EditorStyles.toggle, contentDisasm);
            _safetyChecks = GUILayout.Toggle(_safetyChecks, contentSafety, EditorStyles.toggle);
            FlowToNewLine(ref remainingWidth, width, EditorStyles.toggle, contentSafety);
            _optimizations = GUILayout.Toggle(_optimizations, contentOptimizations, EditorStyles.toggle);
            FlowToNewLine(ref remainingWidth, width, EditorStyles.toggle, contentOptimizations);
            _fastMath = GUILayout.Toggle(_fastMath, contentFastMath, EditorStyles.toggle);
            FlowToNewLine(ref remainingWidth, width, EditorStyles.toggle, contentFastMath);

            EditorGUI.BeginDisabledGroup(!target.IsSupported);
            _codeGenOptions = EditorGUILayout.Popup(_codeGenOptions, CodeGenOptions, EditorStyles.popup);
            FlowToNewLine(ref remainingWidth, width, EditorStyles.popup, contentCodeGenOptions);

            GUILayout.Label("Font Size", EditorStyles.label);
            fontIndex = EditorGUILayout.Popup(_fontSizeIndex, _fontSizesText, EditorStyles.popup);
            FlowToNewLine(ref remainingWidth, width, EditorStyles.label, contentLabelFontSize);
            FlowToNewLine(ref remainingWidth, width, EditorStyles.popup, contentFontSize);

            doRefresh = GUILayout.Button(contentRefresh, EditorStyles.miniButton);
            FlowToNewLine(ref remainingWidth, width, EditorStyles.miniButton, contentRefresh);

            doCopy = GUILayout.Button(contentCopyToClip, EditorStyles.miniButton);
            FlowToNewLine(ref remainingWidth, width, EditorStyles.miniButton, contentCopyToClip);
            EditorGUI.EndDisabledGroup();

            GUILayout.EndHorizontal();

            _disasmKind = (DisassemblyKind)GUILayout.Toolbar((int)_disasmKind, DisassemblyKindNames, GUILayout.Width(width));
        }
        private static BurstDisassembler.AsmKind FetchAsmKind(TargetCpu cpu, DisassemblyKind kind)
        {
            if (kind == DisassemblyKind.Asm)
            {
                switch (cpu)
                {
                case TargetCpu.ARMV7A_NEON32:
                case TargetCpu.ARMV8A_AARCH64:
                case TargetCpu.ARMV8A_AARCH64_HALFFP:
                case TargetCpu.THUMB2_NEON32:
                    return(BurstDisassembler.AsmKind.ARM);

                case TargetCpu.WASM32:
                    return(BurstDisassembler.AsmKind.Wasm);
                }
                return(BurstDisassembler.AsmKind.Intel);
            }
            else
            {
                return(BurstDisassembler.AsmKind.LLVMIR);
            }
        }
        private void RenderButtonBars(float width, BurstCompileTarget target, out bool doCopy, out int fontIndex)
        {
            float remainingWidth = width;

            var contentDisasm         = new GUIContent("Enhanced Disassembly");
            var contentSafety         = new GUIContent("Safety Checks");
            var contentCodeGenOptions = new GUIContent("Auto");
            var contentLabelFontSize  = new GUIContent("Font Size");
            var contentFontSize       = new GUIContent("99");
            var contentCopyToClip     = new GUIContent("Copy to Clipboard");

            GUILayout.BeginHorizontal();

            _assemblyKind = EditorGUILayout.Popup(_assemblyKind, AssemblyOptions, EditorStyles.popup);
            FlowToNewLine(ref remainingWidth, width, EditorStyles.popup, contentDisasm);

            _safetyChecks = GUILayout.Toggle(_safetyChecks, contentSafety, EditorStyles.toggle);
            FlowToNewLine(ref remainingWidth, width, EditorStyles.toggle, contentSafety);

            EditorGUI.BeginDisabledGroup(!target.HasRequiredBurstCompileAttributes);

            _targetCpu = (TargetCpu)EditorGUILayout.Popup((int)_targetCpu, TargetCpuNames, EditorStyles.popup);
            FlowToNewLine(ref remainingWidth, width, EditorStyles.popup, contentCodeGenOptions);

            GUILayout.Label("Font Size", EditorStyles.label);
            fontIndex = EditorGUILayout.Popup(_fontSizeIndex, _fontSizesText, EditorStyles.popup);
            FlowToNewLine(ref remainingWidth, width, EditorStyles.label, contentLabelFontSize);
            FlowToNewLine(ref remainingWidth, width, EditorStyles.popup, contentFontSize);

            doCopy = GUILayout.Button(contentCopyToClip, EditorStyles.miniButton);
            FlowToNewLine(ref remainingWidth, width, EditorStyles.miniButton, contentCopyToClip);
            EditorGUI.EndDisabledGroup();

            GUILayout.EndHorizontal();

            _disasmKind = (DisassemblyKind)GUILayout.Toolbar((int)_disasmKind, DisassemblyKindNames, GUILayout.ExpandWidth(true), GUILayout.MinWidth(5 * 10));
        }
        public void OnGUI()
        {
            if (_targets == null)
            {
                _targets          = BurstReflection.FindExecuteMethods(AssembliesType.Editor);
                _treeView.Targets = _targets;
                _treeView.Reload();

                if (_selectedItem != null)
                {
                    _treeView.TrySelectByDisplayName(_selectedItem);
                }
            }

            if (_fontSizesText == null)
            {
                _fontSizesText = new string[FontSizes.Length];
                for (var i = 0; i < FontSizes.Length; ++i)
                {
                    _fontSizesText[i] = FontSizes[i].ToString();
                }
            }

            if (_fontSizeIndex == -1)
            {
                _fontSizeIndex = EditorPrefs.GetInt(FontSizeIndexPref, 5);
                _fontSizeIndex = Math.Max(0, _fontSizeIndex);
                _fontSizeIndex = Math.Min(_fontSizeIndex, FontSizes.Length - 1);
            }

            if (_fixedFontStyle == null)
            {
                _fixedFontStyle = new GUIStyle(GUI.skin.label);
                string fontName;
                if (Application.platform == RuntimePlatform.WindowsEditor)
                {
                    fontName = "Consolas";
                }
                else
                {
                    fontName = "Courier";
                }
                _fixedFontStyle.font = Font.CreateDynamicFontFromOSFont(fontName, FontSize);
            }

            if (_searchField == null)
            {
                _searchField = new SearchField();
            }

            if (_textArea == null)
            {
                _textArea = new LongTextArea();
            }

            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical(GUILayout.Width(position.width / 3));

            GUILayout.Label("Compile Targets", EditorStyles.boldLabel);

            var newFilter = _searchField.OnGUI(_treeView.Filter);

            if (newFilter != _treeView.Filter)
            {
                _treeView.Filter = newFilter;
                _treeView.Reload();
            }

            _treeView.OnGUI(GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.ExpandHeight(true),
                                                     GUILayout.ExpandWidth(true)));

            GUILayout.EndVertical();

            GUILayout.BeginVertical();

            var selection = _treeView.GetSelection();

            if (selection.Count == 1)
            {
                var id     = selection[0];
                var target = _targets[id - 1];
                // Stash selected item name to handle domain reloads more gracefully
                _selectedItem = target.GetDisplayName();

                GUILayout.BeginHorizontal();

                _enhancedDisassembly = GUILayout.Toggle(_enhancedDisassembly, "Enhanced Disassembly");
                _safetyChecks        = GUILayout.Toggle(_safetyChecks, "Safety Checks");
                _optimizations       = GUILayout.Toggle(_optimizations, "Optimizations");
                _fastMath            = GUILayout.Toggle(_fastMath, "Fast Math");
                EditorGUI.BeginDisabledGroup(!target.SupportsBurst);
                _codeGenOptions = EditorGUILayout.Popup(_codeGenOptions, CodeGenOptions);

                GUILayout.Label("Font Size");
                var fsi = EditorGUILayout.Popup(_fontSizeIndex, _fontSizesText);

                var doRefresh = GUILayout.Button("Refresh Disassembly");
                var doCopy    = GUILayout.Button("Copy to Clipboard");
                EditorGUI.EndDisabledGroup();

                GUILayout.EndHorizontal();

                _disasmKind = (DisassemblyKind)GUILayout.Toolbar((int)_disasmKind, DisassemblyKindNames);

                var disasm = target.Disassembly != null ? target.Disassembly[(int)_disasmKind] : null;

                if (doRefresh)
                {
                    // TODO: refactor this code with a proper AppendOption to avoid these "\n"
                    var options = new StringBuilder();
                    if (!_safetyChecks)
                    {
                        options.Append("\n" + GetOption(OptionDisableSafetyChecks) + "\n" + GetOption(OptionNoAlias));
                    }

                    if (_enhancedDisassembly)
                    {
                        options.Append("\n" + GetOption(OptionDebug));
                    }

                    if (!_optimizations)
                    {
                        options.Append("\n" + GetOption(OptionDisableOpt));
                    }

                    if (_fastMath)
                    {
                        options.Append("\n" + GetOption(OptionFastMath));
                    }

                    options.AppendFormat("\n" + GetOption(OptionTarget, CodeGenOptions[_codeGenOptions]));

                    var baseOptions = options.ToString().Trim('\n', ' ');

                    target.Disassembly = new string[DisasmOptions.Length];

                    for (var i = 0; i < DisasmOptions.Length; ++i)
                    {
                        target.Disassembly[i] = GetDisassembly(target.Method, baseOptions + DisasmOptions[i]);
                    }

                    if (_enhancedDisassembly && (int)DisassemblyKind.Asm < target.Disassembly.Length)
                    {
                        var processor = new BurstDisassembler();
                        target.Disassembly[(int)DisassemblyKind.Asm] = processor.Process(target.Disassembly[(int)DisassemblyKind.Asm]);
                    }

                    disasm = target.Disassembly[(int)_disasmKind];
                }

                if (disasm != null)
                {
                    _textArea.Text = disasm;
                    _scrollPos     = GUILayout.BeginScrollView(_scrollPos);
                    _textArea.Render(_fixedFontStyle);
                    GUILayout.EndScrollView();
                }

                if (doCopy)
                {
                    EditorGUIUtility.systemCopyBuffer = disasm == null ? "" : disasm;
                }

                if (fsi != _fontSizeIndex)
                {
                    _fontSizeIndex = fsi;
                    EditorPrefs.SetInt(FontSizeIndexPref, fsi);
                    _fixedFontStyle = null;
                }
            }

            GUILayout.EndVertical();

            GUILayout.EndHorizontal();
        }