diff --git a/include/sirit/sirit.h b/include/sirit/sirit.h index 21cde3d..d24ce2c 100644 --- a/include/sirit/sirit.h +++ b/include/sirit/sirit.h @@ -87,8 +87,8 @@ class Module { /// Returns type image. Id OpTypeImage(Id sampled_type, spv::Dim dim, int depth, bool arrayed, - bool ms, int sampled, spv::ImageFormat image_format, - std::optional access_qualifier = {}); + bool ms, int sampled, spv::ImageFormat image_format, + std::optional access_qualifier = {}); /// Returns type sampler. Id OpTypeSampler(); @@ -141,13 +141,12 @@ class Module { Id OpConstant(Id result_type, const Literal& literal); /// Returns a numeric scalar constant. - Id OpConstantComposite(Id result_type, - const std::vector& constituents); + Id OpConstantComposite(Id result_type, const std::vector& constituents); /// Returns a sampler constant. Id OpConstantSampler(Id result_type, - spv::SamplerAddressingMode addressing_mode, - bool normalized, spv::SamplerFilterMode filter_mode); + spv::SamplerAddressingMode addressing_mode, + bool normalized, spv::SamplerFilterMode filter_mode); /// Returns a null constant value. Id OpConstantNull(Id result_type); @@ -156,7 +155,7 @@ class Module { /// Declares a function. Id OpFunction(Id result_type, spv::FunctionControlMask function_control, - Id function_type); + Id function_type); /// Ends a function. Id OpFunctionEnd(); @@ -165,12 +164,12 @@ class Module { /// Declare a structured loop. Id OpLoopMerge(Id merge_block, Id continue_target, - spv::LoopControlMask loop_control, - const std::vector& literals = {}); + spv::LoopControlMask loop_control, + const std::vector& literals = {}); /// Declare a structured selection. Id OpSelectionMerge(Id merge_block, - spv::SelectionControlMask selection_control); + spv::SelectionControlMask selection_control); /// The block label instruction: Any reference to a block is through this /// ref. @@ -182,12 +181,15 @@ class Module { /// If condition is true branch to true_label, otherwise branch to /// false_label. Id OpBranchConditional(Id condition, Id true_label, Id false_label, - std::uint32_t true_weight = 0, - std::uint32_t false_weight = 0); + std::uint32_t true_weight = 0, + std::uint32_t false_weight = 0); /// Returns with no value from a function with void return type. Id OpReturn(); + /// Return a value from a function. + Id OpReturnValue(Id value); + // Debug /// Assign a name string to a reference. @@ -198,34 +200,34 @@ class Module { /// Allocate an object in memory, resulting in a copy to it. Id OpVariable(Id result_type, spv::StorageClass storage_class, - Id initializer = nullptr); + Id initializer = nullptr); /// Load through a pointer. Id OpLoad(Id result_type, Id pointer, - std::optional memory_access = {}); + std::optional memory_access = {}); /// Store through a pointer. Id OpStore(Id pointer, Id object, - std::optional memory_access = {}); + std::optional memory_access = {}); /// Create a pointer into a composite object that can be used with OpLoad /// and OpStore. Id OpAccessChain(Id result_type, Id base, - const std::vector& indexes = {}); + const std::vector& indexes = {}); /// 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 = {}); + const std::vector& indexes = {}); // Annotation /// Add a decoration to target. Id Decorate(Id target, spv::Decoration decoration, - const std::vector& literals = {}); + const std::vector& literals = {}); Id MemberDecorate(Id structure_type, Literal member, - spv::Decoration decoration, - const std::vector& literals = {}); + spv::Decoration decoration, + const std::vector& literals = {}); // Misc diff --git a/src/insts/flow.cpp b/src/insts/flow.cpp index afd0244..0115f68 100644 --- a/src/insts/flow.cpp +++ b/src/insts/flow.cpp @@ -53,4 +53,10 @@ Id Module::OpBranchConditional(Id condition, Id true_label, Id false_label, Id Module::OpReturn() { return AddCode(spv::Op::OpReturn); } +Id Module::OpReturnValue(Id value) { + auto op{std::make_unique(spv::Op::OpReturnValue)}; + op->Add(value); + return AddCode(std::move(op)); +} + } // namespace Sirit