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() { func (v *view) updatePresentsWithTransaction() {
pwt := v.usePresentsWithTransaction() v.ml.SetPresentsWithTransaction(v.usePresentsWithTransaction())
v.ml.SetPresentsWithTransaction(pwt) v.ml.SetMaximumDrawableCount(v.maximumDrawableCount())
// 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)
}
} }
func (v *view) colorPixelFormat() mtl.PixelFormat { func (v *view) colorPixelFormat() mtl.PixelFormat {

View File

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

View File

@ -48,6 +48,15 @@ func (v *view) usePresentsWithTransaction() bool {
return !v.vsyncDisabled && !v.fullscreen 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 ( const (
storageMode = mtl.StorageModeManaged storageMode = mtl.StorageModeManaged
resourceStorageMode = mtl.ResourceStorageModeManaged resourceStorageMode = mtl.ResourceStorageModeManaged