Sort macro defitions for image instructions

This commit is contained in:
ReinUsesLisp 2019-02-19 05:01:07 -03:00
parent 88191480a8
commit 38838c9a9d
2 changed files with 132 additions and 138 deletions

View file

@ -17,6 +17,7 @@ namespace Sirit {
op->Add(operand); \ op->Add(operand); \
return AddCode(std::move(op)); \ return AddCode(std::move(op)); \
} }
DEFINE_UNARY(OpConvertFToU) DEFINE_UNARY(OpConvertFToU)
DEFINE_UNARY(OpConvertFToS) DEFINE_UNARY(OpConvertFToS)
DEFINE_UNARY(OpConvertSToF) DEFINE_UNARY(OpConvertSToF)

View file

@ -10,16 +10,8 @@
namespace Sirit { namespace Sirit {
Id Module::OpSampledImage(Id result_type, Id image, Id sampler) { static void
auto op{ AddImageOperands(Op* op, std::optional<spv::ImageOperandsMask> image_operands,
std::make_unique<Op>(spv::Op::OpSampledImage, bound++, result_type)};
op->Add(image);
op->Add(sampler);
return AddCode(std::move(op));
}
void AddImageOperands(Op* op,
std::optional<spv::ImageOperandsMask> image_operands,
const std::vector<Id>& operands) { const std::vector<Id>& operands) {
if (!image_operands) if (!image_operands)
return; return;
@ -27,22 +19,22 @@ void AddImageOperands(Op* op,
op->Add(operands); op->Add(operands);
} }
#define DEFINE_IMAGE_OP(funcname, opcode) \ #define DEFINE_IMAGE_OP(opcode) \
Id Module::funcname(Id result_type, Id sampled_image, Id coordinate, \ Id Module::opcode(Id result_type, Id sampled_image, Id coordinate, \
std::optional<spv::ImageOperandsMask> image_operands, \ std::optional<spv::ImageOperandsMask> image_operands, \
const std::vector<Id>& operands) { \ const std::vector<Id>& operands) { \
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \ auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
op->Add(sampled_image); \ op->Add(sampled_image); \
op->Add(coordinate); \ op->Add(coordinate); \
AddImageOperands(op.get(), image_operands, operands); \ AddImageOperands(op.get(), image_operands, operands); \
return AddCode(std::move(op)); \ return AddCode(std::move(op)); \
} }
#define DEFINE_IMAGE_EXP_OP(funcname, opcode) \ #define DEFINE_IMAGE_EXP_OP(opcode) \
Id Module::funcname(Id result_type, Id sampled_image, Id coordinate, \ Id Module::opcode(Id result_type, Id sampled_image, Id coordinate, \
spv::ImageOperandsMask image_operands, Id lod, \ spv::ImageOperandsMask image_operands, Id lod, \
const std::vector<Id>& operands) { \ const std::vector<Id>& operands) { \
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \ auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
op->Add(sampled_image); \ op->Add(sampled_image); \
op->Add(coordinate); \ op->Add(coordinate); \
op->Add(static_cast<u32>(image_operands)); \ op->Add(static_cast<u32>(image_operands)); \
@ -51,12 +43,12 @@ void AddImageOperands(Op* op,
return AddCode(std::move(op)); \ return AddCode(std::move(op)); \
} }
#define DEFINE_IMAGE_EXTRA_OP(funcname, opcode) \ #define DEFINE_IMAGE_EXTRA_OP(opcode) \
Id Module::funcname(Id result_type, Id sampled_image, Id coordinate, \ Id Module::opcode(Id result_type, Id sampled_image, Id coordinate, \
Id extra, \ Id extra, \
std::optional<spv::ImageOperandsMask> image_operands, \ std::optional<spv::ImageOperandsMask> image_operands, \
const std::vector<Id>& operands) { \ const std::vector<Id>& operands) { \
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \ auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
op->Add(sampled_image); \ op->Add(sampled_image); \
op->Add(coordinate); \ op->Add(coordinate); \
op->Add(extra); \ op->Add(extra); \
@ -64,11 +56,11 @@ void AddImageOperands(Op* op,
return AddCode(std::move(op)); \ return AddCode(std::move(op)); \
} }
#define DEFINE_IMAGE_EXTRA_EXP_OP(funcname, opcode) \ #define DEFINE_IMAGE_EXTRA_EXP_OP(opcode) \
Id Module::funcname(Id result_type, Id sampled_image, Id coordinate, \ Id Module::opcode(Id result_type, Id sampled_image, Id coordinate, \
Id extra, spv::ImageOperandsMask image_operands, \ Id extra, spv::ImageOperandsMask image_operands, Id lod, \
Id lod, const std::vector<Id>& operands) { \ const std::vector<Id>& operands) { \
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \ auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
op->Add(sampled_image); \ op->Add(sampled_image); \
op->Add(coordinate); \ op->Add(coordinate); \
op->Add(extra); \ op->Add(extra); \
@ -78,24 +70,46 @@ void AddImageOperands(Op* op,
return AddCode(std::move(op)); \ return AddCode(std::move(op)); \
} }
DEFINE_IMAGE_OP(OpImageSampleImplicitLod, spv::Op::OpImageSampleImplicitLod) #define DEFINE_IMAGE_QUERY_OP(opcode) \
DEFINE_IMAGE_EXP_OP(OpImageSampleExplicitLod, spv::Op::OpImageSampleExplicitLod) Id Module::opcode(Id result_type, Id image) { \
DEFINE_IMAGE_EXTRA_OP(OpImageSampleDrefImplicitLod, auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
spv::Op::OpImageSampleDrefImplicitLod) op->Add(image); \
DEFINE_IMAGE_EXTRA_EXP_OP(OpImageSampleDrefExplicitLod, return AddCode(std::move(op)); \
spv::Op::OpImageSampleDrefExplicitLod) }
DEFINE_IMAGE_OP(OpImageSampleProjImplicitLod,
spv::Op::OpImageSampleProjImplicitLod) #define DEFINE_IMAGE_QUERY_BIN_OP(opcode) \
DEFINE_IMAGE_EXP_OP(OpImageSampleProjExplicitLod, Id Module::opcode(Id result_type, Id image, Id extra) { \
spv::Op::OpImageSampleProjExplicitLod) auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
DEFINE_IMAGE_EXTRA_OP(OpImageSampleProjDrefImplicitLod, op->Add(image); \
spv::Op::OpImageSampleProjDrefImplicitLod) op->Add(extra); \
DEFINE_IMAGE_EXTRA_EXP_OP(OpImageSampleProjDrefExplicitLod, return AddCode(std::move(op)); \
spv::Op::OpImageSampleProjDrefExplicitLod) }
DEFINE_IMAGE_OP(OpImageFetch, spv::Op::OpImageFetch)
DEFINE_IMAGE_EXTRA_OP(OpImageGather, spv::Op::OpImageGather) DEFINE_IMAGE_OP(OpImageSampleImplicitLod)
DEFINE_IMAGE_EXTRA_OP(OpImageDrefGather, spv::Op::OpImageDrefGather) DEFINE_IMAGE_EXP_OP(OpImageSampleExplicitLod)
DEFINE_IMAGE_OP(OpImageRead, spv::Op::OpImageRead) DEFINE_IMAGE_EXTRA_OP(OpImageSampleDrefImplicitLod)
DEFINE_IMAGE_EXTRA_EXP_OP(OpImageSampleDrefExplicitLod)
DEFINE_IMAGE_OP(OpImageSampleProjImplicitLod)
DEFINE_IMAGE_EXP_OP(OpImageSampleProjExplicitLod)
DEFINE_IMAGE_EXTRA_OP(OpImageSampleProjDrefImplicitLod)
DEFINE_IMAGE_EXTRA_EXP_OP(OpImageSampleProjDrefExplicitLod)
DEFINE_IMAGE_OP(OpImageFetch)
DEFINE_IMAGE_EXTRA_OP(OpImageGather)
DEFINE_IMAGE_EXTRA_OP(OpImageDrefGather)
DEFINE_IMAGE_OP(OpImageRead)
DEFINE_IMAGE_QUERY_BIN_OP(OpImageQuerySizeLod)
DEFINE_IMAGE_QUERY_OP(OpImageQuerySize)
DEFINE_IMAGE_QUERY_BIN_OP(OpImageQueryLod)
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));
}
Id Module::OpImageWrite(Id image, Id coordinate, Id texel, Id Module::OpImageWrite(Id image, Id coordinate, Id texel,
std::optional<spv::ImageOperandsMask> image_operands, std::optional<spv::ImageOperandsMask> image_operands,
@ -114,25 +128,4 @@ Id Module::OpImage(Id result_type, Id sampled_image) {
return AddCode(std::move(op)); return AddCode(std::move(op));
} }
#define DEFINE_IMAGE_QUERY_OP(funcname, opcode) \
Id Module::funcname(Id result_type, Id image) { \
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
op->Add(image); \
return AddCode(std::move(op)); \
}
#define DEFINE_IMAGE_QUERY_BIN_OP(funcname, opcode) \
Id Module::funcname(Id result_type, Id image, Id extra) { \
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
op->Add(image); \
op->Add(extra); \
return AddCode(std::move(op)); \
}
DEFINE_IMAGE_QUERY_BIN_OP(OpImageQuerySizeLod, spv::Op::OpImageQuerySizeLod)
DEFINE_IMAGE_QUERY_OP(OpImageQuerySize, spv::Op::OpImageQuerySize)
DEFINE_IMAGE_QUERY_BIN_OP(OpImageQueryLod, spv::Op::OpImageQueryLod)
DEFINE_IMAGE_QUERY_OP(OpImageQueryLevels, spv::Op::OpImageQueryLevels)
DEFINE_IMAGE_QUERY_OP(OpImageQuerySamples, spv::Op::OpImageQuerySamples)
} // namespace Sirit } // namespace Sirit