summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glasm
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-05-19 16:32:03 -0300
committerGravatar ameerj2021-07-22 21:51:32 -0400
commitaccad56ee7cc9f77886d164701a35f1e89a3519b (patch)
tree34b272f1f70d0c4d926877c4e960ccec0084ce17 /src/shader_recompiler/backend/glasm
parentglasm: Implement gl_PointSize stores (diff)
downloadyuzu-accad56ee7cc9f77886d164701a35f1e89a3519b.tar.gz
yuzu-accad56ee7cc9f77886d164701a35f1e89a3519b.tar.xz
yuzu-accad56ee7cc9f77886d164701a35f1e89a3519b.zip
glasm: Implement stores to gl_ViewportIndex
Diffstat (limited to 'src/shader_recompiler/backend/glasm')
-rw-r--r--src/shader_recompiler/backend/glasm/emit_context.cpp4
-rw-r--r--src/shader_recompiler/backend/glasm/emit_context.h8
-rw-r--r--src/shader_recompiler/backend/glasm/emit_glasm.cpp16
-rw-r--r--src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp8
4 files changed, 29 insertions, 7 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_context.cpp b/src/shader_recompiler/backend/glasm/emit_context.cpp
index e2182400c..395ac87f2 100644
--- a/src/shader_recompiler/backend/glasm/emit_context.cpp
+++ b/src/shader_recompiler/backend/glasm/emit_context.cpp
@@ -23,7 +23,8 @@ std::string_view InterpDecorator(Interpolation interp) {
23} 23}
24} // Anonymous namespace 24} // Anonymous namespace
25 25
26EmitContext::EmitContext(IR::Program& program, Bindings& bindings) : info{program.info} { 26EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_)
27 : info{program.info}, profile{profile_} {
27 // FIXME: Temporary partial implementation 28 // FIXME: Temporary partial implementation
28 u32 cbuf_index{}; 29 u32 cbuf_index{};
29 for (const auto& desc : program.info.constant_buffer_descriptors) { 30 for (const auto& desc : program.info.constant_buffer_descriptors) {
@@ -41,6 +42,7 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings) : info{progra
41 if (const size_t num = program.info.storage_buffers_descriptors.size(); num > 0) { 42 if (const size_t num = program.info.storage_buffers_descriptors.size(); num > 0) {
42 Add("PARAM c[{}]={{program.local[0..{}]}};", num, num - 1); 43 Add("PARAM c[{}]={{program.local[0..{}]}};", num, num - 1);
43 } 44 }
45 stage = program.stage;
44 switch (program.stage) { 46 switch (program.stage) {
45 case Stage::VertexA: 47 case Stage::VertexA:
46 case Stage::VertexB: 48 case Stage::VertexB:
diff --git a/src/shader_recompiler/backend/glasm/emit_context.h b/src/shader_recompiler/backend/glasm/emit_context.h
index d6b0bf73c..dd1f9ac9f 100644
--- a/src/shader_recompiler/backend/glasm/emit_context.h
+++ b/src/shader_recompiler/backend/glasm/emit_context.h
@@ -11,10 +11,12 @@
11#include <fmt/format.h> 11#include <fmt/format.h>
12 12
13#include "shader_recompiler/backend/glasm/reg_alloc.h" 13#include "shader_recompiler/backend/glasm/reg_alloc.h"
14#include "shader_recompiler/stage.h"
14 15
15namespace Shader { 16namespace Shader {
16struct Info; 17struct Info;
17} 18struct Profile;
19} // namespace Shader
18 20
19namespace Shader::Backend { 21namespace Shader::Backend {
20struct Bindings; 22struct Bindings;
@@ -29,7 +31,7 @@ namespace Shader::Backend::GLASM {
29 31
30class EmitContext { 32class EmitContext {
31public: 33public:
32 explicit EmitContext(IR::Program& program, Bindings& bindings); 34 explicit EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_);
33 35
34 template <typename... Args> 36 template <typename... Args>
35 void Add(const char* format_str, IR::Inst& inst, Args&&... args) { 37 void Add(const char* format_str, IR::Inst& inst, Args&&... args) {
@@ -55,10 +57,12 @@ public:
55 std::string code; 57 std::string code;
56 RegAlloc reg_alloc{*this}; 58 RegAlloc reg_alloc{*this};
57 const Info& info; 59 const Info& info;
60 const Profile& profile;
58 61
59 std::vector<u32> texture_buffer_bindings; 62 std::vector<u32> texture_buffer_bindings;
60 std::vector<u32> texture_bindings; 63 std::vector<u32> texture_bindings;
61 64
65 Stage stage{};
62 std::string_view stage_name = "invalid"; 66 std::string_view stage_name = "invalid";
63}; 67};
64 68
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm.cpp b/src/shader_recompiler/backend/glasm/emit_glasm.cpp
index edf6f5e13..9dc0cacbe 100644
--- a/src/shader_recompiler/backend/glasm/emit_glasm.cpp
+++ b/src/shader_recompiler/backend/glasm/emit_glasm.cpp
@@ -261,7 +261,10 @@ void EmitCode(EmitContext& ctx, const IR::Program& program) {
261 } 261 }
262} 262}
263 263
264void SetupOptions(std::string& header, Info info) { 264void SetupOptions(const IR::Program& program, const Profile& profile, std::string& header) {
265 const Info& info{program.info};
266 const Stage stage{program.stage};
267
265 // TODO: Track the shared atomic ops 268 // TODO: Track the shared atomic ops
266 header += "OPTION NV_internal;" 269 header += "OPTION NV_internal;"
267 "OPTION NV_shader_storage_buffer;" 270 "OPTION NV_shader_storage_buffer;"
@@ -286,6 +289,11 @@ void SetupOptions(std::string& header, Info info) {
286 if (info.uses_sparse_residency) { 289 if (info.uses_sparse_residency) {
287 header += "OPTION EXT_sparse_texture2;"; 290 header += "OPTION EXT_sparse_texture2;";
288 } 291 }
292 if ((info.stores_viewport_index || info.stores_layer) && stage != Stage::Geometry) {
293 if (profile.support_viewport_index_layer_non_geometry) {
294 header += "OPTION NV_viewport_array2;";
295 }
296 }
289 const auto non_zero_frag_colors{info.stores_frag_color | std::views::drop(1)}; 297 const auto non_zero_frag_colors{info.stores_frag_color | std::views::drop(1)};
290 if (std::ranges::find(non_zero_frag_colors, true) != non_zero_frag_colors.end()) { 298 if (std::ranges::find(non_zero_frag_colors, true) != non_zero_frag_colors.end()) {
291 header += "OPTION ARB_draw_buffers;"; 299 header += "OPTION ARB_draw_buffers;";
@@ -312,12 +320,12 @@ std::string_view StageHeader(Stage stage) {
312} 320}
313} // Anonymous namespace 321} // Anonymous namespace
314 322
315std::string EmitGLASM(const Profile&, IR::Program& program, Bindings& bindings) { 323std::string EmitGLASM(const Profile& profile, IR::Program& program, Bindings& bindings) {
316 EmitContext ctx{program, bindings}; 324 EmitContext ctx{program, bindings, profile};
317 Precolor(ctx, program); 325 Precolor(ctx, program);
318 EmitCode(ctx, program); 326 EmitCode(ctx, program);
319 std::string header{StageHeader(program.stage)}; 327 std::string header{StageHeader(program.stage)};
320 SetupOptions(header, program.info); 328 SetupOptions(program, profile, header);
321 switch (program.stage) { 329 switch (program.stage) {
322 case Stage::Compute: 330 case Stage::Compute:
323 header += fmt::format("GROUP_SIZE {} {} {};", program.workgroup_size[0], 331 header += fmt::format("GROUP_SIZE {} {} {};", program.workgroup_size[0],
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp
index f362dd2c8..6484387bc 100644
--- a/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp
+++ b/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp
@@ -7,6 +7,7 @@
7#include "shader_recompiler/backend/glasm/emit_context.h" 7#include "shader_recompiler/backend/glasm/emit_context.h"
8#include "shader_recompiler/backend/glasm/emit_glasm_instructions.h" 8#include "shader_recompiler/backend/glasm/emit_glasm_instructions.h"
9#include "shader_recompiler/frontend/ir/value.h" 9#include "shader_recompiler/frontend/ir/value.h"
10#include "shader_recompiler/profile.h"
10 11
11namespace Shader::Backend::GLASM { 12namespace Shader::Backend::GLASM {
12namespace { 13namespace {
@@ -102,6 +103,13 @@ void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, ScalarF32 value,
102 case IR::Attribute::PositionW: 103 case IR::Attribute::PositionW:
103 ctx.Add("MOV.F result.position.{},{};", swizzle, value); 104 ctx.Add("MOV.F result.position.{},{};", swizzle, value);
104 break; 105 break;
106 case IR::Attribute::ViewportIndex:
107 if (ctx.stage == Stage::Geometry || ctx.profile.support_viewport_index_layer_non_geometry) {
108 ctx.Add("MOV.F result.viewport.x,{};", value);
109 } else {
110 // LOG_WARNING
111 }
112 break;
105 default: 113 default:
106 throw NotImplementedException("Set attribute {}", attr); 114 throw NotImplementedException("Set attribute {}", attr);
107 } 115 }