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) { 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(); DeviceBase* device = GetDevice();
// Even if mEncodingContext.Finish() validation fails, calling it will mutate the internal // 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 // state of the encoding context. The internal state is set to finished, and subsequent
// calls to encode commands will generate errors. // calls to encode commands will generate errors.
if (device->ConsumedError(mEncodingContext.Finish()) || DAWN_TRY(mEncodingContext.Finish());
device->ConsumedError(device->ValidateIsAlive()) || DAWN_TRY(device->ValidateIsAlive());
(device->IsValidationEnabled() &&
device->ConsumedError(ValidateFinish(mEncodingContext.GetIterator(), if (device->IsValidationEnabled()) {
mEncodingContext.GetPassUsages())))) { DAWN_TRY(
return CommandBufferBase::MakeError(device); ValidateFinish(mEncodingContext.GetIterator(), mEncodingContext.GetPassUsages()));
} }
ASSERT(!IsError());
return device->CreateCommandBuffer(this, descriptor); return device->CreateCommandBuffer(this, descriptor);
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -94,6 +94,13 @@ namespace dawn_native { namespace d3d12 {
} }
} // namespace } // 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) Buffer::Buffer(Device* device, const BufferDescriptor* descriptor)
: BufferBase(device, descriptor) { : BufferBase(device, descriptor) {
} }

View File

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

View File

@ -588,6 +588,12 @@ namespace dawn_native { namespace d3d12 {
} // anonymous namespace } // 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) CommandBuffer::CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor)
: CommandBufferBase(encoder, descriptor) { : CommandBufferBase(encoder, descriptor) {
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -21,6 +21,11 @@
namespace dawn_native { namespace d3d12 { 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) SwapChain::SwapChain(Device* device, const SwapChainDescriptor* descriptor)
: OldSwapChainBase(device, descriptor) { : OldSwapChainBase(device, descriptor) {
const auto& im = GetImplementation(); const auto& im = GetImplementation();

View File

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

View File

@ -1017,6 +1017,12 @@ namespace dawn_native { namespace d3d12 {
isValidToDecay == other.isValidToDecay; 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) TextureView::TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor)
: TextureViewBase(texture, descriptor) { : TextureViewBase(texture, descriptor) {
mSrvDesc.Format = D3D12TextureFormat(descriptor->format); mSrvDesc.Format = D3D12TextureFormat(descriptor->format);

View File

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

View File

@ -25,13 +25,16 @@ namespace dawn_native { namespace metal {
class BindGroupLayout final : public BindGroupLayoutBase { class BindGroupLayout final : public BindGroupLayoutBase {
public: 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); void DeallocateBindGroup(BindGroup* bindGroup);
private: private:
BindGroupLayout(DeviceBase* device, const BindGroupLayoutDescriptor* descriptor);
~BindGroupLayout() override = default; ~BindGroupLayout() override = default;
SlabAllocator<BindGroup> mBindGroupAllocator; SlabAllocator<BindGroup> mBindGroupAllocator;
}; };

View File

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

View File

@ -24,9 +24,9 @@ namespace dawn_native { namespace metal {
class BindGroup final : public BindGroupBase, public PlacementAllocated { class BindGroup final : public BindGroupBase, public PlacementAllocated {
public: 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: private:
~BindGroup() override; ~BindGroup() override;

View File

@ -27,7 +27,7 @@ namespace dawn_native { namespace metal {
} }
// static // 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); return ToBackend(descriptor->layout)->AllocateBindGroup(device, descriptor);
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -41,9 +41,6 @@ namespace dawn_native { namespace metal {
MaybeError Initialize(); MaybeError Initialize();
CommandBufferBase* CreateCommandBuffer(CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor) override;
MaybeError TickImpl() override; MaybeError TickImpl() override;
id<MTLDevice> GetMTLDevice(); id<MTLDevice> GetMTLDevice();
@ -78,33 +75,37 @@ namespace dawn_native { namespace metal {
NSPRef<id<MTLDevice>> mtlDevice, NSPRef<id<MTLDevice>> mtlDevice,
const DeviceDescriptor* descriptor); const DeviceDescriptor* descriptor);
ResultOrError<BindGroupBase*> CreateBindGroupImpl( ResultOrError<Ref<BindGroupBase>> CreateBindGroupImpl(
const BindGroupDescriptor* descriptor) override; const BindGroupDescriptor* descriptor) override;
ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl( ResultOrError<Ref<BindGroupLayoutBase>> CreateBindGroupLayoutImpl(
const BindGroupLayoutDescriptor* descriptor) override; const BindGroupLayoutDescriptor* descriptor) override;
ResultOrError<Ref<BufferBase>> CreateBufferImpl( ResultOrError<Ref<BufferBase>> CreateBufferImpl(
const BufferDescriptor* descriptor) override; 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; const ComputePipelineDescriptor* descriptor) override;
ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl( ResultOrError<Ref<PipelineLayoutBase>> CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) override; const PipelineLayoutDescriptor* descriptor) override;
ResultOrError<QuerySetBase*> CreateQuerySetImpl( ResultOrError<Ref<QuerySetBase>> CreateQuerySetImpl(
const QuerySetDescriptor* descriptor) override; const QuerySetDescriptor* descriptor) override;
ResultOrError<RenderPipelineBase*> CreateRenderPipelineImpl( ResultOrError<Ref<RenderPipelineBase>> CreateRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) override; const RenderPipelineDescriptor* descriptor) override;
ResultOrError<SamplerBase*> CreateSamplerImpl(const SamplerDescriptor* descriptor) override; ResultOrError<Ref<SamplerBase>> CreateSamplerImpl(
ResultOrError<ShaderModuleBase*> CreateShaderModuleImpl( const SamplerDescriptor* descriptor) override;
ResultOrError<Ref<ShaderModuleBase>> CreateShaderModuleImpl(
const ShaderModuleDescriptor* descriptor, const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult) override; ShaderModuleParseResult* parseResult) override;
ResultOrError<SwapChainBase*> CreateSwapChainImpl( ResultOrError<Ref<SwapChainBase>> CreateSwapChainImpl(
const SwapChainDescriptor* descriptor) override; const SwapChainDescriptor* descriptor) override;
ResultOrError<NewSwapChainBase*> CreateSwapChainImpl( ResultOrError<Ref<NewSwapChainBase>> CreateSwapChainImpl(
Surface* surface, Surface* surface,
NewSwapChainBase* previousSwapChain, NewSwapChainBase* previousSwapChain,
const SwapChainDescriptor* descriptor) override; const SwapChainDescriptor* descriptor) override;
ResultOrError<Ref<TextureBase>> CreateTextureImpl( ResultOrError<Ref<TextureBase>> CreateTextureImpl(
const TextureDescriptor* descriptor) override; const TextureDescriptor* descriptor) override;
ResultOrError<TextureViewBase*> CreateTextureViewImpl( ResultOrError<Ref<TextureViewBase>> CreateTextureViewImpl(
TextureBase* texture, TextureBase* texture,
const TextureViewDescriptor* descriptor) override; 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) { const BindGroupDescriptor* descriptor) {
return BindGroup::Create(this, descriptor); return BindGroup::Create(this, descriptor);
} }
ResultOrError<BindGroupLayoutBase*> Device::CreateBindGroupLayoutImpl( ResultOrError<Ref<BindGroupLayoutBase>> Device::CreateBindGroupLayoutImpl(
const BindGroupLayoutDescriptor* descriptor) { const BindGroupLayoutDescriptor* descriptor) {
return new BindGroupLayout(this, descriptor); return BindGroupLayout::Create(this, descriptor);
} }
ResultOrError<Ref<BufferBase>> Device::CreateBufferImpl(const BufferDescriptor* descriptor) { ResultOrError<Ref<BufferBase>> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
return Buffer::Create(this, descriptor); return Buffer::Create(this, descriptor);
} }
CommandBufferBase* Device::CreateCommandBuffer(CommandEncoder* encoder, ResultOrError<Ref<CommandBufferBase>> Device::CreateCommandBuffer(
const CommandBufferDescriptor* descriptor) { CommandEncoder* encoder,
return new CommandBuffer(encoder, descriptor); const CommandBufferDescriptor* descriptor) {
return CommandBuffer::Create(encoder, descriptor);
} }
ResultOrError<ComputePipelineBase*> Device::CreateComputePipelineImpl( ResultOrError<Ref<ComputePipelineBase>> Device::CreateComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) { const ComputePipelineDescriptor* descriptor) {
return ComputePipeline::Create(this, descriptor); return ComputePipeline::Create(this, descriptor);
} }
ResultOrError<PipelineLayoutBase*> Device::CreatePipelineLayoutImpl( ResultOrError<Ref<PipelineLayoutBase>> Device::CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) { 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); return QuerySet::Create(this, descriptor);
} }
ResultOrError<RenderPipelineBase*> Device::CreateRenderPipelineImpl( ResultOrError<Ref<RenderPipelineBase>> Device::CreateRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) { const RenderPipelineDescriptor* descriptor) {
return RenderPipeline::Create(this, 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); return Sampler::Create(this, descriptor);
} }
ResultOrError<ShaderModuleBase*> Device::CreateShaderModuleImpl( ResultOrError<Ref<ShaderModuleBase>> Device::CreateShaderModuleImpl(
const ShaderModuleDescriptor* descriptor, const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult) { ShaderModuleParseResult* parseResult) {
return ShaderModule::Create(this, descriptor, parseResult); return ShaderModule::Create(this, descriptor, parseResult);
} }
ResultOrError<SwapChainBase*> Device::CreateSwapChainImpl( ResultOrError<Ref<SwapChainBase>> Device::CreateSwapChainImpl(
const SwapChainDescriptor* descriptor) { const SwapChainDescriptor* descriptor) {
return new OldSwapChain(this, descriptor); return OldSwapChain::Create(this, descriptor);
} }
ResultOrError<NewSwapChainBase*> Device::CreateSwapChainImpl( ResultOrError<Ref<NewSwapChainBase>> Device::CreateSwapChainImpl(
Surface* surface, Surface* surface,
NewSwapChainBase* previousSwapChain, NewSwapChainBase* previousSwapChain,
const SwapChainDescriptor* descriptor) { const SwapChainDescriptor* descriptor) {
return SwapChain::Create(this, surface, previousSwapChain, descriptor); return SwapChain::Create(this, surface, previousSwapChain, descriptor);
} }
ResultOrError<Ref<TextureBase>> Device::CreateTextureImpl(const TextureDescriptor* 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, TextureBase* texture,
const TextureViewDescriptor* descriptor) { const TextureViewDescriptor* descriptor) {
return new TextureView(texture, descriptor); return TextureView::Create(texture, descriptor);
} }
ExecutionSerial Device::CheckAndUpdateCompletedSerials() { ExecutionSerial Device::CheckAndUpdateCompletedSerials() {

View File

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

View File

@ -20,6 +20,12 @@
namespace dawn_native { namespace metal { 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) PipelineLayout::PipelineLayout(Device* device, const PipelineLayoutDescriptor* descriptor)
: PipelineLayoutBase(device, descriptor) { : PipelineLayoutBase(device, descriptor) {
// Each stage has its own numbering namespace in CompilerMSL. // Each stage has its own numbering namespace in CompilerMSL.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -346,6 +346,12 @@ namespace dawn_native { namespace metal {
return mtlDescRef; 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) Texture::Texture(Device* device, const TextureDescriptor* descriptor)
: TextureBase(device, descriptor, TextureState::OwnedInternal) { : TextureBase(device, descriptor, TextureState::OwnedInternal) {
NSRef<MTLTextureDescriptor> mtlDesc = CreateMetalTextureDescriptor(device, descriptor); 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) TextureView::TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor)
: TextureViewBase(texture, descriptor) { : TextureViewBase(texture, descriptor) {
id<MTLTexture> mtlTexture = ToBackend(texture)->GetMTLTexture(); id<MTLTexture> mtlTexture = ToBackend(texture)->GetMTLTexture();

View File

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

View File

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

View File

@ -54,7 +54,7 @@ namespace dawn_native { namespace opengl {
} }
// static // 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); 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 { class BindGroup final : public BindGroupBase, public PlacementAllocated {
public: 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: private:
~BindGroup() override; ~BindGroup() override;

View File

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

View File

@ -27,7 +27,7 @@ namespace dawn_native { namespace opengl {
public: public:
BindGroupLayout(DeviceBase* device, const BindGroupLayoutDescriptor* descriptor); 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); void DeallocateBindGroup(BindGroup* bindGroup);
private: private:

View File

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

View File

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

View File

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

View File

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

View File

@ -46,9 +46,9 @@ namespace dawn_native { namespace opengl {
class ShaderModule final : public ShaderModuleBase { class ShaderModule final : public ShaderModuleBase {
public: public:
static ResultOrError<ShaderModule*> Create(Device* device, static ResultOrError<Ref<ShaderModule>> Create(Device* device,
const ShaderModuleDescriptor* descriptor, const ShaderModuleDescriptor* descriptor,
ShaderModuleParseResult* parseResult); ShaderModuleParseResult* parseResult);
std::string TranslateToGLSL(const char* entryPointName, std::string TranslateToGLSL(const char* entryPointName,
SingleShaderStage stage, SingleShaderStage stage,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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