From fc075a19946ea70fbe710ef40b23a8732474c85e Mon Sep 17 00:00:00 2001 From: ravi688 Date: Sun, 23 Jun 2024 18:03:09 +0530 Subject: [PATCH] Convert 8/16-bit int (and their composite vector) types to their corresponding 32-bit types first - this fixes #3607 - and this also fixes assertion failure in the PR #3628 - this change emits appropriate Op{S|U}Convert instructions instead of OpCompositeExtract followed by OpCompositeConstruct for 8/16-bit integer types. --- glslang/MachineIndependent/ParseHelper.cpp | 84 +++++++++++++++------- 1 file changed, 60 insertions(+), 24 deletions(-) diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index c5f0e63f14..da64835705 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -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; @@ -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; @@ -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; @@ -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;