summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2018-04-20 03:09:25 +0200
committerGitHub <noreply@github.com>2018-04-20 03:09:25 +0200
commit17ad56c1dce85e71d5ab8a87efd7d43d87cacd92 (patch)
treeb95508967e962f25571cb04da2ef07ce92742261 /src
parentMerge pull request #355 from Subv/shader_instr (diff)
parentglsl_shader_decompiler: Use std::string_view instead of std::string for AddLine() (diff)
downloadyuzu-17ad56c1dce85e71d5ab8a87efd7d43d87cacd92.tar
yuzu-17ad56c1dce85e71d5ab8a87efd7d43d87cacd92.tar.gz
yuzu-17ad56c1dce85e71d5ab8a87efd7d43d87cacd92.tar.bz2
yuzu-17ad56c1dce85e71d5ab8a87efd7d43d87cacd92.tar.lz
yuzu-17ad56c1dce85e71d5ab8a87efd7d43d87cacd92.tar.xz
yuzu-17ad56c1dce85e71d5ab8a87efd7d43d87cacd92.tar.zst
yuzu-17ad56c1dce85e71d5ab8a87efd7d43d87cacd92.zip
Diffstat (limited to '')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp42
1 files changed, 30 insertions, 12 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index 4cc617c97..de137558d 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -5,6 +5,7 @@
#include <map>
#include <set>
#include <string>
+#include <string_view>
#include "common/assert.h"
#include "common/common_types.h"
#include "video_core/engines/shader_bytecode.h"
@@ -109,12 +110,25 @@ private:
class ShaderWriter {
public:
- void AddLine(const std::string& text) {
+ void AddLine(std::string_view text) {
DEBUG_ASSERT(scope >= 0);
if (!text.empty()) {
- shader_source += std::string(static_cast<size_t>(scope) * 4, ' ');
+ AppendIndentation();
}
- shader_source += text + '\n';
+ shader_source += text;
+ AddNewLine();
+ }
+
+ void AddLine(char character) {
+ DEBUG_ASSERT(scope >= 0);
+ AppendIndentation();
+ shader_source += character;
+ AddNewLine();
+ }
+
+ void AddNewLine() {
+ DEBUG_ASSERT(scope >= 0);
+ shader_source += '\n';
}
std::string GetResult() {
@@ -124,6 +138,10 @@ public:
int scope = 0;
private:
+ void AppendIndentation() {
+ shader_source.append(static_cast<size_t>(scope) * 4, ' ');
+ }
+
std::string shader_source;
};
@@ -481,7 +499,7 @@ private:
for (const auto& subroutine : subroutines) {
shader.AddLine("bool " + subroutine.GetName() + "();");
}
- shader.AddLine("");
+ shader.AddNewLine();
// Add the main entry point
shader.AddLine("bool exec_shader() {");
@@ -524,14 +542,14 @@ private:
}
--shader.scope;
- shader.AddLine("}");
+ shader.AddLine('}');
}
shader.AddLine("default: return false;");
- shader.AddLine("}");
+ shader.AddLine('}');
--shader.scope;
- shader.AddLine("}");
+ shader.AddLine('}');
shader.AddLine("return false;");
}
@@ -558,7 +576,7 @@ private:
for (const auto& reg : declr_register) {
declarations.AddLine("float " + reg + " = 0.0;");
}
- declarations.AddLine("");
+ declarations.AddNewLine();
for (const auto& index : declr_input_attribute) {
// TODO(bunnei): Use proper number of elements for these
@@ -567,7 +585,7 @@ private:
static_cast<u32>(Attribute::Index::Attribute_0)) +
") in vec4 " + GetInputAttribute(index) + ";");
}
- declarations.AddLine("");
+ declarations.AddNewLine();
for (const auto& index : declr_output_attribute) {
// TODO(bunnei): Use proper number of elements for these
@@ -576,15 +594,15 @@ private:
static_cast<u32>(Attribute::Index::Attribute_0)) +
") out vec4 " + GetOutputAttribute(index) + ";");
}
- declarations.AddLine("");
+ declarations.AddNewLine();
unsigned const_buffer_layout = 0;
for (const auto& entry : GetConstBuffersDeclarations()) {
declarations.AddLine("layout(std430) buffer " + entry.GetName());
- declarations.AddLine("{");
+ declarations.AddLine('{');
declarations.AddLine(" float c" + std::to_string(entry.GetIndex()) + "[];");
declarations.AddLine("};");
- declarations.AddLine("");
+ declarations.AddNewLine();
++const_buffer_layout;
}
}