Skip to content

Commit 5026664

Browse files
authored
[val] Allow Generic casts to/from CodeSectionINTEL storage class (KhronosGroup#6787)
resolves KhronosGroup#6700
1 parent 6ef84b5 commit 5026664

2 files changed

Lines changed: 109 additions & 12 deletions

File tree

source/val/validate_conversion.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -611,10 +611,12 @@ spv_result_t ValidatePtrCastToGeneric(ValidationState_t& _,
611611

612612
if (input_storage_class != spv::StorageClass::Workgroup &&
613613
input_storage_class != spv::StorageClass::CrossWorkgroup &&
614-
input_storage_class != spv::StorageClass::Function)
614+
input_storage_class != spv::StorageClass::Function &&
615+
input_storage_class != spv::StorageClass::CodeSectionINTEL)
615616
return _.diag(SPV_ERROR_INVALID_DATA, inst)
616617
<< "Expected input to have storage class Workgroup, "
617-
<< "CrossWorkgroup or Function: " << spvOpcodeString(opcode);
618+
<< "CrossWorkgroup, Function or CodeSectionINTEL: "
619+
<< spvOpcodeString(opcode);
618620

619621
if (result_data_type != input_data_type)
620622
return _.diag(SPV_ERROR_INVALID_DATA, inst)
@@ -638,10 +640,12 @@ spv_result_t ValidateGenericCastToPtr(ValidationState_t& _,
638640

639641
if (result_storage_class != spv::StorageClass::Workgroup &&
640642
result_storage_class != spv::StorageClass::CrossWorkgroup &&
641-
result_storage_class != spv::StorageClass::Function)
643+
result_storage_class != spv::StorageClass::Function &&
644+
result_storage_class != spv::StorageClass::CodeSectionINTEL)
642645
return _.diag(SPV_ERROR_INVALID_DATA, inst)
643646
<< "Expected Result Type to have storage class Workgroup, "
644-
<< "CrossWorkgroup or Function: " << spvOpcodeString(opcode);
647+
<< "CrossWorkgroup, Function or CodeSectionINTEL: "
648+
<< spvOpcodeString(opcode);
645649

646650
const uint32_t input_type = _.GetOperandTypeId(inst, operand_index);
647651
spv::StorageClass input_storage_class;
@@ -699,10 +703,12 @@ spv_result_t ValidateGenericCastToPtrExplicit(ValidationState_t& _,
699703

700704
if (target_storage_class != spv::StorageClass::Workgroup &&
701705
target_storage_class != spv::StorageClass::CrossWorkgroup &&
702-
target_storage_class != spv::StorageClass::Function)
706+
target_storage_class != spv::StorageClass::Function &&
707+
target_storage_class != spv::StorageClass::CodeSectionINTEL)
703708
return _.diag(SPV_ERROR_INVALID_DATA, inst)
704709
<< "Expected target storage class to be Workgroup, "
705-
<< "CrossWorkgroup or Function: " << spvOpcodeString(opcode);
710+
<< "CrossWorkgroup, Function or CodeSectionINTEL: "
711+
<< spvOpcodeString(opcode);
706712
return SPV_SUCCESS;
707713
}
708714

test/val/val_conversion_test.cpp

Lines changed: 97 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,8 @@ TEST_F(ValidateConversion, PtrCastToGenericWrongInputStorageClass) {
12371237
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
12381238
EXPECT_THAT(getDiagnosticString(),
12391239
HasSubstr("Expected input to have storage class Workgroup, "
1240-
"CrossWorkgroup or Function: PtrCastToGeneric"));
1240+
"CrossWorkgroup, Function or CodeSectionINTEL: "
1241+
"PtrCastToGeneric"));
12411242
}
12421243

12431244
TEST_F(ValidateConversion, PtrCastToGenericPointToDifferentType) {
@@ -1254,6 +1255,36 @@ TEST_F(ValidateConversion, PtrCastToGenericPointToDifferentType) {
12541255
"PtrCastToGeneric"));
12551256
}
12561257

1258+
TEST_F(ValidateConversion, PtrCastToGenericFromCodeSectionINTELSuccess) {
1259+
const std::string spirv = R"(
1260+
OpCapability Kernel
1261+
OpCapability Addresses
1262+
OpCapability FunctionPointersINTEL
1263+
OpCapability GenericPointer
1264+
OpCapability Int8
1265+
OpCapability Linkage
1266+
OpExtension "SPV_INTEL_function_pointers"
1267+
OpMemoryModel Physical64 OpenCL
1268+
OpName %fn "fn"
1269+
OpDecorate %fn LinkageAttributes "fn" Export
1270+
%u8 = OpTypeInt 8 0
1271+
%code_ptr = OpTypePointer CodeSectionINTEL %u8
1272+
%void = OpTypeVoid
1273+
%fn_type = OpTypeFunction %void %code_ptr
1274+
%gen_ptr = OpTypePointer Generic %u8
1275+
%u8_0 = OpConstantNull %u8
1276+
%fn = OpFunction %void None %fn_type
1277+
%param = OpFunctionParameter %code_ptr
1278+
%entry = OpLabel
1279+
%gen = OpPtrCastToGeneric %gen_ptr %param
1280+
OpStore %gen %u8_0 Aligned 1
1281+
OpReturn
1282+
OpFunctionEnd
1283+
)";
1284+
CompileSuccessfully(spirv.c_str());
1285+
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1286+
}
1287+
12571288
TEST_F(ValidateConversion, GenericCastToPtrSuccess) {
12581289
const std::string body = R"(
12591290
%ptr_func = OpVariable %f32ptr_func Function
@@ -1292,7 +1323,8 @@ TEST_F(ValidateConversion, GenericCastToPtrWrongResultStorageClass) {
12921323
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
12931324
EXPECT_THAT(getDiagnosticString(),
12941325
HasSubstr("Expected Result Type to have storage class Workgroup, "
1295-
"CrossWorkgroup or Function: GenericCastToPtr"));
1326+
"CrossWorkgroup, Function or CodeSectionINTEL: "
1327+
"GenericCastToPtr"));
12961328
}
12971329

12981330
TEST_F(ValidateConversion, GenericCastToPtrWrongInputType) {
@@ -1336,6 +1368,36 @@ TEST_F(ValidateConversion, GenericCastToPtrPointToDifferentType) {
13361368
"GenericCastToPtr"));
13371369
}
13381370

1371+
TEST_F(ValidateConversion, GenericCastToPtrToCodeSectionINTELSuccess) {
1372+
const std::string spirv = R"(
1373+
OpCapability Kernel
1374+
OpCapability Addresses
1375+
OpCapability FunctionPointersINTEL
1376+
OpCapability GenericPointer
1377+
OpCapability Int8
1378+
OpCapability Linkage
1379+
OpExtension "SPV_INTEL_function_pointers"
1380+
OpMemoryModel Physical64 OpenCL
1381+
OpName %fn "fn"
1382+
OpDecorate %fn LinkageAttributes "fn" Export
1383+
%u8 = OpTypeInt 8 0
1384+
%code_ptr = OpTypePointer CodeSectionINTEL %u8
1385+
%void = OpTypeVoid
1386+
%fn_type = OpTypeFunction %void %code_ptr
1387+
%gen_ptr = OpTypePointer Generic %u8
1388+
%u8_0 = OpConstantNull %u8
1389+
%fn = OpFunction %void None %fn_type
1390+
%param = OpFunctionParameter %code_ptr
1391+
%entry = OpLabel
1392+
%gen = OpPtrCastToGeneric %gen_ptr %param
1393+
%code = OpGenericCastToPtr %code_ptr %gen
1394+
OpReturn
1395+
OpFunctionEnd
1396+
)";
1397+
CompileSuccessfully(spirv.c_str());
1398+
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1399+
}
1400+
13391401
TEST_F(ValidateConversion, GenericCastToPtrExplicitSuccess) {
13401402
const std::string body = R"(
13411403
%ptr_func = OpVariable %f32ptr_func Function
@@ -1387,10 +1449,10 @@ TEST_F(ValidateConversion, GenericCastToPtrExplicitWrongResultStorageClass) {
13871449

13881450
CompileSuccessfully(GenerateKernelCode(body).c_str());
13891451
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1390-
EXPECT_THAT(
1391-
getDiagnosticString(),
1392-
HasSubstr("Expected target storage class to be Workgroup, "
1393-
"CrossWorkgroup or Function: GenericCastToPtrExplicit"));
1452+
EXPECT_THAT(getDiagnosticString(),
1453+
HasSubstr("Expected target storage class to be Workgroup, "
1454+
"CrossWorkgroup, Function or CodeSectionINTEL: "
1455+
"GenericCastToPtrExplicit"));
13941456
}
13951457

13961458
TEST_F(ValidateConversion, GenericCastToPtrExplicitWrongInputType) {
@@ -1435,6 +1497,35 @@ TEST_F(ValidateConversion, GenericCastToPtrExplicitPointToDifferentType) {
14351497
"GenericCastToPtrExplicit"));
14361498
}
14371499

1500+
TEST_F(ValidateConversion, GenericCastToPtrExplicitToCodeSectionINTELSuccess) {
1501+
const std::string spirv = R"(
1502+
OpCapability Kernel
1503+
OpCapability Addresses
1504+
OpCapability FunctionPointersINTEL
1505+
OpCapability GenericPointer
1506+
OpCapability Int8
1507+
OpCapability Linkage
1508+
OpExtension "SPV_INTEL_function_pointers"
1509+
OpMemoryModel Physical64 OpenCL
1510+
OpName %fn "fn"
1511+
OpDecorate %fn LinkageAttributes "fn" Export
1512+
%u8 = OpTypeInt 8 0
1513+
%code_ptr = OpTypePointer CodeSectionINTEL %u8
1514+
%void = OpTypeVoid
1515+
%fn_type = OpTypeFunction %void %code_ptr
1516+
%gen_ptr = OpTypePointer Generic %u8
1517+
%fn = OpFunction %void None %fn_type
1518+
%param = OpFunctionParameter %code_ptr
1519+
%entry = OpLabel
1520+
%gen = OpPtrCastToGeneric %gen_ptr %param
1521+
%code = OpGenericCastToPtrExplicit %code_ptr %gen CodeSectionINTEL
1522+
OpReturn
1523+
OpFunctionEnd
1524+
)";
1525+
CompileSuccessfully(spirv.c_str());
1526+
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1527+
}
1528+
14381529
TEST_F(ValidateConversion, CoopMatConversionSuccess) {
14391530
const std::string body =
14401531
R"(

0 commit comments

Comments
 (0)