kepler_compute.h 8.2 KB

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