Skip to content

Commit 03e16d2

Browse files
check specId
Signed-off-by: Zhang, Winston <[email protected]>
1 parent c9638d8 commit 03e16d2

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

unified-runtime/source/adapters/level_zero/program.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,8 @@ static bool isValidSpecConstantId(const uint8_t *spirvCode, size_t spirvSize,
10181018
return false;
10191019
}
10201020

1021-
// Parse instructions looking for OpSpecConstant* instructions
1021+
// Parse instructions looking for OpDecorate instructions with SpecId
1022+
// decoration
10221023
size_t pos = headerSize;
10231024
const size_t totalWords = spirvSize / sizeof(uint32_t);
10241025

@@ -1034,16 +1035,14 @@ static bool isValidSpecConstantId(const uint8_t *spirvCode, size_t spirvSize,
10341035
break; // Invalid instruction
10351036
}
10361037

1037-
// OpSpecConstantTrue = 48, OpSpecConstantFalse = 49, OpSpecConstant = 50
1038-
// OpSpecConstantComposite = 51, OpSpecConstantOp = 52
1039-
if (opcode >= 48 && opcode <= 52) {
1040-
if (length >= 3) {
1041-
// All OpSpecConstant* instructions have at least 3 words
1042-
// words[pos + 0] = instruction header
1043-
// words[pos + 1] = result type id
1044-
// words[pos + 2] = result id (this is the specialization constant id)
1045-
uint32_t resultId = words[pos + 2];
1046-
if (resultId == specId) {
1038+
// OpDecorate = 71, and we need decoration SpecId = 1
1039+
if (opcode == 71 && length >= 4) {
1040+
// OpDecorate with at least target_id,
1041+
// decoration, and extra operand
1042+
uint32_t decoration = words[pos + 2];
1043+
if (decoration == 1) { // SpecId decoration
1044+
uint32_t actualSpecId = words[pos + 3];
1045+
if (actualSpecId == specId) {
10471046
return true;
10481047
}
10491048
}

0 commit comments

Comments
 (0)