-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
97 lines (71 loc) · 1.68 KB
/
main.js
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
90
91
92
93
94
95
96
var fs = require('fs');
var process = require('process');
var DXC = require('./dxcompiler.js');
var SPIRV = require('./spirv.js');
var content;
var leftToInit = 1;
let dxc = DXC();
let spirv = SPIRV();
spirv.onRuntimeInitialized = () =>
{
if (--leftToInit == 0) init();
}
dxc.onRuntimeInitialized = () =>
{
console.log('dxc loaded');
if (--leftToInit == 0) init();
}
fs.readFile(process.argv[2], (e, data) =>
{
content = data;
if (--leftToInit == 0) init();
});
function init()
{
console.log('init()');
var options = {
filename: 'test.hlsl',
entryPoint: 'main',
profile: 'ps_6_4',
args: ['-spirv' ],
defines: [ ]
};
var start = new Date().getTime();
console.log('start:', start);
const iterations = 5000;
for(var i = 0; i < iterations; ++i)
{
var res = compile(content, options);
}
var end = new Date().getTime();
console.log('end:', end);
console.log('duration:', (end - start) / iterations / 1000.0);
}
function compile(content, options)
{
var result = { success: false };
var compileResult = dxc.Compile(content, options);
if (!compileResult.success)
{
console.error('failed to compile HLSL:', compileResult.error);
result.error = compileResult.error;
return result;
}
var ptr = spirv._malloc(compileResult.data.length);
var array = new Uint8Array(spirv.HEAPU8.buffer, ptr, compileResult.data.length);
array.set(compileResult.data);
var data = compileResult.data;
var res = spirv.SPIRVtoGLSL(array, { reflect: true });
spirv._free(ptr);
if (!res.success)
{
result.success = false;
result.error = res.error;
}
else
{
result.success = true;
result.glsl = res.glsl;
}
return result;
}