BlockLinearSwizzle.cs 1.3 KB

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