OpCompositeConstruct
| 4124 | |
| 4125 | // OpCompositeConstruct |
| 4126 | Id Builder::createCompositeConstruct(Id typeId, const std::vector<Id>& constituents) |
| 4127 | { |
| 4128 | assert(isAggregateType(typeId) || (getNumTypeConstituents(typeId) > 1 && |
| 4129 | getNumTypeConstituents(typeId) == constituents.size()) || |
| 4130 | ((isCooperativeVectorType(typeId) || isVectorType(typeId)) && constituents.size() == 1)); |
| 4131 | |
| 4132 | if (generatingOpCodeForSpecConst) { |
| 4133 | // Sometime, even in spec-constant-op mode, the constant composite to be |
| 4134 | // constructed may not be a specialization constant. |
| 4135 | // e.g.: |
| 4136 | // const mat2 m2 = mat2(a_spec_const, a_front_end_const, another_front_end_const, third_front_end_const); |
| 4137 | // The first column vector should be a spec constant one, as a_spec_const is a spec constant. |
| 4138 | // The second column vector should NOT be spec constant, as it does not contain any spec constants. |
| 4139 | // To handle such cases, we check the constituents of the constant vector to determine whether this |
| 4140 | // vector should be created as a spec constant. |
| 4141 | return makeCompositeConstant(typeId, constituents, |
| 4142 | std::any_of(constituents.begin(), constituents.end(), |
| 4143 | [&](spv::Id id) { return isSpecConstant(id); })); |
| 4144 | } |
| 4145 | |
| 4146 | bool replicate = false; |
| 4147 | size_t numConstituents = constituents.size(); |
| 4148 | |
| 4149 | if (useReplicatedComposites || isCooperativeVectorType(typeId)) { |
| 4150 | replicate = numConstituents > 0 && |
| 4151 | std::equal(constituents.begin() + 1, constituents.end(), constituents.begin()); |
| 4152 | } |
| 4153 | |
| 4154 | if (replicate) { |
| 4155 | numConstituents = 1; |
| 4156 | addCapability(spv::Capability::ReplicatedCompositesEXT); |
| 4157 | addExtension(spv::E_SPV_EXT_replicated_composites); |
| 4158 | } |
| 4159 | |
| 4160 | Op opcode = replicate ? Op::OpCompositeConstructReplicateEXT : Op::OpCompositeConstruct; |
| 4161 | |
| 4162 | Instruction* op = new Instruction(getUniqueId(), typeId, opcode); |
| 4163 | op->reserveOperands(constituents.size()); |
| 4164 | for (size_t c = 0; c < numConstituents; ++c) |
| 4165 | op->addIdOperand(constituents[c]); |
| 4166 | addInstruction(std::unique_ptr<Instruction>(op)); |
| 4167 | |
| 4168 | return op->getResultId(); |
| 4169 | } |
| 4170 | |
| 4171 | // coopmat conversion |
| 4172 | Id Builder::createCooperativeMatrixConversion(Id typeId, Id source) |
nothing calls this directly
no test coverage detected