Browse Source

shaderpipeline: Add glsl-force-legacy-pipeline config option

rdb 1 year ago
parent
commit
e1b0d18af0

+ 0 - 16
panda/src/gobj/config_gobj.cxx

@@ -545,22 +545,6 @@ ConfigVariableBool stereo_lens_old_convergence
           "old, incorrect behavior, this may be set to 'true' to switch "
           "back to the old calculation."));
 
-ConfigVariableBool glsl_preprocess
-("glsl-preprocess", true,
- PRC_DESC("If this is enabled, Panda looks for lines starting with "
-          "#pragma include when loading a GLSL shader and processes "
-          "it appropriately.  This can be useful if you have code that "
-          "is shared between multiple shaders.  Set this to false if "
-          "you have no need for this feature or if you do your own "
-          "preprocessing of GLSL shaders."));
-
-ConfigVariableInt glsl_include_recursion_limit
-("glsl-include-recursion-limit", 10,
- PRC_DESC("This sets a limit on how many nested #pragma include "
-          "directives that Panda will follow when glsl-preprocess is "
-          "enabled.  This is used to prevent infinite recursion when "
-          "two shader files include each other."));
-
 ConfigureFn(config_gobj) {
   AnimateVerticesRequest::init_type();
   BufferContext::init_type();

+ 0 - 3
panda/src/gobj/config_gobj.h

@@ -91,7 +91,4 @@ extern EXPCL_PANDA_GOBJ ConfigVariableDouble async_load_delay;
 extern EXPCL_PANDA_GOBJ ConfigVariableInt lens_geom_segments;
 extern EXPCL_PANDA_GOBJ ConfigVariableBool stereo_lens_old_convergence;
 
-extern EXPCL_PANDA_GOBJ ConfigVariableBool glsl_preprocess;
-extern EXPCL_PANDA_GOBJ ConfigVariableInt glsl_include_recursion_limit;
-
 #endif

+ 27 - 0
panda/src/shaderpipeline/config_shaderpipeline.cxx

@@ -25,6 +25,33 @@
 
 ConfigureDef(config_shaderpipeline);
 
+ConfigVariableBool glsl_preprocess
+("glsl-preprocess", true,
+ PRC_DESC("If this is enabled, Panda looks for lines starting with "
+          "#pragma include when loading a GLSL shader and processes "
+          "it appropriately.  This can be useful if you have code that "
+          "is shared between multiple shaders.  Set this to false if "
+          "you have no need for this feature or if you do your own "
+          "preprocessing of GLSL shaders."));
+
+ConfigVariableBool glsl_force_legacy_pipeline
+("glsl-force-legacy-pipeline", false,
+ PRC_DESC("If this is enabled, Panda will disable the new shader pipeline "
+          "for all GLSL shaders, and all GLSL shaders will instead be "
+          "compiled by the graphics driver.  If you enable this, GLSL shaders "
+          "will only work if the graphics back-end supports that particular "
+          "GLSL version, so this is not recommended.  Use this only if you "
+          "suspect a bug in the new shader pipeline.  Note that GLSL shaders "
+          "before version 150 always use the legacy GLSL pipeline, and Cg "
+          "shaders always use the new pipeline."));
+
+ConfigVariableInt glsl_include_recursion_limit
+("glsl-include-recursion-limit", 10,
+ PRC_DESC("This sets a limit on how many nested #pragma include "
+          "directives that Panda will follow when glsl-preprocess is "
+          "enabled.  This is used to prevent infinite recursion when "
+          "two shader files include each other."));
+
 ConfigureFn(config_shaderpipeline) {
   init_libshaderpipeline();
 }

+ 6 - 0
panda/src/shaderpipeline/config_shaderpipeline.h

@@ -15,10 +15,16 @@
 #define CONFIG_SHADERPIPELINE_H
 
 #include "pandabase.h"
+#include "configVariableBool.h"
+#include "configVariableInt.h"
 #include "dconfig.h"
 
 ConfigureDecl(config_shaderpipeline, EXPCL_PANDA_SHADERPIPELINE, EXPTP_PANDA_SHADERPIPELINE);
 
+extern ConfigVariableBool glsl_preprocess;
+extern ConfigVariableBool glsl_force_legacy_pipeline;
+extern ConfigVariableInt glsl_include_recursion_limit;
+
 extern EXPCL_PANDA_PGRAPH void init_libshaderpipeline();
 
 #endif

+ 18 - 10
panda/src/shaderpipeline/shaderCompilerGlslang.cxx

@@ -205,18 +205,26 @@ compile_now(ShaderModule::Stage stage, std::istream &in,
     }
   }
 
-  if (!is_cg && glsl_version < 310 && glsl_version != 150) {
-    if (glsl_version != 100 && glsl_version != 110 && glsl_version != 120 &&
-        glsl_version != 130 && glsl_version != 140 && glsl_version != 300) {
-      shader_cat.error()
-        << filename << " uses invalid GLSL version " << glsl_version << ".\n";
-      return nullptr;
+  bool use_legacy_pipeline = false;
+  if (!is_cg) {
+    if (glsl_force_legacy_pipeline) {
+      use_legacy_pipeline = true;
     }
+    else if (glsl_version < 310 && glsl_version != 150) {
+      if (glsl_version != 100 && glsl_version != 110 && glsl_version != 120 &&
+          glsl_version != 130 && glsl_version != 140 && glsl_version != 300) {
+        shader_cat.error()
+          << filename << " uses invalid GLSL version " << glsl_version << ".\n";
+        return nullptr;
+      }
+      use_legacy_pipeline = true;
+      shader_cat.warning()
+        << filename << " uses deprecated GLSL version " << glsl_version
+        << ".  Some features may not work.  Minimum supported version is 330 or 310 es.\n";
+    }
+  }
 
-    shader_cat.warning()
-      << filename << " uses deprecated GLSL version " << glsl_version
-      << ".  Some features may not work.  Minimum supported version is 330 or 310 es.\n";
-
+  if (use_legacy_pipeline) {
     // Fall back to GlslPreProc handler.  Cleaner way to do this?
     static ShaderCompilerGlslPreProc preprocessor;