Avoid redundant creation of RenderPipelineBase in GetCachedRenderPipeline
This patch removes a redundant creation of RenderPipelineBase object in GetCachedRenderPipeline(). Instead, we directly compute the blueprint hash from the uninitialized backend render pipeline object. BUG=dawn:529 TEST=dawn_end2end_tests Change-Id: I3c7a2acfc01ab9e1e631793030ea06c9ae908aa2 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/65000 Commit-Queue: Jiawei Shao <jiawei.shao@intel.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
a57c1db878
commit
3c0925b480
|
@ -141,11 +141,9 @@ namespace dawn_native {
|
|||
|
||||
CreateRenderPipelineAsyncTask::CreateRenderPipelineAsyncTask(
|
||||
Ref<RenderPipelineBase> nonInitializedRenderPipeline,
|
||||
size_t blueprintHash,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata)
|
||||
: mRenderPipeline(std::move(nonInitializedRenderPipeline)),
|
||||
mBlueprintHash(blueprintHash),
|
||||
mCallback(callback),
|
||||
mUserdata(userdata) {
|
||||
ASSERT(mRenderPipeline != nullptr);
|
||||
|
@ -160,7 +158,7 @@ namespace dawn_native {
|
|||
}
|
||||
|
||||
mRenderPipeline->GetDevice()->AddRenderPipelineAsyncCallbackTask(
|
||||
mRenderPipeline, errorMessage, mCallback, mUserdata, mBlueprintHash);
|
||||
mRenderPipeline, errorMessage, mCallback, mUserdata);
|
||||
}
|
||||
|
||||
void CreateRenderPipelineAsyncTask::RunAsync(
|
||||
|
|
|
@ -92,7 +92,6 @@ namespace dawn_native {
|
|||
class CreateRenderPipelineAsyncTask {
|
||||
public:
|
||||
CreateRenderPipelineAsyncTask(Ref<RenderPipelineBase> nonInitializedRenderPipeline,
|
||||
size_t blueprintHash,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata);
|
||||
|
||||
|
@ -102,7 +101,6 @@ namespace dawn_native {
|
|||
|
||||
private:
|
||||
Ref<RenderPipelineBase> mRenderPipeline;
|
||||
size_t mBlueprintHash;
|
||||
WGPUCreateRenderPipelineAsyncCallback mCallback;
|
||||
void* mUserdata;
|
||||
};
|
||||
|
|
|
@ -670,20 +670,14 @@ namespace dawn_native {
|
|||
return std::make_pair(result, blueprintHash);
|
||||
}
|
||||
|
||||
std::pair<Ref<RenderPipelineBase>, size_t> DeviceBase::GetCachedRenderPipeline(
|
||||
const RenderPipelineDescriptor* descriptor) {
|
||||
RenderPipelineBase blueprint(this, descriptor);
|
||||
|
||||
const size_t blueprintHash = blueprint.ComputeContentHash();
|
||||
blueprint.SetContentHash(blueprintHash);
|
||||
|
||||
Ref<RenderPipelineBase> result;
|
||||
auto iter = mCaches->renderPipelines.find(&blueprint);
|
||||
Ref<RenderPipelineBase> DeviceBase::GetCachedRenderPipeline(
|
||||
RenderPipelineBase* uninitializedRenderPipeline) {
|
||||
Ref<RenderPipelineBase> cachedPipeline;
|
||||
auto iter = mCaches->renderPipelines.find(uninitializedRenderPipeline);
|
||||
if (iter != mCaches->renderPipelines.end()) {
|
||||
result = *iter;
|
||||
cachedPipeline = *iter;
|
||||
}
|
||||
|
||||
return std::make_pair(result, blueprintHash);
|
||||
return cachedPipeline;
|
||||
}
|
||||
|
||||
Ref<ComputePipelineBase> DeviceBase::AddOrGetCachedComputePipeline(
|
||||
|
@ -700,9 +694,7 @@ namespace dawn_native {
|
|||
}
|
||||
|
||||
Ref<RenderPipelineBase> DeviceBase::AddOrGetCachedRenderPipeline(
|
||||
Ref<RenderPipelineBase> renderPipeline,
|
||||
size_t blueprintHash) {
|
||||
renderPipeline->SetContentHash(blueprintHash);
|
||||
Ref<RenderPipelineBase> renderPipeline) {
|
||||
auto insertion = mCaches->renderPipelines.insert(renderPipeline.Get());
|
||||
if (insertion.second) {
|
||||
renderPipeline->SetIsCachedReference();
|
||||
|
@ -1261,20 +1253,20 @@ namespace dawn_native {
|
|||
}
|
||||
|
||||
// This function is overwritten with the async version on the backends
|
||||
// that supports creating render pipeline asynchronously
|
||||
void DeviceBase::CreateRenderPipelineAsyncImpl(const RenderPipelineDescriptor* descriptor,
|
||||
size_t blueprintHash,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata) {
|
||||
// that supports initializing render pipeline asynchronously
|
||||
void DeviceBase::InitializeRenderPipelineAsyncImpl(
|
||||
Ref<RenderPipelineBase> renderPipeline,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata) {
|
||||
Ref<RenderPipelineBase> result;
|
||||
std::string errorMessage;
|
||||
|
||||
auto resultOrError = CreateRenderPipelineImpl(descriptor);
|
||||
if (resultOrError.IsError()) {
|
||||
std::unique_ptr<ErrorData> error = resultOrError.AcquireError();
|
||||
MaybeError maybeError = renderPipeline->Initialize();
|
||||
if (maybeError.IsError()) {
|
||||
std::unique_ptr<ErrorData> error = maybeError.AcquireError();
|
||||
errorMessage = error->GetMessage();
|
||||
} else {
|
||||
result = AddOrGetCachedRenderPipeline(resultOrError.AcquireSuccess(), blueprintHash);
|
||||
result = AddOrGetCachedRenderPipeline(renderPipeline);
|
||||
}
|
||||
|
||||
std::unique_ptr<CreateRenderPipelineAsyncCallbackTask> callbackTask =
|
||||
|
@ -1333,15 +1325,17 @@ namespace dawn_native {
|
|||
DAWN_TRY_ASSIGN(layoutRef, ValidateLayoutAndGetRenderPipelineDescriptorWithDefaults(
|
||||
this, *descriptor, &appliedDescriptor));
|
||||
|
||||
auto pipelineAndBlueprintFromCache = GetCachedRenderPipeline(&appliedDescriptor);
|
||||
if (pipelineAndBlueprintFromCache.first.Get() != nullptr) {
|
||||
return std::move(pipelineAndBlueprintFromCache.first);
|
||||
Ref<RenderPipelineBase> uninitializedRenderPipeline =
|
||||
CreateUninitializedRenderPipeline(&appliedDescriptor);
|
||||
|
||||
Ref<RenderPipelineBase> cachedRenderPipeline =
|
||||
GetCachedRenderPipeline(uninitializedRenderPipeline.Get());
|
||||
if (cachedRenderPipeline != nullptr) {
|
||||
return cachedRenderPipeline;
|
||||
}
|
||||
|
||||
Ref<RenderPipelineBase> backendObj;
|
||||
DAWN_TRY_ASSIGN(backendObj, CreateRenderPipelineImpl(&appliedDescriptor));
|
||||
size_t blueprintHash = pipelineAndBlueprintFromCache.second;
|
||||
return AddOrGetCachedRenderPipeline(backendObj, blueprintHash);
|
||||
DAWN_TRY(uninitializedRenderPipeline->Initialize());
|
||||
return AddOrGetCachedRenderPipeline(std::move(uninitializedRenderPipeline));
|
||||
}
|
||||
|
||||
MaybeError DeviceBase::CreateRenderPipelineAsync(const RenderPipelineDescriptor* descriptor,
|
||||
|
@ -1355,23 +1349,26 @@ namespace dawn_native {
|
|||
// Ref will keep the pipeline layout alive until the end of the function where
|
||||
// the pipeline will take another reference.
|
||||
Ref<PipelineLayoutBase> layoutRef;
|
||||
RenderPipelineDescriptor descriptorWithPipelineLayout;
|
||||
RenderPipelineDescriptor appliedDescriptor;
|
||||
DAWN_TRY_ASSIGN(layoutRef, ValidateLayoutAndGetRenderPipelineDescriptorWithDefaults(
|
||||
this, *descriptor, &descriptorWithPipelineLayout));
|
||||
this, *descriptor, &appliedDescriptor));
|
||||
|
||||
Ref<RenderPipelineBase> uninitializedRenderPipeline =
|
||||
CreateUninitializedRenderPipeline(&appliedDescriptor);
|
||||
|
||||
// Call the callback directly when we can get a cached render pipeline object.
|
||||
auto pipelineAndBlueprintFromCache = GetCachedRenderPipeline(&descriptorWithPipelineLayout);
|
||||
if (pipelineAndBlueprintFromCache.first.Get() != nullptr) {
|
||||
Ref<RenderPipelineBase> result = std::move(pipelineAndBlueprintFromCache.first);
|
||||
Ref<RenderPipelineBase> cachedRenderPipeline =
|
||||
GetCachedRenderPipeline(uninitializedRenderPipeline.Get());
|
||||
if (cachedRenderPipeline != nullptr) {
|
||||
callback(WGPUCreatePipelineAsyncStatus_Success,
|
||||
reinterpret_cast<WGPURenderPipeline>(result.Detach()), "", userdata);
|
||||
reinterpret_cast<WGPURenderPipeline>(cachedRenderPipeline.Detach()), "",
|
||||
userdata);
|
||||
} else {
|
||||
// Otherwise we will create the pipeline object in CreateRenderPipelineAsyncImpl(),
|
||||
// where the pipeline object may be created asynchronously and the result will be saved
|
||||
// to mCreatePipelineAsyncTracker.
|
||||
const size_t blueprintHash = pipelineAndBlueprintFromCache.second;
|
||||
CreateRenderPipelineAsyncImpl(&descriptorWithPipelineLayout, blueprintHash, callback,
|
||||
userdata);
|
||||
// Otherwise we will create the pipeline object in InitializeRenderPipelineAsyncImpl(),
|
||||
// where the pipeline object may be initialized asynchronously and the result will be
|
||||
// saved to mCreatePipelineAsyncTracker.
|
||||
InitializeRenderPipelineAsyncImpl(std::move(uninitializedRenderPipeline), callback,
|
||||
userdata);
|
||||
}
|
||||
|
||||
return {};
|
||||
|
@ -1536,6 +1533,11 @@ 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,
|
||||
|
@ -1584,44 +1586,28 @@ namespace dawn_native {
|
|||
Ref<RenderPipelineBase> pipeline,
|
||||
std::string errorMessage,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata,
|
||||
size_t blueprintHash) {
|
||||
void* userdata) {
|
||||
// CreateRenderPipelineAsyncWaitableCallbackTask is declared as an internal class as it
|
||||
// needs to call the private member function DeviceBase::AddOrGetCachedRenderPipeline().
|
||||
struct CreateRenderPipelineAsyncWaitableCallbackTask final
|
||||
: CreateRenderPipelineAsyncCallbackTask {
|
||||
CreateRenderPipelineAsyncWaitableCallbackTask(
|
||||
Ref<RenderPipelineBase> pipeline,
|
||||
std::string errorMessage,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata,
|
||||
size_t blueprintHash)
|
||||
: CreateRenderPipelineAsyncCallbackTask(std::move(pipeline),
|
||||
errorMessage,
|
||||
callback,
|
||||
userdata),
|
||||
mBlueprintHash(blueprintHash) {
|
||||
}
|
||||
using CreateRenderPipelineAsyncCallbackTask::CreateRenderPipelineAsyncCallbackTask;
|
||||
|
||||
void Finish() final {
|
||||
// TODO(dawn:529): call AddOrGetCachedRenderPipeline() asynchronously in
|
||||
// CreateRenderPipelineAsyncTaskImpl::Run() when the front-end pipeline cache is
|
||||
// thread-safe.
|
||||
if (mPipeline.Get() != nullptr) {
|
||||
mPipeline = mPipeline->GetDevice()->AddOrGetCachedRenderPipeline(
|
||||
mPipeline, mBlueprintHash);
|
||||
mPipeline = mPipeline->GetDevice()->AddOrGetCachedRenderPipeline(mPipeline);
|
||||
}
|
||||
|
||||
CreateRenderPipelineAsyncCallbackTask::Finish();
|
||||
}
|
||||
|
||||
private:
|
||||
size_t mBlueprintHash;
|
||||
};
|
||||
|
||||
mCallbackTaskManager->AddCallbackTask(
|
||||
std::make_unique<CreateRenderPipelineAsyncWaitableCallbackTask>(
|
||||
std::move(pipeline), errorMessage, callback, userdata, blueprintHash));
|
||||
std::move(pipeline), errorMessage, callback, userdata));
|
||||
}
|
||||
|
||||
PipelineCompatibilityToken DeviceBase::GetNextPipelineCompatibilityToken() {
|
||||
|
|
|
@ -307,8 +307,7 @@ namespace dawn_native {
|
|||
void AddRenderPipelineAsyncCallbackTask(Ref<RenderPipelineBase> pipeline,
|
||||
std::string errorMessage,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata,
|
||||
size_t blueprintHash);
|
||||
void* userdata);
|
||||
|
||||
PipelineCompatibilityToken GetNextPipelineCompatibilityToken();
|
||||
|
||||
|
@ -339,7 +338,7 @@ namespace dawn_native {
|
|||
const PipelineLayoutDescriptor* descriptor) = 0;
|
||||
virtual ResultOrError<Ref<QuerySetBase>> CreateQuerySetImpl(
|
||||
const QuerySetDescriptor* descriptor) = 0;
|
||||
virtual ResultOrError<Ref<RenderPipelineBase>> CreateRenderPipelineImpl(
|
||||
virtual Ref<RenderPipelineBase> CreateUninitializedRenderPipelineImpl(
|
||||
const RenderPipelineDescriptor* descriptor) = 0;
|
||||
virtual ResultOrError<Ref<SamplerBase>> CreateSamplerImpl(
|
||||
const SamplerDescriptor* descriptor) = 0;
|
||||
|
@ -367,21 +366,23 @@ namespace dawn_native {
|
|||
|
||||
std::pair<Ref<ComputePipelineBase>, size_t> GetCachedComputePipeline(
|
||||
const ComputePipelineDescriptor* descriptor);
|
||||
std::pair<Ref<RenderPipelineBase>, size_t> GetCachedRenderPipeline(
|
||||
const RenderPipelineDescriptor* descriptor);
|
||||
Ref<RenderPipelineBase> GetCachedRenderPipeline(
|
||||
RenderPipelineBase* uninitializedRenderPipeline);
|
||||
Ref<ComputePipelineBase> AddOrGetCachedComputePipeline(
|
||||
Ref<ComputePipelineBase> computePipeline,
|
||||
size_t blueprintHash);
|
||||
Ref<RenderPipelineBase> AddOrGetCachedRenderPipeline(Ref<RenderPipelineBase> renderPipeline,
|
||||
size_t blueprintHash);
|
||||
Ref<RenderPipelineBase> AddOrGetCachedRenderPipeline(
|
||||
Ref<RenderPipelineBase> renderPipeline);
|
||||
virtual void CreateComputePipelineAsyncImpl(const ComputePipelineDescriptor* descriptor,
|
||||
size_t blueprintHash,
|
||||
WGPUCreateComputePipelineAsyncCallback callback,
|
||||
void* userdata);
|
||||
virtual void CreateRenderPipelineAsyncImpl(const RenderPipelineDescriptor* descriptor,
|
||||
size_t blueprintHash,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata);
|
||||
Ref<RenderPipelineBase> CreateUninitializedRenderPipeline(
|
||||
const RenderPipelineDescriptor* descriptor);
|
||||
virtual void InitializeRenderPipelineAsyncImpl(
|
||||
Ref<RenderPipelineBase> renderPipeline,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata);
|
||||
|
||||
void ApplyToggleOverrides(const DeviceDescriptor* deviceDescriptor);
|
||||
void ApplyExtensions(const DeviceDescriptor* deviceDescriptor);
|
||||
|
|
|
@ -554,6 +554,8 @@ namespace dawn_native {
|
|||
mTargets[i].blend = &mTargetBlend[i];
|
||||
}
|
||||
}
|
||||
|
||||
SetContentHash(ComputeContentHash());
|
||||
}
|
||||
|
||||
RenderPipelineBase::RenderPipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag)
|
||||
|
@ -562,7 +564,19 @@ namespace dawn_native {
|
|||
|
||||
// static
|
||||
RenderPipelineBase* RenderPipelineBase::MakeError(DeviceBase* device) {
|
||||
return new RenderPipelineBase(device, ObjectBase::kError);
|
||||
class ErrorRenderPipeline final : public RenderPipelineBase {
|
||||
public:
|
||||
ErrorRenderPipeline(DeviceBase* device)
|
||||
: RenderPipelineBase(device, ObjectBase::kError) {
|
||||
}
|
||||
|
||||
MaybeError Initialize() override {
|
||||
UNREACHABLE();
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
return new ErrorRenderPipeline(device);
|
||||
}
|
||||
|
||||
ObjectType RenderPipelineBase::GetType() const {
|
||||
|
@ -900,7 +914,4 @@ namespace dawn_native {
|
|||
return true;
|
||||
}
|
||||
|
||||
MaybeError RenderPipelineBase::Initialize() {
|
||||
return {};
|
||||
}
|
||||
} // namespace dawn_native
|
||||
|
|
|
@ -105,15 +105,12 @@ 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);
|
||||
|
||||
// CreateRenderPipelineAsyncTask is declared as a friend of RenderPipelineBase as it
|
||||
// needs to call the private member function RenderPipelineBase::Initialize().
|
||||
friend class CreateRenderPipelineAsyncTask;
|
||||
virtual MaybeError Initialize();
|
||||
|
||||
// TODO(dawn:529): store all the following members in a FlatRenderPipelineDescriptor object
|
||||
// Vertex state
|
||||
uint32_t mVertexBufferCount;
|
||||
ityp::bitset<VertexAttributeLocation, kMaxVertexAttributes> mAttributeLocationsUsed;
|
||||
|
|
|
@ -346,9 +346,9 @@ namespace dawn_native { namespace d3d12 {
|
|||
const QuerySetDescriptor* descriptor) {
|
||||
return QuerySet::Create(this, descriptor);
|
||||
}
|
||||
ResultOrError<Ref<RenderPipelineBase>> Device::CreateRenderPipelineImpl(
|
||||
Ref<RenderPipelineBase> Device::CreateUninitializedRenderPipelineImpl(
|
||||
const RenderPipelineDescriptor* descriptor) {
|
||||
return RenderPipeline::Create(this, descriptor);
|
||||
return RenderPipeline::CreateUninitialized(this, descriptor);
|
||||
}
|
||||
ResultOrError<Ref<SamplerBase>> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) {
|
||||
return Sampler::Create(this, descriptor);
|
||||
|
@ -382,11 +382,10 @@ namespace dawn_native { namespace d3d12 {
|
|||
void* userdata) {
|
||||
ComputePipeline::CreateAsync(this, descriptor, blueprintHash, callback, userdata);
|
||||
}
|
||||
void Device::CreateRenderPipelineAsyncImpl(const RenderPipelineDescriptor* descriptor,
|
||||
size_t blueprintHash,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata) {
|
||||
RenderPipeline::CreateAsync(this, descriptor, blueprintHash, callback, userdata);
|
||||
void Device::InitializeRenderPipelineAsyncImpl(Ref<RenderPipelineBase> renderPipeline,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata) {
|
||||
RenderPipeline::InitializeAsync(renderPipeline, callback, userdata);
|
||||
}
|
||||
|
||||
ResultOrError<std::unique_ptr<StagingBufferBase>> Device::CreateStagingBuffer(size_t size) {
|
||||
|
|
|
@ -155,7 +155,7 @@ namespace dawn_native { namespace d3d12 {
|
|||
const PipelineLayoutDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<QuerySetBase>> CreateQuerySetImpl(
|
||||
const QuerySetDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<RenderPipelineBase>> CreateRenderPipelineImpl(
|
||||
Ref<RenderPipelineBase> CreateUninitializedRenderPipelineImpl(
|
||||
const RenderPipelineDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<SamplerBase>> CreateSamplerImpl(
|
||||
const SamplerDescriptor* descriptor) override;
|
||||
|
@ -177,10 +177,9 @@ namespace dawn_native { namespace d3d12 {
|
|||
size_t blueprintHash,
|
||||
WGPUCreateComputePipelineAsyncCallback callback,
|
||||
void* userdata) override;
|
||||
void CreateRenderPipelineAsyncImpl(const RenderPipelineDescriptor* descriptor,
|
||||
size_t blueprintHash,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata) override;
|
||||
void InitializeRenderPipelineAsyncImpl(Ref<RenderPipelineBase> renderPipeline,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata) override;
|
||||
|
||||
void ShutDownImpl() override;
|
||||
MaybeError WaitForIdleForDestruction() override;
|
||||
|
|
|
@ -316,12 +316,10 @@ namespace dawn_native { namespace d3d12 {
|
|||
|
||||
} // anonymous namespace
|
||||
|
||||
ResultOrError<Ref<RenderPipeline>> RenderPipeline::Create(
|
||||
Ref<RenderPipeline> RenderPipeline::CreateUninitialized(
|
||||
Device* device,
|
||||
const RenderPipelineDescriptor* descriptor) {
|
||||
Ref<RenderPipeline> pipeline = AcquireRef(new RenderPipeline(device, descriptor));
|
||||
DAWN_TRY(pipeline->Initialize());
|
||||
return pipeline;
|
||||
return AcquireRef(new RenderPipeline(device, descriptor));
|
||||
}
|
||||
|
||||
MaybeError RenderPipeline::Initialize() {
|
||||
|
@ -472,14 +470,11 @@ namespace dawn_native { namespace d3d12 {
|
|||
return inputLayoutDescriptor;
|
||||
}
|
||||
|
||||
void RenderPipeline::CreateAsync(Device* device,
|
||||
const RenderPipelineDescriptor* descriptor,
|
||||
size_t blueprintHash,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata) {
|
||||
Ref<RenderPipeline> pipeline = AcquireRef(new RenderPipeline(device, descriptor));
|
||||
void RenderPipeline::InitializeAsync(Ref<RenderPipelineBase> renderPipeline,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata) {
|
||||
std::unique_ptr<CreateRenderPipelineAsyncTask> asyncTask =
|
||||
std::make_unique<CreateRenderPipelineAsyncTask>(pipeline, blueprintHash, callback,
|
||||
std::make_unique<CreateRenderPipelineAsyncTask>(std::move(renderPipeline), callback,
|
||||
userdata);
|
||||
CreateRenderPipelineAsyncTask::RunAsync(std::move(asyncTask));
|
||||
}
|
||||
|
|
|
@ -26,16 +26,15 @@ namespace dawn_native { namespace d3d12 {
|
|||
|
||||
class RenderPipeline final : public RenderPipelineBase {
|
||||
public:
|
||||
static ResultOrError<Ref<RenderPipeline>> Create(
|
||||
Device* device,
|
||||
const RenderPipelineDescriptor* descriptor);
|
||||
static void CreateAsync(Device* device,
|
||||
const RenderPipelineDescriptor* descriptor,
|
||||
size_t blueprintHash,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata);
|
||||
static Ref<RenderPipeline> CreateUninitialized(Device* device,
|
||||
const RenderPipelineDescriptor* descriptor);
|
||||
static void InitializeAsync(Ref<RenderPipelineBase> renderPipeline,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata);
|
||||
RenderPipeline() = delete;
|
||||
|
||||
MaybeError Initialize() override;
|
||||
|
||||
D3D12_PRIMITIVE_TOPOLOGY GetD3D12PrimitiveTopology() const;
|
||||
ID3D12PipelineState* GetPipelineState() const;
|
||||
|
||||
|
@ -47,7 +46,6 @@ namespace dawn_native { namespace d3d12 {
|
|||
private:
|
||||
~RenderPipeline() override;
|
||||
using RenderPipelineBase::RenderPipelineBase;
|
||||
MaybeError Initialize() override;
|
||||
D3D12_INPUT_LAYOUT_DESC ComputeInputLayout(
|
||||
std::array<D3D12_INPUT_ELEMENT_DESC, kMaxVertexAttributes>* inputElementDescriptors);
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ namespace dawn_native { namespace metal {
|
|||
const PipelineLayoutDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<QuerySetBase>> CreateQuerySetImpl(
|
||||
const QuerySetDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<RenderPipelineBase>> CreateRenderPipelineImpl(
|
||||
Ref<RenderPipelineBase> CreateUninitializedRenderPipelineImpl(
|
||||
const RenderPipelineDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<SamplerBase>> CreateSamplerImpl(
|
||||
const SamplerDescriptor* descriptor) override;
|
||||
|
@ -117,10 +117,9 @@ namespace dawn_native { namespace metal {
|
|||
size_t blueprintHash,
|
||||
WGPUCreateComputePipelineAsyncCallback callback,
|
||||
void* userdata) override;
|
||||
void CreateRenderPipelineAsyncImpl(const RenderPipelineDescriptor* descriptor,
|
||||
size_t blueprintHash,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata) override;
|
||||
void InitializeRenderPipelineAsyncImpl(Ref<RenderPipelineBase> renderPipeline,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata) override;
|
||||
|
||||
void InitTogglesFromDriver();
|
||||
void ShutDownImpl() override;
|
||||
|
|
|
@ -255,9 +255,9 @@ namespace dawn_native { namespace metal {
|
|||
const QuerySetDescriptor* descriptor) {
|
||||
return QuerySet::Create(this, descriptor);
|
||||
}
|
||||
ResultOrError<Ref<RenderPipelineBase>> Device::CreateRenderPipelineImpl(
|
||||
Ref<RenderPipelineBase> Device::CreateUninitializedRenderPipelineImpl(
|
||||
const RenderPipelineDescriptor* descriptor) {
|
||||
return RenderPipeline::Create(this, descriptor);
|
||||
return RenderPipeline::CreateUninitialized(this, descriptor);
|
||||
}
|
||||
ResultOrError<Ref<SamplerBase>> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) {
|
||||
return Sampler::Create(this, descriptor);
|
||||
|
@ -291,11 +291,10 @@ namespace dawn_native { namespace metal {
|
|||
void* userdata) {
|
||||
ComputePipeline::CreateAsync(this, descriptor, blueprintHash, callback, userdata);
|
||||
}
|
||||
void Device::CreateRenderPipelineAsyncImpl(const RenderPipelineDescriptor* descriptor,
|
||||
size_t blueprintHash,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata) {
|
||||
RenderPipeline::CreateAsync(this, descriptor, blueprintHash, callback, userdata);
|
||||
void Device::InitializeRenderPipelineAsyncImpl(Ref<RenderPipelineBase> renderPipeline,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata) {
|
||||
RenderPipeline::InitializeAsync(renderPipeline, callback, userdata);
|
||||
}
|
||||
|
||||
ResultOrError<ExecutionSerial> Device::CheckAndUpdateCompletedSerials() {
|
||||
|
|
|
@ -27,14 +27,12 @@ namespace dawn_native { namespace metal {
|
|||
|
||||
class RenderPipeline final : public RenderPipelineBase {
|
||||
public:
|
||||
static ResultOrError<Ref<RenderPipeline>> Create(
|
||||
static Ref<RenderPipelineBase> CreateUninitialized(
|
||||
Device* device,
|
||||
const RenderPipelineDescriptor* descriptor);
|
||||
static void CreateAsync(Device* device,
|
||||
const RenderPipelineDescriptor* descriptor,
|
||||
size_t blueprintHash,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata);
|
||||
static void InitializeAsync(Ref<RenderPipelineBase> renderPipeline,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata);
|
||||
|
||||
MTLPrimitiveType GetMTLPrimitiveTopology() const;
|
||||
MTLWinding GetMTLFrontFace() const;
|
||||
|
@ -50,9 +48,10 @@ namespace dawn_native { namespace metal {
|
|||
|
||||
wgpu::ShaderStage GetStagesRequiringStorageBufferLength() const;
|
||||
|
||||
MaybeError Initialize() override;
|
||||
|
||||
private:
|
||||
using RenderPipelineBase::RenderPipelineBase;
|
||||
MaybeError Initialize() override;
|
||||
|
||||
MTLVertexDescriptor* MakeVertexDesc();
|
||||
|
||||
|
|
|
@ -311,12 +311,10 @@ namespace dawn_native { namespace metal {
|
|||
} // anonymous namespace
|
||||
|
||||
// static
|
||||
ResultOrError<Ref<RenderPipeline>> RenderPipeline::Create(
|
||||
Ref<RenderPipelineBase> RenderPipeline::CreateUninitialized(
|
||||
Device* device,
|
||||
const RenderPipelineDescriptor* descriptor) {
|
||||
Ref<RenderPipeline> pipeline = AcquireRef(new RenderPipeline(device, descriptor));
|
||||
DAWN_TRY(pipeline->Initialize());
|
||||
return pipeline;
|
||||
return AcquireRef(new RenderPipeline(device, descriptor));
|
||||
}
|
||||
|
||||
MaybeError RenderPipeline::Initialize() {
|
||||
|
@ -502,14 +500,11 @@ namespace dawn_native { namespace metal {
|
|||
return mtlVertexDescriptor;
|
||||
}
|
||||
|
||||
void RenderPipeline::CreateAsync(Device* device,
|
||||
const RenderPipelineDescriptor* descriptor,
|
||||
size_t blueprintHash,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata) {
|
||||
Ref<RenderPipeline> pipeline = AcquireRef(new RenderPipeline(device, descriptor));
|
||||
void RenderPipeline::InitializeAsync(Ref<RenderPipelineBase> renderPipeline,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata) {
|
||||
std::unique_ptr<CreateRenderPipelineAsyncTask> asyncTask =
|
||||
std::make_unique<CreateRenderPipelineAsyncTask>(pipeline, blueprintHash, callback,
|
||||
std::make_unique<CreateRenderPipelineAsyncTask>(std::move(renderPipeline), callback,
|
||||
userdata);
|
||||
CreateRenderPipelineAsyncTask::RunAsync(std::move(asyncTask));
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ namespace dawn_native { namespace null {
|
|||
const QuerySetDescriptor* descriptor) {
|
||||
return AcquireRef(new QuerySet(this, descriptor));
|
||||
}
|
||||
ResultOrError<Ref<RenderPipelineBase>> Device::CreateRenderPipelineImpl(
|
||||
Ref<RenderPipelineBase> Device::CreateUninitializedRenderPipelineImpl(
|
||||
const RenderPipelineDescriptor* descriptor) {
|
||||
return AcquireRef(new RenderPipeline(this, descriptor));
|
||||
}
|
||||
|
@ -359,6 +359,11 @@ namespace dawn_native { namespace null {
|
|||
return {};
|
||||
}
|
||||
|
||||
// RenderPipeline
|
||||
MaybeError RenderPipeline::Initialize() {
|
||||
return {};
|
||||
}
|
||||
|
||||
// SwapChain
|
||||
|
||||
// static
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace dawn_native { namespace null {
|
|||
using PipelineLayout = PipelineLayoutBase;
|
||||
class QuerySet;
|
||||
class Queue;
|
||||
using RenderPipeline = RenderPipelineBase;
|
||||
class RenderPipeline;
|
||||
using Sampler = SamplerBase;
|
||||
class ShaderModule;
|
||||
class SwapChain;
|
||||
|
@ -135,7 +135,7 @@ namespace dawn_native { namespace null {
|
|||
const PipelineLayoutDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<QuerySetBase>> CreateQuerySetImpl(
|
||||
const QuerySetDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<RenderPipelineBase>> CreateRenderPipelineImpl(
|
||||
Ref<RenderPipelineBase> CreateUninitializedRenderPipelineImpl(
|
||||
const RenderPipelineDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<SamplerBase>> CreateSamplerImpl(
|
||||
const SamplerDescriptor* descriptor) override;
|
||||
|
@ -251,6 +251,13 @@ namespace dawn_native { namespace null {
|
|||
size_t size) override;
|
||||
};
|
||||
|
||||
class RenderPipeline final : public RenderPipelineBase {
|
||||
public:
|
||||
using RenderPipelineBase::RenderPipelineBase;
|
||||
|
||||
MaybeError Initialize() override;
|
||||
};
|
||||
|
||||
class ShaderModule final : public ShaderModuleBase {
|
||||
public:
|
||||
using ShaderModuleBase::ShaderModuleBase;
|
||||
|
|
|
@ -142,9 +142,9 @@ namespace dawn_native { namespace opengl {
|
|||
const QuerySetDescriptor* descriptor) {
|
||||
return AcquireRef(new QuerySet(this, descriptor));
|
||||
}
|
||||
ResultOrError<Ref<RenderPipelineBase>> Device::CreateRenderPipelineImpl(
|
||||
Ref<RenderPipelineBase> Device::CreateUninitializedRenderPipelineImpl(
|
||||
const RenderPipelineDescriptor* descriptor) {
|
||||
return RenderPipeline::Create(this, descriptor);
|
||||
return RenderPipeline::CreateUninitialized(this, descriptor);
|
||||
}
|
||||
ResultOrError<Ref<SamplerBase>> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) {
|
||||
return AcquireRef(new Sampler(this, descriptor));
|
||||
|
|
|
@ -97,7 +97,7 @@ namespace dawn_native { namespace opengl {
|
|||
const PipelineLayoutDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<QuerySetBase>> CreateQuerySetImpl(
|
||||
const QuerySetDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<RenderPipelineBase>> CreateRenderPipelineImpl(
|
||||
Ref<RenderPipelineBase> CreateUninitializedRenderPipelineImpl(
|
||||
const RenderPipelineDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<SamplerBase>> CreateSamplerImpl(
|
||||
const SamplerDescriptor* descriptor) override;
|
||||
|
|
|
@ -215,12 +215,10 @@ namespace dawn_native { namespace opengl {
|
|||
} // anonymous namespace
|
||||
|
||||
// static
|
||||
ResultOrError<Ref<RenderPipeline>> RenderPipeline::Create(
|
||||
Ref<RenderPipeline> RenderPipeline::CreateUninitialized(
|
||||
Device* device,
|
||||
const RenderPipelineDescriptor* descriptor) {
|
||||
Ref<RenderPipeline> pipeline = AcquireRef(new RenderPipeline(device, descriptor));
|
||||
DAWN_TRY(pipeline->Initialize());
|
||||
return pipeline;
|
||||
return AcquireRef(new RenderPipeline(device, descriptor));
|
||||
}
|
||||
|
||||
RenderPipeline::RenderPipeline(Device* device, const RenderPipelineDescriptor* descriptor)
|
||||
|
|
|
@ -29,9 +29,8 @@ namespace dawn_native { namespace opengl {
|
|||
|
||||
class RenderPipeline final : public RenderPipelineBase, public PipelineGL {
|
||||
public:
|
||||
static ResultOrError<Ref<RenderPipeline>> Create(
|
||||
Device* device,
|
||||
const RenderPipelineDescriptor* descriptor);
|
||||
static Ref<RenderPipeline> CreateUninitialized(Device* device,
|
||||
const RenderPipelineDescriptor* descriptor);
|
||||
|
||||
GLenum GetGLPrimitiveTopology() const;
|
||||
ityp::bitset<VertexAttributeLocation, kMaxVertexAttributes> GetAttributesUsingVertexBuffer(
|
||||
|
@ -39,10 +38,11 @@ namespace dawn_native { namespace opengl {
|
|||
|
||||
void ApplyNow(PersistentPipelineState& persistentPipelineState);
|
||||
|
||||
MaybeError Initialize() override;
|
||||
|
||||
private:
|
||||
RenderPipeline(Device* device, const RenderPipelineDescriptor* descriptor);
|
||||
~RenderPipeline() override;
|
||||
MaybeError Initialize() override;
|
||||
|
||||
void CreateVAOForVertexState();
|
||||
|
||||
|
|
|
@ -132,9 +132,9 @@ namespace dawn_native { namespace vulkan {
|
|||
const QuerySetDescriptor* descriptor) {
|
||||
return QuerySet::Create(this, descriptor);
|
||||
}
|
||||
ResultOrError<Ref<RenderPipelineBase>> Device::CreateRenderPipelineImpl(
|
||||
Ref<RenderPipelineBase> Device::CreateUninitializedRenderPipelineImpl(
|
||||
const RenderPipelineDescriptor* descriptor) {
|
||||
return RenderPipeline::Create(this, descriptor);
|
||||
return RenderPipeline::CreateUninitialized(this, descriptor);
|
||||
}
|
||||
ResultOrError<Ref<SamplerBase>> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) {
|
||||
return Sampler::Create(this, descriptor);
|
||||
|
@ -168,11 +168,10 @@ namespace dawn_native { namespace vulkan {
|
|||
void* userdata) {
|
||||
ComputePipeline::CreateAsync(this, descriptor, blueprintHash, callback, userdata);
|
||||
}
|
||||
void Device::CreateRenderPipelineAsyncImpl(const RenderPipelineDescriptor* descriptor,
|
||||
size_t blueprintHash,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata) {
|
||||
RenderPipeline::CreateAsync(this, descriptor, blueprintHash, callback, userdata);
|
||||
void Device::InitializeRenderPipelineAsyncImpl(Ref<RenderPipelineBase> renderPipeline,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata) {
|
||||
RenderPipeline::InitializeAsync(renderPipeline, callback, userdata);
|
||||
}
|
||||
|
||||
MaybeError Device::TickImpl() {
|
||||
|
|
|
@ -119,7 +119,7 @@ namespace dawn_native { namespace vulkan {
|
|||
const PipelineLayoutDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<QuerySetBase>> CreateQuerySetImpl(
|
||||
const QuerySetDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<RenderPipelineBase>> CreateRenderPipelineImpl(
|
||||
Ref<RenderPipelineBase> CreateUninitializedRenderPipelineImpl(
|
||||
const RenderPipelineDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<SamplerBase>> CreateSamplerImpl(
|
||||
const SamplerDescriptor* descriptor) override;
|
||||
|
@ -141,10 +141,9 @@ namespace dawn_native { namespace vulkan {
|
|||
size_t blueprintHash,
|
||||
WGPUCreateComputePipelineAsyncCallback callback,
|
||||
void* userdata) override;
|
||||
void CreateRenderPipelineAsyncImpl(const RenderPipelineDescriptor* descriptor,
|
||||
size_t blueprintHash,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata) override;
|
||||
void InitializeRenderPipelineAsyncImpl(Ref<RenderPipelineBase> renderPipeline,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata) override;
|
||||
|
||||
ResultOrError<VulkanDeviceKnobs> CreateDevice(VkPhysicalDevice physicalDevice);
|
||||
void GatherQueueFromDevice();
|
||||
|
|
|
@ -328,12 +328,10 @@ namespace dawn_native { namespace vulkan {
|
|||
} // anonymous namespace
|
||||
|
||||
// static
|
||||
ResultOrError<Ref<RenderPipeline>> RenderPipeline::Create(
|
||||
Ref<RenderPipeline> RenderPipeline::CreateUninitialized(
|
||||
Device* device,
|
||||
const RenderPipelineDescriptor* descriptor) {
|
||||
Ref<RenderPipeline> pipeline = AcquireRef(new RenderPipeline(device, descriptor));
|
||||
DAWN_TRY(pipeline->Initialize());
|
||||
return pipeline;
|
||||
return AcquireRef(new RenderPipeline(device, descriptor));
|
||||
}
|
||||
|
||||
MaybeError RenderPipeline::Initialize() {
|
||||
|
@ -610,14 +608,11 @@ namespace dawn_native { namespace vulkan {
|
|||
return mHandle;
|
||||
}
|
||||
|
||||
void RenderPipeline::CreateAsync(Device* device,
|
||||
const RenderPipelineDescriptor* descriptor,
|
||||
size_t blueprintHash,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata) {
|
||||
Ref<RenderPipeline> pipeline = AcquireRef(new RenderPipeline(device, descriptor));
|
||||
void RenderPipeline::InitializeAsync(Ref<RenderPipelineBase> renderPipeline,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata) {
|
||||
std::unique_ptr<CreateRenderPipelineAsyncTask> asyncTask =
|
||||
std::make_unique<CreateRenderPipelineAsyncTask>(pipeline, blueprintHash, callback,
|
||||
std::make_unique<CreateRenderPipelineAsyncTask>(std::move(renderPipeline), callback,
|
||||
userdata);
|
||||
CreateRenderPipelineAsyncTask::RunAsync(std::move(asyncTask));
|
||||
}
|
||||
|
|
|
@ -26,24 +26,22 @@ namespace dawn_native { namespace vulkan {
|
|||
|
||||
class RenderPipeline final : public RenderPipelineBase {
|
||||
public:
|
||||
static ResultOrError<Ref<RenderPipeline>> Create(
|
||||
Device* device,
|
||||
const RenderPipelineDescriptor* descriptor);
|
||||
static void CreateAsync(Device* device,
|
||||
const RenderPipelineDescriptor* descriptor,
|
||||
size_t blueprintHash,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata);
|
||||
static Ref<RenderPipeline> CreateUninitialized(Device* device,
|
||||
const RenderPipelineDescriptor* descriptor);
|
||||
static void InitializeAsync(Ref<RenderPipelineBase> renderPipeline,
|
||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||
void* userdata);
|
||||
|
||||
VkPipeline GetHandle() const;
|
||||
|
||||
MaybeError Initialize() override;
|
||||
|
||||
// Dawn API
|
||||
void SetLabelImpl() override;
|
||||
|
||||
private:
|
||||
~RenderPipeline() override;
|
||||
using RenderPipelineBase::RenderPipelineBase;
|
||||
MaybeError Initialize() override;
|
||||
|
||||
struct PipelineVertexInputStateCreateInfoTemporaryAllocations {
|
||||
std::array<VkVertexInputBindingDescription, kMaxVertexBuffers> bindings;
|
||||
|
|
Loading…
Reference in New Issue