TextureHelper.cs 2.8 KB

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