TextureHelper.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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:
  28. return Texture.Width * Texture.Height * 16;
  29. case GalTextureFormat.R16G16B16A16:
  30. return Texture.Width * Texture.Height * 8;
  31. case GalTextureFormat.A8B8G8R8:
  32. case GalTextureFormat.R32:
  33. case GalTextureFormat.ZF32:
  34. return Texture.Width * Texture.Height * 4;
  35. case GalTextureFormat.A1B5G5R5:
  36. case GalTextureFormat.B5G6R5:
  37. case GalTextureFormat.G8R8:
  38. case GalTextureFormat.R16:
  39. return Texture.Width * Texture.Height * 2;
  40. case GalTextureFormat.R8:
  41. return Texture.Width * Texture.Height;
  42. case GalTextureFormat.BC1:
  43. case GalTextureFormat.BC4:
  44. {
  45. int W = (Texture.Width + 3) / 4;
  46. int H = (Texture.Height + 3) / 4;
  47. return W * H * 8;
  48. }
  49. case GalTextureFormat.BC7U:
  50. case GalTextureFormat.BC2:
  51. case GalTextureFormat.BC3:
  52. case GalTextureFormat.BC5:
  53. case GalTextureFormat.Astc2D4x4:
  54. {
  55. int W = (Texture.Width + 3) / 4;
  56. int H = (Texture.Height + 3) / 4;
  57. return W * H * 16;
  58. }
  59. }
  60. throw new NotImplementedException(Texture.Format.ToString());
  61. }
  62. public static (AMemory Memory, long Position) GetMemoryAndPosition(
  63. IAMemory Memory,
  64. long Position)
  65. {
  66. if (Memory is NvGpuVmm Vmm)
  67. {
  68. return (Vmm.Memory, Vmm.GetPhysicalAddress(Position));
  69. }
  70. return ((AMemory)Memory, Position);
  71. }
  72. }
  73. }