summaryrefslogtreecommitdiff
path: root/src/shader_recompiler
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-05-18 21:04:09 -0300
committerGravatar ameerj2021-07-22 21:51:32 -0400
commit8b7d5912d61d56f65fb7e3a03bba544a4c40bfa6 (patch)
treeede1d0e1d3c828b50f4af190f64adf73a30a62e7 /src/shader_recompiler
parentglasm: Implement textureGather instructions (diff)
downloadyuzu-8b7d5912d61d56f65fb7e3a03bba544a4c40bfa6.tar.gz
yuzu-8b7d5912d61d56f65fb7e3a03bba544a4c40bfa6.tar.xz
yuzu-8b7d5912d61d56f65fb7e3a03bba544a4c40bfa6.zip
glasm: Support textures used in more than one stage
Diffstat (limited to 'src/shader_recompiler')
-rw-r--r--src/shader_recompiler/backend/glasm/emit_context.cpp10
-rw-r--r--src/shader_recompiler/backend/glasm/emit_context.h14
-rw-r--r--src/shader_recompiler/backend/glasm/emit_glasm.cpp4
3 files changed, 24 insertions, 4 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_context.cpp b/src/shader_recompiler/backend/glasm/emit_context.cpp
index 4903e9d8e..d1fe84a5f 100644
--- a/src/shader_recompiler/backend/glasm/emit_context.cpp
+++ b/src/shader_recompiler/backend/glasm/emit_context.cpp
@@ -4,6 +4,7 @@
4 4
5#include <string_view> 5#include <string_view>
6 6
7#include "shader_recompiler/backend/bindings.h"
7#include "shader_recompiler/backend/glasm/emit_context.h" 8#include "shader_recompiler/backend/glasm/emit_context.h"
8#include "shader_recompiler/frontend/ir/program.h" 9#include "shader_recompiler/frontend/ir/program.h"
9 10
@@ -22,7 +23,7 @@ std::string_view InterpDecorator(Interpolation interp) {
22} 23}
23} // Anonymous namespace 24} // Anonymous namespace
24 25
25EmitContext::EmitContext(IR::Program& program) { 26EmitContext::EmitContext(IR::Program& program, Bindings& bindings) : info{program.info} {
26 // FIXME: Temporary partial implementation 27 // FIXME: Temporary partial implementation
27 u32 cbuf_index{}; 28 u32 cbuf_index{};
28 for (const auto& desc : program.info.constant_buffer_descriptors) { 29 for (const auto& desc : program.info.constant_buffer_descriptors) {
@@ -79,6 +80,13 @@ EmitContext::EmitContext(IR::Program& program) {
79 Add("OUTPUT out_attr{}[]={{result.attrib[{}..{}]}};", index, index, index); 80 Add("OUTPUT out_attr{}[]={{result.attrib[{}..{}]}};", index, index, index);
80 } 81 }
81 } 82 }
83 const size_t num_textures{program.info.texture_descriptors.size()};
84 texture_bindings.resize(num_textures);
85 for (size_t index = 0; index < num_textures; ++index) {
86 const auto& desc{program.info.texture_descriptors[index]};
87 texture_bindings[index] = bindings.texture;
88 bindings.texture += desc.count;
89 }
82} 90}
83 91
84} // namespace Shader::Backend::GLASM 92} // namespace Shader::Backend::GLASM
diff --git a/src/shader_recompiler/backend/glasm/emit_context.h b/src/shader_recompiler/backend/glasm/emit_context.h
index 4efe42ada..084635c77 100644
--- a/src/shader_recompiler/backend/glasm/emit_context.h
+++ b/src/shader_recompiler/backend/glasm/emit_context.h
@@ -6,11 +6,20 @@
6 6
7#include <string> 7#include <string>
8#include <utility> 8#include <utility>
9#include <vector>
9 10
10#include <fmt/format.h> 11#include <fmt/format.h>
11 12
12#include "shader_recompiler/backend/glasm/reg_alloc.h" 13#include "shader_recompiler/backend/glasm/reg_alloc.h"
13 14
15namespace Shader {
16struct Info;
17}
18
19namespace Shader::Backend {
20struct Bindings;
21}
22
14namespace Shader::IR { 23namespace Shader::IR {
15class Inst; 24class Inst;
16struct Program; 25struct Program;
@@ -20,7 +29,7 @@ namespace Shader::Backend::GLASM {
20 29
21class EmitContext { 30class EmitContext {
22public: 31public:
23 explicit EmitContext(IR::Program& program); 32 explicit EmitContext(IR::Program& program, Bindings& bindings);
24 33
25 template <typename... Args> 34 template <typename... Args>
26 void Add(const char* format_str, IR::Inst& inst, Args&&... args) { 35 void Add(const char* format_str, IR::Inst& inst, Args&&... args) {
@@ -45,6 +54,9 @@ public:
45 54
46 std::string code; 55 std::string code;
47 RegAlloc reg_alloc{*this}; 56 RegAlloc reg_alloc{*this};
57 const Info& info;
58
59 std::vector<u32> texture_bindings;
48 60
49 std::string_view stage_name = "invalid"; 61 std::string_view stage_name = "invalid";
50}; 62};
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm.cpp b/src/shader_recompiler/backend/glasm/emit_glasm.cpp
index a893fa3fb..edf6f5e13 100644
--- a/src/shader_recompiler/backend/glasm/emit_glasm.cpp
+++ b/src/shader_recompiler/backend/glasm/emit_glasm.cpp
@@ -312,8 +312,8 @@ std::string_view StageHeader(Stage stage) {
312} 312}
313} // Anonymous namespace 313} // Anonymous namespace
314 314
315std::string EmitGLASM(const Profile&, IR::Program& program, Bindings&) { 315std::string EmitGLASM(const Profile&, IR::Program& program, Bindings& bindings) {
316 EmitContext ctx{program}; 316 EmitContext ctx{program, bindings};
317 Precolor(ctx, program); 317 Precolor(ctx, program);
318 EmitCode(ctx, program); 318 EmitCode(ctx, program);
319 std::string header{StageHeader(program.stage)}; 319 std::string header{StageHeader(program.stage)};