GpuRegionHandle.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using Ryujinx.Cpu.Tracking;
  2. using Ryujinx.Memory.Tracking;
  3. using System;
  4. namespace Ryujinx.Graphics.Gpu.Memory
  5. {
  6. /// <summary>
  7. /// A tracking handle for a region of GPU VA, represented by one or more tracking handles in CPU VA.
  8. /// </summary>
  9. class GpuRegionHandle : IRegionHandle
  10. {
  11. private readonly CpuRegionHandle[] _cpuRegionHandles;
  12. public bool Dirty
  13. {
  14. get
  15. {
  16. foreach (var regionHandle in _cpuRegionHandles)
  17. {
  18. if (regionHandle.Dirty)
  19. {
  20. return true;
  21. }
  22. }
  23. return false;
  24. }
  25. }
  26. public ulong Address => throw new NotSupportedException();
  27. public ulong Size => throw new NotSupportedException();
  28. public ulong EndAddress => throw new NotSupportedException();
  29. /// <summary>
  30. /// Create a new GpuRegionHandle, made up of mulitple CpuRegionHandles.
  31. /// </summary>
  32. /// <param name="cpuRegionHandles">The CpuRegionHandles that make up this handle</param>
  33. public GpuRegionHandle(CpuRegionHandle[] cpuRegionHandles)
  34. {
  35. _cpuRegionHandles = cpuRegionHandles;
  36. }
  37. /// <summary>
  38. /// Dispose the child handles.
  39. /// </summary>
  40. public void Dispose()
  41. {
  42. foreach (var regionHandle in _cpuRegionHandles)
  43. {
  44. regionHandle.Dispose();
  45. }
  46. }
  47. /// <summary>
  48. /// Register an action to perform when the tracked region is read or written.
  49. /// The action is automatically removed after it runs.
  50. /// </summary>
  51. /// <param name="action">Action to call on read or write</param>
  52. public void RegisterAction(RegionSignal action)
  53. {
  54. foreach (var regionHandle in _cpuRegionHandles)
  55. {
  56. regionHandle.RegisterAction(action);
  57. }
  58. }
  59. /// <summary>
  60. /// Register an action to perform when a precise access occurs (one with exact address and size).
  61. /// If the action returns true, read/write tracking are skipped.
  62. /// </summary>
  63. /// <param name="action">Action to call on read or write</param>
  64. public void RegisterPreciseAction(PreciseRegionSignal action)
  65. {
  66. foreach (var regionHandle in _cpuRegionHandles)
  67. {
  68. regionHandle.RegisterPreciseAction(action);
  69. }
  70. }
  71. /// <summary>
  72. /// Consume the dirty flag for the handles, and reprotect so it can be set on the next write.
  73. /// </summary>
  74. public void Reprotect(bool asDirty = false)
  75. {
  76. foreach (var regionHandle in _cpuRegionHandles)
  77. {
  78. regionHandle.Reprotect(asDirty);
  79. }
  80. }
  81. /// <summary>
  82. /// Force the handles to be dirty, without reprotecting.
  83. /// </summary>
  84. public void ForceDirty()
  85. {
  86. foreach (var regionHandle in _cpuRegionHandles)
  87. {
  88. regionHandle.ForceDirty();
  89. }
  90. }
  91. }
  92. }