[Bf-blender-cvs] [85a290b09d2] tmp-gpu-shader-descriptor-2: Fail compilation when a shader can't be compiled.

Jeroen Bakker noreply at git.blender.org
Fri Jan 7 08:54:33 CET 2022


Commit: 85a290b09d220427b08c13a5be7b66689957cbaf
Author: Jeroen Bakker
Date:   Fri Jan 7 08:52:52 2022 +0100
Branches: tmp-gpu-shader-descriptor-2
https://developer.blender.org/rB85a290b09d220427b08c13a5be7b66689957cbaf

Fail compilation when a shader can't be compiled.

===================================================================

M	source/blender/gpu/intern/gpu_shader.cc
M	source/blender/gpu/intern/gpu_shader_builder.cc
M	source/blender/gpu/intern/gpu_shader_create_info.cc
M	source/blender/gpu/intern/gpu_shader_create_info_private.hh

===================================================================

diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc
index 95879eb8e06..3c2faa59b14 100644
--- a/source/blender/gpu/intern/gpu_shader.cc
+++ b/source/blender/gpu/intern/gpu_shader.cc
@@ -409,12 +409,10 @@ GPUShader *GPU_shader_create_from_info(const GPUShaderCreateInfo *_info)
 
   shader->finalize(&info);
 
-  delete shader;
-  return nullptr;
-  // if (!shader->finalize()) {
-  //   delete shader;
-  //   return nullptr;
-  // }
+  if (!shader->finalize()) {
+    delete shader;
+    return nullptr;
+  }
 
   return wrap(shader);
 }
diff --git a/source/blender/gpu/intern/gpu_shader_builder.cc b/source/blender/gpu/intern/gpu_shader_builder.cc
index 2a99bbf94fc..334bdb2ec58 100644
--- a/source/blender/gpu/intern/gpu_shader_builder.cc
+++ b/source/blender/gpu/intern/gpu_shader_builder.cc
@@ -43,13 +43,13 @@ class ShaderBuilder {
 
  public:
   void init();
-  void bake_create_infos();
+  bool bake_create_infos();
   void exit();
 };
 
-void ShaderBuilder::bake_create_infos()
+bool ShaderBuilder::bake_create_infos()
 {
-  gpu_shader_create_info_compile_all();
+  return gpu_shader_create_info_compile_all();
 }
 
 void ShaderBuilder::init()
@@ -88,10 +88,15 @@ int main(int argc, const char *argv[])
     exit(1);
   }
 
+  int exit_code = 0;
+
   blender::gpu::shader_builder::ShaderBuilder builder;
   builder.init();
-  builder.bake_create_infos();
+  if (!builder.bake_create_infos()) {
+    exit_code = 1;
+  }
   builder.exit();
+  exit(exit_code);
 
-  return 0;
+  return exit_code;
 }
diff --git a/source/blender/gpu/intern/gpu_shader_create_info.cc b/source/blender/gpu/intern/gpu_shader_create_info.cc
index 7dafa077bd2..3ff83c3714c 100644
--- a/source/blender/gpu/intern/gpu_shader_create_info.cc
+++ b/source/blender/gpu/intern/gpu_shader_create_info.cc
@@ -148,18 +148,22 @@ void gpu_shader_create_info_exit()
   delete g_interfaces;
 }
 
-void gpu_shader_create_info_compile_all()
+bool gpu_shader_create_info_compile_all()
 {
   for (ShaderCreateInfo *info : g_create_infos->values()) {
     if (info->do_static_compilation_) {
-      printf("Compiling %s: ... ", info->name_.c_str());
-      GPU_shader_create_from_info(reinterpret_cast<const GPUShaderCreateInfo *>(info));
-      printf("Success\n");
-    }
-    else {
-      printf("Skipping non static %s\n", info->name_.c_str());
+      // printf("Compiling %s: ... \n", info->name_.c_str());
+      GPUShader *shader = GPU_shader_create_from_info(
+          reinterpret_cast<const GPUShaderCreateInfo *>(info));
+      if (shader == nullptr) {
+        printf("Compilation %s Failed\n", info->name_.c_str());
+        return false;
+      }
+      GPU_shader_free(shader);
+      // printf("Success\n");
     }
   }
+  return true;
 }
 
 /* Runtime create infos are not registered in the dictionnary and cannot be searched. */
diff --git a/source/blender/gpu/intern/gpu_shader_create_info_private.hh b/source/blender/gpu/intern/gpu_shader_create_info_private.hh
index c3a73acb6f7..7010fa5e3a2 100644
--- a/source/blender/gpu/intern/gpu_shader_create_info_private.hh
+++ b/source/blender/gpu/intern/gpu_shader_create_info_private.hh
@@ -37,7 +37,7 @@ extern "C" {
 void gpu_shader_create_info_init(void);
 void gpu_shader_create_info_exit(void);
 
-void gpu_shader_create_info_compile_all(void);
+bool gpu_shader_create_info_compile_all(void);
 
 const GPUShaderCreateInfo *gpu_shader_create_info_get(const char *info_name);



More information about the Bf-blender-cvs mailing list