-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathComputeShader.cpp
73 lines (52 loc) · 1.91 KB
/
ComputeShader.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
#include "test/Modules.h"
#include "spvgentwo/Templates.h"
using namespace spvgentwo;
spvgentwo::Module test::computeShader(spvgentwo::IAllocator* _pAllocator, spvgentwo::ILogger* _pLogger)
{
// create a new spir-v module
Module module(_pAllocator, _pLogger);
// configure capabilities and extensions
module.addCapability(spv::Capability::Shader);
module.addCapability(spv::Capability::Kernel);
module.addCapability(spv::Capability::Addresses);
module.addCapability(spv::Capability::Int64);
// global variables
//struct
//{
// float x[];
//};
Type stArray = module.newType().Struct();
// add runt-time float array
stArray.Member().RuntimeArrayElement().Float();
Instruction* uniRtArray = module.uniform(stArray, "u_RtArray");
using complex = array_t<vector_t<float, 4>, 8>;
Instruction* uniArray = module.uniform<complex>("u_Array");
// void main(); entry point
{
EntryPoint& entry = module.addEntryPoint(spv::ExecutionModel::Kernel, "main");
BasicBlock& bb = *entry; // get entry block to this function
Instruction* arLength = bb->opArrayLength(uniRtArray, 0u);
Instruction* f3 = entry.variable(make_vector(1.f, -3.f, 1.f / -0.01f));
f3 = bb->opLoad(f3);
Instruction* g3 = bb->Div(f3, module.constant(-0.0f));
bb->opIsNan(g3);
bb->opIsInf(f3);
bb->opIsFinite(g3);
bb->opIsNormal(f3);
bb->opSignBitSet(g3);
bb->opOrdered(f3, g3);
bb->opUnordered(f3, g3);
Instruction* target = entry.variable<complex>("func_Array");
auto* zero = module.constant(1ull);
bb->opCopyMemorySized(target, uniArray, zero);
bb->opSatConvertSToU(module.constant(13u));
bb->opSatConvertUToS(module.constant(1337u));
Instruction* intVec1 = module.constant(make_vector(0u, 3u, 4u));
Instruction* intVec2 = module.constant(make_vector(3u, 0u, 4u));
bb->opIAddCarry(intVec1, intVec2);
bb->opISubBorrow(intVec2, intVec1);
bb->opUMulExtended(intVec1, intVec1);
bb.returnValue();
}
return module;
}