diff options
author | ReinUsesLisp <[email protected]> | 2020-08-01 01:50:01 -0300 |
---|---|---|
committer | ReinUsesLisp <[email protected]> | 2020-08-01 01:50:01 -0300 |
commit | 0b9ee36247758920e51811cbde06f6b24f969eb1 (patch) | |
tree | 84d39ca441d60781197aa963bf7ec387935c4719 /tests | |
parent | c4ea8f4b76d416db1a53819390bc9581ae038116 (diff) | |
download | sirit-0b9ee36247758920e51811cbde06f6b24f969eb1.tar.gz sirit-0b9ee36247758920e51811cbde06f6b24f969eb1.zip |
Stream SPIR-V instructions directly to a binary
Before this commit sirit generated a stream of tokens that would then be
inserted to the final SPIR-V binary. This design was carried from the
initial design of manually inserting opcodes into the code. Now that
all instructions but labels are inserted when their respective function
is called, the old design can be dropped in favor of generating a valid
stream of SPIR-V opcodes.
The API for variables is broken, but adopting the new one is trivial.
Instead of calling OpVariable and then adding a global or local
variable, OpVariable was removed and global or local variables are
generated when they are called.
Avoiding duplicates is now done with an std::unordered_set instead of
using a linear search jumping through vtables.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/main.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/tests/main.cpp b/tests/main.cpp index 407dcd5..d119c25 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -7,6 +7,7 @@ #include <cstdio> #include <cstdlib> #include <cstring> + #include <sirit/sirit.h> class MyModule : public Sirit::Module { @@ -31,9 +32,9 @@ public: const auto gl_per_vertex_ptr = Name(TypePointer(spv::StorageClass::Output, gl_per_vertex), "out_gl_PerVertex"); - const auto in_pos = Name(OpVariable(in_float4, spv::StorageClass::Input), "in_pos"); + const auto in_pos = Name(AddGlobalVariable(in_float4, spv::StorageClass::Input), "in_pos"); const auto per_vertex = - Name(OpVariable(gl_per_vertex_ptr, spv::StorageClass::Output), "per_vertex"); + Name(AddGlobalVariable(gl_per_vertex_ptr, spv::StorageClass::Output), "per_vertex"); Decorate(in_pos, spv::Decoration::Location, 0); Decorate(gl_per_vertex, spv::Decoration::Block); @@ -41,9 +42,6 @@ public: MemberDecorate(gl_per_vertex, 0, spv::Decoration::BuiltIn, static_cast<std::uint32_t>(spv::BuiltIn::Position)); - AddGlobalVariable(in_pos); - AddGlobalVariable(per_vertex); - const auto main_func = Name( OpFunction(t_void, spv::FunctionControlMask::MaskNone, TypeFunction(t_void)), "main"); AddLabel(); @@ -57,8 +55,8 @@ public: auto tmp_position = OpUndef(float4); tmp_position = OpCompositeInsert(float4, pos_x, tmp_position, 0); tmp_position = OpCompositeInsert(float4, pos_y, tmp_position, 1); - tmp_position = OpCompositeInsert(float4, Constant(t_float, 0.f), tmp_position, 2); - tmp_position = OpCompositeInsert(float4, Constant(t_float, 1.f), tmp_position, 3); + tmp_position = OpCompositeInsert(float4, Constant(t_float, 0.0f), tmp_position, 2); + tmp_position = OpCompositeInsert(float4, Constant(t_float, 1.0f), tmp_position, 3); const auto gl_position = OpAccessChain(out_float4, per_vertex, Constant(t_uint, 0u)); OpStore(gl_position, tmp_position); @@ -123,7 +121,8 @@ static constexpr std::uint8_t expected_binary[] = { 0x1b, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, - 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00}; + 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, +}; int main(int argc, char** argv) { MyModule module; |