mirror of
https://git.suyu.dev/suyu/sirit.git
synced 2025-12-30 03:06:19 +01:00
Change clang-format settings
This commit is contained in:
parent
38838c9a9d
commit
73595f4588
27 changed files with 356 additions and 320 deletions
|
|
@ -4,16 +4,15 @@
|
|||
* Lesser General Public License version 3 or any later version.
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "common_types.h"
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
Id Module::Decorate(Id target, spv::Decoration decoration,
|
||||
const std::vector<Literal>& literals) {
|
||||
Id Module::Decorate(Id target, spv::Decoration decoration, const std::vector<Literal>& literals) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpDecorate)};
|
||||
op->Add(target);
|
||||
op->Add(static_cast<u32>(decoration));
|
||||
|
|
@ -22,8 +21,7 @@ Id Module::Decorate(Id target, spv::Decoration decoration,
|
|||
return target;
|
||||
}
|
||||
|
||||
Id Module::MemberDecorate(Id structure_type, Literal member,
|
||||
spv::Decoration decoration,
|
||||
Id Module::MemberDecorate(Id structure_type, Literal member, spv::Decoration decoration,
|
||||
const std::vector<Literal>& literals) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpMemberDecorate)};
|
||||
op->Add(structure_type);
|
||||
|
|
|
|||
|
|
@ -4,36 +4,35 @@
|
|||
* Lesser General Public License version 3 or any later version.
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include "common_types.h"
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
#include <memory>
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
#define DEFINE_UNARY(funcname, opcode) \
|
||||
Id Module::funcname(Id result_type, Id operand) { \
|
||||
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
||||
op->Add(operand); \
|
||||
return AddCode(std::move(op)); \
|
||||
#define DEFINE_UNARY(funcname, opcode) \
|
||||
Id Module::funcname(Id result_type, Id operand) { \
|
||||
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
||||
op->Add(operand); \
|
||||
return AddCode(std::move(op)); \
|
||||
}
|
||||
|
||||
#define DEFINE_BINARY(funcname, opcode) \
|
||||
Id Module::funcname(Id result_type, Id operand_1, Id operand_2) { \
|
||||
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
||||
op->Add(operand_1); \
|
||||
op->Add(operand_2); \
|
||||
return AddCode(std::move(op)); \
|
||||
#define DEFINE_BINARY(funcname, opcode) \
|
||||
Id Module::funcname(Id result_type, Id operand_1, Id operand_2) { \
|
||||
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
||||
op->Add(operand_1); \
|
||||
op->Add(operand_2); \
|
||||
return AddCode(std::move(op)); \
|
||||
}
|
||||
|
||||
#define DEFINE_TRINARY(funcname, opcode) \
|
||||
Id Module::funcname(Id result_type, Id operand_1, Id operand_2, \
|
||||
Id operand_3) { \
|
||||
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
||||
op->Add(operand_1); \
|
||||
op->Add(operand_2); \
|
||||
op->Add(operand_3); \
|
||||
return AddCode(std::move(op)); \
|
||||
#define DEFINE_TRINARY(funcname, opcode) \
|
||||
Id Module::funcname(Id result_type, Id operand_1, Id operand_2, Id operand_3) { \
|
||||
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
||||
op->Add(operand_1); \
|
||||
op->Add(operand_2); \
|
||||
op->Add(operand_3); \
|
||||
return AddCode(std::move(op)); \
|
||||
}
|
||||
|
||||
DEFINE_UNARY(OpSNegate, spv::Op::OpSNegate)
|
||||
|
|
@ -54,5 +53,4 @@ DEFINE_BINARY(OpFMod, spv::Op::OpFMod)
|
|||
DEFINE_BINARY(OpSRem, spv::Op::OpSRem)
|
||||
DEFINE_BINARY(OpFRem, spv::Op::OpFRem)
|
||||
|
||||
|
||||
} // namespace Sirit
|
||||
|
|
|
|||
|
|
@ -4,32 +4,29 @@
|
|||
* Lesser General Public License version 3 or any later version.
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include "common_types.h"
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
#include <memory>
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
Id Module::OpShiftRightLogical(Id result_type, Id base, Id shift) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpShiftRightLogical, bound++,
|
||||
result_type)};
|
||||
auto op{std::make_unique<Op>(spv::Op::OpShiftRightLogical, bound++, result_type)};
|
||||
op->Add(base);
|
||||
op->Add(shift);
|
||||
return AddCode(std::move(op));
|
||||
}
|
||||
|
||||
Id Module::OpShiftRightArithmetic(Id result_type, Id base, Id shift) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpShiftRightArithmetic, bound++,
|
||||
result_type)};
|
||||
auto op{std::make_unique<Op>(spv::Op::OpShiftRightArithmetic, bound++, result_type)};
|
||||
op->Add(base);
|
||||
op->Add(shift);
|
||||
return AddCode(std::move(op));
|
||||
}
|
||||
|
||||
Id Module::OpShiftLeftLogical(Id result_type, Id base, Id shift) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpShiftLeftLogical, bound++,
|
||||
result_type)};
|
||||
auto op{std::make_unique<Op>(spv::Op::OpShiftLeftLogical, bound++, result_type)};
|
||||
op->Add(base);
|
||||
op->Add(shift);
|
||||
return AddCode(std::move(op));
|
||||
|
|
|
|||
|
|
@ -4,20 +4,18 @@
|
|||
* Lesser General Public License version 3 or any later version.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
#include <cassert>
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
Id Module::ConstantTrue(Id result_type) {
|
||||
return AddDeclaration(
|
||||
std::make_unique<Op>(spv::Op::OpConstantTrue, bound, result_type));
|
||||
return AddDeclaration(std::make_unique<Op>(spv::Op::OpConstantTrue, bound, result_type));
|
||||
}
|
||||
|
||||
Id Module::ConstantFalse(Id result_type) {
|
||||
return AddDeclaration(
|
||||
std::make_unique<Op>(spv::Op::OpConstantFalse, bound, result_type));
|
||||
return AddDeclaration(std::make_unique<Op>(spv::Op::OpConstantFalse, bound, result_type));
|
||||
}
|
||||
|
||||
Id Module::Constant(Id result_type, const Literal& literal) {
|
||||
|
|
@ -26,22 +24,17 @@ Id Module::Constant(Id result_type, const Literal& literal) {
|
|||
return AddDeclaration(std::move(op));
|
||||
}
|
||||
|
||||
Id Module::ConstantComposite(Id result_type,
|
||||
const std::vector<Id>& constituents) {
|
||||
auto op{
|
||||
std::make_unique<Op>(spv::Op::OpConstantComposite, bound, result_type)};
|
||||
Id Module::ConstantComposite(Id result_type, const std::vector<Id>& constituents) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpConstantComposite, bound, result_type)};
|
||||
op->Add(constituents);
|
||||
return AddDeclaration(std::move(op));
|
||||
}
|
||||
|
||||
Id Module::ConstantSampler(Id result_type,
|
||||
spv::SamplerAddressingMode addressing_mode,
|
||||
bool normalized,
|
||||
spv::SamplerFilterMode filter_mode) {
|
||||
Id Module::ConstantSampler(Id result_type, spv::SamplerAddressingMode addressing_mode,
|
||||
bool normalized, spv::SamplerFilterMode filter_mode) {
|
||||
AddCapability(spv::Capability::LiteralSampler);
|
||||
AddCapability(spv::Capability::Kernel);
|
||||
auto op{
|
||||
std::make_unique<Op>(spv::Op::OpConstantSampler, bound, result_type)};
|
||||
auto op{std::make_unique<Op>(spv::Op::OpConstantSampler, bound, result_type)};
|
||||
op->Add(static_cast<u32>(addressing_mode));
|
||||
op->Add(normalized ? 1 : 0);
|
||||
op->Add(static_cast<u32>(filter_mode));
|
||||
|
|
@ -49,8 +42,7 @@ Id Module::ConstantSampler(Id result_type,
|
|||
}
|
||||
|
||||
Id Module::ConstantNull(Id result_type) {
|
||||
return AddDeclaration(
|
||||
std::make_unique<Op>(spv::Op::OpConstantNull, bound, result_type));
|
||||
return AddDeclaration(std::make_unique<Op>(spv::Op::OpConstantNull, bound, result_type));
|
||||
}
|
||||
|
||||
} // namespace Sirit
|
||||
|
|
|
|||
|
|
@ -4,18 +4,18 @@
|
|||
* Lesser General Public License version 3 or any later version.
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include "common_types.h"
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
#include <memory>
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
#define DEFINE_UNARY(opcode) \
|
||||
Id Module::opcode(Id result_type, Id operand) { \
|
||||
auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
|
||||
op->Add(operand); \
|
||||
return AddCode(std::move(op)); \
|
||||
#define DEFINE_UNARY(opcode) \
|
||||
Id Module::opcode(Id result_type, Id operand) { \
|
||||
auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
|
||||
op->Add(operand); \
|
||||
return AddCode(std::move(op)); \
|
||||
}
|
||||
|
||||
DEFINE_UNARY(OpConvertFToU)
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@
|
|||
* Lesser General Public License version 3 or any later version.
|
||||
*/
|
||||
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
|
|
|
|||
|
|
@ -4,16 +4,15 @@
|
|||
* Lesser General Public License version 3 or any later version.
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include <spirv/unified1/GLSL.std.450.h>
|
||||
#include "common_types.h"
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
#include <memory>
|
||||
#include <spirv/unified1/GLSL.std.450.h>
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
Id Module::OpExtInst(Id result_type, Id set, u32 instruction,
|
||||
const std::vector<Id>& operands) {
|
||||
Id Module::OpExtInst(Id result_type, Id set, u32 instruction, const std::vector<Id>& operands) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpExtInst, bound++, result_type)};
|
||||
op->Add(set);
|
||||
op->Add(instruction);
|
||||
|
|
@ -21,22 +20,19 @@ Id Module::OpExtInst(Id result_type, Id set, u32 instruction,
|
|||
return AddCode(std::move(op));
|
||||
}
|
||||
|
||||
#define DEFINE_UNARY(funcname, opcode) \
|
||||
Id Module::funcname(Id result_type, Id operand) { \
|
||||
return OpExtInst(result_type, GetGLSLstd450(), opcode, {operand}); \
|
||||
#define DEFINE_UNARY(funcname, opcode) \
|
||||
Id Module::funcname(Id result_type, Id operand) { \
|
||||
return OpExtInst(result_type, GetGLSLstd450(), opcode, {operand}); \
|
||||
}
|
||||
|
||||
#define DEFINE_BINARY(funcname, opcode) \
|
||||
Id Module::funcname(Id result_type, Id operand_1, Id operand_2) { \
|
||||
return OpExtInst(result_type, GetGLSLstd450(), opcode, \
|
||||
{operand_1, operand_2}); \
|
||||
#define DEFINE_BINARY(funcname, opcode) \
|
||||
Id Module::funcname(Id result_type, Id operand_1, Id operand_2) { \
|
||||
return OpExtInst(result_type, GetGLSLstd450(), opcode, {operand_1, operand_2}); \
|
||||
}
|
||||
|
||||
#define DEFINE_TRINARY(funcname, opcode) \
|
||||
Id Module::funcname(Id result_type, Id operand_1, Id operand_2, \
|
||||
Id operand_3) { \
|
||||
return OpExtInst(result_type, GetGLSLstd450(), opcode, \
|
||||
{operand_1, operand_2, operand_3}); \
|
||||
#define DEFINE_TRINARY(funcname, opcode) \
|
||||
Id Module::funcname(Id result_type, Id operand_1, Id operand_2, Id operand_3) { \
|
||||
return OpExtInst(result_type, GetGLSLstd450(), opcode, {operand_1, operand_2, operand_3}); \
|
||||
}
|
||||
|
||||
DEFINE_UNARY(OpFAbs, GLSLstd450FAbs)
|
||||
|
|
|
|||
|
|
@ -4,16 +4,15 @@
|
|||
* Lesser General Public License version 3 or any later version.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include "common_types.h"
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
Id Module::OpLoopMerge(Id merge_block, Id continue_target,
|
||||
spv::LoopControlMask loop_control,
|
||||
Id Module::OpLoopMerge(Id merge_block, Id continue_target, spv::LoopControlMask loop_control,
|
||||
const std::vector<Id>& literals) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpLoopMerge)};
|
||||
op->Add(merge_block);
|
||||
|
|
@ -23,15 +22,16 @@ Id Module::OpLoopMerge(Id merge_block, Id continue_target,
|
|||
return AddCode(std::move(op));
|
||||
}
|
||||
|
||||
Id Module::OpSelectionMerge(Id merge_block,
|
||||
spv::SelectionControlMask selection_control) {
|
||||
Id Module::OpSelectionMerge(Id merge_block, spv::SelectionControlMask selection_control) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpSelectionMerge)};
|
||||
op->Add(merge_block);
|
||||
op->Add(static_cast<u32>(selection_control));
|
||||
return AddCode(std::move(op));
|
||||
}
|
||||
|
||||
Id Module::OpLabel() { return AddCode(spv::Op::OpLabel, bound++); }
|
||||
Id Module::OpLabel() {
|
||||
return AddCode(spv::Op::OpLabel, bound++);
|
||||
}
|
||||
|
||||
Id Module::OpBranch(Id target_label) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpBranch)};
|
||||
|
|
@ -39,8 +39,8 @@ Id Module::OpBranch(Id target_label) {
|
|||
return AddCode(std::move(op));
|
||||
}
|
||||
|
||||
Id Module::OpBranchConditional(Id condition, Id true_label, Id false_label,
|
||||
u32 true_weight, u32 false_weight) {
|
||||
Id Module::OpBranchConditional(Id condition, Id true_label, Id false_label, u32 true_weight,
|
||||
u32 false_weight) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpBranchConditional)};
|
||||
op->Add(condition);
|
||||
op->Add(true_label);
|
||||
|
|
@ -52,8 +52,7 @@ Id Module::OpBranchConditional(Id condition, Id true_label, Id false_label,
|
|||
return AddCode(std::move(op));
|
||||
}
|
||||
|
||||
Id Module::OpSwitch(Id selector, Id default_label,
|
||||
const std::vector<Literal>& literals,
|
||||
Id Module::OpSwitch(Id selector, Id default_label, const std::vector<Literal>& literals,
|
||||
const std::vector<Id>& labels) {
|
||||
const std::size_t size = literals.size();
|
||||
assert(literals.size() == labels.size());
|
||||
|
|
@ -67,7 +66,9 @@ Id Module::OpSwitch(Id selector, Id default_label,
|
|||
return AddCode(std::move(op));
|
||||
}
|
||||
|
||||
Id Module::OpReturn() { return AddCode(spv::Op::OpReturn); }
|
||||
Id Module::OpReturn() {
|
||||
return AddCode(spv::Op::OpReturn);
|
||||
}
|
||||
|
||||
Id Module::OpReturnValue(Id value) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpReturnValue)};
|
||||
|
|
|
|||
|
|
@ -10,20 +10,19 @@
|
|||
|
||||
namespace Sirit {
|
||||
|
||||
Id Module::OpFunction(Id result_type, spv::FunctionControlMask function_control,
|
||||
Id function_type) {
|
||||
Id Module::OpFunction(Id result_type, spv::FunctionControlMask function_control, Id function_type) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpFunction, bound++, result_type)};
|
||||
op->Add(static_cast<u32>(function_control));
|
||||
op->Add(function_type);
|
||||
return AddCode(std::move(op));
|
||||
}
|
||||
|
||||
Id Module::OpFunctionEnd() { return AddCode(spv::Op::OpFunctionEnd); }
|
||||
Id Module::OpFunctionEnd() {
|
||||
return AddCode(spv::Op::OpFunctionEnd);
|
||||
}
|
||||
|
||||
Id Module::OpFunctionCall(Id result_type, Id function,
|
||||
const std::vector<Id>& arguments) {
|
||||
auto op{
|
||||
std::make_unique<Op>(spv::Op::OpFunctionCall, bound++, result_type)};
|
||||
Id Module::OpFunctionCall(Id result_type, Id function, const std::vector<Id>& arguments) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpFunctionCall, bound++, result_type)};
|
||||
op->Add(function);
|
||||
op->Add(arguments);
|
||||
return AddCode(std::move(op));
|
||||
|
|
|
|||
|
|
@ -10,79 +10,77 @@
|
|||
|
||||
namespace Sirit {
|
||||
|
||||
static void
|
||||
AddImageOperands(Op* op, std::optional<spv::ImageOperandsMask> image_operands,
|
||||
const std::vector<Id>& operands) {
|
||||
static void AddImageOperands(Op* op, std::optional<spv::ImageOperandsMask> image_operands,
|
||||
const std::vector<Id>& operands) {
|
||||
if (!image_operands)
|
||||
return;
|
||||
op->Add(static_cast<u32>(*image_operands));
|
||||
op->Add(operands);
|
||||
}
|
||||
|
||||
#define DEFINE_IMAGE_OP(opcode) \
|
||||
Id Module::opcode(Id result_type, Id sampled_image, Id coordinate, \
|
||||
std::optional<spv::ImageOperandsMask> image_operands, \
|
||||
const std::vector<Id>& operands) { \
|
||||
auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
|
||||
op->Add(sampled_image); \
|
||||
op->Add(coordinate); \
|
||||
AddImageOperands(op.get(), image_operands, operands); \
|
||||
return AddCode(std::move(op)); \
|
||||
#define DEFINE_IMAGE_OP(opcode) \
|
||||
Id Module::opcode(Id result_type, Id sampled_image, Id coordinate, \
|
||||
std::optional<spv::ImageOperandsMask> image_operands, \
|
||||
const std::vector<Id>& operands) { \
|
||||
auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
|
||||
op->Add(sampled_image); \
|
||||
op->Add(coordinate); \
|
||||
AddImageOperands(op.get(), image_operands, operands); \
|
||||
return AddCode(std::move(op)); \
|
||||
}
|
||||
|
||||
#define DEFINE_IMAGE_EXP_OP(opcode) \
|
||||
Id Module::opcode(Id result_type, Id sampled_image, Id coordinate, \
|
||||
spv::ImageOperandsMask image_operands, Id lod, \
|
||||
const std::vector<Id>& operands) { \
|
||||
auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
|
||||
op->Add(sampled_image); \
|
||||
op->Add(coordinate); \
|
||||
op->Add(static_cast<u32>(image_operands)); \
|
||||
op->Add(lod); \
|
||||
op->Add(operands); \
|
||||
return AddCode(std::move(op)); \
|
||||
#define DEFINE_IMAGE_EXP_OP(opcode) \
|
||||
Id Module::opcode(Id result_type, Id sampled_image, Id coordinate, \
|
||||
spv::ImageOperandsMask image_operands, Id lod, \
|
||||
const std::vector<Id>& operands) { \
|
||||
auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
|
||||
op->Add(sampled_image); \
|
||||
op->Add(coordinate); \
|
||||
op->Add(static_cast<u32>(image_operands)); \
|
||||
op->Add(lod); \
|
||||
op->Add(operands); \
|
||||
return AddCode(std::move(op)); \
|
||||
}
|
||||
|
||||
#define DEFINE_IMAGE_EXTRA_OP(opcode) \
|
||||
Id Module::opcode(Id result_type, Id sampled_image, Id coordinate, \
|
||||
Id extra, \
|
||||
std::optional<spv::ImageOperandsMask> image_operands, \
|
||||
const std::vector<Id>& operands) { \
|
||||
auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
|
||||
op->Add(sampled_image); \
|
||||
op->Add(coordinate); \
|
||||
op->Add(extra); \
|
||||
AddImageOperands(op.get(), image_operands, operands); \
|
||||
return AddCode(std::move(op)); \
|
||||
#define DEFINE_IMAGE_EXTRA_OP(opcode) \
|
||||
Id Module::opcode(Id result_type, Id sampled_image, Id coordinate, Id extra, \
|
||||
std::optional<spv::ImageOperandsMask> image_operands, \
|
||||
const std::vector<Id>& operands) { \
|
||||
auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
|
||||
op->Add(sampled_image); \
|
||||
op->Add(coordinate); \
|
||||
op->Add(extra); \
|
||||
AddImageOperands(op.get(), image_operands, operands); \
|
||||
return AddCode(std::move(op)); \
|
||||
}
|
||||
|
||||
#define DEFINE_IMAGE_EXTRA_EXP_OP(opcode) \
|
||||
Id Module::opcode(Id result_type, Id sampled_image, Id coordinate, \
|
||||
Id extra, spv::ImageOperandsMask image_operands, Id lod, \
|
||||
const std::vector<Id>& operands) { \
|
||||
auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
|
||||
op->Add(sampled_image); \
|
||||
op->Add(coordinate); \
|
||||
op->Add(extra); \
|
||||
op->Add(static_cast<u32>(image_operands)); \
|
||||
op->Add(lod); \
|
||||
op->Add(operands); \
|
||||
return AddCode(std::move(op)); \
|
||||
#define DEFINE_IMAGE_EXTRA_EXP_OP(opcode) \
|
||||
Id Module::opcode(Id result_type, Id sampled_image, Id coordinate, Id extra, \
|
||||
spv::ImageOperandsMask image_operands, Id lod, \
|
||||
const std::vector<Id>& operands) { \
|
||||
auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
|
||||
op->Add(sampled_image); \
|
||||
op->Add(coordinate); \
|
||||
op->Add(extra); \
|
||||
op->Add(static_cast<u32>(image_operands)); \
|
||||
op->Add(lod); \
|
||||
op->Add(operands); \
|
||||
return AddCode(std::move(op)); \
|
||||
}
|
||||
|
||||
#define DEFINE_IMAGE_QUERY_OP(opcode) \
|
||||
Id Module::opcode(Id result_type, Id image) { \
|
||||
auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
|
||||
op->Add(image); \
|
||||
return AddCode(std::move(op)); \
|
||||
#define DEFINE_IMAGE_QUERY_OP(opcode) \
|
||||
Id Module::opcode(Id result_type, Id image) { \
|
||||
auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
|
||||
op->Add(image); \
|
||||
return AddCode(std::move(op)); \
|
||||
}
|
||||
|
||||
#define DEFINE_IMAGE_QUERY_BIN_OP(opcode) \
|
||||
Id Module::opcode(Id result_type, Id image, Id extra) { \
|
||||
auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
|
||||
op->Add(image); \
|
||||
op->Add(extra); \
|
||||
return AddCode(std::move(op)); \
|
||||
#define DEFINE_IMAGE_QUERY_BIN_OP(opcode) \
|
||||
Id Module::opcode(Id result_type, Id image, Id extra) { \
|
||||
auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
|
||||
op->Add(image); \
|
||||
op->Add(extra); \
|
||||
return AddCode(std::move(op)); \
|
||||
}
|
||||
|
||||
DEFINE_IMAGE_OP(OpImageSampleImplicitLod)
|
||||
|
|
@ -104,8 +102,7 @@ DEFINE_IMAGE_QUERY_OP(OpImageQueryLevels)
|
|||
DEFINE_IMAGE_QUERY_OP(OpImageQuerySamples)
|
||||
|
||||
Id Module::OpSampledImage(Id result_type, Id image, Id sampler) {
|
||||
auto op{
|
||||
std::make_unique<Op>(spv::Op::OpSampledImage, bound++, result_type)};
|
||||
auto op{std::make_unique<Op>(spv::Op::OpSampledImage, bound++, result_type)};
|
||||
op->Add(image);
|
||||
op->Add(sampler);
|
||||
return AddCode(std::move(op));
|
||||
|
|
|
|||
|
|
@ -4,36 +4,35 @@
|
|||
* Lesser General Public License version 3 or any later version.
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include "common_types.h"
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
#include <memory>
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
#define DEFINE_UNARY(funcname, opcode) \
|
||||
Id Module::funcname(Id result_type, Id operand) { \
|
||||
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
||||
op->Add(operand); \
|
||||
return AddCode(std::move(op)); \
|
||||
#define DEFINE_UNARY(funcname, opcode) \
|
||||
Id Module::funcname(Id result_type, Id operand) { \
|
||||
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
||||
op->Add(operand); \
|
||||
return AddCode(std::move(op)); \
|
||||
}
|
||||
|
||||
#define DEFINE_BINARY(funcname, opcode) \
|
||||
Id Module::funcname(Id result_type, Id operand_1, Id operand_2) { \
|
||||
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
||||
op->Add(operand_1); \
|
||||
op->Add(operand_2); \
|
||||
return AddCode(std::move(op)); \
|
||||
#define DEFINE_BINARY(funcname, opcode) \
|
||||
Id Module::funcname(Id result_type, Id operand_1, Id operand_2) { \
|
||||
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
||||
op->Add(operand_1); \
|
||||
op->Add(operand_2); \
|
||||
return AddCode(std::move(op)); \
|
||||
}
|
||||
|
||||
#define DEFINE_TRINARY(funcname, opcode) \
|
||||
Id Module::funcname(Id result_type, Id operand_1, Id operand_2, \
|
||||
Id operand_3) { \
|
||||
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
||||
op->Add(operand_1); \
|
||||
op->Add(operand_2); \
|
||||
op->Add(operand_3); \
|
||||
return AddCode(std::move(op)); \
|
||||
#define DEFINE_TRINARY(funcname, opcode) \
|
||||
Id Module::funcname(Id result_type, Id operand_1, Id operand_2, Id operand_3) { \
|
||||
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
||||
op->Add(operand_1); \
|
||||
op->Add(operand_2); \
|
||||
op->Add(operand_3); \
|
||||
return AddCode(std::move(op)); \
|
||||
}
|
||||
|
||||
DEFINE_UNARY(OpIsNan, spv::Op::OpIsNan)
|
||||
|
|
|
|||
|
|
@ -4,14 +4,13 @@
|
|||
* Lesser General Public License version 3 or any later version.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
#include <cassert>
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
Id Module::OpVariable(Id result_type, spv::StorageClass storage_class,
|
||||
Id initializer) {
|
||||
Id Module::OpVariable(Id result_type, spv::StorageClass storage_class, Id initializer) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpVariable, bound++, result_type)};
|
||||
op->Add(static_cast<u32>(storage_class));
|
||||
if (initializer) {
|
||||
|
|
@ -20,8 +19,7 @@ Id Module::OpVariable(Id result_type, spv::StorageClass storage_class,
|
|||
return AddCode(std::move(op));
|
||||
}
|
||||
|
||||
Id Module::OpLoad(Id result_type, Id pointer,
|
||||
std::optional<spv::MemoryAccessMask> memory_access) {
|
||||
Id Module::OpLoad(Id result_type, Id pointer, std::optional<spv::MemoryAccessMask> memory_access) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpLoad, bound++, result_type)};
|
||||
op->Add(pointer);
|
||||
if (memory_access) {
|
||||
|
|
@ -30,8 +28,7 @@ Id Module::OpLoad(Id result_type, Id pointer,
|
|||
return AddCode(std::move(op));
|
||||
}
|
||||
|
||||
Id Module::OpStore(Id pointer, Id object,
|
||||
std::optional<spv::MemoryAccessMask> memory_access) {
|
||||
Id Module::OpStore(Id pointer, Id object, std::optional<spv::MemoryAccessMask> memory_access) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpStore)};
|
||||
op->Add(pointer);
|
||||
op->Add(object);
|
||||
|
|
@ -41,8 +38,7 @@ Id Module::OpStore(Id pointer, Id object,
|
|||
return AddCode(std::move(op));
|
||||
}
|
||||
|
||||
Id Module::OpAccessChain(Id result_type, Id base,
|
||||
const std::vector<Id>& indexes) {
|
||||
Id Module::OpAccessChain(Id result_type, Id base, const std::vector<Id>& indexes) {
|
||||
assert(indexes.size() > 0);
|
||||
auto op{std::make_unique<Op>(spv::Op::OpAccessChain, bound++, result_type)};
|
||||
op->Add(base);
|
||||
|
|
@ -52,18 +48,15 @@ Id Module::OpAccessChain(Id result_type, Id base,
|
|||
|
||||
Id Module::OpCompositeInsert(Id result_type, Id object, Id composite,
|
||||
const std::vector<Literal>& indexes) {
|
||||
auto op{
|
||||
std::make_unique<Op>(spv::Op::OpCompositeInsert, bound++, result_type)};
|
||||
auto op{std::make_unique<Op>(spv::Op::OpCompositeInsert, bound++, result_type)};
|
||||
op->Add(object);
|
||||
op->Add(composite);
|
||||
op->Add(indexes);
|
||||
return AddCode(std::move(op));
|
||||
}
|
||||
|
||||
Id Module::OpCompositeExtract(Id result_type, Id composite,
|
||||
const std::vector<Literal>& indexes) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpCompositeExtract, bound++,
|
||||
result_type)};
|
||||
Id Module::OpCompositeExtract(Id result_type, Id composite, const std::vector<Literal>& indexes) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpCompositeExtract, bound++, result_type)};
|
||||
op->Add(composite);
|
||||
op->Add(indexes);
|
||||
return AddCode(std::move(op));
|
||||
|
|
@ -71,8 +64,7 @@ Id Module::OpCompositeExtract(Id result_type, Id composite,
|
|||
|
||||
Id Module::OpCompositeConstruct(Id result_type, const std::vector<Id>& ids) {
|
||||
assert(ids.size() >= 1);
|
||||
auto op{std::make_unique<Op>(spv::Op::OpCompositeConstruct, bound++,
|
||||
result_type)};
|
||||
auto op{std::make_unique<Op>(spv::Op::OpCompositeConstruct, bound++, result_type)};
|
||||
op->Add(ids);
|
||||
return AddCode(std::move(op));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
* Lesser General Public License version 3 or any later version.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
#include <cassert>
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
* Lesser General Public License version 3 or any later version.
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include "op.h"
|
||||
|
|
@ -63,9 +63,9 @@ Id Module::OpTypeMatrix(Id column_type, int column_count) {
|
|||
return AddDeclaration(std::move(op));
|
||||
}
|
||||
|
||||
Id Module::OpTypeImage(Id sampled_type, spv::Dim dim, int depth, bool arrayed,
|
||||
bool ms, int sampled, spv::ImageFormat image_format,
|
||||
std::optional<spv::AccessQualifier> access_qualifier) {
|
||||
Id Module::OpTypeImage(Id sampled_type, spv::Dim dim, int depth, bool arrayed, bool ms, int sampled,
|
||||
spv::ImageFormat image_format,
|
||||
std::optional<spv::AccessQualifier> access_qualifier) {
|
||||
switch (dim) {
|
||||
case spv::Dim::Dim1D:
|
||||
AddCapability(spv::Capability::Sampled1D);
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
* Lesser General Public License version 3 or any later version.
|
||||
*/
|
||||
|
||||
#include "literal_number.h"
|
||||
#include <cassert>
|
||||
#include "literal_number.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
|
|
@ -23,7 +23,9 @@ void LiteralNumber::Fetch(Stream& stream) const {
|
|||
}
|
||||
}
|
||||
|
||||
u16 LiteralNumber::GetWordCount() const { return is_32 ? 1 : 2; }
|
||||
u16 LiteralNumber::GetWordCount() const {
|
||||
return is_32 ? 1 : 2;
|
||||
}
|
||||
|
||||
bool LiteralNumber::operator==(const Operand& other) const {
|
||||
if (operand_type == other.GetType()) {
|
||||
|
|
|
|||
|
|
@ -6,15 +6,15 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "operand.h"
|
||||
#include "stream.h"
|
||||
#include <cstring>
|
||||
#include <typeindex>
|
||||
#include "operand.h"
|
||||
#include "stream.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
class LiteralNumber : public Operand {
|
||||
public:
|
||||
public:
|
||||
LiteralNumber(std::type_index type);
|
||||
~LiteralNumber();
|
||||
|
||||
|
|
@ -23,7 +23,8 @@ class LiteralNumber : public Operand {
|
|||
|
||||
virtual bool operator==(const Operand& other) const;
|
||||
|
||||
template <typename T> static LiteralNumber* Create(T value) {
|
||||
template <typename T>
|
||||
static LiteralNumber* Create(T value) {
|
||||
static_assert(sizeof(T) == 4 || sizeof(T) == 8);
|
||||
|
||||
LiteralNumber* number = new LiteralNumber(std::type_index(typeid(T)));
|
||||
|
|
@ -32,7 +33,7 @@ class LiteralNumber : public Operand {
|
|||
return number;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
std::type_index type;
|
||||
bool is_32{};
|
||||
u64 raw{};
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
* Lesser General Public License version 3 or any later version.
|
||||
*/
|
||||
|
||||
#include "literal_string.h"
|
||||
#include "common_types.h"
|
||||
#include <string>
|
||||
#include "common_types.h"
|
||||
#include "literal_string.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "operand.h"
|
||||
#include "stream.h"
|
||||
#include <string>
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
class LiteralString : public Operand {
|
||||
public:
|
||||
public:
|
||||
LiteralString(const std::string& string);
|
||||
~LiteralString();
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ class LiteralString : public Operand {
|
|||
|
||||
virtual bool operator==(const Operand& other) const;
|
||||
|
||||
private:
|
||||
private:
|
||||
const std::string string;
|
||||
};
|
||||
|
||||
|
|
|
|||
16
src/op.cpp
16
src/op.cpp
|
|
@ -26,7 +26,9 @@ void Op::Fetch(Stream& stream) const {
|
|||
stream.Write(id.value());
|
||||
}
|
||||
|
||||
u16 Op::GetWordCount() const { return 1; }
|
||||
u16 Op::GetWordCount() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool Op::operator==(const Operand& other) const {
|
||||
if (operand_type != other.GetType()) {
|
||||
|
|
@ -100,11 +102,17 @@ void Op::Add(const std::vector<Literal>& literals) {
|
|||
}
|
||||
}
|
||||
|
||||
void Op::Add(const Operand* operand) { operands.push_back(operand); }
|
||||
void Op::Add(const Operand* operand) {
|
||||
operands.push_back(operand);
|
||||
}
|
||||
|
||||
void Op::Add(u32 integer) { Sink(LiteralNumber::Create<u32>(integer)); }
|
||||
void Op::Add(u32 integer) {
|
||||
Sink(LiteralNumber::Create<u32>(integer));
|
||||
}
|
||||
|
||||
void Op::Add(const std::string& string) { Sink(new LiteralString(string)); }
|
||||
void Op::Add(const std::string& string) {
|
||||
Sink(new LiteralString(string));
|
||||
}
|
||||
|
||||
void Op::Add(const std::vector<Id>& ids) {
|
||||
for (Id op : ids) {
|
||||
|
|
|
|||
9
src/op.h
9
src/op.h
|
|
@ -6,18 +6,17 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include "common_types.h"
|
||||
#include "operand.h"
|
||||
#include "sirit/sirit.h"
|
||||
#include "stream.h"
|
||||
#include <optional>
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
class Op : public Operand {
|
||||
public:
|
||||
explicit Op(spv::Op opcode, std::optional<u32> id = {},
|
||||
Id result_type = nullptr);
|
||||
public:
|
||||
explicit Op(spv::Op opcode, std::optional<u32> id = {}, Id result_type = nullptr);
|
||||
~Op();
|
||||
|
||||
virtual void Fetch(Stream& stream) const;
|
||||
|
|
@ -43,7 +42,7 @@ class Op : public Operand {
|
|||
|
||||
void Add(const std::vector<Id>& ids);
|
||||
|
||||
private:
|
||||
private:
|
||||
u16 WordCount() const;
|
||||
|
||||
spv::Op opcode;
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
* Lesser General Public License version 3 or any later version.
|
||||
*/
|
||||
|
||||
#include "operand.h"
|
||||
#include <cassert>
|
||||
#include "operand.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
|
|
@ -22,12 +22,16 @@ u16 Operand::GetWordCount() const {
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool Operand::operator==(const Operand& other) const { return false; }
|
||||
bool Operand::operator==(const Operand& other) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Operand::operator!=(const Operand& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
OperandType Operand::GetType() const { return operand_type; }
|
||||
OperandType Operand::GetType() const {
|
||||
return operand_type;
|
||||
}
|
||||
|
||||
} // namespace Sirit
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace Sirit {
|
|||
enum class OperandType { Invalid, Op, Number, String };
|
||||
|
||||
class Operand {
|
||||
public:
|
||||
public:
|
||||
Operand();
|
||||
virtual ~Operand();
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ class Operand {
|
|||
|
||||
OperandType GetType() const;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
OperandType operand_type{};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,16 +4,17 @@
|
|||
* Lesser General Public License version 3 or any later version.
|
||||
*/
|
||||
|
||||
#include "sirit/sirit.h"
|
||||
#include "common_types.h"
|
||||
#include "op.h"
|
||||
#include "stream.h"
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include "common_types.h"
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
#include "stream.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
template <typename T> static void WriteSet(Stream& stream, const T& set) {
|
||||
template <typename T>
|
||||
static void WriteSet(Stream& stream, const T& set) {
|
||||
for (const auto& item : set) {
|
||||
item->Write(stream);
|
||||
}
|
||||
|
|
@ -73,15 +74,13 @@ void Module::AddCapability(spv::Capability capability) {
|
|||
capabilities.insert(capability);
|
||||
}
|
||||
|
||||
void Module::SetMemoryModel(spv::AddressingModel addressing_model,
|
||||
spv::MemoryModel memory_model) {
|
||||
void Module::SetMemoryModel(spv::AddressingModel addressing_model, spv::MemoryModel memory_model) {
|
||||
this->addressing_model = addressing_model;
|
||||
this->memory_model = memory_model;
|
||||
}
|
||||
|
||||
void Module::AddEntryPoint(spv::ExecutionModel execution_model, Id entry_point,
|
||||
const std::string& name,
|
||||
const std::vector<Id>& interfaces) {
|
||||
const std::string& name, const std::vector<Id>& interfaces) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpEntryPoint)};
|
||||
op->Add(static_cast<u32>(execution_model));
|
||||
op->Add(entry_point);
|
||||
|
|
@ -91,7 +90,7 @@ void Module::AddEntryPoint(spv::ExecutionModel execution_model, Id entry_point,
|
|||
}
|
||||
|
||||
void Module::AddExecutionMode(Id entry_point, spv::ExecutionMode mode,
|
||||
const std::vector<Literal>& literals) {
|
||||
const std::vector<Literal>& literals) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpExecutionMode)};
|
||||
op->Add(entry_point);
|
||||
op->Add(static_cast<u32>(mode));
|
||||
|
|
@ -121,9 +120,8 @@ Id Module::AddCode(spv::Op opcode, std::optional<u32> id) {
|
|||
}
|
||||
|
||||
Id Module::AddDeclaration(std::unique_ptr<Op> op) {
|
||||
const auto& found{
|
||||
std::find_if(declarations.begin(), declarations.end(),
|
||||
[&op](const auto& other) { return *other == *op; })};
|
||||
const auto& found{std::find_if(declarations.begin(), declarations.end(),
|
||||
[&op](const auto& other) { return *other == *op; })};
|
||||
if (found != declarations.end()) {
|
||||
return found->get();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ void Stream::Write(u16 value) {
|
|||
Write(mem[1]);
|
||||
}
|
||||
|
||||
void Stream::Write(u8 value) { bytes.push_back(value); }
|
||||
void Stream::Write(u8 value) {
|
||||
bytes.push_back(value);
|
||||
}
|
||||
|
||||
} // namespace Sirit
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "common_types.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "common_types.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
class Stream {
|
||||
public:
|
||||
public:
|
||||
explicit Stream(std::vector<u8>& bytes);
|
||||
~Stream();
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ class Stream {
|
|||
|
||||
void Write(u8 value);
|
||||
|
||||
private:
|
||||
private:
|
||||
std::vector<u8>& bytes;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue