@@ -5,7 +5,7 @@ use crate::spirv_type::SpirvType;
5
5
use rspirv:: dr;
6
6
use rspirv:: grammar:: { LogicalOperand , OperandKind , OperandQuantifier } ;
7
7
use rspirv:: spirv:: {
8
- Dim , FPFastMathMode , FragmentShadingRate , FunctionControl , ImageOperands , KernelProfilingInfo ,
8
+ FPFastMathMode , FragmentShadingRate , FunctionControl , ImageOperands , KernelProfilingInfo ,
9
9
LoopControl , MemoryAccess , MemorySemantics , Op , RayFlags , SelectionControl , StorageClass , Word ,
10
10
} ;
11
11
use rustc_ast:: ast:: { InlineAsmOptions , InlineAsmTemplatePiece } ;
@@ -333,7 +333,6 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
333
333
return ;
334
334
}
335
335
_ => {
336
- self . validate_instruction ( & inst) ;
337
336
self . emit ( )
338
337
. insert_into_block ( dr:: InsertPoint :: End , inst)
339
338
. unwrap ( ) ;
@@ -1314,131 +1313,6 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
1314
1313
}
1315
1314
true
1316
1315
}
1317
-
1318
- pub fn validate_instruction ( & mut self , inst : & dr:: Instruction ) {
1319
- fn find_image_ty < ' cx , ' tcx > (
1320
- builder : & mut Builder < ' cx , ' tcx > ,
1321
- inst : & dr:: Instruction ,
1322
- ) -> Option < SpirvType > {
1323
- // Assumes the image parameter is the first operand
1324
- let image_obj = inst. operands [ 0 ] . unwrap_id_ref ( ) ;
1325
- let emit = builder. emit ( ) ;
1326
- // Assumes the image's value definition is in the current block
1327
- let block = & emit. module_ref ( ) . functions [ emit. selected_function ( ) . unwrap ( ) ] . blocks
1328
- [ emit. selected_block ( ) . unwrap ( ) ] ;
1329
- // Loop through the block to find the defining instruction
1330
- let defining_inst = match block
1331
- . instructions
1332
- . iter ( )
1333
- . find ( |inst| inst. result_id == Some ( image_obj) )
1334
- {
1335
- Some ( defining_inst) => defining_inst,
1336
- None => {
1337
- // Something has gone wrong. All the asm! blocks using these instructions
1338
- // should produce the image value in their own basic blocks (usually with
1339
- // an OpLoad), so there's probably some typo somewhere with an error
1340
- // already emitted, so just skip validation. If there truly is something
1341
- // bad going on, spirv-val will catch it.
1342
- return None ;
1343
- }
1344
- } ;
1345
- match builder. lookup_type ( defining_inst. result_type . unwrap ( ) ) {
1346
- SpirvType :: SampledImage { image_type } => Some ( builder. lookup_type ( image_type) ) ,
1347
- ty => Some ( ty) ,
1348
- }
1349
- }
1350
-
1351
- fn is_valid_query_size ( ty : & SpirvType ) -> bool {
1352
- match * ty {
1353
- SpirvType :: Image {
1354
- dim,
1355
- multisampled,
1356
- sampled,
1357
- ..
1358
- } => match dim {
1359
- Dim :: Dim1D | Dim :: Dim2D | Dim :: Dim3D | Dim :: DimCube => {
1360
- multisampled == 1 || sampled == 0 || sampled == 2
1361
- }
1362
- Dim :: DimBuffer | Dim :: DimRect => true ,
1363
- Dim :: DimSubpassData => false ,
1364
- } ,
1365
- _ => true ,
1366
- }
1367
- }
1368
-
1369
- fn is_valid_query_size_lod ( ty : & SpirvType ) -> bool {
1370
- match * ty {
1371
- SpirvType :: Image {
1372
- dim, multisampled, ..
1373
- } => match dim {
1374
- Dim :: Dim1D | Dim :: Dim2D | Dim :: Dim3D | Dim :: DimCube => multisampled == 0 ,
1375
- _ => false ,
1376
- } ,
1377
- _ => true ,
1378
- }
1379
- }
1380
-
1381
- match inst. class . opcode {
1382
- Op :: ImageQueryLevels | Op :: ImageQueryLod => {
1383
- let image_ty = match find_image_ty ( self , inst) {
1384
- Some ( ty) => ty,
1385
- None => return ,
1386
- } ;
1387
- if let SpirvType :: Image { dim, .. } = image_ty {
1388
- match dim {
1389
- Dim :: Dim1D | Dim :: Dim2D | Dim :: Dim3D | Dim :: DimCube => { }
1390
- bad => self
1391
- . struct_err ( & format ! (
1392
- "Op{}'s image has a dimension of {:?}" ,
1393
- inst. class. opname, bad
1394
- ) )
1395
- . note ( "Allowed dimensions are 1D, 2D, 3D, and Cube" )
1396
- . emit ( ) ,
1397
- }
1398
- }
1399
- // If the type isn't an image, something has gone wrong. The functions in image.rs
1400
- // shouldn't allow it, so the user is doing something weird. Let spirv-val handle
1401
- // the error later on.
1402
- }
1403
- Op :: ImageQuerySize => {
1404
- let image_ty = match find_image_ty ( self , inst) {
1405
- Some ( ty) => ty,
1406
- None => return ,
1407
- } ;
1408
- if !is_valid_query_size ( & image_ty) {
1409
- let mut err =
1410
- self . struct_err ( "OpImageQuerySize is invalid for this image type" ) ;
1411
- err. note (
1412
- "allowed dimensions are 1D, 2D, 3D, Buffer, Rect, or Cube. \
1413
- if dimension is 1D, 2D, 3D, or Cube, it must have either \
1414
- multisampled be true, *or* sampled of Unknown or No",
1415
- ) ;
1416
- if is_valid_query_size_lod ( & image_ty) {
1417
- err. note ( "query_size_lod is valid for this image, did you mean to use it instead?" ) ;
1418
- }
1419
- err. emit ( ) ;
1420
- }
1421
- }
1422
- Op :: ImageQuerySizeLod => {
1423
- let image_ty = match find_image_ty ( self , inst) {
1424
- Some ( ty) => ty,
1425
- None => return ,
1426
- } ;
1427
- if !is_valid_query_size_lod ( & image_ty) {
1428
- let mut err =
1429
- self . struct_err ( "OpImageQuerySizeLod is invalid for this image type" ) ;
1430
- err. note ( "The image's dimension must be 1D, 2D, 3D, or Cube. Multisampled must be false." ) ;
1431
- if is_valid_query_size ( & image_ty) {
1432
- err. note (
1433
- "query_size is valid for this image, did you mean to use it instead?" ,
1434
- ) ;
1435
- }
1436
- err. emit ( ) ;
1437
- }
1438
- }
1439
- _ => { }
1440
- }
1441
- }
1442
1316
}
1443
1317
1444
1318
pub const IMAGE_OPERANDS : & [ ( & str , ImageOperands ) ] = & [
0 commit comments