fermi_2d.h 4.4 KB

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