compatible_formats.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // Copyright 2020 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <array>
  5. #include <bitset>
  6. #include <cstddef>
  7. #include "video_core/compatible_formats.h"
  8. #include "video_core/surface.h"
  9. namespace VideoCore::Surface {
  10. namespace {
  11. // Compatibility table taken from Table 3.X.2 in:
  12. // https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_texture_view.txt
  13. constexpr std::array VIEW_CLASS_128_BITS = {
  14. PixelFormat::R32G32B32A32_FLOAT,
  15. PixelFormat::R32G32B32A32_UINT,
  16. PixelFormat::R32G32B32A32_SINT,
  17. };
  18. constexpr std::array VIEW_CLASS_96_BITS = {
  19. PixelFormat::R32G32B32_FLOAT,
  20. };
  21. // Missing formats:
  22. // PixelFormat::RGB32UI,
  23. // PixelFormat::RGB32I,
  24. constexpr std::array VIEW_CLASS_64_BITS = {
  25. PixelFormat::R32G32_FLOAT, PixelFormat::R32G32_UINT,
  26. PixelFormat::R32G32_SINT, PixelFormat::R16G16B16A16_FLOAT,
  27. PixelFormat::R16G16B16A16_UNORM, PixelFormat::R16G16B16A16_SNORM,
  28. PixelFormat::R16G16B16A16_UINT, PixelFormat::R16G16B16A16_SINT,
  29. };
  30. // TODO: How should we handle 48 bits?
  31. constexpr std::array VIEW_CLASS_32_BITS = {
  32. PixelFormat::R16G16_FLOAT, PixelFormat::B10G11R11_FLOAT, PixelFormat::R32_FLOAT,
  33. PixelFormat::A2B10G10R10_UNORM, PixelFormat::R16G16_UINT, PixelFormat::R32_UINT,
  34. PixelFormat::R16G16_SINT, PixelFormat::R32_SINT, PixelFormat::A8B8G8R8_UNORM,
  35. PixelFormat::R16G16_UNORM, PixelFormat::A8B8G8R8_SNORM, PixelFormat::R16G16_SNORM,
  36. PixelFormat::A8B8G8R8_SRGB, PixelFormat::E5B9G9R9_FLOAT, PixelFormat::B8G8R8A8_UNORM,
  37. PixelFormat::B8G8R8A8_SRGB, PixelFormat::A8B8G8R8_UINT, PixelFormat::A8B8G8R8_SINT,
  38. PixelFormat::A2B10G10R10_UINT,
  39. };
  40. // TODO: How should we handle 24 bits?
  41. constexpr std::array VIEW_CLASS_16_BITS = {
  42. PixelFormat::R16_FLOAT, PixelFormat::R8G8_UINT, PixelFormat::R16_UINT,
  43. PixelFormat::R16_SINT, PixelFormat::R8G8_UNORM, PixelFormat::R16_UNORM,
  44. PixelFormat::R8G8_SNORM, PixelFormat::R16_SNORM, PixelFormat::R8G8_SINT,
  45. };
  46. constexpr std::array VIEW_CLASS_8_BITS = {
  47. PixelFormat::R8_UINT,
  48. PixelFormat::R8_UNORM,
  49. PixelFormat::R8_SINT,
  50. PixelFormat::R8_SNORM,
  51. };
  52. constexpr std::array VIEW_CLASS_RGTC1_RED = {
  53. PixelFormat::BC4_UNORM,
  54. PixelFormat::BC4_SNORM,
  55. };
  56. constexpr std::array VIEW_CLASS_RGTC2_RG = {
  57. PixelFormat::BC5_UNORM,
  58. PixelFormat::BC5_SNORM,
  59. };
  60. constexpr std::array VIEW_CLASS_BPTC_UNORM = {
  61. PixelFormat::BC7_UNORM,
  62. PixelFormat::BC7_SRGB,
  63. };
  64. constexpr std::array VIEW_CLASS_BPTC_FLOAT = {
  65. PixelFormat::BC6H_SFLOAT,
  66. PixelFormat::BC6H_UFLOAT,
  67. };
  68. // Compatibility table taken from Table 4.X.1 in:
  69. // https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_copy_image.txt
  70. constexpr std::array COPY_CLASS_128_BITS = {
  71. PixelFormat::R32G32B32A32_UINT, PixelFormat::R32G32B32A32_FLOAT, PixelFormat::R32G32B32A32_SINT,
  72. PixelFormat::BC2_UNORM, PixelFormat::BC2_SRGB, PixelFormat::BC3_UNORM,
  73. PixelFormat::BC3_SRGB, PixelFormat::BC5_UNORM, PixelFormat::BC5_SNORM,
  74. PixelFormat::BC7_UNORM, PixelFormat::BC7_SRGB, PixelFormat::BC6H_SFLOAT,
  75. PixelFormat::BC6H_UFLOAT,
  76. };
  77. // Missing formats:
  78. // PixelFormat::RGBA32I
  79. // COMPRESSED_RG_RGTC2
  80. constexpr std::array COPY_CLASS_64_BITS = {
  81. PixelFormat::R16G16B16A16_FLOAT, PixelFormat::R16G16B16A16_UINT,
  82. PixelFormat::R16G16B16A16_UNORM, PixelFormat::R16G16B16A16_SNORM,
  83. PixelFormat::R16G16B16A16_SINT, PixelFormat::R32G32_UINT,
  84. PixelFormat::R32G32_FLOAT, PixelFormat::R32G32_SINT,
  85. PixelFormat::BC1_RGBA_UNORM, PixelFormat::BC1_RGBA_SRGB,
  86. };
  87. // Missing formats:
  88. // COMPRESSED_RGB_S3TC_DXT1_EXT
  89. // COMPRESSED_SRGB_S3TC_DXT1_EXT
  90. // COMPRESSED_RGBA_S3TC_DXT1_EXT
  91. // COMPRESSED_SIGNED_RED_RGTC1
  92. void Enable(FormatCompatibility::Table& compatiblity, size_t format_a, size_t format_b) {
  93. compatiblity[format_a][format_b] = true;
  94. compatiblity[format_b][format_a] = true;
  95. }
  96. void Enable(FormatCompatibility::Table& compatibility, PixelFormat format_a, PixelFormat format_b) {
  97. Enable(compatibility, static_cast<size_t>(format_a), static_cast<size_t>(format_b));
  98. }
  99. template <typename Range>
  100. void EnableRange(FormatCompatibility::Table& compatibility, const Range& range) {
  101. for (auto it_a = range.begin(); it_a != range.end(); ++it_a) {
  102. for (auto it_b = it_a; it_b != range.end(); ++it_b) {
  103. Enable(compatibility, *it_a, *it_b);
  104. }
  105. }
  106. }
  107. } // Anonymous namespace
  108. FormatCompatibility::FormatCompatibility() {
  109. for (size_t i = 0; i < MaxPixelFormat; ++i) {
  110. // Identity is allowed
  111. Enable(view, i, i);
  112. }
  113. EnableRange(view, VIEW_CLASS_128_BITS);
  114. EnableRange(view, VIEW_CLASS_96_BITS);
  115. EnableRange(view, VIEW_CLASS_64_BITS);
  116. EnableRange(view, VIEW_CLASS_32_BITS);
  117. EnableRange(view, VIEW_CLASS_16_BITS);
  118. EnableRange(view, VIEW_CLASS_8_BITS);
  119. EnableRange(view, VIEW_CLASS_RGTC1_RED);
  120. EnableRange(view, VIEW_CLASS_RGTC2_RG);
  121. EnableRange(view, VIEW_CLASS_BPTC_UNORM);
  122. EnableRange(view, VIEW_CLASS_BPTC_FLOAT);
  123. copy = view;
  124. EnableRange(copy, COPY_CLASS_128_BITS);
  125. EnableRange(copy, COPY_CLASS_64_BITS);
  126. }
  127. } // namespace VideoCore::Surface