command_processor.cpp 21 KB

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