glasm: Add graphics specific shader declarations to GLASM

This commit is contained in:
ReinUsesLisp 2021-05-15 18:14:29 -03:00 committed by ameerj
parent 057dee4856
commit 3764750339
2 changed files with 63 additions and 6 deletions

View File

@ -2,10 +2,25 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <string_view>
#include "shader_recompiler/backend/glasm/emit_context.h" #include "shader_recompiler/backend/glasm/emit_context.h"
#include "shader_recompiler/frontend/ir/program.h" #include "shader_recompiler/frontend/ir/program.h"
namespace Shader::Backend::GLASM { namespace Shader::Backend::GLASM {
namespace {
std::string_view InterpDecorator(Interpolation interp) {
switch (interp) {
case Interpolation::Smooth:
return "";
case Interpolation::Flat:
return "FLAT ";
case Interpolation::NoPerspective:
return "NOPERSPECTIVE ";
}
throw InvalidArgument("Invalid interpolation {}", interp);
}
} // Anonymous namespace
EmitContext::EmitContext(IR::Program& program) { EmitContext::EmitContext(IR::Program& program) {
// FIXME: Temporary partial implementation // FIXME: Temporary partial implementation
@ -42,6 +57,28 @@ EmitContext::EmitContext(IR::Program& program) {
stage_name = "compute"; stage_name = "compute";
break; break;
} }
for (size_t index = 0; index < program.info.input_generics.size(); ++index) {
const auto& generic{program.info.input_generics[index]};
if (generic.used) {
Add("{}ATTRIB in_attr{}[]={{{}.attrib[{}..{}]}};",
InterpDecorator(generic.interpolation), index, stage_name, index, index);
}
}
for (size_t index = 0; index < program.info.stores_frag_color.size(); ++index) {
if (!program.info.stores_frag_color[index]) {
continue;
}
if (index == 0) {
Add("OUTPUT frag_color0=result.color;");
} else {
Add("OUTPUT frag_color{}[]=result.color[{}];", index, index);
}
}
for (size_t index = 0; index < program.info.stores_generics.size(); ++index) {
if (program.info.stores_generics[index]) {
Add("OUTPUT out_attr{}[]={{result.attrib[{}..{}]}};", index, index, index);
}
}
} }
} // namespace Shader::Backend::GLASM } // namespace Shader::Backend::GLASM

View File

@ -261,6 +261,12 @@ void EmitCode(EmitContext& ctx, const IR::Program& program) {
} }
void SetupOptions(std::string& header, Info info) { void SetupOptions(std::string& header, Info info) {
// TODO: Track the shared atomic ops
header += "OPTION NV_internal;"
"OPTION NV_shader_storage_buffer;"
"OPTION NV_gpu_program_fp64;"
"OPTION NV_bindless_texture;"
"OPTION ARB_derivative_control;";
if (info.uses_int64_bit_atomics) { if (info.uses_int64_bit_atomics) {
header += "OPTION NV_shader_atomic_int64;"; header += "OPTION NV_shader_atomic_int64;";
} }
@ -276,10 +282,25 @@ void SetupOptions(std::string& header, Info info) {
if (info.uses_subgroup_shuffles) { if (info.uses_subgroup_shuffles) {
header += "OPTION NV_shader_thread_shuffle;"; header += "OPTION NV_shader_thread_shuffle;";
} }
// TODO: Track the shared atomic ops }
header += "OPTION NV_shader_storage_buffer;"
"OPTION NV_gpu_program_fp64;" std::string_view StageHeader(Stage stage) {
"OPTION NV_bindless_texture;"; switch (stage) {
case Stage::VertexA:
case Stage::VertexB:
return "!!NVvp5.0\n";
case Stage::TessellationControl:
return "!!NVtcs5.0\n";
case Stage::TessellationEval:
return "!!NVtes5.0\n";
case Stage::Geometry:
return "!!NVgp5.0\n";
case Stage::Fragment:
return "!!NVfp5.0\n";
case Stage::Compute:
return "!!NVcp5.0\n";
}
throw InvalidArgument("Invalid stage {}", stage);
} }
} // Anonymous namespace } // Anonymous namespace
@ -287,8 +308,7 @@ std::string EmitGLASM(const Profile&, IR::Program& program, Bindings&) {
EmitContext ctx{program}; EmitContext ctx{program};
Precolor(ctx, program); Precolor(ctx, program);
EmitCode(ctx, program); EmitCode(ctx, program);
std::string header = "!!NVcp5.0\n" std::string header{StageHeader(program.stage)};
"OPTION NV_internal;";
SetupOptions(header, program.info); SetupOptions(header, program.info);
switch (program.stage) { switch (program.stage) {
case Stage::Compute: case Stage::Compute: