Turn on SpecConstantOpMode based on node qualifier
Move SpecConstantOpModeGuard from makeSpvConstantFromConstSubTree() to visitbinary() and visitunary(). Checking if the visiting node is a spec constants, if so, turn on the SpecConstantOpMode, otherwise, stay in the normal mode.
This commit is contained in:
@@ -72,12 +72,14 @@ public:
|
||||
SpecConstantOpModeGuard(spv::Builder* builder)
|
||||
: builder_(builder) {
|
||||
previous_flag_ = builder->isInSpecConstCodeGenMode();
|
||||
builder->setToSpecConstCodeGenMode();
|
||||
}
|
||||
~SpecConstantOpModeGuard() {
|
||||
previous_flag_ ? builder_->setToSpecConstCodeGenMode()
|
||||
: builder_->setToNormalCodeGenMode();
|
||||
}
|
||||
void turnOnSpecConstantOpMode() {
|
||||
builder_->setToSpecConstCodeGenMode();
|
||||
}
|
||||
|
||||
private:
|
||||
spv::Builder* builder_;
|
||||
@@ -813,6 +815,10 @@ void TGlslangToSpvTraverser::visitSymbol(glslang::TIntermSymbol* symbol)
|
||||
|
||||
bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::TIntermBinary* node)
|
||||
{
|
||||
SpecConstantOpModeGuard spec_constant_op_mode_setter(&builder);
|
||||
if (node->getType().getQualifier().isSpecConstant())
|
||||
spec_constant_op_mode_setter.turnOnSpecConstantOpMode();
|
||||
|
||||
// First, handle special cases
|
||||
switch (node->getOp()) {
|
||||
case glslang::EOpAssign:
|
||||
@@ -985,6 +991,10 @@ bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::T
|
||||
|
||||
bool TGlslangToSpvTraverser::visitUnary(glslang::TVisit /* visit */, glslang::TIntermUnary* node)
|
||||
{
|
||||
SpecConstantOpModeGuard spec_constant_op_mode_setter(&builder);
|
||||
if (node->getType().getQualifier().isSpecConstant())
|
||||
spec_constant_op_mode_setter.turnOnSpecConstantOpMode();
|
||||
|
||||
spv::Id result = spv::NoResult;
|
||||
|
||||
// try texturing first
|
||||
@@ -1946,7 +1956,7 @@ spv::Id TGlslangToSpvTraverser::makeArraySizeId(const glslang::TArraySizes& arra
|
||||
glslang::TIntermTyped* specNode = arraySizes.getDimNode(dim);
|
||||
if (specNode != nullptr) {
|
||||
builder.clearAccessChain();
|
||||
SpecConstantOpModeGuard set_to_spec_const_mode(&builder);
|
||||
// SpecConstantOpModeGuard set_to_spec_const_mode(&builder);
|
||||
specNode->traverse(this);
|
||||
return accessChainLoad(specNode->getAsTyped()->getType());
|
||||
}
|
||||
@@ -3920,22 +3930,12 @@ spv::Id TGlslangToSpvTraverser::createSpvConstantFromConstSubTree(
|
||||
} else if (glslang::TIntermBinary* bn = subTree->getAsBinaryNode()) {
|
||||
// Binary operation node, we should generate OpSpecConstantOp <binary op>
|
||||
// This case should only happen when Specialization Constants are involved.
|
||||
|
||||
// Spec constants defined with binary operations and other constants requires
|
||||
// OpSpecConstantOp instruction.
|
||||
SpecConstantOpModeGuard set_to_spec_const_mode(&builder);
|
||||
|
||||
bn->traverse(this);
|
||||
return accessChainLoad(bn->getType());
|
||||
|
||||
} else if (glslang::TIntermUnary* un = subTree->getAsUnaryNode()) {
|
||||
// Unary operation node, similar to binary operation node, should only
|
||||
// happen when specialization constants are involved.
|
||||
|
||||
// Spec constants defined with unary operations and other constants requires
|
||||
// OpSpecConstantOp instruction.
|
||||
SpecConstantOpModeGuard set_to_spec_const_mode(&builder);
|
||||
|
||||
un->traverse(this);
|
||||
return accessChainLoad(un->getType());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user