From 04c9a802a7ba86baed6f0dbce603d1adbf790d31 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 27 Oct 2024 00:12:56 +0900 Subject: [PATCH] ebiten: add BenchmarkBuiltinShader --- export_test.go | 6 ++++++ shader_test.go | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/export_test.go b/export_test.go index affa4ce57..cb0d08767 100644 --- a/export_test.go +++ b/export_test.go @@ -14,6 +14,12 @@ package ebiten +import "github.com/hajimehoshi/ebiten/v2/internal/builtinshader" + var ( ImageToBytes = imageToBytes ) + +func BuiltinShader(filter builtinshader.Filter, address builtinshader.Address, useColorM bool) *Shader { + return builtinShader(filter, address, useColorM) +} diff --git a/shader_test.go b/shader_test.go index e49eab1f4..954838ee5 100644 --- a/shader_test.go +++ b/shader_test.go @@ -22,6 +22,7 @@ import ( "testing" "github.com/hajimehoshi/ebiten/v2" + "github.com/hajimehoshi/ebiten/v2/internal/builtinshader" ) func TestShaderFill(t *testing.T) { @@ -2818,3 +2819,11 @@ func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 { } } } + +func BenchmarkBuiltinShader(b *testing.B) { + // Create a shader to cache the shader compilation result. + _ = ebiten.BuiltinShader(builtinshader.FilterNearest, builtinshader.AddressUnsafe, false) + for i := 0; i < b.N; i++ { + _ = ebiten.BuiltinShader(builtinshader.FilterNearest, builtinshader.AddressUnsafe, false) + } +}