DeviceBase: Make object creation use ResultOrError<Ref<T>>

This is in preparation for a change that will change all the
CreateFooInternal to be CreateFoo so they can be called in a
reentrant manner without special refcounting.

This also standardizes all the backends (except OpenGL and Null)
to use Object::Create that returns a Ref<T> or ResultOrError<Ref<T>>,
something we wanted to do for a long time.

Bug: dawn:723

Change-Id: I9e0baced333ffeb0affbc6a276c9bd9de082263a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/46440
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2021-03-31 18:36:32 +00:00 committed by Commit Bot service account
parent 7ef8633593
commit 50f995851d
92 changed files with 701 additions and 620 deletions

View File

@ -897,18 +897,28 @@ namespace dawn_native {
}
CommandBufferBase* CommandEncoder::APIFinish(const CommandBufferDescriptor* descriptor) {
Ref<CommandBufferBase> commandBuffer;
if (GetDevice()->ConsumedError(FinishInternal(descriptor), &commandBuffer)) {
return CommandBufferBase::MakeError(GetDevice());
}
ASSERT(!IsError());
return commandBuffer.Detach();
}
ResultOrError<Ref<CommandBufferBase>> CommandEncoder::FinishInternal(
const CommandBufferDescriptor* descriptor) {
DeviceBase* device = GetDevice();
// Even if mEncodingContext.Finish() validation fails, calling it will mutate the internal
// state of the encoding context. The internal state is set to finished, and subsequent
// calls to encode commands will generate errors.
if (device->ConsumedError(mEncodingContext.Finish()) ||
device->ConsumedError(device->ValidateIsAlive()) ||
(device->IsValidationEnabled() &&
device->ConsumedError(ValidateFinish(mEncodingContext.GetIterator(),
mEncodingContext.GetPassUsages())))) {
return CommandBufferBase::MakeError(device);
DAWN_TRY(mEncodingContext.Finish());
DAWN_TRY(device->ValidateIsAlive());
if (device->IsValidationEnabled()) {
DAWN_TRY(
ValidateFinish(mEncodingContext.GetIterator(), mEncodingContext.GetPassUsages()));
}
ASSERT(!IsError());
return device->CreateCommandBuffer(this, descriptor);
}

View File

@ -74,6 +74,9 @@ namespace dawn_native {
CommandBufferBase* APIFinish(const CommandBufferDescriptor* descriptor = nullptr);
private:
ResultOrError<Ref<CommandBufferBase>> FinishInternal(
const CommandBufferDescriptor* descriptor);
MaybeError ValidateFinish(CommandIterator* commands,
const PerPassUsages& perPassUsages) const;

View File

@ -442,18 +442,17 @@ namespace dawn_native {
const size_t blueprintHash = blueprint.ComputeContentHash();
blueprint.SetContentHash(blueprintHash);
Ref<BindGroupLayoutBase> result = nullptr;
Ref<BindGroupLayoutBase> result;
auto iter = mCaches->bindGroupLayouts.find(&blueprint);
if (iter != mCaches->bindGroupLayouts.end()) {
result = *iter;
} else {
BindGroupLayoutBase* backendObj;
DAWN_TRY_ASSIGN(backendObj, CreateBindGroupLayoutImpl(descriptor));
backendObj->SetIsCachedReference();
backendObj->SetContentHash(blueprintHash);
mCaches->bindGroupLayouts.insert(backendObj);
result = AcquireRef(backendObj);
DAWN_TRY_ASSIGN(result, CreateBindGroupLayoutImpl(descriptor));
result->SetIsCachedReference();
result->SetContentHash(blueprintHash);
mCaches->bindGroupLayouts.insert(result.Get());
}
return std::move(result);
}
@ -477,25 +476,25 @@ namespace dawn_native {
return mEmptyBindGroupLayout.Get();
}
ResultOrError<ComputePipelineBase*> DeviceBase::GetOrCreateComputePipeline(
ResultOrError<Ref<ComputePipelineBase>> DeviceBase::GetOrCreateComputePipeline(
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);
if (iter != mCaches->computePipelines.end()) {
(*iter)->Reference();
return *iter;
result = *iter;
} else {
DAWN_TRY_ASSIGN(result, CreateComputePipelineImpl(descriptor));
result->SetIsCachedReference();
result->SetContentHash(blueprintHash);
mCaches->computePipelines.insert(result.Get());
}
ComputePipelineBase* backendObj;
DAWN_TRY_ASSIGN(backendObj, CreateComputePipelineImpl(descriptor));
backendObj->SetIsCachedReference();
backendObj->SetContentHash(blueprintHash);
mCaches->computePipelines.insert(backendObj);
return backendObj;
return std::move(result);
}
void DeviceBase::UncacheComputePipeline(ComputePipelineBase* obj) {
@ -504,25 +503,25 @@ namespace dawn_native {
ASSERT(removedCount == 1);
}
ResultOrError<PipelineLayoutBase*> DeviceBase::GetOrCreatePipelineLayout(
ResultOrError<Ref<PipelineLayoutBase>> DeviceBase::GetOrCreatePipelineLayout(
const PipelineLayoutDescriptor* descriptor) {
PipelineLayoutBase blueprint(this, descriptor);
const size_t blueprintHash = blueprint.ComputeContentHash();
blueprint.SetContentHash(blueprintHash);
Ref<PipelineLayoutBase> result;
auto iter = mCaches->pipelineLayouts.find(&blueprint);
if (iter != mCaches->pipelineLayouts.end()) {
(*iter)->Reference();
return *iter;
result = *iter;
} else {
DAWN_TRY_ASSIGN(result, CreatePipelineLayoutImpl(descriptor));
result->SetIsCachedReference();
result->SetContentHash(blueprintHash);
mCaches->pipelineLayouts.insert(result.Get());
}
PipelineLayoutBase* backendObj;
DAWN_TRY_ASSIGN(backendObj, CreatePipelineLayoutImpl(descriptor));
backendObj->SetIsCachedReference();
backendObj->SetContentHash(blueprintHash);
mCaches->pipelineLayouts.insert(backendObj);
return backendObj;
return std::move(result);
}
void DeviceBase::UncachePipelineLayout(PipelineLayoutBase* obj) {
@ -531,25 +530,25 @@ namespace dawn_native {
ASSERT(removedCount == 1);
}
ResultOrError<RenderPipelineBase*> DeviceBase::GetOrCreateRenderPipeline(
ResultOrError<Ref<RenderPipelineBase>> DeviceBase::GetOrCreateRenderPipeline(
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);
if (iter != mCaches->renderPipelines.end()) {
(*iter)->Reference();
return *iter;
result = *iter;
} else {
DAWN_TRY_ASSIGN(result, CreateRenderPipelineImpl(descriptor));
result->SetIsCachedReference();
result->SetContentHash(blueprintHash);
mCaches->renderPipelines.insert(result.Get());
}
RenderPipelineBase* backendObj;
DAWN_TRY_ASSIGN(backendObj, CreateRenderPipelineImpl(descriptor));
backendObj->SetIsCachedReference();
backendObj->SetContentHash(blueprintHash);
mCaches->renderPipelines.insert(backendObj);
return backendObj;
return std::move(result);
}
void DeviceBase::UncacheRenderPipeline(RenderPipelineBase* obj) {
@ -558,25 +557,25 @@ namespace dawn_native {
ASSERT(removedCount == 1);
}
ResultOrError<SamplerBase*> DeviceBase::GetOrCreateSampler(
ResultOrError<Ref<SamplerBase>> DeviceBase::GetOrCreateSampler(
const SamplerDescriptor* descriptor) {
SamplerBase blueprint(this, descriptor);
const size_t blueprintHash = blueprint.ComputeContentHash();
blueprint.SetContentHash(blueprintHash);
Ref<SamplerBase> result;
auto iter = mCaches->samplers.find(&blueprint);
if (iter != mCaches->samplers.end()) {
(*iter)->Reference();
return *iter;
result = *iter;
} else {
DAWN_TRY_ASSIGN(result, CreateSamplerImpl(descriptor));
result->SetIsCachedReference();
result->SetContentHash(blueprintHash);
mCaches->samplers.insert(result.Get());
}
SamplerBase* backendObj;
DAWN_TRY_ASSIGN(backendObj, CreateSamplerImpl(descriptor));
backendObj->SetIsCachedReference();
backendObj->SetContentHash(blueprintHash);
mCaches->samplers.insert(backendObj);
return backendObj;
return std::move(result);
}
void DeviceBase::UncacheSampler(SamplerBase* obj) {
@ -585,7 +584,7 @@ namespace dawn_native {
ASSERT(removedCount == 1);
}
ResultOrError<ShaderModuleBase*> DeviceBase::GetOrCreateShaderModule(
ResultOrError<Ref<ShaderModuleBase>> DeviceBase::GetOrCreateShaderModule(
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult) {
ShaderModuleBase blueprint(this, descriptor);
@ -593,29 +592,29 @@ namespace dawn_native {
const size_t blueprintHash = blueprint.ComputeContentHash();
blueprint.SetContentHash(blueprintHash);
Ref<ShaderModuleBase> result;
auto iter = mCaches->shaderModules.find(&blueprint);
if (iter != mCaches->shaderModules.end()) {
(*iter)->Reference();
return *iter;
}
ShaderModuleBase* backendObj;
result = *iter;
} else {
if (parseResult == nullptr) {
// We skip the parse on creation if validation isn't enabled which let's us quickly
// lookup in the cache without validating and parsing. We need the parsed module now, so
// call validate. Most of |ValidateShaderModuleDescriptor| is parsing, but we can
// consider splitting it if additional validation is added.
// lookup in the cache without validating and parsing. We need the parsed module
// now, so call validate. Most of |ValidateShaderModuleDescriptor| is parsing, but
// we can consider splitting it if additional validation is added.
ASSERT(!IsValidationEnabled());
ShaderModuleParseResult localParseResult =
ValidateShaderModuleDescriptor(this, descriptor).AcquireSuccess();
DAWN_TRY_ASSIGN(backendObj, CreateShaderModuleImpl(descriptor, &localParseResult));
DAWN_TRY_ASSIGN(result, CreateShaderModuleImpl(descriptor, &localParseResult));
} else {
DAWN_TRY_ASSIGN(backendObj, CreateShaderModuleImpl(descriptor, parseResult));
DAWN_TRY_ASSIGN(result, CreateShaderModuleImpl(descriptor, parseResult));
}
backendObj->SetIsCachedReference();
backendObj->SetContentHash(blueprintHash);
mCaches->shaderModules.insert(backendObj);
return backendObj;
result->SetIsCachedReference();
result->SetContentHash(blueprintHash);
mCaches->shaderModules.insert(result.Get());
}
return std::move(result);
}
void DeviceBase::UncacheShaderModule(ShaderModuleBase* obj) {
@ -665,23 +664,19 @@ namespace dawn_native {
// Object creation API methods
BindGroupBase* DeviceBase::APICreateBindGroup(const BindGroupDescriptor* descriptor) {
BindGroupBase* result = nullptr;
if (ConsumedError(CreateBindGroupInternal(&result, descriptor))) {
Ref<BindGroupBase> result;
if (ConsumedError(CreateBindGroupInternal(descriptor), &result)) {
return BindGroupBase::MakeError(this);
}
return result;
return result.Detach();
}
BindGroupLayoutBase* DeviceBase::APICreateBindGroupLayout(
const BindGroupLayoutDescriptor* descriptor) {
BindGroupLayoutBase* result = nullptr;
if (ConsumedError(CreateBindGroupLayoutInternal(&result, descriptor))) {
Ref<BindGroupLayoutBase> result;
if (ConsumedError(CreateBindGroupLayoutInternal(descriptor), &result)) {
return BindGroupLayoutBase::MakeError(this);
}
return result;
return result.Detach();
}
BufferBase* DeviceBase::APICreateBuffer(const BufferDescriptor* descriptor) {
Ref<BufferBase> result = nullptr;
@ -689,7 +684,6 @@ namespace dawn_native {
ASSERT(result == nullptr);
return BufferBase::MakeError(this, descriptor);
}
return result.Detach();
}
CommandEncoder* DeviceBase::APICreateCommandEncoder(
@ -698,19 +692,15 @@ namespace dawn_native {
}
ComputePipelineBase* DeviceBase::APICreateComputePipeline(
const ComputePipelineDescriptor* descriptor) {
ComputePipelineBase* result = nullptr;
if (ConsumedError(CreateComputePipelineInternal(&result, descriptor))) {
Ref<ComputePipelineBase> result;
if (ConsumedError(CreateComputePipelineInternal(descriptor), &result)) {
return ComputePipelineBase::MakeError(this);
}
return result;
return result.Detach();
}
void DeviceBase::APICreateComputePipelineAsync(const ComputePipelineDescriptor* descriptor,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) {
ComputePipelineBase* result = nullptr;
if (IsToggleEnabled(Toggle::DisallowUnsafeAPIs)) {
callback(WGPUCreatePipelineAsyncStatus_Error, nullptr,
"CreateComputePipelineAsync is disallowed because it isn't completely "
@ -719,51 +709,45 @@ namespace dawn_native {
return;
}
MaybeError maybeError = CreateComputePipelineInternal(&result, descriptor);
if (maybeError.IsError()) {
std::unique_ptr<ErrorData> error = maybeError.AcquireError();
ResultOrError<Ref<ComputePipelineBase>> maybeResult =
CreateComputePipelineInternal(descriptor);
if (maybeResult.IsError()) {
std::unique_ptr<ErrorData> error = maybeResult.AcquireError();
callback(WGPUCreatePipelineAsyncStatus_Error, nullptr, error->GetMessage().c_str(),
userdata);
return;
}
std::unique_ptr<CreateComputePipelineAsyncTask> request =
std::make_unique<CreateComputePipelineAsyncTask>(result, callback, userdata);
std::make_unique<CreateComputePipelineAsyncTask>(maybeResult.AcquireSuccess().Detach(),
callback, userdata);
mCreatePipelineAsyncTracker->TrackTask(std::move(request), GetPendingCommandSerial());
}
PipelineLayoutBase* DeviceBase::APICreatePipelineLayout(
const PipelineLayoutDescriptor* descriptor) {
PipelineLayoutBase* result = nullptr;
if (ConsumedError(CreatePipelineLayoutInternal(&result, descriptor))) {
Ref<PipelineLayoutBase> result;
if (ConsumedError(CreatePipelineLayoutInternal(descriptor), &result)) {
return PipelineLayoutBase::MakeError(this);
}
return result;
return result.Detach();
}
QuerySetBase* DeviceBase::APICreateQuerySet(const QuerySetDescriptor* descriptor) {
QuerySetBase* result = nullptr;
if (ConsumedError(CreateQuerySetInternal(&result, descriptor))) {
Ref<QuerySetBase> result;
if (ConsumedError(CreateQuerySetInternal(descriptor), &result)) {
return QuerySetBase::MakeError(this);
}
return result;
return result.Detach();
}
SamplerBase* DeviceBase::APICreateSampler(const SamplerDescriptor* descriptor) {
SamplerBase* result = nullptr;
if (ConsumedError(CreateSamplerInternal(&result, descriptor))) {
Ref<SamplerBase> result;
if (ConsumedError(CreateSamplerInternal(descriptor), &result)) {
return SamplerBase::MakeError(this);
}
return result;
return result.Detach();
}
void DeviceBase::APICreateRenderPipelineAsync(const RenderPipelineDescriptor2* descriptor,
WGPUCreateRenderPipelineAsyncCallback callback,
void* userdata) {
RenderPipelineBase* result = nullptr;
if (IsToggleEnabled(Toggle::DisallowUnsafeAPIs)) {
callback(WGPUCreatePipelineAsyncStatus_Error, nullptr,
"CreateRenderPipelineAsync is disallowed because it isn't completely "
@ -772,91 +756,79 @@ namespace dawn_native {
return;
}
MaybeError maybeError = CreateRenderPipelineInternal(&result, descriptor);
if (maybeError.IsError()) {
std::unique_ptr<ErrorData> error = maybeError.AcquireError();
ResultOrError<Ref<RenderPipelineBase>> maybeResult =
CreateRenderPipelineInternal(descriptor);
if (maybeResult.IsError()) {
std::unique_ptr<ErrorData> error = maybeResult.AcquireError();
callback(WGPUCreatePipelineAsyncStatus_Error, nullptr, error->GetMessage().c_str(),
userdata);
return;
}
std::unique_ptr<CreateRenderPipelineAsyncTask> request =
std::make_unique<CreateRenderPipelineAsyncTask>(result, callback, userdata);
std::make_unique<CreateRenderPipelineAsyncTask>(maybeResult.AcquireSuccess().Detach(),
callback, userdata);
mCreatePipelineAsyncTracker->TrackTask(std::move(request), GetPendingCommandSerial());
}
RenderBundleEncoder* DeviceBase::APICreateRenderBundleEncoder(
const RenderBundleEncoderDescriptor* descriptor) {
RenderBundleEncoder* result = nullptr;
if (ConsumedError(CreateRenderBundleEncoderInternal(&result, descriptor))) {
Ref<RenderBundleEncoder> result;
if (ConsumedError(CreateRenderBundleEncoderInternal(descriptor), &result)) {
return RenderBundleEncoder::MakeError(this);
}
return result;
return result.Detach();
}
RenderPipelineBase* DeviceBase::APICreateRenderPipeline(
const RenderPipelineDescriptor* descriptor) {
RenderPipelineBase* result = nullptr;
// TODO: Enable this warning once the tests have been converted to either use the new
// format or expect the deprecation warning.
/*EmitDeprecationWarning(
"The format of RenderPipelineDescriptor has changed, and will soon require the "
"new structure. Please begin using CreateRenderPipeline2() instead.");*/
if (ConsumedError(CreateRenderPipelineInternal(&result, descriptor))) {
Ref<RenderPipelineBase> result;
if (ConsumedError(CreateRenderPipelineInternal(descriptor), &result)) {
return RenderPipelineBase::MakeError(this);
}
return result;
return result.Detach();
}
RenderPipelineBase* DeviceBase::APICreateRenderPipeline2(
const RenderPipelineDescriptor2* descriptor) {
RenderPipelineBase* result = nullptr;
if (ConsumedError(CreateRenderPipelineInternal(&result, descriptor))) {
Ref<RenderPipelineBase> result;
if (ConsumedError(CreateRenderPipelineInternal(descriptor), &result)) {
return RenderPipelineBase::MakeError(this);
}
return result;
return result.Detach();
}
ShaderModuleBase* DeviceBase::APICreateShaderModule(const ShaderModuleDescriptor* descriptor) {
ShaderModuleBase* result = nullptr;
if (ConsumedError(CreateShaderModuleInternal(&result, descriptor))) {
Ref<ShaderModuleBase> result;
if (ConsumedError(CreateShaderModuleInternal(descriptor), &result)) {
return ShaderModuleBase::MakeError(this);
}
return result;
return result.Detach();
}
SwapChainBase* DeviceBase::APICreateSwapChain(Surface* surface,
const SwapChainDescriptor* descriptor) {
SwapChainBase* result = nullptr;
if (ConsumedError(CreateSwapChainInternal(&result, surface, descriptor))) {
Ref<SwapChainBase> result;
if (ConsumedError(CreateSwapChainInternal(surface, descriptor), &result)) {
return SwapChainBase::MakeError(this);
}
return result;
return result.Detach();
}
TextureBase* DeviceBase::APICreateTexture(const TextureDescriptor* descriptor) {
Ref<TextureBase> result;
if (ConsumedError(CreateTextureInternal(descriptor), &result)) {
return TextureBase::MakeError(this);
}
return result.Detach();
}
TextureViewBase* DeviceBase::CreateTextureView(TextureBase* texture,
const TextureViewDescriptor* descriptor) {
TextureViewBase* result = nullptr;
if (ConsumedError(CreateTextureViewInternal(&result, texture, descriptor))) {
Ref<TextureViewBase> result;
if (ConsumedError(CreateTextureViewInternal(texture, descriptor), &result)) {
return TextureViewBase::MakeError(this);
}
return result;
return result.Detach();
}
// For Dawn Wire
@ -971,27 +943,22 @@ namespace dawn_native {
// Implementation details of object creation
MaybeError DeviceBase::CreateBindGroupInternal(BindGroupBase** result,
ResultOrError<Ref<BindGroupBase>> DeviceBase::CreateBindGroupInternal(
const BindGroupDescriptor* descriptor) {
DAWN_TRY(ValidateIsAlive());
if (IsValidationEnabled()) {
DAWN_TRY(ValidateBindGroupDescriptor(this, descriptor));
}
DAWN_TRY_ASSIGN(*result, CreateBindGroupImpl(descriptor));
return {};
return CreateBindGroupImpl(descriptor);
}
MaybeError DeviceBase::CreateBindGroupLayoutInternal(
BindGroupLayoutBase** result,
ResultOrError<Ref<BindGroupLayoutBase>> DeviceBase::CreateBindGroupLayoutInternal(
const BindGroupLayoutDescriptor* descriptor) {
DAWN_TRY(ValidateIsAlive());
if (IsValidationEnabled()) {
DAWN_TRY(ValidateBindGroupLayoutDescriptor(this, descriptor));
}
Ref<BindGroupLayoutBase> bgl;
DAWN_TRY_ASSIGN(bgl, GetOrCreateBindGroupLayout(descriptor));
*result = bgl.Detach();
return {};
return GetOrCreateBindGroupLayout(descriptor);
}
ResultOrError<Ref<BufferBase>> DeviceBase::CreateBufferInternal(
@ -1011,8 +978,7 @@ namespace dawn_native {
return std::move(buffer);
}
MaybeError DeviceBase::CreateComputePipelineInternal(
ComputePipelineBase** result,
ResultOrError<Ref<ComputePipelineBase>> DeviceBase::CreateComputePipelineInternal(
const ComputePipelineDescriptor* descriptor) {
DAWN_TRY(ValidateIsAlive());
if (IsValidationEnabled()) {
@ -1032,47 +998,40 @@ namespace dawn_native {
descriptorWithDefaultLayout.layout = layoutRef.Get();
DAWN_TRY_ASSIGN(*result, GetOrCreateComputePipeline(&descriptorWithDefaultLayout));
return GetOrCreateComputePipeline(&descriptorWithDefaultLayout);
} else {
DAWN_TRY_ASSIGN(*result, GetOrCreateComputePipeline(descriptor));
return GetOrCreateComputePipeline(descriptor);
}
return {};
}
MaybeError DeviceBase::CreatePipelineLayoutInternal(
PipelineLayoutBase** result,
ResultOrError<Ref<PipelineLayoutBase>> DeviceBase::CreatePipelineLayoutInternal(
const PipelineLayoutDescriptor* descriptor) {
DAWN_TRY(ValidateIsAlive());
if (IsValidationEnabled()) {
DAWN_TRY(ValidatePipelineLayoutDescriptor(this, descriptor));
}
DAWN_TRY_ASSIGN(*result, GetOrCreatePipelineLayout(descriptor));
return {};
return GetOrCreatePipelineLayout(descriptor);
}
MaybeError DeviceBase::CreateQuerySetInternal(QuerySetBase** result,
ResultOrError<Ref<QuerySetBase>> DeviceBase::CreateQuerySetInternal(
const QuerySetDescriptor* descriptor) {
DAWN_TRY(ValidateIsAlive());
if (IsValidationEnabled()) {
DAWN_TRY(ValidateQuerySetDescriptor(this, descriptor));
}
DAWN_TRY_ASSIGN(*result, CreateQuerySetImpl(descriptor));
return {};
return CreateQuerySetImpl(descriptor);
}
MaybeError DeviceBase::CreateRenderBundleEncoderInternal(
RenderBundleEncoder** result,
ResultOrError<Ref<RenderBundleEncoder>> DeviceBase::CreateRenderBundleEncoderInternal(
const RenderBundleEncoderDescriptor* descriptor) {
DAWN_TRY(ValidateIsAlive());
if (IsValidationEnabled()) {
DAWN_TRY(ValidateRenderBundleEncoderDescriptor(this, descriptor));
}
*result = new RenderBundleEncoder(this, descriptor);
return {};
return RenderBundleEncoder::Create(this, descriptor);
}
MaybeError DeviceBase::CreateRenderPipelineInternal(
RenderPipelineBase** result,
ResultOrError<Ref<RenderPipelineBase>> DeviceBase::CreateRenderPipelineInternal(
const RenderPipelineDescriptor2* descriptor) {
DAWN_TRY(ValidateIsAlive());
if (IsValidationEnabled()) {
@ -1164,13 +1123,10 @@ namespace dawn_native {
normalizedDescriptor.layout = layoutRef.Get();
}
DAWN_TRY_ASSIGN(*result, GetOrCreateRenderPipeline(&normalizedDescriptor));
return {};
return GetOrCreateRenderPipeline(&normalizedDescriptor);
}
MaybeError DeviceBase::CreateRenderPipelineInternal(
RenderPipelineBase** result,
ResultOrError<Ref<RenderPipelineBase>> DeviceBase::CreateRenderPipelineInternal(
const RenderPipelineDescriptor* descriptor) {
DAWN_TRY(ValidateIsAlive());
@ -1188,14 +1144,13 @@ namespace dawn_native {
PipelineLayoutBase::CreateDefault(this, GetStages(descriptor)));
descriptorWithDefaultLayout.layout = layoutRef.Get();
DAWN_TRY_ASSIGN(*result, GetOrCreateRenderPipeline(&descriptorWithDefaultLayout));
return GetOrCreateRenderPipeline(&descriptorWithDefaultLayout);
} else {
DAWN_TRY_ASSIGN(*result, GetOrCreateRenderPipeline(descriptor));
return GetOrCreateRenderPipeline(descriptor);
}
return {};
}
MaybeError DeviceBase::CreateSamplerInternal(SamplerBase** result,
ResultOrError<Ref<SamplerBase>> DeviceBase::CreateSamplerInternal(
const SamplerDescriptor* descriptor) {
const SamplerDescriptor defaultDescriptor = {};
DAWN_TRY(ValidateIsAlive());
@ -1203,11 +1158,10 @@ namespace dawn_native {
if (IsValidationEnabled()) {
DAWN_TRY(ValidateSamplerDescriptor(this, descriptor));
}
DAWN_TRY_ASSIGN(*result, GetOrCreateSampler(descriptor));
return {};
return GetOrCreateSampler(descriptor);
}
MaybeError DeviceBase::CreateShaderModuleInternal(ShaderModuleBase** result,
ResultOrError<Ref<ShaderModuleBase>> DeviceBase::CreateShaderModuleInternal(
const ShaderModuleDescriptor* descriptor) {
DAWN_TRY(ValidateIsAlive());
@ -1218,11 +1172,10 @@ namespace dawn_native {
parseResultPtr = &parseResult;
}
DAWN_TRY_ASSIGN(*result, GetOrCreateShaderModule(descriptor, parseResultPtr));
return {};
return GetOrCreateShaderModule(descriptor, parseResultPtr);
}
MaybeError DeviceBase::CreateSwapChainInternal(SwapChainBase** result,
ResultOrError<Ref<SwapChainBase>> DeviceBase::CreateSwapChainInternal(
Surface* surface,
const SwapChainDescriptor* descriptor) {
DAWN_TRY(ValidateIsAlive());
@ -1232,26 +1185,25 @@ namespace dawn_native {
// TODO(dawn:269): Remove this code path once implementation-based swapchains are removed.
if (surface == nullptr) {
DAWN_TRY_ASSIGN(*result, CreateSwapChainImpl(descriptor));
return CreateSwapChainImpl(descriptor);
} else {
ASSERT(descriptor->implementation == 0);
NewSwapChainBase* previousSwapChain = surface->GetAttachedSwapChain();
ResultOrError<NewSwapChainBase*> maybeNewSwapChain =
ResultOrError<Ref<NewSwapChainBase>> maybeNewSwapChain =
CreateSwapChainImpl(surface, previousSwapChain, descriptor);
if (previousSwapChain != nullptr) {
previousSwapChain->DetachFromSurface();
}
NewSwapChainBase* newSwapChain = nullptr;
Ref<NewSwapChainBase> newSwapChain;
DAWN_TRY_ASSIGN(newSwapChain, std::move(maybeNewSwapChain));
newSwapChain->SetIsAttached();
surface->SetAttachedSwapChain(newSwapChain);
*result = newSwapChain;
surface->SetAttachedSwapChain(newSwapChain.Get());
return newSwapChain;
}
return {};
}
ResultOrError<Ref<TextureBase>> DeviceBase::CreateTextureInternal(
@ -1265,7 +1217,7 @@ namespace dawn_native {
return CreateTextureImpl(&fixedDescriptor);
}
MaybeError DeviceBase::CreateTextureViewInternal(TextureViewBase** result,
ResultOrError<Ref<TextureViewBase>> DeviceBase::CreateTextureViewInternal(
TextureBase* texture,
const TextureViewDescriptor* descriptor) {
DAWN_TRY(ValidateIsAlive());
@ -1274,8 +1226,7 @@ namespace dawn_native {
if (IsValidationEnabled()) {
DAWN_TRY(ValidateTextureViewDescriptor(texture, &desc));
}
DAWN_TRY_ASSIGN(*result, CreateTextureViewImpl(texture, &desc));
return {};
return CreateTextureViewImpl(texture, &desc);
}
// Other implementation details

View File

@ -81,7 +81,7 @@ namespace dawn_native {
// The reference returned has the same lifetime as the device.
const Format& GetValidInternalFormat(wgpu::TextureFormat format) const;
virtual CommandBufferBase* CreateCommandBuffer(
virtual ResultOrError<Ref<CommandBufferBase>> CreateCommandBuffer(
CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor) = 0;
@ -110,22 +110,22 @@ namespace dawn_native {
BindGroupLayoutBase* GetEmptyBindGroupLayout();
ResultOrError<ComputePipelineBase*> GetOrCreateComputePipeline(
ResultOrError<Ref<ComputePipelineBase>> GetOrCreateComputePipeline(
const ComputePipelineDescriptor* descriptor);
void UncacheComputePipeline(ComputePipelineBase* obj);
ResultOrError<PipelineLayoutBase*> GetOrCreatePipelineLayout(
ResultOrError<Ref<PipelineLayoutBase>> GetOrCreatePipelineLayout(
const PipelineLayoutDescriptor* descriptor);
void UncachePipelineLayout(PipelineLayoutBase* obj);
ResultOrError<RenderPipelineBase*> GetOrCreateRenderPipeline(
ResultOrError<Ref<RenderPipelineBase>> GetOrCreateRenderPipeline(
const RenderPipelineDescriptor* descriptor);
void UncacheRenderPipeline(RenderPipelineBase* obj);
ResultOrError<SamplerBase*> GetOrCreateSampler(const SamplerDescriptor* descriptor);
ResultOrError<Ref<SamplerBase>> GetOrCreateSampler(const SamplerDescriptor* descriptor);
void UncacheSampler(SamplerBase* obj);
ResultOrError<ShaderModuleBase*> GetOrCreateShaderModule(
ResultOrError<Ref<ShaderModuleBase>> GetOrCreateShaderModule(
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult);
void UncacheShaderModule(ShaderModuleBase* obj);
@ -259,35 +259,35 @@ namespace dawn_native {
void IncrementLastSubmittedCommandSerial();
private:
virtual ResultOrError<BindGroupBase*> CreateBindGroupImpl(
virtual ResultOrError<Ref<BindGroupBase>> CreateBindGroupImpl(
const BindGroupDescriptor* descriptor) = 0;
virtual ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
virtual ResultOrError<Ref<BindGroupLayoutBase>> CreateBindGroupLayoutImpl(
const BindGroupLayoutDescriptor* descriptor) = 0;
virtual ResultOrError<Ref<BufferBase>> CreateBufferImpl(
const BufferDescriptor* descriptor) = 0;
virtual ResultOrError<ComputePipelineBase*> CreateComputePipelineImpl(
virtual ResultOrError<Ref<ComputePipelineBase>> CreateComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) = 0;
virtual ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
virtual ResultOrError<Ref<PipelineLayoutBase>> CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) = 0;
virtual ResultOrError<QuerySetBase*> CreateQuerySetImpl(
virtual ResultOrError<Ref<QuerySetBase>> CreateQuerySetImpl(
const QuerySetDescriptor* descriptor) = 0;
virtual ResultOrError<RenderPipelineBase*> CreateRenderPipelineImpl(
virtual ResultOrError<Ref<RenderPipelineBase>> CreateRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) = 0;
virtual ResultOrError<SamplerBase*> CreateSamplerImpl(
virtual ResultOrError<Ref<SamplerBase>> CreateSamplerImpl(
const SamplerDescriptor* descriptor) = 0;
virtual ResultOrError<ShaderModuleBase*> CreateShaderModuleImpl(
virtual ResultOrError<Ref<ShaderModuleBase>> CreateShaderModuleImpl(
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult) = 0;
virtual ResultOrError<SwapChainBase*> CreateSwapChainImpl(
virtual ResultOrError<Ref<SwapChainBase>> CreateSwapChainImpl(
const SwapChainDescriptor* descriptor) = 0;
// Note that previousSwapChain may be nullptr, or come from a different backend.
virtual ResultOrError<NewSwapChainBase*> CreateSwapChainImpl(
virtual ResultOrError<Ref<NewSwapChainBase>> CreateSwapChainImpl(
Surface* surface,
NewSwapChainBase* previousSwapChain,
const SwapChainDescriptor* descriptor) = 0;
virtual ResultOrError<Ref<TextureBase>> CreateTextureImpl(
const TextureDescriptor* descriptor) = 0;
virtual ResultOrError<TextureViewBase*> CreateTextureViewImpl(
virtual ResultOrError<Ref<TextureViewBase>> CreateTextureViewImpl(
TextureBase* texture,
const TextureViewDescriptor* descriptor) = 0;
@ -295,32 +295,31 @@ namespace dawn_native {
ResultOrError<Ref<BindGroupLayoutBase>> CreateEmptyBindGroupLayout();
MaybeError CreateBindGroupInternal(BindGroupBase** result,
ResultOrError<Ref<BindGroupBase>> CreateBindGroupInternal(
const BindGroupDescriptor* descriptor);
MaybeError CreateBindGroupLayoutInternal(BindGroupLayoutBase** result,
ResultOrError<Ref<BindGroupLayoutBase>> CreateBindGroupLayoutInternal(
const BindGroupLayoutDescriptor* descriptor);
ResultOrError<Ref<BufferBase>> CreateBufferInternal(const BufferDescriptor* descriptor);
MaybeError CreateComputePipelineInternal(ComputePipelineBase** result,
ResultOrError<Ref<ComputePipelineBase>> CreateComputePipelineInternal(
const ComputePipelineDescriptor* descriptor);
MaybeError CreatePipelineLayoutInternal(PipelineLayoutBase** result,
ResultOrError<Ref<PipelineLayoutBase>> CreatePipelineLayoutInternal(
const PipelineLayoutDescriptor* descriptor);
MaybeError CreateQuerySetInternal(QuerySetBase** result,
ResultOrError<Ref<QuerySetBase>> CreateQuerySetInternal(
const QuerySetDescriptor* descriptor);
MaybeError CreateRenderBundleEncoderInternal(
RenderBundleEncoder** result,
ResultOrError<Ref<RenderBundleEncoder>> CreateRenderBundleEncoderInternal(
const RenderBundleEncoderDescriptor* descriptor);
MaybeError CreateRenderPipelineInternal(RenderPipelineBase** result,
ResultOrError<Ref<RenderPipelineBase>> CreateRenderPipelineInternal(
const RenderPipelineDescriptor2* descriptor);
MaybeError CreateRenderPipelineInternal(RenderPipelineBase** result,
ResultOrError<Ref<RenderPipelineBase>> CreateRenderPipelineInternal(
const RenderPipelineDescriptor* descriptor);
MaybeError CreateSamplerInternal(SamplerBase** result, const SamplerDescriptor* descriptor);
MaybeError CreateShaderModuleInternal(ShaderModuleBase** result,
ResultOrError<Ref<SamplerBase>> CreateSamplerInternal(const SamplerDescriptor* descriptor);
ResultOrError<Ref<ShaderModuleBase>> CreateShaderModuleInternal(
const ShaderModuleDescriptor* descriptor);
MaybeError CreateSwapChainInternal(SwapChainBase** result,
ResultOrError<Ref<SwapChainBase>> CreateSwapChainInternal(
Surface* surface,
const SwapChainDescriptor* descriptor);
ResultOrError<Ref<TextureBase>> CreateTextureInternal(const TextureDescriptor* descriptor);
MaybeError CreateTextureViewInternal(TextureViewBase** result,
ResultOrError<Ref<TextureViewBase>> CreateTextureViewInternal(
TextureBase* texture,
const TextureViewDescriptor* descriptor);

View File

@ -213,8 +213,6 @@ namespace dawn_native {
}
// Create the deduced pipeline layout, validating if it is valid.
Ref<PipelineLayoutBase> result = nullptr;
{
ityp::array<BindGroupIndex, BindGroupLayoutBase*, kMaxBindGroups> bgls = {};
for (BindGroupIndex group(0); group < pipelineBGLCount; ++group) {
bgls[group] = bindGroupLayouts[group].Get();
@ -226,21 +224,17 @@ namespace dawn_native {
DAWN_TRY(ValidatePipelineLayoutDescriptor(device, &desc));
PipelineLayoutBase* pipelineLayout;
DAWN_TRY_ASSIGN(pipelineLayout, device->GetOrCreatePipelineLayout(&desc));
result = AcquireRef(pipelineLayout);
ASSERT(!pipelineLayout->IsError());
Ref<PipelineLayoutBase> result;
DAWN_TRY_ASSIGN(result, device->GetOrCreatePipelineLayout(&desc));
ASSERT(!result->IsError());
// Sanity check in debug that the pipeline layout is compatible with the current
// pipeline.
for (const StageAndDescriptor& stage : stages) {
const EntryPointMetadata& metadata = stage.module->GetEntryPoint(stage.entryPoint);
ASSERT(ValidateCompatibilityWithPipelineLayout(device, metadata, pipelineLayout)
ASSERT(ValidateCompatibilityWithPipelineLayout(device, metadata, result.Get())
.IsSuccess());
}
}
return std::move(result);
}

View File

@ -90,6 +90,13 @@ namespace dawn_native {
mBundleEncodingContext(device, this) {
}
// static
Ref<RenderBundleEncoder> RenderBundleEncoder::Create(
DeviceBase* device,
const RenderBundleEncoderDescriptor* descriptor) {
return AcquireRef(new RenderBundleEncoder(device, descriptor));
}
// static
RenderBundleEncoder* RenderBundleEncoder::MakeError(DeviceBase* device) {
return new RenderBundleEncoder(device, ObjectBase::kError);

View File

@ -28,8 +28,8 @@ namespace dawn_native {
class RenderBundleEncoder final : public RenderEncoderBase {
public:
RenderBundleEncoder(DeviceBase* device, const RenderBundleEncoderDescriptor* descriptor);
static Ref<RenderBundleEncoder> Create(DeviceBase* device,
const RenderBundleEncoderDescriptor* descriptor);
static RenderBundleEncoder* MakeError(DeviceBase* device);
RenderBundleBase* APIFinish(const RenderBundleDescriptor* descriptor);
@ -37,6 +37,7 @@ namespace dawn_native {
CommandIterator AcquireCommands();
private:
RenderBundleEncoder(DeviceBase* device, const RenderBundleEncoderDescriptor* descriptor);
RenderBundleEncoder(DeviceBase* device, ErrorTag errorTag);
ResultOrError<RenderBundleBase*> FinishImpl(const RenderBundleDescriptor* descriptor);

View File

@ -25,7 +25,7 @@
namespace dawn_native { namespace d3d12 {
// static
ResultOrError<BindGroup*> BindGroup::Create(Device* device,
ResultOrError<Ref<BindGroup>> BindGroup::Create(Device* device,
const BindGroupDescriptor* descriptor) {
return ToBackend(descriptor->layout)->AllocateBindGroup(device, descriptor);
}

View File

@ -28,7 +28,7 @@ namespace dawn_native { namespace d3d12 {
class BindGroup final : public BindGroupBase, public PlacementAllocated {
public:
static ResultOrError<BindGroup*> Create(Device* device,
static ResultOrError<Ref<BindGroup>> Create(Device* device,
const BindGroupDescriptor* descriptor);
BindGroup(Device* device,

View File

@ -56,6 +56,12 @@ namespace dawn_native { namespace d3d12 {
}
} // anonymous namespace
// static
Ref<BindGroupLayout> BindGroupLayout::Create(Device* device,
const BindGroupLayoutDescriptor* descriptor) {
return AcquireRef(new BindGroupLayout(device, descriptor));
}
BindGroupLayout::BindGroupLayout(Device* device, const BindGroupLayoutDescriptor* descriptor)
: BindGroupLayoutBase(device, descriptor),
mBindingOffsets(GetBindingCount()),
@ -138,7 +144,7 @@ namespace dawn_native { namespace d3d12 {
device->GetSamplerStagingDescriptorAllocator(GetSamplerDescriptorCount());
}
ResultOrError<BindGroup*> BindGroupLayout::AllocateBindGroup(
ResultOrError<Ref<BindGroup>> BindGroupLayout::AllocateBindGroup(
Device* device,
const BindGroupDescriptor* descriptor) {
uint32_t viewSizeIncrement = 0;
@ -158,7 +164,7 @@ namespace dawn_native { namespace d3d12 {
bindGroup->SetSamplerAllocationEntry(std::move(samplerHeapCacheEntry));
}
return bindGroup.Detach();
return bindGroup;
}
void BindGroupLayout::DeallocateBindGroup(BindGroup* bindGroup,

View File

@ -30,9 +30,10 @@ namespace dawn_native { namespace d3d12 {
class BindGroupLayout final : public BindGroupLayoutBase {
public:
BindGroupLayout(Device* device, const BindGroupLayoutDescriptor* descriptor);
static Ref<BindGroupLayout> Create(Device* device,
const BindGroupLayoutDescriptor* descriptor);
ResultOrError<BindGroup*> AllocateBindGroup(Device* device,
ResultOrError<Ref<BindGroup>> AllocateBindGroup(Device* device,
const BindGroupDescriptor* descriptor);
void DeallocateBindGroup(BindGroup* bindGroup, CPUDescriptorHeapAllocation* viewAllocation);
@ -53,6 +54,7 @@ namespace dawn_native { namespace d3d12 {
const D3D12_DESCRIPTOR_RANGE* GetSamplerDescriptorRanges() const;
private:
BindGroupLayout(Device* device, const BindGroupLayoutDescriptor* descriptor);
~BindGroupLayout() override = default;
ityp::stack_vec<BindingIndex, uint32_t, kMaxOptimalBindingsPerGroup> mBindingOffsets;
std::array<uint32_t, DescriptorType::Count> mDescriptorCounts;

View File

@ -94,6 +94,13 @@ namespace dawn_native { namespace d3d12 {
}
} // namespace
// static
ResultOrError<Ref<Buffer>> Buffer::Create(Device* device, const BufferDescriptor* descriptor) {
Ref<Buffer> buffer = AcquireRef(new Buffer(device, descriptor));
DAWN_TRY(buffer->Initialize(descriptor->mappedAtCreation));
return buffer;
}
Buffer::Buffer(Device* device, const BufferDescriptor* descriptor)
: BufferBase(device, descriptor) {
}

View File

@ -27,9 +27,8 @@ namespace dawn_native { namespace d3d12 {
class Buffer final : public BufferBase {
public:
Buffer(Device* device, const BufferDescriptor* descriptor);
MaybeError Initialize(bool mappedAtCreation);
static ResultOrError<Ref<Buffer>> Create(Device* device,
const BufferDescriptor* descriptor);
ID3D12Resource* GetD3D12Resource() const;
D3D12_GPU_VIRTUAL_ADDRESS GetVA() const;
@ -51,7 +50,10 @@ namespace dawn_native { namespace d3d12 {
const CopyTextureToBufferCmd* copy);
private:
Buffer(Device* device, const BufferDescriptor* descriptor);
~Buffer() override;
MaybeError Initialize(bool mappedAtCreation);
MaybeError MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) override;
void UnmapImpl() override;
void DestroyImpl() override;

View File

@ -588,6 +588,12 @@ namespace dawn_native { namespace d3d12 {
} // anonymous namespace
// static
Ref<CommandBuffer> CommandBuffer::Create(CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor) {
return AcquireRef(new CommandBuffer(encoder, descriptor));
}
CommandBuffer::CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor)
: CommandBufferBase(encoder, descriptor) {
}

View File

@ -30,11 +30,14 @@ namespace dawn_native { namespace d3d12 {
class CommandBuffer final : public CommandBufferBase {
public:
CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor);
static Ref<CommandBuffer> Create(CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor);
MaybeError RecordCommands(CommandRecordingContext* commandContext);
private:
CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor);
MaybeError RecordComputePass(CommandRecordingContext* commandContext,
BindGroupStateTracker* bindingTracker);
MaybeError RecordRenderPass(CommandRecordingContext* commandContext,

View File

@ -24,12 +24,12 @@
namespace dawn_native { namespace d3d12 {
ResultOrError<ComputePipeline*> ComputePipeline::Create(
ResultOrError<Ref<ComputePipeline>> ComputePipeline::Create(
Device* device,
const ComputePipelineDescriptor* descriptor) {
Ref<ComputePipeline> pipeline = AcquireRef(new ComputePipeline(device, descriptor));
DAWN_TRY(pipeline->Initialize(descriptor));
return pipeline.Detach();
return pipeline;
}
MaybeError ComputePipeline::Initialize(const ComputePipelineDescriptor* descriptor) {

View File

@ -25,7 +25,8 @@ namespace dawn_native { namespace d3d12 {
class ComputePipeline final : public ComputePipelineBase {
public:
static ResultOrError<ComputePipeline*> Create(Device* device,
static ResultOrError<Ref<ComputePipeline>> Create(
Device* device,
const ComputePipelineDescriptor* descriptor);
ComputePipeline() = delete;

View File

@ -297,51 +297,51 @@ namespace dawn_native { namespace d3d12 {
return mPendingCommands.ExecuteCommandList(this);
}
ResultOrError<BindGroupBase*> Device::CreateBindGroupImpl(
ResultOrError<Ref<BindGroupBase>> Device::CreateBindGroupImpl(
const BindGroupDescriptor* descriptor) {
return BindGroup::Create(this, descriptor);
}
ResultOrError<BindGroupLayoutBase*> Device::CreateBindGroupLayoutImpl(
ResultOrError<Ref<BindGroupLayoutBase>> Device::CreateBindGroupLayoutImpl(
const BindGroupLayoutDescriptor* descriptor) {
return new BindGroupLayout(this, descriptor);
return BindGroupLayout::Create(this, descriptor);
}
ResultOrError<Ref<BufferBase>> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
Ref<Buffer> buffer = AcquireRef(new Buffer(this, descriptor));
DAWN_TRY(buffer->Initialize(descriptor->mappedAtCreation));
return std::move(buffer);
return Buffer::Create(this, descriptor);
}
CommandBufferBase* Device::CreateCommandBuffer(CommandEncoder* encoder,
ResultOrError<Ref<CommandBufferBase>> Device::CreateCommandBuffer(
CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor) {
return new CommandBuffer(encoder, descriptor);
return CommandBuffer::Create(encoder, descriptor);
}
ResultOrError<ComputePipelineBase*> Device::CreateComputePipelineImpl(
ResultOrError<Ref<ComputePipelineBase>> Device::CreateComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) {
return ComputePipeline::Create(this, descriptor);
}
ResultOrError<PipelineLayoutBase*> Device::CreatePipelineLayoutImpl(
ResultOrError<Ref<PipelineLayoutBase>> Device::CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) {
return PipelineLayout::Create(this, descriptor);
}
ResultOrError<QuerySetBase*> Device::CreateQuerySetImpl(const QuerySetDescriptor* descriptor) {
ResultOrError<Ref<QuerySetBase>> Device::CreateQuerySetImpl(
const QuerySetDescriptor* descriptor) {
return QuerySet::Create(this, descriptor);
}
ResultOrError<RenderPipelineBase*> Device::CreateRenderPipelineImpl(
ResultOrError<Ref<RenderPipelineBase>> Device::CreateRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) {
return RenderPipeline::Create(this, descriptor);
}
ResultOrError<SamplerBase*> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) {
return new Sampler(this, descriptor);
ResultOrError<Ref<SamplerBase>> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) {
return Sampler::Create(this, descriptor);
}
ResultOrError<ShaderModuleBase*> Device::CreateShaderModuleImpl(
ResultOrError<Ref<ShaderModuleBase>> Device::CreateShaderModuleImpl(
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult) {
return ShaderModule::Create(this, descriptor, parseResult);
}
ResultOrError<SwapChainBase*> Device::CreateSwapChainImpl(
ResultOrError<Ref<SwapChainBase>> Device::CreateSwapChainImpl(
const SwapChainDescriptor* descriptor) {
return new SwapChain(this, descriptor);
return SwapChain::Create(this, descriptor);
}
ResultOrError<NewSwapChainBase*> Device::CreateSwapChainImpl(
ResultOrError<Ref<NewSwapChainBase>> Device::CreateSwapChainImpl(
Surface* surface,
NewSwapChainBase* previousSwapChain,
const SwapChainDescriptor* descriptor) {
@ -350,10 +350,10 @@ namespace dawn_native { namespace d3d12 {
ResultOrError<Ref<TextureBase>> Device::CreateTextureImpl(const TextureDescriptor* descriptor) {
return Texture::Create(this, descriptor);
}
ResultOrError<TextureViewBase*> Device::CreateTextureViewImpl(
ResultOrError<Ref<TextureViewBase>> Device::CreateTextureViewImpl(
TextureBase* texture,
const TextureViewDescriptor* descriptor) {
return new TextureView(texture, descriptor);
return TextureView::Create(texture, descriptor);
}
ResultOrError<std::unique_ptr<StagingBufferBase>> Device::CreateStagingBuffer(size_t size) {

View File

@ -46,7 +46,8 @@ namespace dawn_native { namespace d3d12 {
MaybeError Initialize();
CommandBufferBase* CreateCommandBuffer(CommandEncoder* encoder,
ResultOrError<Ref<CommandBufferBase>> CreateCommandBuffer(
CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor) override;
MaybeError TickImpl() override;
@ -140,33 +141,34 @@ namespace dawn_native { namespace d3d12 {
private:
using DeviceBase::DeviceBase;
ResultOrError<BindGroupBase*> CreateBindGroupImpl(
ResultOrError<Ref<BindGroupBase>> CreateBindGroupImpl(
const BindGroupDescriptor* descriptor) override;
ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
ResultOrError<Ref<BindGroupLayoutBase>> CreateBindGroupLayoutImpl(
const BindGroupLayoutDescriptor* descriptor) override;
ResultOrError<Ref<BufferBase>> CreateBufferImpl(
const BufferDescriptor* descriptor) override;
ResultOrError<ComputePipelineBase*> CreateComputePipelineImpl(
ResultOrError<Ref<ComputePipelineBase>> CreateComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) override;
ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
ResultOrError<Ref<PipelineLayoutBase>> CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) override;
ResultOrError<QuerySetBase*> CreateQuerySetImpl(
ResultOrError<Ref<QuerySetBase>> CreateQuerySetImpl(
const QuerySetDescriptor* descriptor) override;
ResultOrError<RenderPipelineBase*> CreateRenderPipelineImpl(
ResultOrError<Ref<RenderPipelineBase>> CreateRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) override;
ResultOrError<SamplerBase*> CreateSamplerImpl(const SamplerDescriptor* descriptor) override;
ResultOrError<ShaderModuleBase*> CreateShaderModuleImpl(
ResultOrError<Ref<SamplerBase>> CreateSamplerImpl(
const SamplerDescriptor* descriptor) override;
ResultOrError<Ref<ShaderModuleBase>> CreateShaderModuleImpl(
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult) override;
ResultOrError<SwapChainBase*> CreateSwapChainImpl(
ResultOrError<Ref<SwapChainBase>> CreateSwapChainImpl(
const SwapChainDescriptor* descriptor) override;
ResultOrError<NewSwapChainBase*> CreateSwapChainImpl(
ResultOrError<Ref<NewSwapChainBase>> CreateSwapChainImpl(
Surface* surface,
NewSwapChainBase* previousSwapChain,
const SwapChainDescriptor* descriptor) override;
ResultOrError<Ref<TextureBase>> CreateTextureImpl(
const TextureDescriptor* descriptor) override;
ResultOrError<TextureViewBase*> CreateTextureViewImpl(
ResultOrError<Ref<TextureViewBase>> CreateTextureViewImpl(
TextureBase* texture,
const TextureViewDescriptor* descriptor) override;

View File

@ -54,12 +54,12 @@ namespace dawn_native { namespace d3d12 {
}
} // anonymous namespace
ResultOrError<PipelineLayout*> PipelineLayout::Create(
ResultOrError<Ref<PipelineLayout>> PipelineLayout::Create(
Device* device,
const PipelineLayoutDescriptor* descriptor) {
Ref<PipelineLayout> layout = AcquireRef(new PipelineLayout(device, descriptor));
DAWN_TRY(layout->Initialize());
return layout.Detach();
return layout;
}
MaybeError PipelineLayout::Initialize() {

View File

@ -26,7 +26,8 @@ namespace dawn_native { namespace d3d12 {
class PipelineLayout final : public PipelineLayoutBase {
public:
static ResultOrError<PipelineLayout*> Create(Device* device,
static ResultOrError<Ref<PipelineLayout>> Create(
Device* device,
const PipelineLayoutDescriptor* descriptor);
uint32_t GetCbvUavSrvRootParameterIndex(BindGroupIndex group) const;

View File

@ -33,11 +33,11 @@ namespace dawn_native { namespace d3d12 {
} // anonymous namespace
// static
ResultOrError<QuerySet*> QuerySet::Create(Device* device,
ResultOrError<Ref<QuerySet>> QuerySet::Create(Device* device,
const QuerySetDescriptor* descriptor) {
Ref<QuerySet> querySet = AcquireRef(new QuerySet(device, descriptor));
DAWN_TRY(querySet->Initialize());
return querySet.Detach();
return querySet;
}
MaybeError QuerySet::Initialize() {

View File

@ -24,7 +24,7 @@ namespace dawn_native { namespace d3d12 {
class QuerySet : public QuerySetBase {
public:
static ResultOrError<QuerySet*> Create(Device* device,
static ResultOrError<Ref<QuerySet>> Create(Device* device,
const QuerySetDescriptor* descriptor);
ID3D12QueryHeap* GetQueryHeap() const;

View File

@ -295,12 +295,12 @@ namespace dawn_native { namespace d3d12 {
} // anonymous namespace
ResultOrError<RenderPipeline*> RenderPipeline::Create(
ResultOrError<Ref<RenderPipeline>> RenderPipeline::Create(
Device* device,
const RenderPipelineDescriptor* descriptor) {
Ref<RenderPipeline> pipeline = AcquireRef(new RenderPipeline(device, descriptor));
DAWN_TRY(pipeline->Initialize(descriptor));
return pipeline.Detach();
return pipeline;
}
MaybeError RenderPipeline::Initialize(const RenderPipelineDescriptor* descriptor) {

View File

@ -26,7 +26,8 @@ namespace dawn_native { namespace d3d12 {
class RenderPipeline final : public RenderPipelineBase {
public:
static ResultOrError<RenderPipeline*> Create(Device* device,
static ResultOrError<Ref<RenderPipeline>> Create(
Device* device,
const RenderPipelineDescriptor* descriptor);
RenderPipeline() = delete;

View File

@ -32,6 +32,11 @@ namespace dawn_native { namespace d3d12 {
}
} // namespace
// static
Ref<Sampler> Sampler::Create(Device* device, const SamplerDescriptor* descriptor) {
return AcquireRef(new Sampler(device, descriptor));
}
Sampler::Sampler(Device* device, const SamplerDescriptor* descriptor)
: SamplerBase(device, descriptor) {
D3D12_FILTER_TYPE minFilter;

View File

@ -25,11 +25,12 @@ namespace dawn_native { namespace d3d12 {
class Sampler final : public SamplerBase {
public:
Sampler(Device* device, const SamplerDescriptor* descriptor);
static Ref<Sampler> Create(Device* device, const SamplerDescriptor* descriptor);
const D3D12_SAMPLER_DESC& GetSamplerDescriptor() const;
private:
Sampler(Device* device, const SamplerDescriptor* descriptor);
~Sampler() override = default;
D3D12_SAMPLER_DESC mSamplerDesc = {};
};

View File

@ -172,12 +172,12 @@ namespace dawn_native { namespace d3d12 {
}
// static
ResultOrError<ShaderModule*> ShaderModule::Create(Device* device,
ResultOrError<Ref<ShaderModule>> ShaderModule::Create(Device* device,
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult) {
Ref<ShaderModule> module = AcquireRef(new ShaderModule(device, descriptor));
DAWN_TRY(module->Initialize(parseResult));
return module.Detach();
return module;
}
ShaderModule::ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor)

View File

@ -45,7 +45,7 @@ namespace dawn_native { namespace d3d12 {
class ShaderModule final : public ShaderModuleBase {
public:
static ResultOrError<ShaderModule*> Create(Device* device,
static ResultOrError<Ref<ShaderModule>> Create(Device* device,
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult);

View File

@ -21,6 +21,11 @@
namespace dawn_native { namespace d3d12 {
// static
Ref<SwapChain> SwapChain::Create(Device* device, const SwapChainDescriptor* descriptor) {
return AcquireRef(new SwapChain(device, descriptor));
}
SwapChain::SwapChain(Device* device, const SwapChainDescriptor* descriptor)
: OldSwapChainBase(device, descriptor) {
const auto& im = GetImplementation();

View File

@ -23,9 +23,10 @@ namespace dawn_native { namespace d3d12 {
class SwapChain final : public OldSwapChainBase {
public:
SwapChain(Device* device, const SwapChainDescriptor* descriptor);
static Ref<SwapChain> Create(Device* device, const SwapChainDescriptor* descriptor);
protected:
SwapChain(Device* device, const SwapChainDescriptor* descriptor);
~SwapChain() override;
TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override;
MaybeError OnBeforePresent(TextureViewBase* view) override;

View File

@ -1017,6 +1017,12 @@ namespace dawn_native { namespace d3d12 {
isValidToDecay == other.isValidToDecay;
}
// static
Ref<TextureView> TextureView::Create(TextureBase* texture,
const TextureViewDescriptor* descriptor) {
return AcquireRef(new TextureView(texture, descriptor));
}
TextureView::TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor)
: TextureViewBase(texture, descriptor) {
mSrvDesc.Format = D3D12TextureFormat(descriptor->format);

View File

@ -128,7 +128,8 @@ namespace dawn_native { namespace d3d12 {
class TextureView final : public TextureViewBase {
public:
TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor);
static Ref<TextureView> Create(TextureBase* texture,
const TextureViewDescriptor* descriptor);
DXGI_FORMAT GetD3D12Format() const;
@ -138,6 +139,8 @@ namespace dawn_native { namespace d3d12 {
D3D12_UNORDERED_ACCESS_VIEW_DESC GetUAVDescriptor() const;
private:
TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor);
D3D12_SHADER_RESOURCE_VIEW_DESC mSrvDesc;
};
}} // namespace dawn_native::d3d12

View File

@ -25,13 +25,16 @@ namespace dawn_native { namespace metal {
class BindGroupLayout final : public BindGroupLayoutBase {
public:
BindGroupLayout(DeviceBase* device, const BindGroupLayoutDescriptor* descriptor);
static Ref<BindGroupLayout> Create(DeviceBase* device,
const BindGroupLayoutDescriptor* descriptor);
BindGroup* AllocateBindGroup(Device* device, const BindGroupDescriptor* descriptor);
Ref<BindGroup> AllocateBindGroup(Device* device, const BindGroupDescriptor* descriptor);
void DeallocateBindGroup(BindGroup* bindGroup);
private:
BindGroupLayout(DeviceBase* device, const BindGroupLayoutDescriptor* descriptor);
~BindGroupLayout() override = default;
SlabAllocator<BindGroup> mBindGroupAllocator;
};

View File

@ -18,15 +18,21 @@
namespace dawn_native { namespace metal {
// static
Ref<BindGroupLayout> BindGroupLayout::Create(DeviceBase* device,
const BindGroupLayoutDescriptor* descriptor) {
return AcquireRef(new BindGroupLayout(device, descriptor));
}
BindGroupLayout::BindGroupLayout(DeviceBase* device,
const BindGroupLayoutDescriptor* descriptor)
: BindGroupLayoutBase(device, descriptor),
mBindGroupAllocator(MakeFrontendBindGroupAllocator<BindGroup>(4096)) {
}
BindGroup* BindGroupLayout::AllocateBindGroup(Device* device,
Ref<BindGroup> BindGroupLayout::AllocateBindGroup(Device* device,
const BindGroupDescriptor* descriptor) {
return mBindGroupAllocator.Allocate(device, descriptor);
return AcquireRef(mBindGroupAllocator.Allocate(device, descriptor));
}
void BindGroupLayout::DeallocateBindGroup(BindGroup* bindGroup) {

View File

@ -24,9 +24,9 @@ namespace dawn_native { namespace metal {
class BindGroup final : public BindGroupBase, public PlacementAllocated {
public:
BindGroup(Device* device, const BindGroupDescriptor* descriptor);
static Ref<BindGroup> Create(Device* device, const BindGroupDescriptor* descriptor);
static BindGroup* Create(Device* device, const BindGroupDescriptor* descriptor);
BindGroup(Device* device, const BindGroupDescriptor* descriptor);
private:
~BindGroup() override;

View File

@ -27,7 +27,7 @@ namespace dawn_native { namespace metal {
}
// static
BindGroup* BindGroup::Create(Device* device, const BindGroupDescriptor* descriptor) {
Ref<BindGroup> BindGroup::Create(Device* device, const BindGroupDescriptor* descriptor) {
return ToBackend(descriptor->layout)->AllocateBindGroup(device, descriptor);
}

View File

@ -31,11 +31,14 @@ namespace dawn_native { namespace metal {
class CommandBuffer final : public CommandBufferBase {
public:
CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor);
static Ref<CommandBuffer> Create(CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor);
MaybeError FillCommands(CommandRecordingContext* commandContext);
private:
using CommandBufferBase::CommandBufferBase;
MaybeError EncodeComputePass(CommandRecordingContext* commandContext);
MaybeError EncodeRenderPass(CommandRecordingContext* commandContext,
MTLRenderPassDescriptor* mtlRenderPass,

View File

@ -544,8 +544,10 @@ namespace dawn_native { namespace metal {
} // anonymous namespace
CommandBuffer::CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor)
: CommandBufferBase(encoder, descriptor) {
// static
Ref<CommandBuffer> CommandBuffer::Create(CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor) {
return AcquireRef(new CommandBuffer(encoder, descriptor));
}
MaybeError CommandBuffer::FillCommands(CommandRecordingContext* commandContext) {

View File

@ -27,7 +27,8 @@ namespace dawn_native { namespace metal {
class ComputePipeline final : public ComputePipelineBase {
public:
static ResultOrError<ComputePipeline*> Create(Device* device,
static ResultOrError<Ref<ComputePipeline>> Create(
Device* device,
const ComputePipelineDescriptor* descriptor);
void Encode(id<MTLComputeCommandEncoder> encoder);

View File

@ -20,12 +20,12 @@
namespace dawn_native { namespace metal {
// static
ResultOrError<ComputePipeline*> ComputePipeline::Create(
ResultOrError<Ref<ComputePipeline>> ComputePipeline::Create(
Device* device,
const ComputePipelineDescriptor* descriptor) {
Ref<ComputePipeline> pipeline = AcquireRef(new ComputePipeline(device, descriptor));
DAWN_TRY(pipeline->Initialize(descriptor));
return pipeline.Detach();
return pipeline;
}
MaybeError ComputePipeline::Initialize(const ComputePipelineDescriptor* descriptor) {

View File

@ -41,9 +41,6 @@ namespace dawn_native { namespace metal {
MaybeError Initialize();
CommandBufferBase* CreateCommandBuffer(CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor) override;
MaybeError TickImpl() override;
id<MTLDevice> GetMTLDevice();
@ -78,33 +75,37 @@ namespace dawn_native { namespace metal {
NSPRef<id<MTLDevice>> mtlDevice,
const DeviceDescriptor* descriptor);
ResultOrError<BindGroupBase*> CreateBindGroupImpl(
ResultOrError<Ref<BindGroupBase>> CreateBindGroupImpl(
const BindGroupDescriptor* descriptor) override;
ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
ResultOrError<Ref<BindGroupLayoutBase>> CreateBindGroupLayoutImpl(
const BindGroupLayoutDescriptor* descriptor) override;
ResultOrError<Ref<BufferBase>> CreateBufferImpl(
const BufferDescriptor* descriptor) override;
ResultOrError<ComputePipelineBase*> CreateComputePipelineImpl(
ResultOrError<Ref<CommandBufferBase>> CreateCommandBuffer(
CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor) override;
ResultOrError<Ref<ComputePipelineBase>> CreateComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) override;
ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
ResultOrError<Ref<PipelineLayoutBase>> CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) override;
ResultOrError<QuerySetBase*> CreateQuerySetImpl(
ResultOrError<Ref<QuerySetBase>> CreateQuerySetImpl(
const QuerySetDescriptor* descriptor) override;
ResultOrError<RenderPipelineBase*> CreateRenderPipelineImpl(
ResultOrError<Ref<RenderPipelineBase>> CreateRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) override;
ResultOrError<SamplerBase*> CreateSamplerImpl(const SamplerDescriptor* descriptor) override;
ResultOrError<ShaderModuleBase*> CreateShaderModuleImpl(
ResultOrError<Ref<SamplerBase>> CreateSamplerImpl(
const SamplerDescriptor* descriptor) override;
ResultOrError<Ref<ShaderModuleBase>> CreateShaderModuleImpl(
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult) override;
ResultOrError<SwapChainBase*> CreateSwapChainImpl(
ResultOrError<Ref<SwapChainBase>> CreateSwapChainImpl(
const SwapChainDescriptor* descriptor) override;
ResultOrError<NewSwapChainBase*> CreateSwapChainImpl(
ResultOrError<Ref<NewSwapChainBase>> CreateSwapChainImpl(
Surface* surface,
NewSwapChainBase* previousSwapChain,
const SwapChainDescriptor* descriptor) override;
ResultOrError<Ref<TextureBase>> CreateTextureImpl(
const TextureDescriptor* descriptor) override;
ResultOrError<TextureViewBase*> CreateTextureViewImpl(
ResultOrError<Ref<TextureViewBase>> CreateTextureViewImpl(
TextureBase* texture,
const TextureViewDescriptor* descriptor) override;

View File

@ -117,61 +117,63 @@ namespace dawn_native { namespace metal {
}
}
ResultOrError<BindGroupBase*> Device::CreateBindGroupImpl(
ResultOrError<Ref<BindGroupBase>> Device::CreateBindGroupImpl(
const BindGroupDescriptor* descriptor) {
return BindGroup::Create(this, descriptor);
}
ResultOrError<BindGroupLayoutBase*> Device::CreateBindGroupLayoutImpl(
ResultOrError<Ref<BindGroupLayoutBase>> Device::CreateBindGroupLayoutImpl(
const BindGroupLayoutDescriptor* descriptor) {
return new BindGroupLayout(this, descriptor);
return BindGroupLayout::Create(this, descriptor);
}
ResultOrError<Ref<BufferBase>> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
return Buffer::Create(this, descriptor);
}
CommandBufferBase* Device::CreateCommandBuffer(CommandEncoder* encoder,
ResultOrError<Ref<CommandBufferBase>> Device::CreateCommandBuffer(
CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor) {
return new CommandBuffer(encoder, descriptor);
return CommandBuffer::Create(encoder, descriptor);
}
ResultOrError<ComputePipelineBase*> Device::CreateComputePipelineImpl(
ResultOrError<Ref<ComputePipelineBase>> Device::CreateComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) {
return ComputePipeline::Create(this, descriptor);
}
ResultOrError<PipelineLayoutBase*> Device::CreatePipelineLayoutImpl(
ResultOrError<Ref<PipelineLayoutBase>> Device::CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) {
return new PipelineLayout(this, descriptor);
return PipelineLayout::Create(this, descriptor);
}
ResultOrError<QuerySetBase*> Device::CreateQuerySetImpl(const QuerySetDescriptor* descriptor) {
ResultOrError<Ref<QuerySetBase>> Device::CreateQuerySetImpl(
const QuerySetDescriptor* descriptor) {
return QuerySet::Create(this, descriptor);
}
ResultOrError<RenderPipelineBase*> Device::CreateRenderPipelineImpl(
ResultOrError<Ref<RenderPipelineBase>> Device::CreateRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) {
return RenderPipeline::Create(this, descriptor);
}
ResultOrError<SamplerBase*> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) {
ResultOrError<Ref<SamplerBase>> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) {
return Sampler::Create(this, descriptor);
}
ResultOrError<ShaderModuleBase*> Device::CreateShaderModuleImpl(
ResultOrError<Ref<ShaderModuleBase>> Device::CreateShaderModuleImpl(
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult) {
return ShaderModule::Create(this, descriptor, parseResult);
}
ResultOrError<SwapChainBase*> Device::CreateSwapChainImpl(
ResultOrError<Ref<SwapChainBase>> Device::CreateSwapChainImpl(
const SwapChainDescriptor* descriptor) {
return new OldSwapChain(this, descriptor);
return OldSwapChain::Create(this, descriptor);
}
ResultOrError<NewSwapChainBase*> Device::CreateSwapChainImpl(
ResultOrError<Ref<NewSwapChainBase>> Device::CreateSwapChainImpl(
Surface* surface,
NewSwapChainBase* previousSwapChain,
const SwapChainDescriptor* descriptor) {
return SwapChain::Create(this, surface, previousSwapChain, descriptor);
}
ResultOrError<Ref<TextureBase>> Device::CreateTextureImpl(const TextureDescriptor* descriptor) {
return AcquireRef(new Texture(this, descriptor));
return Texture::Create(this, descriptor);
}
ResultOrError<TextureViewBase*> Device::CreateTextureViewImpl(
ResultOrError<Ref<TextureViewBase>> Device::CreateTextureViewImpl(
TextureBase* texture,
const TextureViewDescriptor* descriptor) {
return new TextureView(texture, descriptor);
return TextureView::Create(texture, descriptor);
}
ExecutionSerial Device::CheckAndUpdateCompletedSerials() {

View File

@ -42,7 +42,8 @@ namespace dawn_native { namespace metal {
class PipelineLayout final : public PipelineLayoutBase {
public:
PipelineLayout(Device* device, const PipelineLayoutDescriptor* descriptor);
static Ref<PipelineLayout> Create(Device* device,
const PipelineLayoutDescriptor* descriptor);
using BindingIndexInfo =
ityp::array<BindGroupIndex,
@ -54,6 +55,7 @@ namespace dawn_native { namespace metal {
uint32_t GetBufferBindingCount(SingleShaderStage stage);
private:
PipelineLayout(Device* device, const PipelineLayoutDescriptor* descriptor);
~PipelineLayout() override = default;
PerStage<BindingIndexInfo> mIndexInfo;
PerStage<uint32_t> mBufferBindingCount;

View File

@ -20,6 +20,12 @@
namespace dawn_native { namespace metal {
// static
Ref<PipelineLayout> PipelineLayout::Create(Device* device,
const PipelineLayoutDescriptor* descriptor) {
return AcquireRef(new PipelineLayout(device, descriptor));
}
PipelineLayout::PipelineLayout(Device* device, const PipelineLayoutDescriptor* descriptor)
: PipelineLayoutBase(device, descriptor) {
// Each stage has its own numbering namespace in CompilerMSL.

View File

@ -27,7 +27,7 @@ namespace dawn_native { namespace metal {
class QuerySet final : public QuerySetBase {
public:
static ResultOrError<QuerySet*> Create(Device* device,
static ResultOrError<Ref<QuerySet>> Create(Device* device,
const QuerySetDescriptor* descriptor);
id<MTLBuffer> GetVisibilityBuffer() const;

View File

@ -62,11 +62,11 @@ namespace dawn_native { namespace metal {
}
// static
ResultOrError<QuerySet*> QuerySet::Create(Device* device,
ResultOrError<Ref<QuerySet>> QuerySet::Create(Device* device,
const QuerySetDescriptor* descriptor) {
Ref<QuerySet> queryset = AcquireRef(new QuerySet(device, descriptor));
DAWN_TRY(queryset->Initialize());
return queryset.Detach();
return queryset;
}
MaybeError QuerySet::Initialize() {

View File

@ -27,7 +27,8 @@ namespace dawn_native { namespace metal {
class RenderPipeline final : public RenderPipelineBase {
public:
static ResultOrError<RenderPipeline*> Create(Device* device,
static ResultOrError<Ref<RenderPipeline>> Create(
Device* device,
const RenderPipelineDescriptor* descriptor);
MTLPrimitiveType GetMTLPrimitiveTopology() const;

View File

@ -310,12 +310,12 @@ namespace dawn_native { namespace metal {
} // anonymous namespace
// static
ResultOrError<RenderPipeline*> RenderPipeline::Create(
ResultOrError<Ref<RenderPipeline>> RenderPipeline::Create(
Device* device,
const RenderPipelineDescriptor* descriptor) {
Ref<RenderPipeline> pipeline = AcquireRef(new RenderPipeline(device, descriptor));
DAWN_TRY(pipeline->Initialize(descriptor));
return pipeline.Detach();
return pipeline;
}
MaybeError RenderPipeline::Initialize(const RenderPipelineDescriptor* descriptor) {

View File

@ -27,7 +27,8 @@ namespace dawn_native { namespace metal {
class Sampler final : public SamplerBase {
public:
static ResultOrError<Sampler*> Create(Device* device, const SamplerDescriptor* descriptor);
static ResultOrError<Ref<Sampler>> Create(Device* device,
const SamplerDescriptor* descriptor);
id<MTLSamplerState> GetMTLSamplerState();

View File

@ -51,13 +51,14 @@ namespace dawn_native { namespace metal {
}
// static
ResultOrError<Sampler*> Sampler::Create(Device* device, const SamplerDescriptor* descriptor) {
ResultOrError<Ref<Sampler>> Sampler::Create(Device* device,
const SamplerDescriptor* descriptor) {
if (descriptor->compare != wgpu::CompareFunction::Undefined &&
device->IsToggleEnabled(Toggle::MetalDisableSamplerCompare)) {
return DAWN_VALIDATION_ERROR("Sampler compare function not supported.");
}
return new Sampler(device, descriptor);
return AcquireRef(new Sampler(device, descriptor));
}
Sampler::Sampler(Device* device, const SamplerDescriptor* descriptor)

View File

@ -34,7 +34,7 @@ namespace dawn_native { namespace metal {
class ShaderModule final : public ShaderModuleBase {
public:
static ResultOrError<ShaderModule*> Create(Device* device,
static ResultOrError<Ref<ShaderModule>> Create(Device* device,
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult);

View File

@ -34,12 +34,12 @@
namespace dawn_native { namespace metal {
// static
ResultOrError<ShaderModule*> ShaderModule::Create(Device* device,
ResultOrError<Ref<ShaderModule>> ShaderModule::Create(Device* device,
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult) {
Ref<ShaderModule> module = AcquireRef(new ShaderModule(device, descriptor));
DAWN_TRY(module->Initialize(parseResult));
return module.Detach();
return module;
}
ShaderModule::ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor)

View File

@ -29,9 +29,10 @@ namespace dawn_native { namespace metal {
class OldSwapChain final : public OldSwapChainBase {
public:
OldSwapChain(Device* device, const SwapChainDescriptor* descriptor);
static Ref<OldSwapChain> Create(Device* deivce, const SwapChainDescriptor* descriptor);
protected:
OldSwapChain(Device* device, const SwapChainDescriptor* descriptor);
~OldSwapChain() override;
TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override;
MaybeError OnBeforePresent(TextureViewBase* view) override;
@ -39,7 +40,7 @@ namespace dawn_native { namespace metal {
class SwapChain final : public NewSwapChainBase {
public:
static ResultOrError<SwapChain*> Create(Device* device,
static ResultOrError<Ref<SwapChain>> Create(Device* device,
Surface* surface,
NewSwapChainBase* previousSwapChain,
const SwapChainDescriptor* descriptor);

View File

@ -26,6 +26,11 @@ namespace dawn_native { namespace metal {
// OldSwapChain
// static
Ref<OldSwapChain> OldSwapChain::Create(Device* device, const SwapChainDescriptor* descriptor) {
return AcquireRef(new OldSwapChain(device, descriptor));
}
OldSwapChain::OldSwapChain(Device* device, const SwapChainDescriptor* descriptor)
: OldSwapChainBase(device, descriptor) {
const auto& im = GetImplementation();
@ -58,14 +63,13 @@ namespace dawn_native { namespace metal {
// SwapChain
// static
ResultOrError<SwapChain*> SwapChain::Create(Device* device,
ResultOrError<Ref<SwapChain>> SwapChain::Create(Device* device,
Surface* surface,
NewSwapChainBase* previousSwapChain,
const SwapChainDescriptor* descriptor) {
std::unique_ptr<SwapChain> swapchain =
std::make_unique<SwapChain>(device, surface, descriptor);
Ref<SwapChain> swapchain = AcquireRef(new SwapChain(device, surface, descriptor));
DAWN_TRY(swapchain->Initialize(previousSwapChain));
return swapchain.release();
return swapchain;
}
SwapChain::~SwapChain() {

View File

@ -35,7 +35,9 @@ namespace dawn_native { namespace metal {
class Texture final : public TextureBase {
public:
Texture(Device* device, const TextureDescriptor* descriptor);
static ResultOrError<Ref<Texture>> Create(Device* device,
const TextureDescriptor* descriptor);
Texture(Device* device,
const TextureDescriptor* descriptor,
NSPRef<id<MTLTexture>> mtlTexture);
@ -49,6 +51,7 @@ namespace dawn_native { namespace metal {
void EnsureSubresourceContentInitialized(const SubresourceRange& range);
private:
Texture(Device* device, const TextureDescriptor* descriptor);
~Texture() override;
void DestroyImpl() override;
@ -60,11 +63,14 @@ namespace dawn_native { namespace metal {
class TextureView final : public TextureViewBase {
public:
TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor);
static ResultOrError<Ref<TextureView>> Create(TextureBase* texture,
const TextureViewDescriptor* descriptor);
id<MTLTexture> GetMTLTexture();
private:
TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor);
NSPRef<id<MTLTexture>> mMtlTextureView;
};

View File

@ -346,6 +346,12 @@ namespace dawn_native { namespace metal {
return mtlDescRef;
}
// static
ResultOrError<Ref<Texture>> Texture::Create(Device* device,
const TextureDescriptor* descriptor) {
return AcquireRef(new Texture(device, descriptor));
}
Texture::Texture(Device* device, const TextureDescriptor* descriptor)
: TextureBase(device, descriptor, TextureState::OwnedInternal) {
NSRef<MTLTextureDescriptor> mtlDesc = CreateMetalTextureDescriptor(device, descriptor);
@ -600,6 +606,12 @@ namespace dawn_native { namespace metal {
}
}
// static
ResultOrError<Ref<TextureView>> TextureView::Create(TextureBase* texture,
const TextureViewDescriptor* descriptor) {
return AcquireRef(new TextureView(texture, descriptor));
}
TextureView::TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor)
: TextureViewBase(texture, descriptor) {
id<MTLTexture> mtlTexture = ToBackend(texture)->GetMTLTexture();

View File

@ -92,52 +92,54 @@ namespace dawn_native { namespace null {
return DeviceBase::Initialize(new Queue(this));
}
ResultOrError<BindGroupBase*> Device::CreateBindGroupImpl(
ResultOrError<Ref<BindGroupBase>> Device::CreateBindGroupImpl(
const BindGroupDescriptor* descriptor) {
return new BindGroup(this, descriptor);
return AcquireRef(new BindGroup(this, descriptor));
}
ResultOrError<BindGroupLayoutBase*> Device::CreateBindGroupLayoutImpl(
ResultOrError<Ref<BindGroupLayoutBase>> Device::CreateBindGroupLayoutImpl(
const BindGroupLayoutDescriptor* descriptor) {
return new BindGroupLayout(this, descriptor);
return AcquireRef(new BindGroupLayout(this, descriptor));
}
ResultOrError<Ref<BufferBase>> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
DAWN_TRY(IncrementMemoryUsage(descriptor->size));
return AcquireRef(new Buffer(this, descriptor));
}
CommandBufferBase* Device::CreateCommandBuffer(CommandEncoder* encoder,
ResultOrError<Ref<CommandBufferBase>> Device::CreateCommandBuffer(
CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor) {
return new CommandBuffer(encoder, descriptor);
return AcquireRef(new CommandBuffer(encoder, descriptor));
}
ResultOrError<ComputePipelineBase*> Device::CreateComputePipelineImpl(
ResultOrError<Ref<ComputePipelineBase>> Device::CreateComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) {
return new ComputePipeline(this, descriptor);
return AcquireRef(new ComputePipeline(this, descriptor));
}
ResultOrError<PipelineLayoutBase*> Device::CreatePipelineLayoutImpl(
ResultOrError<Ref<PipelineLayoutBase>> Device::CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) {
return new PipelineLayout(this, descriptor);
return AcquireRef(new PipelineLayout(this, descriptor));
}
ResultOrError<QuerySetBase*> Device::CreateQuerySetImpl(const QuerySetDescriptor* descriptor) {
return new QuerySet(this, descriptor);
ResultOrError<Ref<QuerySetBase>> Device::CreateQuerySetImpl(
const QuerySetDescriptor* descriptor) {
return AcquireRef(new QuerySet(this, descriptor));
}
ResultOrError<RenderPipelineBase*> Device::CreateRenderPipelineImpl(
ResultOrError<Ref<RenderPipelineBase>> Device::CreateRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) {
return new RenderPipeline(this, descriptor);
return AcquireRef(new RenderPipeline(this, descriptor));
}
ResultOrError<SamplerBase*> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) {
return new Sampler(this, descriptor);
ResultOrError<Ref<SamplerBase>> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) {
return AcquireRef(new Sampler(this, descriptor));
}
ResultOrError<ShaderModuleBase*> Device::CreateShaderModuleImpl(
ResultOrError<Ref<ShaderModuleBase>> Device::CreateShaderModuleImpl(
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult) {
Ref<ShaderModule> module = AcquireRef(new ShaderModule(this, descriptor));
DAWN_TRY(module->Initialize(parseResult));
return module.Detach();
return module;
}
ResultOrError<SwapChainBase*> Device::CreateSwapChainImpl(
ResultOrError<Ref<SwapChainBase>> Device::CreateSwapChainImpl(
const SwapChainDescriptor* descriptor) {
return new OldSwapChain(this, descriptor);
return AcquireRef(new OldSwapChain(this, descriptor));
}
ResultOrError<NewSwapChainBase*> Device::CreateSwapChainImpl(
ResultOrError<Ref<NewSwapChainBase>> Device::CreateSwapChainImpl(
Surface* surface,
NewSwapChainBase* previousSwapChain,
const SwapChainDescriptor* descriptor) {
@ -146,10 +148,10 @@ namespace dawn_native { namespace null {
ResultOrError<Ref<TextureBase>> Device::CreateTextureImpl(const TextureDescriptor* descriptor) {
return AcquireRef(new Texture(this, descriptor, TextureBase::TextureState::OwnedInternal));
}
ResultOrError<TextureViewBase*> Device::CreateTextureViewImpl(
ResultOrError<Ref<TextureViewBase>> Device::CreateTextureViewImpl(
TextureBase* texture,
const TextureViewDescriptor* descriptor) {
return new TextureView(texture, descriptor);
return AcquireRef(new TextureView(texture, descriptor));
}
ResultOrError<std::unique_ptr<StagingBufferBase>> Device::CreateStagingBuffer(size_t size) {
@ -355,14 +357,13 @@ namespace dawn_native { namespace null {
// SwapChain
// static
ResultOrError<SwapChain*> SwapChain::Create(Device* device,
ResultOrError<Ref<SwapChain>> SwapChain::Create(Device* device,
Surface* surface,
NewSwapChainBase* previousSwapChain,
const SwapChainDescriptor* descriptor) {
std::unique_ptr<SwapChain> swapchain =
std::make_unique<SwapChain>(device, surface, descriptor);
Ref<SwapChain> swapchain = AcquireRef(new SwapChain(device, surface, descriptor));
DAWN_TRY(swapchain->Initialize(previousSwapChain));
return swapchain.release();
return swapchain;
}
MaybeError SwapChain::Initialize(NewSwapChainBase* previousSwapChain) {

View File

@ -91,7 +91,8 @@ namespace dawn_native { namespace null {
MaybeError Initialize();
CommandBufferBase* CreateCommandBuffer(CommandEncoder* encoder,
ResultOrError<Ref<CommandBufferBase>> CreateCommandBuffer(
CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor) override;
MaybeError TickImpl() override;
@ -121,33 +122,34 @@ namespace dawn_native { namespace null {
private:
using DeviceBase::DeviceBase;
ResultOrError<BindGroupBase*> CreateBindGroupImpl(
ResultOrError<Ref<BindGroupBase>> CreateBindGroupImpl(
const BindGroupDescriptor* descriptor) override;
ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
ResultOrError<Ref<BindGroupLayoutBase>> CreateBindGroupLayoutImpl(
const BindGroupLayoutDescriptor* descriptor) override;
ResultOrError<Ref<BufferBase>> CreateBufferImpl(
const BufferDescriptor* descriptor) override;
ResultOrError<ComputePipelineBase*> CreateComputePipelineImpl(
ResultOrError<Ref<ComputePipelineBase>> CreateComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) override;
ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
ResultOrError<Ref<PipelineLayoutBase>> CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) override;
ResultOrError<QuerySetBase*> CreateQuerySetImpl(
ResultOrError<Ref<QuerySetBase>> CreateQuerySetImpl(
const QuerySetDescriptor* descriptor) override;
ResultOrError<RenderPipelineBase*> CreateRenderPipelineImpl(
ResultOrError<Ref<RenderPipelineBase>> CreateRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) override;
ResultOrError<SamplerBase*> CreateSamplerImpl(const SamplerDescriptor* descriptor) override;
ResultOrError<ShaderModuleBase*> CreateShaderModuleImpl(
ResultOrError<Ref<SamplerBase>> CreateSamplerImpl(
const SamplerDescriptor* descriptor) override;
ResultOrError<Ref<ShaderModuleBase>> CreateShaderModuleImpl(
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult) override;
ResultOrError<SwapChainBase*> CreateSwapChainImpl(
ResultOrError<Ref<SwapChainBase>> CreateSwapChainImpl(
const SwapChainDescriptor* descriptor) override;
ResultOrError<NewSwapChainBase*> CreateSwapChainImpl(
ResultOrError<Ref<NewSwapChainBase>> CreateSwapChainImpl(
Surface* surface,
NewSwapChainBase* previousSwapChain,
const SwapChainDescriptor* descriptor) override;
ResultOrError<Ref<TextureBase>> CreateTextureImpl(
const TextureDescriptor* descriptor) override;
ResultOrError<TextureViewBase*> CreateTextureViewImpl(
ResultOrError<Ref<TextureViewBase>> CreateTextureViewImpl(
TextureBase* texture,
const TextureViewDescriptor* descriptor) override;
@ -254,7 +256,7 @@ namespace dawn_native { namespace null {
class SwapChain final : public NewSwapChainBase {
public:
static ResultOrError<SwapChain*> Create(Device* device,
static ResultOrError<Ref<SwapChain>> Create(Device* device,
Surface* surface,
NewSwapChainBase* previousSwapChain,
const SwapChainDescriptor* descriptor);

View File

@ -54,7 +54,7 @@ namespace dawn_native { namespace opengl {
}
// static
BindGroup* BindGroup::Create(Device* device, const BindGroupDescriptor* descriptor) {
Ref<BindGroup> BindGroup::Create(Device* device, const BindGroupDescriptor* descriptor) {
return ToBackend(descriptor->layout)->AllocateBindGroup(device, descriptor);
}

View File

@ -26,9 +26,9 @@ namespace dawn_native { namespace opengl {
class BindGroup final : public BindGroupBase, public PlacementAllocated {
public:
BindGroup(Device* device, const BindGroupDescriptor* descriptor);
static Ref<BindGroup> Create(Device* device, const BindGroupDescriptor* descriptor);
static BindGroup* Create(Device* device, const BindGroupDescriptor* descriptor);
BindGroup(Device* device, const BindGroupDescriptor* descriptor);
private:
~BindGroup() override;

View File

@ -24,9 +24,9 @@ namespace dawn_native { namespace opengl {
mBindGroupAllocator(MakeFrontendBindGroupAllocator<BindGroup>(4096)) {
}
BindGroup* BindGroupLayout::AllocateBindGroup(Device* device,
Ref<BindGroup> BindGroupLayout::AllocateBindGroup(Device* device,
const BindGroupDescriptor* descriptor) {
return mBindGroupAllocator.Allocate(device, descriptor);
return AcquireRef(mBindGroupAllocator.Allocate(device, descriptor));
}
void BindGroupLayout::DeallocateBindGroup(BindGroup* bindGroup) {

View File

@ -27,7 +27,7 @@ namespace dawn_native { namespace opengl {
public:
BindGroupLayout(DeviceBase* device, const BindGroupLayoutDescriptor* descriptor);
BindGroup* AllocateBindGroup(Device* device, const BindGroupDescriptor* descriptor);
Ref<BindGroup> AllocateBindGroup(Device* device, const BindGroupDescriptor* descriptor);
void DeallocateBindGroup(BindGroup* bindGroup);
private:

View File

@ -110,50 +110,52 @@ namespace dawn_native { namespace opengl {
return result;
}
ResultOrError<BindGroupBase*> Device::CreateBindGroupImpl(
ResultOrError<Ref<BindGroupBase>> Device::CreateBindGroupImpl(
const BindGroupDescriptor* descriptor) {
DAWN_TRY(ValidateGLBindGroupDescriptor(descriptor));
return BindGroup::Create(this, descriptor);
}
ResultOrError<BindGroupLayoutBase*> Device::CreateBindGroupLayoutImpl(
ResultOrError<Ref<BindGroupLayoutBase>> Device::CreateBindGroupLayoutImpl(
const BindGroupLayoutDescriptor* descriptor) {
return new BindGroupLayout(this, descriptor);
return AcquireRef(new BindGroupLayout(this, descriptor));
}
ResultOrError<Ref<BufferBase>> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
return AcquireRef(new Buffer(this, descriptor));
}
CommandBufferBase* Device::CreateCommandBuffer(CommandEncoder* encoder,
ResultOrError<Ref<CommandBufferBase>> Device::CreateCommandBuffer(
CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor) {
return new CommandBuffer(encoder, descriptor);
return AcquireRef(new CommandBuffer(encoder, descriptor));
}
ResultOrError<ComputePipelineBase*> Device::CreateComputePipelineImpl(
ResultOrError<Ref<ComputePipelineBase>> Device::CreateComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) {
return new ComputePipeline(this, descriptor);
return AcquireRef(new ComputePipeline(this, descriptor));
}
ResultOrError<PipelineLayoutBase*> Device::CreatePipelineLayoutImpl(
ResultOrError<Ref<PipelineLayoutBase>> Device::CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) {
return new PipelineLayout(this, descriptor);
return AcquireRef(new PipelineLayout(this, descriptor));
}
ResultOrError<QuerySetBase*> Device::CreateQuerySetImpl(const QuerySetDescriptor* descriptor) {
return new QuerySet(this, descriptor);
ResultOrError<Ref<QuerySetBase>> Device::CreateQuerySetImpl(
const QuerySetDescriptor* descriptor) {
return AcquireRef(new QuerySet(this, descriptor));
}
ResultOrError<RenderPipelineBase*> Device::CreateRenderPipelineImpl(
ResultOrError<Ref<RenderPipelineBase>> Device::CreateRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) {
return new RenderPipeline(this, descriptor);
return AcquireRef(new RenderPipeline(this, descriptor));
}
ResultOrError<SamplerBase*> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) {
return new Sampler(this, descriptor);
ResultOrError<Ref<SamplerBase>> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) {
return AcquireRef(new Sampler(this, descriptor));
}
ResultOrError<ShaderModuleBase*> Device::CreateShaderModuleImpl(
ResultOrError<Ref<ShaderModuleBase>> Device::CreateShaderModuleImpl(
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult) {
return ShaderModule::Create(this, descriptor, parseResult);
}
ResultOrError<SwapChainBase*> Device::CreateSwapChainImpl(
ResultOrError<Ref<SwapChainBase>> Device::CreateSwapChainImpl(
const SwapChainDescriptor* descriptor) {
return new SwapChain(this, descriptor);
return AcquireRef(new SwapChain(this, descriptor));
}
ResultOrError<NewSwapChainBase*> Device::CreateSwapChainImpl(
ResultOrError<Ref<NewSwapChainBase>> Device::CreateSwapChainImpl(
Surface* surface,
NewSwapChainBase* previousSwapChain,
const SwapChainDescriptor* descriptor) {
@ -162,10 +164,10 @@ namespace dawn_native { namespace opengl {
ResultOrError<Ref<TextureBase>> Device::CreateTextureImpl(const TextureDescriptor* descriptor) {
return AcquireRef(new Texture(this, descriptor));
}
ResultOrError<TextureViewBase*> Device::CreateTextureViewImpl(
ResultOrError<Ref<TextureViewBase>> Device::CreateTextureViewImpl(
TextureBase* texture,
const TextureViewDescriptor* descriptor) {
return new TextureView(texture, descriptor);
return AcquireRef(new TextureView(texture, descriptor));
}
void Device::SubmitFenceSync() {

View File

@ -49,8 +49,8 @@ namespace dawn_native { namespace opengl {
void SubmitFenceSync();
// Dawn API
CommandBufferBase* CreateCommandBuffer(CommandEncoder* encoder,
ResultOrError<Ref<CommandBufferBase>> CreateCommandBuffer(
CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor) override;
MaybeError TickImpl() override;
@ -77,33 +77,34 @@ namespace dawn_native { namespace opengl {
const DeviceDescriptor* descriptor,
const OpenGLFunctions& functions);
ResultOrError<BindGroupBase*> CreateBindGroupImpl(
ResultOrError<Ref<BindGroupBase>> CreateBindGroupImpl(
const BindGroupDescriptor* descriptor) override;
ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
ResultOrError<Ref<BindGroupLayoutBase>> CreateBindGroupLayoutImpl(
const BindGroupLayoutDescriptor* descriptor) override;
ResultOrError<Ref<BufferBase>> CreateBufferImpl(
const BufferDescriptor* descriptor) override;
ResultOrError<ComputePipelineBase*> CreateComputePipelineImpl(
ResultOrError<Ref<ComputePipelineBase>> CreateComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) override;
ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
ResultOrError<Ref<PipelineLayoutBase>> CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) override;
ResultOrError<QuerySetBase*> CreateQuerySetImpl(
ResultOrError<Ref<QuerySetBase>> CreateQuerySetImpl(
const QuerySetDescriptor* descriptor) override;
ResultOrError<RenderPipelineBase*> CreateRenderPipelineImpl(
ResultOrError<Ref<RenderPipelineBase>> CreateRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) override;
ResultOrError<SamplerBase*> CreateSamplerImpl(const SamplerDescriptor* descriptor) override;
ResultOrError<ShaderModuleBase*> CreateShaderModuleImpl(
ResultOrError<Ref<SamplerBase>> CreateSamplerImpl(
const SamplerDescriptor* descriptor) override;
ResultOrError<Ref<ShaderModuleBase>> CreateShaderModuleImpl(
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult) override;
ResultOrError<SwapChainBase*> CreateSwapChainImpl(
ResultOrError<Ref<SwapChainBase>> CreateSwapChainImpl(
const SwapChainDescriptor* descriptor) override;
ResultOrError<NewSwapChainBase*> CreateSwapChainImpl(
ResultOrError<Ref<NewSwapChainBase>> CreateSwapChainImpl(
Surface* surface,
NewSwapChainBase* previousSwapChain,
const SwapChainDescriptor* descriptor) override;
ResultOrError<Ref<TextureBase>> CreateTextureImpl(
const TextureDescriptor* descriptor) override;
ResultOrError<TextureViewBase*> CreateTextureViewImpl(
ResultOrError<Ref<TextureViewBase>> CreateTextureViewImpl(
TextureBase* texture,
const TextureViewDescriptor* descriptor) override;

View File

@ -99,8 +99,8 @@ namespace dawn_native { namespace opengl {
ASSERT(desc.minFilter == wgpu::FilterMode::Nearest);
ASSERT(desc.magFilter == wgpu::FilterMode::Nearest);
ASSERT(desc.mipmapFilter == wgpu::FilterMode::Nearest);
mDummySampler = AcquireRef(
ToBackend(layout->GetDevice()->GetOrCreateSampler(&desc).AcquireSuccess()));
mDummySampler =
ToBackend(layout->GetDevice()->GetOrCreateSampler(&desc).AcquireSuccess());
}
// Link all the shaders together.

View File

@ -65,12 +65,12 @@ namespace dawn_native { namespace opengl {
}
// static
ResultOrError<ShaderModule*> ShaderModule::Create(Device* device,
ResultOrError<Ref<ShaderModule>> ShaderModule::Create(Device* device,
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult) {
Ref<ShaderModule> module = AcquireRef(new ShaderModule(device, descriptor));
DAWN_TRY(module->Initialize(parseResult));
return module.Detach();
return module;
}
ShaderModule::ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor)

View File

@ -46,7 +46,7 @@ namespace dawn_native { namespace opengl {
class ShaderModule final : public ShaderModuleBase {
public:
static ResultOrError<ShaderModule*> Create(Device* device,
static ResultOrError<Ref<ShaderModule>> Create(Device* device,
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult);

View File

@ -74,12 +74,12 @@ namespace dawn_native { namespace vulkan {
}
// static
ResultOrError<BindGroupLayout*> BindGroupLayout::Create(
ResultOrError<Ref<BindGroupLayout>> BindGroupLayout::Create(
Device* device,
const BindGroupLayoutDescriptor* descriptor) {
Ref<BindGroupLayout> bgl = AcquireRef(new BindGroupLayout(device, descriptor));
DAWN_TRY(bgl->Initialize());
return bgl.Detach();
return bgl;
}
MaybeError BindGroupLayout::Initialize() {
@ -158,13 +158,14 @@ namespace dawn_native { namespace vulkan {
return mHandle;
}
ResultOrError<BindGroup*> BindGroupLayout::AllocateBindGroup(
ResultOrError<Ref<BindGroup>> BindGroupLayout::AllocateBindGroup(
Device* device,
const BindGroupDescriptor* descriptor) {
DescriptorSetAllocation descriptorSetAllocation;
DAWN_TRY_ASSIGN(descriptorSetAllocation, mDescriptorSetAllocator->Allocate());
return mBindGroupAllocator.Allocate(device, descriptor, descriptorSetAllocation);
return AcquireRef(
mBindGroupAllocator.Allocate(device, descriptor, descriptorSetAllocation));
}
void BindGroupLayout::DeallocateBindGroup(BindGroup* bindGroup,

View File

@ -45,14 +45,15 @@ namespace dawn_native { namespace vulkan {
// expensive syscall.
class BindGroupLayout final : public BindGroupLayoutBase {
public:
static ResultOrError<BindGroupLayout*> Create(Device* device,
static ResultOrError<Ref<BindGroupLayout>> Create(
Device* device,
const BindGroupLayoutDescriptor* descriptor);
BindGroupLayout(DeviceBase* device, const BindGroupLayoutDescriptor* descriptor);
VkDescriptorSetLayout GetHandle() const;
ResultOrError<BindGroup*> AllocateBindGroup(Device* device,
ResultOrError<Ref<BindGroup>> AllocateBindGroup(Device* device,
const BindGroupDescriptor* descriptor);
void DeallocateBindGroup(BindGroup* bindGroup,
DescriptorSetAllocation* descriptorSetAllocation);

View File

@ -27,7 +27,7 @@
namespace dawn_native { namespace vulkan {
// static
ResultOrError<BindGroup*> BindGroup::Create(Device* device,
ResultOrError<Ref<BindGroup>> BindGroup::Create(Device* device,
const BindGroupDescriptor* descriptor) {
return ToBackend(descriptor->layout)->AllocateBindGroup(device, descriptor);
}

View File

@ -28,7 +28,7 @@ namespace dawn_native { namespace vulkan {
class BindGroup final : public BindGroupBase, public PlacementAllocated {
public:
static ResultOrError<BindGroup*> Create(Device* device,
static ResultOrError<Ref<BindGroup>> Create(Device* device,
const BindGroupDescriptor* descriptor);
BindGroup(Device* device,

View File

@ -433,9 +433,9 @@ namespace dawn_native { namespace vulkan {
} // anonymous namespace
// static
CommandBuffer* CommandBuffer::Create(CommandEncoder* encoder,
Ref<CommandBuffer> CommandBuffer::Create(CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor) {
return new CommandBuffer(encoder, descriptor);
return AcquireRef(new CommandBuffer(encoder, descriptor));
}
CommandBuffer::CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor)

View File

@ -32,7 +32,7 @@ namespace dawn_native { namespace vulkan {
class CommandBuffer final : public CommandBufferBase {
public:
static CommandBuffer* Create(CommandEncoder* encoder,
static Ref<CommandBuffer> Create(CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor);
MaybeError RecordCommands(CommandRecordingContext* recordingContext);

View File

@ -24,12 +24,12 @@
namespace dawn_native { namespace vulkan {
// static
ResultOrError<ComputePipeline*> ComputePipeline::Create(
ResultOrError<Ref<ComputePipeline>> ComputePipeline::Create(
Device* device,
const ComputePipelineDescriptor* descriptor) {
Ref<ComputePipeline> pipeline = AcquireRef(new ComputePipeline(device, descriptor));
DAWN_TRY(pipeline->Initialize(descriptor));
return pipeline.Detach();
return pipeline;
}
MaybeError ComputePipeline::Initialize(const ComputePipelineDescriptor* descriptor) {

View File

@ -26,7 +26,8 @@ namespace dawn_native { namespace vulkan {
class ComputePipeline final : public ComputePipelineBase {
public:
static ResultOrError<ComputePipeline*> Create(Device* device,
static ResultOrError<Ref<ComputePipeline>> Create(
Device* device,
const ComputePipelineDescriptor* descriptor);
VkPipeline GetHandle() const;

View File

@ -102,49 +102,51 @@ namespace dawn_native { namespace vulkan {
ShutDownBase();
}
ResultOrError<BindGroupBase*> Device::CreateBindGroupImpl(
ResultOrError<Ref<BindGroupBase>> Device::CreateBindGroupImpl(
const BindGroupDescriptor* descriptor) {
return BindGroup::Create(this, descriptor);
}
ResultOrError<BindGroupLayoutBase*> Device::CreateBindGroupLayoutImpl(
ResultOrError<Ref<BindGroupLayoutBase>> Device::CreateBindGroupLayoutImpl(
const BindGroupLayoutDescriptor* descriptor) {
return BindGroupLayout::Create(this, descriptor);
}
ResultOrError<Ref<BufferBase>> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
return Buffer::Create(this, descriptor);
}
CommandBufferBase* Device::CreateCommandBuffer(CommandEncoder* encoder,
ResultOrError<Ref<CommandBufferBase>> Device::CreateCommandBuffer(
CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor) {
return CommandBuffer::Create(encoder, descriptor);
}
ResultOrError<ComputePipelineBase*> Device::CreateComputePipelineImpl(
ResultOrError<Ref<ComputePipelineBase>> Device::CreateComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) {
return ComputePipeline::Create(this, descriptor);
}
ResultOrError<PipelineLayoutBase*> Device::CreatePipelineLayoutImpl(
ResultOrError<Ref<PipelineLayoutBase>> Device::CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) {
return PipelineLayout::Create(this, descriptor);
}
ResultOrError<QuerySetBase*> Device::CreateQuerySetImpl(const QuerySetDescriptor* descriptor) {
ResultOrError<Ref<QuerySetBase>> Device::CreateQuerySetImpl(
const QuerySetDescriptor* descriptor) {
return QuerySet::Create(this, descriptor);
}
ResultOrError<RenderPipelineBase*> Device::CreateRenderPipelineImpl(
ResultOrError<Ref<RenderPipelineBase>> Device::CreateRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) {
return RenderPipeline::Create(this, descriptor);
}
ResultOrError<SamplerBase*> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) {
ResultOrError<Ref<SamplerBase>> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) {
return Sampler::Create(this, descriptor);
}
ResultOrError<ShaderModuleBase*> Device::CreateShaderModuleImpl(
ResultOrError<Ref<ShaderModuleBase>> Device::CreateShaderModuleImpl(
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult) {
return ShaderModule::Create(this, descriptor, parseResult);
}
ResultOrError<SwapChainBase*> Device::CreateSwapChainImpl(
ResultOrError<Ref<SwapChainBase>> Device::CreateSwapChainImpl(
const SwapChainDescriptor* descriptor) {
return OldSwapChain::Create(this, descriptor);
}
ResultOrError<NewSwapChainBase*> Device::CreateSwapChainImpl(
ResultOrError<Ref<NewSwapChainBase>> Device::CreateSwapChainImpl(
Surface* surface,
NewSwapChainBase* previousSwapChain,
const SwapChainDescriptor* descriptor) {
@ -153,7 +155,7 @@ namespace dawn_native { namespace vulkan {
ResultOrError<Ref<TextureBase>> Device::CreateTextureImpl(const TextureDescriptor* descriptor) {
return Texture::Create(this, descriptor);
}
ResultOrError<TextureViewBase*> Device::CreateTextureViewImpl(
ResultOrError<Ref<TextureViewBase>> Device::CreateTextureViewImpl(
TextureBase* texture,
const TextureViewDescriptor* descriptor) {
return TextureView::Create(texture, descriptor);

View File

@ -77,8 +77,8 @@ namespace dawn_native { namespace vulkan {
ExternalImageExportInfoVk* info,
std::vector<ExternalSemaphoreHandle>* semaphoreHandle);
// Dawn API
CommandBufferBase* CreateCommandBuffer(CommandEncoder* encoder,
ResultOrError<Ref<CommandBufferBase>> CreateCommandBuffer(
CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor) override;
MaybeError TickImpl() override;
@ -114,33 +114,34 @@ namespace dawn_native { namespace vulkan {
private:
Device(Adapter* adapter, const DeviceDescriptor* descriptor);
ResultOrError<BindGroupBase*> CreateBindGroupImpl(
ResultOrError<Ref<BindGroupBase>> CreateBindGroupImpl(
const BindGroupDescriptor* descriptor) override;
ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
ResultOrError<Ref<BindGroupLayoutBase>> CreateBindGroupLayoutImpl(
const BindGroupLayoutDescriptor* descriptor) override;
ResultOrError<Ref<BufferBase>> CreateBufferImpl(
const BufferDescriptor* descriptor) override;
ResultOrError<ComputePipelineBase*> CreateComputePipelineImpl(
ResultOrError<Ref<ComputePipelineBase>> CreateComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) override;
ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
ResultOrError<Ref<PipelineLayoutBase>> CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) override;
ResultOrError<QuerySetBase*> CreateQuerySetImpl(
ResultOrError<Ref<QuerySetBase>> CreateQuerySetImpl(
const QuerySetDescriptor* descriptor) override;
ResultOrError<RenderPipelineBase*> CreateRenderPipelineImpl(
ResultOrError<Ref<RenderPipelineBase>> CreateRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) override;
ResultOrError<SamplerBase*> CreateSamplerImpl(const SamplerDescriptor* descriptor) override;
ResultOrError<ShaderModuleBase*> CreateShaderModuleImpl(
ResultOrError<Ref<SamplerBase>> CreateSamplerImpl(
const SamplerDescriptor* descriptor) override;
ResultOrError<Ref<ShaderModuleBase>> CreateShaderModuleImpl(
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult) override;
ResultOrError<SwapChainBase*> CreateSwapChainImpl(
ResultOrError<Ref<SwapChainBase>> CreateSwapChainImpl(
const SwapChainDescriptor* descriptor) override;
ResultOrError<NewSwapChainBase*> CreateSwapChainImpl(
ResultOrError<Ref<NewSwapChainBase>> CreateSwapChainImpl(
Surface* surface,
NewSwapChainBase* previousSwapChain,
const SwapChainDescriptor* descriptor) override;
ResultOrError<Ref<TextureBase>> CreateTextureImpl(
const TextureDescriptor* descriptor) override;
ResultOrError<TextureViewBase*> CreateTextureViewImpl(
ResultOrError<Ref<TextureViewBase>> CreateTextureViewImpl(
TextureBase* texture,
const TextureViewDescriptor* descriptor) override;

View File

@ -23,12 +23,12 @@
namespace dawn_native { namespace vulkan {
// static
ResultOrError<PipelineLayout*> PipelineLayout::Create(
ResultOrError<Ref<PipelineLayout>> PipelineLayout::Create(
Device* device,
const PipelineLayoutDescriptor* descriptor) {
Ref<PipelineLayout> layout = AcquireRef(new PipelineLayout(device, descriptor));
DAWN_TRY(layout->Initialize());
return layout.Detach();
return layout;
}
MaybeError PipelineLayout::Initialize() {

View File

@ -26,7 +26,8 @@ namespace dawn_native { namespace vulkan {
class PipelineLayout final : public PipelineLayoutBase {
public:
static ResultOrError<PipelineLayout*> Create(Device* device,
static ResultOrError<Ref<PipelineLayout>> Create(
Device* device,
const PipelineLayoutDescriptor* descriptor);
VkPipelineLayout GetHandle() const;

View File

@ -64,11 +64,11 @@ namespace dawn_native { namespace vulkan {
} // anonymous namespace
// static
ResultOrError<QuerySet*> QuerySet::Create(Device* device,
ResultOrError<Ref<QuerySet>> QuerySet::Create(Device* device,
const QuerySetDescriptor* descriptor) {
Ref<QuerySet> queryset = AcquireRef(new QuerySet(device, descriptor));
DAWN_TRY(queryset->Initialize());
return queryset.Detach();
return queryset;
}
MaybeError QuerySet::Initialize() {

View File

@ -25,7 +25,7 @@ namespace dawn_native { namespace vulkan {
class QuerySet final : public QuerySetBase {
public:
static ResultOrError<QuerySet*> Create(Device* device,
static ResultOrError<Ref<QuerySet>> Create(Device* device,
const QuerySetDescriptor* descriptor);
VkQueryPool GetHandle() const;

View File

@ -319,12 +319,12 @@ namespace dawn_native { namespace vulkan {
} // anonymous namespace
// static
ResultOrError<RenderPipeline*> RenderPipeline::Create(
ResultOrError<Ref<RenderPipeline>> RenderPipeline::Create(
Device* device,
const RenderPipelineDescriptor* descriptor) {
Ref<RenderPipeline> pipeline = AcquireRef(new RenderPipeline(device, descriptor));
DAWN_TRY(pipeline->Initialize(descriptor));
return pipeline.Detach();
return pipeline;
}
MaybeError RenderPipeline::Initialize(const RenderPipelineDescriptor* descriptor) {

View File

@ -26,7 +26,8 @@ namespace dawn_native { namespace vulkan {
class RenderPipeline final : public RenderPipelineBase {
public:
static ResultOrError<RenderPipeline*> Create(Device* device,
static ResultOrError<Ref<RenderPipeline>> Create(
Device* device,
const RenderPipelineDescriptor* descriptor);
VkPipeline GetHandle() const;

View File

@ -53,10 +53,11 @@ namespace dawn_native { namespace vulkan {
} // anonymous namespace
// static
ResultOrError<Sampler*> Sampler::Create(Device* device, const SamplerDescriptor* descriptor) {
ResultOrError<Ref<Sampler>> Sampler::Create(Device* device,
const SamplerDescriptor* descriptor) {
Ref<Sampler> sampler = AcquireRef(new Sampler(device, descriptor));
DAWN_TRY(sampler->Initialize(descriptor));
return sampler.Detach();
return sampler;
}
MaybeError Sampler::Initialize(const SamplerDescriptor* descriptor) {

View File

@ -26,7 +26,8 @@ namespace dawn_native { namespace vulkan {
class Sampler final : public SamplerBase {
public:
static ResultOrError<Sampler*> Create(Device* device, const SamplerDescriptor* descriptor);
static ResultOrError<Ref<Sampler>> Create(Device* device,
const SamplerDescriptor* descriptor);
VkSampler GetHandle() const;

View File

@ -30,15 +30,12 @@
namespace dawn_native { namespace vulkan {
// static
ResultOrError<ShaderModule*> ShaderModule::Create(Device* device,
ResultOrError<Ref<ShaderModule>> ShaderModule::Create(Device* device,
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult) {
Ref<ShaderModule> module = AcquireRef(new ShaderModule(device, descriptor));
if (module == nullptr) {
return DAWN_VALIDATION_ERROR("Unable to create ShaderModule");
}
DAWN_TRY(module->Initialize(parseResult));
return module.Detach();
return module;
}
ShaderModule::ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor)

View File

@ -26,7 +26,7 @@ namespace dawn_native { namespace vulkan {
class ShaderModule final : public ShaderModuleBase {
public:
static ResultOrError<ShaderModule*> Create(Device* device,
static ResultOrError<Ref<ShaderModule>> Create(Device* device,
const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult);

View File

@ -35,8 +35,8 @@ namespace dawn_native { namespace vulkan {
// OldSwapChain
// static
OldSwapChain* OldSwapChain::Create(Device* device, const SwapChainDescriptor* descriptor) {
return new OldSwapChain(device, descriptor);
Ref<OldSwapChain> OldSwapChain::Create(Device* device, const SwapChainDescriptor* descriptor) {
return AcquireRef(new OldSwapChain(device, descriptor));
}
OldSwapChain::OldSwapChain(Device* device, const SwapChainDescriptor* descriptor)
@ -211,14 +211,13 @@ namespace dawn_native { namespace vulkan {
} // anonymous namespace
// static
ResultOrError<SwapChain*> SwapChain::Create(Device* device,
ResultOrError<Ref<SwapChain>> SwapChain::Create(Device* device,
Surface* surface,
NewSwapChainBase* previousSwapChain,
const SwapChainDescriptor* descriptor) {
std::unique_ptr<SwapChain> swapchain =
std::make_unique<SwapChain>(device, surface, descriptor);
Ref<SwapChain> swapchain = AcquireRef(new SwapChain(device, surface, descriptor));
DAWN_TRY(swapchain->Initialize(previousSwapChain));
return swapchain.release();
return swapchain;
}
SwapChain::~SwapChain() {

View File

@ -29,7 +29,7 @@ namespace dawn_native { namespace vulkan {
class OldSwapChain : public OldSwapChainBase {
public:
static OldSwapChain* Create(Device* device, const SwapChainDescriptor* descriptor);
static Ref<OldSwapChain> Create(Device* device, const SwapChainDescriptor* descriptor);
protected:
OldSwapChain(Device* device, const SwapChainDescriptor* descriptor);
@ -44,7 +44,7 @@ namespace dawn_native { namespace vulkan {
class SwapChain : public NewSwapChainBase {
public:
static ResultOrError<SwapChain*> Create(Device* device,
static ResultOrError<Ref<SwapChain>> Create(Device* device,
Surface* surface,
NewSwapChainBase* previousSwapChain,
const SwapChainDescriptor* descriptor);

View File

@ -1162,11 +1162,11 @@ namespace dawn_native { namespace vulkan {
}
// static
ResultOrError<TextureView*> TextureView::Create(TextureBase* texture,
ResultOrError<Ref<TextureView>> TextureView::Create(TextureBase* texture,
const TextureViewDescriptor* descriptor) {
Ref<TextureView> view = AcquireRef(new TextureView(texture, descriptor));
DAWN_TRY(view->Initialize(descriptor));
return view.Detach();
return view;
}
MaybeError TextureView::Initialize(const TextureViewDescriptor* descriptor) {

View File

@ -167,7 +167,7 @@ namespace dawn_native { namespace vulkan {
class TextureView final : public TextureViewBase {
public:
static ResultOrError<TextureView*> Create(TextureBase* texture,
static ResultOrError<Ref<TextureView>> Create(TextureBase* texture,
const TextureViewDescriptor* descriptor);
VkImageView GetHandle() const;