BlockLinearSwizzle.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. namespace Ryujinx.Graphics.Texture
  3. {
  4. class BlockLinearSwizzle : ISwizzle
  5. {
  6. private int BhShift;
  7. private int BppShift;
  8. private int BhMask;
  9. private int XShift;
  10. private int GobStride;
  11. public BlockLinearSwizzle(int Width, int Bpp, int BlockHeight = 16)
  12. {
  13. BhMask = (BlockHeight * 8) - 1;
  14. BhShift = CountLsbZeros(BlockHeight * 8);
  15. BppShift = CountLsbZeros(Bpp);
  16. int WidthInGobs = (int)MathF.Ceiling(Width * Bpp / 64f);
  17. GobStride = 512 * BlockHeight * WidthInGobs;
  18. XShift = CountLsbZeros(512 * BlockHeight);
  19. }
  20. private int CountLsbZeros(int Value)
  21. {
  22. int Count = 0;
  23. while (((Value >> Count) & 1) == 0)
  24. {
  25. Count++;
  26. }
  27. return Count;
  28. }
  29. public int GetSwizzleOffset(int X, int Y)
  30. {
  31. X <<= BppShift;
  32. int Position = (Y >> BhShift) * GobStride;
  33. Position += (X >> 6) << XShift;
  34. Position += ((Y & BhMask) >> 3) << 9;
  35. Position += ((X & 0x3f) >> 5) << 8;
  36. Position += ((Y & 0x07) >> 1) << 6;
  37. Position += ((X & 0x1f) >> 4) << 5;
  38. Position += ((Y & 0x01) >> 0) << 4;
  39. Position += ((X & 0x0f) >> 0) << 0;
  40. return Position;
  41. }
  42. }
  43. }