mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 17:05:38 +00:00
gpu/internal/rendertest: clean up headless context immediately
GPU contexts can hold on to a significant amount of resources. Clean them up immediately instead of at test cleanup. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -58,6 +58,7 @@ func BenchmarkDrawUICached(b *testing.B) {
|
|||||||
// As BenchmarkDraw but the same op.Ops every time that is not reset - this
|
// As BenchmarkDraw but the same op.Ops every time that is not reset - this
|
||||||
// should thus allow for maximal cache usage.
|
// should thus allow for maximal cache usage.
|
||||||
gtx, w, th := setupBenchmark(b)
|
gtx, w, th := setupBenchmark(b)
|
||||||
|
defer w.Release()
|
||||||
drawCore(gtx, th)
|
drawCore(gtx, th)
|
||||||
w.Frame(gtx.Ops)
|
w.Frame(gtx.Ops)
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
@@ -73,6 +74,7 @@ func BenchmarkDrawUI(b *testing.B) {
|
|||||||
// resetting the ops and drawing, similar to how a typical UI would function.
|
// resetting the ops and drawing, similar to how a typical UI would function.
|
||||||
// This will allow font caching across frames.
|
// This will allow font caching across frames.
|
||||||
gtx, w, th := setupBenchmark(b)
|
gtx, w, th := setupBenchmark(b)
|
||||||
|
defer w.Release()
|
||||||
drawCore(gtx, th)
|
drawCore(gtx, th)
|
||||||
w.Frame(gtx.Ops)
|
w.Frame(gtx.Ops)
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
@@ -95,6 +97,7 @@ func BenchmarkDrawUI(b *testing.B) {
|
|||||||
func BenchmarkDrawUITransformed(b *testing.B) {
|
func BenchmarkDrawUITransformed(b *testing.B) {
|
||||||
// Like BenchmarkDraw UI but transformed at every frame
|
// Like BenchmarkDraw UI but transformed at every frame
|
||||||
gtx, w, th := setupBenchmark(b)
|
gtx, w, th := setupBenchmark(b)
|
||||||
|
defer w.Release()
|
||||||
drawCore(gtx, th)
|
drawCore(gtx, th)
|
||||||
w.Frame(gtx.Ops)
|
w.Frame(gtx.Ops)
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
@@ -120,6 +123,7 @@ func Benchmark1000Circles(b *testing.B) {
|
|||||||
// shapes will be possible and resets buffers on each operation to prevent caching
|
// shapes will be possible and resets buffers on each operation to prevent caching
|
||||||
// between frames.
|
// between frames.
|
||||||
gtx, w, _ := setupBenchmark(b)
|
gtx, w, _ := setupBenchmark(b)
|
||||||
|
defer w.Release()
|
||||||
draw1000Circles(gtx)
|
draw1000Circles(gtx)
|
||||||
w.Frame(gtx.Ops)
|
w.Frame(gtx.Ops)
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
@@ -136,6 +140,7 @@ func Benchmark1000CirclesInstanced(b *testing.B) {
|
|||||||
// Like Benchmark1000Circles but will record them and thus allow for caching between
|
// Like Benchmark1000Circles but will record them and thus allow for caching between
|
||||||
// them.
|
// them.
|
||||||
gtx, w, _ := setupBenchmark(b)
|
gtx, w, _ := setupBenchmark(b)
|
||||||
|
defer w.Release()
|
||||||
draw1000CirclesInstanced(gtx)
|
draw1000CirclesInstanced(gtx)
|
||||||
w.Frame(gtx.Ops)
|
w.Frame(gtx.Ops)
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ func buildSquares(size int) paint.ImageOp {
|
|||||||
func drawImage(t *testing.T, size int, ops *op.Ops, draw func(o *op.Ops)) (im *image.RGBA, err error) {
|
func drawImage(t *testing.T, size int, ops *op.Ops, draw func(o *op.Ops)) (im *image.RGBA, err error) {
|
||||||
sz := image.Point{X: size, Y: size}
|
sz := image.Point{X: size, Y: size}
|
||||||
w := newWindow(t, sz.X, sz.Y)
|
w := newWindow(t, sz.X, sz.Y)
|
||||||
|
defer w.Release()
|
||||||
draw(ops)
|
draw(ops)
|
||||||
if err := w.Frame(ops); err != nil {
|
if err := w.Frame(ops); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -109,6 +110,7 @@ func multiRun(t *testing.T, frames ...frameT) {
|
|||||||
var err error
|
var err error
|
||||||
sz := image.Point{X: 128, Y: 128}
|
sz := image.Point{X: 128, Y: 128}
|
||||||
w := newWindow(t, sz.X, sz.Y)
|
w := newWindow(t, sz.X, sz.Y)
|
||||||
|
defer w.Release()
|
||||||
ops := new(op.Ops)
|
ops := new(op.Ops)
|
||||||
for i := range frames {
|
for i := range frames {
|
||||||
ops.Reset()
|
ops.Reset()
|
||||||
@@ -135,7 +137,6 @@ func multiRun(t *testing.T, frames ...frameT) {
|
|||||||
saveImage(t, name, img)
|
saveImage(t, name, img)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifyRef(t *testing.T, img *image.RGBA, frame int) (ok bool) {
|
func verifyRef(t *testing.T, img *image.RGBA, frame int) (ok bool) {
|
||||||
@@ -275,7 +276,6 @@ func newWindow(t testing.TB, width, height int) *headless.Window {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Skipf("failed to create headless window, skipping: %v", err)
|
t.Skipf("failed to create headless window, skipping: %v", err)
|
||||||
}
|
}
|
||||||
t.Cleanup(w.Release)
|
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user