mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
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:
parent
5e7ec81f5c
commit
ece60af1b7
@ -1189,9 +1189,6 @@ func (g *Graphics) SetVsyncEnabled(enabled bool) {
|
||||
g.vsyncEnabled = enabled
|
||||
}
|
||||
|
||||
func (g *Graphics) SetFullscreen(fullscreen bool) {
|
||||
}
|
||||
|
||||
func (g *Graphics) NeedsRestoring() bool {
|
||||
return false
|
||||
}
|
||||
|
@ -45,7 +45,6 @@ type Graphics interface {
|
||||
NewImage(width, height int) (Image, error)
|
||||
NewScreenFramebufferImage(width, height int) (Image, error)
|
||||
SetVsyncEnabled(enabled bool)
|
||||
SetFullscreen(fullscreen bool)
|
||||
NeedsRestoring() bool
|
||||
NeedsClearingScreen() bool
|
||||
IsGL() bool
|
||||
|
@ -208,14 +208,10 @@ func (g *Graphics) flushIfNeeded(present bool) {
|
||||
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.Commit()
|
||||
if g.view.presentsWithTransaction() && present && g.screenDrawable != (ca.MetalDrawable{}) {
|
||||
g.cb.WaitUntilScheduled()
|
||||
g.screenDrawable.Present()
|
||||
}
|
||||
|
||||
for _, t := range g.tmpTextures {
|
||||
t.Release()
|
||||
@ -631,10 +627,6 @@ func (g *Graphics) SetVsyncEnabled(enabled bool) {
|
||||
g.view.setDisplaySyncEnabled(enabled)
|
||||
}
|
||||
|
||||
func (g *Graphics) SetFullscreen(fullscreen bool) {
|
||||
g.view.setFullscreen(fullscreen)
|
||||
}
|
||||
|
||||
func (g *Graphics) NeedsRestoring() bool {
|
||||
return false
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ type view struct {
|
||||
|
||||
windowChanged bool
|
||||
vsyncDisabled bool
|
||||
fullscreen bool
|
||||
|
||||
device mtl.Device
|
||||
ml ca.MetalLayer
|
||||
@ -54,22 +53,6 @@ func (v *view) setDisplaySyncEnabled(enabled bool) {
|
||||
func (v *view) forceSetDisplaySyncEnabled(enabled bool) {
|
||||
v.ml.SetDisplaySyncEnabled(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 {
|
||||
@ -96,6 +79,12 @@ func (v *view) initialize() error {
|
||||
v.forceSetDisplaySyncEnabled(!v.vsyncDisabled)
|
||||
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
|
||||
}
|
||||
|
||||
@ -107,7 +96,3 @@ func (v *view) nextDrawable() ca.MetalDrawable {
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func (v *view) presentsWithTransaction() bool {
|
||||
return v.ml.PresentsWithTransaction()
|
||||
}
|
||||
|
@ -57,15 +57,6 @@ func (v *view) update() {
|
||||
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 (
|
||||
storageMode = mtl.StorageModeShared
|
||||
resourceStorageMode = mtl.ResourceStorageModeShared
|
||||
|
@ -42,23 +42,6 @@ func (v *view) update() {
|
||||
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 (
|
||||
storageMode = mtl.StorageModeManaged
|
||||
resourceStorageMode = mtl.ResourceStorageModeManaged
|
||||
|
@ -272,10 +272,6 @@ func (g *Graphics) SetVsyncEnabled(enabled bool) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
func (g *Graphics) SetFullscreen(fullscreen bool) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
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).
|
||||
if runtime.GOOS == "js" {
|
||||
|
@ -1266,7 +1266,6 @@ func (u *userInterfaceImpl) setFullscreen(fullscreen bool) {
|
||||
if u.isFullscreen() == fullscreen {
|
||||
return
|
||||
}
|
||||
u.graphicsDriver.SetFullscreen(fullscreen)
|
||||
|
||||
// Enter the fullscreen.
|
||||
if fullscreen {
|
||||
|
Loading…
Reference in New Issue
Block a user