TileInfo.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using Ryujinx.Graphics.Nvdec.Vp9.Common;
  2. using System;
  3. using System.Diagnostics;
  4. namespace Ryujinx.Graphics.Nvdec.Vp9.Types
  5. {
  6. internal struct TileInfo
  7. {
  8. private const int MinTileWidthB64 = 4;
  9. private const int MaxTileWidthB64 = 64;
  10. public int MiRowStart, MiRowEnd;
  11. public int MiColStart, MiColEnd;
  12. public static int MiColsAlignedToSb(int nMis)
  13. {
  14. return BitUtils.AlignPowerOfTwo(nMis, Constants.MiBlockSizeLog2);
  15. }
  16. private static int GetTileOffset(int idx, int mis, int log2)
  17. {
  18. int sbCols = MiColsAlignedToSb(mis) >> Constants.MiBlockSizeLog2;
  19. int offset = ((idx * sbCols) >> log2) << Constants.MiBlockSizeLog2;
  20. return Math.Min(offset, mis);
  21. }
  22. public void SetRow(ref Vp9Common cm, int row)
  23. {
  24. MiRowStart = GetTileOffset(row, cm.MiRows, cm.Log2TileRows);
  25. MiRowEnd = GetTileOffset(row + 1, cm.MiRows, cm.Log2TileRows);
  26. }
  27. public void SetCol(ref Vp9Common cm, int col)
  28. {
  29. MiColStart = GetTileOffset(col, cm.MiCols, cm.Log2TileCols);
  30. MiColEnd = GetTileOffset(col + 1, cm.MiCols, cm.Log2TileCols);
  31. }
  32. public void Init(ref Vp9Common cm, int row, int col)
  33. {
  34. SetRow(ref cm, row);
  35. SetCol(ref cm, col);
  36. }
  37. // Checks that the given miRow, miCol and search point
  38. // are inside the borders of the tile.
  39. public bool IsInside(int miCol, int miRow, int miRows, ref Position miPos)
  40. {
  41. return !(miRow + miPos.Row < 0 ||
  42. miCol + miPos.Col < MiColStart ||
  43. miRow + miPos.Row >= miRows ||
  44. miCol + miPos.Col >= MiColEnd);
  45. }
  46. private static int GetMinLog2TileCols(int sb64Cols)
  47. {
  48. int minLog2 = 0;
  49. while ((MaxTileWidthB64 << minLog2) < sb64Cols)
  50. {
  51. ++minLog2;
  52. }
  53. return minLog2;
  54. }
  55. private static int GetMaxLog2TileCols(int sb64Cols)
  56. {
  57. int maxLog2 = 1;
  58. while ((sb64Cols >> maxLog2) >= MinTileWidthB64)
  59. {
  60. ++maxLog2;
  61. }
  62. return maxLog2 - 1;
  63. }
  64. public static void GetTileNBits(int miCols, ref int minLog2TileCols, ref int maxLog2TileCols)
  65. {
  66. int sb64Cols = MiColsAlignedToSb(miCols) >> Constants.MiBlockSizeLog2;
  67. minLog2TileCols = GetMinLog2TileCols(sb64Cols);
  68. maxLog2TileCols = GetMaxLog2TileCols(sb64Cols);
  69. Debug.Assert(minLog2TileCols <= maxLog2TileCols);
  70. }
  71. }
  72. }