gpu: fold buffer clearing into framebuffer bind

In Metal, clearing a framebuffer is most efficiently done during bind.
Modify our driver accordingly.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-08-11 15:03:45 +02:00
parent d38c78d7ac
commit 1af910959b
7 changed files with 71 additions and 61 deletions
+19 -3
View File
@@ -30,14 +30,13 @@ type Device interface {
NewFragmentShader(src shader.Sources) (FragmentShader, error)
NewPipeline(desc PipelineDesc) (Pipeline, error)
Clear(r, g, b, a float32)
Viewport(x, y, width, height int)
DrawArrays(mode DrawMode, off, count int)
DrawElements(mode DrawMode, off, count int)
BindProgram(p Program)
BindPipeline(p Pipeline)
BindFramebuffer(f Framebuffer)
BindFramebuffer(f Framebuffer, a LoadDesc)
BindTexture(unit int, t Texture)
BindVertexBuffer(b Buffer, stride, offset int)
BindIndexBuffer(b Buffer)
@@ -53,6 +52,16 @@ type Device interface {
Release()
}
type LoadDesc struct {
Action LoadAction
ClearColor struct {
R float32
G float32
B float32
A float32
}
}
type Pipeline interface {
Release()
}
@@ -89,6 +98,8 @@ type TextureFormat uint8
type BufferBinding uint8
type LoadAction uint8
type Features uint
type Caps struct {
@@ -119,7 +130,6 @@ type Buffer interface {
type Framebuffer interface {
RenderTarget
Invalidate()
Release()
ReadPixels(src image.Rectangle, pixels []byte) error
}
@@ -182,6 +192,12 @@ const (
BlendFactorDstColor
)
const (
LoadActionKeep LoadAction = iota
LoadActionClear
LoadActionInvalidate
)
var ErrContentLost = errors.New("buffer content lost")
func (f Features) Has(feats Features) bool {