maxwell_3d.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <cinttypes>
  5. #include <cstring>
  6. #include "common/assert.h"
  7. #include "core/core.h"
  8. #include "core/core_timing.h"
  9. #include "video_core/debug_utils/debug_utils.h"
  10. #include "video_core/engines/maxwell_3d.h"
  11. #include "video_core/memory_manager.h"
  12. #include "video_core/rasterizer_interface.h"
  13. #include "video_core/textures/texture.h"
  14. namespace Tegra::Engines {
  15. /// First register id that is actually a Macro call.
  16. constexpr u32 MacroRegistersStart = 0xE00;
  17. Maxwell3D::Maxwell3D(Core::System& system, VideoCore::RasterizerInterface& rasterizer,
  18. MemoryManager& memory_manager)
  19. : system{system}, rasterizer{rasterizer}, memory_manager{memory_manager}, macro_interpreter{
  20. *this} {
  21. InitializeRegisterDefaults();
  22. }
  23. void Maxwell3D::InitializeRegisterDefaults() {
  24. // Initializes registers to their default values - what games expect them to be at boot. This is
  25. // for certain registers that may not be explicitly set by games.
  26. // Reset all registers to zero
  27. std::memset(&regs, 0, sizeof(regs));
  28. // Depth range near/far is not always set, but is expected to be the default 0.0f, 1.0f. This is
  29. // needed for ARMS.
  30. for (std::size_t viewport{}; viewport < Regs::NumViewports; ++viewport) {
  31. regs.viewports[viewport].depth_range_near = 0.0f;
  32. regs.viewports[viewport].depth_range_far = 1.0f;
  33. }
  34. // Doom and Bomberman seems to use the uninitialized registers and just enable blend
  35. // so initialize blend registers with sane values
  36. regs.blend.equation_rgb = Regs::Blend::Equation::Add;
  37. regs.blend.factor_source_rgb = Regs::Blend::Factor::One;
  38. regs.blend.factor_dest_rgb = Regs::Blend::Factor::Zero;
  39. regs.blend.equation_a = Regs::Blend::Equation::Add;
  40. regs.blend.factor_source_a = Regs::Blend::Factor::One;
  41. regs.blend.factor_dest_a = Regs::Blend::Factor::Zero;
  42. for (std::size_t blend_index = 0; blend_index < Regs::NumRenderTargets; blend_index++) {
  43. regs.independent_blend[blend_index].equation_rgb = Regs::Blend::Equation::Add;
  44. regs.independent_blend[blend_index].factor_source_rgb = Regs::Blend::Factor::One;
  45. regs.independent_blend[blend_index].factor_dest_rgb = Regs::Blend::Factor::Zero;
  46. regs.independent_blend[blend_index].equation_a = Regs::Blend::Equation::Add;
  47. regs.independent_blend[blend_index].factor_source_a = Regs::Blend::Factor::One;
  48. regs.independent_blend[blend_index].factor_dest_a = Regs::Blend::Factor::Zero;
  49. }
  50. regs.stencil_front_op_fail = Regs::StencilOp::Keep;
  51. regs.stencil_front_op_zfail = Regs::StencilOp::Keep;
  52. regs.stencil_front_op_zpass = Regs::StencilOp::Keep;
  53. regs.stencil_front_func_func = Regs::ComparisonOp::Always;
  54. regs.stencil_front_func_mask = 0xFFFFFFFF;
  55. regs.stencil_front_mask = 0xFFFFFFFF;
  56. regs.stencil_two_side_enable = 1;
  57. regs.stencil_back_op_fail = Regs::StencilOp::Keep;
  58. regs.stencil_back_op_zfail = Regs::StencilOp::Keep;
  59. regs.stencil_back_op_zpass = Regs::StencilOp::Keep;
  60. regs.stencil_back_func_func = Regs::ComparisonOp::Always;
  61. regs.stencil_back_func_mask = 0xFFFFFFFF;
  62. regs.stencil_back_mask = 0xFFFFFFFF;
  63. // TODO(Rodrigo): Most games do not set a point size. I think this is a case of a
  64. // register carrying a default value. Assume it's OpenGL's default (1).
  65. regs.point_size = 1.0f;
  66. // TODO(bunnei): Some games do not initialize the color masks (e.g. Sonic Mania). Assuming a
  67. // default of enabled fixes rendering here.
  68. for (std::size_t color_mask = 0; color_mask < Regs::NumRenderTargets; color_mask++) {
  69. regs.color_mask[color_mask].R.Assign(1);
  70. regs.color_mask[color_mask].G.Assign(1);
  71. regs.color_mask[color_mask].B.Assign(1);
  72. regs.color_mask[color_mask].A.Assign(1);
  73. }
  74. // Commercial games seem to assume this value is enabled and nouveau sets this value manually.
  75. regs.rt_separate_frag_data = 1;
  76. }
  77. void Maxwell3D::CallMacroMethod(u32 method, std::vector<u32> parameters) {
  78. // Reset the current macro.
  79. executing_macro = 0;
  80. // Lookup the macro offset
  81. const u32 entry{(method - MacroRegistersStart) >> 1};
  82. const auto& search{macro_offsets.find(entry)};
  83. if (search == macro_offsets.end()) {
  84. LOG_CRITICAL(HW_GPU, "macro not found for method 0x{:X}!", method);
  85. UNREACHABLE();
  86. return;
  87. }
  88. // Execute the current macro.
  89. macro_interpreter.Execute(search->second, std::move(parameters));
  90. }
  91. void Maxwell3D::CallMethod(const GPU::MethodCall& method_call) {
  92. auto debug_context = system.GetGPUDebugContext();
  93. const u32 method = method_call.method;
  94. // It is an error to write to a register other than the current macro's ARG register before it
  95. // has finished execution.
  96. if (executing_macro != 0) {
  97. ASSERT(method == executing_macro + 1);
  98. }
  99. // Methods after 0xE00 are special, they're actually triggers for some microcode that was
  100. // uploaded to the GPU during initialization.
  101. if (method >= MacroRegistersStart) {
  102. // We're trying to execute a macro
  103. if (executing_macro == 0) {
  104. // A macro call must begin by writing the macro method's register, not its argument.
  105. ASSERT_MSG((method % 2) == 0,
  106. "Can't start macro execution by writing to the ARGS register");
  107. executing_macro = method;
  108. }
  109. macro_params.push_back(method_call.argument);
  110. // Call the macro when there are no more parameters in the command buffer
  111. if (method_call.IsLastCall()) {
  112. CallMacroMethod(executing_macro, std::move(macro_params));
  113. }
  114. return;
  115. }
  116. ASSERT_MSG(method < Regs::NUM_REGS,
  117. "Invalid Maxwell3D register, increase the size of the Regs structure");
  118. if (debug_context) {
  119. debug_context->OnEvent(Tegra::DebugContext::Event::MaxwellCommandLoaded, nullptr);
  120. }
  121. if (regs.reg_array[method] != method_call.argument) {
  122. regs.reg_array[method] = method_call.argument;
  123. // Color buffers
  124. constexpr u32 first_rt_reg = MAXWELL3D_REG_INDEX(rt);
  125. constexpr u32 registers_per_rt = sizeof(regs.rt[0]) / sizeof(u32);
  126. if (method >= first_rt_reg &&
  127. method < first_rt_reg + registers_per_rt * Regs::NumRenderTargets) {
  128. const std::size_t rt_index = (method - first_rt_reg) / registers_per_rt;
  129. dirty_flags.color_buffer.set(rt_index);
  130. }
  131. // Zeta buffer
  132. constexpr u32 registers_in_zeta = sizeof(regs.zeta) / sizeof(u32);
  133. if (method == MAXWELL3D_REG_INDEX(zeta_enable) ||
  134. method == MAXWELL3D_REG_INDEX(zeta_width) ||
  135. method == MAXWELL3D_REG_INDEX(zeta_height) ||
  136. (method >= MAXWELL3D_REG_INDEX(zeta) &&
  137. method < MAXWELL3D_REG_INDEX(zeta) + registers_in_zeta)) {
  138. dirty_flags.zeta_buffer = true;
  139. }
  140. // Shader
  141. constexpr u32 shader_registers_count =
  142. sizeof(regs.shader_config[0]) * Regs::MaxShaderProgram / sizeof(u32);
  143. if (method >= MAXWELL3D_REG_INDEX(shader_config[0]) &&
  144. method < MAXWELL3D_REG_INDEX(shader_config[0]) + shader_registers_count) {
  145. dirty_flags.shaders = true;
  146. }
  147. // Vertex format
  148. if (method >= MAXWELL3D_REG_INDEX(vertex_attrib_format) &&
  149. method < MAXWELL3D_REG_INDEX(vertex_attrib_format) + regs.vertex_attrib_format.size()) {
  150. dirty_flags.vertex_attrib_format = true;
  151. }
  152. // Vertex buffer
  153. if (method >= MAXWELL3D_REG_INDEX(vertex_array) &&
  154. method < MAXWELL3D_REG_INDEX(vertex_array) + 4 * 32) {
  155. dirty_flags.vertex_array.set((method - MAXWELL3D_REG_INDEX(vertex_array)) >> 2);
  156. } else if (method >= MAXWELL3D_REG_INDEX(vertex_array_limit) &&
  157. method < MAXWELL3D_REG_INDEX(vertex_array_limit) + 2 * 32) {
  158. dirty_flags.vertex_array.set((method - MAXWELL3D_REG_INDEX(vertex_array_limit)) >> 1);
  159. } else if (method >= MAXWELL3D_REG_INDEX(instanced_arrays) &&
  160. method < MAXWELL3D_REG_INDEX(instanced_arrays) + 32) {
  161. dirty_flags.vertex_array.set(method - MAXWELL3D_REG_INDEX(instanced_arrays));
  162. }
  163. }
  164. switch (method) {
  165. case MAXWELL3D_REG_INDEX(macros.data): {
  166. ProcessMacroUpload(method_call.argument);
  167. break;
  168. }
  169. case MAXWELL3D_REG_INDEX(macros.bind): {
  170. ProcessMacroBind(method_call.argument);
  171. break;
  172. }
  173. case MAXWELL3D_REG_INDEX(const_buffer.cb_data[0]):
  174. case MAXWELL3D_REG_INDEX(const_buffer.cb_data[1]):
  175. case MAXWELL3D_REG_INDEX(const_buffer.cb_data[2]):
  176. case MAXWELL3D_REG_INDEX(const_buffer.cb_data[3]):
  177. case MAXWELL3D_REG_INDEX(const_buffer.cb_data[4]):
  178. case MAXWELL3D_REG_INDEX(const_buffer.cb_data[5]):
  179. case MAXWELL3D_REG_INDEX(const_buffer.cb_data[6]):
  180. case MAXWELL3D_REG_INDEX(const_buffer.cb_data[7]):
  181. case MAXWELL3D_REG_INDEX(const_buffer.cb_data[8]):
  182. case MAXWELL3D_REG_INDEX(const_buffer.cb_data[9]):
  183. case MAXWELL3D_REG_INDEX(const_buffer.cb_data[10]):
  184. case MAXWELL3D_REG_INDEX(const_buffer.cb_data[11]):
  185. case MAXWELL3D_REG_INDEX(const_buffer.cb_data[12]):
  186. case MAXWELL3D_REG_INDEX(const_buffer.cb_data[13]):
  187. case MAXWELL3D_REG_INDEX(const_buffer.cb_data[14]):
  188. case MAXWELL3D_REG_INDEX(const_buffer.cb_data[15]): {
  189. ProcessCBData(method_call.argument);
  190. break;
  191. }
  192. case MAXWELL3D_REG_INDEX(cb_bind[0].raw_config): {
  193. ProcessCBBind(Regs::ShaderStage::Vertex);
  194. break;
  195. }
  196. case MAXWELL3D_REG_INDEX(cb_bind[1].raw_config): {
  197. ProcessCBBind(Regs::ShaderStage::TesselationControl);
  198. break;
  199. }
  200. case MAXWELL3D_REG_INDEX(cb_bind[2].raw_config): {
  201. ProcessCBBind(Regs::ShaderStage::TesselationEval);
  202. break;
  203. }
  204. case MAXWELL3D_REG_INDEX(cb_bind[3].raw_config): {
  205. ProcessCBBind(Regs::ShaderStage::Geometry);
  206. break;
  207. }
  208. case MAXWELL3D_REG_INDEX(cb_bind[4].raw_config): {
  209. ProcessCBBind(Regs::ShaderStage::Fragment);
  210. break;
  211. }
  212. case MAXWELL3D_REG_INDEX(draw.vertex_end_gl): {
  213. DrawArrays();
  214. break;
  215. }
  216. case MAXWELL3D_REG_INDEX(clear_buffers): {
  217. ProcessClearBuffers();
  218. break;
  219. }
  220. case MAXWELL3D_REG_INDEX(query.query_get): {
  221. ProcessQueryGet();
  222. break;
  223. }
  224. case MAXWELL3D_REG_INDEX(sync_info): {
  225. ProcessSyncPoint();
  226. break;
  227. }
  228. default:
  229. break;
  230. }
  231. if (debug_context) {
  232. debug_context->OnEvent(Tegra::DebugContext::Event::MaxwellCommandProcessed, nullptr);
  233. }
  234. }
  235. void Maxwell3D::ProcessMacroUpload(u32 data) {
  236. ASSERT_MSG(regs.macros.upload_address < macro_memory.size(),
  237. "upload_address exceeded macro_memory size!");
  238. macro_memory[regs.macros.upload_address++] = data;
  239. }
  240. void Maxwell3D::ProcessMacroBind(u32 data) {
  241. macro_offsets[regs.macros.entry] = data;
  242. }
  243. void Maxwell3D::ProcessQueryGet() {
  244. const GPUVAddr sequence_address{regs.query.QueryAddress()};
  245. // Since the sequence address is given as a GPU VAddr, we have to convert it to an application
  246. // VAddr before writing.
  247. // TODO(Subv): Support the other query units.
  248. ASSERT_MSG(regs.query.query_get.unit == Regs::QueryUnit::Crop,
  249. "Units other than CROP are unimplemented");
  250. u64 result = 0;
  251. // TODO(Subv): Support the other query variables
  252. switch (regs.query.query_get.select) {
  253. case Regs::QuerySelect::Zero:
  254. // This seems to actually write the query sequence to the query address.
  255. result = regs.query.query_sequence;
  256. break;
  257. default:
  258. UNIMPLEMENTED_MSG("Unimplemented query select type {}",
  259. static_cast<u32>(regs.query.query_get.select.Value()));
  260. }
  261. // TODO(Subv): Research and implement how query sync conditions work.
  262. struct LongQueryResult {
  263. u64_le value;
  264. u64_le timestamp;
  265. };
  266. static_assert(sizeof(LongQueryResult) == 16, "LongQueryResult has wrong size");
  267. switch (regs.query.query_get.mode) {
  268. case Regs::QueryMode::Write:
  269. case Regs::QueryMode::Write2: {
  270. u32 sequence = regs.query.query_sequence;
  271. if (regs.query.query_get.short_query) {
  272. // Write the current query sequence to the sequence address.
  273. // TODO(Subv): Find out what happens if you use a long query type but mark it as a short
  274. // query.
  275. memory_manager.Write<u32>(sequence_address, sequence);
  276. } else {
  277. // Write the 128-bit result structure in long mode. Note: We emulate an infinitely fast
  278. // GPU, this command may actually take a while to complete in real hardware due to GPU
  279. // wait queues.
  280. LongQueryResult query_result{};
  281. query_result.value = result;
  282. // TODO(Subv): Generate a real GPU timestamp and write it here instead of CoreTiming
  283. query_result.timestamp = system.CoreTiming().GetTicks();
  284. memory_manager.WriteBlock(sequence_address, &query_result, sizeof(query_result));
  285. }
  286. dirty_flags.OnMemoryWrite();
  287. break;
  288. }
  289. default:
  290. UNIMPLEMENTED_MSG("Query mode {} not implemented",
  291. static_cast<u32>(regs.query.query_get.mode.Value()));
  292. }
  293. }
  294. void Maxwell3D::ProcessSyncPoint() {
  295. const u32 sync_point = regs.sync_info.sync_point.Value();
  296. const u32 increment = regs.sync_info.increment.Value();
  297. const u32 cache_flush = regs.sync_info.unknown.Value();
  298. LOG_DEBUG(HW_GPU, "Syncpoint set {}, increment: {}, unk: {}", sync_point, increment,
  299. cache_flush);
  300. }
  301. void Maxwell3D::DrawArrays() {
  302. LOG_DEBUG(HW_GPU, "called, topology={}, count={}", static_cast<u32>(regs.draw.topology.Value()),
  303. regs.vertex_buffer.count);
  304. ASSERT_MSG(!(regs.index_array.count && regs.vertex_buffer.count), "Both indexed and direct?");
  305. auto debug_context = system.GetGPUDebugContext();
  306. if (debug_context) {
  307. debug_context->OnEvent(Tegra::DebugContext::Event::IncomingPrimitiveBatch, nullptr);
  308. }
  309. // Both instance configuration registers can not be set at the same time.
  310. ASSERT_MSG(!regs.draw.instance_next || !regs.draw.instance_cont,
  311. "Illegal combination of instancing parameters");
  312. if (regs.draw.instance_next) {
  313. // Increment the current instance *before* drawing.
  314. state.current_instance += 1;
  315. } else if (!regs.draw.instance_cont) {
  316. // Reset the current instance to 0.
  317. state.current_instance = 0;
  318. }
  319. const bool is_indexed{regs.index_array.count && !regs.vertex_buffer.count};
  320. rasterizer.AccelerateDrawBatch(is_indexed);
  321. if (debug_context) {
  322. debug_context->OnEvent(Tegra::DebugContext::Event::FinishedPrimitiveBatch, nullptr);
  323. }
  324. // TODO(bunnei): Below, we reset vertex count so that we can use these registers to determine if
  325. // the game is trying to draw indexed or direct mode. This needs to be verified on HW still -
  326. // it's possible that it is incorrect and that there is some other register used to specify the
  327. // drawing mode.
  328. if (is_indexed) {
  329. regs.index_array.count = 0;
  330. } else {
  331. regs.vertex_buffer.count = 0;
  332. }
  333. }
  334. void Maxwell3D::ProcessCBBind(Regs::ShaderStage stage) {
  335. // Bind the buffer currently in CB_ADDRESS to the specified index in the desired shader stage.
  336. auto& shader = state.shader_stages[static_cast<std::size_t>(stage)];
  337. auto& bind_data = regs.cb_bind[static_cast<std::size_t>(stage)];
  338. auto& buffer = shader.const_buffers[bind_data.index];
  339. ASSERT(bind_data.index < Regs::MaxConstBuffers);
  340. buffer.enabled = bind_data.valid.Value() != 0;
  341. buffer.index = bind_data.index;
  342. buffer.address = regs.const_buffer.BufferAddress();
  343. buffer.size = regs.const_buffer.cb_size;
  344. }
  345. void Maxwell3D::ProcessCBData(u32 value) {
  346. // Write the input value to the current const buffer at the current position.
  347. const GPUVAddr buffer_address = regs.const_buffer.BufferAddress();
  348. ASSERT(buffer_address != 0);
  349. // Don't allow writing past the end of the buffer.
  350. ASSERT(regs.const_buffer.cb_pos + sizeof(u32) <= regs.const_buffer.cb_size);
  351. const GPUVAddr address{buffer_address + regs.const_buffer.cb_pos};
  352. u8* ptr{memory_manager.GetPointer(address)};
  353. rasterizer.InvalidateRegion(ToCacheAddr(ptr), sizeof(u32));
  354. memory_manager.Write<u32>(address, value);
  355. dirty_flags.OnMemoryWrite();
  356. // Increment the current buffer position.
  357. regs.const_buffer.cb_pos = regs.const_buffer.cb_pos + 4;
  358. }
  359. Texture::TICEntry Maxwell3D::GetTICEntry(u32 tic_index) const {
  360. const GPUVAddr tic_address_gpu{regs.tic.TICAddress() + tic_index * sizeof(Texture::TICEntry)};
  361. Texture::TICEntry tic_entry;
  362. memory_manager.ReadBlock(tic_address_gpu, &tic_entry, sizeof(Texture::TICEntry));
  363. ASSERT_MSG(tic_entry.header_version == Texture::TICHeaderVersion::BlockLinear ||
  364. tic_entry.header_version == Texture::TICHeaderVersion::Pitch,
  365. "TIC versions other than BlockLinear or Pitch are unimplemented");
  366. const auto r_type = tic_entry.r_type.Value();
  367. const auto g_type = tic_entry.g_type.Value();
  368. const auto b_type = tic_entry.b_type.Value();
  369. const auto a_type = tic_entry.a_type.Value();
  370. // TODO(Subv): Different data types for separate components are not supported
  371. ASSERT(r_type == g_type && r_type == b_type && r_type == a_type);
  372. return tic_entry;
  373. }
  374. Texture::TSCEntry Maxwell3D::GetTSCEntry(u32 tsc_index) const {
  375. const GPUVAddr tsc_address_gpu{regs.tsc.TSCAddress() + tsc_index * sizeof(Texture::TSCEntry)};
  376. Texture::TSCEntry tsc_entry;
  377. memory_manager.ReadBlock(tsc_address_gpu, &tsc_entry, sizeof(Texture::TSCEntry));
  378. return tsc_entry;
  379. }
  380. std::vector<Texture::FullTextureInfo> Maxwell3D::GetStageTextures(Regs::ShaderStage stage) const {
  381. std::vector<Texture::FullTextureInfo> textures;
  382. auto& fragment_shader = state.shader_stages[static_cast<std::size_t>(stage)];
  383. auto& tex_info_buffer = fragment_shader.const_buffers[regs.tex_cb_index];
  384. ASSERT(tex_info_buffer.enabled && tex_info_buffer.address != 0);
  385. GPUVAddr tex_info_buffer_end = tex_info_buffer.address + tex_info_buffer.size;
  386. // Offset into the texture constbuffer where the texture info begins.
  387. static constexpr std::size_t TextureInfoOffset = 0x20;
  388. for (GPUVAddr current_texture = tex_info_buffer.address + TextureInfoOffset;
  389. current_texture < tex_info_buffer_end; current_texture += sizeof(Texture::TextureHandle)) {
  390. const Texture::TextureHandle tex_handle{memory_manager.Read<u32>(current_texture)};
  391. Texture::FullTextureInfo tex_info{};
  392. // TODO(Subv): Use the shader to determine which textures are actually accessed.
  393. tex_info.index =
  394. static_cast<u32>(current_texture - tex_info_buffer.address - TextureInfoOffset) /
  395. sizeof(Texture::TextureHandle);
  396. // Load the TIC data.
  397. auto tic_entry = GetTICEntry(tex_handle.tic_id);
  398. // TODO(Subv): Workaround for BitField's move constructor being deleted.
  399. std::memcpy(&tex_info.tic, &tic_entry, sizeof(tic_entry));
  400. // Load the TSC data
  401. auto tsc_entry = GetTSCEntry(tex_handle.tsc_id);
  402. // TODO(Subv): Workaround for BitField's move constructor being deleted.
  403. std::memcpy(&tex_info.tsc, &tsc_entry, sizeof(tsc_entry));
  404. textures.push_back(tex_info);
  405. }
  406. return textures;
  407. }
  408. Texture::FullTextureInfo Maxwell3D::GetTextureInfo(const Texture::TextureHandle tex_handle,
  409. std::size_t offset) const {
  410. Texture::FullTextureInfo tex_info{};
  411. tex_info.index = static_cast<u32>(offset);
  412. // Load the TIC data.
  413. auto tic_entry = GetTICEntry(tex_handle.tic_id);
  414. // TODO(Subv): Workaround for BitField's move constructor being deleted.
  415. std::memcpy(&tex_info.tic, &tic_entry, sizeof(tic_entry));
  416. // Load the TSC data
  417. auto tsc_entry = GetTSCEntry(tex_handle.tsc_id);
  418. // TODO(Subv): Workaround for BitField's move constructor being deleted.
  419. std::memcpy(&tex_info.tsc, &tsc_entry, sizeof(tsc_entry));
  420. return tex_info;
  421. }
  422. Texture::FullTextureInfo Maxwell3D::GetStageTexture(Regs::ShaderStage stage,
  423. std::size_t offset) const {
  424. const auto& shader = state.shader_stages[static_cast<std::size_t>(stage)];
  425. const auto& tex_info_buffer = shader.const_buffers[regs.tex_cb_index];
  426. ASSERT(tex_info_buffer.enabled && tex_info_buffer.address != 0);
  427. const GPUVAddr tex_info_address =
  428. tex_info_buffer.address + offset * sizeof(Texture::TextureHandle);
  429. ASSERT(tex_info_address < tex_info_buffer.address + tex_info_buffer.size);
  430. const Texture::TextureHandle tex_handle{memory_manager.Read<u32>(tex_info_address)};
  431. return GetTextureInfo(tex_handle, offset);
  432. }
  433. u32 Maxwell3D::GetRegisterValue(u32 method) const {
  434. ASSERT_MSG(method < Regs::NUM_REGS, "Invalid Maxwell3D register");
  435. return regs.reg_array[method];
  436. }
  437. void Maxwell3D::ProcessClearBuffers() {
  438. ASSERT(regs.clear_buffers.R == regs.clear_buffers.G &&
  439. regs.clear_buffers.R == regs.clear_buffers.B &&
  440. regs.clear_buffers.R == regs.clear_buffers.A);
  441. rasterizer.Clear();
  442. }
  443. u32 Maxwell3D::AccessConstBuffer32(Regs::ShaderStage stage, u64 const_buffer, u64 offset) const {
  444. const auto& shader_stage = state.shader_stages[static_cast<std::size_t>(stage)];
  445. const auto& buffer = shader_stage.const_buffers[const_buffer];
  446. u32 result;
  447. std::memcpy(&result, memory_manager.GetPointer(buffer.address + offset), sizeof(u32));
  448. return result;
  449. }
  450. } // namespace Tegra::Engines