forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GPU: Introduce CommandBuffer Mojo interface
This adds CommandBuffer as a new Mojo interface associated with its owning GpuChannel. There's also a corresponding CommandBufferClient associated and running in the opposite direction. Since there's a good bit of new infrastructure involved to ensure behavioral parity with the current message dispatch, this CL only migrates one message to each new interface for now. To replicate the existing scheduling behavior of messages moved to the CommandBuffer interface, a new gpu::SchedulerTaskRunner is introduced to expose a base::SequencedTaskRunner interface for a specific sequence on the gpu::Scheduler. The CommandBuffer's Mojo receiver binds using this task runner. This also requires loosening some sequence safety checks inside Mojo bindings. To wit, we want all received messages to be dispatched by a SchedulerTaskRunner, but we want to set up and tear down the receiver from tasks that are NOT run by that SchedulerTaskRunner. Since the base sequencing APIs (and in turn Mojo bindings' internal safety checks) aren't very well suited to this kind of arrangement, we have to pull a few strings: endpoints may now be bound to a sequence other than the one doing the binding (this turns out to be trivially safe to allow), and they can also be torn down from a sequence other than the one to which they're bound, provided the caller knows what they're doing and uses the dubious but aptly foreboding ResetFromAnotherSequenceUnsafe(). Bug: 1196476 Change-Id: Ie2b2cd775c271f0e9a105949e9df65b88f21ffa2 Binary-Size: New usage of associated endpoints introduces a lot of new generated code. https://crbug.com/1208544 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2863930 Commit-Queue: Ken Rockot <rockot@google.com> Reviewed-by: Sunny Sachanandani <sunnyps@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: Daniel Cheng <dcheng@chromium.org> Cr-Commit-Position: refs/heads/master@{#885034}
- Loading branch information
Showing
26 changed files
with
542 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "gpu/command_buffer/service/scheduler_task_runner.h" | ||
|
||
#include <utility> | ||
#include <vector> | ||
|
||
#include "base/bind.h" | ||
#include "base/check.h" | ||
#include "base/no_destructor.h" | ||
#include "base/threading/thread_local.h" | ||
#include "gpu/command_buffer/common/sync_token.h" | ||
#include "gpu/command_buffer/service/scheduler.h" | ||
|
||
namespace gpu { | ||
|
||
namespace { | ||
|
||
base::ThreadLocalPointer<const SchedulerTaskRunner>& | ||
GetCurrentTaskRunnerStorage() { | ||
static base::NoDestructor<base::ThreadLocalPointer<const SchedulerTaskRunner>> | ||
runner; | ||
return *runner; | ||
} | ||
|
||
void SetCurrentTaskRunner(const SchedulerTaskRunner* runner) { | ||
GetCurrentTaskRunnerStorage().Set(runner); | ||
} | ||
|
||
const SchedulerTaskRunner* GetCurrentTaskRunner() { | ||
return GetCurrentTaskRunnerStorage().Get(); | ||
} | ||
|
||
} // namespace | ||
|
||
SchedulerTaskRunner::SchedulerTaskRunner(Scheduler& scheduler, | ||
SequenceId sequence_id) | ||
: scheduler_(scheduler), sequence_id_(sequence_id) {} | ||
|
||
SchedulerTaskRunner::~SchedulerTaskRunner() = default; | ||
|
||
void SchedulerTaskRunner::ShutDown() { | ||
is_running_ = false; | ||
} | ||
|
||
bool SchedulerTaskRunner::PostDelayedTask(const base::Location& from_here, | ||
base::OnceClosure task, | ||
base::TimeDelta delay) { | ||
return PostNonNestableDelayedTask(from_here, std::move(task), delay); | ||
} | ||
|
||
bool SchedulerTaskRunner::PostNonNestableDelayedTask( | ||
const base::Location& from_here, | ||
base::OnceClosure task, | ||
base::TimeDelta delay) { | ||
if (!is_running_) | ||
return false; | ||
|
||
CHECK(delay.is_zero()); | ||
scheduler_.ScheduleTask(Scheduler::Task( | ||
sequence_id_, | ||
base::BindOnce(&SchedulerTaskRunner::RunTask, this, std::move(task)), | ||
std::vector<SyncToken>())); | ||
return true; | ||
} | ||
|
||
bool SchedulerTaskRunner::RunsTasksInCurrentSequence() const { | ||
const SchedulerTaskRunner* current = GetCurrentTaskRunner(); | ||
return current != nullptr && current->sequence_id_ == sequence_id_; | ||
} | ||
|
||
void SchedulerTaskRunner::RunTask(base::OnceClosure task) { | ||
// Scheduler doesn't nest tasks, so we don't support nesting. | ||
DCHECK(!GetCurrentTaskRunner()); | ||
SetCurrentTaskRunner(this); | ||
std::move(task).Run(); | ||
SetCurrentTaskRunner(nullptr); | ||
} | ||
|
||
} // namespace gpu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef GPU_COMMAND_BUFFER_SERVICE_SCHEDULER_TASK_RUNNER_H_ | ||
#define GPU_COMMAND_BUFFER_SERVICE_SCHEDULER_TASK_RUNNER_H_ | ||
|
||
#include "base/sequenced_task_runner.h" | ||
#include "gpu/command_buffer/service/sequence_id.h" | ||
#include "gpu/gpu_export.h" | ||
|
||
namespace gpu { | ||
|
||
class Scheduler; | ||
|
||
// A SequencedTaskRunner implementation to abstract task execution for a | ||
// specific SequenceId on the GPU Scheduler. This object does not support | ||
// delayed tasks, because the underlying Scheduler implementation does not | ||
// support scheduling delayed tasks. Also note that tasks run by this object do | ||
// not support running nested RunLoops. | ||
class GPU_EXPORT SchedulerTaskRunner : public base::SequencedTaskRunner { | ||
public: | ||
// Constructs a SchedulerTaskRunner that runs tasks on `scheduler`, on the | ||
// sequence identified by `sequence_id`. This instance must not outlive | ||
// `scheduler`. | ||
SchedulerTaskRunner(Scheduler& scheduler, SequenceId sequence_id); | ||
|
||
// Once this is called, all subsequent tasks will be rejected. | ||
void ShutDown(); | ||
|
||
// base::SequencedTaskRunner: | ||
bool PostDelayedTask(const base::Location& from_here, | ||
base::OnceClosure task, | ||
base::TimeDelta delay) override; | ||
bool PostNonNestableDelayedTask(const base::Location& from_here, | ||
base::OnceClosure task, | ||
base::TimeDelta delay) override; | ||
bool RunsTasksInCurrentSequence() const override; | ||
|
||
private: | ||
~SchedulerTaskRunner() override; | ||
|
||
void RunTask(base::OnceClosure task); | ||
|
||
Scheduler& scheduler_; | ||
const SequenceId sequence_id_; | ||
bool is_running_ = true; | ||
}; | ||
|
||
} // namespace gpu | ||
|
||
#endif // GPU_COMMAND_BUFFER_SERVICE_SCHEDULER_TASK_RUNNER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.