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

@ -1,138 +1,131 @@
/* This file is part of the sirit project. /* This file is part of the sirit project.
* Copyright (c) 2018 ReinUsesLisp * Copyright (c) 2018 ReinUsesLisp
* This software may be used and distributed according to the terms of the GNU * This software may be used and distributed according to the terms of the GNU
* Lesser General Public License version 3 or any later version. * Lesser General Public License version 3 or any later version.
*/ */
#include "common_types.h" #include "common_types.h"
#include "op.h" #include "op.h"
#include "sirit/sirit.h" #include "sirit/sirit.h"
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)}; const std::vector<Id>& operands) {
op->Add(image); if (!image_operands)
op->Add(sampler); return;
return AddCode(std::move(op)); op->Add(static_cast<u32>(*image_operands));
} op->Add(operands);
}
void AddImageOperands(Op* op,
std::optional<spv::ImageOperandsMask> image_operands, #define DEFINE_IMAGE_OP(opcode) \
const std::vector<Id>& operands) { Id Module::opcode(Id result_type, Id sampled_image, Id coordinate, \
if (!image_operands) std::optional<spv::ImageOperandsMask> image_operands, \
return; const std::vector<Id>& operands) { \
op->Add(static_cast<u32>(*image_operands)); auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
op->Add(operands); op->Add(sampled_image); \
} op->Add(coordinate); \
AddImageOperands(op.get(), image_operands, operands); \
#define DEFINE_IMAGE_OP(funcname, opcode) \ return AddCode(std::move(op)); \
Id Module::funcname(Id result_type, Id sampled_image, Id coordinate, \ }
std::optional<spv::ImageOperandsMask> image_operands, \
const std::vector<Id>& operands) { \ #define DEFINE_IMAGE_EXP_OP(opcode) \
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \ Id Module::opcode(Id result_type, Id sampled_image, Id coordinate, \
op->Add(sampled_image); \ spv::ImageOperandsMask image_operands, Id lod, \
op->Add(coordinate); \ const std::vector<Id>& operands) { \
AddImageOperands(op.get(), image_operands, operands); \ auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
return AddCode(std::move(op)); \ op->Add(sampled_image); \
} op->Add(coordinate); \
op->Add(static_cast<u32>(image_operands)); \
#define DEFINE_IMAGE_EXP_OP(funcname, opcode) \ op->Add(lod); \
Id Module::funcname(Id result_type, Id sampled_image, Id coordinate, \ op->Add(operands); \
spv::ImageOperandsMask image_operands, Id lod, \ return AddCode(std::move(op)); \
const std::vector<Id>& operands) { \ }
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
op->Add(sampled_image); \ #define DEFINE_IMAGE_EXTRA_OP(opcode) \
op->Add(coordinate); \ Id Module::opcode(Id result_type, Id sampled_image, Id coordinate, \
op->Add(static_cast<u32>(image_operands)); \ Id extra, \
op->Add(lod); \ std::optional<spv::ImageOperandsMask> image_operands, \
op->Add(operands); \ const std::vector<Id>& operands) { \
return AddCode(std::move(op)); \ auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
} op->Add(sampled_image); \
op->Add(coordinate); \
#define DEFINE_IMAGE_EXTRA_OP(funcname, opcode) \ op->Add(extra); \
Id Module::funcname(Id result_type, Id sampled_image, Id coordinate, \ AddImageOperands(op.get(), image_operands, operands); \
Id extra, \ return AddCode(std::move(op)); \
std::optional<spv::ImageOperandsMask> image_operands, \ }
const std::vector<Id>& operands) { \
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \ #define DEFINE_IMAGE_EXTRA_EXP_OP(opcode) \
op->Add(sampled_image); \ Id Module::opcode(Id result_type, Id sampled_image, Id coordinate, \
op->Add(coordinate); \ Id extra, spv::ImageOperandsMask image_operands, Id lod, \
op->Add(extra); \ const std::vector<Id>& operands) { \
AddImageOperands(op.get(), image_operands, operands); \ auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
return AddCode(std::move(op)); \ op->Add(sampled_image); \
} op->Add(coordinate); \
op->Add(extra); \
#define DEFINE_IMAGE_EXTRA_EXP_OP(funcname, opcode) \ op->Add(static_cast<u32>(image_operands)); \
Id Module::funcname(Id result_type, Id sampled_image, Id coordinate, \ op->Add(lod); \
Id extra, spv::ImageOperandsMask image_operands, \ op->Add(operands); \
Id lod, const std::vector<Id>& operands) { \ return AddCode(std::move(op)); \
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \ }
op->Add(sampled_image); \
op->Add(coordinate); \ #define DEFINE_IMAGE_QUERY_OP(opcode) \
op->Add(extra); \ Id Module::opcode(Id result_type, Id image) { \
op->Add(static_cast<u32>(image_operands)); \ auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
op->Add(lod); \ op->Add(image); \
op->Add(operands); \ return AddCode(std::move(op)); \
return AddCode(std::move(op)); \ }
}
#define DEFINE_IMAGE_QUERY_BIN_OP(opcode) \
DEFINE_IMAGE_OP(OpImageSampleImplicitLod, spv::Op::OpImageSampleImplicitLod) Id Module::opcode(Id result_type, Id image, Id extra) { \
DEFINE_IMAGE_EXP_OP(OpImageSampleExplicitLod, spv::Op::OpImageSampleExplicitLod) auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
DEFINE_IMAGE_EXTRA_OP(OpImageSampleDrefImplicitLod, op->Add(image); \
spv::Op::OpImageSampleDrefImplicitLod) op->Add(extra); \
DEFINE_IMAGE_EXTRA_EXP_OP(OpImageSampleDrefExplicitLod, return AddCode(std::move(op)); \
spv::Op::OpImageSampleDrefExplicitLod) }
DEFINE_IMAGE_OP(OpImageSampleProjImplicitLod,
spv::Op::OpImageSampleProjImplicitLod) DEFINE_IMAGE_OP(OpImageSampleImplicitLod)
DEFINE_IMAGE_EXP_OP(OpImageSampleProjExplicitLod, DEFINE_IMAGE_EXP_OP(OpImageSampleExplicitLod)
spv::Op::OpImageSampleProjExplicitLod) DEFINE_IMAGE_EXTRA_OP(OpImageSampleDrefImplicitLod)
DEFINE_IMAGE_EXTRA_OP(OpImageSampleProjDrefImplicitLod, DEFINE_IMAGE_EXTRA_EXP_OP(OpImageSampleDrefExplicitLod)
spv::Op::OpImageSampleProjDrefImplicitLod) DEFINE_IMAGE_OP(OpImageSampleProjImplicitLod)
DEFINE_IMAGE_EXTRA_EXP_OP(OpImageSampleProjDrefExplicitLod, DEFINE_IMAGE_EXP_OP(OpImageSampleProjExplicitLod)
spv::Op::OpImageSampleProjDrefExplicitLod) DEFINE_IMAGE_EXTRA_OP(OpImageSampleProjDrefImplicitLod)
DEFINE_IMAGE_OP(OpImageFetch, spv::Op::OpImageFetch) DEFINE_IMAGE_EXTRA_EXP_OP(OpImageSampleProjDrefExplicitLod)
DEFINE_IMAGE_EXTRA_OP(OpImageGather, spv::Op::OpImageGather) DEFINE_IMAGE_OP(OpImageFetch)
DEFINE_IMAGE_EXTRA_OP(OpImageDrefGather, spv::Op::OpImageDrefGather) DEFINE_IMAGE_EXTRA_OP(OpImageGather)
DEFINE_IMAGE_OP(OpImageRead, spv::Op::OpImageRead) DEFINE_IMAGE_EXTRA_OP(OpImageDrefGather)
DEFINE_IMAGE_OP(OpImageRead)
Id Module::OpImageWrite(Id image, Id coordinate, Id texel, DEFINE_IMAGE_QUERY_BIN_OP(OpImageQuerySizeLod)
std::optional<spv::ImageOperandsMask> image_operands, DEFINE_IMAGE_QUERY_OP(OpImageQuerySize)
const std::vector<Id>& operands) { DEFINE_IMAGE_QUERY_BIN_OP(OpImageQueryLod)
auto op{std::make_unique<Op>(spv::Op::OpImageWrite)}; DEFINE_IMAGE_QUERY_OP(OpImageQueryLevels)
op->Add(image); DEFINE_IMAGE_QUERY_OP(OpImageQuerySamples)
op->Add(coordinate);
op->Add(texel); Id Module::OpSampledImage(Id result_type, Id image, Id sampler) {
AddImageOperands(op.get(), image_operands, operands); auto op{
return AddCode(std::move(op)); std::make_unique<Op>(spv::Op::OpSampledImage, bound++, result_type)};
} op->Add(image);
op->Add(sampler);
Id Module::OpImage(Id result_type, Id sampled_image) { return AddCode(std::move(op));
auto op{std::make_unique<Op>(spv::Op::OpImage, bound++, result_type)}; }
op->Add(sampled_image);
return AddCode(std::move(op)); Id Module::OpImageWrite(Id image, Id coordinate, Id texel,
} std::optional<spv::ImageOperandsMask> image_operands,
const std::vector<Id>& operands) {
#define DEFINE_IMAGE_QUERY_OP(funcname, opcode) \ auto op{std::make_unique<Op>(spv::Op::OpImageWrite)};
Id Module::funcname(Id result_type, Id image) { \ op->Add(image);
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \ op->Add(coordinate);
op->Add(image); \ op->Add(texel);
return AddCode(std::move(op)); \ AddImageOperands(op.get(), image_operands, operands);
} return AddCode(std::move(op));
}
#define DEFINE_IMAGE_QUERY_BIN_OP(funcname, opcode) \
Id Module::funcname(Id result_type, Id image, Id extra) { \ Id Module::OpImage(Id result_type, Id sampled_image) {
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \ auto op{std::make_unique<Op>(spv::Op::OpImage, bound++, result_type)};
op->Add(image); \ op->Add(sampled_image);
op->Add(extra); \ return AddCode(std::move(op));
return AddCode(std::move(op)); \ }
}
} // namespace Sirit
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