-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathFunctionCall.cpp
42 lines (32 loc) · 1.29 KB
/
FunctionCall.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
#include "test/Modules.h"
#include "spvgentwo/Templates.h"
using namespace spvgentwo;
Module test::functionCall(IAllocator* _pAllocator, ILogger* _pLogger)
{
// create a new spir-v module
Module module(_pAllocator, _pLogger);
// configure capabilities and extensions
module.addCapability(spv::Capability::Shader);
// global variables
Instruction* uniformVar = module.uniform<vector_t<float, 3>>(u8"u_Position");
// float add(float x, float y)
Function& funcAdd = module.addFunction<float, float, float>(u8"add", spv::FunctionControlMask::Const);
{
BasicBlock& bb = *funcAdd; // get entry block to this function
Instruction* x = funcAdd.getParameter(0);
Instruction* y = funcAdd.getParameter(1);
Instruction* z = bb.Add(x, y);
bb.returnValue(z);
}
// void entryPoint();
{
EntryPoint& entry = module.addEntryPoint(spv::ExecutionModel::Fragment, u8"main");
entry.addExecutionMode(spv::ExecutionMode::OriginUpperLeft);
BasicBlock& bb = *entry; // get entry block to this function
Instruction* uniVec = bb->opLoad(uniformVar);
Instruction* s = bb->opDot(uniVec, uniVec);
entry->call(&funcAdd, s, s); // call add(s, s)
entry->opReturn();
}
return module;
}