-
Notifications
You must be signed in to change notification settings - Fork 70
/
compute.go
74 lines (53 loc) · 1.4 KB
/
compute.go
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
// Copyright (c) 2022, Cogent Core. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import "cogentcore.org/core/math32"
//gosl:hlsl basic
// #include "fastexp.hlsl"
//gosl:end basic
//gosl:start basic
// DataStruct has the test data
type DataStruct struct {
// raw value
Raw float32
// integrated value
Integ float32
// exp of integ
Exp float32
// must pad to multiple of 4 floats for arrays
Pad2 float32
}
// ParamStruct has the test params
type ParamStruct struct {
// rate constant in msec
Tau float32
// 1/Tau
Dt float32
pad, pad1 float32
}
// IntegFromRaw computes integrated value from current raw value
func (ps *ParamStruct) IntegFromRaw(ds *DataStruct) {
ds.Integ += ps.Dt * (ds.Raw - ds.Integ)
ds.Exp = math32.FastExp(-ds.Integ)
}
//gosl:end basic
// note: only core compute code needs to be in shader -- all init is done CPU-side
func (ps *ParamStruct) Defaults() {
ps.Tau = 5
ps.Update()
}
func (ps *ParamStruct) Update() {
ps.Dt = 1.0 / ps.Tau
}
//gosl:hlsl basic
/*
// // note: double-commented lines required here -- binding is var, set
[[vk::binding(0, 0)]] RWStructuredBuffer<ParamStruct> Params;
[[vk::binding(0, 1)]] RWStructuredBuffer<DataStruct> Data;
[numthreads(64, 1, 1)]
void main(uint3 idx : SV_DispatchThreadID) {
Params[0].IntegFromRaw(Data[idx.x]);
}
*/
//gosl:end basic