convert_to_half_pass.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. // Copyright (c) 2019 The Khronos Group Inc.
  2. // Copyright (c) 2019 Valve Corporation
  3. // Copyright (c) 2019 LunarG Inc.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. #include "convert_to_half_pass.h"
  17. #include "source/opt/ir_builder.h"
  18. namespace spvtools {
  19. namespace opt {
  20. namespace {
  21. // Indices of operands in SPIR-V instructions
  22. constexpr int kImageSampleDrefIdInIdx = 2;
  23. } // namespace
  24. bool ConvertToHalfPass::IsArithmetic(Instruction* inst) {
  25. return target_ops_core_.count(inst->opcode()) != 0 ||
  26. (inst->opcode() == spv::Op::OpExtInst &&
  27. inst->GetSingleWordInOperand(0) ==
  28. context()->get_feature_mgr()->GetExtInstImportId_GLSLstd450() &&
  29. target_ops_450_.count(inst->GetSingleWordInOperand(1)) != 0);
  30. }
  31. bool ConvertToHalfPass::IsFloat(Instruction* inst, uint32_t width) {
  32. uint32_t ty_id = inst->type_id();
  33. if (ty_id == 0) return false;
  34. return Pass::IsFloat(ty_id, width);
  35. }
  36. bool ConvertToHalfPass::IsStruct(Instruction* inst) {
  37. uint32_t ty_id = inst->type_id();
  38. if (ty_id == 0) return false;
  39. Instruction* ty_inst = Pass::GetBaseType(ty_id);
  40. return (ty_inst->opcode() == spv::Op::OpTypeStruct);
  41. }
  42. bool ConvertToHalfPass::IsDecoratedRelaxed(Instruction* inst) {
  43. uint32_t r_id = inst->result_id();
  44. for (auto r_inst : get_decoration_mgr()->GetDecorationsFor(r_id, false))
  45. if (r_inst->opcode() == spv::Op::OpDecorate &&
  46. spv::Decoration(r_inst->GetSingleWordInOperand(1)) ==
  47. spv::Decoration::RelaxedPrecision) {
  48. return true;
  49. }
  50. return false;
  51. }
  52. bool ConvertToHalfPass::IsRelaxed(uint32_t id) {
  53. return relaxed_ids_set_.count(id) > 0;
  54. }
  55. void ConvertToHalfPass::AddRelaxed(uint32_t id) { relaxed_ids_set_.insert(id); }
  56. bool ConvertToHalfPass::CanRelaxOpOperands(Instruction* inst) {
  57. return image_ops_.count(inst->opcode()) == 0;
  58. }
  59. analysis::Type* ConvertToHalfPass::FloatScalarType(uint32_t width) {
  60. analysis::Float float_ty(width);
  61. return context()->get_type_mgr()->GetRegisteredType(&float_ty);
  62. }
  63. analysis::Type* ConvertToHalfPass::FloatVectorType(uint32_t v_len,
  64. uint32_t width) {
  65. analysis::Type* reg_float_ty = FloatScalarType(width);
  66. analysis::Vector vec_ty(reg_float_ty, v_len);
  67. return context()->get_type_mgr()->GetRegisteredType(&vec_ty);
  68. }
  69. analysis::Type* ConvertToHalfPass::FloatMatrixType(uint32_t v_cnt,
  70. uint32_t vty_id,
  71. uint32_t width) {
  72. Instruction* vty_inst = get_def_use_mgr()->GetDef(vty_id);
  73. uint32_t v_len = vty_inst->GetSingleWordInOperand(1);
  74. analysis::Type* reg_vec_ty = FloatVectorType(v_len, width);
  75. analysis::Matrix mat_ty(reg_vec_ty, v_cnt);
  76. return context()->get_type_mgr()->GetRegisteredType(&mat_ty);
  77. }
  78. uint32_t ConvertToHalfPass::EquivFloatTypeId(uint32_t ty_id, uint32_t width) {
  79. analysis::Type* reg_equiv_ty;
  80. Instruction* ty_inst = get_def_use_mgr()->GetDef(ty_id);
  81. if (ty_inst->opcode() == spv::Op::OpTypeMatrix)
  82. reg_equiv_ty = FloatMatrixType(ty_inst->GetSingleWordInOperand(1),
  83. ty_inst->GetSingleWordInOperand(0), width);
  84. else if (ty_inst->opcode() == spv::Op::OpTypeVector)
  85. reg_equiv_ty = FloatVectorType(ty_inst->GetSingleWordInOperand(1), width);
  86. else // spv::Op::OpTypeFloat
  87. reg_equiv_ty = FloatScalarType(width);
  88. return context()->get_type_mgr()->GetTypeInstruction(reg_equiv_ty);
  89. }
  90. void ConvertToHalfPass::GenConvert(uint32_t* val_idp, uint32_t width,
  91. Instruction* inst) {
  92. Instruction* val_inst = get_def_use_mgr()->GetDef(*val_idp);
  93. uint32_t ty_id = val_inst->type_id();
  94. uint32_t nty_id = EquivFloatTypeId(ty_id, width);
  95. if (nty_id == ty_id) return;
  96. Instruction* cvt_inst;
  97. InstructionBuilder builder(
  98. context(), inst,
  99. IRContext::kAnalysisDefUse | IRContext::kAnalysisInstrToBlockMapping);
  100. if (val_inst->opcode() == spv::Op::OpUndef)
  101. cvt_inst = builder.AddNullaryOp(nty_id, spv::Op::OpUndef);
  102. else
  103. cvt_inst = builder.AddUnaryOp(nty_id, spv::Op::OpFConvert, *val_idp);
  104. *val_idp = cvt_inst->result_id();
  105. }
  106. bool ConvertToHalfPass::MatConvertCleanup(Instruction* inst) {
  107. if (inst->opcode() != spv::Op::OpFConvert) return false;
  108. uint32_t mty_id = inst->type_id();
  109. Instruction* mty_inst = get_def_use_mgr()->GetDef(mty_id);
  110. if (mty_inst->opcode() != spv::Op::OpTypeMatrix) return false;
  111. uint32_t vty_id = mty_inst->GetSingleWordInOperand(0);
  112. uint32_t v_cnt = mty_inst->GetSingleWordInOperand(1);
  113. Instruction* vty_inst = get_def_use_mgr()->GetDef(vty_id);
  114. uint32_t cty_id = vty_inst->GetSingleWordInOperand(0);
  115. Instruction* cty_inst = get_def_use_mgr()->GetDef(cty_id);
  116. InstructionBuilder builder(
  117. context(), inst,
  118. IRContext::kAnalysisDefUse | IRContext::kAnalysisInstrToBlockMapping);
  119. // Convert each component vector, combine them with OpCompositeConstruct
  120. // and replace original instruction.
  121. uint32_t orig_width = (cty_inst->GetSingleWordInOperand(0) == 16) ? 32 : 16;
  122. uint32_t orig_mat_id = inst->GetSingleWordInOperand(0);
  123. uint32_t orig_vty_id = EquivFloatTypeId(vty_id, orig_width);
  124. std::vector<Operand> opnds = {};
  125. for (uint32_t vidx = 0; vidx < v_cnt; ++vidx) {
  126. Instruction* ext_inst = builder.AddIdLiteralOp(
  127. orig_vty_id, spv::Op::OpCompositeExtract, orig_mat_id, vidx);
  128. Instruction* cvt_inst =
  129. builder.AddUnaryOp(vty_id, spv::Op::OpFConvert, ext_inst->result_id());
  130. opnds.push_back({SPV_OPERAND_TYPE_ID, {cvt_inst->result_id()}});
  131. }
  132. uint32_t mat_id = TakeNextId();
  133. std::unique_ptr<Instruction> mat_inst(new Instruction(
  134. context(), spv::Op::OpCompositeConstruct, mty_id, mat_id, opnds));
  135. (void)builder.AddInstruction(std::move(mat_inst));
  136. context()->ReplaceAllUsesWith(inst->result_id(), mat_id);
  137. // Turn original instruction into copy so it is valid.
  138. inst->SetOpcode(spv::Op::OpCopyObject);
  139. inst->SetResultType(EquivFloatTypeId(mty_id, orig_width));
  140. get_def_use_mgr()->AnalyzeInstUse(inst);
  141. return true;
  142. }
  143. bool ConvertToHalfPass::RemoveRelaxedDecoration(uint32_t id) {
  144. return context()->get_decoration_mgr()->RemoveDecorationsFrom(
  145. id, [](const Instruction& dec) {
  146. if (dec.opcode() == spv::Op::OpDecorate &&
  147. spv::Decoration(dec.GetSingleWordInOperand(1u)) ==
  148. spv::Decoration::RelaxedPrecision) {
  149. return true;
  150. } else
  151. return false;
  152. });
  153. }
  154. bool ConvertToHalfPass::GenHalfArith(Instruction* inst) {
  155. bool modified = false;
  156. // If this is a OpCompositeExtract instruction and has a struct operand, we
  157. // should not relax this instruction. Doing so could cause a mismatch between
  158. // the result type and the struct member type.
  159. bool hasStructOperand = false;
  160. if (inst->opcode() == spv::Op::OpCompositeExtract) {
  161. inst->ForEachInId([&hasStructOperand, this](uint32_t* idp) {
  162. Instruction* op_inst = get_def_use_mgr()->GetDef(*idp);
  163. if (IsStruct(op_inst)) hasStructOperand = true;
  164. });
  165. if (hasStructOperand) {
  166. return false;
  167. }
  168. }
  169. // Convert all float32 based operands to float16 equivalent and change
  170. // instruction type to float16 equivalent.
  171. inst->ForEachInId([&inst, &modified, this](uint32_t* idp) {
  172. Instruction* op_inst = get_def_use_mgr()->GetDef(*idp);
  173. if (!IsFloat(op_inst, 32)) return;
  174. GenConvert(idp, 16, inst);
  175. modified = true;
  176. });
  177. if (IsFloat(inst, 32)) {
  178. inst->SetResultType(EquivFloatTypeId(inst->type_id(), 16));
  179. converted_ids_.insert(inst->result_id());
  180. modified = true;
  181. }
  182. if (modified) get_def_use_mgr()->AnalyzeInstUse(inst);
  183. return modified;
  184. }
  185. bool ConvertToHalfPass::ProcessPhi(Instruction* inst, uint32_t from_width,
  186. uint32_t to_width) {
  187. // Add converts of any float operands to to_width if they are of from_width.
  188. // If converting to 16, change type of phi to float16 equivalent and remember
  189. // result id. Converts need to be added to preceding blocks.
  190. uint32_t ocnt = 0;
  191. uint32_t* prev_idp;
  192. bool modified = false;
  193. inst->ForEachInId([&ocnt, &prev_idp, &from_width, &to_width, &modified,
  194. this](uint32_t* idp) {
  195. if (ocnt % 2 == 0) {
  196. prev_idp = idp;
  197. } else {
  198. Instruction* val_inst = get_def_use_mgr()->GetDef(*prev_idp);
  199. if (IsFloat(val_inst, from_width)) {
  200. BasicBlock* bp = context()->get_instr_block(*idp);
  201. auto insert_before = bp->tail();
  202. if (insert_before != bp->begin()) {
  203. --insert_before;
  204. if (insert_before->opcode() != spv::Op::OpSelectionMerge &&
  205. insert_before->opcode() != spv::Op::OpLoopMerge)
  206. ++insert_before;
  207. }
  208. GenConvert(prev_idp, to_width, &*insert_before);
  209. modified = true;
  210. }
  211. }
  212. ++ocnt;
  213. });
  214. if (to_width == 16u) {
  215. inst->SetResultType(EquivFloatTypeId(inst->type_id(), 16u));
  216. converted_ids_.insert(inst->result_id());
  217. modified = true;
  218. }
  219. if (modified) get_def_use_mgr()->AnalyzeInstUse(inst);
  220. return modified;
  221. }
  222. bool ConvertToHalfPass::ProcessConvert(Instruction* inst) {
  223. // If float32 and relaxed, change to float16 convert
  224. if (IsFloat(inst, 32) && IsRelaxed(inst->result_id())) {
  225. inst->SetResultType(EquivFloatTypeId(inst->type_id(), 16));
  226. get_def_use_mgr()->AnalyzeInstUse(inst);
  227. converted_ids_.insert(inst->result_id());
  228. }
  229. // If operand and result types are the same, change FConvert to CopyObject to
  230. // keep validator happy; simplification and DCE will clean it up
  231. // One way this can happen is if an FConvert generated during this pass
  232. // (likely by ProcessPhi) is later encountered here and its operand has been
  233. // changed to half.
  234. uint32_t val_id = inst->GetSingleWordInOperand(0);
  235. Instruction* val_inst = get_def_use_mgr()->GetDef(val_id);
  236. if (inst->type_id() == val_inst->type_id())
  237. inst->SetOpcode(spv::Op::OpCopyObject);
  238. return true; // modified
  239. }
  240. bool ConvertToHalfPass::ProcessImageRef(Instruction* inst) {
  241. bool modified = false;
  242. // If image reference, only need to convert dref args back to float32
  243. if (dref_image_ops_.count(inst->opcode()) != 0) {
  244. uint32_t dref_id = inst->GetSingleWordInOperand(kImageSampleDrefIdInIdx);
  245. if (converted_ids_.count(dref_id) > 0) {
  246. GenConvert(&dref_id, 32, inst);
  247. inst->SetInOperand(kImageSampleDrefIdInIdx, {dref_id});
  248. get_def_use_mgr()->AnalyzeInstUse(inst);
  249. modified = true;
  250. }
  251. }
  252. return modified;
  253. }
  254. bool ConvertToHalfPass::ProcessDefault(Instruction* inst) {
  255. // If non-relaxed instruction has changed operands, need to convert
  256. // them back to float32
  257. if (inst->opcode() == spv::Op::OpPhi) return ProcessPhi(inst, 16u, 32u);
  258. bool modified = false;
  259. inst->ForEachInId([&inst, &modified, this](uint32_t* idp) {
  260. if (converted_ids_.count(*idp) == 0) return;
  261. uint32_t old_id = *idp;
  262. GenConvert(idp, 32, inst);
  263. if (*idp != old_id) modified = true;
  264. });
  265. if (modified) get_def_use_mgr()->AnalyzeInstUse(inst);
  266. return modified;
  267. }
  268. bool ConvertToHalfPass::GenHalfInst(Instruction* inst) {
  269. bool modified = false;
  270. // Remember id for later deletion of RelaxedPrecision decoration
  271. bool inst_relaxed = IsRelaxed(inst->result_id());
  272. if (IsArithmetic(inst) && inst_relaxed)
  273. modified = GenHalfArith(inst);
  274. else if (inst->opcode() == spv::Op::OpPhi && inst_relaxed)
  275. modified = ProcessPhi(inst, 32u, 16u);
  276. else if (inst->opcode() == spv::Op::OpFConvert)
  277. modified = ProcessConvert(inst);
  278. else if (image_ops_.count(inst->opcode()) != 0)
  279. modified = ProcessImageRef(inst);
  280. else
  281. modified = ProcessDefault(inst);
  282. return modified;
  283. }
  284. bool ConvertToHalfPass::CloseRelaxInst(Instruction* inst) {
  285. if (inst->result_id() == 0) return false;
  286. if (IsRelaxed(inst->result_id())) return false;
  287. if (!IsFloat(inst, 32)) return false;
  288. if (IsDecoratedRelaxed(inst)) {
  289. AddRelaxed(inst->result_id());
  290. return true;
  291. }
  292. if (closure_ops_.count(inst->opcode()) == 0) return false;
  293. // Can relax if all float operands are relaxed
  294. bool relax = true;
  295. bool hasStructOperand = false;
  296. inst->ForEachInId([&relax, &hasStructOperand, this](uint32_t* idp) {
  297. Instruction* op_inst = get_def_use_mgr()->GetDef(*idp);
  298. if (IsStruct(op_inst)) hasStructOperand = true;
  299. if (!IsFloat(op_inst, 32)) return;
  300. if (!IsRelaxed(*idp)) relax = false;
  301. });
  302. // If the instruction has a struct operand, we should not relax it, even if
  303. // all its uses are relaxed. Doing so could cause a mismatch between the
  304. // result type and the struct member type.
  305. if (hasStructOperand) {
  306. return false;
  307. }
  308. if (relax) {
  309. AddRelaxed(inst->result_id());
  310. return true;
  311. }
  312. // Can relax if all uses are relaxed
  313. relax = true;
  314. get_def_use_mgr()->ForEachUser(inst, [&relax, this](Instruction* uinst) {
  315. if (uinst->result_id() == 0 || !IsFloat(uinst, 32) ||
  316. (!IsDecoratedRelaxed(uinst) && !IsRelaxed(uinst->result_id())) ||
  317. !CanRelaxOpOperands(uinst)) {
  318. relax = false;
  319. return;
  320. }
  321. });
  322. if (relax) {
  323. AddRelaxed(inst->result_id());
  324. return true;
  325. }
  326. return false;
  327. }
  328. bool ConvertToHalfPass::ProcessFunction(Function* func) {
  329. // Do a closure of Relaxed on composite and phi instructions
  330. bool changed = true;
  331. while (changed) {
  332. changed = false;
  333. cfg()->ForEachBlockInReversePostOrder(
  334. func->entry().get(), [&changed, this](BasicBlock* bb) {
  335. for (auto ii = bb->begin(); ii != bb->end(); ++ii)
  336. changed |= CloseRelaxInst(&*ii);
  337. });
  338. }
  339. // Do convert of relaxed instructions to half precision
  340. bool modified = false;
  341. cfg()->ForEachBlockInReversePostOrder(
  342. func->entry().get(), [&modified, this](BasicBlock* bb) {
  343. for (auto ii = bb->begin(); ii != bb->end(); ++ii)
  344. modified |= GenHalfInst(&*ii);
  345. });
  346. // Replace invalid converts of matrix into equivalent vector extracts,
  347. // converts and finally a composite construct
  348. cfg()->ForEachBlockInReversePostOrder(
  349. func->entry().get(), [&modified, this](BasicBlock* bb) {
  350. for (auto ii = bb->begin(); ii != bb->end(); ++ii)
  351. modified |= MatConvertCleanup(&*ii);
  352. });
  353. return modified;
  354. }
  355. Pass::Status ConvertToHalfPass::ProcessImpl() {
  356. Pass::ProcessFunction pfn = [this](Function* fp) {
  357. return ProcessFunction(fp);
  358. };
  359. bool modified = context()->ProcessReachableCallTree(pfn);
  360. // If modified, make sure module has Float16 capability
  361. if (modified) context()->AddCapability(spv::Capability::Float16);
  362. // Remove all RelaxedPrecision decorations from instructions and globals
  363. for (auto c_id : relaxed_ids_set_) {
  364. modified |= RemoveRelaxedDecoration(c_id);
  365. }
  366. for (auto& val : get_module()->types_values()) {
  367. uint32_t v_id = val.result_id();
  368. if (v_id != 0) {
  369. modified |= RemoveRelaxedDecoration(v_id);
  370. }
  371. }
  372. return modified ? Status::SuccessWithChange : Status::SuccessWithoutChange;
  373. }
  374. Pass::Status ConvertToHalfPass::Process() {
  375. Initialize();
  376. return ProcessImpl();
  377. }
  378. void ConvertToHalfPass::Initialize() {
  379. target_ops_core_ = {
  380. spv::Op::OpVectorExtractDynamic,
  381. spv::Op::OpVectorInsertDynamic,
  382. spv::Op::OpVectorShuffle,
  383. spv::Op::OpCompositeConstruct,
  384. spv::Op::OpCompositeInsert,
  385. spv::Op::OpCompositeExtract,
  386. spv::Op::OpCopyObject,
  387. spv::Op::OpTranspose,
  388. spv::Op::OpConvertSToF,
  389. spv::Op::OpConvertUToF,
  390. // spv::Op::OpFConvert,
  391. // spv::Op::OpQuantizeToF16,
  392. spv::Op::OpFNegate,
  393. spv::Op::OpFAdd,
  394. spv::Op::OpFSub,
  395. spv::Op::OpFMul,
  396. spv::Op::OpFDiv,
  397. spv::Op::OpFMod,
  398. spv::Op::OpVectorTimesScalar,
  399. spv::Op::OpMatrixTimesScalar,
  400. spv::Op::OpVectorTimesMatrix,
  401. spv::Op::OpMatrixTimesVector,
  402. spv::Op::OpMatrixTimesMatrix,
  403. spv::Op::OpOuterProduct,
  404. spv::Op::OpDot,
  405. spv::Op::OpSelect,
  406. spv::Op::OpFOrdEqual,
  407. spv::Op::OpFUnordEqual,
  408. spv::Op::OpFOrdNotEqual,
  409. spv::Op::OpFUnordNotEqual,
  410. spv::Op::OpFOrdLessThan,
  411. spv::Op::OpFUnordLessThan,
  412. spv::Op::OpFOrdGreaterThan,
  413. spv::Op::OpFUnordGreaterThan,
  414. spv::Op::OpFOrdLessThanEqual,
  415. spv::Op::OpFUnordLessThanEqual,
  416. spv::Op::OpFOrdGreaterThanEqual,
  417. spv::Op::OpFUnordGreaterThanEqual,
  418. };
  419. target_ops_450_ = {
  420. GLSLstd450Round, GLSLstd450RoundEven, GLSLstd450Trunc, GLSLstd450FAbs,
  421. GLSLstd450FSign, GLSLstd450Floor, GLSLstd450Ceil, GLSLstd450Fract,
  422. GLSLstd450Radians, GLSLstd450Degrees, GLSLstd450Sin, GLSLstd450Cos,
  423. GLSLstd450Tan, GLSLstd450Asin, GLSLstd450Acos, GLSLstd450Atan,
  424. GLSLstd450Sinh, GLSLstd450Cosh, GLSLstd450Tanh, GLSLstd450Asinh,
  425. GLSLstd450Acosh, GLSLstd450Atanh, GLSLstd450Atan2, GLSLstd450Pow,
  426. GLSLstd450Exp, GLSLstd450Log, GLSLstd450Exp2, GLSLstd450Log2,
  427. GLSLstd450Sqrt, GLSLstd450InverseSqrt, GLSLstd450Determinant,
  428. GLSLstd450MatrixInverse,
  429. // TODO(greg-lunarg): GLSLstd450ModfStruct,
  430. GLSLstd450FMin, GLSLstd450FMax, GLSLstd450FClamp, GLSLstd450FMix,
  431. GLSLstd450Step, GLSLstd450SmoothStep, GLSLstd450Fma,
  432. // TODO(greg-lunarg): GLSLstd450FrexpStruct,
  433. GLSLstd450Ldexp, GLSLstd450Length, GLSLstd450Distance, GLSLstd450Cross,
  434. GLSLstd450Normalize, GLSLstd450FaceForward, GLSLstd450Reflect,
  435. GLSLstd450Refract, GLSLstd450NMin, GLSLstd450NMax, GLSLstd450NClamp};
  436. image_ops_ = {spv::Op::OpImageSampleImplicitLod,
  437. spv::Op::OpImageSampleExplicitLod,
  438. spv::Op::OpImageSampleDrefImplicitLod,
  439. spv::Op::OpImageSampleDrefExplicitLod,
  440. spv::Op::OpImageSampleProjImplicitLod,
  441. spv::Op::OpImageSampleProjExplicitLod,
  442. spv::Op::OpImageSampleProjDrefImplicitLod,
  443. spv::Op::OpImageSampleProjDrefExplicitLod,
  444. spv::Op::OpImageFetch,
  445. spv::Op::OpImageGather,
  446. spv::Op::OpImageDrefGather,
  447. spv::Op::OpImageRead,
  448. spv::Op::OpImageSparseSampleImplicitLod,
  449. spv::Op::OpImageSparseSampleExplicitLod,
  450. spv::Op::OpImageSparseSampleDrefImplicitLod,
  451. spv::Op::OpImageSparseSampleDrefExplicitLod,
  452. spv::Op::OpImageSparseSampleProjImplicitLod,
  453. spv::Op::OpImageSparseSampleProjExplicitLod,
  454. spv::Op::OpImageSparseSampleProjDrefImplicitLod,
  455. spv::Op::OpImageSparseSampleProjDrefExplicitLod,
  456. spv::Op::OpImageSparseFetch,
  457. spv::Op::OpImageSparseGather,
  458. spv::Op::OpImageSparseDrefGather,
  459. spv::Op::OpImageSparseTexelsResident,
  460. spv::Op::OpImageSparseRead};
  461. dref_image_ops_ = {
  462. spv::Op::OpImageSampleDrefImplicitLod,
  463. spv::Op::OpImageSampleDrefExplicitLod,
  464. spv::Op::OpImageSampleProjDrefImplicitLod,
  465. spv::Op::OpImageSampleProjDrefExplicitLod,
  466. spv::Op::OpImageDrefGather,
  467. spv::Op::OpImageSparseSampleDrefImplicitLod,
  468. spv::Op::OpImageSparseSampleDrefExplicitLod,
  469. spv::Op::OpImageSparseSampleProjDrefImplicitLod,
  470. spv::Op::OpImageSparseSampleProjDrefExplicitLod,
  471. spv::Op::OpImageSparseDrefGather,
  472. };
  473. closure_ops_ = {
  474. spv::Op::OpVectorExtractDynamic,
  475. spv::Op::OpVectorInsertDynamic,
  476. spv::Op::OpVectorShuffle,
  477. spv::Op::OpCompositeConstruct,
  478. spv::Op::OpCompositeInsert,
  479. spv::Op::OpCompositeExtract,
  480. spv::Op::OpCopyObject,
  481. spv::Op::OpTranspose,
  482. spv::Op::OpPhi,
  483. };
  484. relaxed_ids_set_.clear();
  485. converted_ids_.clear();
  486. }
  487. } // namespace opt
  488. } // namespace spvtools