command_processor.cpp 24 KB

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