internal/graphicsdriver/metal: stop using presentsWithTransaction

presentsWithTransaction caused many troubles. The critical thing was
that nextDrawable sometimes took more than one second when a user
inputs with NSTextView.

Fortunately, applications work well even without presentsWithTransaction.

Updates #1029
Updates #1196
Updates #1745
Updates #1974
This commit is contained in:
Hajime Hoshi 2022-12-27 18:53:45 +09:00
parent 5e7ec81f5c
commit ece60af1b7
8 changed files with 7 additions and 65 deletions

View File

@ -1189,9 +1189,6 @@ func (g *Graphics) SetVsyncEnabled(enabled bool) {
g.vsyncEnabled = enabled g.vsyncEnabled = enabled
} }
func (g *Graphics) SetFullscreen(fullscreen bool) {
}
func (g *Graphics) NeedsRestoring() bool { func (g *Graphics) NeedsRestoring() bool {
return false return false
} }

View File

@ -45,7 +45,6 @@ type Graphics interface {
NewImage(width, height int) (Image, error) NewImage(width, height int) (Image, error)
NewScreenFramebufferImage(width, height int) (Image, error) NewScreenFramebufferImage(width, height int) (Image, error)
SetVsyncEnabled(enabled bool) SetVsyncEnabled(enabled bool)
SetFullscreen(fullscreen bool)
NeedsRestoring() bool NeedsRestoring() bool
NeedsClearingScreen() bool NeedsClearingScreen() bool
IsGL() bool IsGL() bool

View File

@ -208,14 +208,10 @@ func (g *Graphics) flushIfNeeded(present bool) {
g.screenDrawable = g.view.nextDrawable() g.screenDrawable = g.view.nextDrawable()
} }
if !g.view.presentsWithTransaction() && present && g.screenDrawable != (ca.MetalDrawable{}) { if present && g.screenDrawable != (ca.MetalDrawable{}) {
g.cb.PresentDrawable(g.screenDrawable) g.cb.PresentDrawable(g.screenDrawable)
} }
g.cb.Commit() g.cb.Commit()
if g.view.presentsWithTransaction() && present && g.screenDrawable != (ca.MetalDrawable{}) {
g.cb.WaitUntilScheduled()
g.screenDrawable.Present()
}
for _, t := range g.tmpTextures { for _, t := range g.tmpTextures {
t.Release() t.Release()
@ -631,10 +627,6 @@ func (g *Graphics) SetVsyncEnabled(enabled bool) {
g.view.setDisplaySyncEnabled(enabled) g.view.setDisplaySyncEnabled(enabled)
} }
func (g *Graphics) SetFullscreen(fullscreen bool) {
g.view.setFullscreen(fullscreen)
}
func (g *Graphics) NeedsRestoring() bool { func (g *Graphics) NeedsRestoring() bool {
return false return false
} }

View File

@ -28,7 +28,6 @@ type view struct {
windowChanged bool windowChanged bool
vsyncDisabled bool vsyncDisabled bool
fullscreen bool
device mtl.Device device mtl.Device
ml ca.MetalLayer ml ca.MetalLayer
@ -54,22 +53,6 @@ func (v *view) setDisplaySyncEnabled(enabled bool) {
func (v *view) forceSetDisplaySyncEnabled(enabled bool) { func (v *view) forceSetDisplaySyncEnabled(enabled bool) {
v.ml.SetDisplaySyncEnabled(enabled) v.ml.SetDisplaySyncEnabled(enabled)
v.vsyncDisabled = !enabled v.vsyncDisabled = !enabled
// setting presentsWithTransaction true makes the FPS stable (#1196). We're not sure why...
v.updatePresentsWithTransaction()
}
func (v *view) setFullscreen(fullscreen bool) {
if v.fullscreen == fullscreen {
return
}
v.fullscreen = fullscreen
v.updatePresentsWithTransaction()
}
func (v *view) updatePresentsWithTransaction() {
v.ml.SetPresentsWithTransaction(v.usePresentsWithTransaction())
v.ml.SetMaximumDrawableCount(v.maximumDrawableCount())
} }
func (v *view) colorPixelFormat() mtl.PixelFormat { func (v *view) colorPixelFormat() mtl.PixelFormat {
@ -96,6 +79,12 @@ func (v *view) initialize() error {
v.forceSetDisplaySyncEnabled(!v.vsyncDisabled) v.forceSetDisplaySyncEnabled(!v.vsyncDisabled)
v.ml.SetFramebufferOnly(true) v.ml.SetFramebufferOnly(true)
// presentsWithTransaction doesn't work in the fullscreen mode (#1745, #1974).
// presentsWithTransaction doesn't work with vsync off (#1196).
// nextDrawable took more than one second if the window has other controls like NSTextView (#1029).
v.ml.SetPresentsWithTransaction(false)
v.ml.SetMaximumDrawableCount(3)
return nil return nil
} }
@ -107,7 +96,3 @@ func (v *view) nextDrawable() ca.MetalDrawable {
} }
return d return d
} }
func (v *view) presentsWithTransaction() bool {
return v.ml.PresentsWithTransaction()
}

View File

@ -57,15 +57,6 @@ func (v *view) update() {
C.setFrame(v.ml.Layer(), unsafe.Pointer(v.uiview)) C.setFrame(v.ml.Layer(), unsafe.Pointer(v.uiview))
} }
func (v *view) usePresentsWithTransaction() bool {
// Do not use presentsWithTransaction on iOS (#1799).
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

@ -42,23 +42,6 @@ func (v *view) update() {
v.windowChanged = false v.windowChanged = false
} }
func (v *view) usePresentsWithTransaction() bool {
// Disable presentsWithTransaction on the fullscreen mode (#1745, #1974).
if v.fullscreen {
return false
}
return !v.vsyncDisabled
}
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

View File

@ -272,10 +272,6 @@ func (g *Graphics) SetVsyncEnabled(enabled bool) {
// Do nothing // Do nothing
} }
func (g *Graphics) SetFullscreen(fullscreen bool) {
// Do nothing
}
func (g *Graphics) NeedsRestoring() bool { func (g *Graphics) NeedsRestoring() bool {
// Though it is possible to have a logic to restore the graphics data for GPU, do not use it for performance (#1603). // Though it is possible to have a logic to restore the graphics data for GPU, do not use it for performance (#1603).
if runtime.GOOS == "js" { if runtime.GOOS == "js" {

View File

@ -1266,7 +1266,6 @@ func (u *userInterfaceImpl) setFullscreen(fullscreen bool) {
if u.isFullscreen() == fullscreen { if u.isFullscreen() == fullscreen {
return return
} }
u.graphicsDriver.SetFullscreen(fullscreen)
// Enter the fullscreen. // Enter the fullscreen.
if fullscreen { if fullscreen {