fix the wrong generated code when a non-constant array is declared with its size derived from spec constant operations
This commit is contained in:
parent
aa0298bfde
commit
4c9126153d
3 changed files with 133 additions and 112 deletions
|
|
@ -66,6 +66,25 @@ namespace {
|
|||
// or a different instruction sequence to do something gets used).
|
||||
const int GeneratorVersion = 1;
|
||||
|
||||
namespace {
|
||||
class SpecConstantOpModeGuard {
|
||||
public:
|
||||
SpecConstantOpModeGuard(spv::Builder* builder)
|
||||
: builder_(builder) {
|
||||
previous_flag_ = builder->isInSpecConstCodeGenMode();
|
||||
builder->setToSpecConstCodeGenMode();
|
||||
}
|
||||
~SpecConstantOpModeGuard() {
|
||||
previous_flag_ ? builder_->setToSpecConstCodeGenMode()
|
||||
: builder_->setToNormalCodeGenMode();
|
||||
}
|
||||
|
||||
private:
|
||||
spv::Builder* builder_;
|
||||
bool previous_flag_;
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
// The main holder of information for translating glslang to SPIR-V.
|
||||
//
|
||||
|
|
@ -1927,6 +1946,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);
|
||||
specNode->traverse(this);
|
||||
return accessChainLoad(specNode->getAsTyped()->getType());
|
||||
}
|
||||
|
|
@ -3868,25 +3888,6 @@ spv::Id TGlslangToSpvTraverser::createSpvConstantFromConstUnionArray(const glsla
|
|||
return builder.makeCompositeConstant(typeId, spvConsts);
|
||||
}
|
||||
|
||||
namespace {
|
||||
class SpecConstantOpModeGuard {
|
||||
public:
|
||||
SpecConstantOpModeGuard(spv::Builder* builder)
|
||||
: builder_(builder) {
|
||||
previous_flag_ = builder->isInSpecConstCodeGenMode();
|
||||
builder->setToSpecConstCodeGenMode();
|
||||
}
|
||||
~SpecConstantOpModeGuard() {
|
||||
previous_flag_ ? builder_->setToSpecConstCodeGenMode()
|
||||
: builder_->setToNormalCodeGenMode();
|
||||
}
|
||||
|
||||
private:
|
||||
spv::Builder* builder_;
|
||||
bool previous_flag_;
|
||||
};
|
||||
}
|
||||
|
||||
// Create constant ID from const initializer sub tree.
|
||||
spv::Id TGlslangToSpvTraverser::createSpvConstantFromConstSubTree(
|
||||
glslang::TIntermTyped* subTree)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue