-
Notifications
You must be signed in to change notification settings - Fork 4
/
playgroundShader.js
93 lines (76 loc) · 2.11 KB
/
playgroundShader.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
const playgroundSource = `
internal uniform float time;
// Return the current time in milliseconds
public float getTime()
{
return time;
}
// type field: 1 for format string, 2 for normal string, 3 for integer, 4 for float, 5 for double,
struct FormatedStruct
{
uint32_t type = 0xFFFFFFFF;
uint32_t low = 0;
uint32_t high = 0;
};
// This is global variable, intead of shader parameter.
internal static int g_printBufferIndex = 0;
internal RWStructuredBuffer<FormatedStruct> g_printedBuffer;
interface IPrintf
{
uint32_t typeFlag();
uint32_t writePrintfWords();
};
extension uint : IPrintf
{
uint32_t typeFlag() { return 3;}
uint32_t writePrintfWords() { return (uint32_t)this; }
}
extension int : IPrintf
{
uint32_t typeFlag() { return 3;}
uint32_t writePrintfWords() { return (uint32_t)this; }
}
// extension int64_t : IPrintf
// {
// uint64_t writePrintfWords() { return (uint64_t)this; }
// }
// extension uint64_t : IPrintf
// {
// uint64_t writePrintfWords() { return (uint64_t)this; }
// }
extension float : IPrintf
{
uint32_t typeFlag() { return 4;}
uint32_t writePrintfWords() { return bit_cast<uint32_t>(this); }
}
// extension double : IPrintf
// {
// uint64_t writePrintfWords() { return bit_cast<uint64_t>(this); }
// }
extension String : IPrintf
{
uint32_t typeFlag() { return 2;}
uint32_t writePrintfWords() { return getStringHash(this); }
}
void handleEach<T>(T value, int index) where T : IPrintf
{
g_printedBuffer[index].type = value.typeFlag();
g_printedBuffer[index].low = value.writePrintfWords();
}
public void print<each T>(String format, expand each T values) where T : IPrintf
{
//if (format.length != 0)
{
g_printedBuffer[g_printBufferIndex].type = 1;
g_printedBuffer[g_printBufferIndex].low = getStringHash(format);
g_printBufferIndex++;
expand(handleEach(each values, g_printBufferIndex++));
g_printedBuffer[g_printBufferIndex++] = {};
}
}
[OverloadRank(1)]
public void printf<each T>(String format, expand each T values) where T : IPrintf
{
print(format, expand each values);
}
`;