mirror of
https://github.com/azahar-emu/sirit.git
synced 2026-04-01 08:30:59 +02:00
Use some C++17 features
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <optional>
|
||||
#include "sirit/sirit.h"
|
||||
#include "insts.h"
|
||||
|
||||
@@ -26,7 +27,7 @@ Ref Module::TypeInt(int width, bool is_signed) {
|
||||
} else if (width == 64) {
|
||||
AddCapability(spv::Capability::Int64);
|
||||
}
|
||||
Op* op{new Op(spv::Op::OpTypeInt, bound)};
|
||||
auto const op{new Op(spv::Op::OpTypeInt, bound)};
|
||||
op->Add(width);
|
||||
op->Add(is_signed ? 1 : 0);
|
||||
return AddDeclaration(op);
|
||||
@@ -38,14 +39,14 @@ Ref Module::TypeFloat(int width) {
|
||||
} else if (width == 64) {
|
||||
AddCapability(spv::Capability::Float64);
|
||||
}
|
||||
Op* op{new Op(spv::Op::OpTypeFloat, bound)};
|
||||
auto const op{new Op(spv::Op::OpTypeFloat, bound)};
|
||||
op->Add(width);
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
|
||||
Ref Module::TypeVector(Ref component_type, int component_count) {
|
||||
assert(component_count >= 2);
|
||||
Op* op{new Op(spv::Op::OpTypeVector, bound)};
|
||||
auto const op{new Op(spv::Op::OpTypeVector, bound)};
|
||||
op->Add(component_type);
|
||||
op->Add(component_count);
|
||||
return AddDeclaration(op);
|
||||
@@ -61,8 +62,8 @@ Ref Module::TypeMatrix(Ref column_type, int column_count) {
|
||||
}
|
||||
|
||||
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) {
|
||||
int sampled, spv::ImageFormat image_format,
|
||||
std::optional<spv::AccessQualifier> access_qualifier) {
|
||||
switch (dim) {
|
||||
case spv::Dim::Dim1D:
|
||||
AddCapability(spv::Capability::Sampled1D);
|
||||
@@ -123,7 +124,7 @@ Ref Module::TypeImage(Ref sampled_type, spv::Dim dim, int depth, bool arrayed, b
|
||||
AddCapability(spv::Capability::StorageImageExtendedFormats);
|
||||
break;
|
||||
}
|
||||
Op* op{new Op(spv::Op::OpTypeImage, bound)};
|
||||
auto const op{new Op(spv::Op::OpTypeImage, bound)};
|
||||
op->Add(sampled_type);
|
||||
op->Add(static_cast<u32>(dim));
|
||||
op->Add(depth);
|
||||
@@ -131,9 +132,9 @@ Ref Module::TypeImage(Ref sampled_type, spv::Dim dim, int depth, bool arrayed, b
|
||||
op->Add(ms ? 1 : 0);
|
||||
op->Add(sampled);
|
||||
op->Add(static_cast<u32>(image_format));
|
||||
if (static_cast<u32>(access_qualifier) != Undefined) {
|
||||
if (access_qualifier.has_value()) {
|
||||
AddCapability(spv::Capability::Kernel);
|
||||
op->Add(static_cast<u32>(access_qualifier));
|
||||
op->Add(static_cast<u32>(access_qualifier.value()));
|
||||
}
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
@@ -143,13 +144,13 @@ Ref Module::TypeSampler() {
|
||||
}
|
||||
|
||||
Ref Module::TypeSampledImage(Ref image_type) {
|
||||
Op* op{new Op(spv::Op::OpTypeSampledImage, bound)};
|
||||
auto const op{new Op(spv::Op::OpTypeSampledImage, bound)};
|
||||
op->Add(image_type);
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
|
||||
Ref Module::TypeArray(Ref element_type, Ref length) {
|
||||
Op* op{new Op(spv::Op::OpTypeArray, bound)};
|
||||
auto const op{new Op(spv::Op::OpTypeArray, bound)};
|
||||
op->Add(element_type);
|
||||
op->Add(length);
|
||||
return AddDeclaration(op);
|
||||
@@ -157,20 +158,20 @@ Ref Module::TypeArray(Ref element_type, Ref length) {
|
||||
|
||||
Ref Module::TypeRuntimeArray(Ref element_type) {
|
||||
AddCapability(spv::Capability::Shader);
|
||||
Op* op{new Op(spv::Op::OpTypeRuntimeArray, bound)};
|
||||
auto const op{new Op(spv::Op::OpTypeRuntimeArray, bound)};
|
||||
op->Add(element_type);
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
|
||||
Ref Module::TypeStruct(const std::vector<Ref>& members) {
|
||||
Op* op{new Op(spv::Op::OpTypeStruct, bound)};
|
||||
auto const op{new Op(spv::Op::OpTypeStruct, bound)};
|
||||
op->Add(members);
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
|
||||
Ref Module::TypeOpaque(const std::string& name) {
|
||||
AddCapability(spv::Capability::Kernel);
|
||||
Op* op{new Op(spv::Op::OpTypeOpaque, bound)};
|
||||
auto const op{new Op(spv::Op::OpTypeOpaque, bound)};
|
||||
op->Add(name);
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
@@ -191,14 +192,14 @@ Ref Module::TypePointer(spv::StorageClass storage_class, Ref type) {
|
||||
AddCapability(spv::Capability::AtomicStorage);
|
||||
break;
|
||||
}
|
||||
Op* op{new Op(spv::Op::OpTypePointer, bound)};
|
||||
auto const op{new Op(spv::Op::OpTypePointer, bound)};
|
||||
op->Add(static_cast<u32>(storage_class));
|
||||
op->Add(type);
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
|
||||
Ref Module::TypeFunction(Ref return_type, const std::vector<Ref>& arguments) {
|
||||
Op* op{new Op(spv::Op::OpTypeFunction, bound)};
|
||||
auto const op{new Op(spv::Op::OpTypeFunction, bound)};
|
||||
op->Add(return_type);
|
||||
op->Add(arguments);
|
||||
return AddDeclaration(op);
|
||||
@@ -226,7 +227,7 @@ Ref Module::TypeQueue() {
|
||||
|
||||
Ref Module::TypePipe(spv::AccessQualifier access_qualifier) {
|
||||
AddCapability(spv::Capability::Pipes);
|
||||
Op* op{new Op(spv::Op::OpTypePipe, bound)};
|
||||
auto const op{new Op(spv::Op::OpTypePipe, bound)};
|
||||
op->Add(static_cast<u32>(access_qualifier));
|
||||
return AddDeclaration(op);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user