RtFormat.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using Ryujinx.Graphics.GAL;
  2. using Ryujinx.Graphics.Gpu.Image;
  3. namespace Ryujinx.Graphics.Gpu.State
  4. {
  5. /// <summary>
  6. /// Render target buffer texture format.
  7. /// </summary>
  8. enum RtFormat
  9. {
  10. D32Float = 0xa,
  11. D16Unorm = 0x13,
  12. D24UnormS8Uint = 0x14,
  13. D24Unorm = 0x15,
  14. S8UintD24Unorm = 0x16,
  15. S8Uint = 0x17,
  16. D32FloatS8Uint = 0x19,
  17. R32G32B32A32Float = 0xc0,
  18. R32G32B32A32Sint = 0xc1,
  19. R32G32B32A32Uint = 0xc2,
  20. R32G32B32X32Float = 0xc3,
  21. R32G32B32X32Sint = 0xc4,
  22. R32G32B32X32Uint = 0xc5,
  23. R16G16B16X16Unorm = 0xc6,
  24. R16G16B16X16Snorm = 0xc7,
  25. R16G16B16X16Sint = 0xc8,
  26. R16G16B16X16Uint = 0xc9,
  27. R16G16B16A16Float = 0xca,
  28. R32G32Float = 0xcb,
  29. R32G32Sint = 0xcc,
  30. R32G32Uint = 0xcd,
  31. R16G16B16X16Float = 0xce,
  32. B8G8R8A8Unorm = 0xcf,
  33. B8G8R8A8Srgb = 0xd0,
  34. R10G10B10A2Unorm = 0xd1,
  35. R10G10B10A2Uint = 0xd2,
  36. R8G8B8A8Unorm = 0xd5,
  37. R8G8B8A8Srgb = 0xd6,
  38. R8G8B8X8Snorm = 0xd7,
  39. R8G8B8X8Sint = 0xd8,
  40. R8G8B8X8Uint = 0xd9,
  41. R16G16Unorm = 0xda,
  42. R16G16Snorm = 0xdb,
  43. R16G16Sint = 0xdc,
  44. R16G16Uint = 0xdd,
  45. R16G16Float = 0xde,
  46. R11G11B10Float = 0xe0,
  47. R32Sint = 0xe3,
  48. R32Uint = 0xe4,
  49. R32Float = 0xe5,
  50. B8G8R8X8Unorm = 0xe6,
  51. B8G8R8X8Srgb = 0xe7,
  52. B5G6R5Unorm = 0xe8,
  53. B5G5R5A1Unorm = 0xe9,
  54. R8G8Unorm = 0xea,
  55. R8G8Snorm = 0xeb,
  56. R8G8Sint = 0xec,
  57. R8G8Uint = 0xed,
  58. R16Unorm = 0xee,
  59. R16Snorm = 0xef,
  60. R16Sint = 0xf0,
  61. R16Uint = 0xf1,
  62. R16Float = 0xf2,
  63. R8Unorm = 0xf3,
  64. R8Snorm = 0xf4,
  65. R8Sint = 0xf5,
  66. R8Uint = 0xf6,
  67. B5G5R5X1Unorm = 0xf8,
  68. R8G8B8X8Unorm = 0xf9,
  69. R8G8B8X8Srgb = 0xfa
  70. }
  71. static class RtFormatConverter
  72. {
  73. /// <summary>
  74. /// Converts the render target buffer texture format to a host compatible format.
  75. /// </summary>
  76. /// <param name="format">Render target format</param>
  77. /// <returns>Host compatible format enum value</returns>
  78. public static FormatInfo Convert(this RtFormat format)
  79. {
  80. return format switch
  81. {
  82. RtFormat.D32Float => new FormatInfo(Format.D32Float, 1, 1, 4),
  83. RtFormat.D16Unorm => new FormatInfo(Format.D16Unorm, 1, 1, 2),
  84. RtFormat.D24UnormS8Uint => new FormatInfo(Format.D24UnormS8Uint, 1, 1, 4),
  85. RtFormat.D24Unorm => new FormatInfo(Format.D24UnormS8Uint, 1, 1, 4),
  86. RtFormat.S8UintD24Unorm => new FormatInfo(Format.D24UnormS8Uint, 1, 1, 4),
  87. RtFormat.S8Uint => new FormatInfo(Format.S8Uint, 1, 1, 1),
  88. RtFormat.D32FloatS8Uint => new FormatInfo(Format.D32FloatS8Uint, 1, 1, 8),
  89. RtFormat.R32G32B32A32Float => new FormatInfo(Format.R32G32B32A32Float, 1, 1, 16),
  90. RtFormat.R32G32B32A32Sint => new FormatInfo(Format.R32G32B32A32Sint, 1, 1, 16),
  91. RtFormat.R32G32B32A32Uint => new FormatInfo(Format.R32G32B32A32Uint, 1, 1, 16),
  92. RtFormat.R32G32B32X32Float => new FormatInfo(Format.R32G32B32A32Float, 1, 1, 16),
  93. RtFormat.R32G32B32X32Sint => new FormatInfo(Format.R32G32B32A32Sint, 1, 1, 16),
  94. RtFormat.R32G32B32X32Uint => new FormatInfo(Format.R32G32B32A32Uint, 1, 1, 16),
  95. RtFormat.R16G16B16X16Unorm => new FormatInfo(Format.R16G16B16A16Unorm, 1, 1, 8),
  96. RtFormat.R16G16B16X16Snorm => new FormatInfo(Format.R16G16B16A16Snorm, 1, 1, 8),
  97. RtFormat.R16G16B16X16Sint => new FormatInfo(Format.R16G16B16A16Sint, 1, 1, 8),
  98. RtFormat.R16G16B16X16Uint => new FormatInfo(Format.R16G16B16A16Uint, 1, 1, 8),
  99. RtFormat.R16G16B16A16Float => new FormatInfo(Format.R16G16B16A16Float, 1, 1, 8),
  100. RtFormat.R32G32Float => new FormatInfo(Format.R32G32Float, 1, 1, 8),
  101. RtFormat.R32G32Sint => new FormatInfo(Format.R32G32Sint, 1, 1, 8),
  102. RtFormat.R32G32Uint => new FormatInfo(Format.R32G32Uint, 1, 1, 8),
  103. RtFormat.R16G16B16X16Float => new FormatInfo(Format.R16G16B16A16Float, 1, 1, 8),
  104. RtFormat.B8G8R8A8Unorm => new FormatInfo(Format.B8G8R8A8Unorm, 1, 1, 4),
  105. RtFormat.B8G8R8A8Srgb => new FormatInfo(Format.B8G8R8A8Srgb, 1, 1, 4),
  106. RtFormat.R10G10B10A2Unorm => new FormatInfo(Format.R10G10B10A2Unorm, 1, 1, 4),
  107. RtFormat.R10G10B10A2Uint => new FormatInfo(Format.R10G10B10A2Uint, 1, 1, 4),
  108. RtFormat.R8G8B8A8Unorm => new FormatInfo(Format.R8G8B8A8Unorm, 1, 1, 4),
  109. RtFormat.R8G8B8A8Srgb => new FormatInfo(Format.R8G8B8A8Srgb, 1, 1, 4),
  110. RtFormat.R8G8B8X8Snorm => new FormatInfo(Format.R8G8B8A8Snorm, 1, 1, 4),
  111. RtFormat.R8G8B8X8Sint => new FormatInfo(Format.R8G8B8A8Sint, 1, 1, 4),
  112. RtFormat.R8G8B8X8Uint => new FormatInfo(Format.R8G8B8A8Uint, 1, 1, 4),
  113. RtFormat.R16G16Unorm => new FormatInfo(Format.R16G16Unorm, 1, 1, 4),
  114. RtFormat.R16G16Snorm => new FormatInfo(Format.R16G16Snorm, 1, 1, 4),
  115. RtFormat.R16G16Sint => new FormatInfo(Format.R16G16Sint, 1, 1, 4),
  116. RtFormat.R16G16Uint => new FormatInfo(Format.R16G16Uint, 1, 1, 4),
  117. RtFormat.R16G16Float => new FormatInfo(Format.R16G16Float, 1, 1, 4),
  118. RtFormat.R11G11B10Float => new FormatInfo(Format.R11G11B10Float, 1, 1, 4),
  119. RtFormat.R32Sint => new FormatInfo(Format.R32Sint, 1, 1, 4),
  120. RtFormat.R32Uint => new FormatInfo(Format.R32Uint, 1, 1, 4),
  121. RtFormat.R32Float => new FormatInfo(Format.R32Float, 1, 1, 4),
  122. RtFormat.B8G8R8X8Unorm => new FormatInfo(Format.B8G8R8A8Unorm, 1, 1, 4),
  123. RtFormat.B8G8R8X8Srgb => new FormatInfo(Format.B8G8R8A8Srgb, 1, 1, 4),
  124. RtFormat.B5G6R5Unorm => new FormatInfo(Format.B5G6R5Unorm, 1, 1, 2),
  125. RtFormat.B5G5R5A1Unorm => new FormatInfo(Format.B5G5R5A1Unorm, 1, 1, 2),
  126. RtFormat.R8G8Unorm => new FormatInfo(Format.R8G8Unorm, 1, 1, 2),
  127. RtFormat.R8G8Snorm => new FormatInfo(Format.R8G8Snorm, 1, 1, 2),
  128. RtFormat.R8G8Sint => new FormatInfo(Format.R8G8Sint, 1, 1, 2),
  129. RtFormat.R8G8Uint => new FormatInfo(Format.R8G8Uint, 1, 1, 2),
  130. RtFormat.R16Unorm => new FormatInfo(Format.R16Unorm, 1, 1, 2),
  131. RtFormat.R16Snorm => new FormatInfo(Format.R16Snorm, 1, 1, 2),
  132. RtFormat.R16Sint => new FormatInfo(Format.R16Sint, 1, 1, 2),
  133. RtFormat.R16Uint => new FormatInfo(Format.R16Uint, 1, 1, 2),
  134. RtFormat.R16Float => new FormatInfo(Format.R16Float, 1, 1, 2),
  135. RtFormat.R8Unorm => new FormatInfo(Format.R8Unorm, 1, 1, 1),
  136. RtFormat.R8Snorm => new FormatInfo(Format.R8Snorm, 1, 1, 1),
  137. RtFormat.R8Sint => new FormatInfo(Format.R8Sint, 1, 1, 1),
  138. RtFormat.R8Uint => new FormatInfo(Format.R8Uint, 1, 1, 1),
  139. RtFormat.B5G5R5X1Unorm => new FormatInfo(Format.B5G5R5X1Unorm, 1, 1, 2),
  140. RtFormat.R8G8B8X8Unorm => new FormatInfo(Format.R8G8B8A8Unorm, 1, 1, 4),
  141. RtFormat.R8G8B8X8Srgb => new FormatInfo(Format.R8G8B8A8Srgb, 1, 1, 4),
  142. _ => FormatInfo.Default
  143. };
  144. }
  145. }
  146. }