mirror of
https://git.suyu.dev/suyu/sirit.git
synced 2026-02-24 18:03:01 +00:00
Alias "const Op*" -> "Ref".
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
Op::Op(spv::Op opcode_, u32 id_, const Op* result_type_)
|
||||
Op::Op(spv::Op opcode_, u32 id_, Ref result_type_)
|
||||
: opcode(opcode_), id(id_), result_type(result_type_) {
|
||||
operand_type = OperandType::Op;
|
||||
}
|
||||
@@ -76,8 +76,8 @@ void Op::Add(const std::string& string) {
|
||||
Add(new LiteralString(string));
|
||||
}
|
||||
|
||||
void Op::Add(const std::vector<const Op*>& ids) {
|
||||
for (const Op* op : ids) {
|
||||
void Op::Add(const std::vector<Ref>& ids) {
|
||||
for (Ref op : ids) {
|
||||
Add(op);
|
||||
}
|
||||
}
|
||||
|
||||
6
src/op.h
6
src/op.h
@@ -15,7 +15,7 @@ namespace Sirit {
|
||||
|
||||
class Op : public Operand {
|
||||
public:
|
||||
explicit Op(spv::Op opcode, u32 id = UINT32_MAX, const Op* result_type = nullptr);
|
||||
explicit Op(spv::Op opcode, u32 id = UINT32_MAX, Ref result_type = nullptr);
|
||||
~Op();
|
||||
|
||||
virtual void Fetch(Stream& stream) const;
|
||||
@@ -33,14 +33,14 @@ public:
|
||||
|
||||
void Add(const std::string& string);
|
||||
|
||||
void Add(const std::vector<const Op*>& ids);
|
||||
void Add(const std::vector<Ref>& ids);
|
||||
|
||||
private:
|
||||
u16 WordCount() const;
|
||||
|
||||
spv::Op opcode;
|
||||
|
||||
const Op* result_type;
|
||||
Ref result_type;
|
||||
|
||||
u32 id;
|
||||
|
||||
|
||||
@@ -10,22 +10,21 @@
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
const Op* Module::ConstantTrue(const Op* result_type) {
|
||||
Ref Module::ConstantTrue(Ref result_type) {
|
||||
return AddDeclaration(new Op(spv::Op::OpConstantTrue, bound, result_type));
|
||||
}
|
||||
|
||||
const Op* Module::ConstantFalse(const Op* result_type) {
|
||||
Ref Module::ConstantFalse(Ref result_type) {
|
||||
return AddDeclaration(new Op(spv::Op::OpConstantFalse, bound, result_type));
|
||||
}
|
||||
|
||||
const Op* Module::Constant(const Op* result_type, Operand* literal) {
|
||||
Ref Module::Constant(Ref result_type, Operand* literal) {
|
||||
Op* op{new Op(spv::Op::OpConstant, bound, result_type)};
|
||||
op->Add(literal);
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
|
||||
const Op* Module::ConstantComposite(const Op* result_type,
|
||||
const std::vector<const Op*>& constituents) {
|
||||
Ref Module::ConstantComposite(Ref result_type, const std::vector<Ref>& constituents) {
|
||||
Op* op{new Op(spv::Op::OpConstantComposite, bound, result_type)};
|
||||
op->Add(constituents);
|
||||
return AddDeclaration(op);
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
const Op* Module::Label() {
|
||||
Ref Module::Label() {
|
||||
return AddCode(spv::Op::OpLabel, bound++);
|
||||
}
|
||||
|
||||
const Op* Module::Return() {
|
||||
Ref Module::Return() {
|
||||
return AddCode(spv::Op::OpReturn);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,15 +9,14 @@
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
const Op* Module::Function(const Op* result_type, spv::FunctionControlMask function_control,
|
||||
const Op* function_type) {
|
||||
Ref Module::Function(Ref result_type, spv::FunctionControlMask function_control, Ref function_type) {
|
||||
Op* op{new Op{spv::Op::OpFunction, bound++, result_type}};
|
||||
op->Add(static_cast<u32>(function_control));
|
||||
op->Add(function_type);
|
||||
return AddCode(op);
|
||||
}
|
||||
|
||||
const Op* Module::FunctionEnd() {
|
||||
Ref Module::FunctionEnd() {
|
||||
return AddCode(spv::Op::OpFunctionEnd);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,15 +10,15 @@
|
||||
|
||||
namespace Sirit {
|
||||
|
||||
const Op* Module::TypeVoid() {
|
||||
Ref Module::TypeVoid() {
|
||||
return AddDeclaration(new Op(spv::Op::OpTypeVoid, bound));
|
||||
}
|
||||
|
||||
const Op* Module::TypeBool() {
|
||||
Ref Module::TypeBool() {
|
||||
return AddDeclaration(new Op(spv::Op::OpTypeBool, bound));
|
||||
}
|
||||
|
||||
const Op* Module::TypeInt(int width, bool is_signed) {
|
||||
Ref Module::TypeInt(int width, bool is_signed) {
|
||||
if (width == 8) {
|
||||
AddCapability(spv::Capability::Int8);
|
||||
} else if (width == 16) {
|
||||
@@ -32,7 +32,7 @@ const Op* Module::TypeInt(int width, bool is_signed) {
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
|
||||
const Op* Module::TypeFloat(int width) {
|
||||
Ref Module::TypeFloat(int width) {
|
||||
if (width == 16) {
|
||||
AddCapability(spv::Capability::Float16);
|
||||
} else if (width == 64) {
|
||||
@@ -43,7 +43,7 @@ const Op* Module::TypeFloat(int width) {
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
|
||||
const Op* Module::TypeVector(const Op* component_type, int component_count) {
|
||||
Ref Module::TypeVector(Ref component_type, int component_count) {
|
||||
assert(component_count >= 2);
|
||||
Op* op{new Op(spv::Op::OpTypeVector, bound)};
|
||||
op->Add(component_type);
|
||||
@@ -51,7 +51,7 @@ const Op* Module::TypeVector(const Op* component_type, int component_count) {
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
|
||||
const Op* Module::TypeMatrix(const Op* column_type, int column_count) {
|
||||
Ref Module::TypeMatrix(Ref column_type, int column_count) {
|
||||
assert(column_count >= 2);
|
||||
AddCapability(spv::Capability::Matrix);
|
||||
Op* op{new Op(spv::Op::OpTypeMatrix, bound)};
|
||||
@@ -60,7 +60,7 @@ const Op* Module::TypeMatrix(const Op* column_type, int column_count) {
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
|
||||
const Op* Module::TypeImage(const Op* sampled_type, spv::Dim dim, int depth, bool arrayed, bool ms,
|
||||
Ref Module::TypeImage(Ref sampled_type, spv::Dim dim, int depth, bool arrayed, bool ms,
|
||||
int sampled, spv::ImageFormat image_format,
|
||||
spv::AccessQualifier access_qualifier) {
|
||||
switch (dim) {
|
||||
@@ -138,44 +138,44 @@ const Op* Module::TypeImage(const Op* sampled_type, spv::Dim dim, int depth, boo
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
|
||||
const Op* Module::TypeSampler() {
|
||||
Ref Module::TypeSampler() {
|
||||
return AddDeclaration(new Op(spv::Op::OpTypeSampler, bound));
|
||||
}
|
||||
|
||||
const Op* Module::TypeSampledImage(const Op* image_type) {
|
||||
Ref Module::TypeSampledImage(Ref image_type) {
|
||||
Op* op{new Op(spv::Op::OpTypeSampledImage, bound)};
|
||||
op->Add(image_type);
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
|
||||
const Op* Module::TypeArray(const Op* element_type, const Op* length) {
|
||||
Ref Module::TypeArray(Ref element_type, Ref length) {
|
||||
Op* op{new Op(spv::Op::OpTypeArray, bound)};
|
||||
op->Add(element_type);
|
||||
op->Add(length);
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
|
||||
const Op* Module::TypeRuntimeArray(const Op* element_type) {
|
||||
Ref Module::TypeRuntimeArray(Ref element_type) {
|
||||
AddCapability(spv::Capability::Shader);
|
||||
Op* op{new Op(spv::Op::OpTypeRuntimeArray, bound)};
|
||||
op->Add(element_type);
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
|
||||
const Op* Module::TypeStruct(const std::vector<const Op*>& members) {
|
||||
Ref Module::TypeStruct(const std::vector<Ref>& members) {
|
||||
Op* op{new Op(spv::Op::OpTypeStruct, bound)};
|
||||
op->Add(members);
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
|
||||
const Op* Module::TypeOpaque(const std::string& name) {
|
||||
Ref Module::TypeOpaque(const std::string& name) {
|
||||
AddCapability(spv::Capability::Kernel);
|
||||
Op* op{new Op(spv::Op::OpTypeOpaque, bound)};
|
||||
op->Add(name);
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
|
||||
const Op* Module::TypePointer(spv::StorageClass storage_class, const Op* type) {
|
||||
Ref Module::TypePointer(spv::StorageClass storage_class, Ref type) {
|
||||
switch (storage_class) {
|
||||
case spv::StorageClass::Uniform:
|
||||
case spv::StorageClass::Output:
|
||||
@@ -197,34 +197,34 @@ const Op* Module::TypePointer(spv::StorageClass storage_class, const Op* type) {
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
|
||||
const Op* Module::TypeFunction(const Op* return_type, const std::vector<const Op*>& arguments) {
|
||||
Ref Module::TypeFunction(Ref return_type, const std::vector<Ref>& arguments) {
|
||||
Op* op{new Op(spv::Op::OpTypeFunction, bound)};
|
||||
op->Add(return_type);
|
||||
op->Add(arguments);
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
|
||||
const Op* Module::TypeEvent() {
|
||||
Ref Module::TypeEvent() {
|
||||
AddCapability(spv::Capability::Kernel);
|
||||
return AddDeclaration(new Op(spv::Op::OpTypeEvent, bound));
|
||||
}
|
||||
|
||||
const Op* Module::TypeDeviceEvent() {
|
||||
Ref Module::TypeDeviceEvent() {
|
||||
AddCapability(spv::Capability::DeviceEnqueue);
|
||||
return AddDeclaration(new Op(spv::Op::OpTypeDeviceEvent, bound));
|
||||
}
|
||||
|
||||
const Op* Module::TypeReserveId() {
|
||||
Ref Module::TypeReserveId() {
|
||||
AddCapability(spv::Capability::Pipes);
|
||||
return AddDeclaration(new Op(spv::Op::OpTypeReserveId, bound));
|
||||
}
|
||||
|
||||
const Op* Module::TypeQueue() {
|
||||
Ref Module::TypeQueue() {
|
||||
AddCapability(spv::Capability::DeviceEnqueue);
|
||||
return AddDeclaration(new Op(spv::Op::OpTypeQueue, bound));
|
||||
}
|
||||
|
||||
const Op* Module::TypePipe(spv::AccessQualifier access_qualifier) {
|
||||
Ref Module::TypePipe(spv::AccessQualifier access_qualifier) {
|
||||
AddCapability(spv::Capability::Pipes);
|
||||
Op* op{new Op(spv::Op::OpTypePipe, bound)};
|
||||
op->Add(static_cast<u32>(access_qualifier));
|
||||
|
||||
@@ -73,8 +73,8 @@ void Module::SetMemoryModel(spv::AddressingModel addressing_model, spv::MemoryMo
|
||||
this->memory_model = memory_model;
|
||||
}
|
||||
|
||||
void Module::AddEntryPoint(spv::ExecutionModel execution_model, const Op* entry_point,
|
||||
const std::string& name, const std::vector<const Op*>& interfaces) {
|
||||
void Module::AddEntryPoint(spv::ExecutionModel execution_model, Ref entry_point,
|
||||
const std::string& name, const std::vector<Ref>& interfaces) {
|
||||
Op* op{new Op(spv::Op::OpEntryPoint)};
|
||||
op->Add(static_cast<u32>(execution_model));
|
||||
op->Add(entry_point);
|
||||
@@ -83,22 +83,22 @@ void Module::AddEntryPoint(spv::ExecutionModel execution_model, const Op* entry_
|
||||
entry_points.push_back(std::unique_ptr<Op>(op));
|
||||
}
|
||||
|
||||
const Op* Module::Emit(const Op* op) {
|
||||
Ref Module::Emit(Ref op) {
|
||||
assert(op);
|
||||
code.push_back(op);
|
||||
return op;
|
||||
}
|
||||
|
||||
const Op* Module::AddCode(Op* op) {
|
||||
Ref Module::AddCode(Op* op) {
|
||||
code_store.push_back(std::unique_ptr<Op>(op));
|
||||
return op;
|
||||
}
|
||||
|
||||
const Op* Module::AddCode(spv::Op opcode, u32 id) {
|
||||
Ref Module::AddCode(spv::Op opcode, u32 id) {
|
||||
return AddCode(new Op{opcode, id});
|
||||
}
|
||||
|
||||
const Op* Module::AddDeclaration(Op* op) {
|
||||
Ref Module::AddDeclaration(Op* op) {
|
||||
const auto& found{std::find_if(declarations.begin(), declarations.end(), [=](const auto& other) {
|
||||
return *other == *op;
|
||||
})};
|
||||
|
||||
Reference in New Issue
Block a user