diff --git a/include/sirit/sirit.h b/include/sirit/sirit.h index 996b8db..892158e 100644 --- a/include/sirit/sirit.h +++ b/include/sirit/sirit.h @@ -292,6 +292,15 @@ class Module { /// Integer addition of Operand 1 and Operand 2. Id OpIAdd(Id result_type, Id operand_1, Id operand_2); + // Extensions + + /// Execute an instruction in an imported set of extended instructions. + Id OpExtInst(Id result_type, Id set, std::uint32_t instruction, + const std::vector& operands); + + /// Result is x if x >= 0; otherwise result is -x. + Id OpFAbs(Id result_type, Id x); + private: Id AddCode(std::unique_ptr op); @@ -301,27 +310,23 @@ class Module { Id AddAnnotation(std::unique_ptr op); + Id GetGLSLstd450(); + const std::uint32_t version; std::uint32_t bound{1}; std::set capabilities; - - std::set extensions; - + std::unique_ptr glsl_std_450; std::set> ext_inst_import; spv::AddressingModel addressing_model{spv::AddressingModel::Logical}; spv::MemoryModel memory_model{spv::MemoryModel::GLSL450}; std::vector> entry_points; - std::vector> execution_mode; - std::vector> debug; - std::vector> annotations; - std::vector> declarations; std::vector global_variables; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b3d717e..eacfdbb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,6 +24,7 @@ add_library(sirit insts/conversion.cpp insts/bit.cpp insts/arithmetic.cpp + insts/extension.cpp ) target_include_directories(sirit PUBLIC ../include diff --git a/src/insts/extension.cpp b/src/insts/extension.cpp new file mode 100644 index 0000000..ad842b1 --- /dev/null +++ b/src/insts/extension.cpp @@ -0,0 +1,28 @@ +/* This file is part of the sirit project. + * Copyright (c) 2018 ReinUsesLisp + * This software may be used and distributed according to the terms of the GNU + * Lesser General Public License version 2.1 or any later version. + */ + +#include "common_types.h" +#include "op.h" +#include "sirit/sirit.h" +#include +#include + +namespace Sirit { + +Id Module::OpExtInst(Id result_type, Id set, u32 instruction, + const std::vector& operands) { + auto op{std::make_unique(spv::Op::OpExtInst, bound++, result_type)}; + op->Add(set); + op->Add(instruction); + op->Add(operands); + return AddCode(std::move(op)); +} + +Id Module::OpFAbs(Id result_type, Id x) { + return OpExtInst(result_type, GetGLSLstd450(), GLSLstd450FAbs, {x}); +} + +} // namespace Sirit \ No newline at end of file diff --git a/src/sirit.cpp b/src/sirit.cpp index 56b25b8..6726985 100644 --- a/src/sirit.cpp +++ b/src/sirit.cpp @@ -43,7 +43,9 @@ std::vector Module::Assemble() const { for (const auto capability : capabilities) { WriteEnum(stream, spv::Op::OpCapability, capability); } - // TODO write extensions + if (glsl_std_450) { + glsl_std_450->Write(stream); + } // TODO write ext inst imports Op memory_model_ref{spv::Op::OpMemoryModel}; @@ -123,4 +125,11 @@ Id Module::AddAnnotation(std::unique_ptr op) { return id; } +Id Module::GetGLSLstd450() { + if (!glsl_std_450) { + glsl_std_450 = std::make_unique(spv::Op::OpExtInstImport, bound++); + } + return glsl_std_450.get(); +} + } // namespace Sirit