kepler_compute.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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/const_buffer_engine_interface.h"
  12. #include "video_core/engines/engine_interface.h"
  13. #include "video_core/engines/engine_upload.h"
  14. #include "video_core/engines/shader_type.h"
  15. #include "video_core/gpu.h"
  16. #include "video_core/textures/texture.h"
  17. namespace Core {
  18. class System;
  19. }
  20. namespace Tegra {
  21. class MemoryManager;
  22. }
  23. namespace VideoCore {
  24. class RasterizerInterface;
  25. }
  26. namespace Tegra::Engines {
  27. /**
  28. * This Engine is known as GK104_Compute. Documentation can be found in:
  29. * https://github.com/envytools/envytools/blob/master/rnndb/graph/gk104_compute.xml
  30. * https://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/drivers/nouveau/nvc0/nve4_compute.xml.h
  31. */
  32. #define KEPLER_COMPUTE_REG_INDEX(field_name) \
  33. (offsetof(Tegra::Engines::KeplerCompute::Regs, field_name) / sizeof(u32))
  34. class KeplerCompute final : public ConstBufferEngineInterface, public EngineInterface {
  35. public:
  36. explicit KeplerCompute(Core::System& system, VideoCore::RasterizerInterface& rasterizer,
  37. MemoryManager& memory_manager);
  38. ~KeplerCompute();
  39. static constexpr std::size_t NumConstBuffers = 8;
  40. struct Regs {
  41. static constexpr std::size_t NUM_REGS = 0xCF8;
  42. union {
  43. struct {
  44. INSERT_UNION_PADDING_WORDS(0x60);
  45. Upload::Registers upload;
  46. struct {
  47. union {
  48. BitField<0, 1, u32> linear;
  49. };
  50. } exec_upload;
  51. u32 data_upload;
  52. INSERT_UNION_PADDING_WORDS(0x3F);
  53. struct {
  54. u32 address;
  55. GPUVAddr Address() const {
  56. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address) << 8));
  57. }
  58. } launch_desc_loc;
  59. INSERT_UNION_PADDING_WORDS(0x1);
  60. u32 launch;
  61. INSERT_UNION_PADDING_WORDS(0x4A7);
  62. struct {
  63. u32 address_high;
  64. u32 address_low;
  65. u32 limit;
  66. GPUVAddr Address() const {
  67. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) |
  68. address_low);
  69. }
  70. } tsc;
  71. INSERT_UNION_PADDING_WORDS(0x3);
  72. struct {
  73. u32 address_high;
  74. u32 address_low;
  75. u32 limit;
  76. GPUVAddr Address() const {
  77. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) |
  78. address_low);
  79. }
  80. } tic;
  81. INSERT_UNION_PADDING_WORDS(0x22);
  82. struct {
  83. u32 address_high;
  84. u32 address_low;
  85. GPUVAddr Address() const {
  86. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) |
  87. address_low);
  88. }
  89. } code_loc;
  90. INSERT_UNION_PADDING_WORDS(0x3FE);
  91. u32 tex_cb_index;
  92. INSERT_UNION_PADDING_WORDS(0x374);
  93. };
  94. std::array<u32, NUM_REGS> reg_array;
  95. };
  96. } regs{};
  97. struct LaunchParams {
  98. static constexpr std::size_t NUM_LAUNCH_PARAMETERS = 0x40;
  99. INSERT_PADDING_WORDS(0x8);
  100. u32 program_start;
  101. INSERT_PADDING_WORDS(0x2);
  102. BitField<30, 1, u32> linked_tsc;
  103. BitField<0, 31, u32> grid_dim_x;
  104. union {
  105. BitField<0, 16, u32> grid_dim_y;
  106. BitField<16, 16, u32> grid_dim_z;
  107. };
  108. INSERT_PADDING_WORDS(0x3);
  109. BitField<0, 18, u32> shared_alloc;
  110. BitField<16, 16, u32> block_dim_x;
  111. union {
  112. BitField<0, 16, u32> block_dim_y;
  113. BitField<16, 16, u32> block_dim_z;
  114. };
  115. union {
  116. BitField<0, 8, u32> const_buffer_enable_mask;
  117. BitField<29, 2, u32> cache_layout;
  118. };
  119. INSERT_PADDING_WORDS(0x8);
  120. struct ConstBufferConfig {
  121. u32 address_low;
  122. union {
  123. BitField<0, 8, u32> address_high;
  124. BitField<15, 17, u32> size;
  125. };
  126. GPUVAddr Address() const {
  127. return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high.Value()) << 32) |
  128. address_low);
  129. }
  130. };
  131. std::array<ConstBufferConfig, NumConstBuffers> const_buffer_config;
  132. union {
  133. BitField<0, 20, u32> local_pos_alloc;
  134. BitField<27, 5, u32> barrier_alloc;
  135. };
  136. union {
  137. BitField<0, 20, u32> local_neg_alloc;
  138. BitField<24, 5, u32> gpr_alloc;
  139. };
  140. union {
  141. BitField<0, 20, u32> local_crs_alloc;
  142. BitField<24, 5, u32> sass_version;
  143. };
  144. INSERT_PADDING_WORDS(0x10);
  145. } launch_description{};
  146. struct {
  147. u32 write_offset = 0;
  148. u32 copy_size = 0;
  149. std::vector<u8> inner_buffer;
  150. } state{};
  151. static_assert(sizeof(Regs) == Regs::NUM_REGS * sizeof(u32),
  152. "KeplerCompute Regs has wrong size");
  153. static_assert(sizeof(LaunchParams) == LaunchParams::NUM_LAUNCH_PARAMETERS * sizeof(u32),
  154. "KeplerCompute LaunchParams has wrong size");
  155. /// Write the value to the register identified by method.
  156. void CallMethod(u32 method, u32 method_argument, bool is_last_call) override;
  157. /// Write multiple values to the register identified by method.
  158. void CallMultiMethod(u32 method, const u32* base_start, u32 amount,
  159. u32 methods_pending) override;
  160. Texture::FullTextureInfo GetTexture(std::size_t offset) const;
  161. /// Given a texture handle, returns the TSC and TIC entries.
  162. Texture::FullTextureInfo GetTextureInfo(Texture::TextureHandle tex_handle) const;
  163. u32 AccessConstBuffer32(ShaderType stage, u64 const_buffer, u64 offset) const override;
  164. SamplerDescriptor AccessBoundSampler(ShaderType stage, u64 offset) const override;
  165. SamplerDescriptor AccessBindlessSampler(ShaderType stage, u64 const_buffer,
  166. u64 offset) const override;
  167. SamplerDescriptor AccessSampler(u32 handle) const override;
  168. u32 GetBoundBuffer() const override {
  169. return regs.tex_cb_index;
  170. }
  171. VideoCore::GuestDriverProfile& AccessGuestDriverProfile() override;
  172. const VideoCore::GuestDriverProfile& AccessGuestDriverProfile() const override;
  173. private:
  174. Core::System& system;
  175. VideoCore::RasterizerInterface& rasterizer;
  176. MemoryManager& memory_manager;
  177. Upload::State upload_state;
  178. void ProcessLaunch();
  179. /// Retrieves information about a specific TIC entry from the TIC buffer.
  180. Texture::TICEntry GetTICEntry(u32 tic_index) const;
  181. /// Retrieves information about a specific TSC entry from the TSC buffer.
  182. Texture::TSCEntry GetTSCEntry(u32 tsc_index) const;
  183. };
  184. #define ASSERT_REG_POSITION(field_name, position) \
  185. static_assert(offsetof(KeplerCompute::Regs, field_name) == position * 4, \
  186. "Field " #field_name " has invalid position")
  187. #define ASSERT_LAUNCH_PARAM_POSITION(field_name, position) \
  188. static_assert(offsetof(KeplerCompute::LaunchParams, field_name) == position * 4, \
  189. "Field " #field_name " has invalid position")
  190. ASSERT_REG_POSITION(upload, 0x60);
  191. ASSERT_REG_POSITION(exec_upload, 0x6C);
  192. ASSERT_REG_POSITION(data_upload, 0x6D);
  193. ASSERT_REG_POSITION(launch, 0xAF);
  194. ASSERT_REG_POSITION(tsc, 0x557);
  195. ASSERT_REG_POSITION(tic, 0x55D);
  196. ASSERT_REG_POSITION(code_loc, 0x582);
  197. ASSERT_REG_POSITION(tex_cb_index, 0x982);
  198. ASSERT_LAUNCH_PARAM_POSITION(program_start, 0x8);
  199. ASSERT_LAUNCH_PARAM_POSITION(grid_dim_x, 0xC);
  200. ASSERT_LAUNCH_PARAM_POSITION(shared_alloc, 0x11);
  201. ASSERT_LAUNCH_PARAM_POSITION(block_dim_x, 0x12);
  202. ASSERT_LAUNCH_PARAM_POSITION(const_buffer_enable_mask, 0x14);
  203. ASSERT_LAUNCH_PARAM_POSITION(const_buffer_config, 0x1D);
  204. #undef ASSERT_REG_POSITION
  205. } // namespace Tegra::Engines