TextureHelper.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.BC2:
  41. case GalTextureFormat.BC3:
  42. case GalTextureFormat.BC5:
  43. case GalTextureFormat.Astc2D4x4:
  44. {
  45. int W = (Texture.Width + 3) / 4;
  46. int H = (Texture.Height + 3) / 4;
  47. return W * H * 16;
  48. }
  49. }
  50. throw new NotImplementedException(Texture.Format.ToString());
  51. }
  52. public static (AMemory Memory, long Position) GetMemoryAndPosition(
  53. IAMemory Memory,
  54. long Position)
  55. {
  56. if (Memory is NvGpuVmm Vmm)
  57. {
  58. return (Vmm.Memory, Vmm.GetPhysicalAddress(Position));
  59. }
  60. return ((AMemory)Memory, Position);
  61. }
  62. }
  63. }