TextureHelper.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using ChocolArm64.Memory;
  2. using Ryujinx.Graphics.Gal;
  3. using Ryujinx.Graphics.Memory;
  4. using System;
  5. namespace Ryujinx.Graphics.Texture
  6. {
  7. static class TextureHelper
  8. {
  9. public static ISwizzle GetSwizzle(TextureInfo Texture, int BlockWidth, int Bpp)
  10. {
  11. int Width = (Texture.Width + (BlockWidth - 1)) / BlockWidth;
  12. int AlignMask = Texture.TileWidth * (64 / Bpp) - 1;
  13. Width = (Width + AlignMask) & ~AlignMask;
  14. switch (Texture.Swizzle)
  15. {
  16. case TextureSwizzle._1dBuffer:
  17. case TextureSwizzle.Pitch:
  18. case TextureSwizzle.PitchColorKey:
  19. return new LinearSwizzle(Texture.Pitch, Bpp);
  20. case TextureSwizzle.BlockLinear:
  21. case TextureSwizzle.BlockLinearColorKey:
  22. return new BlockLinearSwizzle(Width, Bpp, Texture.BlockHeight);
  23. }
  24. throw new NotImplementedException(Texture.Swizzle.ToString());
  25. }
  26. public static (AMemory Memory, long Position) GetMemoryAndPosition(
  27. IAMemory Memory,
  28. long Position)
  29. {
  30. if (Memory is NvGpuVmm Vmm)
  31. {
  32. return (Vmm.Memory, Vmm.GetPhysicalAddress(Position));
  33. }
  34. return ((AMemory)Memory, Position);
  35. }
  36. }
  37. }