fermi_2d.h 3.1 KB

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