transform_feedback.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright 2021 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <algorithm>
  5. #include <array>
  6. #include <vector>
  7. #include "common/alignment.h"
  8. #include "common/assert.h"
  9. #include "shader_recompiler/shader_info.h"
  10. #include "video_core/transform_feedback.h"
  11. namespace VideoCommon {
  12. std::vector<Shader::TransformFeedbackVarying> MakeTransformFeedbackVaryings(
  13. const TransformFeedbackState& state) {
  14. static constexpr std::array VECTORS{
  15. 28, // gl_Position
  16. 32, // Generic 0
  17. 36, // Generic 1
  18. 40, // Generic 2
  19. 44, // Generic 3
  20. 48, // Generic 4
  21. 52, // Generic 5
  22. 56, // Generic 6
  23. 60, // Generic 7
  24. 64, // Generic 8
  25. 68, // Generic 9
  26. 72, // Generic 10
  27. 76, // Generic 11
  28. 80, // Generic 12
  29. 84, // Generic 13
  30. 88, // Generic 14
  31. 92, // Generic 15
  32. 96, // Generic 16
  33. 100, // Generic 17
  34. 104, // Generic 18
  35. 108, // Generic 19
  36. 112, // Generic 20
  37. 116, // Generic 21
  38. 120, // Generic 22
  39. 124, // Generic 23
  40. 128, // Generic 24
  41. 132, // Generic 25
  42. 136, // Generic 26
  43. 140, // Generic 27
  44. 144, // Generic 28
  45. 148, // Generic 29
  46. 152, // Generic 30
  47. 156, // Generic 31
  48. 160, // gl_FrontColor
  49. 164, // gl_FrontSecondaryColor
  50. 160, // gl_BackColor
  51. 164, // gl_BackSecondaryColor
  52. 192, // gl_TexCoord[0]
  53. 196, // gl_TexCoord[1]
  54. 200, // gl_TexCoord[2]
  55. 204, // gl_TexCoord[3]
  56. 208, // gl_TexCoord[4]
  57. 212, // gl_TexCoord[5]
  58. 216, // gl_TexCoord[6]
  59. 220, // gl_TexCoord[7]
  60. };
  61. std::vector<Shader::TransformFeedbackVarying> xfb(256);
  62. for (size_t buffer = 0; buffer < state.layouts.size(); ++buffer) {
  63. const auto& locations = state.varyings[buffer];
  64. const auto& layout = state.layouts[buffer];
  65. const u32 varying_count = layout.varying_count;
  66. u32 highest = 0;
  67. for (u32 offset = 0; offset < varying_count; ++offset) {
  68. const u32 base_offset = offset;
  69. const u8 location = locations[offset];
  70. UNIMPLEMENTED_IF_MSG(layout.stream != 0, "Stream is not zero: {}", layout.stream);
  71. Shader::TransformFeedbackVarying varying{
  72. .buffer = static_cast<u32>(buffer),
  73. .stride = layout.stride,
  74. .offset = offset * 4,
  75. .components = 1,
  76. };
  77. if (std::ranges::find(VECTORS, Common::AlignDown(location, 4)) != VECTORS.end()) {
  78. UNIMPLEMENTED_IF_MSG(location % 4 != 0, "Unaligned TFB");
  79. const u8 base_index = location / 4;
  80. while (offset + 1 < varying_count && base_index == locations[offset + 1] / 4) {
  81. ++offset;
  82. ++varying.components;
  83. }
  84. }
  85. xfb[location] = varying;
  86. highest = std::max(highest, (base_offset + varying.components) * 4);
  87. }
  88. UNIMPLEMENTED_IF(highest != layout.stride);
  89. }
  90. return xfb;
  91. }
  92. } // namespace VideoCommon