From fa400d236704396d81b024273dbc6ca0c925d640 Mon Sep 17 00:00:00 2001 From: Mark Segal Date: Mon, 22 Feb 2021 12:22:43 -0800 Subject: Record ids for array dimensions that are specialization constants. Test: Build succeeds. --- spirv_reflect.c | 7 +++++-- spirv_reflect.h | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/spirv_reflect.c b/spirv_reflect.c index fc59c9f..14c1e6e 100644 --- a/spirv_reflect.c +++ b/spirv_reflect.c @@ -1629,16 +1629,19 @@ static SpvReflectResult ParseType( // Get length for current dimension Node* p_length_node = FindNode(p_parser, length_id); if (IsNotNull(p_length_node)) { + uint32_t dim_index = p_type->traits.array.dims_count; if (p_length_node->op == SpvOpSpecConstant || p_length_node->op == SpvOpSpecConstantOp) { - p_type->traits.array.dims[p_type->traits.array.dims_count] = 0xFFFFFFFF; + p_type->traits.array.dims[dim_index] = 0xFFFFFFFF; + p_type->traits.array.spec_constant_op_ids[dim_index] = length_id; p_type->traits.array.dims_count += 1; } else { uint32_t length = 0; IF_READU32(result, p_parser, p_length_node->word_offset + 3, length); if (result == SPV_REFLECT_RESULT_SUCCESS) { // Write the array dim and increment the count and offset - p_type->traits.array.dims[p_type->traits.array.dims_count] = length; + p_type->traits.array.dims[dim_index] = length; + p_type->traits.array.spec_constant_op_ids[dim_index] = 0xFFFFFFFF; p_type->traits.array.dims_count += 1; } else { result = SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE; diff --git a/spirv_reflect.h b/spirv_reflect.h index 8075825..b6a17bd 100644 --- a/spirv_reflect.h +++ b/spirv_reflect.h @@ -262,6 +262,8 @@ typedef struct SpvReflectImageTraits { typedef struct SpvReflectArrayTraits { uint32_t dims_count; uint32_t dims[SPV_REFLECT_MAX_ARRAY_DIMS]; + // Stores Ids for dimensions that are specialization constants + uint32_t spec_constant_op_ids[SPV_REFLECT_MAX_ARRAY_DIMS]; uint32_t stride; // Measured in bytes } SpvReflectArrayTraits; -- cgit v1.2.3 From 65efb7d9d3fca388b2f1657536f18e7e58e7ea3d Mon Sep 17 00:00:00 2001 From: Mark Segal Date: Tue, 23 Feb 2021 12:23:32 -0800 Subject: Handle runtime arrays as another dimension type. --- spirv_reflect.c | 6 ++++++ spirv_reflect.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/spirv_reflect.c b/spirv_reflect.c index 14c1e6e..31dd0cc 100644 --- a/spirv_reflect.c +++ b/spirv_reflect.c @@ -1663,8 +1663,14 @@ static SpvReflectResult ParseType( break; case SpvOpTypeRuntimeArray: { + p_type->type_flags |= SPV_REFLECT_TYPE_FLAG_ARRAY; uint32_t element_type_id = (uint32_t)INVALID_VALUE; IF_READU32(result, p_parser, p_node->word_offset + 2, element_type_id); + p_type->traits.array.stride = p_node->decorations.array_stride; + uint32_t dim_index = p_type->traits.array.dims_count; + p_type->traits.array.dims[dim_index] = 0; + p_type->traits.array.spec_constant_op_ids[dim_index] = 0; + p_type->traits.array.dims_count += 1; // Parse next dimension or element type Node* p_next_node = FindNode(p_parser, element_type_id); if (IsNotNull(p_next_node)) { diff --git a/spirv_reflect.h b/spirv_reflect.h index b6a17bd..22b587c 100644 --- a/spirv_reflect.h +++ b/spirv_reflect.h @@ -261,6 +261,8 @@ typedef struct SpvReflectImageTraits { typedef struct SpvReflectArrayTraits { uint32_t dims_count; + // Each entry is: 0xFFFFFFFF for a specialization constant dimension, + // 0 for a runtime array dimension, and the array length otherwise. uint32_t dims[SPV_REFLECT_MAX_ARRAY_DIMS]; // Stores Ids for dimensions that are specialization constants uint32_t spec_constant_op_ids[SPV_REFLECT_MAX_ARRAY_DIMS]; -- cgit v1.2.3