maxwell_3d.cpp 21 KB

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