Fixup build issues

This commit is contained in:
ReinUsesLisp 2018-11-01 05:13:30 -03:00
parent f3a63aa55f
commit 91e0769db5
6 changed files with 78 additions and 74 deletions

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 "insts.h" #include "op.h"
#include "sirit/sirit.h" #include "sirit/sirit.h"
#include <cassert> #include <cassert>
@ -12,51 +12,51 @@ 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{new Op(spv::Op::OpVariable, bound++, result_type)}; auto op{std::make_unique<Op>(spv::Op::OpVariable, bound++, result_type)};
AddEnum(op, storage_class); op->Add(static_cast<u32>(storage_class));
if (initializer) { if (initializer) {
op->Add(initializer); op->Add(initializer);
} }
return AddCode(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{new 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) {
AddEnum(op, *memory_access); op->Add(static_cast<u32>(*memory_access));
} }
return AddCode(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{new 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);
if (memory_access) { if (memory_access) {
AddEnum(op, *memory_access); op->Add(static_cast<u32>(*memory_access));
} }
return AddCode(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{new 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);
op->Add(indexes); op->Add(indexes);
return AddCode(op); return AddCode(std::move(op));
} }
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{new Op(spv::Op::OpCompositeInsert, bound++, result_type)}; auto op{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(op); return AddCode(std::move(op));
} }
} // namespace Sirit } // namespace Sirit

View File

@ -4,14 +4,14 @@
* Lesser General Public License version 2.1 or any later version. * Lesser General Public License version 2.1 or any later version.
*/ */
#include "insts.h" #include "op.h"
#include "sirit/sirit.h" #include "sirit/sirit.h"
#include <cassert> #include <cassert>
namespace Sirit { namespace Sirit {
Id Module::OpUndef(Id result_type) { Id Module::OpUndef(Id result_type) {
return AddCode(new Op(spv::Op::OpUndef, bound++, result_type)); return AddCode(std::make_unique<Op>(spv::Op::OpUndef, bound++, result_type));
} }
} // namespace Sirit } // namespace Sirit

View File

@ -4,20 +4,21 @@
* Lesser General Public License version 2.1 or any later version. * Lesser General Public License version 2.1 or any later version.
*/ */
#include <memory>
#include <cassert> #include <cassert>
#include <optional> #include <optional>
#include "insts.h" #include "op.h"
#include "sirit/sirit.h" #include "sirit/sirit.h"
namespace Sirit { namespace Sirit {
Id Module::OpTypeVoid() { Id Module::OpTypeVoid() {
return AddDeclaration(new Op(spv::Op::OpTypeVoid, bound)); return AddDeclaration(std::make_unique<Op>(spv::Op::OpTypeVoid, bound));
} }
Id Module::OpTypeBool() { Id Module::OpTypeBool() {
return AddDeclaration(new Op(spv::Op::OpTypeBool, bound)); return AddDeclaration(std::make_unique<Op>(spv::Op::OpTypeBool, bound));
} }
Id Module::OpTypeInt(int width, bool is_signed) { Id Module::OpTypeInt(int width, bool is_signed) {
@ -28,10 +29,10 @@ Id Module::OpTypeInt(int width, bool is_signed) {
} else if (width == 64) { } else if (width == 64) {
AddCapability(spv::Capability::Int64); AddCapability(spv::Capability::Int64);
} }
auto op{new Op(spv::Op::OpTypeInt, bound)}; auto op{std::make_unique<Op>(spv::Op::OpTypeInt, bound)};
op->Add(width); op->Add(width);
op->Add(is_signed ? 1 : 0); op->Add(is_signed ? 1 : 0);
return AddDeclaration(op); return AddDeclaration(std::move(op));
} }
Id Module::OpTypeFloat(int width) { Id Module::OpTypeFloat(int width) {
@ -40,26 +41,26 @@ Id Module::OpTypeFloat(int width) {
} else if (width == 64) { } else if (width == 64) {
AddCapability(spv::Capability::Float64); AddCapability(spv::Capability::Float64);
} }
auto op{new Op(spv::Op::OpTypeFloat, bound)}; auto op{std::make_unique<Op>(spv::Op::OpTypeFloat, bound)};
op->Add(width); op->Add(width);
return AddDeclaration(op); return AddDeclaration(std::move(op));
} }
Id Module::OpTypeVector(Id component_type, int component_count) { Id Module::OpTypeVector(Id component_type, int component_count) {
assert(component_count >= 2); assert(component_count >= 2);
auto op{new Op(spv::Op::OpTypeVector, bound)}; auto op{std::make_unique<Op>(spv::Op::OpTypeVector, bound)};
op->Add(component_type); op->Add(component_type);
op->Add(component_count); op->Add(component_count);
return AddDeclaration(op); return AddDeclaration(std::move(op));
} }
Id Module::OpTypeMatrix(Id column_type, int column_count) { Id Module::OpTypeMatrix(Id 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)}; auto op{std::make_unique<Op>(spv::Op::OpTypeMatrix, bound)};
op->Add(column_type); op->Add(column_type);
op->Add(column_count); op->Add(column_count);
return AddDeclaration(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,
@ -125,7 +126,7 @@ Id Module::OpTypeImage(Id sampled_type, spv::Dim dim, int depth, bool arrayed,
AddCapability(spv::Capability::StorageImageExtendedFormats); AddCapability(spv::Capability::StorageImageExtendedFormats);
break; break;
} }
auto op{new Op(spv::Op::OpTypeImage, bound)}; auto op{std::make_unique<Op>(spv::Op::OpTypeImage, bound)};
op->Add(sampled_type); op->Add(sampled_type);
op->Add(static_cast<u32>(dim)); op->Add(static_cast<u32>(dim));
op->Add(depth); op->Add(depth);
@ -137,44 +138,44 @@ Id Module::OpTypeImage(Id sampled_type, spv::Dim dim, int depth, bool arrayed,
AddCapability(spv::Capability::Kernel); AddCapability(spv::Capability::Kernel);
op->Add(static_cast<u32>(access_qualifier.value())); op->Add(static_cast<u32>(access_qualifier.value()));
} }
return AddDeclaration(op); return AddDeclaration(std::move(op));
} }
Id Module::OpTypeSampler() { Id Module::OpTypeSampler() {
return AddDeclaration(new Op(spv::Op::OpTypeSampler, bound)); return AddDeclaration(std::make_unique<Op>(spv::Op::OpTypeSampler, bound));
} }
Id Module::OpTypeSampledImage(Id image_type) { Id Module::OpTypeSampledImage(Id image_type) {
auto op{new Op(spv::Op::OpTypeSampledImage, bound)}; auto op{std::make_unique<Op>(spv::Op::OpTypeSampledImage, bound)};
op->Add(image_type); op->Add(image_type);
return AddDeclaration(op); return AddDeclaration(std::move(op));
} }
Id Module::OpTypeArray(Id element_type, Id length) { Id Module::OpTypeArray(Id element_type, Id length) {
auto op{new Op(spv::Op::OpTypeArray, bound)}; auto op{std::make_unique<Op>(spv::Op::OpTypeArray, bound)};
op->Add(element_type); op->Add(element_type);
op->Add(length); op->Add(length);
return AddDeclaration(op); return AddDeclaration(std::move(op));
} }
Id Module::OpTypeRuntimeArray(Id element_type) { Id Module::OpTypeRuntimeArray(Id element_type) {
AddCapability(spv::Capability::Shader); AddCapability(spv::Capability::Shader);
auto op{new Op(spv::Op::OpTypeRuntimeArray, bound)}; auto op{std::make_unique<Op>(spv::Op::OpTypeRuntimeArray, bound)};
op->Add(element_type); op->Add(element_type);
return AddDeclaration(op); return AddDeclaration(std::move(op));
} }
Id Module::OpTypeStruct(const std::vector<Id>& members) { Id Module::OpTypeStruct(const std::vector<Id>& members) {
auto op{new Op(spv::Op::OpTypeStruct, bound)}; auto op{std::make_unique<Op>(spv::Op::OpTypeStruct, bound)};
op->Add(members); op->Add(members);
return AddDeclaration(op); return AddDeclaration(std::move(op));
} }
Id Module::OpTypeOpaque(const std::string& name) { Id Module::OpTypeOpaque(const std::string& name) {
AddCapability(spv::Capability::Kernel); AddCapability(spv::Capability::Kernel);
auto op{new Op(spv::Op::OpTypeOpaque, bound)}; auto op{std::make_unique<Op>(spv::Op::OpTypeOpaque, bound)};
op->Add(name); op->Add(name);
return AddDeclaration(op); return AddDeclaration(std::move(op));
} }
Id Module::OpTypePointer(spv::StorageClass storage_class, Id type) { Id Module::OpTypePointer(spv::StorageClass storage_class, Id type) {
@ -193,44 +194,44 @@ Id Module::OpTypePointer(spv::StorageClass storage_class, Id type) {
AddCapability(spv::Capability::AtomicStorage); AddCapability(spv::Capability::AtomicStorage);
break; break;
} }
auto op{new Op(spv::Op::OpTypePointer, bound)}; auto op{std::make_unique<Op>(spv::Op::OpTypePointer, bound)};
op->Add(static_cast<u32>(storage_class)); op->Add(static_cast<u32>(storage_class));
op->Add(type); op->Add(type);
return AddDeclaration(op); return AddDeclaration(std::move(op));
} }
Id Module::OpTypeFunction(Id return_type, const std::vector<Id>& arguments) { Id Module::OpTypeFunction(Id return_type, const std::vector<Id>& arguments) {
auto op{new Op(spv::Op::OpTypeFunction, bound)}; auto op{std::make_unique<Op>(spv::Op::OpTypeFunction, bound)};
op->Add(return_type); op->Add(return_type);
op->Add(arguments); op->Add(arguments);
return AddDeclaration(op); return AddDeclaration(std::move(op));
} }
Id Module::OpTypeEvent() { Id Module::OpTypeEvent() {
AddCapability(spv::Capability::Kernel); AddCapability(spv::Capability::Kernel);
return AddDeclaration(new Op(spv::Op::OpTypeEvent, bound)); return AddDeclaration(std::make_unique<Op>(spv::Op::OpTypeEvent, bound));
} }
Id Module::OpTypeDeviceEvent() { Id Module::OpTypeDeviceEvent() {
AddCapability(spv::Capability::DeviceEnqueue); AddCapability(spv::Capability::DeviceEnqueue);
return AddDeclaration(new Op(spv::Op::OpTypeDeviceEvent, bound)); return AddDeclaration(std::make_unique<Op>(spv::Op::OpTypeDeviceEvent, bound));
} }
Id Module::OpTypeReserveId() { Id Module::OpTypeReserveId() {
AddCapability(spv::Capability::Pipes); AddCapability(spv::Capability::Pipes);
return AddDeclaration(new Op(spv::Op::OpTypeReserveId, bound)); return AddDeclaration(std::make_unique<Op>(spv::Op::OpTypeReserveId, bound));
} }
Id Module::OpTypeQueue() { Id Module::OpTypeQueue() {
AddCapability(spv::Capability::DeviceEnqueue); AddCapability(spv::Capability::DeviceEnqueue);
return AddDeclaration(new Op(spv::Op::OpTypeQueue, bound)); return AddDeclaration(std::make_unique<Op>(spv::Op::OpTypeQueue, bound));
} }
Id Module::OpTypePipe(spv::AccessQualifier access_qualifier) { Id Module::OpTypePipe(spv::AccessQualifier access_qualifier) {
AddCapability(spv::Capability::Pipes); AddCapability(spv::Capability::Pipes);
auto op{new Op(spv::Op::OpTypePipe, bound)}; auto op{std::make_unique<Op>(spv::Op::OpTypePipe, bound)};
op->Add(static_cast<u32>(access_qualifier)); op->Add(static_cast<u32>(access_qualifier));
return AddDeclaration(op); return AddDeclaration(std::move(op));
} }
} // namespace Sirit } // namespace Sirit

View File

@ -113,7 +113,7 @@ void Op::Add(const std::vector<Id>& ids) {
} }
u16 Op::WordCount() const { u16 Op::WordCount() const {
u16 count{1}; u16 count = 1;
if (result_type) { if (result_type) {
count++; count++;
} }

View File

@ -75,12 +75,12 @@ void Module::SetMemoryModel(spv::AddressingModel addressing_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 const op{new 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);
op->Add(name); op->Add(name);
op->Add(interfaces); op->Add(interfaces);
entry_points.push_back(std::unique_ptr<Op>(op)); entry_points.push_back(std::move(op));
} }
Id Module::Emit(Id op) { Id Module::Emit(Id op) {
@ -95,8 +95,9 @@ Id Module::AddGlobalVariable(Id variable) {
} }
Id Module::AddCode(std::unique_ptr<Op> op) { Id Module::AddCode(std::unique_ptr<Op> op) {
const auto id = op.get();
code_store.push_back(std::move(op)); code_store.push_back(std::move(op));
return op.get(); return id;
} }
Id Module::AddCode(spv::Op opcode, std::optional<u32> id) { Id Module::AddCode(spv::Op opcode, std::optional<u32> id) {
@ -117,8 +118,9 @@ Id Module::AddDeclaration(std::unique_ptr<Op> op) {
} }
Id Module::AddAnnotation(std::unique_ptr<Op> op) { Id Module::AddAnnotation(std::unique_ptr<Op> op) {
const auto id = op.get();
annotations.push_back(std::move(op)); annotations.push_back(std::move(op));
return op.get(); return id;
} }
} // namespace Sirit } // namespace Sirit

View File

@ -19,48 +19,49 @@ 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 = OpName(OpTypeVoid(), "void"); const auto t_void = Name(OpTypeVoid(), "void");
const auto t_uint = OpName(OpTypeInt(32, false), "uint"); const auto t_uint = Name(OpTypeInt(32, false), "uint");
const auto t_float = OpName(OpTypeFloat(32), "float"); const auto t_float = Name(OpTypeFloat(32), "float");
const auto float4 = OpName(OpTypeVector(t_float, 4), "float4"); const auto float4 = Name(OpTypeVector(t_float, 4), "float4");
const auto in_float = OpName(OpTypePointer(spv::StorageClass::Input, t_float), "in_float"); const auto in_float = Name(OpTypePointer(spv::StorageClass::Input, t_float), "in_float");
const auto in_float4 = OpName(OpTypePointer(spv::StorageClass::Input, float4), "in_float4"); const auto in_float4 = Name(OpTypePointer(spv::StorageClass::Input, float4), "in_float4");
const auto out_float4 = OpName(OpTypePointer(spv::StorageClass::Output, float4), "out_float4"); const auto out_float4 = Name(OpTypePointer(spv::StorageClass::Output, float4), "out_float4");
const auto gl_per_vertex = OpName(OpTypeStruct({float4}), "gl_PerVertex"); const auto gl_per_vertex = Name(OpTypeStruct({float4}), "gl_PerVertex");
const auto gl_per_vertex_ptr = OpName(OpTypePointer(spv::StorageClass::Output, gl_per_vertex), "out_gl_PerVertex"); const auto gl_per_vertex_ptr = Name(OpTypePointer(spv::StorageClass::Output, gl_per_vertex), "out_gl_PerVertex");
const auto in_pos = OpName(OpVariable(in_float4, spv::StorageClass::Input), "in_pos"); const auto in_pos = Name(OpVariable(in_float4, spv::StorageClass::Input), "in_pos");
const auto per_vertex = OpName(OpVariable(gl_per_vertex_ptr, spv::StorageClass::Output), "per_vertex"); const auto per_vertex = Name(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);
Decorate(gl_per_vertex, spv::Decoration::Block);
MemberDecorate(gl_per_vertex, 0, spv::Decoration::BuiltIn, {static_cast<u32>(spv::BuiltIn::Position)}); MemberDecorate(gl_per_vertex, 0, spv::Decoration::BuiltIn, {static_cast<u32>(spv::BuiltIn::Position)});
AddGlobalVariable(in_pos); AddGlobalVariable(in_pos);
AddGlobalVariable(per_vertex); AddGlobalVariable(per_vertex);
const auto main_func = Emit(OpName(OpFunction(t_void, spv::FunctionControlMask::MaskNone, TypeFunction(t_void)), "main")); const auto main_func = Emit(Name(OpFunction(t_void, spv::FunctionControlMask::MaskNone, OpTypeFunction(t_void)), "main"));
Emit(Label()); Emit(OpLabel());
const auto ptr_pos_x = Emit(OpAccessChain(in_float, in_pos, {OpConstant(t_uint, 0u)})); const auto ptr_pos_x = Emit(OpAccessChain(in_float, in_pos, {OpConstant(t_uint, 0u)}));
const auto ptr_pos_y = Emit(OpAccessChain(in_float, in_pos, {OpConstant(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(OpLoad(t_float, ptr_pos_x));
const auto pos_y = Emit(Load(t_float, ptr_pos_y)); const auto pos_y = Emit(OpLoad(t_float, ptr_pos_y));
auto tmp_position = Emit(Undef(float4)); auto tmp_position = Emit(OpUndef(float4));
tmp_position = Emit(OpCompositeInsert(float4, pos_x, tmp_position, {0})); tmp_position = Emit(OpCompositeInsert(float4, pos_x, tmp_position, {0}));
tmp_position = Emit(OpCompositeInsert(float4, pos_y, tmp_position, {1})); tmp_position = Emit(OpCompositeInsert(float4, pos_y, tmp_position, {1}));
tmp_position = Emit(OpCompositeInsert(float4, OpConstant(t_float, 0.f), tmp_position, {2})); tmp_position = Emit(OpCompositeInsert(float4, OpConstant(t_float, 0.f), tmp_position, {2}));
tmp_position = Emit(OpCompositeInsert(float4, OpConstant(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(OpAccessChain(out_float4, per_vertex, {OpConstant(t_uint, 0u)})); const auto gl_position = Emit(OpAccessChain(out_float4, per_vertex, {OpConstant(t_uint, 0u)}));
Emit(Store(gl_position, tmp_position)); Emit(OpStore(gl_position, tmp_position));
Emit(Return()); Emit(OpReturn());
Emit(FunctionEnd()); Emit(OpFunctionEnd());
AddEntryPoint(spv::ExecutionModel::Vertex, main_func, "main", {in_pos, per_vertex}); AddEntryPoint(spv::ExecutionModel::Vertex, main_func, "main", {in_pos, per_vertex});
} }