kepler_memory.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 Core {
  12. class System;
  13. }
  14. namespace Tegra {
  15. class MemoryManager;
  16. }
  17. namespace VideoCore {
  18. class RasterizerInterface;
  19. }
  20. namespace Tegra::Engines {
  21. #define KEPLERMEMORY_REG_INDEX(field_name) \
  22. (offsetof(Tegra::Engines::KeplerMemory::Regs, field_name) / sizeof(u32))
  23. class KeplerMemory final {
  24. public:
  25. KeplerMemory(Core::System& system, VideoCore::RasterizerInterface& rasterizer,
  26. MemoryManager& memory_manager);
  27. ~KeplerMemory();
  28. /// Write the value to the register identified by method.
  29. void CallMethod(const GPU::MethodCall& method_call);
  30. struct Regs {
  31. static constexpr size_t NUM_REGS = 0x7F;
  32. union {
  33. struct {
  34. INSERT_PADDING_WORDS(0x60);
  35. u32 line_length_in;
  36. u32 line_count;
  37. struct {
  38. u32 address_high;
  39. u32 address_low;
  40. u32 pitch;
  41. u32 block_dimensions;
  42. u32 width;
  43. u32 height;
  44. u32 depth;
  45. u32 z;
  46. u32 x;
  47. u32 y;
  48. GPUVAddr Address() const {
  49. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) |
  50. address_low);
  51. }
  52. } dest;
  53. struct {
  54. union {
  55. BitField<0, 1, u32> linear;
  56. };
  57. } exec;
  58. u32 data;
  59. INSERT_PADDING_WORDS(0x11);
  60. };
  61. std::array<u32, NUM_REGS> reg_array;
  62. };
  63. } regs{};
  64. struct {
  65. u32 write_offset = 0;
  66. } state{};
  67. private:
  68. Core::System& system;
  69. VideoCore::RasterizerInterface& rasterizer;
  70. MemoryManager& memory_manager;
  71. void ProcessData(u32 data);
  72. };
  73. #define ASSERT_REG_POSITION(field_name, position) \
  74. static_assert(offsetof(KeplerMemory::Regs, field_name) == position * 4, \
  75. "Field " #field_name " has invalid position")
  76. ASSERT_REG_POSITION(line_length_in, 0x60);
  77. ASSERT_REG_POSITION(line_count, 0x61);
  78. ASSERT_REG_POSITION(dest, 0x62);
  79. ASSERT_REG_POSITION(exec, 0x6C);
  80. ASSERT_REG_POSITION(data, 0x6D);
  81. #undef ASSERT_REG_POSITION
  82. } // namespace Tegra::Engines