Skip to content

Commit

Permalink
Convert 8/16-bit int (and their composite vector) types to their corr…
Browse files Browse the repository at this point in the history
…esponding 32-bit types first

 - this fixes KhronosGroup#3607
 - and this also fixes assertion failure in the PR KhronosGroup#3628

 - this change emits appropriate Op{S|U}Convert instructions instead of OpCompositeExtract followed by OpCompositeConstruct
   for 8/16-bit integer types.
  • Loading branch information
ravi688 committed Jun 23, 2024
1 parent 2d8b71f commit fc075a1
Showing 1 changed file with 60 additions and 24 deletions.
84 changes: 60 additions & 24 deletions glslang/MachineIndependent/ParseHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8570,12 +8570,21 @@ TIntermTyped* TParseContext::constructBuiltIn(const TType& type, TOperator op, T
TType tempType(EbtInt, EvqTemporary, type.getVectorSize());
newNode = node;
if (tempType != newNode->getType()) {
TOperator aggregateOp;
if (op == EOpConstructInt8)
aggregateOp = EOpConstructInt;
else
aggregateOp = (TOperator)(EOpConstructIVec2 + op - EOpConstructI8Vec2);
newNode = intermediate.setAggregateOperator(newNode, aggregateOp, tempType, node->getLoc());
// if the source and target size matches then we need to emit OpSConvert instruction
// which would convert 8-bit or 16-bit integer types to 32-bit sized integer type (including vector composites)
if (type.getVectorSize() == node->getType().getVectorSize()) {
newNode = intermediate.addConversion(EbtInt, newNode);
}
// otherwise create aggregate operator
// which internally emits OpCompositeExtract followed by OpCompositeConstruct instruction.
else {
TOperator aggregateOp;
if (op == EOpConstructInt8)
aggregateOp = EOpConstructInt;
else
aggregateOp = (TOperator)(EOpConstructIVec2 + op - EOpConstructI8Vec2);
newNode = intermediate.setAggregateOperator(newNode, aggregateOp, tempType, node->getLoc());
}
}
newNode = intermediate.addConversion(EbtInt8, newNode);
return newNode;
Expand All @@ -8594,12 +8603,21 @@ TIntermTyped* TParseContext::constructBuiltIn(const TType& type, TOperator op, T
TType tempType(EbtUint, EvqTemporary, type.getVectorSize());
newNode = node;
if (tempType != newNode->getType()) {
TOperator aggregateOp;
if (op == EOpConstructUint8)
aggregateOp = EOpConstructUint;
else
aggregateOp = (TOperator)(EOpConstructUVec2 + op - EOpConstructU8Vec2);
newNode = intermediate.setAggregateOperator(newNode, aggregateOp, tempType, node->getLoc());
// if the source and target size matches then we need to emit OpUConvert instruction
// which would convert 8-bit or 16-bit integer types to 32-bit sized integer type (including vector composites)
if (type.getVectorSize() == node->getType().getVectorSize()) {
newNode = intermediate.addConversion(EbtUint, newNode);
}
// otherwise create aggregate operator
// which internally emits OpCompositeExtract followed by OpCompositeConstruct instruction.
else {
TOperator aggregateOp;
if (op == EOpConstructUint8)
aggregateOp = EOpConstructUint;
else
aggregateOp = (TOperator)(EOpConstructUVec2 + op - EOpConstructU8Vec2);
newNode = intermediate.setAggregateOperator(newNode, aggregateOp, tempType, node->getLoc());
}
}
newNode = intermediate.addConversion(EbtUint8, newNode);
return newNode;
Expand All @@ -8618,12 +8636,21 @@ TIntermTyped* TParseContext::constructBuiltIn(const TType& type, TOperator op, T
TType tempType(EbtInt, EvqTemporary, type.getVectorSize());
newNode = node;
if (tempType != newNode->getType()) {
TOperator aggregateOp;
if (op == EOpConstructInt16)
aggregateOp = EOpConstructInt;
else
aggregateOp = (TOperator)(EOpConstructIVec2 + op - EOpConstructI16Vec2);
newNode = intermediate.setAggregateOperator(newNode, aggregateOp, tempType, node->getLoc());
// if the source and target size matches then we need to emit OpSConvert instruction
// which would convert 8-bit or 16-bit integer types to 32-bit sized integer type (including vector composites)
if (type.getVectorSize() == node->getType().getVectorSize()) {
newNode = intermediate.addConversion(EbtInt, newNode);
}
// otherwise create aggregate operator
// which internally emits OpCompositeExtract followed by OpCompositeConstruct instruction.
else {
TOperator aggregateOp;
if (op == EOpConstructInt16)
aggregateOp = EOpConstructInt;
else
aggregateOp = (TOperator)(EOpConstructIVec2 + op - EOpConstructI16Vec2);
newNode = intermediate.setAggregateOperator(newNode, aggregateOp, tempType, node->getLoc());
}
}
newNode = intermediate.addConversion(EbtInt16, newNode);
return newNode;
Expand All @@ -8642,12 +8669,21 @@ TIntermTyped* TParseContext::constructBuiltIn(const TType& type, TOperator op, T
TType tempType(EbtUint, EvqTemporary, type.getVectorSize());
newNode = node;
if (tempType != newNode->getType()) {
TOperator aggregateOp;
if (op == EOpConstructUint16)
aggregateOp = EOpConstructUint;
else
aggregateOp = (TOperator)(EOpConstructUVec2 + op - EOpConstructU16Vec2);
newNode = intermediate.setAggregateOperator(newNode, aggregateOp, tempType, node->getLoc());
// if the source and target size matches then we need to emit OpUConvert instruction
// which would convert 8-bit or 16-bit integer types to 32-bit sized integer type (including vector composites)
if (type.getVectorSize() == node->getType().getVectorSize()) {
newNode = intermediate.addConversion(EbtUint, newNode);
}
// otherwise create aggregate operator
// which internally emits OpCompositeExtract followed by OpCompositeConstruct instruction.
else {
TOperator aggregateOp;
if (op == EOpConstructUint16)
aggregateOp = EOpConstructUint;
else
aggregateOp = (TOperator)(EOpConstructUVec2 + op - EOpConstructU16Vec2);
newNode = intermediate.setAggregateOperator(newNode, aggregateOp, tempType, node->getLoc());
}
}
newNode = intermediate.addConversion(EbtUint16, newNode);
return newNode;
Expand Down

0 comments on commit fc075a1

Please sign in to comment.