Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Suyu
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Suyu
Commits
3f261f22
There was an error fetching the commit references. Please try again later.
Commit
3f261f22
authored
2 years ago
by
Liam
Browse files
Options
Downloads
Patches
Plain Diff
vk_scheduler: split work queue waits and execution waits
parent
ec4e2d1f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/video_core/renderer_vulkan/vk_scheduler.cpp
+59
-25
59 additions, 25 deletions
src/video_core/renderer_vulkan/vk_scheduler.cpp
src/video_core/renderer_vulkan/vk_scheduler.h
+3
-3
3 additions, 3 deletions
src/video_core/renderer_vulkan/vk_scheduler.h
with
62 additions
and
28 deletions
src/video_core/renderer_vulkan/vk_scheduler.cpp
+
59
−
25
View file @
3f261f22
...
@@ -47,14 +47,15 @@ Scheduler::Scheduler(const Device& device_, StateTracker& state_tracker_)
...
@@ -47,14 +47,15 @@ Scheduler::Scheduler(const Device& device_, StateTracker& state_tracker_)
Scheduler
::~
Scheduler
()
=
default
;
Scheduler
::~
Scheduler
()
=
default
;
void
Scheduler
::
Flush
(
VkSemaphore
signal_semaphore
,
VkSemaphore
wait_semaphore
)
{
void
Scheduler
::
Flush
(
VkSemaphore
signal_semaphore
,
VkSemaphore
wait_semaphore
)
{
// When flushing, we only send data to the worker thread; no waiting is necessary.
SubmitExecution
(
signal_semaphore
,
wait_semaphore
);
SubmitExecution
(
signal_semaphore
,
wait_semaphore
);
AllocateNewContext
();
AllocateNewContext
();
}
}
void
Scheduler
::
Finish
(
VkSemaphore
signal_semaphore
,
VkSemaphore
wait_semaphore
)
{
void
Scheduler
::
Finish
(
VkSemaphore
signal_semaphore
,
VkSemaphore
wait_semaphore
)
{
// When finishing, we need to wait for the submission to have executed on the device.
const
u64
presubmit_tick
=
CurrentTick
();
const
u64
presubmit_tick
=
CurrentTick
();
SubmitExecution
(
signal_semaphore
,
wait_semaphore
);
SubmitExecution
(
signal_semaphore
,
wait_semaphore
);
WaitWorker
();
Wait
(
presubmit_tick
);
Wait
(
presubmit_tick
);
AllocateNewContext
();
AllocateNewContext
();
}
}
...
@@ -63,8 +64,13 @@ void Scheduler::WaitWorker() {
...
@@ -63,8 +64,13 @@ void Scheduler::WaitWorker() {
MICROPROFILE_SCOPE
(
Vulkan_WaitForWorker
);
MICROPROFILE_SCOPE
(
Vulkan_WaitForWorker
);
DispatchWork
();
DispatchWork
();
std
::
unique_lock
lock
{
work_mutex
};
// Ensure the queue is drained.
wait_cv
.
wait
(
lock
,
[
this
]
{
return
work_queue
.
empty
();
});
std
::
unique_lock
ql
{
queue_mutex
};
event_cv
.
wait
(
ql
,
[
this
]
{
return
work_queue
.
empty
();
});
// Now wait for execution to finish.
// This needs to be done in the same order as WorkerThread.
std
::
unique_lock
el
{
execution_mutex
};
}
}
void
Scheduler
::
DispatchWork
()
{
void
Scheduler
::
DispatchWork
()
{
...
@@ -72,10 +78,10 @@ void Scheduler::DispatchWork() {
...
@@ -72,10 +78,10 @@ void Scheduler::DispatchWork() {
return
;
return
;
}
}
{
{
std
::
scoped_lock
lock
{
work
_mutex
};
std
::
scoped_lock
ql
{
queue
_mutex
};
work_queue
.
push
(
std
::
move
(
chunk
));
work_queue
.
push
(
std
::
move
(
chunk
));
}
}
work
_cv
.
notify_
one
();
event
_cv
.
notify_
all
();
AcquireNewChunk
();
AcquireNewChunk
();
}
}
...
@@ -137,30 +143,55 @@ bool Scheduler::UpdateRescaling(bool is_rescaling) {
...
@@ -137,30 +143,55 @@ bool Scheduler::UpdateRescaling(bool is_rescaling) {
void
Scheduler
::
WorkerThread
(
std
::
stop_token
stop_token
)
{
void
Scheduler
::
WorkerThread
(
std
::
stop_token
stop_token
)
{
Common
::
SetCurrentThreadName
(
"VulkanWorker"
);
Common
::
SetCurrentThreadName
(
"VulkanWorker"
);
do
{
const
auto
TryPopQueue
{[
this
](
auto
&
work
)
->
bool
{
if
(
work_queue
.
empty
())
{
return
false
;
}
work
=
std
::
move
(
work_queue
.
front
());
work_queue
.
pop
();
event_cv
.
notify_all
();
return
true
;
}};
while
(
!
stop_token
.
stop_requested
())
{
std
::
unique_ptr
<
CommandChunk
>
work
;
std
::
unique_ptr
<
CommandChunk
>
work
;
bool
has_submit
{
false
};
{
{
std
::
unique_lock
lock
{
work_mutex
};
std
::
unique_lock
lk
{
queue_mutex
};
if
(
work_queue
.
empty
())
{
wait_cv
.
notify_all
();
// Wait for work.
}
Common
::
CondvarWait
(
event_cv
,
lk
,
stop_token
,
[
&
]
{
return
TryPopQueue
(
work
);
});
Common
::
CondvarWait
(
work_cv
,
lock
,
stop_token
,
[
&
]
{
return
!
work_queue
.
empty
();
});
// If we've been asked to stop, we're done.
if
(
stop_token
.
stop_requested
())
{
if
(
stop_token
.
stop_requested
())
{
continue
;
return
;
}
}
work
=
std
::
move
(
work_queue
.
front
());
work_queue
.
pop
();
has_submit
=
work
->
HasSubmit
();
// Exchange lock ownership so that we take the execution lock before
// the queue lock goes out of scope. This allows us to force execution
// to complete in the next step.
std
::
exchange
(
lk
,
std
::
unique_lock
{
execution_mutex
});
// Perform the work, tracking whether the chunk was a submission
// before executing.
const
bool
has_submit
=
work
->
HasSubmit
();
work
->
ExecuteAll
(
current_cmdbuf
);
work
->
ExecuteAll
(
current_cmdbuf
);
// If the chunk was a submission, reallocate the command buffer.
if
(
has_submit
)
{
AllocateWorkerCommandBuffer
();
}
}
}
if
(
has_submit
)
{
AllocateWorkerCommandBuffer
();
{
std
::
scoped_lock
rl
{
reserve_mutex
};
// Recycle the chunk back to the reserve.
chunk_reserve
.
emplace_back
(
std
::
move
(
work
));
}
}
std
::
scoped_lock
reserve_lock
{
reserve_mutex
};
}
chunk_reserve
.
push_back
(
std
::
move
(
work
));
}
while
(
!
stop_token
.
stop_requested
());
}
}
void
Scheduler
::
AllocateWorkerCommandBuffer
()
{
void
Scheduler
::
AllocateWorkerCommandBuffer
()
{
...
@@ -289,13 +320,16 @@ void Scheduler::EndRenderPass() {
...
@@ -289,13 +320,16 @@ void Scheduler::EndRenderPass() {
}
}
void
Scheduler
::
AcquireNewChunk
()
{
void
Scheduler
::
AcquireNewChunk
()
{
std
::
scoped_lock
lock
{
reserve_mutex
};
std
::
scoped_lock
rl
{
reserve_mutex
};
if
(
chunk_reserve
.
empty
())
{
if
(
chunk_reserve
.
empty
())
{
// If we don't have anything reserved, we need to make a new chunk.
chunk
=
std
::
make_unique
<
CommandChunk
>
();
chunk
=
std
::
make_unique
<
CommandChunk
>
();
return
;
}
else
{
// Otherwise, we can just take from the reserve.
chunk
=
std
::
make_unique
<
CommandChunk
>
();
chunk_reserve
.
pop_back
();
}
}
chunk
=
std
::
move
(
chunk_reserve
.
back
());
chunk_reserve
.
pop_back
();
}
}
}
// namespace Vulkan
}
// namespace Vulkan
This diff is collapsed.
Click to expand it.
src/video_core/renderer_vulkan/vk_scheduler.h
+
3
−
3
View file @
3f261f22
...
@@ -232,10 +232,10 @@ private:
...
@@ -232,10 +232,10 @@ private:
std
::
queue
<
std
::
unique_ptr
<
CommandChunk
>>
work_queue
;
std
::
queue
<
std
::
unique_ptr
<
CommandChunk
>>
work_queue
;
std
::
vector
<
std
::
unique_ptr
<
CommandChunk
>>
chunk_reserve
;
std
::
vector
<
std
::
unique_ptr
<
CommandChunk
>>
chunk_reserve
;
std
::
mutex
execution_mutex
;
std
::
mutex
reserve_mutex
;
std
::
mutex
reserve_mutex
;
std
::
mutex
work_mutex
;
std
::
mutex
queue_mutex
;
std
::
condition_variable_any
work_cv
;
std
::
condition_variable_any
event_cv
;
std
::
condition_variable
wait_cv
;
std
::
jthread
worker_thread
;
std
::
jthread
worker_thread
;
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment