1
0
Fork 0
mirror of https://git.suyu.dev/suyu/sirit.git synced 2024-12-23 04:32:04 +00:00
sirit/tests/main.cpp

62 lines
1.8 KiB
C++
Raw Normal View History

2018-08-23 08:59:57 +01:00
/* 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
* General Public License version 2 or any later version.
*/
#include <sirit/sirit.h>
2018-08-26 00:16:37 +01:00
#include <cstdio>
#include <cstdlib>
class MyModule : public Sirit::Module {
public:
MyModule() {}
~MyModule() = default;
void Generate() {
AddCapability(spv::Capability::Shader);
SetMemoryModel(spv::AddressingModel::Logical, spv::MemoryModel::GLSL450);
2018-08-26 18:25:59 +01:00
// Type testing
TypeBool();
TypeBool();
TypeInt(64, true);
TypeInt(64, false);
TypeInt(16, false);
TypeFloat(16);
TypeFloat(32);
TypeFloat(64);
TypeVector(TypeBool(), 4);
TypeVector(TypeBool(), 3);
TypeVector(TypeVector(TypeFloat(32), 4), 3);
TypeVector(TypeVector(TypeFloat(32), 4), 3);
TypeMatrix(TypeVector(TypeFloat(32), 4), 4);
TypeImage(TypeFloat(32), spv::Dim::Dim2D, 0, false, false, 0,
spv::ImageFormat::Rg32f, spv::AccessQualifier::ReadOnly);
TypeSampledImage(TypeImage(TypeFloat(32), spv::Dim::Rect, 0, false, false, 0,
spv::ImageFormat::Rg32f, spv::AccessQualifier::ReadOnly));
2018-08-26 00:16:37 +01:00
auto main_type{TypeFunction(TypeVoid())};
2018-08-26 00:34:06 +01:00
auto main_func{Emit(Function(TypeVoid(), spv::FunctionControlMask::MaskNone, main_type))};
Emit(Label());
Emit(Return());
Emit(FunctionEnd());
2018-08-26 00:16:37 +01:00
AddEntryPoint(spv::ExecutionModel::Vertex, main_func, "main");
}
};
int main(int argc, char** argv) {
MyModule module;
module.Generate();
module.Optimize(2);
std::vector<std::uint8_t> code{module.Assembly()};
FILE* file = fopen("sirit.spv", "wb");
fwrite(code.data(), 1, code.size(), file);
fclose(file);
2018-08-23 08:59:57 +01:00
return 0;
}