kepler_compute.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <array>
  5. #include <cstddef>
  6. #include <vector>
  7. #include "common/bit_field.h"
  8. #include "common/common_funcs.h"
  9. #include "common/common_types.h"
  10. #include "video_core/engines/engine_interface.h"
  11. #include "video_core/engines/engine_upload.h"
  12. #include "video_core/textures/texture.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 : public EngineInterface {
  31. public:
  32. explicit KeplerCompute(Core::System& system, MemoryManager& memory_manager);
  33. ~KeplerCompute();
  34. /// Binds a rasterizer to this engine.
  35. void BindRasterizer(VideoCore::RasterizerInterface* rasterizer);
  36. static constexpr std::size_t NumConstBuffers = 8;
  37. struct Regs {
  38. static constexpr std::size_t NUM_REGS = 0xCF8;
  39. union {
  40. struct {
  41. INSERT_PADDING_WORDS_NOINIT(0x60);
  42. Upload::Registers upload;
  43. struct {
  44. union {
  45. BitField<0, 1, u32> linear;
  46. };
  47. } exec_upload;
  48. u32 data_upload;
  49. INSERT_PADDING_WORDS_NOINIT(0x3F);
  50. struct {
  51. u32 address;
  52. GPUVAddr Address() const {
  53. return GPUVAddr{address} << 8;
  54. }
  55. } launch_desc_loc;
  56. INSERT_PADDING_WORDS_NOINIT(0x1);
  57. u32 launch;
  58. INSERT_PADDING_WORDS_NOINIT(0x4A7);
  59. struct {
  60. u32 address_high;
  61. u32 address_low;
  62. u32 limit;
  63. GPUVAddr Address() const {
  64. return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low};
  65. }
  66. } tsc;
  67. INSERT_PADDING_WORDS_NOINIT(0x3);
  68. struct {
  69. u32 address_high;
  70. u32 address_low;
  71. u32 limit;
  72. GPUVAddr Address() const {
  73. return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low};
  74. }
  75. } tic;
  76. INSERT_PADDING_WORDS_NOINIT(0x22);
  77. struct {
  78. u32 address_high;
  79. u32 address_low;
  80. GPUVAddr Address() const {
  81. return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low};
  82. }
  83. } code_loc;
  84. INSERT_PADDING_WORDS_NOINIT(0x3FE);
  85. u32 tex_cb_index;
  86. INSERT_PADDING_WORDS_NOINIT(0x374);
  87. };
  88. std::array<u32, NUM_REGS> reg_array;
  89. };
  90. } regs{};
  91. struct LaunchParams {
  92. static constexpr std::size_t NUM_LAUNCH_PARAMETERS = 0x40;
  93. INSERT_PADDING_WORDS(0x8);
  94. u32 program_start;
  95. INSERT_PADDING_WORDS(0x2);
  96. BitField<30, 1, u32> linked_tsc;
  97. BitField<0, 31, u32> grid_dim_x;
  98. union {
  99. BitField<0, 16, u32> grid_dim_y;
  100. BitField<16, 16, u32> grid_dim_z;
  101. };
  102. INSERT_PADDING_WORDS(0x3);
  103. BitField<0, 18, u32> shared_alloc;
  104. BitField<16, 16, u32> block_dim_x;
  105. union {
  106. BitField<0, 16, u32> block_dim_y;
  107. BitField<16, 16, u32> block_dim_z;
  108. };
  109. union {
  110. BitField<0, 8, u32> const_buffer_enable_mask;
  111. BitField<29, 2, u32> cache_layout;
  112. };
  113. INSERT_PADDING_WORDS(0x8);
  114. struct ConstBufferConfig {
  115. u32 address_low;
  116. union {
  117. BitField<0, 8, u32> address_high;
  118. BitField<15, 17, u32> size;
  119. };
  120. GPUVAddr Address() const {
  121. return (GPUVAddr{address_high.Value()} << 32) | GPUVAddr{address_low};
  122. }
  123. };
  124. std::array<ConstBufferConfig, NumConstBuffers> const_buffer_config;
  125. union {
  126. BitField<0, 20, u32> local_pos_alloc;
  127. BitField<27, 5, u32> barrier_alloc;
  128. };
  129. union {
  130. BitField<0, 20, u32> local_neg_alloc;
  131. BitField<24, 5, u32> gpr_alloc;
  132. };
  133. union {
  134. BitField<0, 20, u32> local_crs_alloc;
  135. BitField<24, 5, u32> sass_version;
  136. };
  137. INSERT_PADDING_WORDS(0x10);
  138. } launch_description{};
  139. struct {
  140. u32 write_offset = 0;
  141. u32 copy_size = 0;
  142. std::vector<u8> inner_buffer;
  143. } state{};
  144. static_assert(sizeof(Regs) == Regs::NUM_REGS * sizeof(u32),
  145. "KeplerCompute Regs has wrong size");
  146. static_assert(sizeof(LaunchParams) == LaunchParams::NUM_LAUNCH_PARAMETERS * sizeof(u32),
  147. "KeplerCompute LaunchParams has wrong size");
  148. /// Write the value to the register identified by method.
  149. void CallMethod(u32 method, u32 method_argument, bool is_last_call) override;
  150. /// Write multiple values to the register identified by method.
  151. void CallMultiMethod(u32 method, const u32* base_start, u32 amount,
  152. u32 methods_pending) override;
  153. private:
  154. void ProcessLaunch();
  155. /// Retrieves information about a specific TIC entry from the TIC buffer.
  156. Texture::TICEntry GetTICEntry(u32 tic_index) const;
  157. /// Retrieves information about a specific TSC entry from the TSC buffer.
  158. Texture::TSCEntry GetTSCEntry(u32 tsc_index) const;
  159. Core::System& system;
  160. MemoryManager& memory_manager;
  161. VideoCore::RasterizerInterface* rasterizer = nullptr;
  162. Upload::State upload_state;
  163. };
  164. #define ASSERT_REG_POSITION(field_name, position) \
  165. static_assert(offsetof(KeplerCompute::Regs, field_name) == position * 4, \
  166. "Field " #field_name " has invalid position")
  167. #define ASSERT_LAUNCH_PARAM_POSITION(field_name, position) \
  168. static_assert(offsetof(KeplerCompute::LaunchParams, field_name) == position * 4, \
  169. "Field " #field_name " has invalid position")
  170. ASSERT_REG_POSITION(upload, 0x60);
  171. ASSERT_REG_POSITION(exec_upload, 0x6C);
  172. ASSERT_REG_POSITION(data_upload, 0x6D);
  173. ASSERT_REG_POSITION(launch, 0xAF);
  174. ASSERT_REG_POSITION(tsc, 0x557);
  175. ASSERT_REG_POSITION(tic, 0x55D);
  176. ASSERT_REG_POSITION(code_loc, 0x582);
  177. ASSERT_REG_POSITION(tex_cb_index, 0x982);
  178. ASSERT_LAUNCH_PARAM_POSITION(program_start, 0x8);
  179. ASSERT_LAUNCH_PARAM_POSITION(grid_dim_x, 0xC);
  180. ASSERT_LAUNCH_PARAM_POSITION(shared_alloc, 0x11);
  181. ASSERT_LAUNCH_PARAM_POSITION(block_dim_x, 0x12);
  182. ASSERT_LAUNCH_PARAM_POSITION(const_buffer_enable_mask, 0x14);
  183. ASSERT_LAUNCH_PARAM_POSITION(const_buffer_config, 0x1D);
  184. #undef ASSERT_REG_POSITION
  185. } // namespace Tegra::Engines