fermi_2d.h 4.7 KB

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