PhysicalMemory.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. namespace Ryujinx.Graphics.Gpu.Memory
  4. {
  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. public const int PageSize = Cpu.MemoryManager.PageSize;
  12. private readonly Cpu.MemoryManager _cpuMemory;
  13. /// <summary>
  14. /// Creates a new instance of the physical memory.
  15. /// </summary>
  16. /// <param name="cpuMemory">CPU memory manager of the application process</param>
  17. public PhysicalMemory(Cpu.MemoryManager cpuMemory)
  18. {
  19. _cpuMemory = cpuMemory;
  20. }
  21. /// <summary>
  22. /// Gets a span of data from the application process.
  23. /// </summary>
  24. /// <param name="address">Start address of the range</param>
  25. /// <param name="size">Size in bytes to be range</param>
  26. /// <returns>A read only span of the data at the specified memory location</returns>
  27. public ReadOnlySpan<byte> GetSpan(ulong address, int size)
  28. {
  29. return _cpuMemory.GetSpan(address, size);
  30. }
  31. /// <summary>
  32. /// Writes data to the application process.
  33. /// </summary>
  34. /// <param name="address">Address to write into</param>
  35. /// <param name="data">Data to be written</param>
  36. public void Write(ulong address, ReadOnlySpan<byte> data)
  37. {
  38. _cpuMemory.Write(address, data);
  39. }
  40. /// <summary>
  41. /// Checks if a specified virtual memory region has been modified by the CPU since the last call.
  42. /// </summary>
  43. /// <param name="address">CPU virtual address of the region</param>
  44. /// <param name="size">Size of the region</param>
  45. /// <param name="name">Resource name</param>
  46. /// <param name="modifiedRanges">Optional array where the modified ranges should be written</param>
  47. /// <returns>The number of modified ranges</returns>
  48. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  49. public int QueryModified(ulong address, ulong size, ResourceName name, (ulong, ulong)[] modifiedRanges = null)
  50. {
  51. return _cpuMemory.QueryModified(address, size, (int)name, modifiedRanges);
  52. }
  53. }
  54. }