spirv: Extract vtn_handle_debug_text() helper
authorCaio Oliveira <caio.oliveira@intel.com>
Thu, 11 May 2023 21:32:45 +0000 (14:32 -0700)
committerMarge Bot <emma+marge@anholt.net>
Wed, 17 May 2023 18:27:41 +0000 (18:27 +0000)
This will be later used by gl_spirv handling.

Reviewed-by: Alejandro PiƱeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22973>

src/compiler/spirv/spirv_to_nir.c
src/compiler/spirv/vtn_private.h

index d94c736..11c12ce 100644 (file)
@@ -4497,28 +4497,13 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
                                 const uint32_t *w, unsigned count)
 {
    switch (opcode) {
-   case SpvOpSource: {
-      const char *lang;
-      switch (w[1]) {
-      default:
-      case SpvSourceLanguageUnknown:      lang = "unknown";    break;
-      case SpvSourceLanguageESSL:         lang = "ESSL";       break;
-      case SpvSourceLanguageGLSL:         lang = "GLSL";       break;
-      case SpvSourceLanguageOpenCL_C:     lang = "OpenCL C";   break;
-      case SpvSourceLanguageOpenCL_CPP:   lang = "OpenCL C++"; break;
-      case SpvSourceLanguageHLSL:         lang = "HLSL";       break;
-      }
-
-      uint32_t version = w[2];
-
-      const char *file =
-         (count > 3) ? vtn_value(b, w[3], vtn_value_type_string)->str : "";
-
-      vtn_info("Parsing SPIR-V from %s %u source file %s", lang, version, file);
-
-      b->source_lang = w[1];
+   case SpvOpString:
+   case SpvOpSource:
+   case SpvOpSourceExtension:
+   case SpvOpSourceContinued:
+   case SpvOpModuleProcessed:
+      vtn_handle_debug_text(b, opcode, w, count);
       break;
-   }
 
    case SpvOpExtension: {
       /* Implementing both NV_mesh_shader and EXT_mesh_shader
@@ -4530,11 +4515,6 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
          b->shader->info.mesh.nv = true;
       break;
    }
-   case SpvOpSourceExtension:
-   case SpvOpSourceContinued:
-   case SpvOpModuleProcessed:
-      /* Unhandled, but these are for debug so that's ok. */
-      break;
 
    case SpvOpCapability: {
       SpvCapability cap = w[1];
@@ -5022,11 +5002,6 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
       vtn_handle_entry_point(b, w, count);
       break;
 
-   case SpvOpString:
-      vtn_push_value(b, w[1], vtn_value_type_string)->str =
-         vtn_string_literal(b, &w[2], count - 2, NULL);
-      break;
-
    case SpvOpName:
       b->values[w[1]].name = vtn_string_literal(b, &w[2], count - 2, NULL);
       break;
@@ -5063,6 +5038,50 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
    return true;
 }
 
+void
+vtn_handle_debug_text(struct vtn_builder *b, SpvOp opcode,
+                      const uint32_t *w, unsigned count)
+{
+   switch (opcode) {
+   case SpvOpString:
+      vtn_push_value(b, w[1], vtn_value_type_string)->str =
+         vtn_string_literal(b, &w[2], count - 2, NULL);
+      break;
+
+   case SpvOpSource: {
+      const char *lang;
+      switch (w[1]) {
+      default:
+      case SpvSourceLanguageUnknown:      lang = "unknown";    break;
+      case SpvSourceLanguageESSL:         lang = "ESSL";       break;
+      case SpvSourceLanguageGLSL:         lang = "GLSL";       break;
+      case SpvSourceLanguageOpenCL_C:     lang = "OpenCL C";   break;
+      case SpvSourceLanguageOpenCL_CPP:   lang = "OpenCL C++"; break;
+      case SpvSourceLanguageHLSL:         lang = "HLSL";       break;
+      }
+
+      uint32_t version = w[2];
+
+      const char *file =
+         (count > 3) ? vtn_value(b, w[3], vtn_value_type_string)->str : "";
+
+      vtn_info("Parsing SPIR-V from %s %u source file %s", lang, version, file);
+
+      b->source_lang = w[1];
+      break;
+   }
+
+   case SpvOpSourceExtension:
+   case SpvOpSourceContinued:
+   case SpvOpModuleProcessed:
+      /* Unhandled, but these are for debug so that's ok. */
+      break;
+
+   default:
+      unreachable("Unhandled opcode");
+   }
+}
+
 static void
 vtn_handle_execution_mode(struct vtn_builder *b, struct vtn_value *entry_point,
                           const struct vtn_decoration *mode, UNUSED void *data)
index 4653678..0f55936 100644 (file)
@@ -955,6 +955,9 @@ struct vtn_builder* vtn_create_builder(const uint32_t *words, size_t word_count,
 void vtn_handle_entry_point(struct vtn_builder *b, const uint32_t *w,
                             unsigned count);
 
+void vtn_handle_debug_text(struct vtn_builder *b, SpvOp opcode,
+                           const uint32_t *w, unsigned count);
+
 void vtn_handle_decoration(struct vtn_builder *b, SpvOp opcode,
                            const uint32_t *w, unsigned count);