summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Lioncash2019-05-14 17:59:25 -0400
committerGravatar Lioncash2019-05-20 14:14:48 -0400
commit6fb29764d61df8f42075ec363af1a1b3458afd17 (patch)
tree428c740987e848b54baf21ce7489b1a40644e1db /src
parentgl_shader_decompiler: Utilize fmt overload of AddLine() where applicable (diff)
downloadyuzu-6fb29764d61df8f42075ec363af1a1b3458afd17.tar.gz
yuzu-6fb29764d61df8f42075ec363af1a1b3458afd17.tar.xz
yuzu-6fb29764d61df8f42075ec363af1a1b3458afd17.zip
gl_shader_decompiler: Replace individual overloads with the fmt-based one
Gets rid of the need to special-case brace handling depending on the overload used, and makes it consistent across the board with how fmt handles them. Strings with compile-time deducible strings are directly forwarded to std::string's constructor, so we don't need to worry about the performance difference here, as it'll be identical.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp44
1 files changed, 16 insertions, 28 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index 7c32e0abc..233a8aca2 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -57,19 +57,7 @@ public:
57 shader_source += text; 57 shader_source += text;
58 } 58 }
59 59
60 void AddLine(std::string_view text) { 60 // Forwards all arguments directly to libfmt.
61 AddExpression(text);
62 AddNewLine();
63 }
64
65 void AddLine(char character) {
66 DEBUG_ASSERT(scope >= 0);
67 AppendIndentation();
68 shader_source += character;
69 AddNewLine();
70 }
71
72 // Overload the forwards all arguments directly to libfmt.
73 // Note that all formatting requirements for fmt must be 61 // Note that all formatting requirements for fmt must be
74 // obeyed when using this function. (e.g. {{ must be used 62 // obeyed when using this function. (e.g. {{ must be used
75 // printing the character '{' is desirable. Ditto for }} and '}', 63 // printing the character '{' is desirable. Ditto for }} and '}',
@@ -191,10 +179,10 @@ public:
191 code.AddLine("uint flow_stack[{}];", FLOW_STACK_SIZE); 179 code.AddLine("uint flow_stack[{}];", FLOW_STACK_SIZE);
192 code.AddLine("uint flow_stack_top = 0u;"); 180 code.AddLine("uint flow_stack_top = 0u;");
193 181
194 code.AddLine("while (true) {"); 182 code.AddLine("while (true) {{");
195 ++code.scope; 183 ++code.scope;
196 184
197 code.AddLine("switch (jmp_to) {"); 185 code.AddLine("switch (jmp_to) {{");
198 186
199 for (const auto& pair : ir.GetBasicBlocks()) { 187 for (const auto& pair : ir.GetBasicBlocks()) {
200 const auto [address, bb] = pair; 188 const auto [address, bb] = pair;
@@ -204,15 +192,15 @@ public:
204 VisitBlock(bb); 192 VisitBlock(bb);
205 193
206 --code.scope; 194 --code.scope;
207 code.AddLine('}'); 195 code.AddLine("}}");
208 } 196 }
209 197
210 code.AddLine("default: return;"); 198 code.AddLine("default: return;");
211 code.AddLine('}'); 199 code.AddLine("}}");
212 200
213 for (std::size_t i = 0; i < 2; ++i) { 201 for (std::size_t i = 0; i < 2; ++i) {
214 --code.scope; 202 --code.scope;
215 code.AddLine('}'); 203 code.AddLine("}}");
216 } 204 }
217 } 205 }
218 206
@@ -267,7 +255,7 @@ private:
267 void DeclareVertexRedeclarations() { 255 void DeclareVertexRedeclarations() {
268 bool clip_distances_declared = false; 256 bool clip_distances_declared = false;
269 257
270 code.AddLine("out gl_PerVertex {"); 258 code.AddLine("out gl_PerVertex {{");
271 ++code.scope; 259 ++code.scope;
272 260
273 code.AddLine("vec4 gl_Position;"); 261 code.AddLine("vec4 gl_Position;");
@@ -283,7 +271,7 @@ private:
283 } 271 }
284 272
285 --code.scope; 273 --code.scope;
286 code.AddLine("};"); 274 code.AddLine("}};");
287 code.AddNewLine(); 275 code.AddNewLine();
288 } 276 }
289 277
@@ -419,7 +407,7 @@ private:
419 code.AddLine("layout (std140, binding = CBUF_BINDING_{}) uniform {} {{", index, 407 code.AddLine("layout (std140, binding = CBUF_BINDING_{}) uniform {} {{", index,
420 GetConstBufferBlock(index)); 408 GetConstBufferBlock(index));
421 code.AddLine(" vec4 {}[MAX_CONSTBUFFER_ELEMENTS];", GetConstBuffer(index)); 409 code.AddLine(" vec4 {}[MAX_CONSTBUFFER_ELEMENTS];", GetConstBuffer(index));
422 code.AddLine("};"); 410 code.AddLine("}};");
423 code.AddNewLine(); 411 code.AddNewLine();
424 } 412 }
425 } 413 }
@@ -440,7 +428,7 @@ private:
440 code.AddLine("layout (std430, binding = GMEM_BINDING_{}_{}) {} buffer {} {{", 428 code.AddLine("layout (std430, binding = GMEM_BINDING_{}_{}) {} buffer {} {{",
441 base.cbuf_index, base.cbuf_offset, qualifier, GetGlobalMemoryBlock(base)); 429 base.cbuf_index, base.cbuf_offset, qualifier, GetGlobalMemoryBlock(base));
442 code.AddLine(" float {}[];", GetGlobalMemory(base)); 430 code.AddLine(" float {}[];", GetGlobalMemory(base));
443 code.AddLine("};"); 431 code.AddLine("}};");
444 code.AddNewLine(); 432 code.AddNewLine();
445 } 433 }
446 } 434 }
@@ -622,7 +610,7 @@ private:
622 VisitBlock(conditional->GetCode()); 610 VisitBlock(conditional->GetCode());
623 611
624 --code.scope; 612 --code.scope;
625 code.AddLine('}'); 613 code.AddLine("}}");
626 return {}; 614 return {};
627 } 615 }
628 616
@@ -1461,7 +1449,7 @@ private:
1461 1449
1462 UNIMPLEMENTED_IF_MSG(header.ps.omap.sample_mask != 0, "Sample mask write is unimplemented"); 1450 UNIMPLEMENTED_IF_MSG(header.ps.omap.sample_mask != 0, "Sample mask write is unimplemented");
1463 1451
1464 code.AddLine("if (alpha_test[0] != 0) {"); 1452 code.AddLine("if (alpha_test[0] != 0) {{");
1465 ++code.scope; 1453 ++code.scope;
1466 // We start on the register containing the alpha value in the first RT. 1454 // We start on the register containing the alpha value in the first RT.
1467 u32 current_reg = 3; 1455 u32 current_reg = 3;
@@ -1477,7 +1465,7 @@ private:
1477 } 1465 }
1478 } 1466 }
1479 --code.scope; 1467 --code.scope;
1480 code.AddLine('}'); 1468 code.AddLine("}}");
1481 1469
1482 // Write the color outputs using the data in the shader registers, disabled 1470 // Write the color outputs using the data in the shader registers, disabled
1483 // rendertargets/components are skipped in the register assignment. 1471 // rendertargets/components are skipped in the register assignment.
@@ -1496,7 +1484,7 @@ private:
1496 if (header.ps.omap.depth) { 1484 if (header.ps.omap.depth) {
1497 // The depth output is always 2 registers after the last color output, and current_reg 1485 // The depth output is always 2 registers after the last color output, and current_reg
1498 // already contains one past the last color register. 1486 // already contains one past the last color register.
1499 code.AddLine("gl_FragDepth = " + SafeGetRegister(current_reg + 1) + ';'); 1487 code.AddLine("gl_FragDepth = {};", SafeGetRegister(current_reg + 1));
1500 } 1488 }
1501 1489
1502 code.AddLine("return;"); 1490 code.AddLine("return;");
@@ -1506,11 +1494,11 @@ private:
1506 std::string Discard(Operation operation) { 1494 std::string Discard(Operation operation) {
1507 // Enclose "discard" in a conditional, so that GLSL compilation does not complain 1495 // Enclose "discard" in a conditional, so that GLSL compilation does not complain
1508 // about unexecuted instructions that may follow this. 1496 // about unexecuted instructions that may follow this.
1509 code.AddLine("if (true) {"); 1497 code.AddLine("if (true) {{");
1510 ++code.scope; 1498 ++code.scope;
1511 code.AddLine("discard;"); 1499 code.AddLine("discard;");
1512 --code.scope; 1500 --code.scope;
1513 code.AddLine("}"); 1501 code.AddLine("}}");
1514 return {}; 1502 return {};
1515 } 1503 }
1516 1504