Avoid redundant creation of ComputePipelineBase in GetCachedComputePipeline

This patch removes a redundant creation of ComputePipelineBase object
in GetCachedComputePipeline(). Instead, we directly compute the blueprint
hash from the uninitialized backend compute pipeline object.

BUG=dawn:529
TEST=dawn_end2end_tests

Change-Id: I9b982664aa140ab385418a202270b9988cfcb9f3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/66221
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Jiawei Shao 2021-10-13 00:43:05 +00:00 committed by Dawn LUCI CQ
parent d174cef8fa
commit 8fd1eb5443
26 changed files with 177 additions and 219 deletions

View File

@ -46,6 +46,7 @@ namespace dawn_native {
{{SingleShaderStage::Compute, descriptor->compute.module,
descriptor->compute.entryPoint, descriptor->compute.constantCount,
descriptor->compute.constants}}) {
SetContentHash(ComputeContentHash());
}
ComputePipelineBase::ComputePipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag)
@ -59,13 +60,21 @@ namespace dawn_native {
}
}
MaybeError ComputePipelineBase::Initialize() {
return {};
}
// static
ComputePipelineBase* ComputePipelineBase::MakeError(DeviceBase* device) {
return new ComputePipelineBase(device, ObjectBase::kError);
class ErrorComputePipeline final : public ComputePipelineBase {
public:
ErrorComputePipeline(DeviceBase* device)
: ComputePipelineBase(device, ObjectBase::kError) {
}
MaybeError Initialize() override {
UNREACHABLE();
return {};
}
};
return new ErrorComputePipeline(device);
}
ObjectType ComputePipelineBase::GetType() const {

View File

@ -43,11 +43,6 @@ namespace dawn_native {
private:
ComputePipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag);
// CreateComputePipelineAsyncTask is declared as a friend of ComputePipelineBase as it
// needs to call the private member function ComputePipelineBase::Initialize().
friend class CreateComputePipelineAsyncTask;
virtual MaybeError Initialize();
};
} // namespace dawn_native

View File

@ -103,11 +103,9 @@ namespace dawn_native {
CreateComputePipelineAsyncTask::CreateComputePipelineAsyncTask(
Ref<ComputePipelineBase> nonInitializedComputePipeline,
size_t blueprintHash,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata)
: mComputePipeline(std::move(nonInitializedComputePipeline)),
mBlueprintHash(blueprintHash),
mCallback(callback),
mUserdata(userdata) {
ASSERT(mComputePipeline != nullptr);
@ -122,7 +120,7 @@ namespace dawn_native {
}
mComputePipeline->GetDevice()->AddComputePipelineAsyncCallbackTask(
mComputePipeline, errorMessage, mCallback, mUserdata, mBlueprintHash);
mComputePipeline, errorMessage, mCallback, mUserdata);
}
void CreateComputePipelineAsyncTask::RunAsync(

View File

@ -72,7 +72,6 @@ namespace dawn_native {
class CreateComputePipelineAsyncTask {
public:
CreateComputePipelineAsyncTask(Ref<ComputePipelineBase> nonInitializedComputePipeline,
size_t blueprintHash,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata);
@ -82,7 +81,6 @@ namespace dawn_native {
private:
Ref<ComputePipelineBase> mComputePipeline;
size_t mBlueprintHash;
WGPUCreateComputePipelineAsyncCallback mCallback;
void* mUserdata;
};

View File

@ -678,20 +678,15 @@ namespace dawn_native {
return mEmptyBindGroupLayout.Get();
}
std::pair<Ref<ComputePipelineBase>, size_t> DeviceBase::GetCachedComputePipeline(
const ComputePipelineDescriptor* descriptor) {
ComputePipelineBase blueprint(this, descriptor);
const size_t blueprintHash = blueprint.ComputeContentHash();
blueprint.SetContentHash(blueprintHash);
Ref<ComputePipelineBase> result;
auto iter = mCaches->computePipelines.find(&blueprint);
Ref<ComputePipelineBase> DeviceBase::GetCachedComputePipeline(
ComputePipelineBase* uninitializedComputePipeline) {
Ref<ComputePipelineBase> cachedPipeline;
auto iter = mCaches->computePipelines.find(uninitializedComputePipeline);
if (iter != mCaches->computePipelines.end()) {
result = *iter;
cachedPipeline = *iter;
}
return std::make_pair(result, blueprintHash);
return cachedPipeline;
}
Ref<RenderPipelineBase> DeviceBase::GetCachedRenderPipeline(
@ -705,9 +700,7 @@ namespace dawn_native {
}
Ref<ComputePipelineBase> DeviceBase::AddOrGetCachedComputePipeline(
Ref<ComputePipelineBase> computePipeline,
size_t blueprintHash) {
computePipeline->SetContentHash(blueprintHash);
Ref<ComputePipelineBase> computePipeline) {
auto insertion = mCaches->computePipelines.insert(computePipeline.Get());
if (insertion.second) {
computePipeline->SetIsCachedReference();
@ -1226,15 +1219,16 @@ namespace dawn_native {
DAWN_TRY_ASSIGN(layoutRef, ValidateLayoutAndGetComputePipelineDescriptorWithDefaults(
this, *descriptor, &appliedDescriptor));
auto pipelineAndBlueprintFromCache = GetCachedComputePipeline(&appliedDescriptor);
if (pipelineAndBlueprintFromCache.first.Get() != nullptr) {
return std::move(pipelineAndBlueprintFromCache.first);
Ref<ComputePipelineBase> uninitializedComputePipeline =
CreateUninitializedComputePipelineImpl(&appliedDescriptor);
Ref<ComputePipelineBase> cachedComputePipeline =
GetCachedComputePipeline(uninitializedComputePipeline.Get());
if (cachedComputePipeline.Get() != nullptr) {
return cachedComputePipeline;
}
Ref<ComputePipelineBase> backendObj;
DAWN_TRY_ASSIGN(backendObj, CreateComputePipelineImpl(&appliedDescriptor));
size_t blueprintHash = pipelineAndBlueprintFromCache.second;
return AddOrGetCachedComputePipeline(backendObj, blueprintHash);
DAWN_TRY(uninitializedComputePipeline->Initialize());
return AddOrGetCachedComputePipeline(std::move(uninitializedComputePipeline));
}
MaybeError DeviceBase::CreateComputePipelineAsync(
@ -1251,38 +1245,42 @@ namespace dawn_native {
DAWN_TRY_ASSIGN(layoutRef, ValidateLayoutAndGetComputePipelineDescriptorWithDefaults(
this, *descriptor, &appliedDescriptor));
Ref<ComputePipelineBase> uninitializedComputePipeline =
CreateUninitializedComputePipelineImpl(&appliedDescriptor);
// Call the callback directly when we can get a cached compute pipeline object.
auto pipelineAndBlueprintFromCache = GetCachedComputePipeline(&appliedDescriptor);
if (pipelineAndBlueprintFromCache.first.Get() != nullptr) {
Ref<ComputePipelineBase> result = std::move(pipelineAndBlueprintFromCache.first);
Ref<ComputePipelineBase> cachedComputePipeline =
GetCachedComputePipeline(uninitializedComputePipeline.Get());
if (cachedComputePipeline.Get() != nullptr) {
callback(WGPUCreatePipelineAsyncStatus_Success,
reinterpret_cast<WGPUComputePipeline>(result.Detach()), "", userdata);
reinterpret_cast<WGPUComputePipeline>(cachedComputePipeline.Detach()), "",
userdata);
} else {
// Otherwise we will create the pipeline object in CreateComputePipelineAsyncImpl(),
// where the pipeline object may be created asynchronously and the result will be saved
// to mCreatePipelineAsyncTracker.
const size_t blueprintHash = pipelineAndBlueprintFromCache.second;
CreateComputePipelineAsyncImpl(&appliedDescriptor, blueprintHash, callback, userdata);
// Otherwise we will create the pipeline object in InitializeComputePipelineAsyncImpl(),
// where the pipeline object may be initialized asynchronously and the result will be
// saved to mCreatePipelineAsyncTracker.
InitializeComputePipelineAsyncImpl(std::move(uninitializedComputePipeline), callback,
userdata);
}
return {};
}
// This function is overwritten with the async version on the backends that supports creating
// compute pipeline asynchronously.
void DeviceBase::CreateComputePipelineAsyncImpl(const ComputePipelineDescriptor* descriptor,
size_t blueprintHash,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) {
// This function is overwritten with the async version on the backends that supports
// initializing compute pipelines asynchronously.
void DeviceBase::InitializeComputePipelineAsyncImpl(
Ref<ComputePipelineBase> computePipeline,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) {
Ref<ComputePipelineBase> result;
std::string errorMessage;
auto resultOrError = CreateComputePipelineImpl(descriptor);
if (resultOrError.IsError()) {
std::unique_ptr<ErrorData> error = resultOrError.AcquireError();
MaybeError maybeError = computePipeline->Initialize();
if (maybeError.IsError()) {
std::unique_ptr<ErrorData> error = maybeError.AcquireError();
errorMessage = error->GetMessage();
} else {
result = AddOrGetCachedComputePipeline(resultOrError.AcquireSuccess(), blueprintHash);
result = AddOrGetCachedComputePipeline(std::move(computePipeline));
}
std::unique_ptr<CreateComputePipelineAsyncCallbackTask> callbackTask =
@ -1305,7 +1303,7 @@ namespace dawn_native {
std::unique_ptr<ErrorData> error = maybeError.AcquireError();
errorMessage = error->GetMessage();
} else {
result = AddOrGetCachedRenderPipeline(renderPipeline);
result = AddOrGetCachedRenderPipeline(std::move(renderPipeline));
}
std::unique_ptr<CreateRenderPipelineAsyncCallbackTask> callbackTask =
@ -1367,7 +1365,7 @@ namespace dawn_native {
this, *descriptor, &appliedDescriptor));
Ref<RenderPipelineBase> uninitializedRenderPipeline =
CreateUninitializedRenderPipeline(&appliedDescriptor);
CreateUninitializedRenderPipelineImpl(&appliedDescriptor);
Ref<RenderPipelineBase> cachedRenderPipeline =
GetCachedRenderPipeline(uninitializedRenderPipeline.Get());
@ -1395,7 +1393,7 @@ namespace dawn_native {
this, *descriptor, &appliedDescriptor));
Ref<RenderPipelineBase> uninitializedRenderPipeline =
CreateUninitializedRenderPipeline(&appliedDescriptor);
CreateUninitializedRenderPipelineImpl(&appliedDescriptor);
// Call the callback directly when we can get a cached render pipeline object.
Ref<RenderPipelineBase> cachedRenderPipeline =
@ -1578,53 +1576,31 @@ namespace dawn_native {
return mWorkerTaskPool.get();
}
Ref<RenderPipelineBase> DeviceBase::CreateUninitializedRenderPipeline(
const RenderPipelineDescriptor* descriptor) {
return CreateUninitializedRenderPipelineImpl(descriptor);
}
void DeviceBase::AddComputePipelineAsyncCallbackTask(
Ref<ComputePipelineBase> pipeline,
std::string errorMessage,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata,
size_t blueprintHash) {
void* userdata) {
// CreateComputePipelineAsyncWaitableCallbackTask is declared as an internal class as it
// needs to call the private member function DeviceBase::AddOrGetCachedComputePipeline().
struct CreateComputePipelineAsyncWaitableCallbackTask final
: CreateComputePipelineAsyncCallbackTask {
CreateComputePipelineAsyncWaitableCallbackTask(
Ref<ComputePipelineBase> pipeline,
std::string errorMessage,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata,
size_t blueprintHash)
: CreateComputePipelineAsyncCallbackTask(std::move(pipeline),
errorMessage,
callback,
userdata),
mBlueprintHash(blueprintHash) {
}
using CreateComputePipelineAsyncCallbackTask::CreateComputePipelineAsyncCallbackTask;
void Finish() final {
// TODO(dawn:529): call AddOrGetCachedComputePipeline() asynchronously in
// CreateComputePipelineAsyncTaskImpl::Run() when the front-end pipeline cache is
// thread-safe.
if (mPipeline.Get() != nullptr) {
mPipeline = mPipeline->GetDevice()->AddOrGetCachedComputePipeline(
mPipeline, mBlueprintHash);
mPipeline = mPipeline->GetDevice()->AddOrGetCachedComputePipeline(mPipeline);
}
CreateComputePipelineAsyncCallbackTask::Finish();
}
private:
size_t mBlueprintHash;
};
mCallbackTaskManager->AddCallbackTask(
std::make_unique<CreateComputePipelineAsyncWaitableCallbackTask>(
std::move(pipeline), errorMessage, callback, userdata, blueprintHash));
std::move(pipeline), errorMessage, callback, userdata));
}
void DeviceBase::AddRenderPipelineAsyncCallbackTask(

View File

@ -342,8 +342,7 @@ namespace dawn_native {
void AddComputePipelineAsyncCallbackTask(Ref<ComputePipelineBase> pipeline,
std::string errorMessage,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata,
size_t blueprintHash);
void* userdata);
void AddRenderPipelineAsyncCallbackTask(Ref<RenderPipelineBase> pipeline,
std::string errorMessage,
WGPUCreateRenderPipelineAsyncCallback callback,
@ -376,14 +375,10 @@ namespace dawn_native {
PipelineCompatibilityToken pipelineCompatibilityToken) = 0;
virtual ResultOrError<Ref<BufferBase>> CreateBufferImpl(
const BufferDescriptor* descriptor) = 0;
virtual ResultOrError<Ref<ComputePipelineBase>> CreateComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) = 0;
virtual ResultOrError<Ref<PipelineLayoutBase>> CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) = 0;
virtual ResultOrError<Ref<QuerySetBase>> CreateQuerySetImpl(
const QuerySetDescriptor* descriptor) = 0;
virtual Ref<RenderPipelineBase> CreateUninitializedRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) = 0;
virtual ResultOrError<Ref<SamplerBase>> CreateSamplerImpl(
const SamplerDescriptor* descriptor) = 0;
virtual ResultOrError<Ref<ShaderModuleBase>> CreateShaderModuleImpl(
@ -401,6 +396,10 @@ namespace dawn_native {
virtual ResultOrError<Ref<TextureViewBase>> CreateTextureViewImpl(
TextureBase* texture,
const TextureViewDescriptor* descriptor) = 0;
virtual Ref<ComputePipelineBase> CreateUninitializedComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) = 0;
virtual Ref<RenderPipelineBase> CreateUninitializedRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) = 0;
virtual void SetLabelImpl();
virtual MaybeError TickImpl() = 0;
@ -408,21 +407,18 @@ namespace dawn_native {
ResultOrError<Ref<BindGroupLayoutBase>> CreateEmptyBindGroupLayout();
std::pair<Ref<ComputePipelineBase>, size_t> GetCachedComputePipeline(
const ComputePipelineDescriptor* descriptor);
Ref<ComputePipelineBase> GetCachedComputePipeline(
ComputePipelineBase* uninitializedComputePipeline);
Ref<RenderPipelineBase> GetCachedRenderPipeline(
RenderPipelineBase* uninitializedRenderPipeline);
Ref<ComputePipelineBase> AddOrGetCachedComputePipeline(
Ref<ComputePipelineBase> computePipeline,
size_t blueprintHash);
Ref<ComputePipelineBase> computePipeline);
Ref<RenderPipelineBase> AddOrGetCachedRenderPipeline(
Ref<RenderPipelineBase> renderPipeline);
virtual void CreateComputePipelineAsyncImpl(const ComputePipelineDescriptor* descriptor,
size_t blueprintHash,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata);
Ref<RenderPipelineBase> CreateUninitializedRenderPipeline(
const RenderPipelineDescriptor* descriptor);
virtual void InitializeComputePipelineAsyncImpl(
Ref<ComputePipelineBase> computePipeline,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata);
virtual void InitializeRenderPipelineAsyncImpl(
Ref<RenderPipelineBase> renderPipeline,
WGPUCreateRenderPipelineAsyncCallback callback,

View File

@ -66,6 +66,9 @@ namespace dawn_native {
// Implementation of the API entrypoint. Do not use in a reentrant manner.
BindGroupLayoutBase* APIGetBindGroupLayout(uint32_t groupIndex);
// Initialize() should only be called once by the frontend.
virtual MaybeError Initialize() = 0;
protected:
PipelineBase(DeviceBase* device,
PipelineLayoutBase* layout,

View File

@ -105,9 +105,6 @@ namespace dawn_native {
bool operator()(const RenderPipelineBase* a, const RenderPipelineBase* b) const;
};
// Initialize() should only be called once by the frontend.
virtual MaybeError Initialize() = 0;
private:
RenderPipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag);

View File

@ -24,12 +24,10 @@
namespace dawn_native { namespace d3d12 {
ResultOrError<Ref<ComputePipeline>> ComputePipeline::Create(
Ref<ComputePipeline> ComputePipeline::CreateUninitialized(
Device* device,
const ComputePipelineDescriptor* descriptor) {
Ref<ComputePipeline> pipeline = AcquireRef(new ComputePipeline(device, descriptor));
DAWN_TRY(pipeline->Initialize());
return pipeline;
return AcquireRef(new ComputePipeline(device, descriptor));
}
MaybeError ComputePipeline::Initialize() {
@ -77,14 +75,11 @@ namespace dawn_native { namespace d3d12 {
GetLabel());
}
void ComputePipeline::CreateAsync(Device* device,
const ComputePipelineDescriptor* descriptor,
size_t blueprintHash,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) {
Ref<ComputePipeline> pipeline = AcquireRef(new ComputePipeline(device, descriptor));
void ComputePipeline::InitializeAsync(Ref<ComputePipelineBase> computePipeline,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) {
std::unique_ptr<CreateComputePipelineAsyncTask> asyncTask =
std::make_unique<CreateComputePipelineAsyncTask>(pipeline, blueprintHash, callback,
std::make_unique<CreateComputePipelineAsyncTask>(std::move(computePipeline), callback,
userdata);
CreateComputePipelineAsyncTask::RunAsync(std::move(asyncTask));
}

View File

@ -25,25 +25,24 @@ namespace dawn_native { namespace d3d12 {
class ComputePipeline final : public ComputePipelineBase {
public:
static ResultOrError<Ref<ComputePipeline>> Create(
static Ref<ComputePipeline> CreateUninitialized(
Device* device,
const ComputePipelineDescriptor* descriptor);
static void CreateAsync(Device* device,
const ComputePipelineDescriptor* descriptor,
size_t blueprintHash,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata);
static void InitializeAsync(Ref<ComputePipelineBase> computePipeline,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata);
ComputePipeline() = delete;
ID3D12PipelineState* GetPipelineState() const;
MaybeError Initialize() override;
// Dawn API
void SetLabelImpl() override;
private:
~ComputePipeline() override;
using ComputePipelineBase::ComputePipelineBase;
MaybeError Initialize() override;
ComPtr<ID3D12PipelineState> mPipelineState;
};

View File

@ -334,9 +334,9 @@ namespace dawn_native { namespace d3d12 {
const CommandBufferDescriptor* descriptor) {
return CommandBuffer::Create(encoder, descriptor);
}
ResultOrError<Ref<ComputePipelineBase>> Device::CreateComputePipelineImpl(
Ref<ComputePipelineBase> Device::CreateUninitializedComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) {
return ComputePipeline::Create(this, descriptor);
return ComputePipeline::CreateUninitialized(this, descriptor);
}
ResultOrError<Ref<PipelineLayoutBase>> Device::CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) {
@ -376,16 +376,15 @@ namespace dawn_native { namespace d3d12 {
const TextureViewDescriptor* descriptor) {
return TextureView::Create(texture, descriptor);
}
void Device::CreateComputePipelineAsyncImpl(const ComputePipelineDescriptor* descriptor,
size_t blueprintHash,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) {
ComputePipeline::CreateAsync(this, descriptor, blueprintHash, callback, userdata);
void Device::InitializeComputePipelineAsyncImpl(Ref<ComputePipelineBase> computePipeline,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) {
ComputePipeline::InitializeAsync(std::move(computePipeline), callback, userdata);
}
void Device::InitializeRenderPipelineAsyncImpl(Ref<RenderPipelineBase> renderPipeline,
WGPUCreateRenderPipelineAsyncCallback callback,
void* userdata) {
RenderPipeline::InitializeAsync(renderPipeline, callback, userdata);
RenderPipeline::InitializeAsync(std::move(renderPipeline), callback, userdata);
}
ResultOrError<std::unique_ptr<StagingBufferBase>> Device::CreateStagingBuffer(size_t size) {

View File

@ -149,14 +149,10 @@ namespace dawn_native { namespace d3d12 {
PipelineCompatibilityToken pipelineCompatibilityToken) override;
ResultOrError<Ref<BufferBase>> CreateBufferImpl(
const BufferDescriptor* descriptor) override;
ResultOrError<Ref<ComputePipelineBase>> CreateComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) override;
ResultOrError<Ref<PipelineLayoutBase>> CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) override;
ResultOrError<Ref<QuerySetBase>> CreateQuerySetImpl(
const QuerySetDescriptor* descriptor) override;
Ref<RenderPipelineBase> CreateUninitializedRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) override;
ResultOrError<Ref<SamplerBase>> CreateSamplerImpl(
const SamplerDescriptor* descriptor) override;
ResultOrError<Ref<ShaderModuleBase>> CreateShaderModuleImpl(
@ -173,10 +169,13 @@ namespace dawn_native { namespace d3d12 {
ResultOrError<Ref<TextureViewBase>> CreateTextureViewImpl(
TextureBase* texture,
const TextureViewDescriptor* descriptor) override;
void CreateComputePipelineAsyncImpl(const ComputePipelineDescriptor* descriptor,
size_t blueprintHash,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) override;
Ref<ComputePipelineBase> CreateUninitializedComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) override;
Ref<RenderPipelineBase> CreateUninitializedRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) override;
void InitializeComputePipelineAsyncImpl(Ref<ComputePipelineBase> computePipeline,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) override;
void InitializeRenderPipelineAsyncImpl(Ref<RenderPipelineBase> renderPipeline,
WGPUCreateRenderPipelineAsyncCallback callback,
void* userdata) override;

View File

@ -27,14 +27,12 @@ namespace dawn_native { namespace metal {
class ComputePipeline final : public ComputePipelineBase {
public:
static ResultOrError<Ref<ComputePipeline>> Create(
static Ref<ComputePipeline> CreateUninitialized(
Device* device,
const ComputePipelineDescriptor* descriptor);
static void CreateAsync(Device* device,
const ComputePipelineDescriptor* descriptor,
size_t blueprintHash,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata);
static void InitializeAsync(Ref<ComputePipelineBase> computePipeline,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata);
void Encode(id<MTLComputeCommandEncoder> encoder);
MTLSize GetLocalWorkGroupSize() const;

View File

@ -21,12 +21,10 @@
namespace dawn_native { namespace metal {
// static
ResultOrError<Ref<ComputePipeline>> ComputePipeline::Create(
Ref<ComputePipeline> ComputePipeline::CreateUninitialized(
Device* device,
const ComputePipelineDescriptor* descriptor) {
Ref<ComputePipeline> pipeline = AcquireRef(new ComputePipeline(device, descriptor));
DAWN_TRY(pipeline->Initialize());
return pipeline;
return AcquireRef(new ComputePipeline(device, descriptor));
}
MaybeError ComputePipeline::Initialize() {
@ -76,14 +74,11 @@ namespace dawn_native { namespace metal {
return mRequiresStorageBufferLength;
}
void ComputePipeline::CreateAsync(Device* device,
const ComputePipelineDescriptor* descriptor,
size_t blueprintHash,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) {
Ref<ComputePipeline> pipeline = AcquireRef(new ComputePipeline(device, descriptor));
void ComputePipeline::InitializeAsync(Ref<ComputePipelineBase> computePipeline,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) {
std::unique_ptr<CreateComputePipelineAsyncTask> asyncTask =
std::make_unique<CreateComputePipelineAsyncTask>(pipeline, blueprintHash, callback,
std::make_unique<CreateComputePipelineAsyncTask>(std::move(computePipeline), callback,
userdata);
CreateComputePipelineAsyncTask::RunAsync(std::move(asyncTask));
}

View File

@ -89,14 +89,10 @@ namespace dawn_native { namespace metal {
ResultOrError<Ref<CommandBufferBase>> CreateCommandBuffer(
CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor) override;
ResultOrError<Ref<ComputePipelineBase>> CreateComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) override;
ResultOrError<Ref<PipelineLayoutBase>> CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) override;
ResultOrError<Ref<QuerySetBase>> CreateQuerySetImpl(
const QuerySetDescriptor* descriptor) override;
Ref<RenderPipelineBase> CreateUninitializedRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) override;
ResultOrError<Ref<SamplerBase>> CreateSamplerImpl(
const SamplerDescriptor* descriptor) override;
ResultOrError<Ref<ShaderModuleBase>> CreateShaderModuleImpl(
@ -113,10 +109,13 @@ namespace dawn_native { namespace metal {
ResultOrError<Ref<TextureViewBase>> CreateTextureViewImpl(
TextureBase* texture,
const TextureViewDescriptor* descriptor) override;
void CreateComputePipelineAsyncImpl(const ComputePipelineDescriptor* descriptor,
size_t blueprintHash,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) override;
Ref<ComputePipelineBase> CreateUninitializedComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) override;
Ref<RenderPipelineBase> CreateUninitializedRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) override;
void InitializeComputePipelineAsyncImpl(Ref<ComputePipelineBase> computePipeline,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) override;
void InitializeRenderPipelineAsyncImpl(Ref<RenderPipelineBase> renderPipeline,
WGPUCreateRenderPipelineAsyncCallback callback,
void* userdata) override;

View File

@ -243,9 +243,9 @@ namespace dawn_native { namespace metal {
const CommandBufferDescriptor* descriptor) {
return CommandBuffer::Create(encoder, descriptor);
}
ResultOrError<Ref<ComputePipelineBase>> Device::CreateComputePipelineImpl(
Ref<ComputePipelineBase> Device::CreateUninitializedComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) {
return ComputePipeline::Create(this, descriptor);
return ComputePipeline::CreateUninitialized(this, descriptor);
}
ResultOrError<Ref<PipelineLayoutBase>> Device::CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) {
@ -285,16 +285,15 @@ namespace dawn_native { namespace metal {
const TextureViewDescriptor* descriptor) {
return TextureView::Create(texture, descriptor);
}
void Device::CreateComputePipelineAsyncImpl(const ComputePipelineDescriptor* descriptor,
size_t blueprintHash,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) {
ComputePipeline::CreateAsync(this, descriptor, blueprintHash, callback, userdata);
void Device::InitializeComputePipelineAsyncImpl(Ref<ComputePipelineBase> computePipeline,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) {
ComputePipeline::InitializeAsync(std::move(computePipeline), callback, userdata);
}
void Device::InitializeRenderPipelineAsyncImpl(Ref<RenderPipelineBase> renderPipeline,
WGPUCreateRenderPipelineAsyncCallback callback,
void* userdata) {
RenderPipeline::InitializeAsync(renderPipeline, callback, userdata);
RenderPipeline::InitializeAsync(std::move(renderPipeline), callback, userdata);
}
ResultOrError<ExecutionSerial> Device::CheckAndUpdateCompletedSerials() {

View File

@ -112,7 +112,7 @@ namespace dawn_native { namespace null {
const CommandBufferDescriptor* descriptor) {
return AcquireRef(new CommandBuffer(encoder, descriptor));
}
ResultOrError<Ref<ComputePipelineBase>> Device::CreateComputePipelineImpl(
Ref<ComputePipelineBase> Device::CreateUninitializedComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) {
return AcquireRef(new ComputePipeline(this, descriptor));
}
@ -371,6 +371,11 @@ namespace dawn_native { namespace null {
return {};
}
// ComputePipeline
MaybeError ComputePipeline::Initialize() {
return {};
}
// RenderPipeline
MaybeError RenderPipeline::Initialize() {
return {};

View File

@ -43,7 +43,7 @@ namespace dawn_native { namespace null {
class BindGroupLayout;
class Buffer;
class CommandBuffer;
using ComputePipeline = ComputePipelineBase;
class ComputePipeline;
class Device;
using PipelineLayout = PipelineLayoutBase;
class QuerySet;
@ -129,7 +129,7 @@ namespace dawn_native { namespace null {
PipelineCompatibilityToken pipelineCompatibilityToken) override;
ResultOrError<Ref<BufferBase>> CreateBufferImpl(
const BufferDescriptor* descriptor) override;
ResultOrError<Ref<ComputePipelineBase>> CreateComputePipelineImpl(
Ref<ComputePipelineBase> CreateUninitializedComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) override;
ResultOrError<Ref<PipelineLayoutBase>> CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) override;
@ -261,6 +261,13 @@ namespace dawn_native { namespace null {
size_t size) override;
};
class ComputePipeline final : public ComputePipelineBase {
public:
using ComputePipelineBase::ComputePipelineBase;
MaybeError Initialize() override;
};
class RenderPipeline final : public RenderPipelineBase {
public:
using RenderPipelineBase::RenderPipelineBase;

View File

@ -19,12 +19,10 @@
namespace dawn_native { namespace opengl {
// static
ResultOrError<Ref<ComputePipeline>> ComputePipeline::Create(
Ref<ComputePipeline> ComputePipeline::CreateUninitialized(
Device* device,
const ComputePipelineDescriptor* descriptor) {
Ref<ComputePipeline> pipeline = AcquireRef(new ComputePipeline(device, descriptor));
DAWN_TRY(pipeline->Initialize());
return pipeline;
return AcquireRef(new ComputePipeline(device, descriptor));
}
ComputePipeline::~ComputePipeline() {

View File

@ -27,16 +27,17 @@ namespace dawn_native { namespace opengl {
class ComputePipeline final : public ComputePipelineBase, public PipelineGL {
public:
static ResultOrError<Ref<ComputePipeline>> Create(
static Ref<ComputePipeline> CreateUninitialized(
Device* device,
const ComputePipelineDescriptor* descriptor);
void ApplyNow();
MaybeError Initialize() override;
private:
using ComputePipelineBase::ComputePipelineBase;
~ComputePipeline() override;
MaybeError Initialize() override;
};
}} // namespace dawn_native::opengl

View File

@ -130,9 +130,9 @@ namespace dawn_native { namespace opengl {
const CommandBufferDescriptor* descriptor) {
return AcquireRef(new CommandBuffer(encoder, descriptor));
}
ResultOrError<Ref<ComputePipelineBase>> Device::CreateComputePipelineImpl(
Ref<ComputePipelineBase> Device::CreateUninitializedComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) {
return ComputePipeline::Create(this, descriptor);
return ComputePipeline::CreateUninitialized(this, descriptor);
}
ResultOrError<Ref<PipelineLayoutBase>> Device::CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) {

View File

@ -91,14 +91,10 @@ namespace dawn_native { namespace opengl {
PipelineCompatibilityToken pipelineCompatibilityToken) override;
ResultOrError<Ref<BufferBase>> CreateBufferImpl(
const BufferDescriptor* descriptor) override;
ResultOrError<Ref<ComputePipelineBase>> CreateComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) override;
ResultOrError<Ref<PipelineLayoutBase>> CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) override;
ResultOrError<Ref<QuerySetBase>> CreateQuerySetImpl(
const QuerySetDescriptor* descriptor) override;
Ref<RenderPipelineBase> CreateUninitializedRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) override;
ResultOrError<Ref<SamplerBase>> CreateSamplerImpl(
const SamplerDescriptor* descriptor) override;
ResultOrError<Ref<ShaderModuleBase>> CreateShaderModuleImpl(
@ -115,6 +111,10 @@ namespace dawn_native { namespace opengl {
ResultOrError<Ref<TextureViewBase>> CreateTextureViewImpl(
TextureBase* texture,
const TextureViewDescriptor* descriptor) override;
Ref<ComputePipelineBase> CreateUninitializedComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) override;
Ref<RenderPipelineBase> CreateUninitializedRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) override;
void InitTogglesFromDriver();
ResultOrError<ExecutionSerial> CheckAndUpdateCompletedSerials() override;

View File

@ -25,12 +25,10 @@
namespace dawn_native { namespace vulkan {
// static
ResultOrError<Ref<ComputePipeline>> ComputePipeline::Create(
Ref<ComputePipeline> ComputePipeline::CreateUninitialized(
Device* device,
const ComputePipelineDescriptor* descriptor) {
Ref<ComputePipeline> pipeline = AcquireRef(new ComputePipeline(device, descriptor));
DAWN_TRY(pipeline->Initialize());
return pipeline;
return AcquireRef(new ComputePipeline(device, descriptor));
}
MaybeError ComputePipeline::Initialize() {
@ -102,14 +100,11 @@ namespace dawn_native { namespace vulkan {
return mHandle;
}
void ComputePipeline::CreateAsync(Device* device,
const ComputePipelineDescriptor* descriptor,
size_t blueprintHash,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) {
Ref<ComputePipeline> pipeline = AcquireRef(new ComputePipeline(device, descriptor));
void ComputePipeline::InitializeAsync(Ref<ComputePipelineBase> computePipeline,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) {
std::unique_ptr<CreateComputePipelineAsyncTask> asyncTask =
std::make_unique<CreateComputePipelineAsyncTask>(pipeline, blueprintHash, callback,
std::make_unique<CreateComputePipelineAsyncTask>(std::move(computePipeline), callback,
userdata);
CreateComputePipelineAsyncTask::RunAsync(std::move(asyncTask));
}

View File

@ -26,24 +26,23 @@ namespace dawn_native { namespace vulkan {
class ComputePipeline final : public ComputePipelineBase {
public:
static ResultOrError<Ref<ComputePipeline>> Create(
static Ref<ComputePipeline> CreateUninitialized(
Device* device,
const ComputePipelineDescriptor* descriptor);
static void CreateAsync(Device* device,
const ComputePipelineDescriptor* descriptor,
size_t blueprintHash,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata);
static void InitializeAsync(Ref<ComputePipelineBase> computePipeline,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata);
VkPipeline GetHandle() const;
MaybeError Initialize() override;
// Dawn API
void SetLabelImpl() override;
private:
~ComputePipeline() override;
using ComputePipelineBase::ComputePipelineBase;
MaybeError Initialize() override;
VkPipeline mHandle = VK_NULL_HANDLE;
};

View File

@ -120,9 +120,9 @@ namespace dawn_native { namespace vulkan {
const CommandBufferDescriptor* descriptor) {
return CommandBuffer::Create(encoder, descriptor);
}
ResultOrError<Ref<ComputePipelineBase>> Device::CreateComputePipelineImpl(
Ref<ComputePipelineBase> Device::CreateUninitializedComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) {
return ComputePipeline::Create(this, descriptor);
return ComputePipeline::CreateUninitialized(this, descriptor);
}
ResultOrError<Ref<PipelineLayoutBase>> Device::CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) {
@ -162,16 +162,15 @@ namespace dawn_native { namespace vulkan {
const TextureViewDescriptor* descriptor) {
return TextureView::Create(texture, descriptor);
}
void Device::CreateComputePipelineAsyncImpl(const ComputePipelineDescriptor* descriptor,
size_t blueprintHash,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) {
ComputePipeline::CreateAsync(this, descriptor, blueprintHash, callback, userdata);
void Device::InitializeComputePipelineAsyncImpl(Ref<ComputePipelineBase> computePipeline,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) {
ComputePipeline::InitializeAsync(std::move(computePipeline), callback, userdata);
}
void Device::InitializeRenderPipelineAsyncImpl(Ref<RenderPipelineBase> renderPipeline,
WGPUCreateRenderPipelineAsyncCallback callback,
void* userdata) {
RenderPipeline::InitializeAsync(renderPipeline, callback, userdata);
RenderPipeline::InitializeAsync(std::move(renderPipeline), callback, userdata);
}
MaybeError Device::TickImpl() {

View File

@ -113,14 +113,10 @@ namespace dawn_native { namespace vulkan {
PipelineCompatibilityToken pipelineCompatibilityToken) override;
ResultOrError<Ref<BufferBase>> CreateBufferImpl(
const BufferDescriptor* descriptor) override;
ResultOrError<Ref<ComputePipelineBase>> CreateComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) override;
ResultOrError<Ref<PipelineLayoutBase>> CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) override;
ResultOrError<Ref<QuerySetBase>> CreateQuerySetImpl(
const QuerySetDescriptor* descriptor) override;
Ref<RenderPipelineBase> CreateUninitializedRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) override;
ResultOrError<Ref<SamplerBase>> CreateSamplerImpl(
const SamplerDescriptor* descriptor) override;
ResultOrError<Ref<ShaderModuleBase>> CreateShaderModuleImpl(
@ -137,10 +133,13 @@ namespace dawn_native { namespace vulkan {
ResultOrError<Ref<TextureViewBase>> CreateTextureViewImpl(
TextureBase* texture,
const TextureViewDescriptor* descriptor) override;
void CreateComputePipelineAsyncImpl(const ComputePipelineDescriptor* descriptor,
size_t blueprintHash,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) override;
Ref<ComputePipelineBase> CreateUninitializedComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) override;
Ref<RenderPipelineBase> CreateUninitializedRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) override;
void InitializeComputePipelineAsyncImpl(Ref<ComputePipelineBase> computePipeline,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) override;
void InitializeRenderPipelineAsyncImpl(Ref<RenderPipelineBase> renderPipeline,
WGPUCreateRenderPipelineAsyncCallback callback,
void* userdata) override;