vertex_shader.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <stack>
  5. #include <boost/range/algorithm.hpp>
  6. #include <common/file_util.h>
  7. #include <nihstro/shader_bytecode.h>
  8. #include "common/profiler.h"
  9. #include "pica.h"
  10. #include "vertex_shader.h"
  11. #include "debug_utils/debug_utils.h"
  12. using nihstro::OpCode;
  13. using nihstro::Instruction;
  14. using nihstro::RegisterType;
  15. using nihstro::SourceRegister;
  16. using nihstro::SwizzlePattern;
  17. namespace Pica {
  18. namespace VertexShader {
  19. struct VertexShaderState {
  20. const u32* program_counter;
  21. const float24* input_register_table[16];
  22. Math::Vec4<float24> output_registers[16];
  23. Math::Vec4<float24> temporary_registers[16];
  24. bool conditional_code[2];
  25. // Two Address registers and one loop counter
  26. // TODO: How many bits do these actually have?
  27. s32 address_registers[3];
  28. enum {
  29. INVALID_ADDRESS = 0xFFFFFFFF
  30. };
  31. struct CallStackElement {
  32. u32 final_address; // Address upon which we jump to return_address
  33. u32 return_address; // Where to jump when leaving scope
  34. u8 repeat_counter; // How often to repeat until this call stack element is removed
  35. u8 loop_increment; // Which value to add to the loop counter after an iteration
  36. // TODO: Should this be a signed value? Does it even matter?
  37. u32 loop_address; // The address where we'll return to after each loop iteration
  38. };
  39. // TODO: Is there a maximal size for this?
  40. std::stack<CallStackElement> call_stack;
  41. struct {
  42. u32 max_offset; // maximum program counter ever reached
  43. u32 max_opdesc_id; // maximum swizzle pattern index ever used
  44. } debug;
  45. };
  46. static void ProcessShaderCode(VertexShaderState& state) {
  47. const auto& uniforms = g_state.vs.uniforms;
  48. const auto& swizzle_data = g_state.vs.swizzle_data;
  49. const auto& program_code = g_state.vs.program_code;
  50. // Placeholder for invalid inputs
  51. static float24 dummy_vec4_float24[4];
  52. while (true) {
  53. if (!state.call_stack.empty()) {
  54. auto& top = state.call_stack.top();
  55. if (state.program_counter - program_code.data() == top.final_address) {
  56. state.address_registers[2] += top.loop_increment;
  57. if (top.repeat_counter-- == 0) {
  58. state.program_counter = &program_code[top.return_address];
  59. state.call_stack.pop();
  60. } else {
  61. state.program_counter = &program_code[top.loop_address];
  62. }
  63. // TODO: Is "trying again" accurate to hardware?
  64. continue;
  65. }
  66. }
  67. bool exit_loop = false;
  68. const Instruction& instr = *(const Instruction*)state.program_counter;
  69. const SwizzlePattern& swizzle = *(SwizzlePattern*)&swizzle_data[instr.common.operand_desc_id];
  70. static auto call = [&program_code](VertexShaderState& state, u32 offset, u32 num_instructions,
  71. u32 return_offset, u8 repeat_count, u8 loop_increment) {
  72. state.program_counter = &program_code[offset] - 1; // -1 to make sure when incrementing the PC we end up at the correct offset
  73. state.call_stack.push({ offset + num_instructions, return_offset, repeat_count, loop_increment, offset });
  74. };
  75. u32 binary_offset = state.program_counter - program_code.data();
  76. state.debug.max_offset = std::max<u32>(state.debug.max_offset, 1 + binary_offset);
  77. auto LookupSourceRegister = [&](const SourceRegister& source_reg) -> const float24* {
  78. switch (source_reg.GetRegisterType()) {
  79. case RegisterType::Input:
  80. return state.input_register_table[source_reg.GetIndex()];
  81. case RegisterType::Temporary:
  82. return &state.temporary_registers[source_reg.GetIndex()].x;
  83. case RegisterType::FloatUniform:
  84. return &uniforms.f[source_reg.GetIndex()].x;
  85. default:
  86. return dummy_vec4_float24;
  87. }
  88. };
  89. switch (instr.opcode.Value().GetInfo().type) {
  90. case OpCode::Type::Arithmetic:
  91. {
  92. bool is_inverted = 0 != (instr.opcode.Value().GetInfo().subtype & OpCode::Info::SrcInversed);
  93. // TODO: We don't really support this properly: For instance, the address register
  94. // offset needs to be applied to SRC2 instead, etc.
  95. // For now, we just abort in this situation.
  96. ASSERT_MSG(!is_inverted, "Bad condition...");
  97. const int address_offset = (instr.common.address_register_index == 0)
  98. ? 0 : state.address_registers[instr.common.address_register_index - 1];
  99. const float24* src1_ = LookupSourceRegister(instr.common.GetSrc1(is_inverted) + address_offset);
  100. const float24* src2_ = LookupSourceRegister(instr.common.GetSrc2(is_inverted));
  101. const bool negate_src1 = ((bool)swizzle.negate_src1 != false);
  102. const bool negate_src2 = ((bool)swizzle.negate_src2 != false);
  103. float24 src1[4] = {
  104. src1_[(int)swizzle.GetSelectorSrc1(0)],
  105. src1_[(int)swizzle.GetSelectorSrc1(1)],
  106. src1_[(int)swizzle.GetSelectorSrc1(2)],
  107. src1_[(int)swizzle.GetSelectorSrc1(3)],
  108. };
  109. if (negate_src1) {
  110. src1[0] = src1[0] * float24::FromFloat32(-1);
  111. src1[1] = src1[1] * float24::FromFloat32(-1);
  112. src1[2] = src1[2] * float24::FromFloat32(-1);
  113. src1[3] = src1[3] * float24::FromFloat32(-1);
  114. }
  115. float24 src2[4] = {
  116. src2_[(int)swizzle.GetSelectorSrc2(0)],
  117. src2_[(int)swizzle.GetSelectorSrc2(1)],
  118. src2_[(int)swizzle.GetSelectorSrc2(2)],
  119. src2_[(int)swizzle.GetSelectorSrc2(3)],
  120. };
  121. if (negate_src2) {
  122. src2[0] = src2[0] * float24::FromFloat32(-1);
  123. src2[1] = src2[1] * float24::FromFloat32(-1);
  124. src2[2] = src2[2] * float24::FromFloat32(-1);
  125. src2[3] = src2[3] * float24::FromFloat32(-1);
  126. }
  127. float24* dest = (instr.common.dest.Value() < 0x10) ? &state.output_registers[instr.common.dest.Value().GetIndex()][0]
  128. : (instr.common.dest.Value() < 0x20) ? &state.temporary_registers[instr.common.dest.Value().GetIndex()][0]
  129. : dummy_vec4_float24;
  130. state.debug.max_opdesc_id = std::max<u32>(state.debug.max_opdesc_id, 1+instr.common.operand_desc_id);
  131. switch (instr.opcode.Value().EffectiveOpCode()) {
  132. case OpCode::Id::ADD:
  133. {
  134. for (int i = 0; i < 4; ++i) {
  135. if (!swizzle.DestComponentEnabled(i))
  136. continue;
  137. dest[i] = src1[i] + src2[i];
  138. }
  139. break;
  140. }
  141. case OpCode::Id::MUL:
  142. {
  143. for (int i = 0; i < 4; ++i) {
  144. if (!swizzle.DestComponentEnabled(i))
  145. continue;
  146. dest[i] = src1[i] * src2[i];
  147. }
  148. break;
  149. }
  150. case OpCode::Id::FLR:
  151. for (int i = 0; i < 4; ++i) {
  152. if (!swizzle.DestComponentEnabled(i))
  153. continue;
  154. dest[i] = float24::FromFloat32(std::floor(src1[i].ToFloat32()));
  155. }
  156. break;
  157. case OpCode::Id::MAX:
  158. for (int i = 0; i < 4; ++i) {
  159. if (!swizzle.DestComponentEnabled(i))
  160. continue;
  161. dest[i] = std::max(src1[i], src2[i]);
  162. }
  163. break;
  164. case OpCode::Id::DP3:
  165. case OpCode::Id::DP4:
  166. {
  167. float24 dot = float24::FromFloat32(0.f);
  168. int num_components = (instr.opcode.Value() == OpCode::Id::DP3) ? 3 : 4;
  169. for (int i = 0; i < num_components; ++i)
  170. dot = dot + src1[i] * src2[i];
  171. for (int i = 0; i < num_components; ++i) {
  172. if (!swizzle.DestComponentEnabled(i))
  173. continue;
  174. dest[i] = dot;
  175. }
  176. break;
  177. }
  178. // Reciprocal
  179. case OpCode::Id::RCP:
  180. {
  181. for (int i = 0; i < 4; ++i) {
  182. if (!swizzle.DestComponentEnabled(i))
  183. continue;
  184. // TODO: Be stable against division by zero!
  185. // TODO: I think this might be wrong... we should only use one component here
  186. dest[i] = float24::FromFloat32(1.0f / src1[i].ToFloat32());
  187. }
  188. break;
  189. }
  190. // Reciprocal Square Root
  191. case OpCode::Id::RSQ:
  192. {
  193. for (int i = 0; i < 4; ++i) {
  194. if (!swizzle.DestComponentEnabled(i))
  195. continue;
  196. // TODO: Be stable against division by zero!
  197. // TODO: I think this might be wrong... we should only use one component here
  198. dest[i] = float24::FromFloat32(1.0f / sqrt(src1[i].ToFloat32()));
  199. }
  200. break;
  201. }
  202. case OpCode::Id::MOVA:
  203. {
  204. for (int i = 0; i < 2; ++i) {
  205. if (!swizzle.DestComponentEnabled(i))
  206. continue;
  207. // TODO: Figure out how the rounding is done on hardware
  208. state.address_registers[i] = static_cast<s32>(src1[i].ToFloat32());
  209. }
  210. break;
  211. }
  212. case OpCode::Id::MOV:
  213. {
  214. for (int i = 0; i < 4; ++i) {
  215. if (!swizzle.DestComponentEnabled(i))
  216. continue;
  217. dest[i] = src1[i];
  218. }
  219. break;
  220. }
  221. case OpCode::Id::CMP:
  222. for (int i = 0; i < 2; ++i) {
  223. // TODO: Can you restrict to one compare via dest masking?
  224. auto compare_op = instr.common.compare_op;
  225. auto op = (i == 0) ? compare_op.x.Value() : compare_op.y.Value();
  226. switch (op) {
  227. case compare_op.Equal:
  228. state.conditional_code[i] = (src1[i] == src2[i]);
  229. break;
  230. case compare_op.NotEqual:
  231. state.conditional_code[i] = (src1[i] != src2[i]);
  232. break;
  233. case compare_op.LessThan:
  234. state.conditional_code[i] = (src1[i] < src2[i]);
  235. break;
  236. case compare_op.LessEqual:
  237. state.conditional_code[i] = (src1[i] <= src2[i]);
  238. break;
  239. case compare_op.GreaterThan:
  240. state.conditional_code[i] = (src1[i] > src2[i]);
  241. break;
  242. case compare_op.GreaterEqual:
  243. state.conditional_code[i] = (src1[i] >= src2[i]);
  244. break;
  245. default:
  246. LOG_ERROR(HW_GPU, "Unknown compare mode %x", static_cast<int>(op));
  247. break;
  248. }
  249. }
  250. break;
  251. default:
  252. LOG_ERROR(HW_GPU, "Unhandled arithmetic instruction: 0x%02x (%s): 0x%08x",
  253. (int)instr.opcode.Value().EffectiveOpCode(), instr.opcode.Value().GetInfo().name, instr.hex);
  254. DEBUG_ASSERT(false);
  255. break;
  256. }
  257. break;
  258. }
  259. case OpCode::Type::MultiplyAdd:
  260. {
  261. if ((instr.opcode.Value().EffectiveOpCode() == OpCode::Id::MAD) ||
  262. (instr.opcode.Value().EffectiveOpCode() == OpCode::Id::MADI)) {
  263. const SwizzlePattern& swizzle = *(SwizzlePattern*)&swizzle_data[instr.mad.operand_desc_id];
  264. bool is_inverted = (instr.opcode.Value().EffectiveOpCode() == OpCode::Id::MADI);
  265. const float24* src1_ = LookupSourceRegister(instr.mad.GetSrc1(is_inverted));
  266. const float24* src2_ = LookupSourceRegister(instr.mad.GetSrc2(is_inverted));
  267. const float24* src3_ = LookupSourceRegister(instr.mad.GetSrc3(is_inverted));
  268. const bool negate_src1 = ((bool)swizzle.negate_src1 != false);
  269. const bool negate_src2 = ((bool)swizzle.negate_src2 != false);
  270. const bool negate_src3 = ((bool)swizzle.negate_src3 != false);
  271. float24 src1[4] = {
  272. src1_[(int)swizzle.GetSelectorSrc1(0)],
  273. src1_[(int)swizzle.GetSelectorSrc1(1)],
  274. src1_[(int)swizzle.GetSelectorSrc1(2)],
  275. src1_[(int)swizzle.GetSelectorSrc1(3)],
  276. };
  277. if (negate_src1) {
  278. src1[0] = src1[0] * float24::FromFloat32(-1);
  279. src1[1] = src1[1] * float24::FromFloat32(-1);
  280. src1[2] = src1[2] * float24::FromFloat32(-1);
  281. src1[3] = src1[3] * float24::FromFloat32(-1);
  282. }
  283. float24 src2[4] = {
  284. src2_[(int)swizzle.GetSelectorSrc2(0)],
  285. src2_[(int)swizzle.GetSelectorSrc2(1)],
  286. src2_[(int)swizzle.GetSelectorSrc2(2)],
  287. src2_[(int)swizzle.GetSelectorSrc2(3)],
  288. };
  289. if (negate_src2) {
  290. src2[0] = src2[0] * float24::FromFloat32(-1);
  291. src2[1] = src2[1] * float24::FromFloat32(-1);
  292. src2[2] = src2[2] * float24::FromFloat32(-1);
  293. src2[3] = src2[3] * float24::FromFloat32(-1);
  294. }
  295. float24 src3[4] = {
  296. src3_[(int)swizzle.GetSelectorSrc3(0)],
  297. src3_[(int)swizzle.GetSelectorSrc3(1)],
  298. src3_[(int)swizzle.GetSelectorSrc3(2)],
  299. src3_[(int)swizzle.GetSelectorSrc3(3)],
  300. };
  301. if (negate_src3) {
  302. src3[0] = src3[0] * float24::FromFloat32(-1);
  303. src3[1] = src3[1] * float24::FromFloat32(-1);
  304. src3[2] = src3[2] * float24::FromFloat32(-1);
  305. src3[3] = src3[3] * float24::FromFloat32(-1);
  306. }
  307. float24* dest = (instr.mad.dest.Value() < 0x10) ? &state.output_registers[instr.mad.dest.Value().GetIndex()][0]
  308. : (instr.mad.dest.Value() < 0x20) ? &state.temporary_registers[instr.mad.dest.Value().GetIndex()][0]
  309. : dummy_vec4_float24;
  310. for (int i = 0; i < 4; ++i) {
  311. if (!swizzle.DestComponentEnabled(i))
  312. continue;
  313. dest[i] = src1[i] * src2[i] + src3[i];
  314. }
  315. } else {
  316. LOG_ERROR(HW_GPU, "Unhandled multiply-add instruction: 0x%02x (%s): 0x%08x",
  317. (int)instr.opcode.Value().EffectiveOpCode(), instr.opcode.Value().GetInfo().name, instr.hex);
  318. }
  319. break;
  320. }
  321. default:
  322. {
  323. static auto evaluate_condition = [](const VertexShaderState& state, bool refx, bool refy, Instruction::FlowControlType flow_control) {
  324. bool results[2] = { refx == state.conditional_code[0],
  325. refy == state.conditional_code[1] };
  326. switch (flow_control.op) {
  327. case flow_control.Or:
  328. return results[0] || results[1];
  329. case flow_control.And:
  330. return results[0] && results[1];
  331. case flow_control.JustX:
  332. return results[0];
  333. case flow_control.JustY:
  334. return results[1];
  335. }
  336. };
  337. // Handle each instruction on its own
  338. switch (instr.opcode.Value()) {
  339. case OpCode::Id::END:
  340. exit_loop = true;
  341. break;
  342. case OpCode::Id::JMPC:
  343. if (evaluate_condition(state, instr.flow_control.refx, instr.flow_control.refy, instr.flow_control)) {
  344. state.program_counter = &program_code[instr.flow_control.dest_offset] - 1;
  345. }
  346. break;
  347. case OpCode::Id::JMPU:
  348. if (uniforms.b[instr.flow_control.bool_uniform_id]) {
  349. state.program_counter = &program_code[instr.flow_control.dest_offset] - 1;
  350. }
  351. break;
  352. case OpCode::Id::CALL:
  353. call(state,
  354. instr.flow_control.dest_offset,
  355. instr.flow_control.num_instructions,
  356. binary_offset + 1, 0, 0);
  357. break;
  358. case OpCode::Id::CALLU:
  359. if (uniforms.b[instr.flow_control.bool_uniform_id]) {
  360. call(state,
  361. instr.flow_control.dest_offset,
  362. instr.flow_control.num_instructions,
  363. binary_offset + 1, 0, 0);
  364. }
  365. break;
  366. case OpCode::Id::CALLC:
  367. if (evaluate_condition(state, instr.flow_control.refx, instr.flow_control.refy, instr.flow_control)) {
  368. call(state,
  369. instr.flow_control.dest_offset,
  370. instr.flow_control.num_instructions,
  371. binary_offset + 1, 0, 0);
  372. }
  373. break;
  374. case OpCode::Id::NOP:
  375. break;
  376. case OpCode::Id::IFU:
  377. if (uniforms.b[instr.flow_control.bool_uniform_id]) {
  378. call(state,
  379. binary_offset + 1,
  380. instr.flow_control.dest_offset - binary_offset - 1,
  381. instr.flow_control.dest_offset + instr.flow_control.num_instructions, 0, 0);
  382. } else {
  383. call(state,
  384. instr.flow_control.dest_offset,
  385. instr.flow_control.num_instructions,
  386. instr.flow_control.dest_offset + instr.flow_control.num_instructions, 0, 0);
  387. }
  388. break;
  389. case OpCode::Id::IFC:
  390. {
  391. // TODO: Do we need to consider swizzlers here?
  392. if (evaluate_condition(state, instr.flow_control.refx, instr.flow_control.refy, instr.flow_control)) {
  393. call(state,
  394. binary_offset + 1,
  395. instr.flow_control.dest_offset - binary_offset - 1,
  396. instr.flow_control.dest_offset + instr.flow_control.num_instructions, 0, 0);
  397. } else {
  398. call(state,
  399. instr.flow_control.dest_offset,
  400. instr.flow_control.num_instructions,
  401. instr.flow_control.dest_offset + instr.flow_control.num_instructions, 0, 0);
  402. }
  403. break;
  404. }
  405. case OpCode::Id::LOOP:
  406. {
  407. state.address_registers[2] = uniforms.i[instr.flow_control.int_uniform_id].y;
  408. call(state,
  409. binary_offset + 1,
  410. instr.flow_control.dest_offset - binary_offset + 1,
  411. instr.flow_control.dest_offset + 1,
  412. uniforms.i[instr.flow_control.int_uniform_id].x,
  413. uniforms.i[instr.flow_control.int_uniform_id].z);
  414. break;
  415. }
  416. default:
  417. LOG_ERROR(HW_GPU, "Unhandled instruction: 0x%02x (%s): 0x%08x",
  418. (int)instr.opcode.Value().EffectiveOpCode(), instr.opcode.Value().GetInfo().name, instr.hex);
  419. break;
  420. }
  421. break;
  422. }
  423. }
  424. ++state.program_counter;
  425. if (exit_loop)
  426. break;
  427. }
  428. }
  429. static Common::Profiling::TimingCategory shader_category("Vertex Shader");
  430. OutputVertex RunShader(const InputVertex& input, int num_attributes) {
  431. Common::Profiling::ScopeTimer timer(shader_category);
  432. const auto& regs = g_state.regs;
  433. const auto& vs = g_state.vs;
  434. VertexShaderState state;
  435. const u32* main = &vs.program_code[regs.vs_main_offset];
  436. state.program_counter = (u32*)main;
  437. state.debug.max_offset = 0;
  438. state.debug.max_opdesc_id = 0;
  439. // Setup input register table
  440. const auto& attribute_register_map = regs.vs_input_register_map;
  441. float24 dummy_register;
  442. boost::fill(state.input_register_table, &dummy_register);
  443. if (num_attributes > 0) state.input_register_table[attribute_register_map.attribute0_register] = &input.attr[0].x;
  444. if (num_attributes > 1) state.input_register_table[attribute_register_map.attribute1_register] = &input.attr[1].x;
  445. if (num_attributes > 2) state.input_register_table[attribute_register_map.attribute2_register] = &input.attr[2].x;
  446. if (num_attributes > 3) state.input_register_table[attribute_register_map.attribute3_register] = &input.attr[3].x;
  447. if (num_attributes > 4) state.input_register_table[attribute_register_map.attribute4_register] = &input.attr[4].x;
  448. if (num_attributes > 5) state.input_register_table[attribute_register_map.attribute5_register] = &input.attr[5].x;
  449. if (num_attributes > 6) state.input_register_table[attribute_register_map.attribute6_register] = &input.attr[6].x;
  450. if (num_attributes > 7) state.input_register_table[attribute_register_map.attribute7_register] = &input.attr[7].x;
  451. if (num_attributes > 8) state.input_register_table[attribute_register_map.attribute8_register] = &input.attr[8].x;
  452. if (num_attributes > 9) state.input_register_table[attribute_register_map.attribute9_register] = &input.attr[9].x;
  453. if (num_attributes > 10) state.input_register_table[attribute_register_map.attribute10_register] = &input.attr[10].x;
  454. if (num_attributes > 11) state.input_register_table[attribute_register_map.attribute11_register] = &input.attr[11].x;
  455. if (num_attributes > 12) state.input_register_table[attribute_register_map.attribute12_register] = &input.attr[12].x;
  456. if (num_attributes > 13) state.input_register_table[attribute_register_map.attribute13_register] = &input.attr[13].x;
  457. if (num_attributes > 14) state.input_register_table[attribute_register_map.attribute14_register] = &input.attr[14].x;
  458. if (num_attributes > 15) state.input_register_table[attribute_register_map.attribute15_register] = &input.attr[15].x;
  459. state.conditional_code[0] = false;
  460. state.conditional_code[1] = false;
  461. ProcessShaderCode(state);
  462. DebugUtils::DumpShader(vs.program_code.data(), state.debug.max_offset, vs.swizzle_data.data(),
  463. state.debug.max_opdesc_id, regs.vs_main_offset,
  464. regs.vs_output_attributes);
  465. // Setup output data
  466. OutputVertex ret;
  467. // TODO(neobrain): Under some circumstances, up to 16 attributes may be output. We need to
  468. // figure out what those circumstances are and enable the remaining outputs then.
  469. for (int i = 0; i < 7; ++i) {
  470. const auto& output_register_map = regs.vs_output_attributes[i];
  471. u32 semantics[4] = {
  472. output_register_map.map_x, output_register_map.map_y,
  473. output_register_map.map_z, output_register_map.map_w
  474. };
  475. for (int comp = 0; comp < 4; ++comp) {
  476. float24* out = ((float24*)&ret) + semantics[comp];
  477. if (semantics[comp] != Regs::VSOutputAttributes::INVALID) {
  478. *out = state.output_registers[i][comp];
  479. } else {
  480. // Zero output so that attributes which aren't output won't have denormals in them,
  481. // which would slow us down later.
  482. memset(out, 0, sizeof(*out));
  483. }
  484. }
  485. }
  486. LOG_TRACE(Render_Software, "Output vertex: pos (%.2f, %.2f, %.2f, %.2f), col(%.2f, %.2f, %.2f, %.2f), tc0(%.2f, %.2f)",
  487. ret.pos.x.ToFloat32(), ret.pos.y.ToFloat32(), ret.pos.z.ToFloat32(), ret.pos.w.ToFloat32(),
  488. ret.color.x.ToFloat32(), ret.color.y.ToFloat32(), ret.color.z.ToFloat32(), ret.color.w.ToFloat32(),
  489. ret.tc0.u().ToFloat32(), ret.tc0.v().ToFloat32());
  490. return ret;
  491. }
  492. } // namespace
  493. } // namespace