Ingen beskrivning
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BurstInspectorTestUtil.cs 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using NUnit.Framework;
  5. using Unity.Burst;
  6. using Unity.Burst.Editor;
  7. using UnityEngine;
  8. internal static class BurstInspectorTestUtil
  9. {
  10. internal static BurstDisassembler GetDisassemblerAndText(
  11. string compileTargetName,
  12. int debugLvl,
  13. BurstTargetCpu targetCpu,
  14. out string textToRender)
  15. {
  16. // Get target job assembly:
  17. var assemblies = BurstReflection.EditorAssembliesThatCanPossiblyContainJobs;
  18. var result = BurstReflection.FindExecuteMethods(assemblies, BurstReflectionAssemblyOptions.None);
  19. var compileTarget = result.CompileTargets.Find(x => x.GetDisplayName() == compileTargetName);
  20. Assert.IsTrue(compileTarget != default, $"Could not find compile target: {compileTarget}");
  21. BurstDisassembler disassembler = new BurstDisassembler();
  22. var options = new StringBuilder();
  23. compileTarget.Options.TryGetOptions(compileTarget.JobType, out string defaultOptions);
  24. options.AppendLine(defaultOptions);
  25. // Disables the 2 current warnings generated from code (since they clutter up the inspector display)
  26. // BC1370 - throw inside code not guarded with ConditionalSafetyCheck attribute
  27. // BC1322 - loop intrinsic on loop that has been optimised away
  28. options.AppendLine($"{BurstCompilerOptions.GetOption(BurstCompilerOptions.OptionDisableWarnings, "BC1370;BC1322")}");
  29. options.AppendLine($"{BurstCompilerOptions.GetOption(BurstCompilerOptions.OptionTarget, targetCpu)}");
  30. options.AppendLine($"{BurstCompilerOptions.GetOption(BurstCompilerOptions.OptionDebug, $"{debugLvl}")}");
  31. var baseOptions = options.ToString();
  32. var append = BurstInspectorGUI.GetDisasmOptions()[(int)DisassemblyKind.Asm];
  33. // Setup disAssembler with the job:
  34. compileTarget.RawDisassembly = BurstInspectorGUI.GetDisassembly(compileTarget.Method, baseOptions + append);
  35. textToRender = compileTarget.RawDisassembly.TrimStart('\n');
  36. return disassembler;
  37. }
  38. }