TextureHelper.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using ARMeilleure.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 (IMemoryManager 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 ((IMemoryManager)memory, position);
  44. }
  45. }
  46. }