@@ -13,6 +13,7 @@ use crate::{
13
13
hal_api:: HalApi ,
14
14
hal_label,
15
15
hub:: Hub ,
16
+ id,
16
17
init_tracker:: {
17
18
BufferInitTracker , BufferInitTrackerAction , MemoryInitKind , TextureInitRange ,
18
19
TextureInitTracker , TextureInitTrackerAction ,
@@ -1949,6 +1950,7 @@ impl<A: HalApi> Device<A> {
1949
1950
used : & mut BindGroupStates < A > ,
1950
1951
storage : & ' a Storage < Buffer < A > > ,
1951
1952
limits : & wgt:: Limits ,
1953
+ device_id : id:: Id < id:: markers:: Device > ,
1952
1954
snatch_guard : & ' a SnatchGuard < ' a > ,
1953
1955
) -> Result < hal:: BufferBinding < ' a , A > , binding_model:: CreateBindGroupError > {
1954
1956
use crate :: binding_model:: CreateBindGroupError as Error ;
@@ -1967,6 +1969,7 @@ impl<A: HalApi> Device<A> {
1967
1969
} )
1968
1970
}
1969
1971
} ;
1972
+
1970
1973
let ( pub_usage, internal_use, range_limit) = match binding_ty {
1971
1974
wgt:: BufferBindingType :: Uniform => (
1972
1975
wgt:: BufferUsages :: UNIFORM ,
@@ -1999,6 +2002,10 @@ impl<A: HalApi> Device<A> {
1999
2002
. add_single ( storage, bb. buffer_id , internal_use)
2000
2003
. ok_or ( Error :: InvalidBuffer ( bb. buffer_id ) ) ?;
2001
2004
2005
+ if buffer. device . as_info ( ) . id ( ) != device_id {
2006
+ return Err ( DeviceError :: WrongDevice . into ( ) ) ;
2007
+ }
2008
+
2002
2009
check_buffer_usage ( bb. buffer_id , buffer. usage , pub_usage) ?;
2003
2010
let raw_buffer = buffer
2004
2011
. raw
@@ -2077,13 +2084,53 @@ impl<A: HalApi> Device<A> {
2077
2084
} )
2078
2085
}
2079
2086
2080
- pub ( crate ) fn create_texture_binding (
2081
- view : & TextureView < A > ,
2082
- internal_use : hal:: TextureUses ,
2083
- pub_usage : wgt:: TextureUsages ,
2087
+ fn create_sampler_binding < ' a > (
2088
+ used : & BindGroupStates < A > ,
2089
+ storage : & ' a Storage < Sampler < A > > ,
2090
+ id : id:: Id < id:: markers:: Sampler > ,
2091
+ device_id : id:: Id < id:: markers:: Device > ,
2092
+ ) -> Result < & ' a Sampler < A > , binding_model:: CreateBindGroupError > {
2093
+ use crate :: binding_model:: CreateBindGroupError as Error ;
2094
+
2095
+ let sampler = used
2096
+ . samplers
2097
+ . add_single ( storage, id)
2098
+ . ok_or ( Error :: InvalidSampler ( id) ) ?;
2099
+
2100
+ if sampler. device . as_info ( ) . id ( ) != device_id {
2101
+ return Err ( DeviceError :: WrongDevice . into ( ) ) ;
2102
+ }
2103
+
2104
+ Ok ( sampler)
2105
+ }
2106
+
2107
+ pub ( crate ) fn create_texture_binding < ' a > (
2108
+ self : & Arc < Self > ,
2109
+ binding : u32 ,
2110
+ decl : & wgt:: BindGroupLayoutEntry ,
2111
+ storage : & ' a Storage < TextureView < A > > ,
2112
+ id : id:: Id < id:: markers:: TextureView > ,
2084
2113
used : & mut BindGroupStates < A > ,
2085
2114
used_texture_ranges : & mut Vec < TextureInitTrackerAction < A > > ,
2086
- ) -> Result < ( ) , binding_model:: CreateBindGroupError > {
2115
+ snatch_guard : & ' a SnatchGuard < ' a > ,
2116
+ ) -> Result < hal:: TextureBinding < ' a , A > , binding_model:: CreateBindGroupError > {
2117
+ use crate :: binding_model:: CreateBindGroupError as Error ;
2118
+
2119
+ let view = used
2120
+ . views
2121
+ . add_single ( storage, id)
2122
+ . ok_or ( Error :: InvalidTextureView ( id) ) ?;
2123
+
2124
+ if view. device . as_info ( ) . id ( ) != self . as_info ( ) . id ( ) {
2125
+ return Err ( DeviceError :: WrongDevice . into ( ) ) ;
2126
+ }
2127
+
2128
+ let ( pub_usage, internal_use) = self . texture_use_parameters (
2129
+ binding,
2130
+ decl,
2131
+ view,
2132
+ "SampledTexture, ReadonlyStorageTexture or WriteonlyStorageTexture" ,
2133
+ ) ?;
2087
2134
let texture = & view. parent ;
2088
2135
let texture_id = texture. as_info ( ) . id ( ) ;
2089
2136
// Careful here: the texture may no longer have its own ref count,
@@ -2113,7 +2160,12 @@ impl<A: HalApi> Device<A> {
2113
2160
kind : MemoryInitKind :: NeedsInitializedMemory ,
2114
2161
} ) ;
2115
2162
2116
- Ok ( ( ) )
2163
+ Ok ( hal:: TextureBinding {
2164
+ view : view
2165
+ . raw ( snatch_guard)
2166
+ . ok_or ( Error :: InvalidTextureView ( id) ) ?,
2167
+ usage : internal_use,
2168
+ } )
2117
2169
}
2118
2170
2119
2171
// This function expects the provided bind group layout to be resolved
@@ -2175,6 +2227,7 @@ impl<A: HalApi> Device<A> {
2175
2227
& mut used,
2176
2228
& * buffer_guard,
2177
2229
& self . limits ,
2230
+ self . as_info ( ) . id ( ) ,
2178
2231
& snatch_guard,
2179
2232
) ?;
2180
2233
@@ -2198,105 +2251,86 @@ impl<A: HalApi> Device<A> {
2198
2251
& mut used,
2199
2252
& * buffer_guard,
2200
2253
& self . limits ,
2254
+ self . as_info ( ) . id ( ) ,
2201
2255
& snatch_guard,
2202
2256
) ?;
2203
2257
hal_buffers. push ( bb) ;
2204
2258
}
2205
2259
( res_index, num_bindings)
2206
2260
}
2207
- Br :: Sampler ( id) => {
2208
- match decl. ty {
2209
- wgt:: BindingType :: Sampler ( ty) => {
2210
- let sampler = used
2211
- . samplers
2212
- . add_single ( & * sampler_guard, id)
2213
- . ok_or ( Error :: InvalidSampler ( id) ) ?;
2214
-
2215
- if sampler. device . as_info ( ) . id ( ) != self . as_info ( ) . id ( ) {
2216
- return Err ( DeviceError :: WrongDevice . into ( ) ) ;
2217
- }
2218
-
2219
- // Allowed sampler values for filtering and comparison
2220
- let ( allowed_filtering, allowed_comparison) = match ty {
2221
- wgt:: SamplerBindingType :: Filtering => ( None , false ) ,
2222
- wgt:: SamplerBindingType :: NonFiltering => ( Some ( false ) , false ) ,
2223
- wgt:: SamplerBindingType :: Comparison => ( None , true ) ,
2224
- } ;
2225
-
2226
- if let Some ( allowed_filtering) = allowed_filtering {
2227
- if allowed_filtering != sampler. filtering {
2228
- return Err ( Error :: WrongSamplerFiltering {
2229
- binding,
2230
- layout_flt : allowed_filtering,
2231
- sampler_flt : sampler. filtering ,
2232
- } ) ;
2233
- }
2234
- }
2261
+ Br :: Sampler ( id) => match decl. ty {
2262
+ wgt:: BindingType :: Sampler ( ty) => {
2263
+ let sampler = Self :: create_sampler_binding (
2264
+ & used,
2265
+ & sampler_guard,
2266
+ id,
2267
+ self . as_info ( ) . id ( ) ,
2268
+ ) ?;
2235
2269
2236
- if allowed_comparison != sampler. comparison {
2237
- return Err ( Error :: WrongSamplerComparison {
2270
+ let ( allowed_filtering, allowed_comparison) = match ty {
2271
+ wgt:: SamplerBindingType :: Filtering => ( None , false ) ,
2272
+ wgt:: SamplerBindingType :: NonFiltering => ( Some ( false ) , false ) ,
2273
+ wgt:: SamplerBindingType :: Comparison => ( None , true ) ,
2274
+ } ;
2275
+ if let Some ( allowed_filtering) = allowed_filtering {
2276
+ if allowed_filtering != sampler. filtering {
2277
+ return Err ( Error :: WrongSamplerFiltering {
2238
2278
binding,
2239
- layout_cmp : allowed_comparison ,
2240
- sampler_cmp : sampler. comparison ,
2279
+ layout_flt : allowed_filtering ,
2280
+ sampler_flt : sampler. filtering ,
2241
2281
} ) ;
2242
2282
}
2243
-
2244
- let res_index = hal_samplers. len ( ) ;
2245
- hal_samplers. push ( sampler. raw ( ) ) ;
2246
- ( res_index, 1 )
2247
2283
}
2248
- _ => {
2249
- return Err ( Error :: WrongBindingType {
2284
+ if allowed_comparison != sampler . comparison {
2285
+ return Err ( Error :: WrongSamplerComparison {
2250
2286
binding,
2251
- actual : decl . ty ,
2252
- expected : "Sampler" ,
2253
- } )
2287
+ layout_cmp : allowed_comparison ,
2288
+ sampler_cmp : sampler . comparison ,
2289
+ } ) ;
2254
2290
}
2291
+
2292
+ let res_index = hal_samplers. len ( ) ;
2293
+ hal_samplers. push ( sampler. raw ( ) ) ;
2294
+ ( res_index, 1 )
2255
2295
}
2256
- }
2296
+ _ => {
2297
+ return Err ( Error :: WrongBindingType {
2298
+ binding,
2299
+ actual : decl. ty ,
2300
+ expected : "Sampler" ,
2301
+ } )
2302
+ }
2303
+ } ,
2257
2304
Br :: SamplerArray ( ref bindings_array) => {
2258
2305
let num_bindings = bindings_array. len ( ) ;
2259
2306
Self :: check_array_binding ( self . features , decl. count , num_bindings) ?;
2260
2307
2261
2308
let res_index = hal_samplers. len ( ) ;
2262
2309
for & id in bindings_array. iter ( ) {
2263
- let sampler = used
2264
- . samplers
2265
- . add_single ( & * sampler_guard, id )
2266
- . ok_or ( Error :: InvalidSampler ( id ) ) ? ;
2267
- if sampler . device . as_info ( ) . id ( ) != self . as_info ( ) . id ( ) {
2268
- return Err ( DeviceError :: WrongDevice . into ( ) ) ;
2269
- }
2310
+ let sampler = Self :: create_sampler_binding (
2311
+ & used ,
2312
+ & sampler_guard,
2313
+ id ,
2314
+ self . as_info ( ) . id ( ) ,
2315
+ ) ? ;
2316
+
2270
2317
hal_samplers. push ( sampler. raw ( ) ) ;
2271
2318
}
2272
2319
2273
2320
( res_index, num_bindings)
2274
2321
}
2275
2322
Br :: TextureView ( id) => {
2276
- let view = used
2277
- . views
2278
- . add_single ( & * texture_view_guard, id)
2279
- . ok_or ( Error :: InvalidTextureView ( id) ) ?;
2280
- let ( pub_usage, internal_use) = self . texture_use_parameters (
2323
+ let tb = self . create_texture_binding (
2281
2324
binding,
2282
2325
decl,
2283
- view,
2284
- "SampledTexture, ReadonlyStorageTexture or WriteonlyStorageTexture" ,
2285
- ) ?;
2286
- Self :: create_texture_binding (
2287
- view,
2288
- internal_use,
2289
- pub_usage,
2326
+ & texture_view_guard,
2327
+ id,
2290
2328
& mut used,
2291
2329
& mut used_texture_ranges,
2330
+ & snatch_guard,
2292
2331
) ?;
2293
2332
let res_index = hal_textures. len ( ) ;
2294
- hal_textures. push ( hal:: TextureBinding {
2295
- view : view
2296
- . raw ( & snatch_guard)
2297
- . ok_or ( Error :: InvalidTextureView ( id) ) ?,
2298
- usage : internal_use,
2299
- } ) ;
2333
+ hal_textures. push ( tb) ;
2300
2334
( res_index, 1 )
2301
2335
}
2302
2336
Br :: TextureViewArray ( ref bindings_array) => {
@@ -2305,26 +2339,17 @@ impl<A: HalApi> Device<A> {
2305
2339
2306
2340
let res_index = hal_textures. len ( ) ;
2307
2341
for & id in bindings_array. iter ( ) {
2308
- let view = used
2309
- . views
2310
- . add_single ( & * texture_view_guard, id)
2311
- . ok_or ( Error :: InvalidTextureView ( id) ) ?;
2312
- let ( pub_usage, internal_use) =
2313
- self . texture_use_parameters ( binding, decl, view,
2314
- "SampledTextureArray, ReadonlyStorageTextureArray or WriteonlyStorageTextureArray" ) ?;
2315
- Self :: create_texture_binding (
2316
- view,
2317
- internal_use,
2318
- pub_usage,
2342
+ let tb = self . create_texture_binding (
2343
+ binding,
2344
+ decl,
2345
+ & texture_view_guard,
2346
+ id,
2319
2347
& mut used,
2320
2348
& mut used_texture_ranges,
2349
+ & snatch_guard,
2321
2350
) ?;
2322
- hal_textures. push ( hal:: TextureBinding {
2323
- view : view
2324
- . raw ( & snatch_guard)
2325
- . ok_or ( Error :: InvalidTextureView ( id) ) ?,
2326
- usage : internal_use,
2327
- } ) ;
2351
+
2352
+ hal_textures. push ( tb) ;
2328
2353
}
2329
2354
2330
2355
( res_index, num_bindings)
0 commit comments