internal/graphicsdriver/directx: reuse vertices/indices buffers whenever possible

This commit is contained in:
Hajime Hoshi 2023-03-23 11:34:39 +09:00
parent e5525a04d5
commit 90723025cc

View File

@ -840,7 +840,7 @@ func (g *Graphics) End(present bool) error {
return err return err
} }
g.releaseResources(g.frameIndex) g.releaseResources(g.frameIndex)
g.releaseVerticesAndIndices(g.frameIndex) g.resetVerticesAndIndices(g.frameIndex, true)
} }
g.pipelineStates.resetConstantBuffers(g.frameIndex) g.pipelineStates.resetConstantBuffers(g.frameIndex)
@ -869,7 +869,7 @@ func (g *Graphics) End(present bool) error {
} }
g.releaseResources(g.frameIndex) g.releaseResources(g.frameIndex)
g.releaseVerticesAndIndices(g.frameIndex) g.resetVerticesAndIndices(g.frameIndex, false)
g.frameStarted = false g.frameStarted = false
} }
@ -961,17 +961,21 @@ func (g *Graphics) releaseResources(frameIndex int) {
g.disposedShaders[frameIndex] = g.disposedShaders[frameIndex][:0] g.disposedShaders[frameIndex] = g.disposedShaders[frameIndex][:0]
} }
func (g *Graphics) releaseVerticesAndIndices(frameIndex int) { func (g *Graphics) resetVerticesAndIndices(frameIndex int, release bool) {
if release {
for i := range g.vertices[frameIndex] { for i := range g.vertices[frameIndex] {
g.vertices[frameIndex][i].release() g.vertices[frameIndex][i].release()
g.vertices[frameIndex][i] = nil g.vertices[frameIndex][i] = nil
} }
}
g.vertices[frameIndex] = g.vertices[frameIndex][:0] g.vertices[frameIndex] = g.vertices[frameIndex][:0]
if release {
for i := range g.indices[frameIndex] { for i := range g.indices[frameIndex] {
g.indices[frameIndex][i].release() g.indices[frameIndex][i].release()
g.indices[frameIndex][i] = nil g.indices[frameIndex][i] = nil
} }
}
g.indices[frameIndex] = g.indices[frameIndex][:0] g.indices[frameIndex] = g.indices[frameIndex][:0]
} }