Browse Source

shader: Some fixes for capability detection

rdb 5 years ago
parent
commit
784681e1a1

+ 24 - 1
panda/src/glstuff/glGraphicsStateGuardian_src.cxx

@@ -1682,11 +1682,11 @@ reset() {
   _supported_shader_caps =
       ShaderModule::C_basic_shader |
       ShaderModule::C_vertex_texture |
-      ShaderModule::C_sampler_shadow |
       ShaderModule::C_invariant;
 
   if (is_at_least_gles_version(3, 0)) {
     _supported_shader_caps |=
+      ShaderModule::C_sampler_shadow |
       ShaderModule::C_matrix_non_square |
       ShaderModule::C_integer |
       ShaderModule::C_texture_lod |
@@ -1697,6 +1697,14 @@ reset() {
       ShaderModule::C_instance_id |
       ShaderModule::C_bit_encoding;
   }
+  else {
+    if (has_extension("GL_EXT_shadow_samplers")) {
+      _supported_shader_caps |= ShaderModule::C_sampler_shadow;
+    }
+    if (has_extension("GL_EXT_shader_texture_lod")) {
+      _supported_shader_caps |= ShaderModule::C_texture_lod;
+    }
+  }
 
   if (is_at_least_gles_version(3, 1)) {
     _supported_shader_caps |=
@@ -1767,6 +1775,21 @@ reset() {
         ShaderModule::C_vertex_id |
         ShaderModule::C_round_even;
     }
+    else {
+      if (has_extension("GL_ARB_shader_texture_lod")) {
+        _supported_shader_caps |= ShaderModule::C_texture_lod;
+      }
+      if (has_extension("GL_EXT_gpu_shader4")) {
+        // These are in principle supported, but SPIRV-Cross might need to be
+        // changed to be able to leverage these.  Most cards that have this
+        // extension also support GLSL 1.30, so it might not be worth adding.
+        _supported_shader_caps |=
+          //ShaderModule::C_integer |
+          //ShaderModule::C_texture_fetch |
+          //ShaderModule::C_sampler_cube_shadow |
+          ShaderModule::C_round_even;
+      }
+    }
 
     // OpenGL 3.1
     if (_glsl_version >= 140 || has_extension("GL_ARB_draw_instanced")) {

+ 1 - 1
panda/src/gobj/shaderModule.h

@@ -108,7 +108,7 @@ public:
 
     // GLSL 1.30
     C_integer = 1 << 5,
-    C_texture_lod = 1 << 6, // textureLod, textureGrad, etc.
+    C_texture_lod = 1 << 6, // textureLod in vshader doesn't count, textureGrad does
     C_texture_fetch = 1 << 7, // texelFetch, textureSize, etc.
     C_sampler_cube_shadow = 1 << 8,
     C_vertex_id = 1 << 9,

+ 8 - 2
panda/src/shaderpipeline/shaderModuleSpirV.cxx

@@ -213,7 +213,10 @@ ShaderModuleSpirV(Stage stage, std::vector<uint32_t> words) :
 
     case spv::OpImageSampleExplicitLod:
     case spv::OpImageSampleProjExplicitLod:
-      _used_caps |= C_texture_lod;
+      if (stage != Stage::vertex) {
+        // TODO: check grad
+        _used_caps |= C_texture_lod;
+      }
       // fall through
     case spv::OpImageSampleImplicitLod:
     case spv::OpImageSampleProjImplicitLod:
@@ -224,7 +227,10 @@ ShaderModuleSpirV(Stage stage, std::vector<uint32_t> words) :
 
     case spv::OpImageSampleDrefExplicitLod:
     case spv::OpImageSampleProjDrefExplicitLod:
-      _used_caps |= C_texture_lod;
+      if (stage != Stage::vertex) {
+        // TODO: check grad
+        _used_caps |= C_texture_lod;
+      }
       // fall through
     case spv::OpImageSampleDrefImplicitLod:
     case spv::OpImageSampleProjDrefImplicitLod: