@@ -1135,13 +1135,72 @@ pub trait ImageWithMethods<
1135
1135
>
1136
1136
{
1137
1137
/// Fetch a single texel with a sampler set at compile time
1138
+ #[ doc( alias = "OpImageFetch" ) ]
1138
1139
fn fetch_with < I > (
1139
1140
& self ,
1140
1141
coordinate : impl ImageCoordinate < I , DIM , ARRAYED > ,
1141
1142
params : Params ,
1142
1143
) -> SampledType :: SampleResult
1143
1144
where
1144
1145
I : Integer ;
1146
+
1147
+ /// Gathers the requested component from four texels.
1148
+ #[ doc( alias = "OpImageGather" ) ]
1149
+ fn gather_with < F > (
1150
+ & self ,
1151
+ sampler : Sampler ,
1152
+ coordinate : impl ImageCoordinate < F , DIM , ARRAYED > ,
1153
+ component : u32 ,
1154
+ params : Params ,
1155
+ ) -> SampledType :: Vec4
1156
+ where
1157
+ Self : HasGather ,
1158
+ F : Float ;
1159
+
1160
+ /// Sample texels at `coord` from the image using `sampler`.
1161
+ fn sample_with < F > (
1162
+ & self ,
1163
+ sampler : Sampler ,
1164
+ coord : impl ImageCoordinate < F , DIM , ARRAYED > ,
1165
+ params : Params ,
1166
+ ) -> SampledType :: SampleResult
1167
+ where
1168
+ F : Float ;
1169
+
1170
+ /// Sample the image's depth reference
1171
+ #[ doc( alias = "OpImageSampleDrefImplicitLod" ) ]
1172
+ fn sample_depth_reference_with < F > (
1173
+ & self ,
1174
+ sampler : Sampler ,
1175
+ coordinate : impl ImageCoordinate < F , DIM , ARRAYED > ,
1176
+ depth_reference : f32 ,
1177
+ params : Params ,
1178
+ ) -> SampledType
1179
+ where
1180
+ F : Float ;
1181
+
1182
+ /// Sample the image with a project coordinate
1183
+ #[ doc( alias = "OpImageSampleProjImplicitLod" ) ]
1184
+ fn sample_with_project_coordinate_with < F > (
1185
+ & self ,
1186
+ sampler : Sampler ,
1187
+ project_coordinate : impl ImageCoordinate < F , DIM , { Arrayed :: True as u32 } > ,
1188
+ params : Params ,
1189
+ ) -> SampledType :: SampleResult
1190
+ where
1191
+ F : Float ;
1192
+
1193
+ /// Sample the image's depth reference with the project coordinate
1194
+ #[ doc( alias = "OpImageSampleProjDrefImplicitLod" ) ]
1195
+ fn sample_depth_reference_with_project_coordinate_with < F > (
1196
+ & self ,
1197
+ sampler : Sampler ,
1198
+ project_coordinate : impl ImageCoordinate < F , DIM , { Arrayed :: True as u32 } > ,
1199
+ depth_reference : f32 ,
1200
+ params : Params ,
1201
+ ) -> SampledType
1202
+ where
1203
+ F : Float ;
1145
1204
}
1146
1205
1147
1206
#[ crate :: macros:: gen_sample_param_permutations]
@@ -1191,6 +1250,167 @@ impl<
1191
1250
}
1192
1251
result. truncate_into ( )
1193
1252
}
1253
+
1254
+ /// Gathers the requested component from four texels.
1255
+ #[ crate :: macros:: gpu_only]
1256
+ #[ doc( alias = "OpImageGather" ) ]
1257
+ #[ inline]
1258
+ fn gather_with < F > (
1259
+ & self ,
1260
+ sampler : Sampler ,
1261
+ coordinate : impl ImageCoordinate < F , DIM , ARRAYED > ,
1262
+ component : u32 ,
1263
+ params : SampleParams ,
1264
+ ) -> SampledType :: Vec4
1265
+ where
1266
+ Self : HasGather ,
1267
+ F : Float ,
1268
+ {
1269
+ let mut result = SampledType :: Vec4 :: default ( ) ;
1270
+ unsafe {
1271
+ asm ! {
1272
+ "%typeSampledImage = OpTypeSampledImage typeof*{this}" ,
1273
+ "%image = OpLoad _ {this}" ,
1274
+ "%sampler = OpLoad _ {sampler}" ,
1275
+ "%coordinate = OpLoad _ {coordinate}" ,
1276
+ "%sampledImage = OpSampledImage %typeSampledImage %image %sampler" ,
1277
+ "%result = OpImageGather typeof*{result} %sampledImage %coordinate {component} $PARAMS" ,
1278
+ "OpStore {result} %result" ,
1279
+ result = in( reg) & mut result,
1280
+ this = in( reg) self ,
1281
+ sampler = in( reg) & sampler,
1282
+ coordinate = in( reg) & coordinate,
1283
+ component = in( reg) component,
1284
+ }
1285
+ }
1286
+ result
1287
+ }
1288
+
1289
+ /// Sample texels at `coord` from the image using `sampler`.
1290
+ #[ crate :: macros:: gpu_only]
1291
+ fn sample_with < F > (
1292
+ & self ,
1293
+ sampler : Sampler ,
1294
+ coord : impl ImageCoordinate < F , DIM , ARRAYED > ,
1295
+ params : SampleParams ,
1296
+ ) -> SampledType :: SampleResult
1297
+ where
1298
+ F : Float ,
1299
+ {
1300
+ unsafe {
1301
+ let mut result = SampledType :: Vec4 :: default ( ) ;
1302
+ asm ! (
1303
+ "%typeSampledImage = OpTypeSampledImage typeof*{this}" ,
1304
+ "%image = OpLoad _ {this}" ,
1305
+ "%sampler = OpLoad _ {sampler}" ,
1306
+ "%coord = OpLoad _ {coord}" ,
1307
+ "%sampledImage = OpSampledImage %typeSampledImage %image %sampler" ,
1308
+ "%result = OpImageSample$LOD typeof*{result} %sampledImage %coord $PARAMS" ,
1309
+ "OpStore {result} %result" ,
1310
+ result = in( reg) & mut result,
1311
+ this = in( reg) self ,
1312
+ sampler = in( reg) & sampler,
1313
+ coord = in( reg) & coord,
1314
+ ) ;
1315
+ result. truncate_into ( )
1316
+ }
1317
+ }
1318
+
1319
+ /// Sample the image's depth reference
1320
+ #[ crate :: macros:: gpu_only]
1321
+ #[ doc( alias = "OpImageSampleDrefImplicitLod" ) ]
1322
+ fn sample_depth_reference_with < F > (
1323
+ & self ,
1324
+ sampler : Sampler ,
1325
+ coordinate : impl ImageCoordinate < F , DIM , ARRAYED > ,
1326
+ depth_reference : f32 ,
1327
+ params : SampleParams ,
1328
+ ) -> SampledType
1329
+ where
1330
+ F : Float ,
1331
+ {
1332
+ let mut result = Default :: default ( ) ;
1333
+ unsafe {
1334
+ asm ! (
1335
+ "%image = OpLoad _ {this}" ,
1336
+ "%sampler = OpLoad _ {sampler}" ,
1337
+ "%coordinate = OpLoad _ {coordinate}" ,
1338
+ "%depth_reference = OpLoad _ {depth_reference}" , // not required to do this way, but done for consistency
1339
+ "%sampledImage = OpSampledImage _ %image %sampler" ,
1340
+ "%result = OpImageSampleDref$LOD _ %sampledImage %coordinate %depth_reference $PARAMS" ,
1341
+ "OpStore {result} %result" ,
1342
+ result = in( reg) & mut result,
1343
+ this = in( reg) self ,
1344
+ sampler = in( reg) & sampler,
1345
+ coordinate = in( reg) & coordinate,
1346
+ depth_reference = in( reg) & depth_reference,
1347
+ ) ;
1348
+ }
1349
+ result
1350
+ }
1351
+
1352
+ /// Sample the image with a project coordinate
1353
+ #[ crate :: macros:: gpu_only]
1354
+ #[ doc( alias = "OpImageSampleProjImplicitLod" ) ]
1355
+ fn sample_with_project_coordinate_with < F > (
1356
+ & self ,
1357
+ sampler : Sampler ,
1358
+ project_coordinate : impl ImageCoordinate < F , DIM , { Arrayed :: True as u32 } > ,
1359
+ params : SampleParams ,
1360
+ ) -> SampledType :: SampleResult
1361
+ where
1362
+ F : Float ,
1363
+ {
1364
+ unsafe {
1365
+ let mut result = SampledType :: Vec4 :: default ( ) ;
1366
+ asm ! (
1367
+ "%image = OpLoad _ {this}" ,
1368
+ "%sampler = OpLoad _ {sampler}" ,
1369
+ "%project_coordinate = OpLoad _ {project_coordinate}" ,
1370
+ "%sampledImage = OpSampledImage _ %image %sampler" ,
1371
+ "%result = OpImageSampleProj$LOD _ %sampledImage %project_coordinate $PARAMS" ,
1372
+ "OpStore {result} %result" ,
1373
+ result = in( reg) & mut result,
1374
+ this = in( reg) self ,
1375
+ sampler = in( reg) & sampler,
1376
+ project_coordinate = in( reg) & project_coordinate,
1377
+ ) ;
1378
+ result. truncate_into ( )
1379
+ }
1380
+ }
1381
+
1382
+ /// Sample the image's depth reference with the project coordinate
1383
+ #[ crate :: macros:: gpu_only]
1384
+ #[ doc( alias = "OpImageSampleProjDrefImplicitLod" ) ]
1385
+ fn sample_depth_reference_with_project_coordinate_with < F > (
1386
+ & self ,
1387
+ sampler : Sampler ,
1388
+ project_coordinate : impl ImageCoordinate < F , DIM , { Arrayed :: True as u32 } > ,
1389
+ depth_reference : f32 ,
1390
+ params : SampleParams ,
1391
+ ) -> SampledType
1392
+ where
1393
+ F : Float ,
1394
+ {
1395
+ let mut result = Default :: default ( ) ;
1396
+ unsafe {
1397
+ asm ! (
1398
+ "%image = OpLoad _ {this}" ,
1399
+ "%sampler = OpLoad _ {sampler}" ,
1400
+ "%project_coordinate = OpLoad _ {project_coordinate}" ,
1401
+ "%depth_reference = OpLoad _ {depth_reference}" , // not required to do this way, but done for consistency
1402
+ "%sampledImage = OpSampledImage _ %image %sampler" ,
1403
+ "%result = OpImageSampleProjDref$LOD _ %sampledImage %project_coordinate %depth_reference $PARAMS" ,
1404
+ "OpStore {result} %result" ,
1405
+ result = in( reg) & mut result,
1406
+ this = in( reg) self ,
1407
+ sampler = in( reg) & sampler,
1408
+ project_coordinate = in( reg) & project_coordinate,
1409
+ depth_reference = in( reg) & depth_reference,
1410
+ ) ;
1411
+ }
1412
+ result
1413
+ }
1194
1414
}
1195
1415
1196
1416
/// This is a marker trait to represent the constraints on `OpImageGather` too complex to be
0 commit comments