TextureHelper.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using ChocolArm64.Memory;
  2. using Ryujinx.Graphics.Gal;
  3. using System;
  4. namespace Ryujinx.HLE.Gpu
  5. {
  6. static class TextureHelper
  7. {
  8. public static ISwizzle GetSwizzle(Texture Texture, int Width, int Bpp)
  9. {
  10. switch (Texture.Swizzle)
  11. {
  12. case TextureSwizzle._1dBuffer:
  13. case TextureSwizzle.Pitch:
  14. case TextureSwizzle.PitchColorKey:
  15. return new LinearSwizzle(Texture.Pitch, Bpp);
  16. case TextureSwizzle.BlockLinear:
  17. case TextureSwizzle.BlockLinearColorKey:
  18. return new BlockLinearSwizzle(Width, Bpp, Texture.BlockHeight);
  19. }
  20. throw new NotImplementedException(Texture.Swizzle.ToString());
  21. }
  22. public static int GetTextureSize(GalTexture Texture)
  23. {
  24. switch (Texture.Format)
  25. {
  26. case GalTextureFormat.R32G32B32A32: return Texture.Width * Texture.Height * 16;
  27. case GalTextureFormat.R16G16B16A16: return Texture.Width * Texture.Height * 8;
  28. case GalTextureFormat.A8B8G8R8: return Texture.Width * Texture.Height * 4;
  29. case GalTextureFormat.R32: return Texture.Width * Texture.Height * 4;
  30. case GalTextureFormat.A1B5G5R5: return Texture.Width * Texture.Height * 2;
  31. case GalTextureFormat.B5G6R5: return Texture.Width * Texture.Height * 2;
  32. case GalTextureFormat.G8R8: return Texture.Width * Texture.Height * 2;
  33. case GalTextureFormat.R16: return Texture.Width * Texture.Height * 2;
  34. case GalTextureFormat.R8: return Texture.Width * Texture.Height;
  35. case GalTextureFormat.BC1:
  36. case GalTextureFormat.BC4:
  37. {
  38. int W = (Texture.Width + 3) / 4;
  39. int H = (Texture.Height + 3) / 4;
  40. return W * H * 8;
  41. }
  42. case GalTextureFormat.BC7U:
  43. case GalTextureFormat.BC2:
  44. case GalTextureFormat.BC3:
  45. case GalTextureFormat.BC5:
  46. case GalTextureFormat.Astc2D4x4:
  47. {
  48. int W = (Texture.Width + 3) / 4;
  49. int H = (Texture.Height + 3) / 4;
  50. return W * H * 16;
  51. }
  52. }
  53. throw new NotImplementedException(Texture.Format.ToString());
  54. }
  55. public static (AMemory Memory, long Position) GetMemoryAndPosition(
  56. IAMemory Memory,
  57. long Position)
  58. {
  59. if (Memory is NvGpuVmm Vmm)
  60. {
  61. return (Vmm.Memory, Vmm.GetPhysicalAddress(Position));
  62. }
  63. return ((AMemory)Memory, Position);
  64. }
  65. }
  66. }