Add support for GLSLstd450 and OpFAbs

This commit is contained in:
ReinUsesLisp 2018-11-04 03:03:06 -03:00
parent 44043bca56
commit 6742afd6dd
4 changed files with 51 additions and 8 deletions

View File

@ -292,6 +292,15 @@ class Module {
/// Integer addition of Operand 1 and Operand 2. /// Integer addition of Operand 1 and Operand 2.
Id OpIAdd(Id result_type, Id operand_1, Id operand_2); Id OpIAdd(Id result_type, Id operand_1, Id operand_2);
// Extensions
/// Execute an instruction in an imported set of extended instructions.
Id OpExtInst(Id result_type, Id set, std::uint32_t instruction,
const std::vector<Id>& operands);
/// Result is x if x >= 0; otherwise result is -x.
Id OpFAbs(Id result_type, Id x);
private: private:
Id AddCode(std::unique_ptr<Op> op); Id AddCode(std::unique_ptr<Op> op);
@ -301,27 +310,23 @@ class Module {
Id AddAnnotation(std::unique_ptr<Op> op); Id AddAnnotation(std::unique_ptr<Op> op);
Id GetGLSLstd450();
const std::uint32_t version; const std::uint32_t version;
std::uint32_t bound{1}; std::uint32_t bound{1};
std::set<spv::Capability> capabilities; std::set<spv::Capability> capabilities;
std::unique_ptr<Op> glsl_std_450;
std::set<std::string> extensions;
std::set<std::unique_ptr<Op>> ext_inst_import; std::set<std::unique_ptr<Op>> ext_inst_import;
spv::AddressingModel addressing_model{spv::AddressingModel::Logical}; spv::AddressingModel addressing_model{spv::AddressingModel::Logical};
spv::MemoryModel memory_model{spv::MemoryModel::GLSL450}; spv::MemoryModel memory_model{spv::MemoryModel::GLSL450};
std::vector<std::unique_ptr<Op>> entry_points; std::vector<std::unique_ptr<Op>> entry_points;
std::vector<std::unique_ptr<Op>> execution_mode; std::vector<std::unique_ptr<Op>> execution_mode;
std::vector<std::unique_ptr<Op>> debug; std::vector<std::unique_ptr<Op>> debug;
std::vector<std::unique_ptr<Op>> annotations; std::vector<std::unique_ptr<Op>> annotations;
std::vector<std::unique_ptr<Op>> declarations; std::vector<std::unique_ptr<Op>> declarations;
std::vector<Id> global_variables; std::vector<Id> global_variables;

View File

@ -24,6 +24,7 @@ add_library(sirit
insts/conversion.cpp insts/conversion.cpp
insts/bit.cpp insts/bit.cpp
insts/arithmetic.cpp insts/arithmetic.cpp
insts/extension.cpp
) )
target_include_directories(sirit target_include_directories(sirit
PUBLIC ../include PUBLIC ../include

28
src/insts/extension.cpp Normal file
View File

@ -0,0 +1,28 @@
/* This file is part of the sirit project.
* Copyright (c) 2018 ReinUsesLisp
* This software may be used and distributed according to the terms of the GNU
* Lesser General Public License version 2.1 or any later version.
*/
#include "common_types.h"
#include "op.h"
#include "sirit/sirit.h"
#include <memory>
#include <spirv/unified1/GLSL.std.450.h>
namespace Sirit {
Id Module::OpExtInst(Id result_type, Id set, u32 instruction,
const std::vector<Id>& operands) {
auto op{std::make_unique<Op>(spv::Op::OpExtInst, bound++, result_type)};
op->Add(set);
op->Add(instruction);
op->Add(operands);
return AddCode(std::move(op));
}
Id Module::OpFAbs(Id result_type, Id x) {
return OpExtInst(result_type, GetGLSLstd450(), GLSLstd450FAbs, {x});
}
} // namespace Sirit

View File

@ -43,7 +43,9 @@ std::vector<u8> Module::Assemble() const {
for (const auto capability : capabilities) { for (const auto capability : capabilities) {
WriteEnum(stream, spv::Op::OpCapability, capability); WriteEnum(stream, spv::Op::OpCapability, capability);
} }
// TODO write extensions if (glsl_std_450) {
glsl_std_450->Write(stream);
}
// TODO write ext inst imports // TODO write ext inst imports
Op memory_model_ref{spv::Op::OpMemoryModel}; Op memory_model_ref{spv::Op::OpMemoryModel};
@ -123,4 +125,11 @@ Id Module::AddAnnotation(std::unique_ptr<Op> op) {
return id; return id;
} }
Id Module::GetGLSLstd450() {
if (!glsl_std_450) {
glsl_std_450 = std::make_unique<Op>(spv::Op::OpExtInstImport, bound++);
}
return glsl_std_450.get();
}
} // namespace Sirit } // namespace Sirit