vertex_shader.cpp 24 KB

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