fermi_2d.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 <cstddef>
  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. namespace Tegra {
  12. class MemoryManager;
  13. }
  14. namespace VideoCore {
  15. class RasterizerInterface;
  16. }
  17. namespace Tegra::Engines {
  18. #define FERMI2D_REG_INDEX(field_name) \
  19. (offsetof(Tegra::Engines::Fermi2D::Regs, field_name) / sizeof(u32))
  20. class Fermi2D final {
  21. public:
  22. explicit Fermi2D(VideoCore::RasterizerInterface& rasterizer, MemoryManager& memory_manager);
  23. ~Fermi2D() = default;
  24. /// Write the value to the register identified by method.
  25. void CallMethod(const GPU::MethodCall& method_call);
  26. struct Regs {
  27. static constexpr std::size_t NUM_REGS = 0x258;
  28. struct Surface {
  29. RenderTargetFormat format;
  30. BitField<0, 1, u32> linear;
  31. union {
  32. BitField<0, 4, u32> block_width;
  33. BitField<4, 4, u32> block_height;
  34. BitField<8, 4, u32> block_depth;
  35. };
  36. u32 depth;
  37. u32 layer;
  38. u32 pitch;
  39. u32 width;
  40. u32 height;
  41. u32 address_high;
  42. u32 address_low;
  43. GPUVAddr Address() const {
  44. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) |
  45. address_low);
  46. }
  47. u32 BlockWidth() const {
  48. // The block width is stored in log2 format.
  49. return 1 << block_width;
  50. }
  51. u32 BlockHeight() const {
  52. // The block height is stored in log2 format.
  53. return 1 << block_height;
  54. }
  55. u32 BlockDepth() const {
  56. // The block depth is stored in log2 format.
  57. return 1 << block_depth;
  58. }
  59. };
  60. static_assert(sizeof(Surface) == 0x28, "Surface has incorrect size");
  61. enum class Operation : u32 {
  62. SrcCopyAnd = 0,
  63. ROPAnd = 1,
  64. Blend = 2,
  65. SrcCopy = 3,
  66. ROP = 4,
  67. SrcCopyPremult = 5,
  68. BlendPremult = 6,
  69. };
  70. union {
  71. struct {
  72. INSERT_PADDING_WORDS(0x80);
  73. Surface dst;
  74. INSERT_PADDING_WORDS(2);
  75. Surface src;
  76. INSERT_PADDING_WORDS(0x15);
  77. Operation operation;
  78. INSERT_PADDING_WORDS(0x177);
  79. u32 blit_control;
  80. INSERT_PADDING_WORDS(0x8);
  81. u32 blit_dst_x;
  82. u32 blit_dst_y;
  83. u32 blit_dst_width;
  84. u32 blit_dst_height;
  85. u64 blit_du_dx;
  86. u64 blit_dv_dy;
  87. u64 blit_src_x;
  88. u64 blit_src_y;
  89. INSERT_PADDING_WORDS(0x21);
  90. };
  91. std::array<u32, NUM_REGS> reg_array;
  92. };
  93. } regs{};
  94. private:
  95. VideoCore::RasterizerInterface& rasterizer;
  96. MemoryManager& memory_manager;
  97. /// Performs the copy from the source surface to the destination surface as configured in the
  98. /// registers.
  99. void HandleSurfaceCopy();
  100. };
  101. #define ASSERT_REG_POSITION(field_name, position) \
  102. static_assert(offsetof(Fermi2D::Regs, field_name) == position * 4, \
  103. "Field " #field_name " has invalid position")
  104. ASSERT_REG_POSITION(dst, 0x80);
  105. ASSERT_REG_POSITION(src, 0x8C);
  106. ASSERT_REG_POSITION(operation, 0xAB);
  107. ASSERT_REG_POSITION(blit_control, 0x223);
  108. ASSERT_REG_POSITION(blit_dst_x, 0x22c);
  109. ASSERT_REG_POSITION(blit_dst_y, 0x22d);
  110. ASSERT_REG_POSITION(blit_dst_width, 0x22e);
  111. ASSERT_REG_POSITION(blit_dst_height, 0x22f);
  112. ASSERT_REG_POSITION(blit_du_dx, 0x230);
  113. ASSERT_REG_POSITION(blit_dv_dy, 0x232);
  114. ASSERT_REG_POSITION(blit_src_x, 0x234);
  115. ASSERT_REG_POSITION(blit_src_y, 0x236);
  116. #undef ASSERT_REG_POSITION
  117. } // namespace Tegra::Engines