SamplerPool.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace Ryujinx.Graphics.Gpu.Image
  4. {
  5. class SamplerPool : Pool<Sampler>
  6. {
  7. public SamplerPool(GpuContext context, ulong address, int maximumId) : base(context, address, maximumId) { }
  8. public override Sampler Get(int id)
  9. {
  10. if ((uint)id >= Items.Length)
  11. {
  12. return null;
  13. }
  14. SynchronizeMemory();
  15. Sampler sampler = Items[id];
  16. if (sampler == null)
  17. {
  18. ulong address = Address + (ulong)(uint)id * DescriptorSize;
  19. Span<byte> data = Context.PhysicalMemory.Read(address, DescriptorSize);
  20. SamplerDescriptor descriptor = MemoryMarshal.Cast<byte, SamplerDescriptor>(data)[0];
  21. sampler = new Sampler(Context, descriptor);
  22. Items[id] = sampler;
  23. }
  24. return sampler;
  25. }
  26. protected override void InvalidateRangeImpl(ulong address, ulong size)
  27. {
  28. ulong endAddress = address + size;
  29. for (; address < endAddress; address += DescriptorSize)
  30. {
  31. int id = (int)((address - Address) / DescriptorSize);
  32. Sampler sampler = Items[id];
  33. if (sampler != null)
  34. {
  35. sampler.Dispose();
  36. Items[id] = null;
  37. }
  38. }
  39. }
  40. protected override void Delete(Sampler item)
  41. {
  42. item?.Dispose();
  43. }
  44. }
  45. }