early-access version 1866
This commit is contained in:
30
externals/sirit/src/instructions/annotation.cpp
vendored
30
externals/sirit/src/instructions/annotation.cpp
vendored
@@ -4,32 +4,24 @@
|
||||
* 3-Clause BSD License
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "common_types.h"
|
||||
#include "op.h"
|
||||
#include <span>
|
||||
|
||||
#include "sirit/sirit.h"
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
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));
|
||||
op->Add(literals);
|
||||
AddAnnotation(std::move(op));
|
||||
return target;
|
||||
Id Module::Decorate(Id target, spv::Decoration decoration, std::span<const Literal> literals) {
|
||||
annotations->Reserve(3 + literals.size());
|
||||
return *annotations << spv::Op::OpDecorate << target << decoration << literals << EndOp{};
|
||||
}
|
||||
|
||||
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);
|
||||
op->Add(member);
|
||||
op->Add(static_cast<u32>(decoration));
|
||||
op->Add(literals);
|
||||
AddAnnotation(std::move(op));
|
||||
return structure_type;
|
||||
std::span<const Literal> literals) {
|
||||
annotations->Reserve(4 + literals.size());
|
||||
return *annotations << spv::Op::OpMemberDecorate << structure_type << member << decoration
|
||||
<< literals << EndOp{};
|
||||
}
|
||||
|
||||
} // namespace Sirit
|
||||
|
25
externals/sirit/src/instructions/arithmetic.cpp
vendored
25
externals/sirit/src/instructions/arithmetic.cpp
vendored
@@ -4,35 +4,22 @@
|
||||
* 3-Clause BSD License
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include "common_types.h"
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
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)); \
|
||||
code->Reserve(4); \
|
||||
return *code << OpId{opcode, result_type} << operand << EndOp{}; \
|
||||
}
|
||||
|
||||
#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)); \
|
||||
code->Reserve(5); \
|
||||
return *code << OpId{opcode, result_type} << operand_1 << operand_2 << EndOp{}; \
|
||||
}
|
||||
|
||||
DEFINE_UNARY(OpSNegate, spv::Op::OpSNegate)
|
||||
|
138
externals/sirit/src/instructions/atomic.cpp
vendored
138
externals/sirit/src/instructions/atomic.cpp
vendored
@@ -4,145 +4,101 @@
|
||||
* 3-Clause BSD License
|
||||
*/
|
||||
|
||||
#include "common_types.h"
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
Id Module::OpAtomicLoad(Id result_type, Id pointer, Id memory, Id semantics) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpAtomicLoad, bound++, result_type)};
|
||||
op->Add(pointer);
|
||||
op->Add(memory);
|
||||
op->Add(semantics);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(6);
|
||||
return *code << OpId{spv::Op::OpAtomicLoad, result_type} << pointer << memory << semantics
|
||||
<< EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpAtomicStore(Id pointer, Id memory, Id semantics, Id value) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpAtomicStore)};
|
||||
op->Add(pointer);
|
||||
op->Add(memory);
|
||||
op->Add(semantics);
|
||||
op->Add(value);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(5);
|
||||
return *code << OpId{spv::Op::OpAtomicStore} << pointer << memory << semantics << value
|
||||
<< EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpAtomicExchange(Id result_type, Id pointer, Id memory, Id semantics, Id value) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpAtomicExchange, bound++, result_type)};
|
||||
op->Add(pointer);
|
||||
op->Add(memory);
|
||||
op->Add(semantics);
|
||||
op->Add(value);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(7);
|
||||
return *code << OpId{spv::Op::OpAtomicExchange, result_type} << pointer << memory << semantics
|
||||
<< value << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpAtomicCompareExchange(Id result_type, Id pointer, Id memory, Id equal, Id unequal,
|
||||
Id value, Id comparator) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpAtomicCompareExchange, bound++, result_type)};
|
||||
op->Add(pointer);
|
||||
op->Add(memory);
|
||||
op->Add(equal);
|
||||
op->Add(unequal);
|
||||
op->Add(value);
|
||||
op->Add(comparator);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(9);
|
||||
return *code << OpId{spv::Op::OpAtomicCompareExchange, result_type} << pointer << memory
|
||||
<< equal << unequal << value << comparator << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpAtomicIIncrement(Id result_type, Id pointer, Id memory, Id semantics) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpAtomicIIncrement, bound++, result_type)};
|
||||
op->Add(pointer);
|
||||
op->Add(memory);
|
||||
op->Add(semantics);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(6);
|
||||
return *code << OpId{spv::Op::OpAtomicIIncrement, result_type} << pointer << memory << semantics
|
||||
<< EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpAtomicIDecrement(Id result_type, Id pointer, Id memory, Id semantics) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpAtomicIDecrement, bound++, result_type)};
|
||||
op->Add(pointer);
|
||||
op->Add(memory);
|
||||
op->Add(semantics);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(6);
|
||||
return *code << OpId{spv::Op::OpAtomicIDecrement, result_type} << pointer << memory << semantics
|
||||
<< EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpAtomicIAdd(Id result_type, Id pointer, Id memory, Id semantics, Id value) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpAtomicIAdd, bound++, result_type)};
|
||||
op->Add(pointer);
|
||||
op->Add(memory);
|
||||
op->Add(semantics);
|
||||
op->Add(value);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(7);
|
||||
return *code << OpId{spv::Op::OpAtomicIAdd, result_type} << pointer << memory << semantics
|
||||
<< value << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpAtomicISub(Id result_type, Id pointer, Id memory, Id semantics, Id value) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpAtomicISub, bound++, result_type)};
|
||||
op->Add(pointer);
|
||||
op->Add(memory);
|
||||
op->Add(semantics);
|
||||
op->Add(value);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(7);
|
||||
return *code << OpId{spv::Op::OpAtomicISub, result_type} << pointer << memory << semantics
|
||||
<< value << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpAtomicSMin(Id result_type, Id pointer, Id memory, Id semantics, Id value) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpAtomicSMin, bound++, result_type)};
|
||||
op->Add(pointer);
|
||||
op->Add(memory);
|
||||
op->Add(semantics);
|
||||
op->Add(value);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(7);
|
||||
return *code << OpId{spv::Op::OpAtomicSMin, result_type} << pointer << memory << semantics
|
||||
<< value << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpAtomicUMin(Id result_type, Id pointer, Id memory, Id semantics, Id value) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpAtomicUMin, bound++, result_type)};
|
||||
op->Add(pointer);
|
||||
op->Add(memory);
|
||||
op->Add(semantics);
|
||||
op->Add(value);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(7);
|
||||
return *code << OpId{spv::Op::OpAtomicUMin, result_type} << pointer << memory << semantics
|
||||
<< value << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpAtomicSMax(Id result_type, Id pointer, Id memory, Id semantics, Id value) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpAtomicSMax, bound++, result_type)};
|
||||
op->Add(pointer);
|
||||
op->Add(memory);
|
||||
op->Add(semantics);
|
||||
op->Add(value);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(7);
|
||||
return *code << OpId{spv::Op::OpAtomicSMax, result_type} << pointer << memory << semantics
|
||||
<< value << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpAtomicUMax(Id result_type, Id pointer, Id memory, Id semantics, Id value) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpAtomicUMax, bound++, result_type)};
|
||||
op->Add(pointer);
|
||||
op->Add(memory);
|
||||
op->Add(semantics);
|
||||
op->Add(value);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(7);
|
||||
return *code << OpId{spv::Op::OpAtomicUMax, result_type} << pointer << memory << semantics
|
||||
<< value << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpAtomicAnd(Id result_type, Id pointer, Id memory, Id semantics, Id value) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpAtomicAnd, bound++, result_type)};
|
||||
op->Add(pointer);
|
||||
op->Add(memory);
|
||||
op->Add(semantics);
|
||||
op->Add(value);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(7);
|
||||
return *code << OpId{spv::Op::OpAtomicAnd, result_type} << pointer << memory << semantics
|
||||
<< value << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpAtomicOr(Id result_type, Id pointer, Id memory, Id semantics, Id value) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpAtomicOr, bound++, result_type)};
|
||||
op->Add(pointer);
|
||||
op->Add(memory);
|
||||
op->Add(semantics);
|
||||
op->Add(value);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(7);
|
||||
return *code << OpId{spv::Op::OpAtomicOr, result_type} << pointer << memory << semantics
|
||||
<< value << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpAtomicXor(Id result_type, Id pointer, Id memory, Id semantics, Id value) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpAtomicXor, bound++, result_type)};
|
||||
op->Add(pointer);
|
||||
op->Add(memory);
|
||||
op->Add(semantics);
|
||||
op->Add(value);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(7);
|
||||
return *code << OpId{spv::Op::OpAtomicXor, result_type} << pointer << memory << semantics
|
||||
<< value << EndOp{};
|
||||
}
|
||||
|
||||
} // namespace Sirit
|
||||
|
17
externals/sirit/src/instructions/barrier.cpp
vendored
17
externals/sirit/src/instructions/barrier.cpp
vendored
@@ -4,25 +4,20 @@
|
||||
* 3-Clause BSD License
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
Id Module::OpControlBarrier(Id execution, Id memory, Id semantics) {
|
||||
auto op = std::make_unique<Op>(spv::Op::OpControlBarrier);
|
||||
op->Add(execution);
|
||||
op->Add(memory);
|
||||
op->Add(semantics);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(4);
|
||||
return *code << spv::Op::OpControlBarrier << execution << memory << semantics << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpMemoryBarrier(Id scope, Id semantics) {
|
||||
auto op = std::make_unique<Op>(spv::Op::OpMemoryBarrier);
|
||||
op->Add(scope);
|
||||
op->Add(semantics);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(3);
|
||||
return *code << spv::Op::OpMemoryBarrier << scope << semantics << EndOp{};
|
||||
}
|
||||
|
||||
} // namespace Sirit
|
||||
|
81
externals/sirit/src/instructions/bit.cpp
vendored
81
externals/sirit/src/instructions/bit.cpp
vendored
@@ -4,96 +4,73 @@
|
||||
* 3-Clause BSD License
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include "common_types.h"
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
Id Module::OpShiftRightLogical(Id result_type, Id base, Id shift) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpShiftRightLogical, bound++, result_type)};
|
||||
op->Add(base);
|
||||
op->Add(shift);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(5);
|
||||
return *code << OpId{spv::Op::OpShiftRightLogical, result_type} << base << shift << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpShiftRightArithmetic(Id result_type, Id base, Id shift) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpShiftRightArithmetic, bound++, result_type)};
|
||||
op->Add(base);
|
||||
op->Add(shift);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(5);
|
||||
return *code << OpId{spv::Op::OpShiftRightArithmetic, result_type} << base << shift << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpShiftLeftLogical(Id result_type, Id base, Id shift) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpShiftLeftLogical, bound++, result_type)};
|
||||
op->Add(base);
|
||||
op->Add(shift);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(5);
|
||||
return *code << OpId{spv::Op::OpShiftLeftLogical, result_type} << base << shift << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpBitwiseOr(Id result_type, Id operand_1, Id operand_2) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpBitwiseOr, bound++, result_type)};
|
||||
op->Add(operand_1);
|
||||
op->Add(operand_2);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(5);
|
||||
return *code << OpId{spv::Op::OpBitwiseOr, result_type} << operand_1 << operand_2 << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpBitwiseXor(Id result_type, Id operand_1, Id operand_2) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpBitwiseXor, bound++, result_type)};
|
||||
op->Add(operand_1);
|
||||
op->Add(operand_2);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(5);
|
||||
return *code << OpId{spv::Op::OpBitwiseXor, result_type} << operand_1 << operand_2 << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpBitwiseAnd(Id result_type, Id operand_1, Id operand_2) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpBitwiseAnd, bound++, result_type)};
|
||||
op->Add(operand_1);
|
||||
op->Add(operand_2);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(5);
|
||||
return *code << OpId{spv::Op::OpBitwiseAnd, result_type} << operand_1 << operand_2 << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpNot(Id result_type, Id operand) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpNot, bound++, result_type)};
|
||||
op->Add(operand);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(4);
|
||||
return *code << OpId{spv::Op::OpNot, result_type} << operand << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpBitFieldInsert(Id result_type, Id base, Id insert, Id offset, Id count) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpBitFieldInsert, bound++, result_type)};
|
||||
op->Add(base);
|
||||
op->Add(insert);
|
||||
op->Add(offset);
|
||||
op->Add(count);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(7);
|
||||
return *code << OpId{spv::Op::OpBitFieldInsert, result_type} << base << insert << offset
|
||||
<< count << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpBitFieldSExtract(Id result_type, Id base, Id offset, Id count) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpBitFieldSExtract, bound++, result_type)};
|
||||
op->Add(base);
|
||||
op->Add(offset);
|
||||
op->Add(count);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(6);
|
||||
return *code << OpId{spv::Op::OpBitFieldSExtract, result_type} << base << offset << count
|
||||
<< EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpBitFieldUExtract(Id result_type, Id base, Id offset, Id count) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpBitFieldUExtract, bound++, result_type)};
|
||||
op->Add(base);
|
||||
op->Add(offset);
|
||||
op->Add(count);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(6);
|
||||
return *code << OpId{spv::Op::OpBitFieldUExtract, result_type} << base << offset << count
|
||||
<< EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpBitReverse(Id result_type, Id base) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpBitReverse, bound++, result_type)};
|
||||
op->Add(base);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(4);
|
||||
return *code << OpId{spv::Op::OpBitReverse, result_type} << base << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpBitCount(Id result_type, Id base) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpBitCount, bound++, result_type)};
|
||||
op->Add(base);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(4);
|
||||
return *code << OpId{spv::Op::OpBitCount, result_type} << base << EndOp{};
|
||||
}
|
||||
|
||||
} // namespace Sirit
|
||||
|
34
externals/sirit/src/instructions/constant.cpp
vendored
34
externals/sirit/src/instructions/constant.cpp
vendored
@@ -5,42 +5,44 @@
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include "op.h"
|
||||
|
||||
#include "sirit/sirit.h"
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
Id Module::ConstantTrue(Id result_type) {
|
||||
return AddDeclaration(std::make_unique<Op>(spv::Op::OpConstantTrue, bound, result_type));
|
||||
declarations->Reserve(3);
|
||||
return *declarations << OpId{spv::Op::OpConstantTrue, result_type} << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::ConstantFalse(Id result_type) {
|
||||
return AddDeclaration(std::make_unique<Op>(spv::Op::OpConstantFalse, bound, result_type));
|
||||
declarations->Reserve(3);
|
||||
return *declarations << OpId{spv::Op::OpConstantFalse, result_type} << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::Constant(Id result_type, const Literal& literal) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpConstant, bound, result_type)};
|
||||
op->Add(literal);
|
||||
return AddDeclaration(std::move(op));
|
||||
declarations->Reserve(3 + 2);
|
||||
return *declarations << OpId{spv::Op::OpConstant, result_type} << literal << EndOp{};
|
||||
}
|
||||
|
||||
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::ConstantComposite(Id result_type, std::span<const Id> constituents) {
|
||||
declarations->Reserve(3 + constituents.size());
|
||||
return *declarations << OpId{spv::Op::OpConstantComposite, result_type} << constituents
|
||||
<< EndOp{};
|
||||
}
|
||||
|
||||
Id Module::ConstantSampler(Id result_type, spv::SamplerAddressingMode addressing_mode,
|
||||
bool normalized, spv::SamplerFilterMode filter_mode) {
|
||||
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));
|
||||
return AddDeclaration(std::move(op));
|
||||
declarations->Reserve(6);
|
||||
return *declarations << OpId{spv::Op::OpConstantSampler, result_type} << addressing_mode
|
||||
<< normalized << filter_mode << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::ConstantNull(Id result_type) {
|
||||
return AddDeclaration(std::make_unique<Op>(spv::Op::OpConstantNull, bound, result_type));
|
||||
declarations->Reserve(3);
|
||||
return *declarations << OpId{spv::Op::OpConstantNull, result_type} << EndOp{};
|
||||
}
|
||||
|
||||
} // namespace Sirit
|
||||
|
10
externals/sirit/src/instructions/conversion.cpp
vendored
10
externals/sirit/src/instructions/conversion.cpp
vendored
@@ -4,18 +4,16 @@
|
||||
* 3-Clause BSD License
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include "common_types.h"
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
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)); \
|
||||
code->Reserve(4); \
|
||||
return *code << OpId{spv::Op::opcode, result_type} << operand << EndOp{}; \
|
||||
}
|
||||
|
||||
DEFINE_UNARY(OpConvertFToU)
|
||||
|
39
externals/sirit/src/instructions/debug.cpp
vendored
39
externals/sirit/src/instructions/debug.cpp
vendored
@@ -4,44 +4,33 @@
|
||||
* 3-Clause BSD License
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
|
||||
#include "common_types.h"
|
||||
#include "stream.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
Id Module::Name(Id target, std::string name) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpName)};
|
||||
op->Add(target);
|
||||
op->Add(std::move(name));
|
||||
debug.push_back(std::move(op));
|
||||
Id Module::Name(Id target, std::string_view name) {
|
||||
debug->Reserve(3 + WordsInString(name));
|
||||
*debug << spv::Op::OpName << target << name << EndOp{};
|
||||
return target;
|
||||
}
|
||||
|
||||
Id Module::MemberName(Id type, u32 member, std::string name) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpMemberName)};
|
||||
op->Add(type);
|
||||
op->Add(member);
|
||||
op->Add(std::move(name));
|
||||
debug.push_back(std::move(op));
|
||||
Id Module::MemberName(Id type, u32 member, std::string_view name) {
|
||||
debug->Reserve(4 + WordsInString(name));
|
||||
*debug << spv::Op::OpMemberName << type << member << name << EndOp{};
|
||||
return type;
|
||||
}
|
||||
|
||||
Id Module::String(std::string string) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpString, bound++)};
|
||||
op->Add(std::move(string));
|
||||
const auto id = op.get();
|
||||
debug.push_back(std::move(op));
|
||||
return id;
|
||||
Id Module::String(std::string_view string) {
|
||||
debug->Reserve(3 + WordsInString(string));
|
||||
return *debug << OpId{spv::Op::OpString} << string << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpLine(Id file, Literal line, Literal column) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpLine)};
|
||||
op->Add(file);
|
||||
op->Add(line);
|
||||
op->Add(column);
|
||||
return AddCode(std::move(op));
|
||||
debug->Reserve(4);
|
||||
return *debug << spv::Op::OpLine << file << line << column << EndOp{};
|
||||
}
|
||||
|
||||
} // namespace Sirit
|
||||
|
29
externals/sirit/src/instructions/derivatives.cpp
vendored
Executable file
29
externals/sirit/src/instructions/derivatives.cpp
vendored
Executable file
@@ -0,0 +1,29 @@
|
||||
/* This file is part of the sirit project.
|
||||
* Copyright (c) 2021 sirit
|
||||
* This software may be used and distributed according to the terms of the
|
||||
* 3-Clause BSD License
|
||||
*/
|
||||
|
||||
#include "sirit/sirit.h"
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
#define DEFINE_UNARY(funcname, opcode) \
|
||||
Id Module::funcname(Id result_type, Id operand) { \
|
||||
code->Reserve(4); \
|
||||
return *code << OpId{opcode, result_type} << operand << EndOp{}; \
|
||||
}
|
||||
|
||||
DEFINE_UNARY(OpDPdx, spv::Op::OpDPdx)
|
||||
DEFINE_UNARY(OpDPdy, spv::Op::OpDPdy)
|
||||
DEFINE_UNARY(OpFwidth, spv::Op::OpFwidth)
|
||||
DEFINE_UNARY(OpDPdxFine, spv::Op::OpDPdxFine)
|
||||
DEFINE_UNARY(OpDPdyFine, spv::Op::OpDPdyFine)
|
||||
DEFINE_UNARY(OpFwidthFine, spv::Op::OpFwidthFine)
|
||||
DEFINE_UNARY(OpDPdxCoarse, spv::Op::OpDPdxCoarse)
|
||||
DEFINE_UNARY(OpDPdyCoarse, spv::Op::OpDPdyCoarse)
|
||||
DEFINE_UNARY(OpFwidthCoarse, spv::Op::OpFwidthCoarse)
|
||||
|
||||
} // namespace Sirit
|
17
externals/sirit/src/instructions/extension.cpp
vendored
17
externals/sirit/src/instructions/extension.cpp
vendored
@@ -4,20 +4,18 @@
|
||||
* 3-Clause BSD License
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include <spirv/unified1/GLSL.std.450.h>
|
||||
#include "common_types.h"
|
||||
#include "op.h"
|
||||
|
||||
#include "sirit/sirit.h"
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
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);
|
||||
op->Add(operands);
|
||||
return AddCode(std::move(op));
|
||||
Id Module::OpExtInst(Id result_type, Id set, u32 instruction, std::span<const Id> operands) {
|
||||
code->Reserve(5 + operands.size());
|
||||
return *code << OpId{spv::Op::OpExtInst, result_type} << set << instruction << operands
|
||||
<< EndOp{};
|
||||
}
|
||||
|
||||
#define DEFINE_UNARY(funcname, opcode) \
|
||||
@@ -74,4 +72,5 @@ DEFINE_UNARY(OpFindUMsb, GLSLstd450FindUMsb)
|
||||
DEFINE_UNARY(OpInterpolateAtCentroid, GLSLstd450InterpolateAtCentroid)
|
||||
DEFINE_BINARY(OpInterpolateAtSample, GLSLstd450InterpolateAtSample)
|
||||
DEFINE_BINARY(OpInterpolateAtOffset, GLSLstd450InterpolateAtOffset)
|
||||
|
||||
} // namespace Sirit
|
||||
|
99
externals/sirit/src/instructions/flow.cpp
vendored
99
externals/sirit/src/instructions/flow.cpp
vendored
@@ -5,79 +5,96 @@
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include "common_types.h"
|
||||
#include "op.h"
|
||||
|
||||
#include "sirit/sirit.h"
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
Id Module::OpPhi(Id result_type, std::span<const Id> operands) {
|
||||
assert(operands.size() % 2 == 0);
|
||||
code->Reserve(3 + operands.size());
|
||||
return *code << OpId{spv::Op::OpPhi, result_type} << operands << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::DeferredOpPhi(Id result_type, std::span<const Id> blocks) {
|
||||
deferred_phi_nodes.push_back(code->LocalAddress());
|
||||
code->Reserve(3 + blocks.size() * 2);
|
||||
*code << OpId{spv::Op::OpPhi, result_type};
|
||||
for (const Id block : blocks) {
|
||||
*code << u32{0} << block;
|
||||
}
|
||||
return *code << EndOp{};
|
||||
}
|
||||
|
||||
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);
|
||||
op->Add(continue_target);
|
||||
op->Add(static_cast<u32>(loop_control));
|
||||
op->Add(literals);
|
||||
return AddCode(std::move(op));
|
||||
std::span<const Id> literals) {
|
||||
code->Reserve(4 + literals.size());
|
||||
return *code << spv::Op::OpLoopMerge << merge_block << continue_target << loop_control
|
||||
<< literals << EndOp{};
|
||||
}
|
||||
|
||||
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));
|
||||
code->Reserve(3);
|
||||
return *code << spv::Op::OpSelectionMerge << merge_block << selection_control << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpLabel() {
|
||||
return code_store.emplace_back(std::make_unique<Op>(spv::Op::OpLabel, bound++)).get();
|
||||
return Id{++bound};
|
||||
}
|
||||
|
||||
Id Module::OpBranch(Id target_label) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpBranch)};
|
||||
op->Add(target_label);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(2);
|
||||
return *code << spv::Op::OpBranch << target_label << EndOp{};
|
||||
}
|
||||
|
||||
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);
|
||||
op->Add(false_label);
|
||||
code->Reserve(6);
|
||||
*code << spv::Op::OpBranchConditional << condition << true_label << false_label;
|
||||
if (true_weight != 0 || false_weight != 0) {
|
||||
op->Add(true_weight);
|
||||
op->Add(false_weight);
|
||||
*code << true_weight << false_weight;
|
||||
}
|
||||
return AddCode(std::move(op));
|
||||
return *code << EndOp{};
|
||||
}
|
||||
|
||||
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();
|
||||
Id Module::OpSwitch(Id selector, Id default_label, std::span<const Literal> literals,
|
||||
std::span<const Id> labels) {
|
||||
assert(literals.size() == labels.size());
|
||||
auto op{std::make_unique<Op>(spv::Op::OpSwitch)};
|
||||
op->Add(selector);
|
||||
op->Add(default_label);
|
||||
const size_t size = literals.size();
|
||||
code->Reserve(3 + size * 2);
|
||||
|
||||
*code << spv::Op::OpSwitch << selector << default_label;
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
op->Add(literals[i]);
|
||||
op->Add(labels[i]);
|
||||
*code << literals[i] << labels[i];
|
||||
}
|
||||
return AddCode(std::move(op));
|
||||
return *code << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpReturn() {
|
||||
return AddCode(spv::Op::OpReturn);
|
||||
void Module::OpReturn() {
|
||||
code->Reserve(1);
|
||||
*code << spv::Op::OpReturn << EndOp{};
|
||||
}
|
||||
|
||||
void Module::OpUnreachable() {
|
||||
code->Reserve(1);
|
||||
*code << spv::Op::OpUnreachable << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpReturnValue(Id value) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpReturnValue)};
|
||||
op->Add(value);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(2);
|
||||
return *code << spv::Op::OpReturnValue << value << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpKill() {
|
||||
return AddCode(std::make_unique<Op>(spv::Op::OpKill));
|
||||
void Module::OpKill() {
|
||||
code->Reserve(1);
|
||||
*code << spv::Op::OpKill << EndOp{};
|
||||
}
|
||||
|
||||
void Module::OpDemoteToHelperInvocationEXT() {
|
||||
code->Reserve(1);
|
||||
*code << spv::Op::OpDemoteToHelperInvocationEXT << EndOp{};
|
||||
}
|
||||
|
||||
} // namespace Sirit
|
||||
|
29
externals/sirit/src/instructions/function.cpp
vendored
29
externals/sirit/src/instructions/function.cpp
vendored
@@ -4,28 +4,31 @@
|
||||
* 3-Clause BSD License
|
||||
*/
|
||||
|
||||
#include "common_types.h"
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
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));
|
||||
code->Reserve(5);
|
||||
return *code << OpId{spv::Op::OpFunction, result_type} << function_control << function_type
|
||||
<< EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpFunctionEnd() {
|
||||
return AddCode(spv::Op::OpFunctionEnd);
|
||||
void Module::OpFunctionEnd() {
|
||||
code->Reserve(1);
|
||||
*code << spv::Op::OpFunctionEnd << EndOp{};
|
||||
}
|
||||
|
||||
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));
|
||||
Id Module::OpFunctionCall(Id result_type, Id function, std::span<const Id> arguments) {
|
||||
code->Reserve(4 + arguments.size());
|
||||
return *code << OpId{spv::Op::OpFunctionCall, result_type} << function << arguments << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpFunctionParameter(Id result_type) {
|
||||
code->Reserve(3);
|
||||
return *code << OpId{spv::Op::OpFunctionParameter, result_type} << EndOp{};
|
||||
}
|
||||
|
||||
} // namespace Sirit
|
||||
|
60
externals/sirit/src/instructions/group.cpp
vendored
60
externals/sirit/src/instructions/group.cpp
vendored
@@ -4,48 +4,62 @@
|
||||
* 3-Clause BSD License
|
||||
*/
|
||||
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
Id Module::OpSubgroupBallotKHR(Id result_type, Id predicate) {
|
||||
auto op = std::make_unique<Op>(spv::Op::OpSubgroupBallotKHR, bound++, result_type);
|
||||
op->Add(predicate);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(4);
|
||||
return *code << OpId{spv::Op::OpSubgroupBallotKHR, result_type} << predicate << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpSubgroupReadInvocationKHR(Id result_type, Id value, Id index) {
|
||||
auto op = std::make_unique<Op>(spv::Op::OpSubgroupReadInvocationKHR, bound++, result_type);
|
||||
op->Add(value);
|
||||
op->Add(index);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(5);
|
||||
return *code << OpId{spv::Op::OpSubgroupReadInvocationKHR, result_type} << value << index
|
||||
<< EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpSubgroupAllKHR(Id result_type, Id predicate) {
|
||||
auto op = std::make_unique<Op>(spv::Op::OpSubgroupAllKHR, bound++, result_type);
|
||||
op->Add(predicate);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(4);
|
||||
return *code << OpId{spv::Op::OpSubgroupAllKHR, result_type} << predicate << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpSubgroupAnyKHR(Id result_type, Id predicate) {
|
||||
auto op = std::make_unique<Op>(spv::Op::OpSubgroupAnyKHR, bound++, result_type);
|
||||
op->Add(predicate);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(4);
|
||||
return *code << OpId{spv::Op::OpSubgroupAnyKHR, result_type} << predicate << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpSubgroupAllEqualKHR(Id result_type, Id predicate) {
|
||||
auto op = std::make_unique<Op>(spv::Op::OpSubgroupAllEqualKHR, bound++, result_type);
|
||||
op->Add(predicate);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(4);
|
||||
return *code << OpId{spv::Op::OpSubgroupAllEqualKHR, result_type} << predicate << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpGroupNonUniformShuffleXor(Id result_type, spv::Scope scope, Id value, Id mask) {
|
||||
auto op = std::make_unique<Op>(spv::Op::OpGroupNonUniformShuffleXor, bound++, result_type);
|
||||
op->Add(static_cast<u32>(scope));
|
||||
op->Add(value);
|
||||
op->Add(mask);
|
||||
return AddCode(std::move(op));
|
||||
Id Module::OpGroupNonUniformShuffleXor(Id result_type, Id scope, Id value, Id mask) {
|
||||
code->Reserve(6);
|
||||
return *code << OpId{spv::Op::OpGroupNonUniformShuffleXor, result_type} << scope << value
|
||||
<< mask << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpGroupNonUniformAll(Id result_type, Id scope, Id predicate) {
|
||||
code->Reserve(5);
|
||||
return *code << OpId{spv::Op::OpGroupNonUniformAll, result_type} << scope << predicate << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpGroupNonUniformAny(Id result_type, Id scope, Id predicate) {
|
||||
code->Reserve(5);
|
||||
return *code << OpId{spv::Op::OpGroupNonUniformAny, result_type} << scope << predicate << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpGroupNonUniformAllEqual(Id result_type, Id scope, Id value) {
|
||||
code->Reserve(5);
|
||||
return *code << OpId{spv::Op::OpGroupNonUniformAllEqual, result_type} << scope << value << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpGroupNonUniformBallot(Id result_type, Id scope, Id predicate) {
|
||||
code->Reserve(5);
|
||||
return *code << OpId{spv::Op::OpGroupNonUniformBallot, result_type} << scope << predicate << EndOp{};
|
||||
}
|
||||
|
||||
} // namespace Sirit
|
||||
|
163
externals/sirit/src/instructions/image.cpp
vendored
163
externals/sirit/src/instructions/image.cpp
vendored
@@ -4,79 +4,58 @@
|
||||
* 3-Clause BSD License
|
||||
*/
|
||||
|
||||
#include "common_types.h"
|
||||
#include "op.h"
|
||||
#include <cassert>
|
||||
|
||||
#include "sirit/sirit.h"
|
||||
|
||||
namespace Sirit {
|
||||
#include "stream.h"
|
||||
|
||||
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);
|
||||
}
|
||||
namespace Sirit {
|
||||
|
||||
#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)); \
|
||||
std::span<const Id> operands) { \
|
||||
code->Reserve(6 + operands.size()); \
|
||||
return *code << OpId{spv::Op::opcode, result_type} << sampled_image << coordinate \
|
||||
<< image_operands << operands << EndOp{}; \
|
||||
}
|
||||
|
||||
#define DEFINE_IMAGE_EXP_OP(opcode) \
|
||||
Id Module::opcode(Id result_type, Id sampled_image, Id coordinate, \
|
||||
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(static_cast<u32>(image_operands)); \
|
||||
op->Add(operands); \
|
||||
return AddCode(std::move(op)); \
|
||||
spv::ImageOperandsMask image_operands, std::span<const Id> operands) { \
|
||||
code->Reserve(6 + operands.size()); \
|
||||
return *code << OpId{spv::Op::opcode, result_type} << sampled_image << coordinate \
|
||||
<< image_operands << operands << EndOp{}; \
|
||||
}
|
||||
|
||||
#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)); \
|
||||
std::span<const Id> operands) { \
|
||||
code->Reserve(7 + operands.size()); \
|
||||
return *code << OpId{spv::Op::opcode, result_type} << sampled_image << coordinate << extra \
|
||||
<< image_operands << operands << EndOp{}; \
|
||||
}
|
||||
|
||||
#define DEFINE_IMAGE_EXTRA_EXP_OP(opcode) \
|
||||
Id Module::opcode(Id result_type, Id sampled_image, Id coordinate, Id extra, \
|
||||
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); \
|
||||
op->Add(static_cast<u32>(image_operands)); \
|
||||
op->Add(operands); \
|
||||
return AddCode(std::move(op)); \
|
||||
spv::ImageOperandsMask image_operands, std::span<const Id> operands) { \
|
||||
code->Reserve(8 + operands.size()); \
|
||||
return *code << OpId{spv::Op::opcode, result_type} << sampled_image << coordinate << extra \
|
||||
<< image_operands << operands << EndOp{}; \
|
||||
}
|
||||
|
||||
#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)); \
|
||||
code->Reserve(5); \
|
||||
return *code << OpId{spv::Op::opcode, result_type} << image << EndOp{}; \
|
||||
}
|
||||
|
||||
#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)); \
|
||||
code->Reserve(5); \
|
||||
return *code << OpId{spv::Op::opcode, result_type} << image << extra << EndOp{}; \
|
||||
}
|
||||
|
||||
DEFINE_IMAGE_OP(OpImageSampleImplicitLod)
|
||||
@@ -98,27 +77,93 @@ 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)};
|
||||
op->Add(image);
|
||||
op->Add(sampler);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(5);
|
||||
return *code << OpId{spv::Op::OpSampledImage, result_type} << image << sampler << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpImageWrite(Id image, Id coordinate, Id texel,
|
||||
std::optional<spv::ImageOperandsMask> image_operands,
|
||||
const std::vector<Id>& operands) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpImageWrite)};
|
||||
op->Add(image);
|
||||
op->Add(coordinate);
|
||||
op->Add(texel);
|
||||
AddImageOperands(op.get(), image_operands, operands);
|
||||
return AddCode(std::move(op));
|
||||
std::span<const Id> operands) {
|
||||
assert(image_operands.has_value() != operands.empty());
|
||||
code->Reserve(5 + operands.size());
|
||||
return *code << spv::Op::OpImageWrite << image << coordinate << texel << image_operands
|
||||
<< operands << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpImage(Id result_type, Id sampled_image) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpImage, bound++, result_type)};
|
||||
op->Add(sampled_image);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(4);
|
||||
return *code << OpId{spv::Op::OpImage, result_type} << sampled_image << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpImageSparseSampleImplicitLod(Id result_type, Id sampled_image, Id coordinate,
|
||||
std::optional<spv::ImageOperandsMask> image_operands,
|
||||
std::span<const Id> operands) {
|
||||
code->Reserve(5 + (image_operands.has_value() ? 1 : 0) + operands.size());
|
||||
return *code << OpId{spv::Op::OpImageSparseSampleImplicitLod, result_type} << sampled_image
|
||||
<< coordinate << image_operands << operands << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpImageSparseSampleExplicitLod(Id result_type, Id sampled_image, Id coordinate,
|
||||
spv::ImageOperandsMask image_operands,
|
||||
std::span<const Id> operands) {
|
||||
code->Reserve(6 + operands.size());
|
||||
return *code << OpId{spv::Op::OpImageSparseSampleExplicitLod, result_type} << sampled_image
|
||||
<< coordinate << image_operands << operands << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpImageSparseSampleDrefImplicitLod(Id result_type, Id sampled_image, Id coordinate,
|
||||
Id dref,
|
||||
std::optional<spv::ImageOperandsMask> image_operands,
|
||||
std::span<const Id> operands) {
|
||||
code->Reserve(6 + (image_operands.has_value() ? 1 : 0) + operands.size());
|
||||
return *code << OpId{spv::Op::OpImageSparseSampleDrefImplicitLod, result_type} << sampled_image
|
||||
<< coordinate << dref << image_operands << operands << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpImageSparseSampleDrefExplicitLod(Id result_type, Id sampled_image, Id coordinate,
|
||||
Id dref, spv::ImageOperandsMask image_operands,
|
||||
std::span<const Id> operands) {
|
||||
code->Reserve(7 + operands.size());
|
||||
return *code << OpId{spv::Op::OpImageSparseSampleDrefExplicitLod, result_type} << sampled_image
|
||||
<< coordinate << dref << image_operands << operands << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpImageSparseFetch(Id result_type, Id image, Id coordinate,
|
||||
std::optional<spv::ImageOperandsMask> image_operands,
|
||||
std::span<const Id> operands) {
|
||||
code->Reserve(5 + (image_operands.has_value() ? 1 : 0) + operands.size());
|
||||
return *code << OpId{spv::Op::OpImageSparseFetch, result_type} << image << coordinate
|
||||
<< image_operands << operands << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpImageSparseGather(Id result_type, Id sampled_image, Id coordinate, Id component,
|
||||
std::optional<spv::ImageOperandsMask> image_operands,
|
||||
std::span<const Id> operands) {
|
||||
code->Reserve(6 + operands.size());
|
||||
return *code << OpId{spv::Op::OpImageSparseGather, result_type} << sampled_image << coordinate
|
||||
<< component << image_operands << operands << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpImageSparseDrefGather(Id result_type, Id sampled_image, Id coordinate, Id dref,
|
||||
std::optional<spv::ImageOperandsMask> image_operands,
|
||||
std::span<const Id> operands) {
|
||||
code->Reserve(6 + operands.size());
|
||||
return *code << OpId{spv::Op::OpImageSparseDrefGather, result_type} << sampled_image
|
||||
<< coordinate << dref << image_operands << operands << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpImageSparseTexelsResident(Id result_type, Id resident_code) {
|
||||
code->Reserve(4);
|
||||
return *code << OpId{spv::Op::OpImageSparseTexelsResident, result_type} << resident_code
|
||||
<< EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpImageSparseRead(Id result_type, Id image, Id coordinate,
|
||||
std::optional<spv::ImageOperandsMask> image_operands,
|
||||
std::span<const Id> operands) {
|
||||
code->Reserve(5 + (image_operands.has_value() ? 1 : 0) + operands.size());
|
||||
return *code << OpId{spv::Op::OpImageSparseTexelsResident, result_type} << image << coordinate
|
||||
<< image_operands << operands << EndOp{};
|
||||
}
|
||||
|
||||
} // namespace Sirit
|
||||
|
100
externals/sirit/src/instructions/logical.cpp
vendored
100
externals/sirit/src/instructions/logical.cpp
vendored
@@ -4,68 +4,62 @@
|
||||
* 3-Clause BSD License
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include "common_types.h"
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
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(opcode) \
|
||||
Id Module::opcode(Id result_type, Id operand) { \
|
||||
code->Reserve(4); \
|
||||
return *code << OpId{spv::Op::opcode, result_type} << operand << EndOp{}; \
|
||||
}
|
||||
|
||||
#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(opcode) \
|
||||
Id Module::opcode(Id result_type, Id operand_1, Id operand_2) { \
|
||||
code->Reserve(5); \
|
||||
return *code << OpId{spv::Op::opcode, result_type} << operand_1 << operand_2 << EndOp{}; \
|
||||
}
|
||||
|
||||
#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(opcode) \
|
||||
Id Module::opcode(Id result_type, Id operand_1, Id operand_2, Id operand_3) { \
|
||||
code->Reserve(6); \
|
||||
return *code << OpId{spv::Op::opcode, result_type} << operand_1 << operand_2 << operand_3 \
|
||||
<< EndOp{}; \
|
||||
}
|
||||
|
||||
DEFINE_UNARY(OpAny, spv::Op::OpAny)
|
||||
DEFINE_UNARY(OpAll, spv::Op::OpAll)
|
||||
DEFINE_UNARY(OpIsNan, spv::Op::OpIsNan)
|
||||
DEFINE_UNARY(OpIsInf, spv::Op::OpIsInf)
|
||||
DEFINE_BINARY(OpLogicalEqual, spv::Op::OpLogicalEqual)
|
||||
DEFINE_BINARY(OpLogicalNotEqual, spv::Op::OpLogicalNotEqual)
|
||||
DEFINE_BINARY(OpLogicalOr, spv::Op::OpLogicalOr)
|
||||
DEFINE_BINARY(OpLogicalAnd, spv::Op::OpLogicalAnd)
|
||||
DEFINE_UNARY(OpLogicalNot, spv::Op::OpLogicalNot)
|
||||
DEFINE_TRINARY(OpSelect, spv::Op::OpSelect)
|
||||
DEFINE_BINARY(OpIEqual, spv::Op::OpIEqual)
|
||||
DEFINE_BINARY(OpINotEqual, spv::Op::OpINotEqual)
|
||||
DEFINE_BINARY(OpUGreaterThan, spv::Op::OpUGreaterThan)
|
||||
DEFINE_BINARY(OpSGreaterThan, spv::Op::OpSGreaterThan)
|
||||
DEFINE_BINARY(OpUGreaterThanEqual, spv::Op::OpUGreaterThanEqual)
|
||||
DEFINE_BINARY(OpSGreaterThanEqual, spv::Op::OpSGreaterThanEqual)
|
||||
DEFINE_BINARY(OpULessThan, spv::Op::OpULessThan)
|
||||
DEFINE_BINARY(OpSLessThan, spv::Op::OpSLessThan)
|
||||
DEFINE_BINARY(OpULessThanEqual, spv::Op::OpULessThanEqual)
|
||||
DEFINE_BINARY(OpSLessThanEqual, spv::Op::OpSLessThanEqual)
|
||||
DEFINE_BINARY(OpFOrdEqual, spv::Op::OpFOrdEqual)
|
||||
DEFINE_BINARY(OpFUnordEqual, spv::Op::OpFUnordEqual)
|
||||
DEFINE_BINARY(OpFOrdNotEqual, spv::Op::OpFOrdNotEqual)
|
||||
DEFINE_BINARY(OpFUnordNotEqual, spv::Op::OpFUnordNotEqual)
|
||||
DEFINE_BINARY(OpFOrdLessThan, spv::Op::OpFOrdLessThan)
|
||||
DEFINE_BINARY(OpFUnordLessThan, spv::Op::OpFUnordLessThan)
|
||||
DEFINE_BINARY(OpFOrdGreaterThan, spv::Op::OpFOrdGreaterThan)
|
||||
DEFINE_BINARY(OpFUnordGreaterThan, spv::Op::OpFUnordGreaterThan)
|
||||
DEFINE_BINARY(OpFOrdLessThanEqual, spv::Op::OpFOrdLessThanEqual)
|
||||
DEFINE_BINARY(OpFUnordLessThanEqual, spv::Op::OpFUnordLessThanEqual)
|
||||
DEFINE_BINARY(OpFOrdGreaterThanEqual, spv::Op::OpFOrdGreaterThanEqual)
|
||||
DEFINE_BINARY(OpFUnordGreaterThanEqual, spv::Op::OpFUnordGreaterThanEqual)
|
||||
DEFINE_UNARY(OpAny)
|
||||
DEFINE_UNARY(OpAll)
|
||||
DEFINE_UNARY(OpIsNan)
|
||||
DEFINE_UNARY(OpIsInf)
|
||||
DEFINE_BINARY(OpLogicalEqual)
|
||||
DEFINE_BINARY(OpLogicalNotEqual)
|
||||
DEFINE_BINARY(OpLogicalOr)
|
||||
DEFINE_BINARY(OpLogicalAnd)
|
||||
DEFINE_UNARY(OpLogicalNot)
|
||||
DEFINE_TRINARY(OpSelect)
|
||||
DEFINE_BINARY(OpIEqual)
|
||||
DEFINE_BINARY(OpINotEqual)
|
||||
DEFINE_BINARY(OpUGreaterThan)
|
||||
DEFINE_BINARY(OpSGreaterThan)
|
||||
DEFINE_BINARY(OpUGreaterThanEqual)
|
||||
DEFINE_BINARY(OpSGreaterThanEqual)
|
||||
DEFINE_BINARY(OpULessThan)
|
||||
DEFINE_BINARY(OpSLessThan)
|
||||
DEFINE_BINARY(OpULessThanEqual)
|
||||
DEFINE_BINARY(OpSLessThanEqual)
|
||||
DEFINE_BINARY(OpFOrdEqual)
|
||||
DEFINE_BINARY(OpFUnordEqual)
|
||||
DEFINE_BINARY(OpFOrdNotEqual)
|
||||
DEFINE_BINARY(OpFUnordNotEqual)
|
||||
DEFINE_BINARY(OpFOrdLessThan)
|
||||
DEFINE_BINARY(OpFUnordLessThan)
|
||||
DEFINE_BINARY(OpFOrdGreaterThan)
|
||||
DEFINE_BINARY(OpFUnordGreaterThan)
|
||||
DEFINE_BINARY(OpFOrdLessThanEqual)
|
||||
DEFINE_BINARY(OpFUnordLessThanEqual)
|
||||
DEFINE_BINARY(OpFOrdGreaterThanEqual)
|
||||
DEFINE_BINARY(OpFUnordGreaterThanEqual)
|
||||
|
||||
} // namespace Sirit
|
||||
|
89
externals/sirit/src/instructions/memory.cpp
vendored
89
externals/sirit/src/instructions/memory.cpp
vendored
@@ -5,91 +5,64 @@
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include "op.h"
|
||||
|
||||
#include "sirit/sirit.h"
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
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) {
|
||||
op->Add(initializer);
|
||||
}
|
||||
return code_store.emplace_back(std::move(op)).get();
|
||||
}
|
||||
|
||||
Id Module::OpImageTexelPointer(Id result_type, Id image, Id coordinate, Id sample) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpImageTexelPointer, bound++, result_type)};
|
||||
op->Add(image);
|
||||
op->Add(coordinate);
|
||||
op->Add(sample);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(6);
|
||||
return *code << OpId{spv::Op::OpImageTexelPointer, result_type} << image << coordinate << sample
|
||||
<< EndOp{};
|
||||
}
|
||||
|
||||
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) {
|
||||
op->Add(static_cast<u32>(*memory_access));
|
||||
}
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(5);
|
||||
return *code << OpId{spv::Op::OpLoad, result_type} << pointer << memory_access << EndOp{};
|
||||
}
|
||||
|
||||
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);
|
||||
if (memory_access) {
|
||||
op->Add(static_cast<u32>(*memory_access));
|
||||
}
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(4);
|
||||
return *code << spv::Op::OpStore << pointer << object << memory_access << EndOp{};
|
||||
}
|
||||
|
||||
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);
|
||||
op->Add(indexes);
|
||||
return AddCode(std::move(op));
|
||||
Id Module::OpAccessChain(Id result_type, Id base, std::span<const Id> indexes) {
|
||||
assert(!indexes.empty());
|
||||
code->Reserve(4 + indexes.size());
|
||||
return *code << OpId{spv::Op::OpAccessChain, result_type} << base << indexes << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpVectorExtractDynamic(Id result_type, Id vector, Id index) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpVectorExtractDynamic, bound++, result_type)};
|
||||
op->Add(vector);
|
||||
op->Add(index);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(5);
|
||||
return *code << OpId{spv::Op::OpVectorExtractDynamic, result_type} << vector << index
|
||||
<< EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpVectorInsertDynamic(Id result_type, Id vector, Id component, Id index) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpVectorInsertDynamic, bound++, result_type)};
|
||||
op->Add(vector);
|
||||
op->Add(component);
|
||||
op->Add(index);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(6);
|
||||
return *code << OpId{spv::Op::OpVectorInsertDynamic, result_type} << vector << component
|
||||
<< index << EndOp{};
|
||||
}
|
||||
|
||||
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)};
|
||||
op->Add(object);
|
||||
op->Add(composite);
|
||||
op->Add(indexes);
|
||||
return AddCode(std::move(op));
|
||||
std::span<const Literal> indexes) {
|
||||
code->Reserve(5 + indexes.size());
|
||||
return *code << OpId{spv::Op::OpCompositeInsert, result_type} << object << composite << indexes
|
||||
<< EndOp{};
|
||||
}
|
||||
|
||||
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));
|
||||
Id Module::OpCompositeExtract(Id result_type, Id composite, std::span<const Literal> indexes) {
|
||||
code->Reserve(4 + indexes.size());
|
||||
return *code << OpId{spv::Op::OpCompositeExtract, result_type} << composite << indexes
|
||||
<< EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpCompositeConstruct(Id result_type, const std::vector<Id>& ids) {
|
||||
Id Module::OpCompositeConstruct(Id result_type, std::span<const Id> ids) {
|
||||
assert(ids.size() >= 1);
|
||||
auto op{std::make_unique<Op>(spv::Op::OpCompositeConstruct, bound++, result_type)};
|
||||
op->Add(ids);
|
||||
return AddCode(std::move(op));
|
||||
code->Reserve(3 + ids.size());
|
||||
return *code << OpId{spv::Op::OpCompositeConstruct, result_type} << ids << EndOp{};
|
||||
}
|
||||
|
||||
} // namespace Sirit
|
||||
|
26
externals/sirit/src/instructions/misc.cpp
vendored
26
externals/sirit/src/instructions/misc.cpp
vendored
@@ -4,21 +4,35 @@
|
||||
* 3-Clause BSD License
|
||||
*/
|
||||
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
Id Module::OpUndef(Id result_type) {
|
||||
return AddCode(std::make_unique<Op>(spv::Op::OpUndef, bound++, result_type));
|
||||
code->Reserve(3);
|
||||
return *code << OpId{spv::Op::OpUndef, result_type} << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpEmitVertex() {
|
||||
return AddCode(std::make_unique<Op>(spv::Op::OpEmitVertex));
|
||||
void Module::OpEmitVertex() {
|
||||
code->Reserve(1);
|
||||
*code << spv::Op::OpEmitVertex << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::OpEndPrimitive() {
|
||||
return AddCode(std::make_unique<Op>(spv::Op::OpEndPrimitive));
|
||||
void Module::OpEndPrimitive() {
|
||||
code->Reserve(1);
|
||||
*code << spv::Op::OpEndPrimitive << EndOp{};
|
||||
}
|
||||
|
||||
void Module::OpEmitStreamVertex(Id stream) {
|
||||
code->Reserve(2);
|
||||
*code << spv::Op::OpEmitStreamVertex << stream << EndOp{};
|
||||
}
|
||||
|
||||
void Module::OpEndStreamPrimitive(Id stream) {
|
||||
code->Reserve(2);
|
||||
*code << spv::Op::OpEndStreamPrimitive << stream << EndOp{};
|
||||
}
|
||||
|
||||
} // namespace Sirit
|
||||
|
113
externals/sirit/src/instructions/type.cpp
vendored
113
externals/sirit/src/instructions/type.cpp
vendored
@@ -5,137 +5,118 @@
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include "op.h"
|
||||
#include "sirit/sirit.h"
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
Id Module::TypeVoid() {
|
||||
return AddDeclaration(std::make_unique<Op>(spv::Op::OpTypeVoid, bound));
|
||||
declarations->Reserve(2);
|
||||
return *declarations << OpId{spv::Op::OpTypeVoid} << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::TypeBool() {
|
||||
return AddDeclaration(std::make_unique<Op>(spv::Op::OpTypeBool, bound));
|
||||
declarations->Reserve(2);
|
||||
return *declarations << OpId{spv::Op::OpTypeBool} << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::TypeInt(int width, bool is_signed) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpTypeInt, bound)};
|
||||
op->Add(width);
|
||||
op->Add(is_signed ? 1 : 0);
|
||||
return AddDeclaration(std::move(op));
|
||||
declarations->Reserve(4);
|
||||
return *declarations << OpId{spv::Op::OpTypeInt} << width << is_signed << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::TypeFloat(int width) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpTypeFloat, bound)};
|
||||
op->Add(width);
|
||||
return AddDeclaration(std::move(op));
|
||||
declarations->Reserve(3);
|
||||
return *declarations << OpId{spv::Op::OpTypeFloat} << width << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::TypeVector(Id component_type, int component_count) {
|
||||
assert(component_count >= 2);
|
||||
auto op{std::make_unique<Op>(spv::Op::OpTypeVector, bound)};
|
||||
op->Add(component_type);
|
||||
op->Add(component_count);
|
||||
return AddDeclaration(std::move(op));
|
||||
declarations->Reserve(4);
|
||||
return *declarations << OpId{spv::Op::OpTypeVector} << component_type << component_count
|
||||
<< EndOp{};
|
||||
}
|
||||
|
||||
Id Module::TypeMatrix(Id column_type, int column_count) {
|
||||
assert(column_count >= 2);
|
||||
auto op{std::make_unique<Op>(spv::Op::OpTypeMatrix, bound)};
|
||||
op->Add(column_type);
|
||||
op->Add(column_count);
|
||||
return AddDeclaration(std::move(op));
|
||||
declarations->Reserve(4);
|
||||
return *declarations << OpId{spv::Op::OpTypeMatrix} << column_type << column_count << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::TypeImage(Id sampled_type, spv::Dim dim, int depth, bool arrayed, bool ms, int sampled,
|
||||
spv::ImageFormat image_format,
|
||||
std::optional<spv::AccessQualifier> access_qualifier) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpTypeImage, bound)};
|
||||
op->Add(sampled_type);
|
||||
op->Add(static_cast<u32>(dim));
|
||||
op->Add(depth);
|
||||
op->Add(arrayed ? 1 : 0);
|
||||
op->Add(ms ? 1 : 0);
|
||||
op->Add(sampled);
|
||||
op->Add(static_cast<u32>(image_format));
|
||||
if (access_qualifier.has_value()) {
|
||||
op->Add(static_cast<u32>(access_qualifier.value()));
|
||||
}
|
||||
return AddDeclaration(std::move(op));
|
||||
declarations->Reserve(10);
|
||||
return *declarations << OpId{spv::Op::OpTypeImage} << sampled_type << dim << depth << arrayed
|
||||
<< ms << sampled << image_format << access_qualifier << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::TypeSampler() {
|
||||
return AddDeclaration(std::make_unique<Op>(spv::Op::OpTypeSampler, bound));
|
||||
declarations->Reserve(2);
|
||||
return *declarations << OpId{spv::Op::OpTypeSampler} << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::TypeSampledImage(Id image_type) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpTypeSampledImage, bound)};
|
||||
op->Add(image_type);
|
||||
return AddDeclaration(std::move(op));
|
||||
declarations->Reserve(3);
|
||||
return *declarations << OpId{spv::Op::OpTypeSampledImage} << image_type << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::TypeArray(Id element_type, Id length) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpTypeArray, bound)};
|
||||
op->Add(element_type);
|
||||
op->Add(length);
|
||||
return AddDeclaration(std::move(op));
|
||||
declarations->Reserve(4);
|
||||
return *declarations << OpId{spv::Op::OpTypeArray} << element_type << length << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::TypeRuntimeArray(Id element_type) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpTypeRuntimeArray, bound)};
|
||||
op->Add(element_type);
|
||||
return AddDeclaration(std::move(op));
|
||||
declarations->Reserve(3);
|
||||
return *declarations << OpId{spv::Op::OpTypeRuntimeArray} << element_type << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::TypeStruct(const std::vector<Id>& members) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpTypeStruct, bound)};
|
||||
op->Add(members);
|
||||
return AddDeclaration(std::move(op));
|
||||
Id Module::TypeStruct(std::span<const Id> members) {
|
||||
declarations->Reserve(2 + members.size());
|
||||
return *declarations << OpId{spv::Op::OpTypeStruct} << members << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::TypeOpaque(std::string name) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpTypeOpaque, bound)};
|
||||
op->Add(std::move(name));
|
||||
return AddDeclaration(std::move(op));
|
||||
Id Module::TypeOpaque(std::string_view name) {
|
||||
declarations->Reserve(3 + WordsInString(name));
|
||||
return *declarations << OpId{spv::Op::OpTypeOpaque} << name << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::TypePointer(spv::StorageClass storage_class, Id type) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpTypePointer, bound)};
|
||||
op->Add(static_cast<u32>(storage_class));
|
||||
op->Add(type);
|
||||
return AddDeclaration(std::move(op));
|
||||
declarations->Reserve(4);
|
||||
return *declarations << OpId{spv::Op::OpTypePointer} << storage_class << type << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::TypeFunction(Id return_type, const std::vector<Id>& arguments) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpTypeFunction, bound)};
|
||||
op->Add(return_type);
|
||||
op->Add(arguments);
|
||||
return AddDeclaration(std::move(op));
|
||||
Id Module::TypeFunction(Id return_type, std::span<const Id> arguments) {
|
||||
declarations->Reserve(3 + arguments.size());
|
||||
return *declarations << OpId{spv::Op::OpTypeFunction} << return_type << arguments << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::TypeEvent() {
|
||||
return AddDeclaration(std::make_unique<Op>(spv::Op::OpTypeEvent, bound));
|
||||
declarations->Reserve(2);
|
||||
return *declarations << OpId{spv::Op::OpTypeEvent} << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::TypeDeviceEvent() {
|
||||
return AddDeclaration(std::make_unique<Op>(spv::Op::OpTypeDeviceEvent, bound));
|
||||
declarations->Reserve(2);
|
||||
return *declarations << OpId{spv::Op::OpTypeDeviceEvent} << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::TypeReserveId() {
|
||||
return AddDeclaration(std::make_unique<Op>(spv::Op::OpTypeReserveId, bound));
|
||||
declarations->Reserve(2);
|
||||
return *declarations << OpId{spv::Op::OpTypeReserveId} << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::TypeQueue() {
|
||||
return AddDeclaration(std::make_unique<Op>(spv::Op::OpTypeQueue, bound));
|
||||
declarations->Reserve(2);
|
||||
return *declarations << OpId{spv::Op::OpTypeQueue} << EndOp{};
|
||||
}
|
||||
|
||||
Id Module::TypePipe(spv::AccessQualifier access_qualifier) {
|
||||
auto op{std::make_unique<Op>(spv::Op::OpTypePipe, bound)};
|
||||
op->Add(static_cast<u32>(access_qualifier));
|
||||
return AddDeclaration(std::move(op));
|
||||
declarations->Reserve(2);
|
||||
return *declarations << OpId{spv::Op::OpTypePipe} << access_qualifier << EndOp{};
|
||||
}
|
||||
|
||||
} // namespace Sirit
|
||||
|
Reference in New Issue
Block a user