-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuffer.go
More file actions
47 lines (39 loc) · 1 KB
/
buffer.go
File metadata and controls
47 lines (39 loc) · 1 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
package wgpu
import (
"github.com/gogpu/wgpu/core"
"github.com/gogpu/wgpu/hal"
)
// Buffer represents a GPU buffer.
type Buffer struct {
core *core.Buffer
device *Device
released bool
}
// Size returns the buffer size in bytes.
func (b *Buffer) Size() uint64 { return b.core.Size() }
// Usage returns the buffer's usage flags.
func (b *Buffer) Usage() BufferUsage { return b.core.Usage() }
// Label returns the buffer's debug label.
func (b *Buffer) Label() string { return b.core.Label() }
// Release destroys the buffer.
func (b *Buffer) Release() {
if b.released {
return
}
b.released = true
b.core.Destroy()
}
// coreBuffer returns the underlying core.Buffer.
func (b *Buffer) coreBuffer() *core.Buffer { return b.core }
// halBuffer returns the underlying HAL buffer.
func (b *Buffer) halBuffer() hal.Buffer {
if b.core == nil || b.device == nil {
return nil
}
if !b.core.HasHAL() {
return nil
}
guard := b.device.core.SnatchLock().Read()
defer guard.Release()
return b.core.Raw(guard)
}