[Bf-blender-cvs] [5d52da2e65a] tmp-vulkan: Vulkan: Compiler log parsing.

Jeroen Bakker noreply at git.blender.org
Mon Jun 28 17:01:01 CEST 2021


Commit: 5d52da2e65ab8379a297c4bf532ff745906ec86b
Author: Jeroen Bakker
Date:   Mon Jun 28 16:59:11 2021 +0200
Branches: tmp-vulkan
https://developer.blender.org/rB5d52da2e65ab8379a297c4bf532ff745906ec86b

Vulkan: Compiler log parsing.

For the vulkan backend we control the compiler and therefore the log
parsing is much simpler then the OpenGL parsers.

This patch formats the log to a better readable/debuggable format so
developers can quickly detect what needs to be done.

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

M	source/blender/gpu/intern/gpu_shader_log.cc
M	source/blender/gpu/intern/gpu_shader_private.hh
M	source/blender/gpu/vulkan/vk_shader.cc
M	source/blender/gpu/vulkan/vk_shader.hh
M	source/blender/gpu/vulkan/vk_shader_log.cc

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

diff --git a/source/blender/gpu/intern/gpu_shader_log.cc b/source/blender/gpu/intern/gpu_shader_log.cc
index 5859afb7fbf..4ece9e37379 100644
--- a/source/blender/gpu/intern/gpu_shader_log.cc
+++ b/source/blender/gpu/intern/gpu_shader_log.cc
@@ -185,6 +185,34 @@ char *GPULogParser::skip_separators(char *log_line, char sep1, char sep2, char s
   return log_line;
 }
 
+char *GPULogParser::skip_separators(char *log_line, char sep1, char sep2) const
+{
+  while (ELEM(log_line[0], sep1, sep2)) {
+    log_line++;
+  }
+  return log_line;
+}
+
+char *GPULogParser::skip_separator(char *log_line, char sep) const
+{
+  while (ELEM(log_line[0], sep)) {
+    log_line++;
+  }
+  return log_line;
+}
+
+char *GPULogParser::skip_until(char *log_line, char stop_char) const
+{
+  char *cursor = log_line;
+  while (!ELEM(cursor[0], '\n', '\0')) {
+    if (cursor[0] == stop_char) {
+      return cursor;
+    }
+    cursor++;
+  }
+  return log_line;
+}
+
 /** \} */
 
 }  // namespace blender::gpu
diff --git a/source/blender/gpu/intern/gpu_shader_private.hh b/source/blender/gpu/intern/gpu_shader_private.hh
index ebdfc3478f8..7d9ffc90ba6 100644
--- a/source/blender/gpu/intern/gpu_shader_private.hh
+++ b/source/blender/gpu/intern/gpu_shader_private.hh
@@ -123,7 +123,11 @@ class GPULogParser {
                       GPULogItem &log_item,
                       const char *error_msg,
                       const char *warning_msg) const;
+  /* TODO(jbakker): Make variable arguments. */
+  char *skip_separator(char *log_line, char sep) const;
+  char *skip_separators(char *log_line, char sep1, char sep2) const;
   char *skip_separators(char *log_line, char sep1, char sep2, char sep3) const;
+  char *skip_until(char *log_line, char stop_char) const;
 
   MEM_CXX_CLASS_ALLOC_FUNCS("GPULogParser");
 };
diff --git a/source/blender/gpu/vulkan/vk_shader.cc b/source/blender/gpu/vulkan/vk_shader.cc
index 10eef786321..4f2af6093af 100644
--- a/source/blender/gpu/vulkan/vk_shader.cc
+++ b/source/blender/gpu/vulkan/vk_shader.cc
@@ -142,11 +142,19 @@ static std::string combine_sources(Span<const char *> sources)
   }
   return combined.str();
 }
-static std::string glsl_patch_get()
+static char *glsl_patch_get()
 {
-  std::stringstream patch;
-  patch << "#version 330\n";
-  return patch.str();
+  static char patch[512] = "\0";
+  if (patch[0] != '\0') {
+    return patch;
+  }
+
+  size_t slen = 0;
+  /* Version need to go first. */
+  STR_CONCAT(patch, slen, "#version 330\n");
+
+  BLI_assert(slen < sizeof(patch));
+  return patch;
 }
 
 std::unique_ptr<std::vector<uint32_t>> VKShader::compile_source(Span<const char *> sources,
@@ -201,7 +209,7 @@ VkShaderModule VKShader::create_shader_module(MutableSpan<const char *> sources,
                                               VKShaderStageType stage)
 {
   /* Patch the shader code using the first source slot. */
-  sources[0] = glsl_patch_get().c_str();
+  sources[0] = glsl_patch_get();
 
   std::unique_ptr<std::vector<uint32_t>> code = compile_source(sources, stage);
   if (!code || code->size() == 0) {
@@ -247,7 +255,7 @@ void VKShader::fragment_shader_from_glsl(MutableSpan<const char *> sources)
 void VKShader::compute_shader_from_glsl(MutableSpan<const char *> sources)
 {
 #ifdef WITH_VULKAN_SHADER_COMPILATION
-  compute_shader_ = this->create_shader_module(sources, VKShaderStageType::Compute);
+  compute_shader_ = this->create_shader_module(sources, VKShaderStageType::ComputeShader);
 #endif
 }
 
diff --git a/source/blender/gpu/vulkan/vk_shader.hh b/source/blender/gpu/vulkan/vk_shader.hh
index 24cfd0dd802..6376b17079d 100644
--- a/source/blender/gpu/vulkan/vk_shader.hh
+++ b/source/blender/gpu/vulkan/vk_shader.hh
@@ -105,7 +105,7 @@ class VKLogParser : public GPULogParser {
   char *parse_line(char *log_line, GPULogItem &log_item) override;
 
  protected:
-  char *skip_severity_prefix(char *log_line, GPULogItem &log_item);
+  char *skip_name_and_stage(char *log_line);
   char *skip_severity_keyword(char *log_line, GPULogItem &log_item);
 
   MEM_CXX_CLASS_ALLOC_FUNCS("GLLogParser");
diff --git a/source/blender/gpu/vulkan/vk_shader_log.cc b/source/blender/gpu/vulkan/vk_shader_log.cc
index e0b210e9ad2..4a5e752a0cb 100644
--- a/source/blender/gpu/vulkan/vk_shader_log.cc
+++ b/source/blender/gpu/vulkan/vk_shader_log.cc
@@ -29,54 +29,32 @@ namespace blender::gpu {
 
 char *VKLogParser::parse_line(char *log_line, GPULogItem &log_item)
 {
-  /* Skip ERROR: or WARNING:. */
-  log_line = skip_severity_prefix(log_line, log_item);
-  log_line = skip_separators(log_line, ':', '(', ' ');
+  log_line = skip_name_and_stage(log_line);
+  log_line = skip_separator(log_line, ':');
 
   /* Parse error line & char numbers. */
   if (log_line[0] >= '0' && log_line[0] <= '9') {
     char *error_line_number_end;
     log_item.cursor.row = (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] != ' ') {
-      log_item.cursor.column = (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') {
-      log_item.cursor.source = log_item.cursor.row;
-      log_item.cursor.row = log_item.cursor.column;
-      log_item.cursor.column = (int)strtol(log_line + 1, &error_line_number_end, 10);
-      log_line = error_line_number_end;
-    }
+    log_line = error_line_number_end;
   }
-
-  if ((log_item.cursor.row != -1) && (log_item.cursor.column != -1)) {
-    if (GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_OFFICIAL) ||
-        GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_MAC, GPU_DRIVER_OFFICIAL)) {
-      /* 0:line */
-      log_item.cursor.row = log_item.cursor.column;
-      log_item.cursor.column = -1;
-    }
-    else {
-      /* line:char */
-    }
-  }
-
-  log_line = skip_separators(log_line, ':', ')', ' ');
+  log_line = skip_separators(log_line, ':', ' ');
 
   /* Skip to message. Avoid redundant info. */
   log_line = skip_severity_keyword(log_line, log_item);
-  log_line = skip_separators(log_line, ':', ')', ' ');
+  log_line = skip_separators(log_line, ':', ' ');
 
   return log_line;
 }
 
-char *VKLogParser::skip_severity_prefix(char *log_line, GPULogItem &log_item)
+char *VKLogParser::skip_name_and_stage(char *log_line)
 {
-  return skip_severity(log_line, log_item, "ERROR", "WARNING");
+  char *name_skip = skip_until(log_line, '.');
+  if (name_skip == log_line) {
+    return log_line;
+  }
+
+  return skip_until(name_skip, ':');
 }
 
 char *VKLogParser::skip_severity_keyword(char *log_line, GPULogItem &log_item)



More information about the Bf-blender-cvs mailing list