@@ -97,13 +97,14 @@ impl SpirvType {
97
97
if let Some ( cached) = cx. type_cache . get ( & self ) {
98
98
return cached;
99
99
}
100
+ let id = Some ( cx. emit_global ( ) . id ( ) ) ;
100
101
let result = match self {
101
- Self :: Void => cx. emit_global ( ) . type_void ( ) ,
102
- Self :: Bool => cx. emit_global ( ) . type_bool ( ) ,
102
+ Self :: Void => cx. emit_global ( ) . type_void_id ( id ) ,
103
+ Self :: Bool => cx. emit_global ( ) . type_bool_id ( id ) ,
103
104
Self :: Integer ( width, signedness) => {
104
- let result = cx
105
- . emit_global ( )
106
- . type_int ( width, if signedness { 1 } else { 0 } ) ;
105
+ let result =
106
+ cx . emit_global ( )
107
+ . type_int_id ( id , width, if signedness { 1 } else { 0 } ) ;
107
108
match width {
108
109
8 if !cx. builder . has_capability ( Capability :: Int8 ) => cx
109
110
. zombie_even_in_user_code ( result, def_span, "u8 without OpCapability Int8" ) ,
@@ -130,7 +131,7 @@ impl SpirvType {
130
131
result
131
132
}
132
133
Self :: Float ( width) => {
133
- let result = cx. emit_global ( ) . type_float ( width) ;
134
+ let result = cx. emit_global ( ) . type_float_id ( id , width) ;
134
135
match width {
135
136
64 if !cx. builder . has_capability ( Capability :: Float64 ) => cx
136
137
. zombie_even_in_user_code (
@@ -156,9 +157,7 @@ impl SpirvType {
156
157
ref field_names,
157
158
} => {
158
159
let mut emit = cx. emit_global ( ) ;
159
- // Ensure a unique struct is emitted each time, due to possibly having different OpMemberDecorates
160
- let id = emit. id ( ) ;
161
- let result = emit. type_struct_id ( Some ( id) , field_types. iter ( ) . cloned ( ) ) ;
160
+ let result = emit. type_struct_id ( id, field_types. iter ( ) . cloned ( ) ) ;
162
161
// The struct size is only used in our own sizeof_in_bits() (used in e.g. ArrayStride decoration)
163
162
if !cx. target . is_kernel ( ) {
164
163
// TODO: kernel mode can't do this??
@@ -181,18 +180,19 @@ impl SpirvType {
181
180
result
182
181
}
183
182
Self :: Opaque { ref name } => cx. emit_global ( ) . type_opaque ( name) ,
184
- Self :: Vector { element, count } => cx. emit_global ( ) . type_vector ( element, count) ,
183
+ Self :: Vector { element, count } => cx. emit_global ( ) . type_vector_id ( id , element, count) ,
185
184
Self :: Array { element, count } => {
186
185
// ArrayStride decoration wants in *bytes*
187
186
let element_size = cx
188
187
. lookup_type ( element)
189
188
. sizeof ( cx)
190
189
. expect ( "Element of sized array must be sized" )
191
190
. bytes ( ) ;
192
- let result = cx. emit_global ( ) . type_array ( element, count. def_cx ( cx) ) ;
191
+ let mut emit = cx. emit_global ( ) ;
192
+ let result = emit. type_array_id ( id, element, count. def_cx ( cx) ) ;
193
193
if !cx. target . is_kernel ( ) {
194
194
// TODO: kernel mode can't do this??
195
- cx . emit_global ( ) . decorate (
195
+ emit . decorate (
196
196
result,
197
197
Decoration :: ArrayStride ,
198
198
iter:: once ( Operand :: LiteralInt32 ( element_size as u32 ) ) ,
@@ -201,14 +201,15 @@ impl SpirvType {
201
201
result
202
202
}
203
203
Self :: RuntimeArray { element } => {
204
- let result = cx. emit_global ( ) . type_runtime_array ( element) ;
204
+ let mut emit = cx. emit_global ( ) ;
205
+ let result = emit. type_runtime_array_id ( id, element) ;
205
206
// ArrayStride decoration wants in *bytes*
206
207
let element_size = cx
207
208
. lookup_type ( element)
208
209
. sizeof ( cx)
209
210
. expect ( "Element of sized array must be sized" )
210
211
. bytes ( ) ;
211
- cx . emit_global ( ) . decorate (
212
+ emit . decorate (
212
213
result,
213
214
Decoration :: ArrayStride ,
214
215
iter:: once ( Operand :: LiteralInt32 ( element_size as u32 ) ) ,
@@ -224,7 +225,7 @@ impl SpirvType {
224
225
// storage classes inferred from `OpVariable`s.
225
226
let result = cx
226
227
. emit_global ( )
227
- . type_pointer ( None , StorageClass :: Generic , pointee) ;
228
+ . type_pointer ( id , StorageClass :: Generic , pointee) ;
228
229
// no pointers to functions
229
230
if let Self :: Function { .. } = cx. lookup_type ( pointee) {
230
231
cx. zombie_even_in_user_code (
@@ -240,7 +241,7 @@ impl SpirvType {
240
241
ref arguments,
241
242
} => cx
242
243
. emit_global ( )
243
- . type_function ( return_type, arguments. iter ( ) . cloned ( ) ) ,
244
+ . type_function_id ( id , return_type, arguments. iter ( ) . cloned ( ) ) ,
244
245
Self :: Image {
245
246
sampled_type,
246
247
dim,
@@ -250,7 +251,8 @@ impl SpirvType {
250
251
sampled,
251
252
image_format,
252
253
access_qualifier,
253
- } => cx. emit_global ( ) . type_image (
254
+ } => cx. emit_global ( ) . type_image_id (
255
+ id,
254
256
sampled_type,
255
257
dim,
256
258
depth,
@@ -260,15 +262,18 @@ impl SpirvType {
260
262
image_format,
261
263
access_qualifier,
262
264
) ,
263
- Self :: Sampler => cx. emit_global ( ) . type_sampler ( ) ,
264
- Self :: AccelerationStructureKhr => cx. emit_global ( ) . type_acceleration_structure_khr ( ) ,
265
- Self :: RayQueryKhr => cx. emit_global ( ) . type_ray_query_khr ( ) ,
266
- Self :: SampledImage { image_type } => cx. emit_global ( ) . type_sampled_image ( image_type) ,
265
+ Self :: Sampler => cx. emit_global ( ) . type_sampler_id ( id) ,
266
+ Self :: AccelerationStructureKhr => {
267
+ cx. emit_global ( ) . type_acceleration_structure_khr_id ( id)
268
+ }
269
+ Self :: RayQueryKhr => cx. emit_global ( ) . type_ray_query_khr_id ( id) ,
270
+ Self :: SampledImage { image_type } => {
271
+ cx. emit_global ( ) . type_sampled_image_id ( id, image_type)
272
+ }
267
273
268
274
Self :: InterfaceBlock { inner_type } => {
269
275
let mut emit = cx. emit_global ( ) ;
270
- let id = emit. id ( ) ;
271
- let result = emit. type_struct_id ( Some ( id) , iter:: once ( inner_type) ) ;
276
+ let result = emit. type_struct_id ( id, iter:: once ( inner_type) ) ;
272
277
emit. decorate ( result, Decoration :: Block , iter:: empty ( ) ) ;
273
278
emit. member_decorate (
274
279
result,
0 commit comments