internal/graphicsdriver/metal: Refactoring

This commit is contained in:
Hajime Hoshi 2021-09-18 17:22:04 +09:00
parent e98e371bb4
commit 11b9a4b161
3 changed files with 15 additions and 10 deletions

View File

@ -70,16 +70,8 @@ func (v *view) setFullscreen(fullscreen bool) {
}
func (v *view) updatePresentsWithTransaction() {
pwt := v.usePresentsWithTransaction()
v.ml.SetPresentsWithTransaction(pwt)
// When presentsWithTransaction is YES and triple buffering is enabled, nextDrawing returns immediately once every two times.
// This makes FPS doubled. To avoid this, disable the triple buffering.
if pwt {
v.ml.SetMaximumDrawableCount(2)
} else {
v.ml.SetMaximumDrawableCount(3)
}
v.ml.SetPresentsWithTransaction(v.usePresentsWithTransaction())
v.ml.SetMaximumDrawableCount(v.maximumDrawableCount())
}
func (v *view) colorPixelFormat() mtl.PixelFormat {

View File

@ -62,6 +62,10 @@ func (v *view) usePresentsWithTransaction() bool {
return false
}
func (v *view) maximumDrawableCount() int {
return 3
}
const (
storageMode = mtl.StorageModeShared
resourceStorageMode = mtl.ResourceStorageModeShared

View File

@ -48,6 +48,15 @@ func (v *view) usePresentsWithTransaction() bool {
return !v.vsyncDisabled && !v.fullscreen
}
func (v *view) maximumDrawableCount() int {
// When presentsWithTransaction is YES and triple buffering is enabled, nextDrawing returns immediately once every two times.
// This makes FPS doubled. To avoid this, disable the triple buffering.
if v.usePresentsWithTransaction() {
return 2
}
return 3
}
const (
storageMode = mtl.StorageModeManaged
resourceStorageMode = mtl.ResourceStorageModeManaged