Lines Matching refs:spv

43 namespace spv {
60 const spv::Op opCode = asOpCode(word);
65 case spv::OpExtInst:
74 spirvbin_t::range_t spirvbin_t::literalRange(spv::Op opCode) const
79 case spv::OpTypeFloat: // fall through...
80 case spv::OpTypePointer: return range_t(2, 3);
81 case spv::OpTypeInt: return range_t(2, 4);
82 // TODO: case spv::OpTypeImage:
83 // TODO: case spv::OpTypeSampledImage:
84 case spv::OpTypeSampler: return range_t(3, 8);
85 case spv::OpTypeVector: // fall through
86 case spv::OpTypeMatrix: // ...
87 case spv::OpTypePipe: return range_t(3, 4);
88 case spv::OpConstant: return range_t(3, maxCount);
93 spirvbin_t::range_t spirvbin_t::typeRange(spv::Op opCode) const
101 case spv::OpTypeVector: // fall through
102 case spv::OpTypeMatrix: // ...
103 case spv::OpTypeSampler: // ...
104 case spv::OpTypeArray: // ...
105 case spv::OpTypeRuntimeArray: // ...
106 case spv::OpTypePipe: return range_t(2, 3);
107 case spv::OpTypeStruct: // fall through
108 case spv::OpTypeFunction: return range_t(2, maxCount);
109 case spv::OpTypePointer: return range_t(3, 4);
114 spirvbin_t::range_t spirvbin_t::constRange(spv::Op opCode) const
119 case spv::OpTypeArray: // fall through...
120 case spv::OpTypeRuntimeArray: return range_t(3, 4);
121 case spv::OpConstantComposite: return range_t(3, maxCount);
129 unsigned spirvbin_t::typeSizeInWords(spv::Id id) const
132 const spv::Op opCode = asOpCode(typeStart);
138 case spv::OpTypeInt: // fall through...
139 case spv::OpTypeFloat: return (spv[typeStart+2]+31)/32;
147 unsigned spirvbin_t::idTypeSizeInWords(spv::Id id) const
159 bool spirvbin_t::isStripOp(spv::Op opCode, unsigned start) const
162 case spv::OpSource:
163 case spv::OpSourceExtension:
164 case spv::OpName:
165 case spv::OpMemberName:
166 case spv::OpLine :
186 bool spirvbin_t::isFlowCtrl(spv::Op opCode) const
189 case spv::OpBranchConditional:
190 case spv::OpBranch:
191 case spv::OpSwitch:
192 case spv::OpLoopMerge:
193 case spv::OpSelectionMerge:
194 case spv::OpLabel:
195 case spv::OpFunction:
196 case spv::OpFunctionEnd: return true;
202 bool spirvbin_t::isTypeOp(spv::Op opCode) const
205 case spv::OpTypeVoid:
206 case spv::OpTypeBool:
207 case spv::OpTypeInt:
208 case spv::OpTypeFloat:
209 case spv::OpTypeVector:
210 case spv::OpTypeMatrix:
211 case spv::OpTypeImage:
212 case spv::OpTypeSampler:
213 case spv::OpTypeArray:
214 case spv::OpTypeRuntimeArray:
215 case spv::OpTypeStruct:
216 case spv::OpTypeOpaque:
217 case spv::OpTypePointer:
218 case spv::OpTypeFunction:
219 case spv::OpTypeEvent:
220 case spv::OpTypeDeviceEvent:
221 case spv::OpTypeReserveId:
222 case spv::OpTypeQueue:
223 case spv::OpTypeSampledImage:
224 case spv::OpTypePipe: return true;
230 bool spirvbin_t::isConstOp(spv::Op opCode) const
233 case spv::OpConstantSampler:
237 case spv::OpConstantNull:
238 case spv::OpConstantTrue:
239 case spv::OpConstantFalse:
240 case spv::OpConstantComposite:
241 case spv::OpConstant:
249 const auto inst_fn_nop = [](spv::Op, unsigned) { return false; };
250 const auto op_fn_nop = [](spv::Id&) { };
255 const spv::Id spirvbin_t::unmapped = spv::Id(-10000);
256 const spv::Id spirvbin_t::unused = spv::Id(-10001);
259 spv::Id spirvbin_t::nextUnusedId(spv::Id id)
267 spv::Id spirvbin_t::localId(spv::Id id, spv::Id newId)
269 //assert(id != spv::NoResult && newId != spv::NoResult);
310 const spirword_t * pos = spv.data() + word;
333 [this](spv::Id& id) {
349 spv::Id unusedId = 1; // can't use 0: that's NoResult
352 for (spv::Id id = 0; id < idMapL.size(); ++id) {
383 [&](spv::Op opCode, unsigned start) {
396 [&](spv::Op opCode, unsigned start) {
399 case spv::OpName:
400 case spv::OpMemberName:
401 case spv::OpDecorate:
402 case spv::OpMemberDecorate:
429 entryPoint = spv::NoResult;
435 spv::Id fnRes = spv::NoResult;
439 [&](spv::Op opCode, unsigned start) {
441 spv::Id typeId = spv::NoResult;
443 if (spv::InstructionDesc[opCode].hasType())
447 if (spv::InstructionDesc[opCode].hasResult()) {
448 const spv::Id resultId = asId(word++);
451 if (typeId != spv::NoResult) {
462 if (opCode == spv::Op::OpName) {
463 const spv::Id target = asId(start+1);
467 } else if (opCode == spv::Op::OpFunctionCall) {
469 } else if (opCode == spv::Op::OpEntryPoint) {
471 } else if (opCode == spv::Op::OpFunction) {
479 } else if (opCode == spv::Op::OpFunctionEnd) {
480 assert(fnRes != spv::NoResult);
492 assert(asId(start + 2) != spv::NoResult);
495 assert(asId(start + 1) != spv::NoResult);
502 [this](spv::Id& id) { localId(id, unmapped); }
511 if (spv.size() < header_size) {
516 if (magic() != spv::MagicNumber) {
536 spv::Op opCode = asOpCode(instructionStart);
538 if (nextInst > int(spv.size())) {
550 if (spv::InstructionDesc[opCode].hasType()) {
555 if (spv::InstructionDesc[opCode].hasResult()) {
562 if (opCode == spv::OpExtInst) {
577 spv::Id idBuffer[idBufferSize];
587 if (opCode == spv::OpSpecConstantOp) {
594 switch (spv::InstructionDesc[opCode].operands.getClass(op)) {
595 case spv::OperandId:
596 case spv::OperandScope:
597 case spv::OperandMemorySemantics:
603 case spv::OperandVariableIds:
608 case spv::OperandVariableLiterals:
610 // if (opCode == spv::OpDecorate && asDecoration(word - 1) == spv::DecorationBuiltIn) {
617 case spv::OperandVariableLiteralId: {
640 case spv::OperandLiteralString: {
647 case spv::OperandVariableLiteralStrings:
651 case spv::OperandExecutionMode:
655 case spv::OperandLiteralNumber:
656 case spv::OperandSource:
657 case spv::OperandExecutionModel:
658 case spv::OperandAddressing:
659 case spv::OperandMemory:
660 case spv::OperandStorage:
661 case spv::OperandDimensionality:
662 case spv::OperandSamplerAddressingMode:
663 case spv::OperandSamplerFilterMode:
664 case spv::OperandSamplerImageFormat:
665 case spv::OperandImageChannelOrder:
666 case spv::OperandImageChannelDataType:
667 case spv::OperandImageOperands:
668 case spv::OperandFPFastMath:
669 case spv::OperandFPRoundingMode:
670 case spv::OperandLinkageType:
671 case spv::OperandAccessQualifier:
672 case spv::OperandFuncParamAttr:
673 case spv::OperandDecoration:
674 case spv::OperandBuiltIn:
675 case spv::OperandSelect:
676 case spv::OperandLoop:
677 case spv::OperandFunction:
678 case spv::OperandMemoryAccess:
679 case spv::OperandGroupOperation:
680 case spv::OperandKernelEnqueueFlags:
681 case spv::OperandKernelProfilingInfo:
682 case spv::OperandCapability:
683 case spv::OperandCooperativeMatrixOperands:
704 end = (end == 0 ? unsigned(spv.size()) : end);
707 unsigned nextInst = unsigned(spv.size());
747 spv::Id fnId = spv::NoResult;
749 instPos.reserve(unsigned(spv.size()) / 16); // initial estimate; can grow if needed.
753 [&](spv::Op, unsigned start) { instPos.push_back(start); return true; },
768 const spv::Op opCode = asOpCode(start);
770 if (opCode == spv::OpFunction)
773 if (opCode == spv::OpFunctionEnd)
774 fnId = spv::NoResult;
776 if (fnId != spv::NoResult) { // if inside a function
777 if (spv::InstructionDesc[opCode].hasResult()) {
778 const unsigned word = start + (spv::InstructionDesc[opCode].hasType() ? 2 : 1);
779 const spv::Id resId = asId(word);
783 if (asOpCode(instPos[i]) == spv::OpFunction)
789 if (asOpCode(instPos[i]) == spv::OpFunctionEnd)
804 spv::Op thisOpCode(spv::OpNop);
807 fnId = spv::NoResult;
810 [&](spv::Op opCode, unsigned start) {
812 case spv::OpFunction:
819 case spv::OpImageSampleImplicitLod:
820 case spv::OpImageSampleExplicitLod:
821 case spv::OpImageSampleDrefImplicitLod:
822 case spv::OpImageSampleDrefExplicitLod:
823 case spv::OpImageSampleProjImplicitLod:
824 case spv::OpImageSampleProjExplicitLod:
825 case spv::OpImageSampleProjDrefImplicitLod:
826 case spv::OpImageSampleProjDrefExplicitLod:
827 case spv::OpDot:
828 case spv::OpCompositeExtract:
829 case spv::OpCompositeInsert:
830 case spv::OpVectorShuffle:
831 case spv::OpLabel:
832 case spv::OpVariable:
834 case spv::OpAccessChain:
835 case spv::OpLoad:
836 case spv::OpStore:
837 case spv::OpCompositeConstruct:
838 case spv::OpFunctionCall:
844 thisOpCode = spv::OpNop;
850 [&](spv::Id& id) {
851 if (thisOpCode != spv::OpNop) {
878 [&](spv::Op opCode, unsigned start) {
880 if ((opCode == spv::OpVariable && asWordCount(start) == 4) &&
881 (spv[start+3] == spv::StorageClassUniform ||
882 spv[start+3] == spv::StorageClassUniformConstant ||
883 spv[start+3] == spv::StorageClassInput))
886 if (opCode == spv::OpAccessChain && fnLocalVars.count(asId(start+3)) > 0)
889 if (opCode == spv::OpLoad && fnLocalVars.count(asId(start+3)) > 0) {
897 [&](spv::Id& id) { if (idMap.find(id) != idMap.end()) id = idMap[id]; }
908 [&](spv::Op opCode, unsigned start) {
910 if ((opCode == spv::OpVariable && asWordCount(start) == 4) &&
911 (spv[start+3] == spv::StorageClassOutput))
914 if (opCode == spv::OpStore && fnLocalVars.count(asId(start+1)) > 0) {
928 [&](spv::Id& id) { if (idMap.find(id) != idMap.end()) id = idMap[id]; }
947 [&](spv::Op opCode, unsigned start) {
955 if ((opCode == spv::OpVariable && spv[start+3] == spv::StorageClassFunction && asWordCount(start) == 4)) {
961 if ((opCode == spv::OpAccessChain || opCode == spv::OpInBoundsAccessChain) && fnLocalVars.count(asId(start+3)) > 0) {
967 if (opCode == spv::OpLoad && fnLocalVars.count(asId(start+3)) > 0) {
968 const spv::Id varId = asId(start+3);
977 if (wordCount > 4 && (spv[start+4] & spv::MemoryAccessVolatileMask)) {
993 if (opCode == spv::OpStore && fnLocalVars.count(asId(start+1)) > 0) {
994 const spv::Id varId = asId(start+1);
1005 if (wordCount > 3 && (spv[start+3] & spv::MemoryAccessVolatileMask)) {
1025 [&](spv::Id& id) {
1037 [&](spv::Op opCode, unsigned start) {
1038 if (opCode == spv::OpLoad && fnLocalVars.count(asId(start+3)) > 0)
1054 spv::Id id = idPair.first;
1063 [&](spv::Op opCode, unsigned start) {
1064 if ((opCode == spv::OpLoad && fnLocalVars.count(asId(start+3)) > 0) ||
1065 (opCode == spv::OpStore && fnLocalVars.count(asId(start+1)) > 0) ||
1066 (opCode == spv::OpVariable && fnLocalVars.count(asId(start+2)) > 0)) {
1075 [&](spv::Id& id) {
1111 [&](spv::Op opCode, unsigned start) {
1112 if (opCode == spv::Op::OpFunctionCall) {
1140 std::unordered_map<spv::Id, int> varUseCount;
1144 [&](spv::Op opCode, unsigned start) {
1145 if (opCode == spv::OpVariable) {
1148 } else if (opCode == spv::OpEntryPoint) {
1158 [&](spv::Id& id) { if (varUseCount[id]) ++varUseCount[id]; }
1166 [&](spv::Op opCode, unsigned start) {
1167 spv::Id id = spv::NoResult;
1168 if (opCode == spv::OpVariable)
1170 if (opCode == spv::OpDecorate || opCode == spv::OpName)
1173 if (id != spv::NoResult && varUseCount[id] == 1)
1190 std::unordered_map<spv::Id, int> typeUseCount;
1202 [&](spv::Id& id) { if (isType[id]) ++typeUseCount[id]; }
1210 const spv::Id typeId = asTypeConstId(typeStart);
1224 bool spirvbin_t::matchType(const spirvbin_t::globaltypes_t& globalTypes, spv::Id lt, spv::Id gt) const
1242 const spv::Op opCode = asOpCode(typeStart);
1271 case spv::OpTypeOpaque: // TODO: disable until we compare the literal strings.
1272 case spv::OpTypeQueue: return false;
1273 case spv::OpTypeEvent: // fall through...
1274 case spv::OpTypeDeviceEvent: // ...
1275 case spv::OpTypeReserveId: return false;
1277 case spv::OpTypeSampler: return cmpLiteral() && cmpConst() && cmpSubType() && wordCount == 8;
1283 spv::Id spirvbin_t::findType(const spirvbin_t::globaltypes_t& globalTypes, spv::Id lt) const
1290 return spv::NoType;
1295 unsigned spirvbin_t::idPos(spv::Id id) const
1311 const spv::Op opCode = asOpCode(typeStart);
1314 case spv::OpTypeVoid: return 0;
1315 case spv::OpTypeBool: return 1;
1316 case spv::OpTypeInt: return 3 + (spv[typeStart+3]);
1317 case spv::OpTypeFloat: return 5;
1318 case spv::OpTypeVector:
1319 return 6 + hashType(idPos(spv[typeStart+2])) * (spv[typeStart+3] - 1);
1320 case spv::OpTypeMatrix:
1321 return 30 + hashType(idPos(spv[typeStart+2])) * (spv[typeStart+3] - 1);
1322 case spv::OpTypeImage:
1323 return 120 + hashType(idPos(spv[typeStart+2])) +
1324 spv[typeStart+3] + // dimensionality
1325 spv[typeStart+4] * 8 * 16 + // depth
1326 spv[typeStart+5] * 4 * 16 + // arrayed
1327 spv[typeStart+6] * 2 * 16 + // multisampled
1328 spv[typeStart+7] * 1 * 16; // format
1329 case spv::OpTypeSampler:
1331 case spv::OpTypeSampledImage:
1333 case spv::OpTypeArray:
1334 return 501 + hashType(idPos(spv[typeStart+2])) * spv[typeStart+3];
1335 case spv::OpTypeRuntimeArray:
1336 return 5000 + hashType(idPos(spv[typeStart+2]));
1337 case spv::OpTypeStruct:
1341 hash += w * hashType(idPos(spv[typeStart+w]));
1345 case spv::OpTypeOpaque: return 6000 + spv[typeStart+2];
1346 case spv::OpTypePointer: return 100000 + hashType(idPos(spv[typeStart+3]));
1347 case spv::OpTypeFunction:
1351 hash += w * hashType(idPos(spv[typeStart+w]));
1355 case spv::OpTypeEvent: return 300000;
1356 case spv::OpTypeDeviceEvent: return 300001;
1357 case spv::OpTypeReserveId: return 300002;
1358 case spv::OpTypeQueue: return 300003;
1359 case spv::OpTypePipe: return 300004;
1360 case spv::OpConstantTrue: return 300007;
1361 case spv::OpConstantFalse: return 300008;
1362 case spv::OpConstantComposite:
1364 std::uint32_t hash = 300011 + hashType(idPos(spv[typeStart+1]));
1366 hash += w * hashType(idPos(spv[typeStart+w]));
1369 case spv::OpConstant:
1371 std::uint32_t hash = 400011 + hashType(idPos(spv[typeStart+1]));
1373 hash += w * spv[typeStart+w];
1376 case spv::OpConstantNull:
1378 std::uint32_t hash = 500009 + hashType(idPos(spv[typeStart+1]));
1381 case spv::OpConstantSampler:
1383 std::uint32_t hash = 600011 + hashType(idPos(spv[typeStart+1]));
1385 hash += w * spv[typeStart+w];
1405 const spv::Id resId = asTypeConstId(typeStart);
1433 for (unsigned word = 0; word < unsigned(spv.size()); ++word) {
1438 spv[strippedPos++] = spv[word];
1441 spv.resize(strippedPos);
1453 spv::Parameterize();
1512 spv.swap(in_spv);
1514 spv.swap(in_spv);
1521 spv.swap(in_spv);
1523 spv.swap(in_spv);