early-access version 1866
This commit is contained in:
+104
-59
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user