Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion gpu/internal/d3d11/d3d11_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"image"
"math"
"math/bits"
"sync"
"unsafe"

"golang.org/x/sys/windows"
Expand Down Expand Up @@ -89,6 +90,8 @@ type Buffer struct {
immutable bool
}

var bufferPool sync.Pool = sync.Pool{New: func() any { return &Buffer{} }}

func init() {
driver.NewDirect3D11Device = newDirect3D11Device
}
Expand Down Expand Up @@ -472,7 +475,9 @@ func (b *Backend) newBuffer(typ driver.BufferBinding, size int, data []byte, imm
return nil, err
}
}
return &Buffer{backend: b, buf: buf, bind: bind, size: size, resView: resView, uaView: uaView, immutable: immutable}, nil
buffer := bufferPool.Get().(*Buffer)
*buffer = Buffer{backend: b, buf: buf, bind: bind, size: size, resView: resView, uaView: uaView, immutable: immutable}
return buffer, nil
}

func (b *Backend) NewComputeProgram(shader shader.Sources) (driver.Program, error) {
Expand Down Expand Up @@ -750,6 +755,7 @@ func (b *Buffer) Release() {
}
d3d11.IUnknownRelease(unsafe.Pointer(b.buf), b.buf.Vtbl.Release)
*b = Buffer{}
bufferPool.Put(b) // Return to pool for reuse. Note: this means that you should not use the buffer after calling Release.
}

func (t *Texture) ReadPixels(src image.Rectangle, pixels []byte, stride int) error {
Expand Down