kepler_compute.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 <vector>
  8. #include "common/bit_field.h"
  9. #include "common/common_funcs.h"
  10. #include "common/common_types.h"
  11. #include "video_core/engines/engine_upload.h"
  12. #include "video_core/gpu.h"
  13. namespace Core {
  14. class System;
  15. }
  16. namespace Tegra {
  17. class MemoryManager;
  18. }
  19. namespace VideoCore {
  20. class RasterizerInterface;
  21. }
  22. namespace Tegra::Engines {
  23. /**
  24. * This Engine is known as GK104_Compute. Documentation can be found in:
  25. * https://github.com/envytools/envytools/blob/master/rnndb/graph/gk104_compute.xml
  26. * https://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/drivers/nouveau/nvc0/nve4_compute.xml.h
  27. */
  28. #define KEPLER_COMPUTE_REG_INDEX(field_name) \
  29. (offsetof(Tegra::Engines::KeplerCompute::Regs, field_name) / sizeof(u32))
  30. class KeplerCompute final {
  31. public:
  32. explicit KeplerCompute(Core::System& system, VideoCore::RasterizerInterface& rasterizer,
  33. MemoryManager& memory_manager);
  34. ~KeplerCompute();
  35. static constexpr std::size_t NumConstBuffers = 8;
  36. struct Regs {
  37. static constexpr std::size_t NUM_REGS = 0xCF8;
  38. union {
  39. struct {
  40. INSERT_PADDING_WORDS(0x60);
  41. Upload::Data upload;
  42. struct {
  43. union {
  44. BitField<0, 1, u32> linear;
  45. };
  46. } exec_upload;
  47. u32 data_upload;
  48. INSERT_PADDING_WORDS(0x3F);
  49. struct {
  50. u32 address;
  51. GPUVAddr Address() const {
  52. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address) << 8));
  53. }
  54. } launch_desc_loc;
  55. INSERT_PADDING_WORDS(0x1);
  56. u32 launch;
  57. INSERT_PADDING_WORDS(0x4A7);
  58. struct {
  59. u32 address_high;
  60. u32 address_low;
  61. u32 limit;
  62. GPUVAddr Address() const {
  63. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) |
  64. address_low);
  65. }
  66. } tsc;
  67. INSERT_PADDING_WORDS(0x3);
  68. struct {
  69. u32 address_high;
  70. u32 address_low;
  71. u32 limit;
  72. GPUVAddr Address() const {
  73. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) |
  74. address_low);
  75. }
  76. } tic;
  77. INSERT_PADDING_WORDS(0x22);
  78. struct {
  79. u32 address_high;
  80. u32 address_low;
  81. GPUVAddr Address() const {
  82. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) |
  83. address_low);
  84. }
  85. } code_loc;
  86. INSERT_PADDING_WORDS(0x3FE);
  87. u32 texture_const_buffer_index;
  88. INSERT_PADDING_WORDS(0x374);
  89. };
  90. std::array<u32, NUM_REGS> reg_array;
  91. };
  92. } regs{};
  93. struct LaunchParams {
  94. static constexpr std::size_t NUM_LAUNCH_PARAMETERS = 0x40;
  95. INSERT_PADDING_WORDS(0x8);
  96. u32 program_start;
  97. INSERT_PADDING_WORDS(0x2);
  98. BitField<30, 1, u32> linked_tsc;
  99. BitField<0, 31, u32> grid_dim_x;
  100. union {
  101. BitField<0, 16, u32> grid_dim_y;
  102. BitField<16, 16, u32> grid_dim_z;
  103. };
  104. INSERT_PADDING_WORDS(0x3);
  105. BitField<0, 16, u32> shared_alloc;
  106. BitField<0, 31, u32> block_dim_x;
  107. union {
  108. BitField<0, 16, u32> block_dim_y;
  109. BitField<16, 16, u32> block_dim_z;
  110. };
  111. union {
  112. BitField<0, 8, u32> const_buffer_enable_mask;
  113. BitField<29, 2, u32> cache_layout;
  114. } memory_config;
  115. INSERT_PADDING_WORDS(0x8);
  116. struct {
  117. u32 address_low;
  118. union {
  119. BitField<0, 8, u32> address_high;
  120. BitField<15, 17, u32> size;
  121. };
  122. GPUVAddr Address() const {
  123. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high.Value()) << 32) |
  124. address_low);
  125. }
  126. } const_buffer_config[8];
  127. union {
  128. BitField<0, 20, u32> local_pos_alloc;
  129. BitField<27, 5, u32> barrier_alloc;
  130. };
  131. union {
  132. BitField<0, 20, u32> local_neg_alloc;
  133. BitField<24, 5, u32> gpr_alloc;
  134. };
  135. INSERT_PADDING_WORDS(0x11);
  136. } launch_description;
  137. struct {
  138. u32 write_offset = 0;
  139. u32 copy_size = 0;
  140. std::vector<u8> inner_buffer;
  141. } state{};
  142. static_assert(sizeof(Regs) == Regs::NUM_REGS * sizeof(u32),
  143. "KeplerCompute Regs has wrong size");
  144. static_assert(sizeof(LaunchParams) == LaunchParams::NUM_LAUNCH_PARAMETERS * sizeof(u32),
  145. "KeplerCompute LaunchParams has wrong size");
  146. /// Write the value to the register identified by method.
  147. void CallMethod(const GPU::MethodCall& method_call);
  148. private:
  149. Core::System& system;
  150. VideoCore::RasterizerInterface& rasterizer;
  151. MemoryManager& memory_manager;
  152. Upload::State upload_state;
  153. void ProcessLaunch();
  154. };
  155. #define ASSERT_REG_POSITION(field_name, position) \
  156. static_assert(offsetof(KeplerCompute::Regs, field_name) == position * 4, \
  157. "Field " #field_name " has invalid position")
  158. #define ASSERT_LAUNCH_PARAM_POSITION(field_name, position) \
  159. static_assert(offsetof(KeplerCompute::LaunchParams, field_name) == position * 4, \
  160. "Field " #field_name " has invalid position")
  161. ASSERT_REG_POSITION(upload, 0x60);
  162. ASSERT_REG_POSITION(exec_upload, 0x6C);
  163. ASSERT_REG_POSITION(data_upload, 0x6D);
  164. ASSERT_REG_POSITION(launch, 0xAF);
  165. ASSERT_REG_POSITION(tsc, 0x557);
  166. ASSERT_REG_POSITION(tic, 0x55D);
  167. ASSERT_REG_POSITION(code_loc, 0x582);
  168. ASSERT_REG_POSITION(texture_const_buffer_index, 0x982);
  169. ASSERT_LAUNCH_PARAM_POSITION(program_start, 0x8);
  170. ASSERT_LAUNCH_PARAM_POSITION(grid_dim_x, 0xC);
  171. ASSERT_LAUNCH_PARAM_POSITION(shared_alloc, 0x11);
  172. ASSERT_LAUNCH_PARAM_POSITION(block_dim_x, 0x12);
  173. ASSERT_LAUNCH_PARAM_POSITION(memory_config, 0x14);
  174. ASSERT_LAUNCH_PARAM_POSITION(const_buffer_config, 0x1D);
  175. #undef ASSERT_REG_POSITION
  176. } // namespace Tegra::Engines