dirty_flags.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2019 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <array>
  5. #include <cstddef>
  6. #include "common/common_types.h"
  7. #include "video_core/dirty_flags.h"
  8. #define OFF(field_name) MAXWELL3D_REG_INDEX(field_name)
  9. #define NUM(field_name) (sizeof(::Tegra::Engines::Maxwell3D::Regs::field_name) / (sizeof(u32)))
  10. namespace VideoCommon::Dirty {
  11. namespace {
  12. using Tegra::Engines::Maxwell3D;
  13. void SetupDirtyVertexBuffers(Maxwell3D::DirtyState::Tables& tables) {
  14. static constexpr std::size_t num_array = 3;
  15. for (std::size_t i = 0; i < Maxwell3D::Regs::NumVertexArrays; ++i) {
  16. const std::size_t array_offset = OFF(vertex_array) + i * NUM(vertex_array[0]);
  17. const std::size_t limit_offset = OFF(vertex_array_limit) + i * NUM(vertex_array_limit[0]);
  18. FillBlock(tables, array_offset, num_array, VertexBuffer0 + i, VertexBuffers);
  19. FillBlock(tables, limit_offset, NUM(vertex_array_limit), VertexBuffer0 + i, VertexBuffers);
  20. }
  21. }
  22. void SetupIndexBuffer(Maxwell3D::DirtyState::Tables& tables) {
  23. FillBlock(tables[0], OFF(index_array), NUM(index_array), IndexBuffer);
  24. }
  25. void SetupDirtyDescriptors(Maxwell3D::DirtyState::Tables& tables) {
  26. FillBlock(tables[0], OFF(tic), NUM(tic), Descriptors);
  27. FillBlock(tables[0], OFF(tsc), NUM(tsc), Descriptors);
  28. }
  29. void SetupDirtyRenderTargets(Maxwell3D::DirtyState::Tables& tables) {
  30. static constexpr std::size_t num_per_rt = NUM(rt[0]);
  31. static constexpr std::size_t begin = OFF(rt);
  32. static constexpr std::size_t num = num_per_rt * Maxwell3D::Regs::NumRenderTargets;
  33. for (std::size_t rt = 0; rt < Maxwell3D::Regs::NumRenderTargets; ++rt) {
  34. FillBlock(tables[0], begin + rt * num_per_rt, num_per_rt, ColorBuffer0 + rt);
  35. }
  36. FillBlock(tables[1], begin, num, RenderTargets);
  37. FillBlock(tables[0], OFF(render_area), NUM(render_area), RenderTargets);
  38. tables[0][OFF(rt_control)] = RenderTargets;
  39. tables[1][OFF(rt_control)] = RenderTargetControl;
  40. static constexpr std::array zeta_flags{ZetaBuffer, RenderTargets};
  41. for (std::size_t i = 0; i < std::size(zeta_flags); ++i) {
  42. const u8 flag = zeta_flags[i];
  43. auto& table = tables[i];
  44. table[OFF(zeta_enable)] = flag;
  45. table[OFF(zeta_width)] = flag;
  46. table[OFF(zeta_height)] = flag;
  47. FillBlock(table, OFF(zeta), NUM(zeta), flag);
  48. }
  49. }
  50. void SetupDirtyShaders(Maxwell3D::DirtyState::Tables& tables) {
  51. FillBlock(tables[0], OFF(shader_config[0]),
  52. NUM(shader_config[0]) * Maxwell3D::Regs::MaxShaderProgram, Shaders);
  53. }
  54. } // Anonymous namespace
  55. void SetupDirtyFlags(Maxwell3D::DirtyState::Tables& tables) {
  56. SetupDirtyVertexBuffers(tables);
  57. SetupIndexBuffer(tables);
  58. SetupDirtyDescriptors(tables);
  59. SetupDirtyRenderTargets(tables);
  60. SetupDirtyShaders(tables);
  61. }
  62. } // namespace VideoCommon::Dirty