Skip to content

Commit 6557f3c

Browse files
Fix size of struct with POD pointer in it
1 parent 281b55e commit 6557f3c

10 files changed

+654
-9
lines changed

common/output_stream.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,10 @@ std::string ToStringComponentType(const SpvReflectTypeDescription& type, uint32_
10171017
ss << type.traits.numeric.vector.component_count;
10181018
}
10191019

1020+
if (type.type_flags & SPV_REFLECT_TYPE_FLAG_REF) {
1021+
ss << "*";
1022+
}
1023+
10201024
return ss.str();
10211025
}
10221026

spirv_reflect.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@
4242

4343
// clang-format off
4444
enum {
45-
SPIRV_STARTING_WORD_INDEX = 5,
46-
SPIRV_WORD_SIZE = sizeof(uint32_t),
47-
SPIRV_BYTE_WIDTH = 8,
48-
SPIRV_MINIMUM_FILE_SIZE = SPIRV_STARTING_WORD_INDEX * SPIRV_WORD_SIZE,
49-
SPIRV_DATA_ALIGNMENT = 4 * SPIRV_WORD_SIZE, // 16
50-
SPIRV_ACCESS_CHAIN_INDEX_OFFSET = 4,
45+
SPIRV_STARTING_WORD_INDEX = 5,
46+
SPIRV_WORD_SIZE = sizeof(uint32_t),
47+
SPIRV_BYTE_WIDTH = 8,
48+
SPIRV_MINIMUM_FILE_SIZE = SPIRV_STARTING_WORD_INDEX * SPIRV_WORD_SIZE,
49+
SPIRV_DATA_ALIGNMENT = 4 * SPIRV_WORD_SIZE, // 16
50+
SPIRV_ACCESS_CHAIN_INDEX_OFFSET = 4,
51+
SPIRV_PHYSICAL_STORAGE_POINTER_SIZE = 8, // Pointers are defined as 64-bit
5152
};
5253

5354
enum {
@@ -2733,8 +2734,8 @@ static SpvReflectResult ParseDescriptorBlockVariableSizes(SpvReflectPrvParser* p
27332734

27342735
// If we found a struct, we need to fall through and get the size of it or else we grab the size here
27352736
if (p_member_type->op != SpvOpTypeStruct) {
2736-
// TODO - we need to rework this loop as a function to get size for each type
2737-
// (or maybe determine this size doesn't matter if not a struct in the pointer)
2737+
// If we hit this, we are seeing a POD pointer and the size is fixed
2738+
p_member_var->size = SPIRV_PHYSICAL_STORAGE_POINTER_SIZE;
27382739
break;
27392740
}
27402741
FALLTHROUGH;

tests/access_chains/pointer_access_chain_phy_storage_buffer.spv.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ all_block_variables:
9494
name:
9595
offset: 0
9696
absolute_offset: 0
97-
size: 0
97+
size: 8
9898
padded_size: 8
9999
decorations: 0x00000000 # NONE
100100
numeric:
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
RWStructuredBuffer<int> result;
2+
3+
struct Data{
4+
int a;
5+
int* b;
6+
int c;
7+
};
8+
[[vk::push_constant]] Data pc;
9+
10+
[shader("compute")]
11+
[numthreads(1,1,1)]
12+
void computeMain(uint3 threadId : SV_DispatchThreadID)
13+
{
14+
result[0] = pc.b[2] + pc.c;
15+
}
1008 Bytes
Binary file not shown.
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
%YAML 1.1
2+
---
3+
all_type_descriptions:
4+
- &td0
5+
id: 10
6+
op: 29
7+
type_name:
8+
struct_member_name:
9+
storage_class: 0 # UniformConstant
10+
type_flags: 0x20000004 # ARRAY INT
11+
decoration_flags: 0x00000000 # NONE
12+
traits:
13+
numeric:
14+
scalar: { width: 32, signedness: 1 }
15+
vector: { component_count: 0 }
16+
matrix: { column_count: 0, row_count: 0, stride: 0 }
17+
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
18+
array: { dims_count: 1, dims: [0,], stride: 4 }
19+
member_count: 0
20+
members:
21+
- &td1
22+
id: 9
23+
op: 30
24+
type_name: "RWStructuredBuffer"
25+
struct_member_name:
26+
storage_class: -1 # NOT APPLICABLE
27+
type_flags: 0x10080000 # STRUCT EXTERNAL_BLOCK
28+
decoration_flags: 0x00000001 # BLOCK
29+
traits:
30+
numeric:
31+
scalar: { width: 0, signedness: 0 }
32+
vector: { component_count: 0 }
33+
matrix: { column_count: 0, row_count: 0, stride: 0 }
34+
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
35+
array: { dims_count: 0, dims: [], stride: 0 }
36+
member_count: 1
37+
members:
38+
- *td0
39+
- &td2
40+
id: 5
41+
op: 21
42+
type_name:
43+
struct_member_name: "a"
44+
storage_class: 0 # UniformConstant
45+
type_flags: 0x00000004 # INT
46+
decoration_flags: 0x00000000 # NONE
47+
traits:
48+
numeric:
49+
scalar: { width: 32, signedness: 1 }
50+
vector: { component_count: 0 }
51+
matrix: { column_count: 0, row_count: 0, stride: 0 }
52+
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
53+
array: { dims_count: 0, dims: [], stride: 0 }
54+
member_count: 0
55+
members:
56+
- &td3
57+
id: 14
58+
op: 32
59+
type_name:
60+
struct_member_name: "b"
61+
storage_class: 5349 # PhysicalStorageBuffer
62+
type_flags: 0x40000004 # REF INT
63+
decoration_flags: 0x00000000 # NONE
64+
traits:
65+
numeric:
66+
scalar: { width: 32, signedness: 1 }
67+
vector: { component_count: 0 }
68+
matrix: { column_count: 0, row_count: 0, stride: 0 }
69+
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
70+
array: { dims_count: 0, dims: [], stride: 0 }
71+
member_count: 0
72+
members:
73+
- &td4
74+
id: 5
75+
op: 21
76+
type_name:
77+
struct_member_name: "c"
78+
storage_class: 0 # UniformConstant
79+
type_flags: 0x00000004 # INT
80+
decoration_flags: 0x00000000 # NONE
81+
traits:
82+
numeric:
83+
scalar: { width: 32, signedness: 1 }
84+
vector: { component_count: 0 }
85+
matrix: { column_count: 0, row_count: 0, stride: 0 }
86+
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
87+
array: { dims_count: 0, dims: [], stride: 0 }
88+
member_count: 0
89+
members:
90+
- &td5
91+
id: 13
92+
op: 30
93+
type_name: "Data_std140"
94+
struct_member_name:
95+
storage_class: -1 # NOT APPLICABLE
96+
type_flags: 0x10080000 # STRUCT EXTERNAL_BLOCK
97+
decoration_flags: 0x00000001 # BLOCK
98+
traits:
99+
numeric:
100+
scalar: { width: 0, signedness: 0 }
101+
vector: { component_count: 0 }
102+
matrix: { column_count: 0, row_count: 0, stride: 0 }
103+
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
104+
array: { dims_count: 0, dims: [], stride: 0 }
105+
member_count: 3
106+
members:
107+
- *td2
108+
- *td3
109+
- *td4
110+
all_block_variables:
111+
- &bv0
112+
name:
113+
offset: 0
114+
absolute_offset: 0
115+
size: 0
116+
padded_size: 0
117+
decorations: 0x00000000 # NONE
118+
numeric:
119+
scalar: { width: 32, signedness: 1 }
120+
vector: { component_count: 0 }
121+
matrix: { column_count: 0, row_count: 0, stride: 0 }
122+
array: { dims_count: 0, dims: [], stride: 0 }
123+
member_count: 0
124+
members:
125+
type_description: *td0
126+
- &bv1
127+
name: "result"
128+
offset: 0
129+
absolute_offset: 0
130+
size: 0
131+
padded_size: 0
132+
decorations: 0x00000000 # NONE
133+
numeric:
134+
scalar: { width: 0, signedness: 0 }
135+
vector: { component_count: 0 }
136+
matrix: { column_count: 0, row_count: 0, stride: 0 }
137+
array: { dims_count: 0, dims: [], stride: 0 }
138+
member_count: 1
139+
members:
140+
- *bv0
141+
type_description: *td1
142+
- &bv2
143+
name: "a"
144+
offset: 0
145+
absolute_offset: 0
146+
size: 4
147+
padded_size: 4
148+
decorations: 0x00000000 # NONE
149+
numeric:
150+
scalar: { width: 32, signedness: 1 }
151+
vector: { component_count: 0 }
152+
matrix: { column_count: 0, row_count: 0, stride: 0 }
153+
array: { dims_count: 0, dims: [], stride: 0 }
154+
member_count: 0
155+
members:
156+
type_description: *td2
157+
- &bv3
158+
name: "b"
159+
offset: 8
160+
absolute_offset: 8
161+
size: 8
162+
padded_size: 8
163+
decorations: 0x00000000 # NONE
164+
numeric:
165+
scalar: { width: 32, signedness: 1 }
166+
vector: { component_count: 0 }
167+
matrix: { column_count: 0, row_count: 0, stride: 0 }
168+
array: { dims_count: 0, dims: [], stride: 0 }
169+
member_count: 0
170+
members:
171+
type_description: *td3
172+
- &bv4
173+
name: "c"
174+
offset: 16
175+
absolute_offset: 16
176+
size: 4
177+
padded_size: 4
178+
decorations: 0x00000000 # NONE
179+
numeric:
180+
scalar: { width: 32, signedness: 1 }
181+
vector: { component_count: 0 }
182+
matrix: { column_count: 0, row_count: 0, stride: 0 }
183+
array: { dims_count: 0, dims: [], stride: 0 }
184+
member_count: 0
185+
members:
186+
type_description: *td4
187+
- &bv5
188+
name: "pc"
189+
offset: 0
190+
absolute_offset: 0
191+
size: 20
192+
padded_size: 20
193+
decorations: 0x00000000 # NONE
194+
numeric:
195+
scalar: { width: 0, signedness: 0 }
196+
vector: { component_count: 0 }
197+
matrix: { column_count: 0, row_count: 0, stride: 0 }
198+
array: { dims_count: 0, dims: [], stride: 0 }
199+
member_count: 3
200+
members:
201+
- *bv2
202+
- *bv3
203+
- *bv4
204+
type_description: *td5
205+
all_descriptor_bindings:
206+
- &db0
207+
spirv_id: 12
208+
name: "result"
209+
binding: 0
210+
input_attachment_index: 0
211+
set: 0
212+
decoration_flags: 0x00000000 # NONE
213+
descriptor_type: 7 # VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
214+
resource_type: 8 # UAV
215+
image: { dim: 0, depth: 0, arrayed: 0, ms: 0, sampled: 0, image_format: 0 } # dim=1D image_format=Unknown
216+
block: *bv1 # "result"
217+
array: { dims_count: 0, dims: [] }
218+
accessed: 1
219+
uav_counter_id: 4294967295
220+
uav_counter_binding:
221+
type_description: *td1
222+
word_offset: { binding: 109, set: 113 }
223+
all_interface_variables:
224+
module:
225+
generator: 0 # ???
226+
entry_point_name: "main"
227+
entry_point_id: 2
228+
source_language: 11 # Unknown
229+
source_language_version: 1
230+
spirv_execution_model: 5 # GLCompute
231+
shader_stage: 0x00000020 # CS
232+
descriptor_binding_count: 1
233+
descriptor_bindings:
234+
- *db0 # "result"
235+
descriptor_set_count: 1
236+
descriptor_sets:
237+
- set: 0
238+
binding_count: 1
239+
bindings:
240+
- *db0 # "result"
241+
input_variable_count: 0,
242+
input_variables:
243+
output_variable_count: 0,
244+
output_variables:
245+
push_constant_count: 1,
246+
push_constants:
247+
- *bv5 # "pc"
248+
specialization_constant_count: 0,
249+
specialization_constants:
250+
...
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
RWStructuredBuffer<int> result;
2+
3+
struct Data2{
4+
int x;
5+
int* y;
6+
};
7+
8+
struct Data{
9+
int a;
10+
Data2* b;
11+
int c;
12+
};
13+
[[vk::push_constant]] Data pc;
14+
15+
[shader("compute")]
16+
[numthreads(1,1,1)]
17+
void computeMain(uint3 threadId : SV_DispatchThreadID)
18+
{
19+
result[0] = pc.b[2].y[2] + pc.c;
20+
}
1.23 KB
Binary file not shown.

0 commit comments

Comments
 (0)