diff options
author | Marcin Ĺšlusarz <marcin.slusarz@intel.com> | 2021-11-24 12:09:51 +0100 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2021-12-01 08:56:29 +0000 |
commit | 4f58cc82e2fcfa7e4633562e2895ba0d75acedbd (patch) | |
tree | 2b68ff7876e466f16d882159a33377c617b7e3b6 | |
parent | 8e568d3f00b31344bc86a7ee1d8e57eb430314a5 (diff) |
spirv: handle SpvOpMemberName
Now we can see field names in structs instead of generic
"fieldN" with NIR_PRINT=1.
Reviewed-by: Caio Oliveira <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13941>
-rw-r--r-- | .gitlab-ci/windows/spirv2dxil_reference.txt | 4 | ||||
-rw-r--r-- | src/compiler/spirv/spirv_to_nir.c | 31 | ||||
-rw-r--r-- | src/compiler/spirv/vtn_private.h | 16 |
3 files changed, 41 insertions, 10 deletions
diff --git a/.gitlab-ci/windows/spirv2dxil_reference.txt b/.gitlab-ci/windows/spirv2dxil_reference.txt index e224911cc70..5d97b3ba61c 100644 --- a/.gitlab-ci/windows/spirv2dxil_reference.txt +++ b/.gitlab-ci/windows/spirv2dxil_reference.txt @@ -1272,11 +1272,11 @@ Test:SpvParserTest_Impl_GenericVulkanShader_GLSL450MemoryModel.spvasm:main|GLCom Test:SpvParserTest_Impl_GenericVulkanShader_SimpleMemoryModel.spvasm:main|GLCompute: Pass
Test:SpvParserTest_Impl_GenericVulkanShader_VulkanMemoryModel.spvasm:main|GLCompute: Fail
SPIR-V WARNING:
- In file ../src/compiler/spirv/spirv_to_nir.c:4663
+ In file ../src/compiler/spirv/spirv_to_nir.c:4687
Unsupported SPIR-V capability: SpvCapabilityVulkanMemoryModel (5345)
28 bytes into the SPIR-V binary
SPIR-V parsing FAILED:
- In file ../src/compiler/spirv/spirv_to_nir.c:4817
+ In file ../src/compiler/spirv/spirv_to_nir.c:4841
Vulkan memory model is unsupported by this driver
68 bytes into the SPIR-V binary
Compilation failed
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index f78205d6962..aa4f3ac9028 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -597,7 +597,8 @@ _foreach_decoration_helper(struct vtn_builder *b, member, base_value->type->length); } else { /* Not a decoration */ - assert(dec->scope == VTN_DEC_EXECUTION_MODE); + assert(dec->scope == VTN_DEC_EXECUTION_MODE || + dec->scope <= VTN_DEC_STRUCT_MEMBER_NAME0); continue; } @@ -688,6 +689,19 @@ vtn_handle_decoration(struct vtn_builder *b, SpvOp opcode, break; } + case SpvOpMemberName: { + struct vtn_value *val = vtn_untyped_value(b, target); + struct vtn_decoration *dec = rzalloc(b, struct vtn_decoration); + + dec->scope = VTN_DEC_STRUCT_MEMBER_NAME0 - *(w++); + + dec->member_name = vtn_string_literal(b, w, w_end - w, NULL); + + dec->next = val->decoration; + val->decoration = dec; + break; + } + case SpvOpGroupMemberDecorate: case SpvOpGroupDecorate: { struct vtn_value *group = @@ -1510,9 +1524,19 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode, NIR_VLA(struct glsl_struct_field, fields, count); for (unsigned i = 0; i < num_fields; i++) { val->type->members[i] = vtn_get_type(b, w[i + 2]); + const char *name = NULL; + for (struct vtn_decoration *dec = val->decoration; dec; dec = dec->next) { + if (dec->scope == VTN_DEC_STRUCT_MEMBER_NAME0 - i) { + name = dec->member_name; + break; + } + } + if (!name) + name = ralloc_asprintf(b, "field%d", i); + fields[i] = (struct glsl_struct_field) { .type = val->type->members[i]->type, - .name = ralloc_asprintf(b, "field%d", i), + .name = name, .location = -1, .offset = -1, }; @@ -4837,9 +4861,6 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode, break; case SpvOpMemberName: - /* TODO */ - break; - case SpvOpExecutionMode: case SpvOpExecutionModeId: case SpvOpDecorationGroup: diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h index a2d2cdcdb16..93985f54f86 100644 --- a/src/compiler/spirv/vtn_private.h +++ b/src/compiler/spirv/vtn_private.h @@ -624,14 +624,23 @@ struct vtn_value { #define VTN_DEC_DECORATION -1 #define VTN_DEC_EXECUTION_MODE -2 +#define VTN_DEC_STRUCT_MEMBER_NAME0 -3 #define VTN_DEC_STRUCT_MEMBER0 0 struct vtn_decoration { struct vtn_decoration *next; - /* Specifies how to apply this decoration. Negative values represent a - * decoration or execution mode. (See the VTN_DEC_ #defines above.) - * Non-negative values specify that it applies to a structure member. + /* Different kinds of decorations are stored in a value, + the scope defines what decoration it refers to: + + - VTN_DEC_DECORATION: + decoration associated with the value + - VTN_DEC_EXECUTION_MODE: + an execution mode associated with an entrypoint value + - VTN_DEC_STRUCT_MEMBER0 + m: + decoration associated with member m of a struct value + - VTN_DEC_STRUCT_MEMBER_NAME0 - m: + name of m'th member of a struct value */ int scope; @@ -641,6 +650,7 @@ struct vtn_decoration { union { SpvDecoration decoration; SpvExecutionMode exec_mode; + const char *member_name; }; }; |