mirror of
https://github.com/yuzu-emu/sirit
synced 2024-11-25 03:08:08 +00:00
Change clang-format settings
This commit is contained in:
parent
38838c9a9d
commit
73595f4588
27 changed files with 356 additions and 320 deletions
|
@ -1,6 +1,88 @@
|
||||||
BasedOnStyle: LLVM
|
---
|
||||||
IndentWidth: 4
|
Language: Cpp
|
||||||
|
# BasedOnStyle: LLVM
|
||||||
Language: Cpp
|
AccessModifierOffset: -4
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignConsecutiveAssignments: false
|
||||||
|
AlignConsecutiveDeclarations: false
|
||||||
|
AlignEscapedNewlinesLeft: false
|
||||||
|
AlignOperands: true
|
||||||
|
AlignTrailingComments: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
AllowShortBlocksOnASingleLine: false
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: Empty
|
||||||
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
AlwaysBreakTemplateDeclarations: true
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: true
|
||||||
|
BraceWrapping:
|
||||||
|
AfterClass: false
|
||||||
|
AfterControlStatement: false
|
||||||
|
AfterEnum: false
|
||||||
|
AfterFunction: false
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterObjCDeclaration: false
|
||||||
|
AfterStruct: false
|
||||||
|
AfterUnion: false
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
IndentBraces: false
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializersBeforeComma: false
|
||||||
|
ColumnLimit: 100
|
||||||
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
DerivePointerAlignment: false
|
DerivePointerAlignment: false
|
||||||
|
DisableFormat: false
|
||||||
|
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '^\<[^Q][^/.>]*\>'
|
||||||
|
Priority: -2
|
||||||
|
- Regex: '^\<'
|
||||||
|
Priority: -1
|
||||||
|
- Regex: '^\"'
|
||||||
|
Priority: 0
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentWidth: 4
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||||
|
MacroBlockBegin: ''
|
||||||
|
MacroBlockEnd: ''
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
NamespaceIndentation: None
|
||||||
|
ObjCBlockIndentWidth: 2
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 19
|
||||||
|
PenaltyBreakComment: 300
|
||||||
|
PenaltyBreakFirstLessLess: 120
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyExcessCharacter: 1000000
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 150
|
||||||
PointerAlignment: Left
|
PointerAlignment: Left
|
||||||
|
ReflowComments: true
|
||||||
|
SortIncludes: true
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
SpacesInAngles: false
|
||||||
|
SpacesInContainerLiterals: true
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
Standard: Cpp11
|
||||||
|
TabWidth: 4
|
||||||
|
UseTab: Never
|
||||||
|
...
|
||||||
|
|
|
@ -10,10 +10,10 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <spirv/unified1/spirv.hpp11>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <spirv/unified1/spirv.hpp11>
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
|
@ -22,12 +22,12 @@ constexpr std::uint32_t GENERATOR_MAGIC_NUMBER = 0;
|
||||||
class Op;
|
class Op;
|
||||||
class Operand;
|
class Operand;
|
||||||
|
|
||||||
using Literal = std::variant<std::uint32_t, std::uint64_t, std::int32_t,
|
using Literal =
|
||||||
std::int64_t, float, double>;
|
std::variant<std::uint32_t, std::uint64_t, std::int32_t, std::int64_t, float, double>;
|
||||||
using Id = const Op*;
|
using Id = const Op*;
|
||||||
|
|
||||||
class Module {
|
class Module {
|
||||||
public:
|
public:
|
||||||
explicit Module(std::uint32_t version = spv::Version);
|
explicit Module(std::uint32_t version = spv::Version);
|
||||||
~Module();
|
~Module();
|
||||||
|
|
||||||
|
@ -46,12 +46,10 @@ class Module {
|
||||||
void AddCapability(spv::Capability capability);
|
void AddCapability(spv::Capability capability);
|
||||||
|
|
||||||
/// Sets module memory model.
|
/// Sets module memory model.
|
||||||
void SetMemoryModel(spv::AddressingModel addressing_model,
|
void SetMemoryModel(spv::AddressingModel addressing_model, spv::MemoryModel memory_model);
|
||||||
spv::MemoryModel memory_model);
|
|
||||||
|
|
||||||
/// Adds an entry point.
|
/// Adds an entry point.
|
||||||
void AddEntryPoint(spv::ExecutionModel execution_model, Id entry_point,
|
void AddEntryPoint(spv::ExecutionModel execution_model, Id entry_point, const std::string& name,
|
||||||
const std::string& name,
|
|
||||||
const std::vector<Id>& interfaces = {});
|
const std::vector<Id>& interfaces = {});
|
||||||
|
|
||||||
/// Declare an execution mode for an entry point.
|
/// Declare an execution mode for an entry point.
|
||||||
|
@ -94,8 +92,8 @@ class Module {
|
||||||
Id OpTypeMatrix(Id column_type, int column_count);
|
Id OpTypeMatrix(Id column_type, int column_count);
|
||||||
|
|
||||||
/// Returns type image.
|
/// Returns type image.
|
||||||
Id OpTypeImage(Id sampled_type, spv::Dim dim, int depth, bool arrayed,
|
Id OpTypeImage(Id sampled_type, spv::Dim dim, int depth, bool arrayed, bool ms, int sampled,
|
||||||
bool ms, int sampled, spv::ImageFormat image_format,
|
spv::ImageFormat image_format,
|
||||||
std::optional<spv::AccessQualifier> access_qualifier = {});
|
std::optional<spv::AccessQualifier> access_qualifier = {});
|
||||||
|
|
||||||
/// Returns type sampler.
|
/// Returns type sampler.
|
||||||
|
@ -152,9 +150,8 @@ class Module {
|
||||||
Id ConstantComposite(Id result_type, const std::vector<Id>& constituents);
|
Id ConstantComposite(Id result_type, const std::vector<Id>& constituents);
|
||||||
|
|
||||||
/// Returns a sampler constant.
|
/// Returns a sampler constant.
|
||||||
Id ConstantSampler(Id result_type,
|
Id ConstantSampler(Id result_type, spv::SamplerAddressingMode addressing_mode, bool normalized,
|
||||||
spv::SamplerAddressingMode addressing_mode,
|
spv::SamplerFilterMode filter_mode);
|
||||||
bool normalized, spv::SamplerFilterMode filter_mode);
|
|
||||||
|
|
||||||
/// Returns a null constant value.
|
/// Returns a null constant value.
|
||||||
Id ConstantNull(Id result_type);
|
Id ConstantNull(Id result_type);
|
||||||
|
@ -162,26 +159,22 @@ class Module {
|
||||||
// Function
|
// Function
|
||||||
|
|
||||||
/// Declares a function.
|
/// Declares a function.
|
||||||
Id OpFunction(Id result_type, spv::FunctionControlMask function_control,
|
Id OpFunction(Id result_type, spv::FunctionControlMask function_control, Id function_type);
|
||||||
Id function_type);
|
|
||||||
|
|
||||||
/// Ends a function.
|
/// Ends a function.
|
||||||
Id OpFunctionEnd();
|
Id OpFunctionEnd();
|
||||||
|
|
||||||
/// Call a function.
|
/// Call a function.
|
||||||
Id OpFunctionCall(Id result_type, Id function,
|
Id OpFunctionCall(Id result_type, Id function, const std::vector<Id>& arguments = {});
|
||||||
const std::vector<Id>& arguments = {});
|
|
||||||
|
|
||||||
// Flow
|
// Flow
|
||||||
|
|
||||||
/// Declare a structured loop.
|
/// Declare a structured loop.
|
||||||
Id OpLoopMerge(Id merge_block, Id continue_target,
|
Id OpLoopMerge(Id merge_block, Id continue_target, spv::LoopControlMask loop_control,
|
||||||
spv::LoopControlMask loop_control,
|
|
||||||
const std::vector<Id>& literals = {});
|
const std::vector<Id>& literals = {});
|
||||||
|
|
||||||
/// Declare a structured selection.
|
/// Declare a structured selection.
|
||||||
Id OpSelectionMerge(Id merge_block,
|
Id OpSelectionMerge(Id merge_block, spv::SelectionControlMask selection_control);
|
||||||
spv::SelectionControlMask selection_control);
|
|
||||||
|
|
||||||
/// The block label instruction: Any reference to a block is through this
|
/// The block label instruction: Any reference to a block is through this
|
||||||
/// ref.
|
/// ref.
|
||||||
|
@ -193,12 +186,10 @@ class Module {
|
||||||
/// If condition is true branch to true_label, otherwise branch to
|
/// If condition is true branch to true_label, otherwise branch to
|
||||||
/// false_label.
|
/// false_label.
|
||||||
Id OpBranchConditional(Id condition, Id true_label, Id false_label,
|
Id OpBranchConditional(Id condition, Id true_label, Id false_label,
|
||||||
std::uint32_t true_weight = 0,
|
std::uint32_t true_weight = 0, std::uint32_t false_weight = 0);
|
||||||
std::uint32_t false_weight = 0);
|
|
||||||
|
|
||||||
/// Multi-way branch to one of the operand label.
|
/// Multi-way branch to one of the operand label.
|
||||||
Id OpSwitch(Id selector, Id default_label,
|
Id OpSwitch(Id selector, Id default_label, const std::vector<Literal>& literals,
|
||||||
const std::vector<Literal>& literals,
|
|
||||||
const std::vector<Id>& labels);
|
const std::vector<Id>& labels);
|
||||||
|
|
||||||
/// Returns with no value from a function with void return type.
|
/// Returns with no value from a function with void return type.
|
||||||
|
@ -229,29 +220,24 @@ class Module {
|
||||||
// Memory
|
// Memory
|
||||||
|
|
||||||
/// Allocate an object in memory, resulting in a copy to it.
|
/// Allocate an object in memory, resulting in a copy to it.
|
||||||
Id OpVariable(Id result_type, spv::StorageClass storage_class,
|
Id OpVariable(Id result_type, spv::StorageClass storage_class, Id initializer = nullptr);
|
||||||
Id initializer = nullptr);
|
|
||||||
|
|
||||||
/// Load through a pointer.
|
/// Load through a pointer.
|
||||||
Id OpLoad(Id result_type, Id pointer,
|
Id OpLoad(Id result_type, Id pointer, std::optional<spv::MemoryAccessMask> memory_access = {});
|
||||||
std::optional<spv::MemoryAccessMask> memory_access = {});
|
|
||||||
|
|
||||||
/// Store through a pointer.
|
/// Store through a pointer.
|
||||||
Id OpStore(Id pointer, Id object,
|
Id OpStore(Id pointer, Id object, std::optional<spv::MemoryAccessMask> memory_access = {});
|
||||||
std::optional<spv::MemoryAccessMask> memory_access = {});
|
|
||||||
|
|
||||||
/// Create a pointer into a composite object that can be used with OpLoad
|
/// Create a pointer into a composite object that can be used with OpLoad
|
||||||
/// and OpStore.
|
/// and OpStore.
|
||||||
Id OpAccessChain(Id result_type, Id base,
|
Id OpAccessChain(Id result_type, Id base, const std::vector<Id>& indexes = {});
|
||||||
const std::vector<Id>& indexes = {});
|
|
||||||
|
|
||||||
/// Make a copy of a composite object, while modifying one part of it.
|
/// Make a copy of a composite object, while modifying one part of it.
|
||||||
Id OpCompositeInsert(Id result_type, Id object, Id composite,
|
Id OpCompositeInsert(Id result_type, Id object, Id composite,
|
||||||
const std::vector<Literal>& indexes = {});
|
const std::vector<Literal>& indexes = {});
|
||||||
|
|
||||||
/// Extract a part of a composite object.
|
/// Extract a part of a composite object.
|
||||||
Id OpCompositeExtract(Id result_type, Id composite,
|
Id OpCompositeExtract(Id result_type, Id composite, const std::vector<Literal>& indexes = {});
|
||||||
const std::vector<Literal>& indexes = {});
|
|
||||||
|
|
||||||
/// Construct a new composite object from a set of constituent objects that
|
/// Construct a new composite object from a set of constituent objects that
|
||||||
/// will fully form it.
|
/// will fully form it.
|
||||||
|
@ -260,11 +246,9 @@ class Module {
|
||||||
// Annotation
|
// Annotation
|
||||||
|
|
||||||
/// Add a decoration to target.
|
/// Add a decoration to target.
|
||||||
Id Decorate(Id target, spv::Decoration decoration,
|
Id Decorate(Id target, spv::Decoration decoration, const std::vector<Literal>& literals = {});
|
||||||
const std::vector<Literal>& literals = {});
|
|
||||||
|
|
||||||
Id MemberDecorate(Id structure_type, Literal member,
|
Id MemberDecorate(Id structure_type, Literal member, spv::Decoration decoration,
|
||||||
spv::Decoration decoration,
|
|
||||||
const std::vector<Literal>& literals = {});
|
const std::vector<Literal>& literals = {});
|
||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
|
@ -383,8 +367,7 @@ class Module {
|
||||||
/// Does a bitwise Not on the operand.
|
/// Does a bitwise Not on the operand.
|
||||||
Id OpNot(Id result_type, Id operand);
|
Id OpNot(Id result_type, Id operand);
|
||||||
|
|
||||||
Id OpBitFieldInsert(Id result_type, Id base, Id insert, Id offset,
|
Id OpBitFieldInsert(Id result_type, Id base, Id insert, Id offset, Id count);
|
||||||
Id count);
|
|
||||||
|
|
||||||
Id OpBitFieldSExtract(Id result_type, Id base, Id offset, Id count);
|
Id OpBitFieldSExtract(Id result_type, Id base, Id offset, Id count);
|
||||||
|
|
||||||
|
@ -533,61 +516,49 @@ class Module {
|
||||||
|
|
||||||
Id OpSampledImage(Id result_type, Id image, Id sampler);
|
Id OpSampledImage(Id result_type, Id image, Id sampler);
|
||||||
|
|
||||||
Id OpImageSampleImplicitLod(
|
Id OpImageSampleImplicitLod(Id result_type, Id sampled_image, Id coordinate,
|
||||||
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 = {});
|
|
||||||
|
|
||||||
Id OpImageSampleExplicitLod(Id result_type, Id sampled_image, Id coordinate,
|
Id OpImageSampleExplicitLod(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 = {});
|
||||||
|
|
||||||
Id OpImageSampleDrefImplicitLod(
|
Id OpImageSampleDrefImplicitLod(Id result_type, Id sampled_image, Id coordinate, Id dref,
|
||||||
Id result_type, Id sampled_image, Id coordinate, Id dref,
|
std::optional<spv::ImageOperandsMask> image_operands = {},
|
||||||
std::optional<spv::ImageOperandsMask> image_operands = {},
|
|
||||||
const std::vector<Id>& operands = {});
|
|
||||||
|
|
||||||
Id OpImageSampleDrefExplicitLod(Id result_type, Id sampled_image,
|
|
||||||
Id coordinate, Id dref,
|
|
||||||
spv::ImageOperandsMask image_operands,
|
|
||||||
Id lod,
|
|
||||||
const std::vector<Id>& operands = {});
|
const std::vector<Id>& operands = {});
|
||||||
|
|
||||||
Id OpImageSampleProjImplicitLod(
|
Id OpImageSampleDrefExplicitLod(Id result_type, Id sampled_image, Id coordinate, Id dref,
|
||||||
Id result_type, Id sampled_image, Id coordinate,
|
spv::ImageOperandsMask image_operands, Id lod,
|
||||||
std::optional<spv::ImageOperandsMask> image_operands = {},
|
|
||||||
const std::vector<Id>& operands = {});
|
|
||||||
|
|
||||||
Id OpImageSampleProjExplicitLod(Id result_type, Id sampled_image,
|
|
||||||
Id coordinate,
|
|
||||||
spv::ImageOperandsMask image_operands,
|
|
||||||
Id lod,
|
|
||||||
const std::vector<Id>& operands = {});
|
const std::vector<Id>& operands = {});
|
||||||
|
|
||||||
Id OpImageSampleProjDrefImplicitLod(
|
Id OpImageSampleProjImplicitLod(Id result_type, Id sampled_image, Id coordinate,
|
||||||
Id result_type, Id sampled_image, Id coordinate, Id dref,
|
std::optional<spv::ImageOperandsMask> image_operands = {},
|
||||||
std::optional<spv::ImageOperandsMask> image_operands = {},
|
const std::vector<Id>& operands = {});
|
||||||
const std::vector<Id>& operands = {});
|
|
||||||
|
|
||||||
Id OpImageSampleProjDrefExplicitLod(Id result_type, Id sampled_image,
|
Id OpImageSampleProjExplicitLod(Id result_type, Id sampled_image, Id coordinate,
|
||||||
Id coordinate, Id dref,
|
spv::ImageOperandsMask image_operands, Id lod,
|
||||||
spv::ImageOperandsMask image_operands,
|
const std::vector<Id>& operands = {});
|
||||||
Id lod,
|
|
||||||
|
Id OpImageSampleProjDrefImplicitLod(Id result_type, Id sampled_image, Id coordinate, Id dref,
|
||||||
|
std::optional<spv::ImageOperandsMask> image_operands = {},
|
||||||
|
const std::vector<Id>& operands = {});
|
||||||
|
|
||||||
|
Id OpImageSampleProjDrefExplicitLod(Id result_type, Id sampled_image, Id coordinate, Id dref,
|
||||||
|
spv::ImageOperandsMask image_operands, Id lod,
|
||||||
const std::vector<Id>& operands = {});
|
const std::vector<Id>& operands = {});
|
||||||
|
|
||||||
Id OpImageFetch(Id result_type, Id sampled_image, Id coordinate,
|
Id OpImageFetch(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 = {});
|
||||||
|
|
||||||
Id OpImageGather(Id result_type, Id sampled_image, Id coordinate,
|
Id OpImageGather(Id result_type, Id sampled_image, Id coordinate, Id component,
|
||||||
Id component,
|
|
||||||
std::optional<spv::ImageOperandsMask> image_operands = {},
|
std::optional<spv::ImageOperandsMask> image_operands = {},
|
||||||
const std::vector<Id>& operands = {});
|
const std::vector<Id>& operands = {});
|
||||||
|
|
||||||
Id
|
Id OpImageDrefGather(Id result_type, Id sampled_image, Id coordinate, Id dref,
|
||||||
OpImageDrefGather(Id result_type, Id sampled_image, Id coordinate, Id dref,
|
std::optional<spv::ImageOperandsMask> image_operands = {},
|
||||||
std::optional<spv::ImageOperandsMask> image_operands = {},
|
const std::vector<Id>& operands = {});
|
||||||
const std::vector<Id>& operands = {});
|
|
||||||
|
|
||||||
Id OpImageRead(Id result_type, Id sampled_image, Id coordinate,
|
Id OpImageRead(Id result_type, Id sampled_image, Id coordinate,
|
||||||
std::optional<spv::ImageOperandsMask> image_operands = {},
|
std::optional<spv::ImageOperandsMask> image_operands = {},
|
||||||
|
@ -609,7 +580,7 @@ class Module {
|
||||||
|
|
||||||
Id OpImageQuerySamples(Id result_type, Id image);
|
Id OpImageQuerySamples(Id result_type, Id image);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Id AddCode(std::unique_ptr<Op> op);
|
Id AddCode(std::unique_ptr<Op> op);
|
||||||
|
|
||||||
Id AddCode(spv::Op opcode, std::optional<std::uint32_t> id = {});
|
Id AddCode(spv::Op opcode, std::optional<std::uint32_t> id = {});
|
||||||
|
|
|
@ -4,16 +4,15 @@
|
||||||
* Lesser General Public License version 3 or any later version.
|
* Lesser General Public License version 3 or any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
#include "common_types.h"
|
#include "common_types.h"
|
||||||
#include "op.h"
|
#include "op.h"
|
||||||
#include "sirit/sirit.h"
|
#include "sirit/sirit.h"
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
Id Module::Decorate(Id target, spv::Decoration decoration,
|
Id Module::Decorate(Id target, spv::Decoration decoration, const std::vector<Literal>& literals) {
|
||||||
const std::vector<Literal>& literals) {
|
|
||||||
auto op{std::make_unique<Op>(spv::Op::OpDecorate)};
|
auto op{std::make_unique<Op>(spv::Op::OpDecorate)};
|
||||||
op->Add(target);
|
op->Add(target);
|
||||||
op->Add(static_cast<u32>(decoration));
|
op->Add(static_cast<u32>(decoration));
|
||||||
|
@ -22,8 +21,7 @@ Id Module::Decorate(Id target, spv::Decoration decoration,
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Module::MemberDecorate(Id structure_type, Literal member,
|
Id Module::MemberDecorate(Id structure_type, Literal member, spv::Decoration decoration,
|
||||||
spv::Decoration decoration,
|
|
||||||
const std::vector<Literal>& literals) {
|
const std::vector<Literal>& literals) {
|
||||||
auto op{std::make_unique<Op>(spv::Op::OpMemberDecorate)};
|
auto op{std::make_unique<Op>(spv::Op::OpMemberDecorate)};
|
||||||
op->Add(structure_type);
|
op->Add(structure_type);
|
||||||
|
|
|
@ -4,36 +4,35 @@
|
||||||
* Lesser General Public License version 3 or any later version.
|
* Lesser General Public License version 3 or any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include "common_types.h"
|
#include "common_types.h"
|
||||||
#include "op.h"
|
#include "op.h"
|
||||||
#include "sirit/sirit.h"
|
#include "sirit/sirit.h"
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
#define DEFINE_UNARY(funcname, opcode) \
|
#define DEFINE_UNARY(funcname, opcode) \
|
||||||
Id Module::funcname(Id result_type, Id operand) { \
|
Id Module::funcname(Id result_type, Id operand) { \
|
||||||
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
||||||
op->Add(operand); \
|
op->Add(operand); \
|
||||||
return AddCode(std::move(op)); \
|
return AddCode(std::move(op)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFINE_BINARY(funcname, opcode) \
|
#define DEFINE_BINARY(funcname, opcode) \
|
||||||
Id Module::funcname(Id result_type, Id operand_1, Id operand_2) { \
|
Id Module::funcname(Id result_type, Id operand_1, Id operand_2) { \
|
||||||
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
||||||
op->Add(operand_1); \
|
op->Add(operand_1); \
|
||||||
op->Add(operand_2); \
|
op->Add(operand_2); \
|
||||||
return AddCode(std::move(op)); \
|
return AddCode(std::move(op)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFINE_TRINARY(funcname, opcode) \
|
#define DEFINE_TRINARY(funcname, opcode) \
|
||||||
Id Module::funcname(Id result_type, Id operand_1, Id operand_2, \
|
Id Module::funcname(Id result_type, Id operand_1, Id operand_2, Id operand_3) { \
|
||||||
Id operand_3) { \
|
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
||||||
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
op->Add(operand_1); \
|
||||||
op->Add(operand_1); \
|
op->Add(operand_2); \
|
||||||
op->Add(operand_2); \
|
op->Add(operand_3); \
|
||||||
op->Add(operand_3); \
|
return AddCode(std::move(op)); \
|
||||||
return AddCode(std::move(op)); \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFINE_UNARY(OpSNegate, spv::Op::OpSNegate)
|
DEFINE_UNARY(OpSNegate, spv::Op::OpSNegate)
|
||||||
|
@ -54,5 +53,4 @@ DEFINE_BINARY(OpFMod, spv::Op::OpFMod)
|
||||||
DEFINE_BINARY(OpSRem, spv::Op::OpSRem)
|
DEFINE_BINARY(OpSRem, spv::Op::OpSRem)
|
||||||
DEFINE_BINARY(OpFRem, spv::Op::OpFRem)
|
DEFINE_BINARY(OpFRem, spv::Op::OpFRem)
|
||||||
|
|
||||||
|
|
||||||
} // namespace Sirit
|
} // namespace Sirit
|
||||||
|
|
|
@ -4,32 +4,29 @@
|
||||||
* Lesser General Public License version 3 or any later version.
|
* Lesser General Public License version 3 or any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include "common_types.h"
|
#include "common_types.h"
|
||||||
#include "op.h"
|
#include "op.h"
|
||||||
#include "sirit/sirit.h"
|
#include "sirit/sirit.h"
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
Id Module::OpShiftRightLogical(Id result_type, Id base, Id shift) {
|
Id Module::OpShiftRightLogical(Id result_type, Id base, Id shift) {
|
||||||
auto op{std::make_unique<Op>(spv::Op::OpShiftRightLogical, bound++,
|
auto op{std::make_unique<Op>(spv::Op::OpShiftRightLogical, bound++, result_type)};
|
||||||
result_type)};
|
|
||||||
op->Add(base);
|
op->Add(base);
|
||||||
op->Add(shift);
|
op->Add(shift);
|
||||||
return AddCode(std::move(op));
|
return AddCode(std::move(op));
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Module::OpShiftRightArithmetic(Id result_type, Id base, Id shift) {
|
Id Module::OpShiftRightArithmetic(Id result_type, Id base, Id shift) {
|
||||||
auto op{std::make_unique<Op>(spv::Op::OpShiftRightArithmetic, bound++,
|
auto op{std::make_unique<Op>(spv::Op::OpShiftRightArithmetic, bound++, result_type)};
|
||||||
result_type)};
|
|
||||||
op->Add(base);
|
op->Add(base);
|
||||||
op->Add(shift);
|
op->Add(shift);
|
||||||
return AddCode(std::move(op));
|
return AddCode(std::move(op));
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Module::OpShiftLeftLogical(Id result_type, Id base, Id shift) {
|
Id Module::OpShiftLeftLogical(Id result_type, Id base, Id shift) {
|
||||||
auto op{std::make_unique<Op>(spv::Op::OpShiftLeftLogical, bound++,
|
auto op{std::make_unique<Op>(spv::Op::OpShiftLeftLogical, bound++, result_type)};
|
||||||
result_type)};
|
|
||||||
op->Add(base);
|
op->Add(base);
|
||||||
op->Add(shift);
|
op->Add(shift);
|
||||||
return AddCode(std::move(op));
|
return AddCode(std::move(op));
|
||||||
|
|
|
@ -4,20 +4,18 @@
|
||||||
* Lesser General Public License version 3 or any later version.
|
* Lesser General Public License version 3 or any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include "op.h"
|
#include "op.h"
|
||||||
#include "sirit/sirit.h"
|
#include "sirit/sirit.h"
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
Id Module::ConstantTrue(Id result_type) {
|
Id Module::ConstantTrue(Id result_type) {
|
||||||
return AddDeclaration(
|
return AddDeclaration(std::make_unique<Op>(spv::Op::OpConstantTrue, bound, result_type));
|
||||||
std::make_unique<Op>(spv::Op::OpConstantTrue, bound, result_type));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Module::ConstantFalse(Id result_type) {
|
Id Module::ConstantFalse(Id result_type) {
|
||||||
return AddDeclaration(
|
return AddDeclaration(std::make_unique<Op>(spv::Op::OpConstantFalse, bound, result_type));
|
||||||
std::make_unique<Op>(spv::Op::OpConstantFalse, bound, result_type));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Module::Constant(Id result_type, const Literal& literal) {
|
Id Module::Constant(Id result_type, const Literal& literal) {
|
||||||
|
@ -26,22 +24,17 @@ Id Module::Constant(Id result_type, const Literal& literal) {
|
||||||
return AddDeclaration(std::move(op));
|
return AddDeclaration(std::move(op));
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Module::ConstantComposite(Id result_type,
|
Id Module::ConstantComposite(Id result_type, const std::vector<Id>& constituents) {
|
||||||
const std::vector<Id>& constituents) {
|
auto op{std::make_unique<Op>(spv::Op::OpConstantComposite, bound, result_type)};
|
||||||
auto op{
|
|
||||||
std::make_unique<Op>(spv::Op::OpConstantComposite, bound, result_type)};
|
|
||||||
op->Add(constituents);
|
op->Add(constituents);
|
||||||
return AddDeclaration(std::move(op));
|
return AddDeclaration(std::move(op));
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Module::ConstantSampler(Id result_type,
|
Id Module::ConstantSampler(Id result_type, spv::SamplerAddressingMode addressing_mode,
|
||||||
spv::SamplerAddressingMode addressing_mode,
|
bool normalized, spv::SamplerFilterMode filter_mode) {
|
||||||
bool normalized,
|
|
||||||
spv::SamplerFilterMode filter_mode) {
|
|
||||||
AddCapability(spv::Capability::LiteralSampler);
|
AddCapability(spv::Capability::LiteralSampler);
|
||||||
AddCapability(spv::Capability::Kernel);
|
AddCapability(spv::Capability::Kernel);
|
||||||
auto op{
|
auto op{std::make_unique<Op>(spv::Op::OpConstantSampler, bound, result_type)};
|
||||||
std::make_unique<Op>(spv::Op::OpConstantSampler, bound, result_type)};
|
|
||||||
op->Add(static_cast<u32>(addressing_mode));
|
op->Add(static_cast<u32>(addressing_mode));
|
||||||
op->Add(normalized ? 1 : 0);
|
op->Add(normalized ? 1 : 0);
|
||||||
op->Add(static_cast<u32>(filter_mode));
|
op->Add(static_cast<u32>(filter_mode));
|
||||||
|
@ -49,8 +42,7 @@ Id Module::ConstantSampler(Id result_type,
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Module::ConstantNull(Id result_type) {
|
Id Module::ConstantNull(Id result_type) {
|
||||||
return AddDeclaration(
|
return AddDeclaration(std::make_unique<Op>(spv::Op::OpConstantNull, bound, result_type));
|
||||||
std::make_unique<Op>(spv::Op::OpConstantNull, bound, result_type));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Sirit
|
} // namespace Sirit
|
||||||
|
|
|
@ -4,18 +4,18 @@
|
||||||
* Lesser General Public License version 3 or any later version.
|
* Lesser General Public License version 3 or any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include "common_types.h"
|
#include "common_types.h"
|
||||||
#include "op.h"
|
#include "op.h"
|
||||||
#include "sirit/sirit.h"
|
#include "sirit/sirit.h"
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
#define DEFINE_UNARY(opcode) \
|
#define DEFINE_UNARY(opcode) \
|
||||||
Id Module::opcode(Id result_type, Id operand) { \
|
Id Module::opcode(Id result_type, Id operand) { \
|
||||||
auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
|
auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
|
||||||
op->Add(operand); \
|
op->Add(operand); \
|
||||||
return AddCode(std::move(op)); \
|
return AddCode(std::move(op)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFINE_UNARY(OpConvertFToU)
|
DEFINE_UNARY(OpConvertFToU)
|
||||||
|
|
|
@ -4,10 +4,10 @@
|
||||||
* Lesser General Public License version 3 or any later version.
|
* Lesser General Public License version 3 or any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "op.h"
|
|
||||||
#include "sirit/sirit.h"
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "op.h"
|
||||||
|
#include "sirit/sirit.h"
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
|
|
|
@ -4,16 +4,15 @@
|
||||||
* Lesser General Public License version 3 or any later version.
|
* Lesser General Public License version 3 or any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <spirv/unified1/GLSL.std.450.h>
|
||||||
#include "common_types.h"
|
#include "common_types.h"
|
||||||
#include "op.h"
|
#include "op.h"
|
||||||
#include "sirit/sirit.h"
|
#include "sirit/sirit.h"
|
||||||
#include <memory>
|
|
||||||
#include <spirv/unified1/GLSL.std.450.h>
|
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
Id Module::OpExtInst(Id result_type, Id set, u32 instruction,
|
Id Module::OpExtInst(Id result_type, Id set, u32 instruction, const std::vector<Id>& operands) {
|
||||||
const std::vector<Id>& operands) {
|
|
||||||
auto op{std::make_unique<Op>(spv::Op::OpExtInst, bound++, result_type)};
|
auto op{std::make_unique<Op>(spv::Op::OpExtInst, bound++, result_type)};
|
||||||
op->Add(set);
|
op->Add(set);
|
||||||
op->Add(instruction);
|
op->Add(instruction);
|
||||||
|
@ -21,22 +20,19 @@ Id Module::OpExtInst(Id result_type, Id set, u32 instruction,
|
||||||
return AddCode(std::move(op));
|
return AddCode(std::move(op));
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFINE_UNARY(funcname, opcode) \
|
#define DEFINE_UNARY(funcname, opcode) \
|
||||||
Id Module::funcname(Id result_type, Id operand) { \
|
Id Module::funcname(Id result_type, Id operand) { \
|
||||||
return OpExtInst(result_type, GetGLSLstd450(), opcode, {operand}); \
|
return OpExtInst(result_type, GetGLSLstd450(), opcode, {operand}); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFINE_BINARY(funcname, opcode) \
|
#define DEFINE_BINARY(funcname, opcode) \
|
||||||
Id Module::funcname(Id result_type, Id operand_1, Id operand_2) { \
|
Id Module::funcname(Id result_type, Id operand_1, Id operand_2) { \
|
||||||
return OpExtInst(result_type, GetGLSLstd450(), opcode, \
|
return OpExtInst(result_type, GetGLSLstd450(), opcode, {operand_1, operand_2}); \
|
||||||
{operand_1, operand_2}); \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFINE_TRINARY(funcname, opcode) \
|
#define DEFINE_TRINARY(funcname, opcode) \
|
||||||
Id Module::funcname(Id result_type, Id operand_1, Id operand_2, \
|
Id Module::funcname(Id result_type, Id operand_1, Id operand_2, Id operand_3) { \
|
||||||
Id operand_3) { \
|
return OpExtInst(result_type, GetGLSLstd450(), opcode, {operand_1, operand_2, operand_3}); \
|
||||||
return OpExtInst(result_type, GetGLSLstd450(), opcode, \
|
|
||||||
{operand_1, operand_2, operand_3}); \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFINE_UNARY(OpFAbs, GLSLstd450FAbs)
|
DEFINE_UNARY(OpFAbs, GLSLstd450FAbs)
|
||||||
|
|
|
@ -4,16 +4,15 @@
|
||||||
* Lesser General Public License version 3 or any later version.
|
* Lesser General Public License version 3 or any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <vector>
|
||||||
#include "common_types.h"
|
#include "common_types.h"
|
||||||
#include "op.h"
|
#include "op.h"
|
||||||
#include "sirit/sirit.h"
|
#include "sirit/sirit.h"
|
||||||
#include <cassert>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
Id Module::OpLoopMerge(Id merge_block, Id continue_target,
|
Id Module::OpLoopMerge(Id merge_block, Id continue_target, spv::LoopControlMask loop_control,
|
||||||
spv::LoopControlMask loop_control,
|
|
||||||
const std::vector<Id>& literals) {
|
const std::vector<Id>& literals) {
|
||||||
auto op{std::make_unique<Op>(spv::Op::OpLoopMerge)};
|
auto op{std::make_unique<Op>(spv::Op::OpLoopMerge)};
|
||||||
op->Add(merge_block);
|
op->Add(merge_block);
|
||||||
|
@ -23,15 +22,16 @@ Id Module::OpLoopMerge(Id merge_block, Id continue_target,
|
||||||
return AddCode(std::move(op));
|
return AddCode(std::move(op));
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Module::OpSelectionMerge(Id merge_block,
|
Id Module::OpSelectionMerge(Id merge_block, spv::SelectionControlMask selection_control) {
|
||||||
spv::SelectionControlMask selection_control) {
|
|
||||||
auto op{std::make_unique<Op>(spv::Op::OpSelectionMerge)};
|
auto op{std::make_unique<Op>(spv::Op::OpSelectionMerge)};
|
||||||
op->Add(merge_block);
|
op->Add(merge_block);
|
||||||
op->Add(static_cast<u32>(selection_control));
|
op->Add(static_cast<u32>(selection_control));
|
||||||
return AddCode(std::move(op));
|
return AddCode(std::move(op));
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Module::OpLabel() { return AddCode(spv::Op::OpLabel, bound++); }
|
Id Module::OpLabel() {
|
||||||
|
return AddCode(spv::Op::OpLabel, bound++);
|
||||||
|
}
|
||||||
|
|
||||||
Id Module::OpBranch(Id target_label) {
|
Id Module::OpBranch(Id target_label) {
|
||||||
auto op{std::make_unique<Op>(spv::Op::OpBranch)};
|
auto op{std::make_unique<Op>(spv::Op::OpBranch)};
|
||||||
|
@ -39,8 +39,8 @@ Id Module::OpBranch(Id target_label) {
|
||||||
return AddCode(std::move(op));
|
return AddCode(std::move(op));
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Module::OpBranchConditional(Id condition, Id true_label, Id false_label,
|
Id Module::OpBranchConditional(Id condition, Id true_label, Id false_label, u32 true_weight,
|
||||||
u32 true_weight, u32 false_weight) {
|
u32 false_weight) {
|
||||||
auto op{std::make_unique<Op>(spv::Op::OpBranchConditional)};
|
auto op{std::make_unique<Op>(spv::Op::OpBranchConditional)};
|
||||||
op->Add(condition);
|
op->Add(condition);
|
||||||
op->Add(true_label);
|
op->Add(true_label);
|
||||||
|
@ -52,8 +52,7 @@ Id Module::OpBranchConditional(Id condition, Id true_label, Id false_label,
|
||||||
return AddCode(std::move(op));
|
return AddCode(std::move(op));
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Module::OpSwitch(Id selector, Id default_label,
|
Id Module::OpSwitch(Id selector, Id default_label, const std::vector<Literal>& literals,
|
||||||
const std::vector<Literal>& literals,
|
|
||||||
const std::vector<Id>& labels) {
|
const std::vector<Id>& labels) {
|
||||||
const std::size_t size = literals.size();
|
const std::size_t size = literals.size();
|
||||||
assert(literals.size() == labels.size());
|
assert(literals.size() == labels.size());
|
||||||
|
@ -67,7 +66,9 @@ Id Module::OpSwitch(Id selector, Id default_label,
|
||||||
return AddCode(std::move(op));
|
return AddCode(std::move(op));
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Module::OpReturn() { return AddCode(spv::Op::OpReturn); }
|
Id Module::OpReturn() {
|
||||||
|
return AddCode(spv::Op::OpReturn);
|
||||||
|
}
|
||||||
|
|
||||||
Id Module::OpReturnValue(Id value) {
|
Id Module::OpReturnValue(Id value) {
|
||||||
auto op{std::make_unique<Op>(spv::Op::OpReturnValue)};
|
auto op{std::make_unique<Op>(spv::Op::OpReturnValue)};
|
||||||
|
|
|
@ -10,20 +10,19 @@
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
Id Module::OpFunction(Id result_type, spv::FunctionControlMask function_control,
|
Id Module::OpFunction(Id result_type, spv::FunctionControlMask function_control, Id function_type) {
|
||||||
Id function_type) {
|
|
||||||
auto op{std::make_unique<Op>(spv::Op::OpFunction, bound++, result_type)};
|
auto op{std::make_unique<Op>(spv::Op::OpFunction, bound++, result_type)};
|
||||||
op->Add(static_cast<u32>(function_control));
|
op->Add(static_cast<u32>(function_control));
|
||||||
op->Add(function_type);
|
op->Add(function_type);
|
||||||
return AddCode(std::move(op));
|
return AddCode(std::move(op));
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Module::OpFunctionEnd() { return AddCode(spv::Op::OpFunctionEnd); }
|
Id Module::OpFunctionEnd() {
|
||||||
|
return AddCode(spv::Op::OpFunctionEnd);
|
||||||
|
}
|
||||||
|
|
||||||
Id Module::OpFunctionCall(Id result_type, Id function,
|
Id Module::OpFunctionCall(Id result_type, Id function, const std::vector<Id>& arguments) {
|
||||||
const std::vector<Id>& arguments) {
|
auto op{std::make_unique<Op>(spv::Op::OpFunctionCall, bound++, result_type)};
|
||||||
auto op{
|
|
||||||
std::make_unique<Op>(spv::Op::OpFunctionCall, bound++, result_type)};
|
|
||||||
op->Add(function);
|
op->Add(function);
|
||||||
op->Add(arguments);
|
op->Add(arguments);
|
||||||
return AddCode(std::move(op));
|
return AddCode(std::move(op));
|
||||||
|
|
|
@ -10,79 +10,77 @@
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
static void
|
static void AddImageOperands(Op* op, std::optional<spv::ImageOperandsMask> image_operands,
|
||||||
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;
|
||||||
op->Add(static_cast<u32>(*image_operands));
|
op->Add(static_cast<u32>(*image_operands));
|
||||||
op->Add(operands);
|
op->Add(operands);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFINE_IMAGE_OP(opcode) \
|
#define DEFINE_IMAGE_OP(opcode) \
|
||||||
Id Module::opcode(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>(spv::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(opcode) \
|
#define DEFINE_IMAGE_EXP_OP(opcode) \
|
||||||
Id Module::opcode(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>(spv::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)); \
|
||||||
op->Add(lod); \
|
op->Add(lod); \
|
||||||
op->Add(operands); \
|
op->Add(operands); \
|
||||||
return AddCode(std::move(op)); \
|
return AddCode(std::move(op)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFINE_IMAGE_EXTRA_OP(opcode) \
|
#define DEFINE_IMAGE_EXTRA_OP(opcode) \
|
||||||
Id Module::opcode(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>(spv::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); \
|
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_EXTRA_EXP_OP(opcode) \
|
#define DEFINE_IMAGE_EXTRA_EXP_OP(opcode) \
|
||||||
Id Module::opcode(Id result_type, Id sampled_image, Id coordinate, \
|
Id Module::opcode(Id result_type, Id sampled_image, Id coordinate, Id extra, \
|
||||||
Id extra, 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>(spv::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); \
|
||||||
op->Add(static_cast<u32>(image_operands)); \
|
op->Add(static_cast<u32>(image_operands)); \
|
||||||
op->Add(lod); \
|
op->Add(lod); \
|
||||||
op->Add(operands); \
|
op->Add(operands); \
|
||||||
return AddCode(std::move(op)); \
|
return AddCode(std::move(op)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFINE_IMAGE_QUERY_OP(opcode) \
|
#define DEFINE_IMAGE_QUERY_OP(opcode) \
|
||||||
Id Module::opcode(Id result_type, Id image) { \
|
Id Module::opcode(Id result_type, Id image) { \
|
||||||
auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
|
auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
|
||||||
op->Add(image); \
|
op->Add(image); \
|
||||||
return AddCode(std::move(op)); \
|
return AddCode(std::move(op)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFINE_IMAGE_QUERY_BIN_OP(opcode) \
|
#define DEFINE_IMAGE_QUERY_BIN_OP(opcode) \
|
||||||
Id Module::opcode(Id result_type, Id image, Id extra) { \
|
Id Module::opcode(Id result_type, Id image, Id extra) { \
|
||||||
auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
|
auto op{std::make_unique<Op>(spv::Op::opcode, bound++, result_type)}; \
|
||||||
op->Add(image); \
|
op->Add(image); \
|
||||||
op->Add(extra); \
|
op->Add(extra); \
|
||||||
return AddCode(std::move(op)); \
|
return AddCode(std::move(op)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFINE_IMAGE_OP(OpImageSampleImplicitLod)
|
DEFINE_IMAGE_OP(OpImageSampleImplicitLod)
|
||||||
|
@ -104,8 +102,7 @@ DEFINE_IMAGE_QUERY_OP(OpImageQueryLevels)
|
||||||
DEFINE_IMAGE_QUERY_OP(OpImageQuerySamples)
|
DEFINE_IMAGE_QUERY_OP(OpImageQuerySamples)
|
||||||
|
|
||||||
Id Module::OpSampledImage(Id result_type, Id image, Id sampler) {
|
Id Module::OpSampledImage(Id result_type, Id image, Id sampler) {
|
||||||
auto op{
|
auto op{std::make_unique<Op>(spv::Op::OpSampledImage, bound++, result_type)};
|
||||||
std::make_unique<Op>(spv::Op::OpSampledImage, bound++, result_type)};
|
|
||||||
op->Add(image);
|
op->Add(image);
|
||||||
op->Add(sampler);
|
op->Add(sampler);
|
||||||
return AddCode(std::move(op));
|
return AddCode(std::move(op));
|
||||||
|
|
|
@ -4,36 +4,35 @@
|
||||||
* Lesser General Public License version 3 or any later version.
|
* Lesser General Public License version 3 or any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include "common_types.h"
|
#include "common_types.h"
|
||||||
#include "op.h"
|
#include "op.h"
|
||||||
#include "sirit/sirit.h"
|
#include "sirit/sirit.h"
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
#define DEFINE_UNARY(funcname, opcode) \
|
#define DEFINE_UNARY(funcname, opcode) \
|
||||||
Id Module::funcname(Id result_type, Id operand) { \
|
Id Module::funcname(Id result_type, Id operand) { \
|
||||||
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
||||||
op->Add(operand); \
|
op->Add(operand); \
|
||||||
return AddCode(std::move(op)); \
|
return AddCode(std::move(op)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFINE_BINARY(funcname, opcode) \
|
#define DEFINE_BINARY(funcname, opcode) \
|
||||||
Id Module::funcname(Id result_type, Id operand_1, Id operand_2) { \
|
Id Module::funcname(Id result_type, Id operand_1, Id operand_2) { \
|
||||||
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
||||||
op->Add(operand_1); \
|
op->Add(operand_1); \
|
||||||
op->Add(operand_2); \
|
op->Add(operand_2); \
|
||||||
return AddCode(std::move(op)); \
|
return AddCode(std::move(op)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFINE_TRINARY(funcname, opcode) \
|
#define DEFINE_TRINARY(funcname, opcode) \
|
||||||
Id Module::funcname(Id result_type, Id operand_1, Id operand_2, \
|
Id Module::funcname(Id result_type, Id operand_1, Id operand_2, Id operand_3) { \
|
||||||
Id operand_3) { \
|
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
||||||
auto op{std::make_unique<Op>(opcode, bound++, result_type)}; \
|
op->Add(operand_1); \
|
||||||
op->Add(operand_1); \
|
op->Add(operand_2); \
|
||||||
op->Add(operand_2); \
|
op->Add(operand_3); \
|
||||||
op->Add(operand_3); \
|
return AddCode(std::move(op)); \
|
||||||
return AddCode(std::move(op)); \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFINE_UNARY(OpIsNan, spv::Op::OpIsNan)
|
DEFINE_UNARY(OpIsNan, spv::Op::OpIsNan)
|
||||||
|
|
|
@ -4,14 +4,13 @@
|
||||||
* Lesser General Public License version 3 or any later version.
|
* Lesser General Public License version 3 or any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include "op.h"
|
#include "op.h"
|
||||||
#include "sirit/sirit.h"
|
#include "sirit/sirit.h"
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
Id Module::OpVariable(Id result_type, spv::StorageClass storage_class,
|
Id Module::OpVariable(Id result_type, spv::StorageClass storage_class, Id initializer) {
|
||||||
Id initializer) {
|
|
||||||
auto op{std::make_unique<Op>(spv::Op::OpVariable, bound++, result_type)};
|
auto op{std::make_unique<Op>(spv::Op::OpVariable, bound++, result_type)};
|
||||||
op->Add(static_cast<u32>(storage_class));
|
op->Add(static_cast<u32>(storage_class));
|
||||||
if (initializer) {
|
if (initializer) {
|
||||||
|
@ -20,8 +19,7 @@ Id Module::OpVariable(Id result_type, spv::StorageClass storage_class,
|
||||||
return AddCode(std::move(op));
|
return AddCode(std::move(op));
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Module::OpLoad(Id result_type, Id pointer,
|
Id Module::OpLoad(Id result_type, Id pointer, std::optional<spv::MemoryAccessMask> memory_access) {
|
||||||
std::optional<spv::MemoryAccessMask> memory_access) {
|
|
||||||
auto op{std::make_unique<Op>(spv::Op::OpLoad, bound++, result_type)};
|
auto op{std::make_unique<Op>(spv::Op::OpLoad, bound++, result_type)};
|
||||||
op->Add(pointer);
|
op->Add(pointer);
|
||||||
if (memory_access) {
|
if (memory_access) {
|
||||||
|
@ -30,8 +28,7 @@ Id Module::OpLoad(Id result_type, Id pointer,
|
||||||
return AddCode(std::move(op));
|
return AddCode(std::move(op));
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Module::OpStore(Id pointer, Id object,
|
Id Module::OpStore(Id pointer, Id object, std::optional<spv::MemoryAccessMask> memory_access) {
|
||||||
std::optional<spv::MemoryAccessMask> memory_access) {
|
|
||||||
auto op{std::make_unique<Op>(spv::Op::OpStore)};
|
auto op{std::make_unique<Op>(spv::Op::OpStore)};
|
||||||
op->Add(pointer);
|
op->Add(pointer);
|
||||||
op->Add(object);
|
op->Add(object);
|
||||||
|
@ -41,8 +38,7 @@ Id Module::OpStore(Id pointer, Id object,
|
||||||
return AddCode(std::move(op));
|
return AddCode(std::move(op));
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Module::OpAccessChain(Id result_type, Id base,
|
Id Module::OpAccessChain(Id result_type, Id base, const std::vector<Id>& indexes) {
|
||||||
const std::vector<Id>& indexes) {
|
|
||||||
assert(indexes.size() > 0);
|
assert(indexes.size() > 0);
|
||||||
auto op{std::make_unique<Op>(spv::Op::OpAccessChain, bound++, result_type)};
|
auto op{std::make_unique<Op>(spv::Op::OpAccessChain, bound++, result_type)};
|
||||||
op->Add(base);
|
op->Add(base);
|
||||||
|
@ -52,18 +48,15 @@ Id Module::OpAccessChain(Id result_type, Id base,
|
||||||
|
|
||||||
Id Module::OpCompositeInsert(Id result_type, Id object, Id composite,
|
Id Module::OpCompositeInsert(Id result_type, Id object, Id composite,
|
||||||
const std::vector<Literal>& indexes) {
|
const std::vector<Literal>& indexes) {
|
||||||
auto op{
|
auto op{std::make_unique<Op>(spv::Op::OpCompositeInsert, bound++, result_type)};
|
||||||
std::make_unique<Op>(spv::Op::OpCompositeInsert, bound++, result_type)};
|
|
||||||
op->Add(object);
|
op->Add(object);
|
||||||
op->Add(composite);
|
op->Add(composite);
|
||||||
op->Add(indexes);
|
op->Add(indexes);
|
||||||
return AddCode(std::move(op));
|
return AddCode(std::move(op));
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Module::OpCompositeExtract(Id result_type, Id composite,
|
Id Module::OpCompositeExtract(Id result_type, Id composite, const std::vector<Literal>& indexes) {
|
||||||
const std::vector<Literal>& indexes) {
|
auto op{std::make_unique<Op>(spv::Op::OpCompositeExtract, bound++, result_type)};
|
||||||
auto op{std::make_unique<Op>(spv::Op::OpCompositeExtract, bound++,
|
|
||||||
result_type)};
|
|
||||||
op->Add(composite);
|
op->Add(composite);
|
||||||
op->Add(indexes);
|
op->Add(indexes);
|
||||||
return AddCode(std::move(op));
|
return AddCode(std::move(op));
|
||||||
|
@ -71,8 +64,7 @@ Id Module::OpCompositeExtract(Id result_type, Id composite,
|
||||||
|
|
||||||
Id Module::OpCompositeConstruct(Id result_type, const std::vector<Id>& ids) {
|
Id Module::OpCompositeConstruct(Id result_type, const std::vector<Id>& ids) {
|
||||||
assert(ids.size() >= 1);
|
assert(ids.size() >= 1);
|
||||||
auto op{std::make_unique<Op>(spv::Op::OpCompositeConstruct, bound++,
|
auto op{std::make_unique<Op>(spv::Op::OpCompositeConstruct, bound++, result_type)};
|
||||||
result_type)};
|
|
||||||
op->Add(ids);
|
op->Add(ids);
|
||||||
return AddCode(std::move(op));
|
return AddCode(std::move(op));
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
* Lesser General Public License version 3 or any later version.
|
* Lesser General Public License version 3 or any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include "op.h"
|
#include "op.h"
|
||||||
#include "sirit/sirit.h"
|
#include "sirit/sirit.h"
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
* Lesser General Public License version 3 or any later version.
|
* Lesser General Public License version 3 or any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include "op.h"
|
#include "op.h"
|
||||||
|
@ -63,9 +63,9 @@ Id Module::OpTypeMatrix(Id column_type, int column_count) {
|
||||||
return AddDeclaration(std::move(op));
|
return AddDeclaration(std::move(op));
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Module::OpTypeImage(Id sampled_type, spv::Dim dim, int depth, bool arrayed,
|
Id Module::OpTypeImage(Id sampled_type, spv::Dim dim, int depth, bool arrayed, bool ms, int sampled,
|
||||||
bool ms, int sampled, spv::ImageFormat image_format,
|
spv::ImageFormat image_format,
|
||||||
std::optional<spv::AccessQualifier> access_qualifier) {
|
std::optional<spv::AccessQualifier> access_qualifier) {
|
||||||
switch (dim) {
|
switch (dim) {
|
||||||
case spv::Dim::Dim1D:
|
case spv::Dim::Dim1D:
|
||||||
AddCapability(spv::Capability::Sampled1D);
|
AddCapability(spv::Capability::Sampled1D);
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
* Lesser General Public License version 3 or any later version.
|
* Lesser General Public License version 3 or any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "literal_number.h"
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include "literal_number.h"
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
|
@ -23,7 +23,9 @@ void LiteralNumber::Fetch(Stream& stream) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 LiteralNumber::GetWordCount() const { return is_32 ? 1 : 2; }
|
u16 LiteralNumber::GetWordCount() const {
|
||||||
|
return is_32 ? 1 : 2;
|
||||||
|
}
|
||||||
|
|
||||||
bool LiteralNumber::operator==(const Operand& other) const {
|
bool LiteralNumber::operator==(const Operand& other) const {
|
||||||
if (operand_type == other.GetType()) {
|
if (operand_type == other.GetType()) {
|
||||||
|
|
|
@ -6,15 +6,15 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "operand.h"
|
|
||||||
#include "stream.h"
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <typeindex>
|
#include <typeindex>
|
||||||
|
#include "operand.h"
|
||||||
|
#include "stream.h"
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
class LiteralNumber : public Operand {
|
class LiteralNumber : public Operand {
|
||||||
public:
|
public:
|
||||||
LiteralNumber(std::type_index type);
|
LiteralNumber(std::type_index type);
|
||||||
~LiteralNumber();
|
~LiteralNumber();
|
||||||
|
|
||||||
|
@ -23,7 +23,8 @@ class LiteralNumber : public Operand {
|
||||||
|
|
||||||
virtual bool operator==(const Operand& other) const;
|
virtual bool operator==(const Operand& other) const;
|
||||||
|
|
||||||
template <typename T> static LiteralNumber* Create(T value) {
|
template <typename T>
|
||||||
|
static LiteralNumber* Create(T value) {
|
||||||
static_assert(sizeof(T) == 4 || sizeof(T) == 8);
|
static_assert(sizeof(T) == 4 || sizeof(T) == 8);
|
||||||
|
|
||||||
LiteralNumber* number = new LiteralNumber(std::type_index(typeid(T)));
|
LiteralNumber* number = new LiteralNumber(std::type_index(typeid(T)));
|
||||||
|
@ -32,7 +33,7 @@ class LiteralNumber : public Operand {
|
||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::type_index type;
|
std::type_index type;
|
||||||
bool is_32{};
|
bool is_32{};
|
||||||
u64 raw{};
|
u64 raw{};
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
* Lesser General Public License version 3 or any later version.
|
* Lesser General Public License version 3 or any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "literal_string.h"
|
|
||||||
#include "common_types.h"
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "common_types.h"
|
||||||
|
#include "literal_string.h"
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,14 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include "operand.h"
|
#include "operand.h"
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
class LiteralString : public Operand {
|
class LiteralString : public Operand {
|
||||||
public:
|
public:
|
||||||
LiteralString(const std::string& string);
|
LiteralString(const std::string& string);
|
||||||
~LiteralString();
|
~LiteralString();
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ class LiteralString : public Operand {
|
||||||
|
|
||||||
virtual bool operator==(const Operand& other) const;
|
virtual bool operator==(const Operand& other) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string string;
|
const std::string string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
16
src/op.cpp
16
src/op.cpp
|
@ -26,7 +26,9 @@ void Op::Fetch(Stream& stream) const {
|
||||||
stream.Write(id.value());
|
stream.Write(id.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 Op::GetWordCount() const { return 1; }
|
u16 Op::GetWordCount() const {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
bool Op::operator==(const Operand& other) const {
|
bool Op::operator==(const Operand& other) const {
|
||||||
if (operand_type != other.GetType()) {
|
if (operand_type != other.GetType()) {
|
||||||
|
@ -100,11 +102,17 @@ void Op::Add(const std::vector<Literal>& literals) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Op::Add(const Operand* operand) { operands.push_back(operand); }
|
void Op::Add(const Operand* operand) {
|
||||||
|
operands.push_back(operand);
|
||||||
|
}
|
||||||
|
|
||||||
void Op::Add(u32 integer) { Sink(LiteralNumber::Create<u32>(integer)); }
|
void Op::Add(u32 integer) {
|
||||||
|
Sink(LiteralNumber::Create<u32>(integer));
|
||||||
|
}
|
||||||
|
|
||||||
void Op::Add(const std::string& string) { Sink(new LiteralString(string)); }
|
void Op::Add(const std::string& string) {
|
||||||
|
Sink(new LiteralString(string));
|
||||||
|
}
|
||||||
|
|
||||||
void Op::Add(const std::vector<Id>& ids) {
|
void Op::Add(const std::vector<Id>& ids) {
|
||||||
for (Id op : ids) {
|
for (Id op : ids) {
|
||||||
|
|
9
src/op.h
9
src/op.h
|
@ -6,18 +6,17 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
#include "common_types.h"
|
#include "common_types.h"
|
||||||
#include "operand.h"
|
#include "operand.h"
|
||||||
#include "sirit/sirit.h"
|
#include "sirit/sirit.h"
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
#include <optional>
|
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
class Op : public Operand {
|
class Op : public Operand {
|
||||||
public:
|
public:
|
||||||
explicit Op(spv::Op opcode, std::optional<u32> id = {},
|
explicit Op(spv::Op opcode, std::optional<u32> id = {}, Id result_type = nullptr);
|
||||||
Id result_type = nullptr);
|
|
||||||
~Op();
|
~Op();
|
||||||
|
|
||||||
virtual void Fetch(Stream& stream) const;
|
virtual void Fetch(Stream& stream) const;
|
||||||
|
@ -43,7 +42,7 @@ class Op : public Operand {
|
||||||
|
|
||||||
void Add(const std::vector<Id>& ids);
|
void Add(const std::vector<Id>& ids);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
u16 WordCount() const;
|
u16 WordCount() const;
|
||||||
|
|
||||||
spv::Op opcode;
|
spv::Op opcode;
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
* Lesser General Public License version 3 or any later version.
|
* Lesser General Public License version 3 or any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "operand.h"
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include "operand.h"
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
|
@ -22,12 +22,16 @@ u16 Operand::GetWordCount() const {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Operand::operator==(const Operand& other) const { return false; }
|
bool Operand::operator==(const Operand& other) const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool Operand::operator!=(const Operand& other) const {
|
bool Operand::operator!=(const Operand& other) const {
|
||||||
return !(*this == other);
|
return !(*this == other);
|
||||||
}
|
}
|
||||||
|
|
||||||
OperandType Operand::GetType() const { return operand_type; }
|
OperandType Operand::GetType() const {
|
||||||
|
return operand_type;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Sirit
|
} // namespace Sirit
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace Sirit {
|
||||||
enum class OperandType { Invalid, Op, Number, String };
|
enum class OperandType { Invalid, Op, Number, String };
|
||||||
|
|
||||||
class Operand {
|
class Operand {
|
||||||
public:
|
public:
|
||||||
Operand();
|
Operand();
|
||||||
virtual ~Operand();
|
virtual ~Operand();
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class Operand {
|
||||||
|
|
||||||
OperandType GetType() const;
|
OperandType GetType() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
OperandType operand_type{};
|
OperandType operand_type{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,16 +4,17 @@
|
||||||
* Lesser General Public License version 3 or any later version.
|
* Lesser General Public License version 3 or any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sirit/sirit.h"
|
|
||||||
#include "common_types.h"
|
|
||||||
#include "op.h"
|
|
||||||
#include "stream.h"
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include "common_types.h"
|
||||||
|
#include "op.h"
|
||||||
|
#include "sirit/sirit.h"
|
||||||
|
#include "stream.h"
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
template <typename T> static void WriteSet(Stream& stream, const T& set) {
|
template <typename T>
|
||||||
|
static void WriteSet(Stream& stream, const T& set) {
|
||||||
for (const auto& item : set) {
|
for (const auto& item : set) {
|
||||||
item->Write(stream);
|
item->Write(stream);
|
||||||
}
|
}
|
||||||
|
@ -73,15 +74,13 @@ void Module::AddCapability(spv::Capability capability) {
|
||||||
capabilities.insert(capability);
|
capabilities.insert(capability);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::SetMemoryModel(spv::AddressingModel addressing_model,
|
void Module::SetMemoryModel(spv::AddressingModel addressing_model, spv::MemoryModel memory_model) {
|
||||||
spv::MemoryModel memory_model) {
|
|
||||||
this->addressing_model = addressing_model;
|
this->addressing_model = addressing_model;
|
||||||
this->memory_model = memory_model;
|
this->memory_model = memory_model;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::AddEntryPoint(spv::ExecutionModel execution_model, Id entry_point,
|
void Module::AddEntryPoint(spv::ExecutionModel execution_model, Id entry_point,
|
||||||
const std::string& name,
|
const std::string& name, const std::vector<Id>& interfaces) {
|
||||||
const std::vector<Id>& interfaces) {
|
|
||||||
auto op{std::make_unique<Op>(spv::Op::OpEntryPoint)};
|
auto op{std::make_unique<Op>(spv::Op::OpEntryPoint)};
|
||||||
op->Add(static_cast<u32>(execution_model));
|
op->Add(static_cast<u32>(execution_model));
|
||||||
op->Add(entry_point);
|
op->Add(entry_point);
|
||||||
|
@ -91,7 +90,7 @@ void Module::AddEntryPoint(spv::ExecutionModel execution_model, Id entry_point,
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::AddExecutionMode(Id entry_point, spv::ExecutionMode mode,
|
void Module::AddExecutionMode(Id entry_point, spv::ExecutionMode mode,
|
||||||
const std::vector<Literal>& literals) {
|
const std::vector<Literal>& literals) {
|
||||||
auto op{std::make_unique<Op>(spv::Op::OpExecutionMode)};
|
auto op{std::make_unique<Op>(spv::Op::OpExecutionMode)};
|
||||||
op->Add(entry_point);
|
op->Add(entry_point);
|
||||||
op->Add(static_cast<u32>(mode));
|
op->Add(static_cast<u32>(mode));
|
||||||
|
@ -121,9 +120,8 @@ Id Module::AddCode(spv::Op opcode, std::optional<u32> id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Module::AddDeclaration(std::unique_ptr<Op> op) {
|
Id Module::AddDeclaration(std::unique_ptr<Op> op) {
|
||||||
const auto& found{
|
const auto& found{std::find_if(declarations.begin(), declarations.end(),
|
||||||
std::find_if(declarations.begin(), declarations.end(),
|
[&op](const auto& other) { return *other == *op; })};
|
||||||
[&op](const auto& other) { return *other == *op; })};
|
|
||||||
if (found != declarations.end()) {
|
if (found != declarations.end()) {
|
||||||
return found->get();
|
return found->get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,8 @@ void Stream::Write(u16 value) {
|
||||||
Write(mem[1]);
|
Write(mem[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stream::Write(u8 value) { bytes.push_back(value); }
|
void Stream::Write(u8 value) {
|
||||||
|
bytes.push_back(value);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Sirit
|
} // namespace Sirit
|
||||||
|
|
|
@ -6,14 +6,14 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "common_types.h"
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "common_types.h"
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
class Stream {
|
class Stream {
|
||||||
public:
|
public:
|
||||||
explicit Stream(std::vector<u8>& bytes);
|
explicit Stream(std::vector<u8>& bytes);
|
||||||
~Stream();
|
~Stream();
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class Stream {
|
||||||
|
|
||||||
void Write(u8 value);
|
void Write(u8 value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<u8>& bytes;
|
std::vector<u8>& bytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue