[Bf-blender-cvs] [0493a328032] tmp-vulkan: Initial SpirV log parsing.

Jeroen Bakker noreply at git.blender.org
Fri Jun 25 16:53:34 CEST 2021


Commit: 0493a328032891bc40e992e031a4a4b36aa2bead
Author: Jeroen Bakker
Date:   Fri Jun 25 16:53:07 2021 +0200
Branches: tmp-vulkan
https://developer.blender.org/rB0493a328032891bc40e992e031a4a4b36aa2bead

Initial SpirV log parsing.

Still work in progress.

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

M	source/blender/gpu/intern/gpu_shader.cc
M	source/blender/gpu/vulkan/vk_shader.cc
M	source/blender/gpu/vulkan/vk_shader.hh

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

diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc
index bb657ff1645..39f1e1f54e8 100644
--- a/source/blender/gpu/intern/gpu_shader.cc
+++ b/source/blender/gpu/intern/gpu_shader.cc
@@ -89,37 +89,65 @@ void Shader::print_log(Span<const char *> sources, char *log, const char *stage,
     }
     /* 0 = error, 1 = warning. */
     int type = -1;
-    /* Skip ERROR: or WARNING:. */
-    const char *prefix[] = {"ERROR", "WARNING"};
-    for (int i = 0; i < ARRAY_SIZE(prefix); i++) {
-      if (STREQLEN(log_line, prefix[i], strlen(prefix[i]))) {
-        log_line += strlen(prefix[i]);
-        type = i;
-        break;
-      }
-    }
-    /* Skip whitespaces and separators. */
-    while (ELEM(log_line[0], ':', '(', ' ')) {
-      log_line++;
-    }
     /* Parse error line & char numbers. */
     error_line = error_char = -1;
-    if (log_line[0] >= '0' && log_line[0] <= '9') {
-      error_line = (int)strtol(log_line, &error_line_number_end, 10);
-      /* Try to fetch the error character (not always available). */
-      if (ELEM(error_line_number_end[0], '(', ':') && error_line_number_end[1] != ' ') {
-        error_char = (int)strtol(error_line_number_end + 1, &log_line, 10);
+
+    /* SpirV log starts with the `shader name.stage name` */
+    /* TODO(jbakker): Use virtual functions and common data structure for parsing. */
+    /* TODO(jbakker): SpirV loglines are off by one. */
+    if (STREQLEN(log_line, name, strlen(name))) {
+      log_line += strlen(name);
+      while (ELEM(log_line[0], '.')) {
+        log_line++;
       }
-      else {
-        log_line = error_line_number_end;
+      log_line += strlen(stage);
+
+      /* Skip whitespaces and separators. */
+      while (ELEM(log_line[0], ':', '(', ' ')) {
+        log_line++;
       }
-      /* There can be a 3rd number (case of mesa driver). */
-      if (ELEM(log_line[0], '(', ':') && log_line[1] >= '0' && log_line[1] <= '9') {
-        error_line = error_char;
-        error_char = (int)strtol(log_line + 1, &error_line_number_end, 10);
-        log_line = error_line_number_end;
+
+      if (log_line[0] >= '0' && log_line[0] <= '9') {
+        error_line = (int)strtol(log_line, &error_line_number_end, 10);
+      }
+
+      while (ELEM(log_line[0], ':', '(', ' ')) {
+        log_line++;
       }
     }
+    else {
+      /* Skip ERROR: or WARNING:. */
+      const char *prefix[] = {"ERROR", "WARNING"};
+      for (int i = 0; i < ARRAY_SIZE(prefix); i++) {
+        if (STREQLEN(log_line, prefix[i], strlen(prefix[i]))) {
+          log_line += strlen(prefix[i]);
+          type = i;
+          break;
+        }
+      }
+      /* Skip whitespaces and separators. */
+      while (ELEM(log_line[0], ':', '(', ' ')) {
+        log_line++;
+      }
+      /* Parse error line & char numbers. */
+      if (log_line[0] >= '0' && log_line[0] <= '9') {
+        error_line = (int)strtol(log_line, &error_line_number_end, 10);
+        /* Try to fetch the error character (not always available). */
+        if (ELEM(error_line_number_end[0], '(', ':') && error_line_number_end[1] != ' ') {
+          error_char = (int)strtol(error_line_number_end + 1, &log_line, 10);
+        }
+        else {
+          log_line = error_line_number_end;
+        }
+        /* There can be a 3rd number (case of mesa driver). */
+        if (ELEM(log_line[0], '(', ':') && log_line[1] >= '0' && log_line[1] <= '9') {
+          error_line = error_char;
+          error_char = (int)strtol(log_line + 1, &error_line_number_end, 10);
+          log_line = error_line_number_end;
+        }
+      }
+    }
+
     /* Skip whitespaces and separators. */
     while (ELEM(log_line[0], ':', ')', ' ')) {
       log_line++;
@@ -198,7 +226,7 @@ void Shader::print_log(Span<const char *> sources, char *log, const char *stage,
     BLI_dynstr_appendf(dynstr, line_prefix);
     /* Skip to message. Avoid redundant info. */
     const char *keywords[] = {"error", "warning"};
-    for (int i = 0; i < ARRAY_SIZE(prefix); i++) {
+    for (int i = 0; i < ARRAY_SIZE(keywords); i++) {
       if (STREQLEN(log_line, keywords[i], strlen(keywords[i]))) {
         log_line += strlen(keywords[i]);
         type = i;
diff --git a/source/blender/gpu/vulkan/vk_shader.cc b/source/blender/gpu/vulkan/vk_shader.cc
index 4d6b8b1413a..e8928640046 100644
--- a/source/blender/gpu/vulkan/vk_shader.cc
+++ b/source/blender/gpu/vulkan/vk_shader.cc
@@ -135,11 +135,11 @@ static std::string to_stage_name(StringRef name, VKShaderStageType stage)
   return ss.str();
 }
 
-static std::string combine_sources(MutableSpan<const char *> sources)
+static std::string combine_sources(Span<const char *> sources)
 {
   std::stringstream combined;
-  for (std::string source : sources) {
-    combined << source;
+  for (int i = 0; i < sources.size(); i++) {
+    combined << sources[i];
   }
   return combined.str();
 }
@@ -150,7 +150,7 @@ static std::string glsl_patch_get()
   return patch.str();
 }
 
-std::unique_ptr<std::vector<uint32_t>> VKShader::compile_source(MutableSpan<const char *> sources,
+std::unique_ptr<std::vector<uint32_t>> VKShader::compile_source(Span<const char *> sources,
                                                                 VKShaderStageType stage)
 {
   std::string stage_name = to_stage_name(name, stage);
@@ -159,7 +159,7 @@ std::unique_ptr<std::vector<uint32_t>> VKShader::compile_source(MutableSpan<cons
 
   shader_compiler::Compiler *compiler = shader_compiler::Compiler::create_default();
   shader_compiler::Job job;
-  job.name = name;
+  job.name = stage_name;
   job.source = source;
   job.compilation_target = shader_compiler::TargetType::SpirV;
   job.source_type = to_source_type(stage);
diff --git a/source/blender/gpu/vulkan/vk_shader.hh b/source/blender/gpu/vulkan/vk_shader.hh
index 584a89ce3ef..3b7e3b6da49 100644
--- a/source/blender/gpu/vulkan/vk_shader.hh
+++ b/source/blender/gpu/vulkan/vk_shader.hh
@@ -92,7 +92,7 @@ class VKShader : public Shader {
   }
 
  private:
-  std::unique_ptr<std::vector<uint32_t>> compile_source(MutableSpan<const char *> sources,
+  std::unique_ptr<std::vector<uint32_t>> compile_source(Span<const char *> sources,
                                                         VKShaderStageType stage);
   VkShaderModule create_shader_module(MutableSpan<const char *> sources, VKShaderStageType stage);



More information about the Bf-blender-cvs mailing list