Use 'consts' as the flattened glslang source of scalar constants to recursively build the aggregate SPIR-V constant. If there are not enough elements present in 'consts', 0 will be substituted; an empty 'consts' can be used to create a fully zeroed SPIR-V constant.
| 11624 | // an empty 'consts' can be used to create a fully zeroed SPIR-V constant. |
| 11625 | // |
| 11626 | spv::Id TGlslangToSpvTraverser::createSpvConstantFromConstUnionArray(const glslang::TType& glslangType, |
| 11627 | const glslang::TConstUnionArray& consts, int& nextConst, bool specConstant) |
| 11628 | { |
| 11629 | // vector of constants for SPIR-V |
| 11630 | std::vector<spv::Id> spvConsts; |
| 11631 | |
| 11632 | // Type is used for struct and array constants |
| 11633 | spv::Id typeId = convertGlslangToSpvType(glslangType); |
| 11634 | |
| 11635 | if (glslangType.isArray()) { |
| 11636 | glslang::TType elementType(glslangType, 0); |
| 11637 | for (int i = 0; i < glslangType.getOuterArraySize(); ++i) |
| 11638 | spvConsts.push_back(createSpvConstantFromConstUnionArray(elementType, consts, nextConst, false)); |
| 11639 | } else if (glslangType.isMatrix()) { |
| 11640 | glslang::TType vectorType(glslangType, 0); |
| 11641 | for (int col = 0; col < glslangType.getMatrixCols(); ++col) |
| 11642 | spvConsts.push_back(createSpvConstantFromConstUnionArray(vectorType, consts, nextConst, false)); |
| 11643 | } else if (glslangType.isCoopMat()) { |
| 11644 | glslang::TType componentType(glslangType.getBasicType()); |
| 11645 | spvConsts.push_back(createSpvConstantFromConstUnionArray(componentType, consts, nextConst, false)); |
| 11646 | } else if (glslangType.isStruct()) { |
| 11647 | glslang::TVector<glslang::TTypeLoc>::const_iterator iter; |
| 11648 | for (iter = glslangType.getStruct()->begin(); iter != glslangType.getStruct()->end(); ++iter) |
| 11649 | spvConsts.push_back(createSpvConstantFromConstUnionArray(*iter->type, consts, nextConst, false)); |
| 11650 | } else if (glslangType.getVectorSize() > 1 || glslangType.isCoopVecOrLongVector()) { |
| 11651 | unsigned int numComponents = glslangType.isCoopVecOrLongVector() ? glslangType.getTypeParameters()->arraySizes->getDimSize(0) : glslangType.getVectorSize(); |
| 11652 | for (unsigned int i = 0; i < numComponents; ++i) { |
| 11653 | bool zero = nextConst >= consts.size(); |
| 11654 | switch (glslangType.getBasicType()) { |
| 11655 | case glslang::EbtInt: |
| 11656 | spvConsts.push_back(builder.makeIntConstant(zero ? 0 : consts[nextConst].getIConst())); |
| 11657 | break; |
| 11658 | case glslang::EbtUint: |
| 11659 | spvConsts.push_back(builder.makeUintConstant(zero ? 0 : consts[nextConst].getUConst())); |
| 11660 | break; |
| 11661 | case glslang::EbtFloat: |
| 11662 | spvConsts.push_back(builder.makeFloatConstant(zero ? 0.0F : (float)consts[nextConst].getDConst())); |
| 11663 | break; |
| 11664 | case glslang::EbtBool: |
| 11665 | spvConsts.push_back(builder.makeBoolConstant(zero ? false : consts[nextConst].getBConst())); |
| 11666 | break; |
| 11667 | case glslang::EbtInt8: |
| 11668 | builder.addCapability(spv::Capability::Int8); |
| 11669 | spvConsts.push_back(builder.makeInt8Constant(zero ? 0 : consts[nextConst].getI8Const())); |
| 11670 | break; |
| 11671 | case glslang::EbtUint8: |
| 11672 | builder.addCapability(spv::Capability::Int8); |
| 11673 | spvConsts.push_back(builder.makeUint8Constant(zero ? 0 : consts[nextConst].getU8Const())); |
| 11674 | break; |
| 11675 | case glslang::EbtInt16: |
| 11676 | builder.addCapability(spv::Capability::Int16); |
| 11677 | spvConsts.push_back(builder.makeInt16Constant(zero ? 0 : consts[nextConst].getI16Const())); |
| 11678 | break; |
| 11679 | case glslang::EbtUint16: |
| 11680 | builder.addCapability(spv::Capability::Int16); |
| 11681 | spvConsts.push_back(builder.makeUint16Constant(zero ? 0 : consts[nextConst].getU16Const())); |
| 11682 | break; |
| 11683 | case glslang::EbtInt64: |
nothing calls this directly
no test coverage detected