transform_feedback.cpp 3.2 KB

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