mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 18:29:23 +00:00
Refactor Serial tracking to be owned by Device frontend.
Move mCompletedSerial and mLastSubmittedSerial to Device frontend and add getters and setters for the device backend to access such. This is to aid the Device in taking more ownership of Serials and Ticking. Bug: dawn:400 Change-Id: Ifa53ac294a871e484716842a3d212373b57847c4 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/20480 Commit-Queue: Natasha Lee <natlee@microsoft.com> Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
4f3811c064
commit
351c95a477
@@ -147,46 +147,37 @@ namespace dawn_native { namespace opengl {
|
||||
|
||||
void Device::SubmitFenceSync() {
|
||||
GLsync sync = gl.FenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
||||
mLastSubmittedSerial++;
|
||||
mFencesInFlight.emplace(sync, mLastSubmittedSerial);
|
||||
}
|
||||
|
||||
Serial Device::GetCompletedCommandSerial() const {
|
||||
return mCompletedSerial;
|
||||
}
|
||||
|
||||
Serial Device::GetLastSubmittedCommandSerial() const {
|
||||
return mLastSubmittedSerial;
|
||||
}
|
||||
|
||||
Serial Device::GetPendingCommandSerial() const {
|
||||
return mLastSubmittedSerial + 1;
|
||||
IncrementLastSubmittedCommandSerial();
|
||||
mFencesInFlight.emplace(sync, GetLastSubmittedCommandSerial());
|
||||
}
|
||||
|
||||
MaybeError Device::TickImpl() {
|
||||
CheckPassedFences();
|
||||
CheckPassedSerials();
|
||||
return {};
|
||||
}
|
||||
|
||||
void Device::CheckPassedFences() {
|
||||
Serial Device::CheckAndUpdateCompletedSerials() {
|
||||
Serial fenceSerial = 0;
|
||||
while (!mFencesInFlight.empty()) {
|
||||
GLsync sync = mFencesInFlight.front().first;
|
||||
Serial fenceSerial = mFencesInFlight.front().second;
|
||||
Serial tentativeSerial = mFencesInFlight.front().second;
|
||||
|
||||
// Fence are added in order, so we can stop searching as soon
|
||||
// as we see one that's not ready.
|
||||
GLenum result = gl.ClientWaitSync(sync, GL_SYNC_FLUSH_COMMANDS_BIT, 0);
|
||||
if (result == GL_TIMEOUT_EXPIRED) {
|
||||
continue;
|
||||
return fenceSerial;
|
||||
}
|
||||
// Update fenceSerial since fence is ready.
|
||||
fenceSerial = tentativeSerial;
|
||||
|
||||
gl.DeleteSync(sync);
|
||||
|
||||
mFencesInFlight.pop();
|
||||
|
||||
ASSERT(fenceSerial > mCompletedSerial);
|
||||
mCompletedSerial = fenceSerial;
|
||||
ASSERT(fenceSerial > GetCompletedCommandSerial());
|
||||
}
|
||||
return fenceSerial;
|
||||
}
|
||||
|
||||
ResultOrError<std::unique_ptr<StagingBufferBase>> Device::CreateStagingBuffer(size_t size) {
|
||||
@@ -207,14 +198,17 @@ namespace dawn_native { namespace opengl {
|
||||
// Some operations might have been started since the last submit and waiting
|
||||
// on a serial that doesn't have a corresponding fence enqueued. Force all
|
||||
// operations to look as if they were completed (because they were).
|
||||
mCompletedSerial = mLastSubmittedSerial + 1;
|
||||
AssumeCommandsComplete();
|
||||
}
|
||||
|
||||
MaybeError Device::WaitForIdleForDestruction() {
|
||||
gl.Finish();
|
||||
CheckPassedFences();
|
||||
CheckPassedSerials();
|
||||
ASSERT(mFencesInFlight.empty());
|
||||
Tick();
|
||||
|
||||
// Force all operations to look as if they were completed
|
||||
AssumeCommandsComplete();
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
@@ -52,9 +52,6 @@ namespace dawn_native { namespace opengl {
|
||||
CommandBufferBase* CreateCommandBuffer(CommandEncoder* encoder,
|
||||
const CommandBufferDescriptor* descriptor) override;
|
||||
|
||||
Serial GetCompletedCommandSerial() const final override;
|
||||
Serial GetLastSubmittedCommandSerial() const final override;
|
||||
Serial GetPendingCommandSerial() const override;
|
||||
MaybeError TickImpl() override;
|
||||
|
||||
ResultOrError<std::unique_ptr<StagingBufferBase>> CreateStagingBuffer(size_t size) override;
|
||||
@@ -96,12 +93,10 @@ namespace dawn_native { namespace opengl {
|
||||
const TextureViewDescriptor* descriptor) override;
|
||||
|
||||
void InitTogglesFromDriver();
|
||||
void CheckPassedFences();
|
||||
Serial CheckAndUpdateCompletedSerials() override;
|
||||
void ShutDownImpl() override;
|
||||
MaybeError WaitForIdleForDestruction() override;
|
||||
|
||||
Serial mCompletedSerial = 0;
|
||||
Serial mLastSubmittedSerial = 0;
|
||||
std::queue<std::pair<GLsync, Serial>> mFencesInFlight;
|
||||
|
||||
GLFormatTable mFormatTable;
|
||||
|
||||
Reference in New Issue
Block a user