summaryrefslogtreecommitdiffstats
path: root/src/shader_recompiler/backend/glsl/emit_context.cpp
diff options
context:
space:
mode:
authorameerj <52414509+ameerj@users.noreply.github.com>2021-05-31 19:28:53 +0200
committerameerj <52414509+ameerj@users.noreply.github.com>2021-07-23 03:51:37 +0200
commit19247ba4fad59b3d821b099dfbcd60e985041249 (patch)
treec30455f98fa5c2fe5b5febdc4baabb61db3fd293 /src/shader_recompiler/backend/glsl/emit_context.cpp
parentglsl: Use NotImplemented macro with function name output (diff)
downloadyuzu-19247ba4fad59b3d821b099dfbcd60e985041249.tar
yuzu-19247ba4fad59b3d821b099dfbcd60e985041249.tar.gz
yuzu-19247ba4fad59b3d821b099dfbcd60e985041249.tar.bz2
yuzu-19247ba4fad59b3d821b099dfbcd60e985041249.tar.lz
yuzu-19247ba4fad59b3d821b099dfbcd60e985041249.tar.xz
yuzu-19247ba4fad59b3d821b099dfbcd60e985041249.tar.zst
yuzu-19247ba4fad59b3d821b099dfbcd60e985041249.zip
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_context.cpp')
-rw-r--r--src/shader_recompiler/backend/glsl/emit_context.cpp50
1 files changed, 46 insertions, 4 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp
index 2a5ec7414..923060386 100644
--- a/src/shader_recompiler/backend/glsl/emit_context.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_context.cpp
@@ -21,6 +21,15 @@ std::string_view InterpDecorator(Interpolation interp) {
throw InvalidArgument("Invalid interpolation {}", interp);
}
+std::string_view ArrayDecorator(Stage stage) {
+ switch (stage) {
+ case Stage::Geometry:
+ return "[1]";
+ default:
+ return "";
+ }
+}
+
std::string_view SamplerType(TextureType type, bool is_depth) {
if (is_depth) {
switch (type) {
@@ -64,6 +73,33 @@ std::string_view SamplerType(TextureType type, bool is_depth) {
}
}
+std::string_view InputPrimitive(InputTopology topology) {
+ switch (topology) {
+ case InputTopology::Points:
+ return "points";
+ case InputTopology::Lines:
+ return "lines";
+ case InputTopology::LinesAdjacency:
+ return "lines_adjacency";
+ case InputTopology::Triangles:
+ return "triangles";
+ case InputTopology::TrianglesAdjacency:
+ return "triangles_adjacency";
+ }
+ throw InvalidArgument("Invalid input topology {}", topology);
+}
+
+std::string_view OutputPrimitive(OutputTopology topology) {
+ switch (topology) {
+ case OutputTopology::PointList:
+ return "points";
+ case OutputTopology::LineStrip:
+ return "line_strip";
+ case OutputTopology::TriangleStrip:
+ return "triangle_strip";
+ }
+ throw InvalidArgument("Invalid output topology {}", topology);
+}
} // namespace
EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_,
@@ -85,6 +121,9 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
break;
case Stage::Geometry:
stage_name = "gs";
+ header += fmt::format("layout({})in;layout({}, max_vertices={})out;\n",
+ InputPrimitive(runtime_info.input_topology),
+ OutputPrimitive(program.output_topology), program.output_vertices);
break;
case Stage::Fragment:
stage_name = "fs";
@@ -99,8 +138,9 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
for (size_t index = 0; index < info.input_generics.size(); ++index) {
const auto& generic{info.input_generics[index]};
if (generic.used) {
- header += fmt::format("layout(location={}) {} in vec4 in_attr{};", index,
- InterpDecorator(generic.interpolation), index);
+ header +=
+ fmt::format("layout(location={}){} in vec4 in_attr{}{};", index,
+ InterpDecorator(generic.interpolation), index, ArrayDecorator(stage));
}
}
for (size_t index = 0; index < info.stores_frag_color.size(); ++index) {
@@ -126,8 +166,6 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
void EmitContext::SetupExtensions(std::string&) {
// TODO: track this usage
header += "#extension GL_ARB_sparse_texture2 : enable\n";
- header += "#extension GL_ARB_shader_viewport_layer_array : enable\n";
- header += "#extension GL_NV_viewport_array2 : enable\n";
header += "#extension GL_EXT_texture_shadow_lod : enable\n";
if (info.uses_int64) {
header += "#extension GL_ARB_gpu_shader_int64 : enable\n";
@@ -157,6 +195,10 @@ void EmitContext::SetupExtensions(std::string&) {
header += "#extension GL_ARB_gpu_shader_int64 : enable\n";
}
}
+ if (info.stores_viewport_index) {
+ header += "#extension GL_ARB_shader_viewport_layer_array : enable\n";
+ header += "#extension GL_NV_viewport_array2 : enable\n";
+ }
}
void EmitContext::DefineConstantBuffers(Bindings& bindings) {