-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathgpucontext_helpers.go
More file actions
77 lines (64 loc) · 2.31 KB
/
Copy pathgpucontext_helpers.go
File metadata and controls
77 lines (64 loc) · 2.31 KB
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
package wgpu
import (
"unsafe"
"github.com/gogpu/gpucontext"
)
// Handle conversion helpers — isolate unsafe.Pointer from consumers.
// Consumers write wgpu.DeviceFromHandle(dev) instead of (*wgpu.Device)(dev.Pointer()).
// DIP: wgpu (implementation) depends on gpucontext (abstraction),
// like database/sql depends on database/sql/driver.
// DeviceFromHandle extracts *Device from a gpucontext.Device handle.
func DeviceFromHandle(h gpucontext.Device) *Device {
if h.IsNil() {
return nil
}
return (*Device)(h.Pointer())
}
// QueueFromHandle extracts *Queue from a gpucontext.Queue handle.
func QueueFromHandle(h gpucontext.Queue) *Queue {
if h.IsNil() {
return nil
}
return (*Queue)(h.Pointer())
}
// AdapterFromHandle extracts *Adapter from a gpucontext.Adapter handle.
func AdapterFromHandle(h gpucontext.Adapter) *Adapter {
if h.IsNil() {
return nil
}
return (*Adapter)(h.Pointer())
}
// SurfaceFromHandle extracts *Surface from a gpucontext.Surface handle.
func SurfaceFromHandle(h gpucontext.Surface) *Surface {
if h.IsNil() {
return nil
}
return (*Surface)(h.Pointer())
}
// InstanceFromHandle extracts *Instance from a gpucontext.Instance handle.
func InstanceFromHandle(h gpucontext.Instance) *Instance {
if h.IsNil() {
return nil
}
return (*Instance)(h.Pointer())
}
// DeviceToHandle wraps *Device into a gpucontext.Device handle.
func DeviceToHandle(d *Device) gpucontext.Device {
return gpucontext.NewDevice(unsafe.Pointer(d)) //nolint:gosec // ADR-018 opaque handle
}
// QueueToHandle wraps *Queue into a gpucontext.Queue handle.
func QueueToHandle(q *Queue) gpucontext.Queue {
return gpucontext.NewQueue(unsafe.Pointer(q)) //nolint:gosec // ADR-018 opaque handle
}
// AdapterToHandle wraps *Adapter into a gpucontext.Adapter handle.
func AdapterToHandle(a *Adapter) gpucontext.Adapter {
return gpucontext.NewAdapter(unsafe.Pointer(a)) //nolint:gosec // ADR-018 opaque handle
}
// SurfaceToHandle wraps *Surface into a gpucontext.Surface handle.
func SurfaceToHandle(s *Surface) gpucontext.Surface {
return gpucontext.NewSurface(unsafe.Pointer(s)) //nolint:gosec // ADR-018 opaque handle
}
// InstanceToHandle wraps *Instance into a gpucontext.Instance handle.
func InstanceToHandle(i *Instance) gpucontext.Instance {
return gpucontext.NewInstance(unsafe.Pointer(i)) //nolint:gosec // ADR-018 opaque handle
}