Skip to content

Commit

Permalink
Promote member decorations to descriptor binding decorations
Browse files Browse the repository at this point in the history
Decoration like non-writable and non-readable are found in spirv as
member decorations. This patch detects decorations that are shared
between all members and promotes them into descriptor binding
decorations.
  • Loading branch information
panos-lunarg committed Feb 13, 2024
1 parent 2f7460f commit c515f22
Show file tree
Hide file tree
Showing 55 changed files with 369 additions and 1 deletion.
3 changes: 3 additions & 0 deletions common/output_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ std::string ToStringDecorationFlags(SpvReflectDecorationFlags decoration_flags)
}
std::stringstream sstream;
PRINT_AND_CLEAR_DECORATION_FLAG(sstream, decoration_flags, NON_WRITABLE);
PRINT_AND_CLEAR_DECORATION_FLAG(sstream, decoration_flags, NON_READABLE);
PRINT_AND_CLEAR_DECORATION_FLAG(sstream, decoration_flags, FLAT);
PRINT_AND_CLEAR_DECORATION_FLAG(sstream, decoration_flags, NOPERSPECTIVE);
PRINT_AND_CLEAR_DECORATION_FLAG(sstream, decoration_flags, BUILT_IN);
Expand Down Expand Up @@ -1808,6 +1809,8 @@ void SpvReflectToYaml::WriteDescriptorBinding(std::ostream& os, const SpvReflect
// uint32_t set;
os << t1 << "set: " << db.set << std::endl;
// SpvReflectDescriptorType descriptor_type;
os << t1 << "decorations: " << AsHexString(db.decoration_flags) << " # " << ToStringDecorationFlags(db.decoration_flags)
<< std::endl;
os << t1 << "descriptor_type: " << db.descriptor_type << " # " << ToStringDescriptorType(db.descriptor_type) << std::endl;
// SpvReflectResourceType resource_type;
os << t1 << "resource_type: " << db.resource_type << " # " << ToStringResourceType(db.resource_type) << std::endl;
Expand Down
28 changes: 28 additions & 0 deletions spirv_reflect.c
Original file line number Diff line number Diff line change
Expand Up @@ -2039,6 +2039,34 @@ static SpvReflectResult ParseDescriptorBindings(SpvReflectPrvParser* p_parser, S
p_descriptor->type_description = p_type;
p_descriptor->decoration_flags = ApplyDecorations(&p_node->decorations);

// Flags like non-writable and non-readable are found as member decorations only.
// If all members have one of those decorations set, promote the decoration up
// to the whole descriptor.
const SpvReflectPrvNode* p_type_node = FindNode(p_parser, p_type->id);
if (IsNotNull(p_type_node) && p_type_node->member_count) {
SpvReflectPrvDecorations common_flags = p_type_node->member_decorations[0];

for (uint32_t m = 1; m < p_type_node->member_count; ++m) {
common_flags.is_relaxed_precision &= p_type_node->member_decorations[m].is_relaxed_precision;
common_flags.is_block &= p_type_node->member_decorations[m].is_block;
common_flags.is_buffer_block &= p_type_node->member_decorations[m].is_buffer_block;
common_flags.is_row_major &= p_type_node->member_decorations[m].is_row_major;
common_flags.is_column_major &= p_type_node->member_decorations[m].is_column_major;
common_flags.is_built_in &= p_type_node->member_decorations[m].is_built_in;
common_flags.is_noperspective &= p_type_node->member_decorations[m].is_noperspective;
common_flags.is_flat &= p_type_node->member_decorations[m].is_flat;
common_flags.is_non_writable &= p_type_node->member_decorations[m].is_non_writable;
common_flags.is_non_readable &= p_type_node->member_decorations[m].is_non_readable;
common_flags.is_patch &= p_type_node->member_decorations[m].is_patch;
common_flags.is_per_vertex &= p_type_node->member_decorations[m].is_per_vertex;
common_flags.is_per_task &= p_type_node->member_decorations[m].is_per_task;
common_flags.is_weight_texture &= p_type_node->member_decorations[m].is_weight_texture;
common_flags.is_block_match_texture &= p_type_node->member_decorations[m].is_block_match_texture;
}

p_descriptor->decoration_flags |= ApplyDecorations(&common_flags);
}

// If this is in the StorageBuffer storage class, it's for sure a storage
// buffer descriptor. We need to handle this case earlier because in SPIR-V
// there are two ways to indicate a storage buffer:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ all_descriptor_bindings:
binding: 0
input_attachment_index: 0
set: 0
decorations: 0x00000000 # NONE
descriptor_type: 7 # VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
resource_type: 8 # UAV
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
Expand Down
2 changes: 2 additions & 0 deletions tests/cbuffer_unused/cbuffer_unused_001.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3303,6 +3303,7 @@ all_descriptor_bindings:
binding: 0
input_attachment_index: 0
set: 0
decorations: 0x00000000 # NONE
descriptor_type: 6 # VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
resource_type: 2 # CBV
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
Expand All @@ -3319,6 +3320,7 @@ all_descriptor_bindings:
binding: 1
input_attachment_index: 0
set: 0
decorations: 0x00000000 # NONE
descriptor_type: 6 # VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
resource_type: 2 # CBV
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
Expand Down
1 change: 1 addition & 0 deletions tests/entry_exec_mode/comp_local_size.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ all_descriptor_bindings:
binding: 0
input_attachment_index: 0
set: 0
decorations: 0x00000000 # NONE
descriptor_type: 7 # VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
resource_type: 8 # UAV
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
Expand Down
2 changes: 2 additions & 0 deletions tests/glsl/buffer_handle_0.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,7 @@ all_descriptor_bindings:
binding: 0
input_attachment_index: 0
set: 0
decorations: 0x00000000 # NONE
descriptor_type: 7 # VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
resource_type: 8 # UAV
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
Expand All @@ -1260,6 +1261,7 @@ all_descriptor_bindings:
binding: 2
input_attachment_index: 0
set: 1
decorations: 0x00000000 # NONE
descriptor_type: 7 # VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
resource_type: 8 # UAV
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
Expand Down
2 changes: 2 additions & 0 deletions tests/glsl/buffer_handle_1.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ all_descriptor_bindings:
binding: 0
input_attachment_index: 0
set: 0
decorations: 0x00000000 # NONE
descriptor_type: 7 # VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
resource_type: 8 # UAV
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
Expand All @@ -649,6 +650,7 @@ all_descriptor_bindings:
binding: 2
input_attachment_index: 0
set: 1
decorations: 0x00000000 # NONE
descriptor_type: 7 # VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
resource_type: 8 # UAV
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
Expand Down
2 changes: 2 additions & 0 deletions tests/glsl/buffer_handle_2.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ all_descriptor_bindings:
binding: 0
input_attachment_index: 0
set: 3
decorations: 0x00000000 # NONE
descriptor_type: 3 # VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
resource_type: 8 # UAV
image: { dim: 1, depth: 0, arrayed: 0, ms: 0, sampled: 2, image_format: 33 } # dim=2D image_format=R32ui
Expand All @@ -764,6 +765,7 @@ all_descriptor_bindings:
binding: 1
input_attachment_index: 0
set: 3
decorations: 0x00000000 # NONE
descriptor_type: 7 # VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
resource_type: 8 # UAV
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
Expand Down
2 changes: 2 additions & 0 deletions tests/glsl/buffer_handle_3.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ all_descriptor_bindings:
binding: 0
input_attachment_index: 0
set: 0
decorations: 0x00000000 # NONE
descriptor_type: 7 # VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
resource_type: 8 # UAV
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
Expand All @@ -388,6 +389,7 @@ all_descriptor_bindings:
binding: 2
input_attachment_index: 0
set: 1
decorations: 0x00000000 # NONE
descriptor_type: 7 # VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
resource_type: 8 # UAV
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
Expand Down
2 changes: 1 addition & 1 deletion tests/glsl/buffer_handle_4.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ all_block_variables:
absolute_offset: 0
size: 0
padded_size: 0
decorations: 0x00000200 # ???
decorations: 0x00000200 # NON_READABLE
numeric:
scalar: { width: 32, signedness: 0 }
vector: { component_count: 0 }
Expand Down
1 change: 1 addition & 0 deletions tests/glsl/buffer_handle_8.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ all_descriptor_bindings:
binding: 1
input_attachment_index: 0
set: 3
decorations: 0x00000000 # NONE
descriptor_type: 7 # VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
resource_type: 8 # UAV
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
Expand Down
1 change: 1 addition & 0 deletions tests/glsl/fn_struct_param.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ all_descriptor_bindings:
binding: 0
input_attachment_index: 0
set: 0
decorations: 0x00000000 # NONE
descriptor_type: 6 # VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
resource_type: 2 # CBV
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
Expand Down
3 changes: 3 additions & 0 deletions tests/glsl/input_attachment.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ all_descriptor_bindings:
binding: 0
input_attachment_index: 0
set: 0
decorations: 0x00000000 # NONE
descriptor_type: 10 # VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
resource_type: 0 # UNDEFINED
image: { dim: 6, depth: 0, arrayed: 0, ms: 0, sampled: 2, image_format: 0 } # dim=SubpassData image_format=Unknown
Expand All @@ -104,6 +105,7 @@ all_descriptor_bindings:
binding: 1
input_attachment_index: 1
set: 0
decorations: 0x00000000 # NONE
descriptor_type: 10 # VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
resource_type: 0 # UNDEFINED
image: { dim: 6, depth: 0, arrayed: 0, ms: 0, sampled: 2, image_format: 0 } # dim=SubpassData image_format=Unknown
Expand All @@ -120,6 +122,7 @@ all_descriptor_bindings:
binding: 2
input_attachment_index: 4
set: 0
decorations: 0x00000000 # NONE
descriptor_type: 10 # VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
resource_type: 0 # UNDEFINED
image: { dim: 6, depth: 0, arrayed: 0, ms: 0, sampled: 2, image_format: 0 } # dim=SubpassData image_format=Unknown
Expand Down
1 change: 1 addition & 0 deletions tests/glsl/matrix_major_order_glsl.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@ all_descriptor_bindings:
binding: 0
input_attachment_index: 0
set: 0
decorations: 0x00000000 # NONE
descriptor_type: 6 # VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
resource_type: 2 # CBV
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
Expand Down
2 changes: 2 additions & 0 deletions tests/glsl/non_writable_image.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ all_descriptor_bindings:
binding: 0
input_attachment_index: 0
set: 0
decorations: 0x00000080 # NON_WRITABLE
descriptor_type: 3 # VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
resource_type: 8 # UAV
image: { dim: 1, depth: 0, arrayed: 0, ms: 0, sampled: 2, image_format: 1 } # dim=2D image_format=Rgba32f
Expand All @@ -89,6 +90,7 @@ all_descriptor_bindings:
binding: 1
input_attachment_index: 0
set: 0
decorations: 0x00000200 # NON_READABLE
descriptor_type: 3 # VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
resource_type: 8 # UAV
image: { dim: 1, depth: 0, arrayed: 0, ms: 0, sampled: 2, image_format: 1 } # dim=2D image_format=Rgba32f
Expand Down
21 changes: 21 additions & 0 deletions tests/glsl/readonly_writeonly.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Compile:
glslangValidator.exe -V -S comp -o readonly_writeonly.spv readonly_writeonly.glsl
*/
#version 450
#pragma shader_stage(compute)

layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;

const int kArraySize = 64;

layout(set = 0, binding = 0) buffer storage_buffer {
readonly float a[kArraySize];
writeonly float b[kArraySize];
writeonly readonly float bar[kArraySize];
} foo;

void main() {
uint idx = gl_GlobalInvocationID.x;
foo.b[idx] = foo.a[idx];
}
Binary file added tests/glsl/readonly_writeonly.spv
Binary file not shown.
Loading

0 comments on commit c515f22

Please sign in to comment.