maxwell_dma.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include "common/assert.h"
  7. #include "common/bit_field.h"
  8. #include "common/common_funcs.h"
  9. #include "common/common_types.h"
  10. #include "video_core/gpu.h"
  11. #include "video_core/memory_manager.h"
  12. namespace VideoCore {
  13. class RasterizerInterface;
  14. }
  15. namespace Tegra::Engines {
  16. class MaxwellDMA final {
  17. public:
  18. explicit MaxwellDMA(VideoCore::RasterizerInterface& rasterizer, MemoryManager& memory_manager);
  19. ~MaxwellDMA() = default;
  20. /// Write the value to the register identified by method.
  21. void CallMethod(const GPU::MethodCall& method_call);
  22. struct Regs {
  23. static constexpr std::size_t NUM_REGS = 0x1D6;
  24. struct Parameters {
  25. union {
  26. BitField<0, 4, u32> block_depth;
  27. BitField<4, 4, u32> block_height;
  28. BitField<8, 4, u32> block_width;
  29. };
  30. u32 size_x;
  31. u32 size_y;
  32. u32 size_z;
  33. u32 pos_z;
  34. union {
  35. BitField<0, 16, u32> pos_x;
  36. BitField<16, 16, u32> pos_y;
  37. };
  38. u32 BlockHeight() const {
  39. return 1 << block_height;
  40. }
  41. u32 BlockDepth() const {
  42. return 1 << block_depth;
  43. }
  44. };
  45. static_assert(sizeof(Parameters) == 24, "Parameters has wrong size");
  46. enum class CopyMode : u32 {
  47. None = 0,
  48. Unk1 = 1,
  49. Unk2 = 2,
  50. };
  51. enum class QueryMode : u32 {
  52. None = 0,
  53. Short = 1,
  54. Long = 2,
  55. };
  56. enum class QueryIntr : u32 {
  57. None = 0,
  58. Block = 1,
  59. NonBlock = 2,
  60. };
  61. union {
  62. struct {
  63. INSERT_PADDING_WORDS(0xC0);
  64. struct {
  65. union {
  66. BitField<0, 2, CopyMode> copy_mode;
  67. BitField<2, 1, u32> flush;
  68. BitField<3, 2, QueryMode> query_mode;
  69. BitField<5, 2, QueryIntr> query_intr;
  70. BitField<7, 1, u32> is_src_linear;
  71. BitField<8, 1, u32> is_dst_linear;
  72. BitField<9, 1, u32> enable_2d;
  73. BitField<10, 1, u32> enable_swizzle;
  74. };
  75. } exec;
  76. INSERT_PADDING_WORDS(0x3F);
  77. struct {
  78. u32 address_high;
  79. u32 address_low;
  80. GPUVAddr Address() const {
  81. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) |
  82. address_low);
  83. }
  84. } src_address;
  85. struct {
  86. u32 address_high;
  87. u32 address_low;
  88. GPUVAddr Address() const {
  89. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) |
  90. address_low);
  91. }
  92. } dst_address;
  93. u32 src_pitch;
  94. u32 dst_pitch;
  95. u32 x_count;
  96. u32 y_count;
  97. INSERT_PADDING_WORDS(0xBB);
  98. Parameters dst_params;
  99. INSERT_PADDING_WORDS(1);
  100. Parameters src_params;
  101. INSERT_PADDING_WORDS(0x13);
  102. };
  103. std::array<u32, NUM_REGS> reg_array;
  104. };
  105. } regs{};
  106. MemoryManager& memory_manager;
  107. private:
  108. VideoCore::RasterizerInterface& rasterizer;
  109. /// Performs the copy from the source buffer to the destination buffer as configured in the
  110. /// registers.
  111. void HandleCopy();
  112. };
  113. #define ASSERT_REG_POSITION(field_name, position) \
  114. static_assert(offsetof(MaxwellDMA::Regs, field_name) == position * 4, \
  115. "Field " #field_name " has invalid position")
  116. ASSERT_REG_POSITION(exec, 0xC0);
  117. ASSERT_REG_POSITION(src_address, 0x100);
  118. ASSERT_REG_POSITION(dst_address, 0x102);
  119. ASSERT_REG_POSITION(src_pitch, 0x104);
  120. ASSERT_REG_POSITION(dst_pitch, 0x105);
  121. ASSERT_REG_POSITION(x_count, 0x106);
  122. ASSERT_REG_POSITION(y_count, 0x107);
  123. ASSERT_REG_POSITION(dst_params, 0x1C3);
  124. ASSERT_REG_POSITION(src_params, 0x1CA);
  125. #undef ASSERT_REG_POSITION
  126. } // namespace Tegra::Engines