Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
skiko
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liuqiang
skiko
Commits
0c89dfa7
Unverified
Commit
0c89dfa7
authored
Jul 07, 2023
by
Elijah Semyonov
Committed by
GitHub
Jul 07, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add overcommitment prevention mechanism (iOS) (#755)
parent
dda594ad
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
1 deletion
+11
-1
MetalRedrawer.ios.kt
.../kotlin/org/jetbrains/skiko/redrawer/MetalRedrawer.ios.kt
+11
-1
No files found.
skiko/src/iosMain/kotlin/org/jetbrains/skiko/redrawer/MetalRedrawer.ios.kt
View file @
0c89dfa7
...
@@ -17,7 +17,7 @@ import platform.Metal.MTLDeviceProtocol
...
@@ -17,7 +17,7 @@ import platform.Metal.MTLDeviceProtocol
import
platform.Metal.MTLPixelFormatBGRA8Unorm
import
platform.Metal.MTLPixelFormatBGRA8Unorm
import
platform.QuartzCore.*
import
platform.QuartzCore.*
import
platform.UIKit.window
import
platform.UIKit.window
import
platform.darwin.
NSObject
import
platform.darwin.
*
private
enum
class
DrawSchedulingState
{
private
enum
class
DrawSchedulingState
{
AVAILABLE_ON_NEXT_FRAME
,
AVAILABLE_ON_NEXT_FRAME
,
...
@@ -37,6 +37,9 @@ internal class MetalRedrawer(
...
@@ -37,6 +37,9 @@ internal class MetalRedrawer(
private
var
currentDrawable
:
CAMetalDrawableProtocol
?
=
null
private
var
currentDrawable
:
CAMetalDrawableProtocol
?
=
null
private
val
metalLayer
=
MetalLayer
()
private
val
metalLayer
=
MetalLayer
()
// Semaphore for preventing command buffers count more than swapchain size to be scheduled/executed at the same time
private
val
inflightSemaphore
=
dispatch_semaphore_create
(
metalLayer
.
maximumDrawableCount
.
toLong
())
/*
/*
* Initial value is [DrawSchedulingState.AVAILABLE_ON_NEXT_FRAME] because voluntarily dispatching a frame
* Initial value is [DrawSchedulingState.AVAILABLE_ON_NEXT_FRAME] because voluntarily dispatching a frame
* disregarding CADisplayLink timing (which is not accessible while it's paused) can cause frame drifting in worst
* disregarding CADisplayLink timing (which is not accessible while it's paused) can cause frame drifting in worst
...
@@ -105,6 +108,9 @@ internal class MetalRedrawer(
...
@@ -105,6 +108,9 @@ internal class MetalRedrawer(
fun
makeContext
()
=
DirectContext
.
makeMetal
(
device
.
objcPtr
(),
queue
.
objcPtr
())
fun
makeContext
()
=
DirectContext
.
makeMetal
(
device
.
objcPtr
(),
queue
.
objcPtr
())
fun
makeRenderTarget
(
width
:
Int
,
height
:
Int
):
BackendRenderTarget
{
fun
makeRenderTarget
(
width
:
Int
,
height
:
Int
):
BackendRenderTarget
{
// If more than swapchain size count of command buffers are inflight
// wait until one finishes work
dispatch_semaphore_wait
(
inflightSemaphore
,
DISPATCH_TIME_FOREVER
)
currentDrawable
=
metalLayer
.
nextDrawable
()
!!
currentDrawable
=
metalLayer
.
nextDrawable
()
!!
return
BackendRenderTarget
.
makeMetal
(
width
,
height
,
currentDrawable
!!
.
texture
.
objcPtr
())
return
BackendRenderTarget
.
makeMetal
(
width
,
height
,
currentDrawable
!!
.
texture
.
objcPtr
())
}
}
...
@@ -190,6 +196,10 @@ internal class MetalRedrawer(
...
@@ -190,6 +196,10 @@ internal class MetalRedrawer(
val
commandBuffer
=
queue
.
commandBuffer
()
!!
val
commandBuffer
=
queue
.
commandBuffer
()
!!
commandBuffer
.
label
=
"Present"
commandBuffer
.
label
=
"Present"
commandBuffer
.
presentDrawable
(
it
)
commandBuffer
.
presentDrawable
(
it
)
commandBuffer
.
addCompletedHandler
{
// Signal work finish, allow a new command buffer to be scheduled
dispatch_semaphore_signal
(
inflightSemaphore
)
}
commandBuffer
.
commit
()
commandBuffer
.
commit
()
currentDrawable
=
null
currentDrawable
=
null
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment