-
Notifications
You must be signed in to change notification settings - Fork 10
/
Types.cpp
89 lines (64 loc) · 2.32 KB
/
Types.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "test/Modules.h"
#include "common/TypeHelper.h"
#include "spvgentwo/Templates.h"
using namespace spvgentwo;
Module test::types(IAllocator* _pAllocator, ILogger* _pLogger)
{
Module module(_pAllocator, _pLogger);
module.addCapability(spv::Capability::Shader);
{
Function& main = module.addEntryPoint<void>(spv::ExecutionModel::Vertex, u8"main");
BasicBlock& bb = *main;
Type innerStruct = module.newType().RayQueryKHR().wrapStruct();
//struct innerStruct
//{
// ray_query_khr_t query;
//};
// add a name to the type
module.addType(innerStruct, u8"innerStruct");
Type myStruct = module.newType();
//struct myStruct
//{
// float x;
// int y;
// vec3 v;
// innerStruct i;
//};
myStruct.Struct();
myStruct.FloatM(); // add 32 bit float as member
myStruct.IntM(); // add signed int as member
myStruct.Member().VectorElement(3).Float(); // add empty member to struct, make it a vector of 3 elements of type float
myStruct.Member(&innerStruct);
Instruction* type = module.addType(myStruct, u8"myStruct");
String name(_pAllocator);
TypeHelper::getTypeName(myStruct, name, type);
_pLogger->logDebug("%s", name.c_str());
type = module.addType(myStruct.wrapPointer(spv::StorageClass::Function));
// add via addType, make a pointer for storage class 'function
Instruction* var = bb->opVariable(type, spv::StorageClass::Function);
// add C++ type via type<T>
type = module.type<unsigned int*>(spv::StorageClass::Function, "uintptr");
dyn_sampled_image_t img{ spv::Op::OpTypeFloat };
// add complex dynamic C++ type
type = module.type<dyn_sampled_image_t>(img);
auto ty = [&module](){ return module.newType(); };
Type t(ty());
module.addType(t.Struct(ty().Float(), ty().UInt(), ty().Bool()));
bb.returnValue();
}
{
Function& f = module.addFunction<int, float, int, sampler_t, vector_t<float, 3>>("testFunc");
String name(_pAllocator);
TypeHelper::getTypeName(f.getFunctionType(), name, f.getFunction());
_pLogger->logDebug("%s", name.c_str());
BasicBlock& bb = *f;
Instruction* var = f.variable<array_t<int, 6>>("myArray");
var = bb->opLoad(var);
name.clear();
TypeHelper::getTypeName(*var->getType(), name, var);
_pLogger->logDebug("%s", name.c_str());
var = bb->opCompositeExtract(var, 3u);
(*f).returnValue(var);
}
return module;
}