summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/backend')
-rw-r--r--src/shader_recompiler/backend/glsl/emit_context.cpp30
-rw-r--r--src/shader_recompiler/backend/glsl/emit_context.h1
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_special.cpp3
3 files changed, 27 insertions, 7 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp
index 0d7f7bc3b..36527bbd4 100644
--- a/src/shader_recompiler/backend/glsl/emit_context.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_context.cpp
@@ -236,6 +236,9 @@ void SetupOutPerVertex(EmitContext& ctx, std::string& header) {
236 if (!StoresPerVertexAttributes(ctx.stage)) { 236 if (!StoresPerVertexAttributes(ctx.stage)) {
237 return; 237 return;
238 } 238 }
239 if (ctx.uses_geometry_passthrough) {
240 return;
241 }
239 header += "out gl_PerVertex{vec4 gl_Position;"; 242 header += "out gl_PerVertex{vec4 gl_Position;";
240 if (ctx.info.stores[IR::Attribute::PointSize]) { 243 if (ctx.info.stores[IR::Attribute::PointSize]) {
241 header += "float gl_PointSize;"; 244 header += "float gl_PointSize;";
@@ -272,12 +275,13 @@ void SetupLegacyInPerFragment(EmitContext& ctx, std::string& header) {
272 275
273EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_, 276EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_,
274 const RuntimeInfo& runtime_info_) 277 const RuntimeInfo& runtime_info_)
275 : info{program.info}, profile{profile_}, runtime_info{runtime_info_} { 278 : info{program.info}, profile{profile_}, runtime_info{runtime_info_}, stage{program.stage},
279 uses_geometry_passthrough{program.is_geometry_passthrough &&
280 profile.support_geometry_shader_passthrough} {
276 if (profile.need_fastmath_off) { 281 if (profile.need_fastmath_off) {
277 header += "#pragma optionNV(fastmath off)\n"; 282 header += "#pragma optionNV(fastmath off)\n";
278 } 283 }
279 SetupExtensions(); 284 SetupExtensions();
280 stage = program.stage;
281 switch (program.stage) { 285 switch (program.stage) {
282 case Stage::VertexA: 286 case Stage::VertexA:
283 case Stage::VertexB: 287 case Stage::VertexB:
@@ -295,10 +299,17 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
295 break; 299 break;
296 case Stage::Geometry: 300 case Stage::Geometry:
297 stage_name = "gs"; 301 stage_name = "gs";
298 header += fmt::format("layout({})in;layout({},max_vertices={})out;" 302 header += fmt::format("layout({})in;", InputPrimitive(runtime_info.input_topology));
299 "in gl_PerVertex{{vec4 gl_Position;}}gl_in[];", 303 if (uses_geometry_passthrough) {
300 InputPrimitive(runtime_info.input_topology), 304 header += "layout(passthrough)in gl_PerVertex{vec4 gl_Position;};";
301 OutputPrimitive(program.output_topology), program.output_vertices); 305 break;
306 } else if (program.is_geometry_passthrough &&
307 !profile.support_geometry_shader_passthrough) {
308 LOG_WARNING(Shader_GLSL, "Passthrough geometry program used but not supported");
309 }
310 header += fmt::format(
311 "layout({},max_vertices={})out;in gl_PerVertex{{vec4 gl_Position;}}gl_in[];",
312 OutputPrimitive(program.output_topology), program.output_vertices);
302 break; 313 break;
303 case Stage::Fragment: 314 case Stage::Fragment:
304 stage_name = "fs"; 315 stage_name = "fs";
@@ -329,7 +340,9 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
329 if (!info.loads.Generic(index) || !runtime_info.previous_stage_stores.Generic(index)) { 340 if (!info.loads.Generic(index) || !runtime_info.previous_stage_stores.Generic(index)) {
330 continue; 341 continue;
331 } 342 }
332 header += fmt::format("layout(location={}){}in vec4 in_attr{}{};", index, 343 const auto qualifier{uses_geometry_passthrough ? "passthrough"
344 : fmt::format("location={}", index)};
345 header += fmt::format("layout({}){}in vec4 in_attr{}{};", qualifier,
333 InterpDecorator(info.interpolation[index]), index, 346 InterpDecorator(info.interpolation[index]), index,
334 InputArrayDecorator(stage)); 347 InputArrayDecorator(stage));
335 } 348 }
@@ -412,6 +425,9 @@ void EmitContext::SetupExtensions() {
412 if (info.uses_derivatives && profile.support_gl_derivative_control) { 425 if (info.uses_derivatives && profile.support_gl_derivative_control) {
413 header += "#extension GL_ARB_derivative_control : enable\n"; 426 header += "#extension GL_ARB_derivative_control : enable\n";
414 } 427 }
428 if (uses_geometry_passthrough) {
429 header += "#extension GL_NV_geometry_shader_passthrough : enable\n";
430 }
415} 431}
416 432
417void EmitContext::DefineConstantBuffers(Bindings& bindings) { 433void EmitContext::DefineConstantBuffers(Bindings& bindings) {
diff --git a/src/shader_recompiler/backend/glsl/emit_context.h b/src/shader_recompiler/backend/glsl/emit_context.h
index ecdf6e5bc..dd7397489 100644
--- a/src/shader_recompiler/backend/glsl/emit_context.h
+++ b/src/shader_recompiler/backend/glsl/emit_context.h
@@ -157,6 +157,7 @@ public:
157 157
158 bool uses_y_direction{}; 158 bool uses_y_direction{};
159 bool uses_cc_carry{}; 159 bool uses_cc_carry{};
160 bool uses_geometry_passthrough{};
160 161
161private: 162private:
162 void SetupExtensions(); 163 void SetupExtensions();
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp
index 298881c7b..9b866f889 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp
@@ -17,6 +17,9 @@ std::string_view OutputVertexIndex(EmitContext& ctx) {
17} 17}
18 18
19void InitializeOutputVaryings(EmitContext& ctx) { 19void InitializeOutputVaryings(EmitContext& ctx) {
20 if (ctx.uses_geometry_passthrough) {
21 return;
22 }
20 if (ctx.stage == Stage::VertexB || ctx.stage == Stage::Geometry) { 23 if (ctx.stage == Stage::VertexB || ctx.stage == Stage::Geometry) {
21 ctx.Add("gl_Position=vec4(0,0,0,1);"); 24 ctx.Add("gl_Position=vec4(0,0,0,1);");
22 } 25 }