TextureHelper.cs 2.8 KB

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