TextureHelper.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using ChocolArm64.Memory;
  2. using Ryujinx.Graphics.Gal;
  3. using System;
  4. namespace Ryujinx.Core.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.R8: return Texture.Width * Texture.Height;
  33. case GalTextureFormat.BC1:
  34. case GalTextureFormat.BC4:
  35. {
  36. int W = (Texture.Width + 3) / 4;
  37. int H = (Texture.Height + 3) / 4;
  38. return W * H * 8;
  39. }
  40. case GalTextureFormat.BC7U:
  41. case GalTextureFormat.BC2:
  42. case GalTextureFormat.BC3:
  43. case GalTextureFormat.BC5:
  44. case GalTextureFormat.Astc2D4x4:
  45. {
  46. int W = (Texture.Width + 3) / 4;
  47. int H = (Texture.Height + 3) / 4;
  48. return W * H * 16;
  49. }
  50. }
  51. throw new NotImplementedException(Texture.Format.ToString());
  52. }
  53. public static (AMemory Memory, long Position) GetMemoryAndPosition(
  54. IAMemory Memory,
  55. long Position)
  56. {
  57. if (Memory is NvGpuVmm Vmm)
  58. {
  59. return (Vmm.Memory, Vmm.GetPhysicalAddress(Position));
  60. }
  61. return ((AMemory)Memory, Position);
  62. }
  63. }
  64. }