TextureHelper.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using ChocolArm64.Memory;
  2. using Ryujinx.Graphics.Gal;
  3. using Ryujinx.Graphics.Memory;
  4. namespace Ryujinx.Graphics.Texture
  5. {
  6. static class TextureHelper
  7. {
  8. public static ISwizzle GetSwizzle(GalImage Image)
  9. {
  10. int BlockWidth = ImageUtils.GetBlockWidth (Image.Format);
  11. int BytesPerPixel = ImageUtils.GetBytesPerPixel(Image.Format);
  12. int Width = (Image.Width + (BlockWidth - 1)) / BlockWidth;
  13. if (Image.Layout == GalMemoryLayout.BlockLinear)
  14. {
  15. int AlignMask = Image.TileWidth * (64 / BytesPerPixel) - 1;
  16. Width = (Width + AlignMask) & ~AlignMask;
  17. return new BlockLinearSwizzle(Width, BytesPerPixel, Image.GobBlockHeight);
  18. }
  19. else
  20. {
  21. return new LinearSwizzle(Image.Pitch, BytesPerPixel);
  22. }
  23. }
  24. public static (MemoryManager Memory, long Position) GetMemoryAndPosition(
  25. IMemory Memory,
  26. long Position)
  27. {
  28. if (Memory is NvGpuVmm Vmm)
  29. {
  30. return (Vmm.Memory, Vmm.GetPhysicalAddress(Position));
  31. }
  32. return ((MemoryManager)Memory, Position);
  33. }
  34. }
  35. }