From 4a0c6e03e173f140192d0cde3355e1f68ec51883 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Mon, 9 Sep 2019 15:41:53 -0300 Subject: [PATCH] Add OpVectorExtractDynamic and OpVectorInsertDynamic --- include/sirit/sirit.h | 6 ++++++ src/instructions/memory.cpp | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/sirit/sirit.h b/include/sirit/sirit.h index ea7dc8e..0c86601 100644 --- a/include/sirit/sirit.h +++ b/include/sirit/sirit.h @@ -285,6 +285,12 @@ public: return OpAccessChain(result_type, base, {indexes...}); } + /// Extract a single, dynamically selected, component of a vector. + Id OpVectorExtractDynamic(Id result_type, Id vector, Id index); + + /// Make a copy of a vector, with a single, variably selected, component modified. + Id OpVectorInsertDynamic(Id result_type, Id vector, Id component, Id index); + /// Make a copy of a composite object, while modifying one part of it. Id OpCompositeInsert(Id result_type, Id object, Id composite, const std::vector& indexes = {}); diff --git a/src/instructions/memory.cpp b/src/instructions/memory.cpp index baae005..884af75 100644 --- a/src/instructions/memory.cpp +++ b/src/instructions/memory.cpp @@ -46,6 +46,21 @@ Id Module::OpAccessChain(Id result_type, Id base, const std::vector& indexes return AddCode(std::move(op)); } +Id Module::OpVectorExtractDynamic(Id result_type, Id vector, Id index) { + auto op{std::make_unique(spv::Op::OpVectorExtractDynamic, bound++, result_type)}; + op->Add(vector); + op->Add(index); + return AddCode(std::move(op)); +} + +Id Module::OpVectorInsertDynamic(Id result_type, Id vector, Id component, Id index) { + auto op{std::make_unique(spv::Op::OpVectorInsertDynamic, bound++, result_type)}; + op->Add(vector); + op->Add(component); + op->Add(index); + return AddCode(std::move(op)); +} + Id Module::OpCompositeInsert(Id result_type, Id object, Id composite, const std::vector& indexes) { auto op{std::make_unique(spv::Op::OpCompositeInsert, bound++, result_type)};