dirty_flags.cpp 2.8 KB

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