summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glasm
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-05-21 02:12:32 -0300
committerGravatar ameerj2021-07-22 21:51:33 -0400
commit9e7b6622c25aa858b96bf0f1c7f94223a2f449a2 (patch)
tree48c62889aeb79d6f0f01a467ba0d1ac01dec512b /src/shader_recompiler/backend/glasm
parentemit_glasm_context_get_and_set.cpp: Add missing semicolons (diff)
downloadyuzu-9e7b6622c25aa858b96bf0f1c7f94223a2f449a2.tar.gz
yuzu-9e7b6622c25aa858b96bf0f1c7f94223a2f449a2.tar.xz
yuzu-9e7b6622c25aa858b96bf0f1c7f94223a2f449a2.zip
shader: Split profile and runtime information in separate structs
Diffstat (limited to 'src/shader_recompiler/backend/glasm')
-rw-r--r--src/shader_recompiler/backend/glasm/emit_context.cpp40
-rw-r--r--src/shader_recompiler/backend/glasm/emit_context.h6
-rw-r--r--src/shader_recompiler/backend/glasm/emit_glasm.cpp19
-rw-r--r--src/shader_recompiler/backend/glasm/emit_glasm.h6
4 files changed, 38 insertions, 33 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_context.cpp b/src/shader_recompiler/backend/glasm/emit_context.cpp
index e42f186c1..659ff6d17 100644
--- a/src/shader_recompiler/backend/glasm/emit_context.cpp
+++ b/src/shader_recompiler/backend/glasm/emit_context.cpp
@@ -23,23 +23,25 @@ std::string_view InterpDecorator(Interpolation interp) {
23} 23}
24} // Anonymous namespace 24} // Anonymous namespace
25 25
26EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_) 26EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_,
27 : info{program.info}, profile{profile_} { 27 const RuntimeInfo& runtime_info_)
28 : profile{profile_}, runtime_info{runtime_info_} {
28 // FIXME: Temporary partial implementation 29 // FIXME: Temporary partial implementation
30 const auto& info{program.info};
29 u32 cbuf_index{}; 31 u32 cbuf_index{};
30 for (const auto& desc : program.info.constant_buffer_descriptors) { 32 for (const auto& desc : info.constant_buffer_descriptors) {
31 if (desc.count != 1) { 33 if (desc.count != 1) {
32 throw NotImplementedException("Constant buffer descriptor array"); 34 throw NotImplementedException("Constant buffer descriptor array");
33 } 35 }
34 Add("CBUFFER c{}[]={{program.buffer[{}]}};", desc.index, cbuf_index); 36 Add("CBUFFER c{}[]={{program.buffer[{}]}};", desc.index, cbuf_index);
35 ++cbuf_index; 37 ++cbuf_index;
36 } 38 }
37 for (const auto& desc : program.info.storage_buffers_descriptors) { 39 for (const auto& desc : info.storage_buffers_descriptors) {
38 if (desc.count != 1) { 40 if (desc.count != 1) {
39 throw NotImplementedException("Storage buffer descriptor array"); 41 throw NotImplementedException("Storage buffer descriptor array");
40 } 42 }
41 } 43 }
42 if (const size_t num = program.info.storage_buffers_descriptors.size(); num > 0) { 44 if (const size_t num = info.storage_buffers_descriptors.size(); num > 0) {
43 Add("PARAM c[{}]={{program.local[0..{}]}};", num, num - 1); 45 Add("PARAM c[{}]={{program.local[0..{}]}};", num, num - 1);
44 } 46 }
45 stage = program.stage; 47 stage = program.stage;
@@ -67,8 +69,8 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
67 break; 69 break;
68 } 70 }
69 const std::string_view attr_stage{stage == Stage::Fragment ? "fragment" : "vertex"}; 71 const std::string_view attr_stage{stage == Stage::Fragment ? "fragment" : "vertex"};
70 for (size_t index = 0; index < program.info.input_generics.size(); ++index) { 72 for (size_t index = 0; index < info.input_generics.size(); ++index) {
71 const auto& generic{program.info.input_generics[index]}; 73 const auto& generic{info.input_generics[index]};
72 if (generic.used) { 74 if (generic.used) {
73 Add("{}ATTRIB in_attr{}[]={{{}.attrib[{}..{}]}};", 75 Add("{}ATTRIB in_attr{}[]={{{}.attrib[{}..{}]}};",
74 InterpDecorator(generic.interpolation), index, attr_stage, index, index); 76 InterpDecorator(generic.interpolation), index, attr_stage, index, index);
@@ -101,8 +103,8 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
101 index, index); 103 index, index);
102 } 104 }
103 } 105 }
104 for (size_t index = 0; index < program.info.stores_frag_color.size(); ++index) { 106 for (size_t index = 0; index < info.stores_frag_color.size(); ++index) {
105 if (!program.info.stores_frag_color[index]) { 107 if (!info.stores_frag_color[index]) {
106 continue; 108 continue;
107 } 109 }
108 if (index == 0) { 110 if (index == 0) {
@@ -111,28 +113,28 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
111 Add("OUTPUT frag_color{}=result.color[{}];", index, index); 113 Add("OUTPUT frag_color{}=result.color[{}];", index, index);
112 } 114 }
113 } 115 }
114 for (size_t index = 0; index < program.info.stores_generics.size(); ++index) { 116 for (size_t index = 0; index < info.stores_generics.size(); ++index) {
115 if (program.info.stores_generics[index]) { 117 if (info.stores_generics[index]) {
116 Add("OUTPUT out_attr{}[]={{result.attrib[{}..{}]}};", index, index, index); 118 Add("OUTPUT out_attr{}[]={{result.attrib[{}..{}]}};", index, index, index);
117 } 119 }
118 } 120 }
119 image_buffer_bindings.reserve(program.info.image_buffer_descriptors.size()); 121 image_buffer_bindings.reserve(info.image_buffer_descriptors.size());
120 for (const auto& desc : program.info.image_buffer_descriptors) { 122 for (const auto& desc : info.image_buffer_descriptors) {
121 image_buffer_bindings.push_back(bindings.image); 123 image_buffer_bindings.push_back(bindings.image);
122 bindings.image += desc.count; 124 bindings.image += desc.count;
123 } 125 }
124 image_bindings.reserve(program.info.image_descriptors.size()); 126 image_bindings.reserve(info.image_descriptors.size());
125 for (const auto& desc : program.info.image_descriptors) { 127 for (const auto& desc : info.image_descriptors) {
126 image_bindings.push_back(bindings.image); 128 image_bindings.push_back(bindings.image);
127 bindings.image += desc.count; 129 bindings.image += desc.count;
128 } 130 }
129 texture_buffer_bindings.reserve(program.info.texture_buffer_descriptors.size()); 131 texture_buffer_bindings.reserve(info.texture_buffer_descriptors.size());
130 for (const auto& desc : program.info.texture_buffer_descriptors) { 132 for (const auto& desc : info.texture_buffer_descriptors) {
131 texture_buffer_bindings.push_back(bindings.texture); 133 texture_buffer_bindings.push_back(bindings.texture);
132 bindings.texture += desc.count; 134 bindings.texture += desc.count;
133 } 135 }
134 texture_bindings.reserve(program.info.texture_descriptors.size()); 136 texture_bindings.reserve(info.texture_descriptors.size());
135 for (const auto& desc : program.info.texture_descriptors) { 137 for (const auto& desc : info.texture_descriptors) {
136 texture_bindings.push_back(bindings.texture); 138 texture_bindings.push_back(bindings.texture);
137 bindings.texture += desc.count; 139 bindings.texture += desc.count;
138 } 140 }
diff --git a/src/shader_recompiler/backend/glasm/emit_context.h b/src/shader_recompiler/backend/glasm/emit_context.h
index e76ed1d7c..1f057fdd5 100644
--- a/src/shader_recompiler/backend/glasm/emit_context.h
+++ b/src/shader_recompiler/backend/glasm/emit_context.h
@@ -16,6 +16,7 @@
16namespace Shader { 16namespace Shader {
17struct Info; 17struct Info;
18struct Profile; 18struct Profile;
19struct RuntimeInfo;
19} // namespace Shader 20} // namespace Shader
20 21
21namespace Shader::Backend { 22namespace Shader::Backend {
@@ -31,7 +32,8 @@ namespace Shader::Backend::GLASM {
31 32
32class EmitContext { 33class EmitContext {
33public: 34public:
34 explicit EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_); 35 explicit EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_,
36 const RuntimeInfo& runtime_info_);
35 37
36 template <typename... Args> 38 template <typename... Args>
37 void Add(const char* format_str, IR::Inst& inst, Args&&... args) { 39 void Add(const char* format_str, IR::Inst& inst, Args&&... args) {
@@ -56,8 +58,8 @@ public:
56 58
57 std::string code; 59 std::string code;
58 RegAlloc reg_alloc{*this}; 60 RegAlloc reg_alloc{*this};
59 const Info& info;
60 const Profile& profile; 61 const Profile& profile;
62 const RuntimeInfo& runtime_info;
61 63
62 std::vector<u32> texture_buffer_bindings; 64 std::vector<u32> texture_buffer_bindings;
63 std::vector<u32> image_buffer_bindings; 65 std::vector<u32> image_buffer_bindings;
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm.cpp b/src/shader_recompiler/backend/glasm/emit_glasm.cpp
index f110fd7f8..edff04a44 100644
--- a/src/shader_recompiler/backend/glasm/emit_glasm.cpp
+++ b/src/shader_recompiler/backend/glasm/emit_glasm.cpp
@@ -374,8 +374,9 @@ std::string_view GetTessSpacing(TessSpacing spacing) {
374} 374}
375} // Anonymous namespace 375} // Anonymous namespace
376 376
377std::string EmitGLASM(const Profile& profile, IR::Program& program, Bindings& bindings) { 377std::string EmitGLASM(const Profile& profile, const RuntimeInfo& runtime_info, IR::Program& program,
378 EmitContext ctx{program, bindings, profile}; 378 Bindings& bindings) {
379 EmitContext ctx{program, bindings, profile, runtime_info};
379 Precolor(ctx, program); 380 Precolor(ctx, program);
380 EmitCode(ctx, program); 381 EmitCode(ctx, program);
381 std::string header{StageHeader(program.stage)}; 382 std::string header{StageHeader(program.stage)};
@@ -385,18 +386,18 @@ std::string EmitGLASM(const Profile& profile, IR::Program& program, Bindings& bi
385 header += fmt::format("VERTICES_OUT {};", program.invocations); 386 header += fmt::format("VERTICES_OUT {};", program.invocations);
386 break; 387 break;
387 case Stage::TessellationEval: 388 case Stage::TessellationEval:
388 header += 389 header += fmt::format("TESS_MODE {};"
389 fmt::format("TESS_MODE {};" 390 "TESS_SPACING {};"
390 "TESS_SPACING {};" 391 "TESS_VERTEX_ORDER {};",
391 "TESS_VERTEX_ORDER {};", 392 GetTessMode(runtime_info.tess_primitive),
392 GetTessMode(profile.tess_primitive), GetTessSpacing(profile.tess_spacing), 393 GetTessSpacing(runtime_info.tess_spacing),
393 profile.tess_clockwise ? "CW" : "CCW"); 394 runtime_info.tess_clockwise ? "CW" : "CCW");
394 break; 395 break;
395 case Stage::Geometry: 396 case Stage::Geometry:
396 header += fmt::format("PRIMITIVE_IN {};" 397 header += fmt::format("PRIMITIVE_IN {};"
397 "PRIMITIVE_OUT {};" 398 "PRIMITIVE_OUT {};"
398 "VERTICES_OUT {};", 399 "VERTICES_OUT {};",
399 InputPrimitive(profile.input_topology), 400 InputPrimitive(runtime_info.input_topology),
400 OutputPrimitive(program.output_topology), program.output_vertices); 401 OutputPrimitive(program.output_topology), program.output_vertices);
401 break; 402 break;
402 case Stage::Compute: 403 case Stage::Compute:
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm.h b/src/shader_recompiler/backend/glasm/emit_glasm.h
index a0dfdd818..3d02d873e 100644
--- a/src/shader_recompiler/backend/glasm/emit_glasm.h
+++ b/src/shader_recompiler/backend/glasm/emit_glasm.h
@@ -12,12 +12,12 @@
12 12
13namespace Shader::Backend::GLASM { 13namespace Shader::Backend::GLASM {
14 14
15[[nodiscard]] std::string EmitGLASM(const Profile& profile, IR::Program& program, 15[[nodiscard]] std::string EmitGLASM(const Profile& profile, const RuntimeInfo& runtime_info,
16 Bindings& binding); 16 IR::Program& program, Bindings& bindings);
17 17
18[[nodiscard]] inline std::string EmitGLASM(const Profile& profile, IR::Program& program) { 18[[nodiscard]] inline std::string EmitGLASM(const Profile& profile, IR::Program& program) {
19 Bindings binding; 19 Bindings binding;
20 return EmitGLASM(profile, program, binding); 20 return EmitGLASM(profile, {}, program, binding);
21} 21}
22 22
23} // namespace Shader::Backend::GLASM 23} // namespace Shader::Backend::GLASM