fermi_2d.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #define FERMI2D_REG_INDEX(field_name) \
  17. (offsetof(Tegra::Engines::Fermi2D::Regs, field_name) / sizeof(u32))
  18. class Fermi2D final {
  19. public:
  20. explicit Fermi2D(VideoCore::RasterizerInterface& rasterizer, MemoryManager& memory_manager);
  21. ~Fermi2D() = default;
  22. /// Write the value to the register identified by method.
  23. void WriteReg(u32 method, u32 value);
  24. struct Regs {
  25. static constexpr std::size_t NUM_REGS = 0x258;
  26. struct Surface {
  27. RenderTargetFormat format;
  28. BitField<0, 1, u32> linear;
  29. union {
  30. BitField<0, 4, u32> block_width;
  31. BitField<4, 4, u32> block_height;
  32. BitField<8, 4, u32> block_depth;
  33. };
  34. u32 depth;
  35. u32 layer;
  36. u32 pitch;
  37. u32 width;
  38. u32 height;
  39. u32 address_high;
  40. u32 address_low;
  41. GPUVAddr Address() const {
  42. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) |
  43. address_low);
  44. }
  45. u32 BlockWidth() const {
  46. // The block width is stored in log2 format.
  47. return 1 << block_width;
  48. }
  49. u32 BlockHeight() const {
  50. // The block height is stored in log2 format.
  51. return 1 << block_height;
  52. }
  53. u32 BlockDepth() const {
  54. // The block depth is stored in log2 format.
  55. return 1 << block_depth;
  56. }
  57. };
  58. static_assert(sizeof(Surface) == 0x28, "Surface has incorrect size");
  59. enum class Operation : u32 {
  60. SrcCopyAnd = 0,
  61. ROPAnd = 1,
  62. Blend = 2,
  63. SrcCopy = 3,
  64. ROP = 4,
  65. SrcCopyPremult = 5,
  66. BlendPremult = 6,
  67. };
  68. union {
  69. struct {
  70. INSERT_PADDING_WORDS(0x80);
  71. Surface dst;
  72. INSERT_PADDING_WORDS(2);
  73. Surface src;
  74. INSERT_PADDING_WORDS(0x15);
  75. Operation operation;
  76. INSERT_PADDING_WORDS(0x9);
  77. // TODO(Subv): This is only a guess.
  78. u32 trigger;
  79. INSERT_PADDING_WORDS(0x1A3);
  80. };
  81. std::array<u32, NUM_REGS> reg_array;
  82. };
  83. } regs{};
  84. MemoryManager& memory_manager;
  85. private:
  86. VideoCore::RasterizerInterface& rasterizer;
  87. /// Performs the copy from the source surface to the destination surface as configured in the
  88. /// registers.
  89. void HandleSurfaceCopy();
  90. };
  91. #define ASSERT_REG_POSITION(field_name, position) \
  92. static_assert(offsetof(Fermi2D::Regs, field_name) == position * 4, \
  93. "Field " #field_name " has invalid position")
  94. ASSERT_REG_POSITION(dst, 0x80);
  95. ASSERT_REG_POSITION(src, 0x8C);
  96. ASSERT_REG_POSITION(operation, 0xAB);
  97. ASSERT_REG_POSITION(trigger, 0xB5);
  98. #undef ASSERT_REG_POSITION
  99. } // namespace Tegra::Engines