Add Op* prefix to instructions that have to be emited

This commit is contained in:
ReinUsesLisp 2018-10-31 21:22:00 -03:00
parent ba3a3a74d7
commit a08aeec982
15 changed files with 149 additions and 144 deletions

View File

@ -68,154 +68,154 @@ class Module {
// Types // Types
/// Returns type void. /// Returns type void.
Ref TypeVoid(); Ref OpTypeVoid();
/// Returns type bool. /// Returns type bool.
Ref TypeBool(); Ref OpTypeBool();
/// Returns type integer. /// Returns type integer.
Ref TypeInt(int width, bool is_signed); Ref OpTypeInt(int width, bool is_signed);
/// Returns type float. /// Returns type float.
Ref TypeFloat(int width); Ref OpTypeFloat(int width);
/// Returns type vector. /// Returns type vector.
Ref TypeVector(Ref component_type, int component_count); Ref OpTypeVector(Ref component_type, int component_count);
/// Returns type matrix. /// Returns type matrix.
Ref TypeMatrix(Ref column_type, int column_count); Ref OpTypeMatrix(Ref column_type, int column_count);
/// Returns type image. /// Returns type image.
Ref TypeImage(Ref sampled_type, spv::Dim dim, int depth, bool arrayed, Ref OpTypeImage(Ref sampled_type, spv::Dim dim, int depth, bool arrayed,
bool ms, int sampled, spv::ImageFormat image_format, bool ms, int sampled, spv::ImageFormat image_format,
std::optional<spv::AccessQualifier> access_qualifier = {}); std::optional<spv::AccessQualifier> access_qualifier = {});
/// Returns type sampler. /// Returns type sampler.
Ref TypeSampler(); Ref OpTypeSampler();
/// Returns type sampled image. /// Returns type sampled image.
Ref TypeSampledImage(Ref image_type); Ref OpTypeSampledImage(Ref image_type);
/// Returns type array. /// Returns type array.
Ref TypeArray(Ref element_type, Ref length); Ref OpTypeArray(Ref element_type, Ref length);
/// Returns type runtime array. /// Returns type runtime array.
Ref TypeRuntimeArray(Ref element_type); Ref OpTypeRuntimeArray(Ref element_type);
/// Returns type struct. /// Returns type struct.
Ref TypeStruct(const std::vector<Ref>& members = {}); Ref OpTypeStruct(const std::vector<Ref>& members = {});
/// Returns type opaque. /// Returns type opaque.
Ref TypeOpaque(const std::string& name); Ref OpTypeOpaque(const std::string& name);
/// Returns type pointer. /// Returns type pointer.
Ref TypePointer(spv::StorageClass storage_class, Ref type); Ref OpTypePointer(spv::StorageClass storage_class, Ref type);
/// Returns type function. /// Returns type function.
Ref TypeFunction(Ref return_type, const std::vector<Ref>& arguments = {}); Ref OpTypeFunction(Ref return_type, const std::vector<Ref>& arguments = {});
/// Returns type event. /// Returns type event.
Ref TypeEvent(); Ref OpTypeEvent();
/// Returns type device event. /// Returns type device event.
Ref TypeDeviceEvent(); Ref OpTypeDeviceEvent();
/// Returns type reserve id. /// Returns type reserve id.
Ref TypeReserveId(); Ref OpTypeReserveId();
/// Returns type queue. /// Returns type queue.
Ref TypeQueue(); Ref OpTypeQueue();
/// Returns type pipe. /// Returns type pipe.
Ref TypePipe(spv::AccessQualifier access_qualifier); Ref OpTypePipe(spv::AccessQualifier access_qualifier);
// Constant // Constant
/// Returns a true scalar constant. /// Returns a true scalar constant.
Ref ConstantTrue(Ref result_type); Ref OpConstantTrue(Ref result_type);
/// Returns a false scalar constant. /// Returns a false scalar constant.
Ref ConstantFalse(Ref result_type); Ref OpConstantFalse(Ref result_type);
/// Returns a numeric scalar constant. /// Returns a numeric scalar constant.
Ref Constant(Ref result_type, const Literal& literal); Ref OpConstant(Ref result_type, const Literal& literal);
/// Returns a numeric scalar constant. /// Returns a numeric scalar constant.
Ref ConstantComposite(Ref result_type, Ref OpConstantComposite(Ref result_type,
const std::vector<Ref>& constituents); const std::vector<Ref>& constituents);
/// Returns a sampler constant. /// Returns a sampler constant.
Ref ConstantSampler(Ref result_type, Ref OpConstantSampler(Ref result_type,
spv::SamplerAddressingMode addressing_mode, spv::SamplerAddressingMode addressing_mode,
bool normalized, spv::SamplerFilterMode filter_mode); bool normalized, spv::SamplerFilterMode filter_mode);
/// Returns a null constant value. /// Returns a null constant value.
Ref ConstantNull(Ref result_type); Ref OpConstantNull(Ref result_type);
// Function // Function
/// Declares a function. /// Declares a function.
Ref Function(Ref result_type, spv::FunctionControlMask function_control, Ref OpFunction(Ref result_type, spv::FunctionControlMask function_control,
Ref function_type); Ref function_type);
/// Ends a function. /// Ends a function.
Ref FunctionEnd(); Ref OpFunctionEnd();
// Flow // Flow
/// Declare a structured loop. /// Declare a structured loop.
Ref LoopMerge(Ref merge_block, Ref continue_target, Ref OpLoopMerge(Ref merge_block, Ref continue_target,
spv::LoopControlMask loop_control, spv::LoopControlMask loop_control,
const std::vector<Ref>& literals = {}); const std::vector<Ref>& literals = {});
/// Declare a structured selection. /// Declare a structured selection.
Ref SelectionMerge(Ref merge_block, Ref OpSelectionMerge(Ref 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.
Ref Label(); Ref OpLabel();
/// Unconditional jump to label. /// Unconditional jump to label.
Ref Branch(Ref target_label); Ref OpBranch(Ref target_label);
/// 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.
Ref BranchConditional(Ref condition, Ref true_label, Ref false_label, Ref OpBranchConditional(Ref condition, Ref true_label, Ref 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);
/// Returns with no value from a function with void return type. /// Returns with no value from a function with void return type.
Ref Return(); Ref OpReturn();
// Debug // Debug
/// Assign a name string to a reference. /// Assign a name string to a reference.
/// @return target /// @return target
Ref Name(Ref target, const std::string& name); Ref OpName(Ref target, const std::string& name);
// Memory // Memory
/// Allocate an object in memory, resulting in a copy to it. /// Allocate an object in memory, resulting in a copy to it.
Ref Variable(Ref result_type, spv::StorageClass storage_class, Ref OpVariable(Ref result_type, spv::StorageClass storage_class,
Ref initializer = nullptr); Ref initializer = nullptr);
/// Load through a pointer. /// Load through a pointer.
Ref Load(Ref result_type, Ref pointer, Ref OpLoad(Ref result_type, Ref pointer,
std::optional<spv::MemoryAccessMask> memory_access = {}); std::optional<spv::MemoryAccessMask> memory_access = {});
/// Store through a pointer. /// Store through a pointer.
Ref Store(Ref pointer, Ref object, Ref OpStore(Ref pointer, Ref 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.
Ref AccessChain(Ref result_type, Ref base, Ref OpAccessChain(Ref result_type, Ref base,
const std::vector<Ref>& indexes = {}); const std::vector<Ref>& 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.
Ref CompositeInsert(Ref result_type, Ref object, Ref composite, Ref OpCompositeInsert(Ref result_type, Ref object, Ref composite,
const std::vector<Literal>& indexes = {}); const std::vector<Literal>& indexes = {});
// Annotation // Annotation
@ -230,7 +230,7 @@ class Module {
// Misc // Misc
/// Make an intermediate object whose value is undefined. /// Make an intermediate object whose value is undefined.
Ref Undef(Ref result_type); Ref OpUndef(Ref result_type);
private: private:
Ref AddCode(Op* op); Ref AddCode(Op* op);

View File

@ -7,10 +7,10 @@ add_library(sirit
stream.h stream.h
operand.cpp operand.cpp
operand.h operand.h
literal-number.cpp literal_number.cpp
literal-number.h literal_number.h
literal-string.cpp literal_string.cpp
literal-string.h literal_string.h
common_types.h common_types.h
insts.h insts.h
insts/type.cpp insts/type.cpp

View File

@ -10,31 +10,31 @@
namespace Sirit { namespace Sirit {
Ref Module::ConstantTrue(Ref result_type) { Ref Module::OpConstantTrue(Ref result_type) {
return AddDeclaration(new Op(spv::Op::OpConstantTrue, bound, result_type)); return AddDeclaration(new Op(spv::Op::OpConstantTrue, bound, result_type));
} }
Ref Module::ConstantFalse(Ref result_type) { Ref Module::OpConstantFalse(Ref result_type) {
return AddDeclaration(new Op(spv::Op::OpConstantFalse, bound, result_type)); return AddDeclaration(new Op(spv::Op::OpConstantFalse, bound, result_type));
} }
Ref Module::Constant(Ref result_type, const Literal& literal) { Ref Module::OpConstant(Ref result_type, const Literal& literal) {
auto op{new Op(spv::Op::OpConstant, bound, result_type)}; auto op{new Op(spv::Op::OpConstant, bound, result_type)};
op->Add(literal); op->Add(literal);
return AddDeclaration(op); return AddDeclaration(op);
} }
Ref Module::ConstantComposite(Ref result_type, Ref Module::OpConstantComposite(Ref result_type,
const std::vector<Ref>& constituents) { const std::vector<Ref>& constituents) {
auto op{new Op(spv::Op::OpConstantComposite, bound, result_type)}; auto op{new Op(spv::Op::OpConstantComposite, bound, result_type)};
op->Add(constituents); op->Add(constituents);
return AddDeclaration(op); return AddDeclaration(op);
} }
Ref Module::ConstantSampler(Ref result_type, Ref Module::OpConstantSampler(Ref result_type,
spv::SamplerAddressingMode addressing_mode, spv::SamplerAddressingMode addressing_mode,
bool normalized, bool normalized,
spv::SamplerFilterMode filter_mode) { spv::SamplerFilterMode filter_mode) {
AddCapability(spv::Capability::LiteralSampler); AddCapability(spv::Capability::LiteralSampler);
AddCapability(spv::Capability::Kernel); AddCapability(spv::Capability::Kernel);
auto op{new Op(spv::Op::OpConstantSampler, bound, result_type)}; auto op{new Op(spv::Op::OpConstantSampler, bound, result_type)};
@ -44,7 +44,7 @@ Ref Module::ConstantSampler(Ref result_type,
return AddDeclaration(op); return AddDeclaration(op);
} }
Ref Module::ConstantNull(Ref result_type) { Ref Module::OpConstantNull(Ref result_type) {
return AddDeclaration(new Op(spv::Op::OpConstantNull, bound, result_type)); return AddDeclaration(new Op(spv::Op::OpConstantNull, bound, result_type));
} }

View File

@ -9,7 +9,7 @@
namespace Sirit { namespace Sirit {
Ref Module::Name(Ref target, const std::string& name) { Ref Module::OpName(Ref target, const std::string& name) {
auto op{new Op(spv::Op::OpName)}; auto op{new Op(spv::Op::OpName)};
op->Add(target); op->Add(target);
op->Add(name); op->Add(name);

View File

@ -9,9 +9,9 @@
namespace Sirit { namespace Sirit {
Ref Module::LoopMerge(Ref merge_block, Ref continue_target, Ref Module::OpLoopMerge(Ref merge_block, Ref continue_target,
spv::LoopControlMask loop_control, spv::LoopControlMask loop_control,
const std::vector<Ref>& literals) { const std::vector<Ref>& literals) {
auto op{new Op(spv::Op::OpLoopMerge)}; auto op{new Op(spv::Op::OpLoopMerge)};
op->Add(merge_block); op->Add(merge_block);
op->Add(continue_target); op->Add(continue_target);
@ -20,25 +20,25 @@ Ref Module::LoopMerge(Ref merge_block, Ref continue_target,
return AddCode(op); return AddCode(op);
} }
Ref Module::SelectionMerge(Ref merge_block, Ref Module::OpSelectionMerge(Ref merge_block,
spv::SelectionControlMask selection_control) { spv::SelectionControlMask selection_control) {
auto op{new Op(spv::Op::OpSelectionMerge)}; auto op{new Op(spv::Op::OpSelectionMerge)};
op->Add(merge_block); op->Add(merge_block);
AddEnum(op, selection_control); AddEnum(op, selection_control);
return AddCode(op); return AddCode(op);
} }
Ref Module::Label() { return AddCode(spv::Op::OpLabel, bound++); } Ref Module::OpLabel() { return AddCode(spv::Op::OpLabel, bound++); }
Ref Module::Branch(Ref target_label) { Ref Module::OpBranch(Ref target_label) {
auto op{new Op(spv::Op::OpBranch)}; auto op{new Op(spv::Op::OpBranch)};
op->Add(target_label); op->Add(target_label);
return AddCode(op); return AddCode(op);
} }
Ref Module::BranchConditional(Ref condition, Ref true_label, Ref false_label, Ref Module::OpBranchConditional(Ref condition, Ref true_label, Ref false_label,
std::uint32_t true_weight, std::uint32_t true_weight,
std::uint32_t false_weight) { std::uint32_t false_weight) {
auto op{new Op(spv::Op::OpBranchConditional)}; auto op{new Op(spv::Op::OpBranchConditional)};
op->Add(condition); op->Add(condition);
op->Add(true_label); op->Add(true_label);
@ -50,6 +50,6 @@ Ref Module::BranchConditional(Ref condition, Ref true_label, Ref false_label,
return AddCode(op); return AddCode(op);
} }
Ref Module::Return() { return AddCode(spv::Op::OpReturn); } Ref Module::OpReturn() { return AddCode(spv::Op::OpReturn); }
} // namespace Sirit } // namespace Sirit

View File

@ -9,14 +9,15 @@
namespace Sirit { namespace Sirit {
Ref Module::Function(Ref result_type, spv::FunctionControlMask function_control, Ref Module::OpFunction(Ref result_type,
Ref function_type) { spv::FunctionControlMask function_control,
Ref function_type) {
auto op{new Op{spv::Op::OpFunction, bound++, result_type}}; auto op{new 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(op); return AddCode(op);
} }
Ref Module::FunctionEnd() { return AddCode(spv::Op::OpFunctionEnd); } Ref Module::OpFunctionEnd() { return AddCode(spv::Op::OpFunctionEnd); }
} // namespace Sirit } // namespace Sirit

View File

@ -10,8 +10,8 @@
namespace Sirit { namespace Sirit {
Ref Module::Variable(Ref result_type, spv::StorageClass storage_class, Ref Module::OpVariable(Ref result_type, spv::StorageClass storage_class,
Ref initializer) { Ref initializer) {
auto op{new Op(spv::Op::OpVariable, bound++, result_type)}; auto op{new Op(spv::Op::OpVariable, bound++, result_type)};
AddEnum(op, storage_class); AddEnum(op, storage_class);
if (initializer) { if (initializer) {
@ -20,8 +20,8 @@ Ref Module::Variable(Ref result_type, spv::StorageClass storage_class,
return AddCode(op); return AddCode(op);
} }
Ref Module::Load(Ref result_type, Ref pointer, Ref Module::OpLoad(Ref result_type, Ref pointer,
std::optional<spv::MemoryAccessMask> memory_access) { std::optional<spv::MemoryAccessMask> memory_access) {
auto op{new Op(spv::Op::OpLoad, bound++, result_type)}; auto op{new Op(spv::Op::OpLoad, bound++, result_type)};
op->Add(pointer); op->Add(pointer);
if (memory_access) { if (memory_access) {
@ -30,8 +30,8 @@ Ref Module::Load(Ref result_type, Ref pointer,
return AddCode(op); return AddCode(op);
} }
Ref Module::Store(Ref pointer, Ref object, Ref Module::OpStore(Ref pointer, Ref object,
std::optional<spv::MemoryAccessMask> memory_access) { std::optional<spv::MemoryAccessMask> memory_access) {
auto op{new Op(spv::Op::OpStore)}; auto op{new Op(spv::Op::OpStore)};
op->Add(pointer); op->Add(pointer);
op->Add(object); op->Add(object);
@ -41,8 +41,8 @@ Ref Module::Store(Ref pointer, Ref object,
return AddCode(op); return AddCode(op);
} }
Ref Module::AccessChain(Ref result_type, Ref base, Ref Module::OpAccessChain(Ref result_type, Ref base,
const std::vector<Ref>& indexes) { const std::vector<Ref>& indexes) {
assert(indexes.size() > 0); assert(indexes.size() > 0);
auto op{new Op(spv::Op::OpAccessChain, bound++, result_type)}; auto op{new Op(spv::Op::OpAccessChain, bound++, result_type)};
op->Add(base); op->Add(base);
@ -50,8 +50,8 @@ Ref Module::AccessChain(Ref result_type, Ref base,
return AddCode(op); return AddCode(op);
} }
Ref Module::CompositeInsert(Ref result_type, Ref object, Ref composite, Ref Module::OpCompositeInsert(Ref result_type, Ref object, Ref composite,
const std::vector<Literal>& indexes) { const std::vector<Literal>& indexes) {
auto op{new Op(spv::Op::OpCompositeInsert, bound++, result_type)}; auto op{new Op(spv::Op::OpCompositeInsert, bound++, result_type)};
op->Add(object); op->Add(object);
op->Add(composite); op->Add(composite);

View File

@ -10,7 +10,7 @@
namespace Sirit { namespace Sirit {
Ref Module::Undef(Ref result_type) { Ref Module::OpUndef(Ref result_type) {
return AddCode(new Op(spv::Op::OpUndef, bound++, result_type)); return AddCode(new Op(spv::Op::OpUndef, bound++, result_type));
} }

View File

@ -12,15 +12,15 @@
namespace Sirit { namespace Sirit {
Ref Module::TypeVoid() { Ref Module::OpTypeVoid() {
return AddDeclaration(new Op(spv::Op::OpTypeVoid, bound)); return AddDeclaration(new Op(spv::Op::OpTypeVoid, bound));
} }
Ref Module::TypeBool() { Ref Module::OpTypeBool() {
return AddDeclaration(new Op(spv::Op::OpTypeBool, bound)); return AddDeclaration(new Op(spv::Op::OpTypeBool, bound));
} }
Ref Module::TypeInt(int width, bool is_signed) { Ref Module::OpTypeInt(int width, bool is_signed) {
if (width == 8) { if (width == 8) {
AddCapability(spv::Capability::Int8); AddCapability(spv::Capability::Int8);
} else if (width == 16) { } else if (width == 16) {
@ -34,7 +34,7 @@ Ref Module::TypeInt(int width, bool is_signed) {
return AddDeclaration(op); return AddDeclaration(op);
} }
Ref Module::TypeFloat(int width) { Ref Module::OpTypeFloat(int width) {
if (width == 16) { if (width == 16) {
AddCapability(spv::Capability::Float16); AddCapability(spv::Capability::Float16);
} else if (width == 64) { } else if (width == 64) {
@ -45,7 +45,7 @@ Ref Module::TypeFloat(int width) {
return AddDeclaration(op); return AddDeclaration(op);
} }
Ref Module::TypeVector(Ref component_type, int component_count) { Ref Module::OpTypeVector(Ref component_type, int component_count) {
assert(component_count >= 2); assert(component_count >= 2);
auto op{new Op(spv::Op::OpTypeVector, bound)}; auto op{new Op(spv::Op::OpTypeVector, bound)};
op->Add(component_type); op->Add(component_type);
@ -53,7 +53,7 @@ Ref Module::TypeVector(Ref component_type, int component_count) {
return AddDeclaration(op); return AddDeclaration(op);
} }
Ref Module::TypeMatrix(Ref column_type, int column_count) { Ref Module::OpTypeMatrix(Ref column_type, int column_count) {
assert(column_count >= 2); assert(column_count >= 2);
AddCapability(spv::Capability::Matrix); AddCapability(spv::Capability::Matrix);
Op* op{new Op(spv::Op::OpTypeMatrix, bound)}; Op* op{new Op(spv::Op::OpTypeMatrix, bound)};
@ -62,9 +62,9 @@ Ref Module::TypeMatrix(Ref column_type, int column_count) {
return AddDeclaration(op); return AddDeclaration(op);
} }
Ref Module::TypeImage(Ref sampled_type, spv::Dim dim, int depth, bool arrayed, Ref Module::OpTypeImage(Ref sampled_type, spv::Dim dim, int depth, bool arrayed,
bool ms, int sampled, spv::ImageFormat image_format, bool ms, int sampled, 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);
@ -140,44 +140,44 @@ Ref Module::TypeImage(Ref sampled_type, spv::Dim dim, int depth, bool arrayed,
return AddDeclaration(op); return AddDeclaration(op);
} }
Ref Module::TypeSampler() { Ref Module::OpTypeSampler() {
return AddDeclaration(new Op(spv::Op::OpTypeSampler, bound)); return AddDeclaration(new Op(spv::Op::OpTypeSampler, bound));
} }
Ref Module::TypeSampledImage(Ref image_type) { Ref Module::OpTypeSampledImage(Ref image_type) {
auto op{new Op(spv::Op::OpTypeSampledImage, bound)}; auto op{new Op(spv::Op::OpTypeSampledImage, bound)};
op->Add(image_type); op->Add(image_type);
return AddDeclaration(op); return AddDeclaration(op);
} }
Ref Module::TypeArray(Ref element_type, Ref length) { Ref Module::OpTypeArray(Ref element_type, Ref length) {
auto op{new Op(spv::Op::OpTypeArray, bound)}; auto op{new Op(spv::Op::OpTypeArray, bound)};
op->Add(element_type); op->Add(element_type);
op->Add(length); op->Add(length);
return AddDeclaration(op); return AddDeclaration(op);
} }
Ref Module::TypeRuntimeArray(Ref element_type) { Ref Module::OpTypeRuntimeArray(Ref element_type) {
AddCapability(spv::Capability::Shader); AddCapability(spv::Capability::Shader);
auto op{new Op(spv::Op::OpTypeRuntimeArray, bound)}; auto op{new Op(spv::Op::OpTypeRuntimeArray, bound)};
op->Add(element_type); op->Add(element_type);
return AddDeclaration(op); return AddDeclaration(op);
} }
Ref Module::TypeStruct(const std::vector<Ref>& members) { Ref Module::OpTypeStruct(const std::vector<Ref>& members) {
auto op{new Op(spv::Op::OpTypeStruct, bound)}; auto op{new Op(spv::Op::OpTypeStruct, bound)};
op->Add(members); op->Add(members);
return AddDeclaration(op); return AddDeclaration(op);
} }
Ref Module::TypeOpaque(const std::string& name) { Ref Module::OpTypeOpaque(const std::string& name) {
AddCapability(spv::Capability::Kernel); AddCapability(spv::Capability::Kernel);
auto op{new Op(spv::Op::OpTypeOpaque, bound)}; auto op{new Op(spv::Op::OpTypeOpaque, bound)};
op->Add(name); op->Add(name);
return AddDeclaration(op); return AddDeclaration(op);
} }
Ref Module::TypePointer(spv::StorageClass storage_class, Ref type) { Ref Module::OpTypePointer(spv::StorageClass storage_class, Ref type) {
switch (storage_class) { switch (storage_class) {
case spv::StorageClass::Uniform: case spv::StorageClass::Uniform:
case spv::StorageClass::Output: case spv::StorageClass::Output:
@ -199,34 +199,34 @@ Ref Module::TypePointer(spv::StorageClass storage_class, Ref type) {
return AddDeclaration(op); return AddDeclaration(op);
} }
Ref Module::TypeFunction(Ref return_type, const std::vector<Ref>& arguments) { Ref Module::OpTypeFunction(Ref return_type, const std::vector<Ref>& arguments) {
auto op{new Op(spv::Op::OpTypeFunction, bound)}; auto op{new Op(spv::Op::OpTypeFunction, bound)};
op->Add(return_type); op->Add(return_type);
op->Add(arguments); op->Add(arguments);
return AddDeclaration(op); return AddDeclaration(op);
} }
Ref Module::TypeEvent() { Ref Module::OpTypeEvent() {
AddCapability(spv::Capability::Kernel); AddCapability(spv::Capability::Kernel);
return AddDeclaration(new Op(spv::Op::OpTypeEvent, bound)); return AddDeclaration(new Op(spv::Op::OpTypeEvent, bound));
} }
Ref Module::TypeDeviceEvent() { Ref Module::OpTypeDeviceEvent() {
AddCapability(spv::Capability::DeviceEnqueue); AddCapability(spv::Capability::DeviceEnqueue);
return AddDeclaration(new Op(spv::Op::OpTypeDeviceEvent, bound)); return AddDeclaration(new Op(spv::Op::OpTypeDeviceEvent, bound));
} }
Ref Module::TypeReserveId() { Ref Module::OpTypeReserveId() {
AddCapability(spv::Capability::Pipes); AddCapability(spv::Capability::Pipes);
return AddDeclaration(new Op(spv::Op::OpTypeReserveId, bound)); return AddDeclaration(new Op(spv::Op::OpTypeReserveId, bound));
} }
Ref Module::TypeQueue() { Ref Module::OpTypeQueue() {
AddCapability(spv::Capability::DeviceEnqueue); AddCapability(spv::Capability::DeviceEnqueue);
return AddDeclaration(new Op(spv::Op::OpTypeQueue, bound)); return AddDeclaration(new Op(spv::Op::OpTypeQueue, bound));
} }
Ref Module::TypePipe(spv::AccessQualifier access_qualifier) { Ref Module::OpTypePipe(spv::AccessQualifier access_qualifier) {
AddCapability(spv::Capability::Pipes); AddCapability(spv::Capability::Pipes);
auto op{new Op(spv::Op::OpTypePipe, bound)}; auto op{new Op(spv::Op::OpTypePipe, bound)};
op->Add(static_cast<u32>(access_qualifier)); op->Add(static_cast<u32>(access_qualifier));

View File

@ -4,7 +4,7 @@
* Lesser General Public License version 2.1 or any later version. * Lesser General Public License version 2.1 or any later version.
*/ */
#include "literal-number.h" #include "literal_number.h"
#include <cassert> #include <cassert>
namespace Sirit { namespace Sirit {

View File

@ -24,6 +24,7 @@ class LiteralNumber : public Operand {
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)));
if (number->is_32 = sizeof(T) == 4; number->is_32) { if (number->is_32 = sizeof(T) == 4; number->is_32) {
number->raw = *reinterpret_cast<u32*>(&value); number->raw = *reinterpret_cast<u32*>(&value);
@ -34,7 +35,7 @@ class LiteralNumber : public Operand {
} }
private: private:
std::type_index type; const std::type_index type;
bool is_32; bool is_32;
u64 raw; u64 raw;
}; };

View File

@ -4,7 +4,9 @@
* Lesser General Public License version 2.1 or any later version. * Lesser General Public License version 2.1 or any later version.
*/ */
#include "literal-string.h" #include "literal_string.h"
#include "common_types.h"
#include <string>
namespace Sirit { namespace Sirit {

View File

@ -23,7 +23,7 @@ class LiteralString : public Operand {
virtual bool operator==(const Operand& other) const; virtual bool operator==(const Operand& other) const;
private: private:
std::string string; const std::string string;
}; };
} // namespace Sirit } // namespace Sirit

View File

@ -7,8 +7,8 @@
#include <cassert> #include <cassert>
#include "common_types.h" #include "common_types.h"
#include "literal-number.h" #include "literal_number.h"
#include "literal-string.h" #include "literal_string.h"
#include "op.h" #include "op.h"
#include "operand.h" #include "operand.h"
@ -88,6 +88,7 @@ void Op::Add(const Literal& literal) {
return LiteralNumber::Create(std::get<5>(literal)); return LiteralNumber::Create(std::get<5>(literal));
default: default:
assert(!"invalid literal type"); assert(!"invalid literal type");
abort();
} }
}(); }();
Sink(operand); Sink(operand);

View File

@ -19,20 +19,20 @@ public:
AddCapability(spv::Capability::Shader); AddCapability(spv::Capability::Shader);
SetMemoryModel(spv::AddressingModel::Logical, spv::MemoryModel::GLSL450); SetMemoryModel(spv::AddressingModel::Logical, spv::MemoryModel::GLSL450);
const auto t_void = Name(TypeVoid(), "void"); const auto t_void = OpName(OpTypeVoid(), "void");
const auto t_uint = Name(TypeInt(32, false), "uint"); const auto t_uint = OpName(OpTypeInt(32, false), "uint");
const auto t_float = Name(TypeFloat(32), "float"); const auto t_float = OpName(OpTypeFloat(32), "float");
const auto float4 = Name(TypeVector(t_float, 4), "float4"); const auto float4 = OpName(OpTypeVector(t_float, 4), "float4");
const auto in_float = Name(TypePointer(spv::StorageClass::Input, t_float), "in_float"); const auto in_float = OpName(OpTypePointer(spv::StorageClass::Input, t_float), "in_float");
const auto in_float4 = Name(TypePointer(spv::StorageClass::Input, float4), "in_float4"); const auto in_float4 = OpName(OpTypePointer(spv::StorageClass::Input, float4), "in_float4");
const auto out_float4 = Name(TypePointer(spv::StorageClass::Output, float4), "out_float4"); const auto out_float4 = OpName(OpTypePointer(spv::StorageClass::Output, float4), "out_float4");
const auto gl_per_vertex = Name(TypeStruct({float4}), "gl_PerVertex"); const auto gl_per_vertex = OpName(OpTypeStruct({float4}), "gl_PerVertex");
const auto gl_per_vertex_ptr = Name(TypePointer(spv::StorageClass::Output, gl_per_vertex), "out_gl_PerVertex"); const auto gl_per_vertex_ptr = OpName(OpTypePointer(spv::StorageClass::Output, gl_per_vertex), "out_gl_PerVertex");
const auto in_pos = Name(Variable(in_float4, spv::StorageClass::Input), "in_pos"); const auto in_pos = OpName(OpVariable(in_float4, spv::StorageClass::Input), "in_pos");
const auto per_vertex = Name(Variable(gl_per_vertex_ptr, spv::StorageClass::Output), "per_vertex"); const auto per_vertex = OpName(OpVariable(gl_per_vertex_ptr, spv::StorageClass::Output), "per_vertex");
Decorate(in_pos, spv::Decoration::Location, {0}); Decorate(in_pos, spv::Decoration::Location, {0});
Decorate(gl_per_vertex, spv::Decoration::Block); Decorate(gl_per_vertex, spv::Decoration::Block);
@ -41,22 +41,22 @@ public:
AddGlobalVariable(in_pos); AddGlobalVariable(in_pos);
AddGlobalVariable(per_vertex); AddGlobalVariable(per_vertex);
const auto main_func = Emit(Name(Function(t_void, spv::FunctionControlMask::MaskNone, TypeFunction(t_void)), "main")); const auto main_func = Emit(OpName(OpFunction(t_void, spv::FunctionControlMask::MaskNone, TypeFunction(t_void)), "main"));
Emit(Label()); Emit(Label());
const auto ptr_pos_x = Emit(AccessChain(in_float, in_pos, {Constant(t_uint, 0u)})); const auto ptr_pos_x = Emit(OpAccessChain(in_float, in_pos, {OpConstant(t_uint, 0u)}));
const auto ptr_pos_y = Emit(AccessChain(in_float, in_pos, {Constant(t_uint, 1u)})); const auto ptr_pos_y = Emit(OpAccessChain(in_float, in_pos, {OpConstant(t_uint, 1u)}));
const auto pos_x = Emit(Load(t_float, ptr_pos_x)); const auto pos_x = Emit(Load(t_float, ptr_pos_x));
const auto pos_y = Emit(Load(t_float, ptr_pos_y)); const auto pos_y = Emit(Load(t_float, ptr_pos_y));
auto tmp_position = Emit(Undef(float4)); auto tmp_position = Emit(Undef(float4));
tmp_position = Emit(CompositeInsert(float4, pos_x, tmp_position, {0})); tmp_position = Emit(OpCompositeInsert(float4, pos_x, tmp_position, {0}));
tmp_position = Emit(CompositeInsert(float4, pos_y, tmp_position, {1})); tmp_position = Emit(OpCompositeInsert(float4, pos_y, tmp_position, {1}));
tmp_position = Emit(CompositeInsert(float4, Constant(t_float, 0.f), tmp_position, {2})); tmp_position = Emit(OpCompositeInsert(float4, OpConstant(t_float, 0.f), tmp_position, {2}));
tmp_position = Emit(CompositeInsert(float4, Constant(t_float, 1.f), tmp_position, {3})); tmp_position = Emit(OpCompositeInsert(float4, OpConstant(t_float, 1.f), tmp_position, {3}));
const auto gl_position = Emit(AccessChain(out_float4, per_vertex, {Constant(t_uint, 0u)})); const auto gl_position = Emit(OpAccessChain(out_float4, per_vertex, {OpConstant(t_uint, 0u)}));
Emit(Store(gl_position, tmp_position)); Emit(Store(gl_position, tmp_position));
Emit(Return()); Emit(Return());