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