command_processor.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <boost/range/algorithm/fill.hpp>
  5. #include "common/profiler.h"
  6. #include "core/hle/service/gsp_gpu.h"
  7. #include "core/hw/gpu.h"
  8. #include "core/settings.h"
  9. #include "debug_utils/debug_utils.h"
  10. #include "clipper.h"
  11. #include "command_processor.h"
  12. #include "math.h"
  13. #include "pica.h"
  14. #include "primitive_assembly.h"
  15. #include "renderer_base.h"
  16. #include "shader/shader_interpreter.h"
  17. #include "video_core.h"
  18. namespace Pica {
  19. namespace CommandProcessor {
  20. static int float_regs_counter = 0;
  21. static u32 uniform_write_buffer[4];
  22. static int default_attr_counter = 0;
  23. static u32 default_attr_write_buffer[3];
  24. Common::Profiling::TimingCategory category_drawing("Drawing");
  25. // Expand a 4-bit mask to 4-byte mask, e.g. 0b0101 -> 0x00FF00FF
  26. static const u32 expand_bits_to_bytes[] = {
  27. 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
  28. 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
  29. 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
  30. 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
  31. };
  32. static void WritePicaReg(u32 id, u32 value, u32 mask) {
  33. auto& regs = g_state.regs;
  34. if (id >= regs.NumIds())
  35. return;
  36. // If we're skipping this frame, only allow trigger IRQ
  37. if (GPU::g_skip_frame && id != PICA_REG_INDEX(trigger_irq))
  38. return;
  39. // TODO: Figure out how register masking acts on e.g. vs.uniform_setup.set_value
  40. u32 old_value = regs[id];
  41. const u32 write_mask = expand_bits_to_bytes[mask];
  42. regs[id] = (old_value & ~write_mask) | (value & write_mask);
  43. DebugUtils::OnPicaRegWrite({ (u16)id, (u16)mask, regs[id] });
  44. if (g_debug_context)
  45. g_debug_context->OnEvent(DebugContext::Event::PicaCommandLoaded, reinterpret_cast<void*>(&id));
  46. switch(id) {
  47. // Trigger IRQ
  48. case PICA_REG_INDEX(trigger_irq):
  49. GSP_GPU::SignalInterrupt(GSP_GPU::InterruptId::P3D);
  50. break;
  51. // Load default vertex input attributes
  52. case PICA_REG_INDEX_WORKAROUND(vs_default_attributes_setup.set_value[0], 0x233):
  53. case PICA_REG_INDEX_WORKAROUND(vs_default_attributes_setup.set_value[1], 0x234):
  54. case PICA_REG_INDEX_WORKAROUND(vs_default_attributes_setup.set_value[2], 0x235):
  55. {
  56. // TODO: Does actual hardware indeed keep an intermediate buffer or does
  57. // it directly write the values?
  58. default_attr_write_buffer[default_attr_counter++] = value;
  59. // Default attributes are written in a packed format such that four float24 values are encoded in
  60. // three 32-bit numbers. We write to internal memory once a full such vector is
  61. // written.
  62. if (default_attr_counter >= 3) {
  63. default_attr_counter = 0;
  64. auto& setup = regs.vs_default_attributes_setup;
  65. if (setup.index >= 16) {
  66. LOG_ERROR(HW_GPU, "Invalid VS default attribute index %d", (int)setup.index);
  67. break;
  68. }
  69. Math::Vec4<float24>& attribute = g_state.vs.default_attributes[setup.index];
  70. // NOTE: The destination component order indeed is "backwards"
  71. attribute.w = float24::FromRawFloat24(default_attr_write_buffer[0] >> 8);
  72. attribute.z = float24::FromRawFloat24(((default_attr_write_buffer[0] & 0xFF) << 16) | ((default_attr_write_buffer[1] >> 16) & 0xFFFF));
  73. attribute.y = float24::FromRawFloat24(((default_attr_write_buffer[1] & 0xFFFF) << 8) | ((default_attr_write_buffer[2] >> 24) & 0xFF));
  74. attribute.x = float24::FromRawFloat24(default_attr_write_buffer[2] & 0xFFFFFF);
  75. LOG_TRACE(HW_GPU, "Set default VS attribute %x to (%f %f %f %f)", (int)setup.index,
  76. attribute.x.ToFloat32(), attribute.y.ToFloat32(), attribute.z.ToFloat32(),
  77. attribute.w.ToFloat32());
  78. // TODO: Verify that this actually modifies the register!
  79. setup.index = setup.index + 1;
  80. }
  81. break;
  82. }
  83. case PICA_REG_INDEX_WORKAROUND(command_buffer.trigger[0], 0x23c):
  84. case PICA_REG_INDEX_WORKAROUND(command_buffer.trigger[1], 0x23d):
  85. {
  86. unsigned index = static_cast<unsigned>(id - PICA_REG_INDEX(command_buffer.trigger[0]));
  87. u32* head_ptr = (u32*)Memory::GetPhysicalPointer(regs.command_buffer.GetPhysicalAddress(index));
  88. g_state.cmd_list.head_ptr = g_state.cmd_list.current_ptr = head_ptr;
  89. g_state.cmd_list.length = regs.command_buffer.GetSize(index) / sizeof(u32);
  90. break;
  91. }
  92. // It seems like these trigger vertex rendering
  93. case PICA_REG_INDEX(trigger_draw):
  94. case PICA_REG_INDEX(trigger_draw_indexed):
  95. {
  96. Common::Profiling::ScopeTimer scope_timer(category_drawing);
  97. #if PICA_LOG_TEV
  98. DebugUtils::DumpTevStageConfig(regs.GetTevStages());
  99. #endif
  100. if (g_debug_context)
  101. g_debug_context->OnEvent(DebugContext::Event::IncomingPrimitiveBatch, nullptr);
  102. const auto& attribute_config = regs.vertex_attributes;
  103. const u32 base_address = attribute_config.GetPhysicalBaseAddress();
  104. // Information about internal vertex attributes
  105. u32 vertex_attribute_sources[16];
  106. boost::fill(vertex_attribute_sources, 0xdeadbeef);
  107. u32 vertex_attribute_strides[16] = {};
  108. Regs::VertexAttributeFormat vertex_attribute_formats[16] = {};
  109. u32 vertex_attribute_elements[16] = {};
  110. u32 vertex_attribute_element_size[16] = {};
  111. // Setup attribute data from loaders
  112. for (int loader = 0; loader < 12; ++loader) {
  113. const auto& loader_config = attribute_config.attribute_loaders[loader];
  114. u32 load_address = base_address + loader_config.data_offset;
  115. // TODO: What happens if a loader overwrites a previous one's data?
  116. for (unsigned component = 0; component < loader_config.component_count; ++component) {
  117. u32 attribute_index = loader_config.GetComponent(component);
  118. vertex_attribute_sources[attribute_index] = load_address;
  119. vertex_attribute_strides[attribute_index] = static_cast<u32>(loader_config.byte_count);
  120. vertex_attribute_formats[attribute_index] = attribute_config.GetFormat(attribute_index);
  121. vertex_attribute_elements[attribute_index] = attribute_config.GetNumElements(attribute_index);
  122. vertex_attribute_element_size[attribute_index] = attribute_config.GetElementSizeInBytes(attribute_index);
  123. load_address += attribute_config.GetStride(attribute_index);
  124. }
  125. }
  126. // Load vertices
  127. bool is_indexed = (id == PICA_REG_INDEX(trigger_draw_indexed));
  128. const auto& index_info = regs.index_array;
  129. const u8* index_address_8 = Memory::GetPhysicalPointer(base_address + index_info.offset);
  130. const u16* index_address_16 = (u16*)index_address_8;
  131. bool index_u16 = index_info.format != 0;
  132. #if PICA_DUMP_GEOMETRY
  133. DebugUtils::GeometryDumper geometry_dumper;
  134. PrimitiveAssembler<DebugUtils::GeometryDumper::Vertex> dumping_primitive_assembler(regs.triangle_topology.Value());
  135. #endif
  136. PrimitiveAssembler<Shader::OutputVertex> primitive_assembler(regs.triangle_topology.Value());
  137. if (g_debug_context) {
  138. for (int i = 0; i < 3; ++i) {
  139. const auto texture = regs.GetTextures()[i];
  140. if (!texture.enabled)
  141. continue;
  142. u8* texture_data = Memory::GetPhysicalPointer(texture.config.GetPhysicalAddress());
  143. if (g_debug_context && Pica::g_debug_context->recorder)
  144. g_debug_context->recorder->MemoryAccessed(texture_data, Pica::Regs::NibblesPerPixel(texture.format) * texture.config.width / 2 * texture.config.height, texture.config.GetPhysicalAddress());
  145. }
  146. }
  147. class {
  148. /// Combine overlapping and close ranges
  149. void SimplifyRanges() {
  150. for (auto it = ranges.begin(); it != ranges.end(); ++it) {
  151. // NOTE: We add 32 to the range end address to make sure "close" ranges are combined, too
  152. auto it2 = std::next(it);
  153. while (it2 != ranges.end() && it->first + it->second + 32 >= it2->first) {
  154. it->second = std::max(it->second, it2->first + it2->second - it->first);
  155. it2 = ranges.erase(it2);
  156. }
  157. }
  158. }
  159. public:
  160. /// Record a particular memory access in the list
  161. void AddAccess(u32 paddr, u32 size) {
  162. // Create new range or extend existing one
  163. ranges[paddr] = std::max(ranges[paddr], size);
  164. // Simplify ranges...
  165. SimplifyRanges();
  166. }
  167. /// Map of accessed ranges (mapping start address to range size)
  168. std::map<u32, u32> ranges;
  169. } memory_accesses;
  170. // Simple circular-replacement vertex cache
  171. // The size has been tuned for optimal balance between hit-rate and the cost of lookup
  172. const size_t VERTEX_CACHE_SIZE = 32;
  173. std::array<u16, VERTEX_CACHE_SIZE> vertex_cache_ids;
  174. std::array<Shader::OutputVertex, VERTEX_CACHE_SIZE> vertex_cache;
  175. unsigned int vertex_cache_pos = 0;
  176. vertex_cache_ids.fill(-1);
  177. Shader::UnitState<false> shader_unit;
  178. Shader::Setup(shader_unit);
  179. for (unsigned int index = 0; index < regs.num_vertices; ++index)
  180. {
  181. unsigned int vertex = is_indexed ? (index_u16 ? index_address_16[index] : index_address_8[index]) : index;
  182. // -1 is a common special value used for primitive restart. Since it's unknown if
  183. // the PICA supports it, and it would mess up the caching, guard against it here.
  184. ASSERT(vertex != -1);
  185. bool vertex_cache_hit = false;
  186. Shader::OutputVertex output;
  187. if (is_indexed) {
  188. if (g_debug_context && Pica::g_debug_context->recorder) {
  189. int size = index_u16 ? 2 : 1;
  190. memory_accesses.AddAccess(base_address + index_info.offset + size * index, size);
  191. }
  192. for (unsigned int i = 0; i < VERTEX_CACHE_SIZE; ++i) {
  193. if (vertex == vertex_cache_ids[i]) {
  194. output = vertex_cache[i];
  195. vertex_cache_hit = true;
  196. break;
  197. }
  198. }
  199. }
  200. if (!vertex_cache_hit) {
  201. // Initialize data for the current vertex
  202. Shader::InputVertex input;
  203. for (int i = 0; i < attribute_config.GetNumTotalAttributes(); ++i) {
  204. if (vertex_attribute_elements[i] != 0) {
  205. // Default attribute values set if array elements have < 4 components. This
  206. // is *not* carried over from the default attribute settings even if they're
  207. // enabled for this attribute.
  208. static const float24 zero = float24::FromFloat32(0.0f);
  209. static const float24 one = float24::FromFloat32(1.0f);
  210. input.attr[i] = Math::Vec4<float24>(zero, zero, zero, one);
  211. // Load per-vertex data from the loader arrays
  212. for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) {
  213. u32 source_addr = vertex_attribute_sources[i] + vertex_attribute_strides[i] * vertex + comp * vertex_attribute_element_size[i];
  214. const u8* srcdata = Memory::GetPhysicalPointer(source_addr);
  215. if (g_debug_context && Pica::g_debug_context->recorder) {
  216. memory_accesses.AddAccess(source_addr,
  217. (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::FLOAT) ? 4
  218. : (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::SHORT) ? 2 : 1);
  219. }
  220. const float srcval = (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::BYTE) ? *(s8*)srcdata :
  221. (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::UBYTE) ? *(u8*)srcdata :
  222. (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::SHORT) ? *(s16*)srcdata :
  223. *(float*)srcdata;
  224. input.attr[i][comp] = float24::FromFloat32(srcval);
  225. LOG_TRACE(HW_GPU, "Loaded component %x of attribute %x for vertex %x (index %x) from 0x%08x + 0x%08lx + 0x%04lx: %f",
  226. comp, i, vertex, index,
  227. attribute_config.GetPhysicalBaseAddress(),
  228. vertex_attribute_sources[i] - base_address,
  229. vertex_attribute_strides[i] * vertex + comp * vertex_attribute_element_size[i],
  230. input.attr[i][comp].ToFloat32());
  231. }
  232. } else if (attribute_config.IsDefaultAttribute(i)) {
  233. // Load the default attribute if we're configured to do so
  234. input.attr[i] = g_state.vs.default_attributes[i];
  235. LOG_TRACE(HW_GPU, "Loaded default attribute %x for vertex %x (index %x): (%f, %f, %f, %f)",
  236. i, vertex, index,
  237. input.attr[i][0].ToFloat32(), input.attr[i][1].ToFloat32(),
  238. input.attr[i][2].ToFloat32(), input.attr[i][3].ToFloat32());
  239. } else {
  240. // TODO(yuriks): In this case, no data gets loaded and the vertex
  241. // remains with the last value it had. This isn't currently maintained
  242. // as global state, however, and so won't work in Citra yet.
  243. }
  244. }
  245. if (g_debug_context)
  246. g_debug_context->OnEvent(DebugContext::Event::VertexLoaded, (void*)&input);
  247. #if PICA_DUMP_GEOMETRY
  248. // NOTE: When dumping geometry, we simply assume that the first input attribute
  249. // corresponds to the position for now.
  250. DebugUtils::GeometryDumper::Vertex dumped_vertex = {
  251. input.attr[0][0].ToFloat32(), input.attr[0][1].ToFloat32(), input.attr[0][2].ToFloat32()
  252. };
  253. using namespace std::placeholders;
  254. dumping_primitive_assembler.SubmitVertex(dumped_vertex,
  255. std::bind(&DebugUtils::GeometryDumper::AddTriangle,
  256. &geometry_dumper, _1, _2, _3));
  257. #endif
  258. // Send to vertex shader
  259. output = Shader::Run(shader_unit, input, attribute_config.GetNumTotalAttributes());
  260. if (is_indexed) {
  261. vertex_cache[vertex_cache_pos] = output;
  262. vertex_cache_ids[vertex_cache_pos] = vertex;
  263. vertex_cache_pos = (vertex_cache_pos + 1) % VERTEX_CACHE_SIZE;
  264. }
  265. }
  266. if (Settings::values.use_hw_renderer) {
  267. // Send to hardware renderer
  268. static auto AddHWTriangle = [](const Pica::Shader::OutputVertex& v0,
  269. const Pica::Shader::OutputVertex& v1,
  270. const Pica::Shader::OutputVertex& v2) {
  271. VideoCore::g_renderer->hw_rasterizer->AddTriangle(v0, v1, v2);
  272. };
  273. primitive_assembler.SubmitVertex(output, AddHWTriangle);
  274. } else {
  275. // Send to triangle clipper
  276. primitive_assembler.SubmitVertex(output, Clipper::ProcessTriangle);
  277. }
  278. }
  279. for (auto& range : memory_accesses.ranges) {
  280. g_debug_context->recorder->MemoryAccessed(Memory::GetPhysicalPointer(range.first),
  281. range.second, range.first);
  282. }
  283. if (Settings::values.use_hw_renderer) {
  284. VideoCore::g_renderer->hw_rasterizer->DrawTriangles();
  285. }
  286. #if PICA_DUMP_GEOMETRY
  287. geometry_dumper.Dump();
  288. #endif
  289. if (g_debug_context) {
  290. g_debug_context->OnEvent(DebugContext::Event::FinishedPrimitiveBatch, nullptr);
  291. }
  292. break;
  293. }
  294. case PICA_REG_INDEX(vs.bool_uniforms):
  295. for (unsigned i = 0; i < 16; ++i)
  296. g_state.vs.uniforms.b[i] = (regs.vs.bool_uniforms.Value() & (1 << i)) != 0;
  297. break;
  298. case PICA_REG_INDEX_WORKAROUND(vs.int_uniforms[0], 0x2b1):
  299. case PICA_REG_INDEX_WORKAROUND(vs.int_uniforms[1], 0x2b2):
  300. case PICA_REG_INDEX_WORKAROUND(vs.int_uniforms[2], 0x2b3):
  301. case PICA_REG_INDEX_WORKAROUND(vs.int_uniforms[3], 0x2b4):
  302. {
  303. int index = (id - PICA_REG_INDEX_WORKAROUND(vs.int_uniforms[0], 0x2b1));
  304. auto values = regs.vs.int_uniforms[index];
  305. g_state.vs.uniforms.i[index] = Math::Vec4<u8>(values.x, values.y, values.z, values.w);
  306. LOG_TRACE(HW_GPU, "Set integer uniform %d to %02x %02x %02x %02x",
  307. index, values.x.Value(), values.y.Value(), values.z.Value(), values.w.Value());
  308. break;
  309. }
  310. case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[0], 0x2c1):
  311. case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[1], 0x2c2):
  312. case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[2], 0x2c3):
  313. case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[3], 0x2c4):
  314. case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[4], 0x2c5):
  315. case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[5], 0x2c6):
  316. case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[6], 0x2c7):
  317. case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[7], 0x2c8):
  318. {
  319. auto& uniform_setup = regs.vs.uniform_setup;
  320. // TODO: Does actual hardware indeed keep an intermediate buffer or does
  321. // it directly write the values?
  322. uniform_write_buffer[float_regs_counter++] = value;
  323. // Uniforms are written in a packed format such that four float24 values are encoded in
  324. // three 32-bit numbers. We write to internal memory once a full such vector is
  325. // written.
  326. if ((float_regs_counter >= 4 && uniform_setup.IsFloat32()) ||
  327. (float_regs_counter >= 3 && !uniform_setup.IsFloat32())) {
  328. float_regs_counter = 0;
  329. auto& uniform = g_state.vs.uniforms.f[uniform_setup.index];
  330. if (uniform_setup.index > 95) {
  331. LOG_ERROR(HW_GPU, "Invalid VS uniform index %d", (int)uniform_setup.index);
  332. break;
  333. }
  334. // NOTE: The destination component order indeed is "backwards"
  335. if (uniform_setup.IsFloat32()) {
  336. for (auto i : {0,1,2,3})
  337. uniform[3 - i] = float24::FromFloat32(*(float*)(&uniform_write_buffer[i]));
  338. } else {
  339. // TODO: Untested
  340. uniform.w = float24::FromRawFloat24(uniform_write_buffer[0] >> 8);
  341. uniform.z = float24::FromRawFloat24(((uniform_write_buffer[0] & 0xFF)<<16) | ((uniform_write_buffer[1] >> 16) & 0xFFFF));
  342. uniform.y = float24::FromRawFloat24(((uniform_write_buffer[1] & 0xFFFF)<<8) | ((uniform_write_buffer[2] >> 24) & 0xFF));
  343. uniform.x = float24::FromRawFloat24(uniform_write_buffer[2] & 0xFFFFFF);
  344. }
  345. LOG_TRACE(HW_GPU, "Set uniform %x to (%f %f %f %f)", (int)uniform_setup.index,
  346. uniform.x.ToFloat32(), uniform.y.ToFloat32(), uniform.z.ToFloat32(),
  347. uniform.w.ToFloat32());
  348. // TODO: Verify that this actually modifies the register!
  349. uniform_setup.index = uniform_setup.index + 1;
  350. }
  351. break;
  352. }
  353. // Load shader program code
  354. case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[0], 0x2cc):
  355. case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[1], 0x2cd):
  356. case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[2], 0x2ce):
  357. case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[3], 0x2cf):
  358. case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[4], 0x2d0):
  359. case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[5], 0x2d1):
  360. case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[6], 0x2d2):
  361. case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[7], 0x2d3):
  362. {
  363. g_state.vs.program_code[regs.vs.program.offset] = value;
  364. regs.vs.program.offset++;
  365. break;
  366. }
  367. // Load swizzle pattern data
  368. case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[0], 0x2d6):
  369. case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[1], 0x2d7):
  370. case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[2], 0x2d8):
  371. case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[3], 0x2d9):
  372. case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[4], 0x2da):
  373. case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[5], 0x2db):
  374. case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[6], 0x2dc):
  375. case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[7], 0x2dd):
  376. {
  377. g_state.vs.swizzle_data[regs.vs.swizzle_patterns.offset] = value;
  378. regs.vs.swizzle_patterns.offset++;
  379. break;
  380. }
  381. default:
  382. break;
  383. }
  384. VideoCore::g_renderer->hw_rasterizer->NotifyPicaRegisterChanged(id);
  385. if (g_debug_context)
  386. g_debug_context->OnEvent(DebugContext::Event::PicaCommandProcessed, reinterpret_cast<void*>(&id));
  387. }
  388. void ProcessCommandList(const u32* list, u32 size) {
  389. g_state.cmd_list.head_ptr = g_state.cmd_list.current_ptr = list;
  390. g_state.cmd_list.length = size / sizeof(u32);
  391. while (g_state.cmd_list.current_ptr < g_state.cmd_list.head_ptr + g_state.cmd_list.length) {
  392. // Align read pointer to 8 bytes
  393. if ((g_state.cmd_list.head_ptr - g_state.cmd_list.current_ptr) % 2 != 0)
  394. ++g_state.cmd_list.current_ptr;
  395. u32 value = *g_state.cmd_list.current_ptr++;
  396. const CommandHeader header = { *g_state.cmd_list.current_ptr++ };
  397. u32 cmd = header.cmd_id;
  398. WritePicaReg(cmd, value, header.parameter_mask);
  399. for (unsigned i = 0; i < header.extra_data_length; ++i) {
  400. u32 cmd = header.cmd_id + (header.group_commands ? i + 1 : 0);
  401. WritePicaReg(cmd, *g_state.cmd_list.current_ptr++, header.parameter_mask);
  402. }
  403. }
  404. }
  405. } // namespace
  406. } // namespace