dirty_flags.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_streams) + i * NUM(vertex_streams[0]);
  16. const std::size_t limit_offset =
  17. OFF(vertex_stream_limits) + i * NUM(vertex_stream_limits[0]);
  18. FillBlock(tables, array_offset, num_array, VertexBuffer0 + i, VertexBuffers);
  19. FillBlock(tables, limit_offset, NUM(vertex_stream_limits), VertexBuffer0 + i,
  20. VertexBuffers);
  21. }
  22. }
  23. void SetupIndexBuffer(Maxwell3D::DirtyState::Tables& tables) {
  24. FillBlock(tables[0], OFF(index_buffer), NUM(index_buffer), IndexBuffer);
  25. }
  26. void SetupDirtyDescriptors(Maxwell3D::DirtyState::Tables& tables) {
  27. FillBlock(tables[0], OFF(tex_header), NUM(tex_header), Descriptors);
  28. FillBlock(tables[0], OFF(tex_sampler), NUM(tex_sampler), Descriptors);
  29. }
  30. void SetupDirtyRenderTargets(Maxwell3D::DirtyState::Tables& tables) {
  31. static constexpr std::size_t num_per_rt = NUM(rt[0]);
  32. static constexpr std::size_t begin = OFF(rt);
  33. static constexpr std::size_t num = num_per_rt * Maxwell3D::Regs::NumRenderTargets;
  34. for (std::size_t rt = 0; rt < Maxwell3D::Regs::NumRenderTargets; ++rt) {
  35. FillBlock(tables[0], begin + rt * num_per_rt, num_per_rt, ColorBuffer0 + rt);
  36. }
  37. FillBlock(tables[1], begin, num, RenderTargets);
  38. FillBlock(tables[0], OFF(surface_clip), NUM(surface_clip), RenderTargets);
  39. tables[0][OFF(rt_control)] = RenderTargets;
  40. tables[1][OFF(rt_control)] = RenderTargetControl;
  41. static constexpr std::array zeta_flags{ZetaBuffer, RenderTargets};
  42. for (std::size_t i = 0; i < std::size(zeta_flags); ++i) {
  43. const u8 flag = zeta_flags[i];
  44. auto& table = tables[i];
  45. table[OFF(zeta_enable)] = flag;
  46. table[OFF(zeta_size.width)] = flag;
  47. table[OFF(zeta_size.height)] = flag;
  48. FillBlock(table, OFF(zeta), NUM(zeta), flag);
  49. }
  50. }
  51. void SetupDirtyShaders(Maxwell3D::DirtyState::Tables& tables) {
  52. FillBlock(tables[0], OFF(pipelines), NUM(pipelines[0]) * Maxwell3D::Regs::MaxShaderProgram,
  53. Shaders);
  54. }
  55. } // Anonymous namespace
  56. void SetupDirtyFlags(Maxwell3D::DirtyState::Tables& tables) {
  57. SetupDirtyVertexBuffers(tables);
  58. SetupIndexBuffer(tables);
  59. SetupDirtyDescriptors(tables);
  60. SetupDirtyRenderTargets(tables);
  61. SetupDirtyShaders(tables);
  62. }
  63. } // namespace VideoCommon::Dirty