PhysicalMemory.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. namespace Ryujinx.Graphics.Gpu.Memory
  3. {
  4. using CpuMemoryManager = ARMeilleure.Memory.MemoryManager;
  5. /// <summary>
  6. /// Represents physical memory, accessible from the GPU.
  7. /// This is actually working CPU virtual addresses, of memory mapped on the application process.
  8. /// </summary>
  9. class PhysicalMemory
  10. {
  11. private readonly CpuMemoryManager _cpuMemory;
  12. /// <summary>
  13. /// Creates a new instance of the physical memory.
  14. /// </summary>
  15. /// <param name="cpuMemory">CPU memory manager of the application process</param>
  16. public PhysicalMemory(CpuMemoryManager cpuMemory)
  17. {
  18. _cpuMemory = cpuMemory;
  19. }
  20. /// <summary>
  21. /// Gets a span of data from the application process.
  22. /// </summary>
  23. /// <param name="address">Start address of the range</param>
  24. /// <param name="size">Size in bytes to be range</param>
  25. /// <returns>A read only span of the data at the specified memory location</returns>
  26. public ReadOnlySpan<byte> GetSpan(ulong address, ulong size)
  27. {
  28. return _cpuMemory.GetSpan(address, size);
  29. }
  30. /// <summary>
  31. /// Writes data to the application process.
  32. /// </summary>
  33. /// <param name="address">Address to write into</param>
  34. /// <param name="data">Data to be written</param>
  35. public void Write(ulong address, ReadOnlySpan<byte> data)
  36. {
  37. _cpuMemory.WriteBytes((long)address, data.ToArray());
  38. }
  39. /// <summary>
  40. /// Gets the modified ranges for a given range of the application process mapped memory.
  41. /// </summary>
  42. /// <param name="address">Start address of the range</param>
  43. /// <param name="size">Size, in bytes, of the range</param>
  44. /// <param name="name">Name of the GPU resource being checked</param>
  45. /// <returns>Ranges, composed of address and size, modified by the application process, form the CPU</returns>
  46. public (ulong, ulong)[] GetModifiedRanges(ulong address, ulong size, ResourceName name)
  47. {
  48. return _cpuMemory.GetModifiedRanges(address, size, (int)name);
  49. }
  50. }
  51. }