diff options
| author | 2018-04-19 21:09:25 -0400 | |
|---|---|---|
| committer | 2018-04-19 21:09:25 -0400 | |
| commit | 17ad56c1dce85e71d5ab8a87efd7d43d87cacd92 (patch) | |
| tree | b95508967e962f25571cb04da2ef07ce92742261 /src | |
| parent | Merge pull request #355 from Subv/shader_instr (diff) | |
| parent | glsl_shader_decompiler: Use std::string_view instead of std::string for AddLi... (diff) | |
| download | yuzu-17ad56c1dce85e71d5ab8a87efd7d43d87cacd92.tar.gz yuzu-17ad56c1dce85e71d5ab8a87efd7d43d87cacd92.tar.xz yuzu-17ad56c1dce85e71d5ab8a87efd7d43d87cacd92.zip | |
Merge pull request #356 from lioncash/shader
glsl_shader_decompiler: Minor API changes to ShaderWriter
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 42 |
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 @@ | |||
| 5 | #include <map> | 5 | #include <map> |
| 6 | #include <set> | 6 | #include <set> |
| 7 | #include <string> | 7 | #include <string> |
| 8 | #include <string_view> | ||
| 8 | #include "common/assert.h" | 9 | #include "common/assert.h" |
| 9 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 10 | #include "video_core/engines/shader_bytecode.h" | 11 | #include "video_core/engines/shader_bytecode.h" |
| @@ -109,12 +110,25 @@ private: | |||
| 109 | 110 | ||
| 110 | class ShaderWriter { | 111 | class ShaderWriter { |
| 111 | public: | 112 | public: |
| 112 | void AddLine(const std::string& text) { | 113 | void AddLine(std::string_view text) { |
| 113 | DEBUG_ASSERT(scope >= 0); | 114 | DEBUG_ASSERT(scope >= 0); |
| 114 | if (!text.empty()) { | 115 | if (!text.empty()) { |
| 115 | shader_source += std::string(static_cast<size_t>(scope) * 4, ' '); | 116 | AppendIndentation(); |
| 116 | } | 117 | } |
| 117 | shader_source += text + '\n'; | 118 | shader_source += text; |
| 119 | AddNewLine(); | ||
| 120 | } | ||
| 121 | |||
| 122 | void AddLine(char character) { | ||
| 123 | DEBUG_ASSERT(scope >= 0); | ||
| 124 | AppendIndentation(); | ||
| 125 | shader_source += character; | ||
| 126 | AddNewLine(); | ||
| 127 | } | ||
| 128 | |||
| 129 | void AddNewLine() { | ||
| 130 | DEBUG_ASSERT(scope >= 0); | ||
| 131 | shader_source += '\n'; | ||
| 118 | } | 132 | } |
| 119 | 133 | ||
| 120 | std::string GetResult() { | 134 | std::string GetResult() { |
| @@ -124,6 +138,10 @@ public: | |||
| 124 | int scope = 0; | 138 | int scope = 0; |
| 125 | 139 | ||
| 126 | private: | 140 | private: |
| 141 | void AppendIndentation() { | ||
| 142 | shader_source.append(static_cast<size_t>(scope) * 4, ' '); | ||
| 143 | } | ||
| 144 | |||
| 127 | std::string shader_source; | 145 | std::string shader_source; |
| 128 | }; | 146 | }; |
| 129 | 147 | ||
| @@ -481,7 +499,7 @@ private: | |||
| 481 | for (const auto& subroutine : subroutines) { | 499 | for (const auto& subroutine : subroutines) { |
| 482 | shader.AddLine("bool " + subroutine.GetName() + "();"); | 500 | shader.AddLine("bool " + subroutine.GetName() + "();"); |
| 483 | } | 501 | } |
| 484 | shader.AddLine(""); | 502 | shader.AddNewLine(); |
| 485 | 503 | ||
| 486 | // Add the main entry point | 504 | // Add the main entry point |
| 487 | shader.AddLine("bool exec_shader() {"); | 505 | shader.AddLine("bool exec_shader() {"); |
| @@ -524,14 +542,14 @@ private: | |||
| 524 | } | 542 | } |
| 525 | 543 | ||
| 526 | --shader.scope; | 544 | --shader.scope; |
| 527 | shader.AddLine("}"); | 545 | shader.AddLine('}'); |
| 528 | } | 546 | } |
| 529 | 547 | ||
| 530 | shader.AddLine("default: return false;"); | 548 | shader.AddLine("default: return false;"); |
| 531 | shader.AddLine("}"); | 549 | shader.AddLine('}'); |
| 532 | 550 | ||
| 533 | --shader.scope; | 551 | --shader.scope; |
| 534 | shader.AddLine("}"); | 552 | shader.AddLine('}'); |
| 535 | 553 | ||
| 536 | shader.AddLine("return false;"); | 554 | shader.AddLine("return false;"); |
| 537 | } | 555 | } |
| @@ -558,7 +576,7 @@ private: | |||
| 558 | for (const auto& reg : declr_register) { | 576 | for (const auto& reg : declr_register) { |
| 559 | declarations.AddLine("float " + reg + " = 0.0;"); | 577 | declarations.AddLine("float " + reg + " = 0.0;"); |
| 560 | } | 578 | } |
| 561 | declarations.AddLine(""); | 579 | declarations.AddNewLine(); |
| 562 | 580 | ||
| 563 | for (const auto& index : declr_input_attribute) { | 581 | for (const auto& index : declr_input_attribute) { |
| 564 | // TODO(bunnei): Use proper number of elements for these | 582 | // TODO(bunnei): Use proper number of elements for these |
| @@ -567,7 +585,7 @@ private: | |||
| 567 | static_cast<u32>(Attribute::Index::Attribute_0)) + | 585 | static_cast<u32>(Attribute::Index::Attribute_0)) + |
| 568 | ") in vec4 " + GetInputAttribute(index) + ";"); | 586 | ") in vec4 " + GetInputAttribute(index) + ";"); |
| 569 | } | 587 | } |
| 570 | declarations.AddLine(""); | 588 | declarations.AddNewLine(); |
| 571 | 589 | ||
| 572 | for (const auto& index : declr_output_attribute) { | 590 | for (const auto& index : declr_output_attribute) { |
| 573 | // TODO(bunnei): Use proper number of elements for these | 591 | // TODO(bunnei): Use proper number of elements for these |
| @@ -576,15 +594,15 @@ private: | |||
| 576 | static_cast<u32>(Attribute::Index::Attribute_0)) + | 594 | static_cast<u32>(Attribute::Index::Attribute_0)) + |
| 577 | ") out vec4 " + GetOutputAttribute(index) + ";"); | 595 | ") out vec4 " + GetOutputAttribute(index) + ";"); |
| 578 | } | 596 | } |
| 579 | declarations.AddLine(""); | 597 | declarations.AddNewLine(); |
| 580 | 598 | ||
| 581 | unsigned const_buffer_layout = 0; | 599 | unsigned const_buffer_layout = 0; |
| 582 | for (const auto& entry : GetConstBuffersDeclarations()) { | 600 | for (const auto& entry : GetConstBuffersDeclarations()) { |
| 583 | declarations.AddLine("layout(std430) buffer " + entry.GetName()); | 601 | declarations.AddLine("layout(std430) buffer " + entry.GetName()); |
| 584 | declarations.AddLine("{"); | 602 | declarations.AddLine('{'); |
| 585 | declarations.AddLine(" float c" + std::to_string(entry.GetIndex()) + "[];"); | 603 | declarations.AddLine(" float c" + std::to_string(entry.GetIndex()) + "[];"); |
| 586 | declarations.AddLine("};"); | 604 | declarations.AddLine("};"); |
| 587 | declarations.AddLine(""); | 605 | declarations.AddNewLine(); |
| 588 | ++const_buffer_layout; | 606 | ++const_buffer_layout; |
| 589 | } | 607 | } |
| 590 | } | 608 | } |