fermi_2d.h 4.9 KB

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