mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-15 08:06:19 +00:00
Let DeviceBase know about Completed and LastSubmitted command Serials
This is needed to implement the timeline fence signal tracker in the frontend Bug: dawn:26 Change-Id: Id6eb2afb81385de5093b57c5cb23ace93c8aab1b Reviewed-on: https://dawn-review.googlesource.com/c/2741 Reviewed-by: Kai Ninomiya <kainino@chromium.org> Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
179db44c25
commit
8b07e43dad
@@ -50,6 +50,17 @@ namespace dawn_native { namespace opengl {
|
||||
CollectPCIInfo();
|
||||
}
|
||||
|
||||
Device::~Device() {
|
||||
CheckPassedFences();
|
||||
ASSERT(mFencesInFlight.empty());
|
||||
|
||||
// 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;
|
||||
Tick();
|
||||
}
|
||||
|
||||
BindGroupBase* Device::CreateBindGroup(BindGroupBuilder* builder) {
|
||||
return new BindGroup(builder);
|
||||
}
|
||||
@@ -112,7 +123,47 @@ namespace dawn_native { namespace opengl {
|
||||
return new TextureView(texture, descriptor);
|
||||
}
|
||||
|
||||
void Device::SubmitFenceSync() {
|
||||
GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
||||
mLastSubmittedSerial++;
|
||||
mFencesInFlight.emplace(sync, mLastSubmittedSerial);
|
||||
}
|
||||
|
||||
Serial Device::GetCompletedCommandSerial() const {
|
||||
return mCompletedSerial;
|
||||
}
|
||||
|
||||
Serial Device::GetLastSubmittedCommandSerial() const {
|
||||
return mLastSubmittedSerial;
|
||||
}
|
||||
|
||||
void Device::TickImpl() {
|
||||
CheckPassedFences();
|
||||
}
|
||||
|
||||
void Device::CheckPassedFences() {
|
||||
while (!mFencesInFlight.empty()) {
|
||||
GLsync sync = mFencesInFlight.front().first;
|
||||
Serial fenceSerial = mFencesInFlight.front().second;
|
||||
|
||||
GLint status = 0;
|
||||
GLsizei length;
|
||||
glGetSynciv(sync, GL_SYNC_CONDITION, sizeof(GLint), &length, &status);
|
||||
ASSERT(length == 1);
|
||||
|
||||
// Fence are added in order, so we can stop searching as soon
|
||||
// as we see one that's not ready.
|
||||
if (!status) {
|
||||
return;
|
||||
}
|
||||
|
||||
glDeleteSync(sync);
|
||||
|
||||
mFencesInFlight.pop();
|
||||
|
||||
ASSERT(fenceSerial > mCompletedSerial);
|
||||
mCompletedSerial = fenceSerial;
|
||||
}
|
||||
}
|
||||
|
||||
const dawn_native::PCIInfo& Device::GetPCIInfo() const {
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
#include "glad/glad.h"
|
||||
|
||||
#include <queue>
|
||||
|
||||
// Remove windows.h macros after glad's include of windows.h
|
||||
#if defined(DAWN_PLATFORM_WINDOWS)
|
||||
# include "common/windows_with_undefs.h"
|
||||
@@ -33,6 +35,11 @@ namespace dawn_native { namespace opengl {
|
||||
class Device : public DeviceBase {
|
||||
public:
|
||||
Device();
|
||||
~Device();
|
||||
|
||||
void SubmitFenceSync();
|
||||
|
||||
// Dawn API
|
||||
BindGroupBase* CreateBindGroup(BindGroupBuilder* builder) override;
|
||||
BlendStateBase* CreateBlendState(BlendStateBuilder* builder) override;
|
||||
BufferViewBase* CreateBufferView(BufferViewBuilder* builder) override;
|
||||
@@ -44,6 +51,8 @@ namespace dawn_native { namespace opengl {
|
||||
RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override;
|
||||
SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override;
|
||||
|
||||
Serial GetCompletedCommandSerial() const final override;
|
||||
Serial GetLastSubmittedCommandSerial() const final override;
|
||||
void TickImpl() override;
|
||||
|
||||
const dawn_native::PCIInfo& GetPCIInfo() const override;
|
||||
@@ -66,6 +75,12 @@ namespace dawn_native { namespace opengl {
|
||||
const TextureViewDescriptor* descriptor) override;
|
||||
void CollectPCIInfo();
|
||||
|
||||
void CheckPassedFences();
|
||||
|
||||
Serial mCompletedSerial = 0;
|
||||
Serial mLastSubmittedSerial = 0;
|
||||
std::queue<std::pair<GLsync, Serial>> mFencesInFlight;
|
||||
|
||||
dawn_native::PCIInfo mPCIInfo;
|
||||
};
|
||||
|
||||
|
||||
@@ -23,9 +23,13 @@ namespace dawn_native { namespace opengl {
|
||||
}
|
||||
|
||||
void Queue::SubmitImpl(uint32_t numCommands, CommandBufferBase* const* commands) {
|
||||
Device* device = ToBackend(GetDevice());
|
||||
|
||||
for (uint32_t i = 0; i < numCommands; ++i) {
|
||||
ToBackend(commands[i])->Execute();
|
||||
}
|
||||
|
||||
device->SubmitFenceSync();
|
||||
}
|
||||
|
||||
}} // namespace dawn_native::opengl
|
||||
|
||||
Reference in New Issue
Block a user