TextureHelper.cs 1.7 KB

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