Parameters of spirv_decorate_id should accept variables

spirv_decorate_id will generate OpDecorateId. The parameter list should
accept variables as part of decorations. This is because OpDecorateId
allows this. The spec says:

  All such <id> Extra Operands must be constant instructions or
  OpVariable instructions.
This commit is contained in:
Rex Xu 2023-03-17 16:10:11 +08:00 committed by arcady-lunarg
parent adcc7e8163
commit 8ff8b45131
8 changed files with 2257 additions and 2136 deletions

View file

@ -168,7 +168,7 @@ void TQualifier::setSpirvDecorateId(int decoration, const TIntermAggregate* args
TVector<const TIntermTyped*> extraOperands;
for (auto arg : args->getSequence()) {
auto extraOperand = arg->getAsTyped();
assert(extraOperand != nullptr && extraOperand->getQualifier().isConstant());
assert(extraOperand != nullptr);
extraOperands.push_back(extraOperand);
}
spirvDecorate->decorateIds[decoration] = extraOperands;
@ -202,30 +202,29 @@ TString TQualifier::getSpirvDecorateQualifierString() const
const auto appendStr = [&](const char* s) { qualifierString.append(s); };
const auto appendDecorate = [&](const TIntermTyped* constant) {
auto& constArray = constant->getAsConstantUnion() != nullptr ? constant->getAsConstantUnion()->getConstArray()
: constant->getAsSymbolNode()->getConstArray();
if (constant->getBasicType() == EbtFloat) {
float value = static_cast<float>(constArray[0].getDConst());
appendFloat(value);
if (constant->getAsConstantUnion()) {
auto& constArray = constant->getAsConstantUnion()->getConstArray();
if (constant->getBasicType() == EbtFloat) {
float value = static_cast<float>(constArray[0].getDConst());
appendFloat(value);
} else if (constant->getBasicType() == EbtInt) {
int value = constArray[0].getIConst();
appendInt(value);
} else if (constant->getBasicType() == EbtUint) {
unsigned value = constArray[0].getUConst();
appendUint(value);
} else if (constant->getBasicType() == EbtBool) {
bool value = constArray[0].getBConst();
appendBool(value);
} else if (constant->getBasicType() == EbtString) {
const TString* value = constArray[0].getSConst();
appendStr(value->c_str());
} else
assert(0);
} else {
assert(constant->getAsSymbolNode());
appendStr(constant->getAsSymbolNode()->getName().c_str());
}
else if (constant->getBasicType() == EbtInt) {
int value = constArray[0].getIConst();
appendInt(value);
}
else if (constant->getBasicType() == EbtUint) {
unsigned value = constArray[0].getUConst();
appendUint(value);
}
else if (constant->getBasicType() == EbtBool) {
bool value = constArray[0].getBConst();
appendBool(value);
}
else if (constant->getBasicType() == EbtString) {
const TString* value = constArray[0].getSConst();
appendStr(value->c_str());
}
else
assert(0);
};
for (auto& decorate : spirvDecorate->decorates) {

View file

@ -378,7 +378,7 @@ GLSLANG_WEB_EXCLUDE_ON
%type <interm.type> spirv_storage_class_qualifier
%type <interm.type> spirv_decorate_qualifier
%type <interm.intermNode> spirv_decorate_parameter_list spirv_decorate_parameter
%type <interm.intermNode> spirv_decorate_id_parameter_list
%type <interm.intermNode> spirv_decorate_id_parameter_list spirv_decorate_id_parameter
%type <interm.intermNode> spirv_decorate_string_parameter_list
%type <interm.type> spirv_type_specifier
%type <interm.spirvTypeParams> spirv_type_parameter_list spirv_type_parameter
@ -4347,23 +4347,33 @@ spirv_decorate_parameter
}
spirv_decorate_id_parameter_list
: constant_expression {
if ($1->getBasicType() != EbtFloat &&
$1->getBasicType() != EbtInt &&
$1->getBasicType() != EbtUint &&
$1->getBasicType() != EbtBool)
parseContext.error($1->getLoc(), "this type not allowed", $1->getType().getBasicString(), "");
: spirv_decorate_id_parameter {
$$ = parseContext.intermediate.makeAggregate($1);
}
| spirv_decorate_id_parameter_list COMMA constant_expression {
if ($3->getBasicType() != EbtFloat &&
$3->getBasicType() != EbtInt &&
$3->getBasicType() != EbtUint &&
$3->getBasicType() != EbtBool)
parseContext.error($3->getLoc(), "this type not allowed", $3->getType().getBasicString(), "");
| spirv_decorate_id_parameter_list COMMA spirv_decorate_id_parameter {
$$ = parseContext.intermediate.growAggregate($1, $3);
}
spirv_decorate_id_parameter
: variable_identifier {
if ($1->getAsConstantUnion() || $1->getAsSymbolNode())
$$ = $1;
else
parseContext.error($1->getLoc(), "only allow constants or variables which are not elements of a composite", "", "");
}
| FLOATCONSTANT {
$$ = parseContext.intermediate.addConstantUnion($1.d, EbtFloat, $1.loc, true);
}
| INTCONSTANT {
$$ = parseContext.intermediate.addConstantUnion($1.i, $1.loc, true);
}
| UINTCONSTANT {
$$ = parseContext.intermediate.addConstantUnion($1.u, $1.loc, true);
}
| BOOLCONSTANT {
$$ = parseContext.intermediate.addConstantUnion($1.b, $1.loc, true);
}
spirv_decorate_string_parameter_list
: STRING_LITERAL {
$$ = parseContext.intermediate.makeAggregate(

View file

@ -378,7 +378,7 @@ extern int yylex(YYSTYPE*, TParseContext&);
%type <interm.type> spirv_storage_class_qualifier
%type <interm.type> spirv_decorate_qualifier
%type <interm.intermNode> spirv_decorate_parameter_list spirv_decorate_parameter
%type <interm.intermNode> spirv_decorate_id_parameter_list
%type <interm.intermNode> spirv_decorate_id_parameter_list spirv_decorate_id_parameter
%type <interm.intermNode> spirv_decorate_string_parameter_list
%type <interm.type> spirv_type_specifier
%type <interm.spirvTypeParams> spirv_type_parameter_list spirv_type_parameter
@ -4347,23 +4347,33 @@ spirv_decorate_parameter
}
spirv_decorate_id_parameter_list
: constant_expression {
if ($1->getBasicType() != EbtFloat &&
$1->getBasicType() != EbtInt &&
$1->getBasicType() != EbtUint &&
$1->getBasicType() != EbtBool)
parseContext.error($1->getLoc(), "this type not allowed", $1->getType().getBasicString(), "");
: spirv_decorate_id_parameter {
$$ = parseContext.intermediate.makeAggregate($1);
}
| spirv_decorate_id_parameter_list COMMA constant_expression {
if ($3->getBasicType() != EbtFloat &&
$3->getBasicType() != EbtInt &&
$3->getBasicType() != EbtUint &&
$3->getBasicType() != EbtBool)
parseContext.error($3->getLoc(), "this type not allowed", $3->getType().getBasicString(), "");
| spirv_decorate_id_parameter_list COMMA spirv_decorate_id_parameter {
$$ = parseContext.intermediate.growAggregate($1, $3);
}
spirv_decorate_id_parameter
: variable_identifier {
if ($1->getAsConstantUnion() || $1->getAsSymbolNode())
$$ = $1;
else
parseContext.error($1->getLoc(), "only allow constants or variables which are not elements of a composite", "", "");
}
| FLOATCONSTANT {
$$ = parseContext.intermediate.addConstantUnion($1.d, EbtFloat, $1.loc, true);
}
| INTCONSTANT {
$$ = parseContext.intermediate.addConstantUnion($1.i, $1.loc, true);
}
| UINTCONSTANT {
$$ = parseContext.intermediate.addConstantUnion($1.u, $1.loc, true);
}
| BOOLCONSTANT {
$$ = parseContext.intermediate.addConstantUnion($1.b, $1.loc, true);
}
spirv_decorate_string_parameter_list
: STRING_LITERAL {
$$ = parseContext.intermediate.makeAggregate(

File diff suppressed because it is too large Load diff