command_processor.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <array>
  5. #include <cstddef>
  6. #include <memory>
  7. #include <utility>
  8. #include "common/assert.h"
  9. #include "common/logging/log.h"
  10. #include "common/microprofile.h"
  11. #include "common/vector_math.h"
  12. #include "core/hle/service/gsp_gpu.h"
  13. #include "core/hw/gpu.h"
  14. #include "core/memory.h"
  15. #include "core/tracer/recorder.h"
  16. #include "video_core/command_processor.h"
  17. #include "video_core/debug_utils/debug_utils.h"
  18. #include "video_core/pica_state.h"
  19. #include "video_core/pica_types.h"
  20. #include "video_core/primitive_assembly.h"
  21. #include "video_core/rasterizer_interface.h"
  22. #include "video_core/regs.h"
  23. #include "video_core/regs_pipeline.h"
  24. #include "video_core/regs_texturing.h"
  25. #include "video_core/renderer_base.h"
  26. #include "video_core/shader/shader.h"
  27. #include "video_core/vertex_loader.h"
  28. #include "video_core/video_core.h"
  29. namespace Pica {
  30. namespace CommandProcessor {
  31. static int float_regs_counter = 0;
  32. static u32 uniform_write_buffer[4];
  33. static int default_attr_counter = 0;
  34. static u32 default_attr_write_buffer[3];
  35. // Expand a 4-bit mask to 4-byte mask, e.g. 0b0101 -> 0x00FF00FF
  36. static const u32 expand_bits_to_bytes[] = {
  37. 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff, 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
  38. 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff, 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff,
  39. };
  40. MICROPROFILE_DEFINE(GPU_Drawing, "GPU", "Drawing", MP_RGB(50, 50, 240));
  41. static void WritePicaReg(u32 id, u32 value, u32 mask) {
  42. auto& regs = g_state.regs;
  43. if (id >= Regs::NUM_REGS) {
  44. LOG_ERROR(HW_GPU,
  45. "Commandlist tried to write to invalid register 0x%03X (value: %08X, mask: %X)",
  46. id, value, mask);
  47. return;
  48. }
  49. // TODO: Figure out how register masking acts on e.g. vs.uniform_setup.set_value
  50. u32 old_value = regs.reg_array[id];
  51. const u32 write_mask = expand_bits_to_bytes[mask];
  52. regs.reg_array[id] = (old_value & ~write_mask) | (value & write_mask);
  53. // Double check for is_pica_tracing to avoid call overhead
  54. if (DebugUtils::IsPicaTracing()) {
  55. DebugUtils::OnPicaRegWrite({(u16)id, (u16)mask, regs.reg_array[id]});
  56. }
  57. if (g_debug_context)
  58. g_debug_context->OnEvent(DebugContext::Event::PicaCommandLoaded,
  59. reinterpret_cast<void*>(&id));
  60. switch (id) {
  61. // Trigger IRQ
  62. case PICA_REG_INDEX(trigger_irq):
  63. Service::GSP::SignalInterrupt(Service::GSP::InterruptId::P3D);
  64. break;
  65. case PICA_REG_INDEX(pipeline.triangle_topology):
  66. g_state.primitive_assembler.Reconfigure(regs.pipeline.triangle_topology);
  67. break;
  68. case PICA_REG_INDEX(pipeline.restart_primitive):
  69. g_state.primitive_assembler.Reset();
  70. break;
  71. case PICA_REG_INDEX(pipeline.vs_default_attributes_setup.index):
  72. g_state.immediate.current_attribute = 0;
  73. default_attr_counter = 0;
  74. break;
  75. // Load default vertex input attributes
  76. case PICA_REG_INDEX_WORKAROUND(pipeline.vs_default_attributes_setup.set_value[0], 0x233):
  77. case PICA_REG_INDEX_WORKAROUND(pipeline.vs_default_attributes_setup.set_value[1], 0x234):
  78. case PICA_REG_INDEX_WORKAROUND(pipeline.vs_default_attributes_setup.set_value[2], 0x235): {
  79. // TODO: Does actual hardware indeed keep an intermediate buffer or does
  80. // it directly write the values?
  81. default_attr_write_buffer[default_attr_counter++] = value;
  82. // Default attributes are written in a packed format such that four float24 values are
  83. // encoded in
  84. // three 32-bit numbers. We write to internal memory once a full such vector is
  85. // written.
  86. if (default_attr_counter >= 3) {
  87. default_attr_counter = 0;
  88. auto& setup = regs.pipeline.vs_default_attributes_setup;
  89. if (setup.index >= 16) {
  90. LOG_ERROR(HW_GPU, "Invalid VS default attribute index %d", (int)setup.index);
  91. break;
  92. }
  93. Math::Vec4<float24> attribute;
  94. // NOTE: The destination component order indeed is "backwards"
  95. attribute.w = float24::FromRaw(default_attr_write_buffer[0] >> 8);
  96. attribute.z = float24::FromRaw(((default_attr_write_buffer[0] & 0xFF) << 16) |
  97. ((default_attr_write_buffer[1] >> 16) & 0xFFFF));
  98. attribute.y = float24::FromRaw(((default_attr_write_buffer[1] & 0xFFFF) << 8) |
  99. ((default_attr_write_buffer[2] >> 24) & 0xFF));
  100. attribute.x = float24::FromRaw(default_attr_write_buffer[2] & 0xFFFFFF);
  101. LOG_TRACE(HW_GPU, "Set default VS attribute %x to (%f %f %f %f)", (int)setup.index,
  102. attribute.x.ToFloat32(), attribute.y.ToFloat32(), attribute.z.ToFloat32(),
  103. attribute.w.ToFloat32());
  104. // TODO: Verify that this actually modifies the register!
  105. if (setup.index < 15) {
  106. g_state.input_default_attributes.attr[setup.index] = attribute;
  107. setup.index++;
  108. } else {
  109. // Put each attribute into an immediate input buffer. When all specified immediate
  110. // attributes are present, the Vertex Shader is invoked and everything is sent to
  111. // the primitive assembler.
  112. auto& immediate_input = g_state.immediate.input_vertex;
  113. auto& immediate_attribute_id = g_state.immediate.current_attribute;
  114. immediate_input.attr[immediate_attribute_id] = attribute;
  115. if (immediate_attribute_id < regs.pipeline.max_input_attrib_index) {
  116. immediate_attribute_id += 1;
  117. } else {
  118. MICROPROFILE_SCOPE(GPU_Drawing);
  119. immediate_attribute_id = 0;
  120. auto* shader_engine = Shader::GetEngine();
  121. shader_engine->SetupBatch(g_state.vs, regs.vs.main_offset);
  122. // Send to vertex shader
  123. if (g_debug_context)
  124. g_debug_context->OnEvent(DebugContext::Event::VertexShaderInvocation,
  125. static_cast<void*>(&immediate_input));
  126. Shader::UnitState shader_unit;
  127. Shader::AttributeBuffer output{};
  128. shader_unit.LoadInput(regs.vs, immediate_input);
  129. shader_engine->Run(g_state.vs, shader_unit);
  130. shader_unit.WriteOutput(regs.vs, output);
  131. // Send to renderer
  132. using Pica::Shader::OutputVertex;
  133. auto AddTriangle = [](const OutputVertex& v0, const OutputVertex& v1,
  134. const OutputVertex& v2) {
  135. VideoCore::g_renderer->Rasterizer()->AddTriangle(v0, v1, v2);
  136. };
  137. g_state.primitive_assembler.SubmitVertex(
  138. Shader::OutputVertex::FromAttributeBuffer(regs.rasterizer, output),
  139. AddTriangle);
  140. }
  141. }
  142. }
  143. break;
  144. }
  145. case PICA_REG_INDEX(pipeline.gpu_mode):
  146. if (regs.pipeline.gpu_mode == PipelineRegs::GPUMode::Configuring) {
  147. MICROPROFILE_SCOPE(GPU_Drawing);
  148. // Draw immediate mode triangles when GPU Mode is set to GPUMode::Configuring
  149. VideoCore::g_renderer->Rasterizer()->DrawTriangles();
  150. if (g_debug_context) {
  151. g_debug_context->OnEvent(DebugContext::Event::FinishedPrimitiveBatch, nullptr);
  152. }
  153. }
  154. break;
  155. case PICA_REG_INDEX_WORKAROUND(pipeline.command_buffer.trigger[0], 0x23c):
  156. case PICA_REG_INDEX_WORKAROUND(pipeline.command_buffer.trigger[1], 0x23d): {
  157. unsigned index =
  158. static_cast<unsigned>(id - PICA_REG_INDEX(pipeline.command_buffer.trigger[0]));
  159. u32* head_ptr = (u32*)Memory::GetPhysicalPointer(
  160. regs.pipeline.command_buffer.GetPhysicalAddress(index));
  161. g_state.cmd_list.head_ptr = g_state.cmd_list.current_ptr = head_ptr;
  162. g_state.cmd_list.length = regs.pipeline.command_buffer.GetSize(index) / sizeof(u32);
  163. break;
  164. }
  165. // It seems like these trigger vertex rendering
  166. case PICA_REG_INDEX(pipeline.trigger_draw):
  167. case PICA_REG_INDEX(pipeline.trigger_draw_indexed): {
  168. MICROPROFILE_SCOPE(GPU_Drawing);
  169. #if PICA_LOG_TEV
  170. DebugUtils::DumpTevStageConfig(regs.GetTevStages());
  171. #endif
  172. if (g_debug_context)
  173. g_debug_context->OnEvent(DebugContext::Event::IncomingPrimitiveBatch, nullptr);
  174. // Processes information about internal vertex attributes to figure out how a vertex is
  175. // loaded.
  176. // Later, these can be compiled and cached.
  177. const u32 base_address = regs.pipeline.vertex_attributes.GetPhysicalBaseAddress();
  178. VertexLoader loader(regs.pipeline);
  179. // Load vertices
  180. bool is_indexed = (id == PICA_REG_INDEX(pipeline.trigger_draw_indexed));
  181. const auto& index_info = regs.pipeline.index_array;
  182. const u8* index_address_8 = Memory::GetPhysicalPointer(base_address + index_info.offset);
  183. const u16* index_address_16 = reinterpret_cast<const u16*>(index_address_8);
  184. bool index_u16 = index_info.format != 0;
  185. PrimitiveAssembler<Shader::OutputVertex>& primitive_assembler = g_state.primitive_assembler;
  186. if (g_debug_context && g_debug_context->recorder) {
  187. for (int i = 0; i < 3; ++i) {
  188. const auto texture = regs.texturing.GetTextures()[i];
  189. if (!texture.enabled)
  190. continue;
  191. u8* texture_data = Memory::GetPhysicalPointer(texture.config.GetPhysicalAddress());
  192. g_debug_context->recorder->MemoryAccessed(
  193. texture_data, Pica::TexturingRegs::NibblesPerPixel(texture.format) *
  194. texture.config.width / 2 * texture.config.height,
  195. texture.config.GetPhysicalAddress());
  196. }
  197. }
  198. DebugUtils::MemoryAccessTracker memory_accesses;
  199. // Simple circular-replacement vertex cache
  200. // The size has been tuned for optimal balance between hit-rate and the cost of lookup
  201. const size_t VERTEX_CACHE_SIZE = 32;
  202. std::array<u16, VERTEX_CACHE_SIZE> vertex_cache_ids;
  203. std::array<Shader::OutputVertex, VERTEX_CACHE_SIZE> vertex_cache;
  204. Shader::OutputVertex output_vertex;
  205. unsigned int vertex_cache_pos = 0;
  206. vertex_cache_ids.fill(-1);
  207. auto* shader_engine = Shader::GetEngine();
  208. Shader::UnitState shader_unit;
  209. shader_engine->SetupBatch(g_state.vs, regs.vs.main_offset);
  210. for (unsigned int index = 0; index < regs.pipeline.num_vertices; ++index) {
  211. // Indexed rendering doesn't use the start offset
  212. unsigned int vertex =
  213. is_indexed ? (index_u16 ? index_address_16[index] : index_address_8[index])
  214. : (index + regs.pipeline.vertex_offset);
  215. // -1 is a common special value used for primitive restart. Since it's unknown if
  216. // the PICA supports it, and it would mess up the caching, guard against it here.
  217. ASSERT(vertex != -1);
  218. bool vertex_cache_hit = false;
  219. if (is_indexed) {
  220. if (g_debug_context && Pica::g_debug_context->recorder) {
  221. int size = index_u16 ? 2 : 1;
  222. memory_accesses.AddAccess(base_address + index_info.offset + size * index,
  223. size);
  224. }
  225. for (unsigned int i = 0; i < VERTEX_CACHE_SIZE; ++i) {
  226. if (vertex == vertex_cache_ids[i]) {
  227. output_vertex = vertex_cache[i];
  228. vertex_cache_hit = true;
  229. break;
  230. }
  231. }
  232. }
  233. if (!vertex_cache_hit) {
  234. // Initialize data for the current vertex
  235. Shader::AttributeBuffer input, output{};
  236. loader.LoadVertex(base_address, index, vertex, input, memory_accesses);
  237. // Send to vertex shader
  238. if (g_debug_context)
  239. g_debug_context->OnEvent(DebugContext::Event::VertexShaderInvocation,
  240. (void*)&input);
  241. shader_unit.LoadInput(regs.vs, input);
  242. shader_engine->Run(g_state.vs, shader_unit);
  243. shader_unit.WriteOutput(regs.vs, output);
  244. // Retrieve vertex from register data
  245. output_vertex = Shader::OutputVertex::FromAttributeBuffer(regs.rasterizer, output);
  246. if (is_indexed) {
  247. vertex_cache[vertex_cache_pos] = output_vertex;
  248. vertex_cache_ids[vertex_cache_pos] = vertex;
  249. vertex_cache_pos = (vertex_cache_pos + 1) % VERTEX_CACHE_SIZE;
  250. }
  251. }
  252. // Send to renderer
  253. using Pica::Shader::OutputVertex;
  254. auto AddTriangle = [](const OutputVertex& v0, const OutputVertex& v1,
  255. const OutputVertex& v2) {
  256. VideoCore::g_renderer->Rasterizer()->AddTriangle(v0, v1, v2);
  257. };
  258. primitive_assembler.SubmitVertex(output_vertex, AddTriangle);
  259. }
  260. for (auto& range : memory_accesses.ranges) {
  261. g_debug_context->recorder->MemoryAccessed(Memory::GetPhysicalPointer(range.first),
  262. range.second, range.first);
  263. }
  264. break;
  265. }
  266. case PICA_REG_INDEX(vs.bool_uniforms):
  267. for (unsigned i = 0; i < 16; ++i)
  268. g_state.vs.uniforms.b[i] = (regs.vs.bool_uniforms.Value() & (1 << i)) != 0;
  269. break;
  270. case PICA_REG_INDEX_WORKAROUND(vs.int_uniforms[0], 0x2b1):
  271. case PICA_REG_INDEX_WORKAROUND(vs.int_uniforms[1], 0x2b2):
  272. case PICA_REG_INDEX_WORKAROUND(vs.int_uniforms[2], 0x2b3):
  273. case PICA_REG_INDEX_WORKAROUND(vs.int_uniforms[3], 0x2b4): {
  274. int index = (id - PICA_REG_INDEX_WORKAROUND(vs.int_uniforms[0], 0x2b1));
  275. auto values = regs.vs.int_uniforms[index];
  276. g_state.vs.uniforms.i[index] = Math::Vec4<u8>(values.x, values.y, values.z, values.w);
  277. LOG_TRACE(HW_GPU, "Set integer uniform %d to %02x %02x %02x %02x", index, values.x.Value(),
  278. values.y.Value(), values.z.Value(), values.w.Value());
  279. break;
  280. }
  281. case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[0], 0x2c1):
  282. case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[1], 0x2c2):
  283. case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[2], 0x2c3):
  284. case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[3], 0x2c4):
  285. case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[4], 0x2c5):
  286. case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[5], 0x2c6):
  287. case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[6], 0x2c7):
  288. case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[7], 0x2c8): {
  289. auto& uniform_setup = regs.vs.uniform_setup;
  290. // TODO: Does actual hardware indeed keep an intermediate buffer or does
  291. // it directly write the values?
  292. uniform_write_buffer[float_regs_counter++] = value;
  293. // Uniforms are written in a packed format such that four float24 values are encoded in
  294. // three 32-bit numbers. We write to internal memory once a full such vector is
  295. // written.
  296. if ((float_regs_counter >= 4 && uniform_setup.IsFloat32()) ||
  297. (float_regs_counter >= 3 && !uniform_setup.IsFloat32())) {
  298. float_regs_counter = 0;
  299. auto& uniform = g_state.vs.uniforms.f[uniform_setup.index];
  300. if (uniform_setup.index > 95) {
  301. LOG_ERROR(HW_GPU, "Invalid VS uniform index %d", (int)uniform_setup.index);
  302. break;
  303. }
  304. // NOTE: The destination component order indeed is "backwards"
  305. if (uniform_setup.IsFloat32()) {
  306. for (auto i : {0, 1, 2, 3})
  307. uniform[3 - i] = float24::FromFloat32(*(float*)(&uniform_write_buffer[i]));
  308. } else {
  309. // TODO: Untested
  310. uniform.w = float24::FromRaw(uniform_write_buffer[0] >> 8);
  311. uniform.z = float24::FromRaw(((uniform_write_buffer[0] & 0xFF) << 16) |
  312. ((uniform_write_buffer[1] >> 16) & 0xFFFF));
  313. uniform.y = float24::FromRaw(((uniform_write_buffer[1] & 0xFFFF) << 8) |
  314. ((uniform_write_buffer[2] >> 24) & 0xFF));
  315. uniform.x = float24::FromRaw(uniform_write_buffer[2] & 0xFFFFFF);
  316. }
  317. LOG_TRACE(HW_GPU, "Set uniform %x to (%f %f %f %f)", (int)uniform_setup.index,
  318. uniform.x.ToFloat32(), uniform.y.ToFloat32(), uniform.z.ToFloat32(),
  319. uniform.w.ToFloat32());
  320. // TODO: Verify that this actually modifies the register!
  321. uniform_setup.index.Assign(uniform_setup.index + 1);
  322. }
  323. break;
  324. }
  325. // Load shader program code
  326. case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[0], 0x2cc):
  327. case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[1], 0x2cd):
  328. case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[2], 0x2ce):
  329. case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[3], 0x2cf):
  330. case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[4], 0x2d0):
  331. case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[5], 0x2d1):
  332. case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[6], 0x2d2):
  333. case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[7], 0x2d3): {
  334. g_state.vs.program_code[regs.vs.program.offset] = value;
  335. regs.vs.program.offset++;
  336. break;
  337. }
  338. // Load swizzle pattern data
  339. case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[0], 0x2d6):
  340. case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[1], 0x2d7):
  341. case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[2], 0x2d8):
  342. case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[3], 0x2d9):
  343. case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[4], 0x2da):
  344. case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[5], 0x2db):
  345. case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[6], 0x2dc):
  346. case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[7], 0x2dd): {
  347. g_state.vs.swizzle_data[regs.vs.swizzle_patterns.offset] = value;
  348. regs.vs.swizzle_patterns.offset++;
  349. break;
  350. }
  351. case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[0], 0x1c8):
  352. case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[1], 0x1c9):
  353. case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[2], 0x1ca):
  354. case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[3], 0x1cb):
  355. case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[4], 0x1cc):
  356. case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[5], 0x1cd):
  357. case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[6], 0x1ce):
  358. case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[7], 0x1cf): {
  359. auto& lut_config = regs.lighting.lut_config;
  360. ASSERT_MSG(lut_config.index < 256, "lut_config.index exceeded maximum value of 255!");
  361. g_state.lighting.luts[lut_config.type][lut_config.index].raw = value;
  362. lut_config.index.Assign(lut_config.index + 1);
  363. break;
  364. }
  365. case PICA_REG_INDEX_WORKAROUND(texturing.fog_lut_data[0], 0xe8):
  366. case PICA_REG_INDEX_WORKAROUND(texturing.fog_lut_data[1], 0xe9):
  367. case PICA_REG_INDEX_WORKAROUND(texturing.fog_lut_data[2], 0xea):
  368. case PICA_REG_INDEX_WORKAROUND(texturing.fog_lut_data[3], 0xeb):
  369. case PICA_REG_INDEX_WORKAROUND(texturing.fog_lut_data[4], 0xec):
  370. case PICA_REG_INDEX_WORKAROUND(texturing.fog_lut_data[5], 0xed):
  371. case PICA_REG_INDEX_WORKAROUND(texturing.fog_lut_data[6], 0xee):
  372. case PICA_REG_INDEX_WORKAROUND(texturing.fog_lut_data[7], 0xef): {
  373. g_state.fog.lut[regs.texturing.fog_lut_offset % 128].raw = value;
  374. regs.texturing.fog_lut_offset.Assign(regs.texturing.fog_lut_offset + 1);
  375. break;
  376. }
  377. default:
  378. break;
  379. }
  380. VideoCore::g_renderer->Rasterizer()->NotifyPicaRegisterChanged(id);
  381. if (g_debug_context)
  382. g_debug_context->OnEvent(DebugContext::Event::PicaCommandProcessed,
  383. reinterpret_cast<void*>(&id));
  384. }
  385. void ProcessCommandList(const u32* list, u32 size) {
  386. g_state.cmd_list.head_ptr = g_state.cmd_list.current_ptr = list;
  387. g_state.cmd_list.length = size / sizeof(u32);
  388. while (g_state.cmd_list.current_ptr < g_state.cmd_list.head_ptr + g_state.cmd_list.length) {
  389. // Align read pointer to 8 bytes
  390. if ((g_state.cmd_list.head_ptr - g_state.cmd_list.current_ptr) % 2 != 0)
  391. ++g_state.cmd_list.current_ptr;
  392. u32 value = *g_state.cmd_list.current_ptr++;
  393. const CommandHeader header = {*g_state.cmd_list.current_ptr++};
  394. WritePicaReg(header.cmd_id, value, header.parameter_mask);
  395. for (unsigned i = 0; i < header.extra_data_length; ++i) {
  396. u32 cmd = header.cmd_id + (header.group_commands ? i + 1 : 0);
  397. WritePicaReg(cmd, *g_state.cmd_list.current_ptr++, header.parameter_mask);
  398. }
  399. }
  400. }
  401. } // namespace
  402. } // namespace