diff options
| author | 2021-05-15 18:14:29 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:31 -0400 | |
| commit | 3764750339fa60f2d79cf3abe1b91ca42ba61401 (patch) | |
| tree | f2ff6aa50b6d5e1e91f42fcbfae9b1d650b8dd10 /src | |
| parent | glasm: Implement local memory for glasm (diff) | |
| download | yuzu-3764750339fa60f2d79cf3abe1b91ca42ba61401.tar.gz yuzu-3764750339fa60f2d79cf3abe1b91ca42ba61401.tar.xz yuzu-3764750339fa60f2d79cf3abe1b91ca42ba61401.zip | |
glasm: Add graphics specific shader declarations to GLASM
Diffstat (limited to 'src')
| -rw-r--r-- | src/shader_recompiler/backend/glasm/emit_context.cpp | 37 | ||||
| -rw-r--r-- | src/shader_recompiler/backend/glasm/emit_glasm.cpp | 32 |
2 files changed, 63 insertions, 6 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_context.cpp b/src/shader_recompiler/backend/glasm/emit_context.cpp index f9d83dd91..66c954ff6 100644 --- a/src/shader_recompiler/backend/glasm/emit_context.cpp +++ b/src/shader_recompiler/backend/glasm/emit_context.cpp | |||
| @@ -2,10 +2,25 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <string_view> | ||
| 6 | |||
| 5 | #include "shader_recompiler/backend/glasm/emit_context.h" | 7 | #include "shader_recompiler/backend/glasm/emit_context.h" |
| 6 | #include "shader_recompiler/frontend/ir/program.h" | 8 | #include "shader_recompiler/frontend/ir/program.h" |
| 7 | 9 | ||
| 8 | namespace Shader::Backend::GLASM { | 10 | namespace Shader::Backend::GLASM { |
| 11 | namespace { | ||
| 12 | std::string_view InterpDecorator(Interpolation interp) { | ||
| 13 | switch (interp) { | ||
| 14 | case Interpolation::Smooth: | ||
| 15 | return ""; | ||
| 16 | case Interpolation::Flat: | ||
| 17 | return "FLAT "; | ||
| 18 | case Interpolation::NoPerspective: | ||
| 19 | return "NOPERSPECTIVE "; | ||
| 20 | } | ||
| 21 | throw InvalidArgument("Invalid interpolation {}", interp); | ||
| 22 | } | ||
| 23 | } // Anonymous namespace | ||
| 9 | 24 | ||
| 10 | EmitContext::EmitContext(IR::Program& program) { | 25 | EmitContext::EmitContext(IR::Program& program) { |
| 11 | // FIXME: Temporary partial implementation | 26 | // FIXME: Temporary partial implementation |
| @@ -42,6 +57,28 @@ EmitContext::EmitContext(IR::Program& program) { | |||
| 42 | stage_name = "compute"; | 57 | stage_name = "compute"; |
| 43 | break; | 58 | break; |
| 44 | } | 59 | } |
| 60 | for (size_t index = 0; index < program.info.input_generics.size(); ++index) { | ||
| 61 | const auto& generic{program.info.input_generics[index]}; | ||
| 62 | if (generic.used) { | ||
| 63 | Add("{}ATTRIB in_attr{}[]={{{}.attrib[{}..{}]}};", | ||
| 64 | InterpDecorator(generic.interpolation), index, stage_name, index, index); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | for (size_t index = 0; index < program.info.stores_frag_color.size(); ++index) { | ||
| 68 | if (!program.info.stores_frag_color[index]) { | ||
| 69 | continue; | ||
| 70 | } | ||
| 71 | if (index == 0) { | ||
| 72 | Add("OUTPUT frag_color0=result.color;"); | ||
| 73 | } else { | ||
| 74 | Add("OUTPUT frag_color{}[]=result.color[{}];", index, index); | ||
| 75 | } | ||
| 76 | } | ||
| 77 | for (size_t index = 0; index < program.info.stores_generics.size(); ++index) { | ||
| 78 | if (program.info.stores_generics[index]) { | ||
| 79 | Add("OUTPUT out_attr{}[]={{result.attrib[{}..{}]}};", index, index, index); | ||
| 80 | } | ||
| 81 | } | ||
| 45 | } | 82 | } |
| 46 | 83 | ||
| 47 | } // namespace Shader::Backend::GLASM | 84 | } // namespace Shader::Backend::GLASM |
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm.cpp b/src/shader_recompiler/backend/glasm/emit_glasm.cpp index 0b70bf3f6..ab6790ce8 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm.cpp | |||
| @@ -261,6 +261,12 @@ void EmitCode(EmitContext& ctx, const IR::Program& program) { | |||
| 261 | } | 261 | } |
| 262 | 262 | ||
| 263 | void SetupOptions(std::string& header, Info info) { | 263 | void SetupOptions(std::string& header, Info info) { |
| 264 | // TODO: Track the shared atomic ops | ||
| 265 | header += "OPTION NV_internal;" | ||
| 266 | "OPTION NV_shader_storage_buffer;" | ||
| 267 | "OPTION NV_gpu_program_fp64;" | ||
| 268 | "OPTION NV_bindless_texture;" | ||
| 269 | "OPTION ARB_derivative_control;"; | ||
| 264 | if (info.uses_int64_bit_atomics) { | 270 | if (info.uses_int64_bit_atomics) { |
| 265 | header += "OPTION NV_shader_atomic_int64;"; | 271 | header += "OPTION NV_shader_atomic_int64;"; |
| 266 | } | 272 | } |
| @@ -276,10 +282,25 @@ void SetupOptions(std::string& header, Info info) { | |||
| 276 | if (info.uses_subgroup_shuffles) { | 282 | if (info.uses_subgroup_shuffles) { |
| 277 | header += "OPTION NV_shader_thread_shuffle;"; | 283 | header += "OPTION NV_shader_thread_shuffle;"; |
| 278 | } | 284 | } |
| 279 | // TODO: Track the shared atomic ops | 285 | } |
| 280 | header += "OPTION NV_shader_storage_buffer;" | 286 | |
| 281 | "OPTION NV_gpu_program_fp64;" | 287 | std::string_view StageHeader(Stage stage) { |
| 282 | "OPTION NV_bindless_texture;"; | 288 | switch (stage) { |
| 289 | case Stage::VertexA: | ||
| 290 | case Stage::VertexB: | ||
| 291 | return "!!NVvp5.0\n"; | ||
| 292 | case Stage::TessellationControl: | ||
| 293 | return "!!NVtcs5.0\n"; | ||
| 294 | case Stage::TessellationEval: | ||
| 295 | return "!!NVtes5.0\n"; | ||
| 296 | case Stage::Geometry: | ||
| 297 | return "!!NVgp5.0\n"; | ||
| 298 | case Stage::Fragment: | ||
| 299 | return "!!NVfp5.0\n"; | ||
| 300 | case Stage::Compute: | ||
| 301 | return "!!NVcp5.0\n"; | ||
| 302 | } | ||
| 303 | throw InvalidArgument("Invalid stage {}", stage); | ||
| 283 | } | 304 | } |
| 284 | } // Anonymous namespace | 305 | } // Anonymous namespace |
| 285 | 306 | ||
| @@ -287,8 +308,7 @@ std::string EmitGLASM(const Profile&, IR::Program& program, Bindings&) { | |||
| 287 | EmitContext ctx{program}; | 308 | EmitContext ctx{program}; |
| 288 | Precolor(ctx, program); | 309 | Precolor(ctx, program); |
| 289 | EmitCode(ctx, program); | 310 | EmitCode(ctx, program); |
| 290 | std::string header = "!!NVcp5.0\n" | 311 | std::string header{StageHeader(program.stage)}; |
| 291 | "OPTION NV_internal;"; | ||
| 292 | SetupOptions(header, program.info); | 312 | SetupOptions(header, program.info); |
| 293 | switch (program.stage) { | 313 | switch (program.stage) { |
| 294 | case Stage::Compute: | 314 | case Stage::Compute: |