summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2020-06-20 22:11:49 -0400
committerGravatar GitHub2020-06-20 22:11:49 -0400
commitf98bf1025ff334c7069a200854637ecf4df8e65d (patch)
tree5fb981e9850a2df0951a7e02092c84c9f94d41ff
parentMerge pull request #4133 from MerryMage/macrojit-shifts (diff)
parentgl_arb_decompiler: Avoid several string copies (diff)
downloadyuzu-f98bf1025ff334c7069a200854637ecf4df8e65d.tar.gz
yuzu-f98bf1025ff334c7069a200854637ecf4df8e65d.tar.xz
yuzu-f98bf1025ff334c7069a200854637ecf4df8e65d.zip
Merge pull request #4120 from lioncash/arb
gl_arb_decompiler: Avoid several string copies
Diffstat (limited to '')
-rw-r--r--src/video_core/renderer_opengl/gl_arb_decompiler.cpp63
1 files changed, 31 insertions, 32 deletions
diff --git a/src/video_core/renderer_opengl/gl_arb_decompiler.cpp b/src/video_core/renderer_opengl/gl_arb_decompiler.cpp
index 1e96b0310..eb5158407 100644
--- a/src/video_core/renderer_opengl/gl_arb_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_arb_decompiler.cpp
@@ -281,14 +281,14 @@ private:
281 281
282 template <const std::string_view& op> 282 template <const std::string_view& op>
283 std::string Unary(Operation operation) { 283 std::string Unary(Operation operation) {
284 const std::string temporary = AllocTemporary(); 284 std::string temporary = AllocTemporary();
285 AddLine("{}{} {}, {};", op, Modifiers(operation), temporary, Visit(operation[0])); 285 AddLine("{}{} {}, {};", op, Modifiers(operation), temporary, Visit(operation[0]));
286 return temporary; 286 return temporary;
287 } 287 }
288 288
289 template <const std::string_view& op> 289 template <const std::string_view& op>
290 std::string Binary(Operation operation) { 290 std::string Binary(Operation operation) {
291 const std::string temporary = AllocTemporary(); 291 std::string temporary = AllocTemporary();
292 AddLine("{}{} {}, {}, {};", op, Modifiers(operation), temporary, Visit(operation[0]), 292 AddLine("{}{} {}, {}, {};", op, Modifiers(operation), temporary, Visit(operation[0]),
293 Visit(operation[1])); 293 Visit(operation[1]));
294 return temporary; 294 return temporary;
@@ -296,7 +296,7 @@ private:
296 296
297 template <const std::string_view& op> 297 template <const std::string_view& op>
298 std::string Trinary(Operation operation) { 298 std::string Trinary(Operation operation) {
299 const std::string temporary = AllocTemporary(); 299 std::string temporary = AllocTemporary();
300 AddLine("{}{} {}, {}, {}, {};", op, Modifiers(operation), temporary, Visit(operation[0]), 300 AddLine("{}{} {}, {}, {}, {};", op, Modifiers(operation), temporary, Visit(operation[0]),
301 Visit(operation[1]), Visit(operation[2])); 301 Visit(operation[1]), Visit(operation[2]));
302 return temporary; 302 return temporary;
@@ -304,7 +304,7 @@ private:
304 304
305 template <const std::string_view& op, bool unordered> 305 template <const std::string_view& op, bool unordered>
306 std::string FloatComparison(Operation operation) { 306 std::string FloatComparison(Operation operation) {
307 const std::string temporary = AllocTemporary(); 307 std::string temporary = AllocTemporary();
308 AddLine("TRUNC.U.CC RC.x, {};", Binary<op>(operation)); 308 AddLine("TRUNC.U.CC RC.x, {};", Binary<op>(operation));
309 AddLine("MOV.S {}, 0;", temporary); 309 AddLine("MOV.S {}, 0;", temporary);
310 AddLine("MOV.S {} (NE.x), -1;", temporary); 310 AddLine("MOV.S {} (NE.x), -1;", temporary);
@@ -331,7 +331,7 @@ private:
331 331
332 template <const std::string_view& op, bool is_nan> 332 template <const std::string_view& op, bool is_nan>
333 std::string HalfComparison(Operation operation) { 333 std::string HalfComparison(Operation operation) {
334 const std::string tmp1 = AllocVectorTemporary(); 334 std::string tmp1 = AllocVectorTemporary();
335 const std::string tmp2 = AllocVectorTemporary(); 335 const std::string tmp2 = AllocVectorTemporary();
336 const std::string op_a = Visit(operation[0]); 336 const std::string op_a = Visit(operation[0]);
337 const std::string op_b = Visit(operation[1]); 337 const std::string op_b = Visit(operation[1]);
@@ -367,15 +367,14 @@ private:
367 AddLine("MOV.F {}.{}, {};", value, Swizzle(i), Visit(meta.values[i])); 367 AddLine("MOV.F {}.{}, {};", value, Swizzle(i), Visit(meta.values[i]));
368 } 368 }
369 369
370 const std::string result = coord; 370 AddLine("ATOMIM.{}.{} {}.x, {}, {}, image[{}], {};", op, type, coord, value, coord,
371 AddLine("ATOMIM.{}.{} {}.x, {}, {}, image[{}], {};", op, type, result, value, coord,
372 image_id, ImageType(meta.image.type)); 371 image_id, ImageType(meta.image.type));
373 return fmt::format("{}.x", result); 372 return fmt::format("{}.x", coord);
374 } 373 }
375 374
376 template <const std::string_view& op, const std::string_view& type> 375 template <const std::string_view& op, const std::string_view& type>
377 std::string Atomic(Operation operation) { 376 std::string Atomic(Operation operation) {
378 const std::string temporary = AllocTemporary(); 377 std::string temporary = AllocTemporary();
379 std::string address; 378 std::string address;
380 std::string_view opname; 379 std::string_view opname;
381 if (const auto gmem = std::get_if<GmemNode>(&*operation[0])) { 380 if (const auto gmem = std::get_if<GmemNode>(&*operation[0])) {
@@ -396,7 +395,7 @@ private:
396 395
397 template <char type> 396 template <char type>
398 std::string Negate(Operation operation) { 397 std::string Negate(Operation operation) {
399 const std::string temporary = AllocTemporary(); 398 std::string temporary = AllocTemporary();
400 if constexpr (type == 'F') { 399 if constexpr (type == 'F') {
401 AddLine("MOV.F32 {}, -{};", temporary, Visit(operation[0])); 400 AddLine("MOV.F32 {}, -{};", temporary, Visit(operation[0]));
402 } else { 401 } else {
@@ -407,7 +406,7 @@ private:
407 406
408 template <char type> 407 template <char type>
409 std::string Absolute(Operation operation) { 408 std::string Absolute(Operation operation) {
410 const std::string temporary = AllocTemporary(); 409 std::string temporary = AllocTemporary();
411 AddLine("MOV.{} {}, |{}|;", type, temporary, Visit(operation[0])); 410 AddLine("MOV.{} {}, |{}|;", type, temporary, Visit(operation[0]));
412 return temporary; 411 return temporary;
413 } 412 }
@@ -1156,20 +1155,20 @@ void ARBDecompiler::VisitAST(const ASTNode& node) {
1156} 1155}
1157 1156
1158std::string ARBDecompiler::VisitExpression(const Expr& node) { 1157std::string ARBDecompiler::VisitExpression(const Expr& node) {
1159 const std::string result = AllocTemporary();
1160 if (const auto expr = std::get_if<ExprAnd>(&*node)) { 1158 if (const auto expr = std::get_if<ExprAnd>(&*node)) {
1159 std::string result = AllocTemporary();
1161 AddLine("AND.U {}, {}, {};", result, VisitExpression(expr->operand1), 1160 AddLine("AND.U {}, {}, {};", result, VisitExpression(expr->operand1),
1162 VisitExpression(expr->operand2)); 1161 VisitExpression(expr->operand2));
1163 return result; 1162 return result;
1164 } 1163 }
1165 if (const auto expr = std::get_if<ExprOr>(&*node)) { 1164 if (const auto expr = std::get_if<ExprOr>(&*node)) {
1166 const std::string result = AllocTemporary(); 1165 std::string result = AllocTemporary();
1167 AddLine("OR.U {}, {}, {};", result, VisitExpression(expr->operand1), 1166 AddLine("OR.U {}, {}, {};", result, VisitExpression(expr->operand1),
1168 VisitExpression(expr->operand2)); 1167 VisitExpression(expr->operand2));
1169 return result; 1168 return result;
1170 } 1169 }
1171 if (const auto expr = std::get_if<ExprNot>(&*node)) { 1170 if (const auto expr = std::get_if<ExprNot>(&*node)) {
1172 const std::string result = AllocTemporary(); 1171 std::string result = AllocTemporary();
1173 AddLine("CMP.S {}, {}, 0, -1;", result, VisitExpression(expr->operand1)); 1172 AddLine("CMP.S {}, {}, 0, -1;", result, VisitExpression(expr->operand1));
1174 return result; 1173 return result;
1175 } 1174 }
@@ -1186,7 +1185,7 @@ std::string ARBDecompiler::VisitExpression(const Expr& node) {
1186 return expr->value ? "0xffffffff" : "0"; 1185 return expr->value ? "0xffffffff" : "0";
1187 } 1186 }
1188 if (const auto expr = std::get_if<ExprGprEqual>(&*node)) { 1187 if (const auto expr = std::get_if<ExprGprEqual>(&*node)) {
1189 const std::string result = AllocTemporary(); 1188 std::string result = AllocTemporary();
1190 AddLine("SEQ.U {}, R{}.x, {};", result, expr->gpr, expr->value); 1189 AddLine("SEQ.U {}, R{}.x, {};", result, expr->gpr, expr->value);
1191 return result; 1190 return result;
1192 } 1191 }
@@ -1231,13 +1230,13 @@ std::string ARBDecompiler::Visit(const Node& node) {
1231 } 1230 }
1232 1231
1233 if (const auto immediate = std::get_if<ImmediateNode>(&*node)) { 1232 if (const auto immediate = std::get_if<ImmediateNode>(&*node)) {
1234 const std::string temporary = AllocTemporary(); 1233 std::string temporary = AllocTemporary();
1235 AddLine("MOV.U {}, {};", temporary, immediate->GetValue()); 1234 AddLine("MOV.U {}, {};", temporary, immediate->GetValue());
1236 return temporary; 1235 return temporary;
1237 } 1236 }
1238 1237
1239 if (const auto predicate = std::get_if<PredicateNode>(&*node)) { 1238 if (const auto predicate = std::get_if<PredicateNode>(&*node)) {
1240 const std::string temporary = AllocTemporary(); 1239 std::string temporary = AllocTemporary();
1241 switch (const auto index = predicate->GetIndex(); index) { 1240 switch (const auto index = predicate->GetIndex(); index) {
1242 case Tegra::Shader::Pred::UnusedIndex: 1241 case Tegra::Shader::Pred::UnusedIndex:
1243 AddLine("MOV.S {}, -1;", temporary); 1242 AddLine("MOV.S {}, -1;", temporary);
@@ -1333,13 +1332,13 @@ std::string ARBDecompiler::Visit(const Node& node) {
1333 } else { 1332 } else {
1334 offset_string = Visit(offset); 1333 offset_string = Visit(offset);
1335 } 1334 }
1336 const std::string temporary = AllocTemporary(); 1335 std::string temporary = AllocTemporary();
1337 AddLine("LDC.F32 {}, cbuf{}[{}];", temporary, cbuf->GetIndex(), offset_string); 1336 AddLine("LDC.F32 {}, cbuf{}[{}];", temporary, cbuf->GetIndex(), offset_string);
1338 return temporary; 1337 return temporary;
1339 } 1338 }
1340 1339
1341 if (const auto gmem = std::get_if<GmemNode>(&*node)) { 1340 if (const auto gmem = std::get_if<GmemNode>(&*node)) {
1342 const std::string temporary = AllocTemporary(); 1341 std::string temporary = AllocTemporary();
1343 AddLine("SUB.U {}, {}, {};", temporary, Visit(gmem->GetRealAddress()), 1342 AddLine("SUB.U {}, {}, {};", temporary, Visit(gmem->GetRealAddress()),
1344 Visit(gmem->GetBaseAddress())); 1343 Visit(gmem->GetBaseAddress()));
1345 AddLine("LDB.U32 {}, {}[{}];", temporary, GlobalMemoryName(gmem->GetDescriptor()), 1344 AddLine("LDB.U32 {}, {}[{}];", temporary, GlobalMemoryName(gmem->GetDescriptor()),
@@ -1348,14 +1347,14 @@ std::string ARBDecompiler::Visit(const Node& node) {
1348 } 1347 }
1349 1348
1350 if (const auto lmem = std::get_if<LmemNode>(&*node)) { 1349 if (const auto lmem = std::get_if<LmemNode>(&*node)) {
1351 const std::string temporary = Visit(lmem->GetAddress()); 1350 std::string temporary = Visit(lmem->GetAddress());
1352 AddLine("SHR.U {}, {}, 2;", temporary, temporary); 1351 AddLine("SHR.U {}, {}, 2;", temporary, temporary);
1353 AddLine("MOV.U {}, lmem[{}].x;", temporary, temporary); 1352 AddLine("MOV.U {}, lmem[{}].x;", temporary, temporary);
1354 return temporary; 1353 return temporary;
1355 } 1354 }
1356 1355
1357 if (const auto smem = std::get_if<SmemNode>(&*node)) { 1356 if (const auto smem = std::get_if<SmemNode>(&*node)) {
1358 const std::string temporary = Visit(smem->GetAddress()); 1357 std::string temporary = Visit(smem->GetAddress());
1359 AddLine("LDS.U32 {}, shared_mem[{}];", temporary, temporary); 1358 AddLine("LDS.U32 {}, shared_mem[{}];", temporary, temporary);
1360 return temporary; 1359 return temporary;
1361 } 1360 }
@@ -1535,7 +1534,7 @@ std::string ARBDecompiler::Assign(Operation operation) {
1535} 1534}
1536 1535
1537std::string ARBDecompiler::Select(Operation operation) { 1536std::string ARBDecompiler::Select(Operation operation) {
1538 const std::string temporary = AllocTemporary(); 1537 std::string temporary = AllocTemporary();
1539 AddLine("CMP.S {}, {}, {}, {};", temporary, Visit(operation[0]), Visit(operation[1]), 1538 AddLine("CMP.S {}, {}, {}, {};", temporary, Visit(operation[0]), Visit(operation[1]),
1540 Visit(operation[2])); 1539 Visit(operation[2]));
1541 return temporary; 1540 return temporary;
@@ -1545,12 +1544,12 @@ std::string ARBDecompiler::FClamp(Operation operation) {
1545 // 1.0f in hex, replace with std::bit_cast on C++20 1544 // 1.0f in hex, replace with std::bit_cast on C++20
1546 static constexpr u32 POSITIVE_ONE = 0x3f800000; 1545 static constexpr u32 POSITIVE_ONE = 0x3f800000;
1547 1546
1548 const std::string temporary = AllocTemporary(); 1547 std::string temporary = AllocTemporary();
1549 const Node& value = operation[0]; 1548 const Node& value = operation[0];
1550 const Node& low = operation[1]; 1549 const Node& low = operation[1];
1551 const Node& high = operation[2]; 1550 const Node& high = operation[2];
1552 const auto imm_low = std::get_if<ImmediateNode>(&*low); 1551 const auto* const imm_low = std::get_if<ImmediateNode>(&*low);
1553 const auto imm_high = std::get_if<ImmediateNode>(&*high); 1552 const auto* const imm_high = std::get_if<ImmediateNode>(&*high);
1554 if (imm_low && imm_high && imm_low->GetValue() == 0 && imm_high->GetValue() == POSITIVE_ONE) { 1553 if (imm_low && imm_high && imm_low->GetValue() == 0 && imm_high->GetValue() == POSITIVE_ONE) {
1555 AddLine("MOV.F32.SAT {}, {};", temporary, Visit(value)); 1554 AddLine("MOV.F32.SAT {}, {};", temporary, Visit(value));
1556 } else { 1555 } else {
@@ -1574,7 +1573,7 @@ std::string ARBDecompiler::FCastHalf1(Operation operation) {
1574} 1573}
1575 1574
1576std::string ARBDecompiler::FSqrt(Operation operation) { 1575std::string ARBDecompiler::FSqrt(Operation operation) {
1577 const std::string temporary = AllocTemporary(); 1576 std::string temporary = AllocTemporary();
1578 AddLine("RSQ.F32 {}, {};", temporary, Visit(operation[0])); 1577 AddLine("RSQ.F32 {}, {};", temporary, Visit(operation[0]));
1579 AddLine("RCP.F32 {}, {};", temporary, temporary); 1578 AddLine("RCP.F32 {}, {};", temporary, temporary);
1580 return temporary; 1579 return temporary;
@@ -1588,7 +1587,7 @@ std::string ARBDecompiler::FSwizzleAdd(Operation operation) {
1588 AddLine("ADD.F {}.x, {}, {};", temporary, Visit(operation[0]), Visit(operation[1])); 1587 AddLine("ADD.F {}.x, {}, {};", temporary, Visit(operation[0]), Visit(operation[1]));
1589 return fmt::format("{}.x", temporary); 1588 return fmt::format("{}.x", temporary);
1590 } 1589 }
1591 const std::string lut = AllocVectorTemporary(); 1590
1592 AddLine("AND.U {}.z, {}.threadid, 3;", temporary, StageInputName(stage)); 1591 AddLine("AND.U {}.z, {}.threadid, 3;", temporary, StageInputName(stage));
1593 AddLine("SHL.U {}.z, {}.z, 1;", temporary, temporary); 1592 AddLine("SHL.U {}.z, {}.z, 1;", temporary, temporary);
1594 AddLine("SHR.U {}.z, {}, {}.z;", temporary, Visit(operation[2]), temporary); 1593 AddLine("SHR.U {}.z, {}, {}.z;", temporary, Visit(operation[2]), temporary);
@@ -1766,21 +1765,21 @@ std::string ARBDecompiler::LogicalAssign(Operation operation) {
1766} 1765}
1767 1766
1768std::string ARBDecompiler::LogicalPick2(Operation operation) { 1767std::string ARBDecompiler::LogicalPick2(Operation operation) {
1769 const std::string temporary = AllocTemporary(); 1768 std::string temporary = AllocTemporary();
1770 const u32 index = std::get<ImmediateNode>(*operation[1]).GetValue(); 1769 const u32 index = std::get<ImmediateNode>(*operation[1]).GetValue();
1771 AddLine("MOV.U {}, {}.{};", temporary, Visit(operation[0]), Swizzle(index)); 1770 AddLine("MOV.U {}, {}.{};", temporary, Visit(operation[0]), Swizzle(index));
1772 return temporary; 1771 return temporary;
1773} 1772}
1774 1773
1775std::string ARBDecompiler::LogicalAnd2(Operation operation) { 1774std::string ARBDecompiler::LogicalAnd2(Operation operation) {
1776 const std::string temporary = AllocTemporary(); 1775 std::string temporary = AllocTemporary();
1777 const std::string op = Visit(operation[0]); 1776 const std::string op = Visit(operation[0]);
1778 AddLine("AND.U {}, {}.x, {}.y;", temporary, op, op); 1777 AddLine("AND.U {}, {}.x, {}.y;", temporary, op, op);
1779 return temporary; 1778 return temporary;
1780} 1779}
1781 1780
1782std::string ARBDecompiler::FloatOrdered(Operation operation) { 1781std::string ARBDecompiler::FloatOrdered(Operation operation) {
1783 const std::string temporary = AllocTemporary(); 1782 std::string temporary = AllocTemporary();
1784 AddLine("MOVC.F32 RC.x, {};", Visit(operation[0])); 1783 AddLine("MOVC.F32 RC.x, {};", Visit(operation[0]));
1785 AddLine("MOVC.F32 RC.y, {};", Visit(operation[1])); 1784 AddLine("MOVC.F32 RC.y, {};", Visit(operation[1]));
1786 AddLine("MOV.S {}, -1;", temporary); 1785 AddLine("MOV.S {}, -1;", temporary);
@@ -1790,7 +1789,7 @@ std::string ARBDecompiler::FloatOrdered(Operation operation) {
1790} 1789}
1791 1790
1792std::string ARBDecompiler::FloatUnordered(Operation operation) { 1791std::string ARBDecompiler::FloatUnordered(Operation operation) {
1793 const std::string temporary = AllocTemporary(); 1792 std::string temporary = AllocTemporary();
1794 AddLine("MOVC.F32 RC.x, {};", Visit(operation[0])); 1793 AddLine("MOVC.F32 RC.x, {};", Visit(operation[0]));
1795 AddLine("MOVC.F32 RC.y, {};", Visit(operation[1])); 1794 AddLine("MOVC.F32 RC.y, {};", Visit(operation[1]));
1796 AddLine("MOV.S {}, 0;", temporary); 1795 AddLine("MOV.S {}, 0;", temporary);
@@ -1800,7 +1799,7 @@ std::string ARBDecompiler::FloatUnordered(Operation operation) {
1800} 1799}
1801 1800
1802std::string ARBDecompiler::LogicalAddCarry(Operation operation) { 1801std::string ARBDecompiler::LogicalAddCarry(Operation operation) {
1803 const std::string temporary = AllocTemporary(); 1802 std::string temporary = AllocTemporary();
1804 AddLine("ADDC.U RC, {}, {};", Visit(operation[0]), Visit(operation[1])); 1803 AddLine("ADDC.U RC, {}, {};", Visit(operation[0]), Visit(operation[1]));
1805 AddLine("MOV.S {}, 0;", temporary); 1804 AddLine("MOV.S {}, 0;", temporary);
1806 AddLine("IF CF.x;"); 1805 AddLine("IF CF.x;");