From c4f39f0074a2042ad99643083202ebb9b9abf4b6 Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Thu, 11 May 2023 14:32:45 -0700 Subject: [PATCH] spirv: Extract vtn_handle_debug_text() helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will be later used by gl_spirv handling. Reviewed-by: Alejandro PiƱeiro Part-of: (cherry picked from commit a32f97530a3874d4b3933c591683c3b4a60306f5) --- .pick_status.json | 2 +- src/compiler/spirv/spirv_to_nir.c | 81 +++++++++++++++++++------------ src/compiler/spirv/vtn_private.h | 3 ++ 3 files changed, 54 insertions(+), 32 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 1207ee30dbf..f07048c7513 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -6502,7 +6502,7 @@ "description": "spirv: Extract vtn_handle_debug_text() helper", "nominated": false, "nomination_type": null, - "resolution": 4, + "resolution": 1, "main_sha": null, "because_sha": null }, diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index 5cb7691506e..0adcf78136a 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -4452,28 +4452,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 @@ -4485,11 +4470,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]; @@ -4971,11 +4951,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; @@ -5012,6 +4987,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) diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h index bd65a60d9bd..b1ec64defea 100644 --- a/src/compiler/spirv/vtn_private.h +++ b/src/compiler/spirv/vtn_private.h @@ -1015,6 +1015,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);