Implement WaitableEvent and WorkerTaskPool for multi-threaded tasks

This patch adds the basic implementation of WaitableEvent and
WorkerTaskPool for multi-threaded tasks in Dawn (for example, the
multi-threaded implementation of CreateReady*Pipeline()).

BUG=dawn:529
TEST=dawn_unittests

Change-Id: Ibf84348f4c0f0d26badc19ae94cd536cef89d084
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/36360
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Jiawei Shao
2021-01-20 08:56:07 +00:00
committed by Commit Bot service account
parent 311a17a8fe
commit 064f33e441
11 changed files with 312 additions and 0 deletions

View File

@@ -19,6 +19,7 @@
#include <cstddef>
#include <cstdint>
#include <memory>
#include <dawn/webgpu.h>
@@ -60,6 +61,24 @@ namespace dawn_platform {
CachingInterface& operator=(const CachingInterface&) = delete;
};
class DAWN_PLATFORM_EXPORT WaitableEvent {
public:
WaitableEvent() = default;
virtual ~WaitableEvent() = default;
virtual void Wait() = 0; // Wait for completion
virtual bool IsComplete() = 0; // Non-blocking check if the event is complete
};
using PostWorkerTaskCallback = void (*)(void* userdata);
class DAWN_PLATFORM_EXPORT WorkerTaskPool {
public:
WorkerTaskPool() = default;
virtual ~WorkerTaskPool() = default;
virtual std::unique_ptr<WaitableEvent> PostWorkerTask(PostWorkerTaskCallback,
void* userdata) = 0;
};
class DAWN_PLATFORM_EXPORT Platform {
public:
Platform();
@@ -85,6 +104,7 @@ namespace dawn_platform {
// device which uses it to persistently cache objects.
virtual CachingInterface* GetCachingInterface(const void* fingerprint,
size_t fingerprintSize);
virtual std::unique_ptr<WorkerTaskPool> CreateWorkerTaskPool();
private:
Platform(const Platform&) = delete;