Make Device::CreateSamplerImpl to return a ResultOrError

This will allow backends to do error-handling internally for things like
allocation failures though non of them take advantage of it yet.
This commit is contained in:
Corentin Wallez 2018-05-28 15:40:41 -04:00 committed by Corentin Wallez
parent 50e0986e0e
commit 79d9e16d3c
12 changed files with 30 additions and 12 deletions

View File

@ -139,7 +139,13 @@ namespace backend {
return nullptr;
}
return CreateSamplerImpl(descriptor);
ResultOrError<SamplerBase*> maybeSampler = CreateSamplerImpl(descriptor);
if (maybeSampler.IsError()) {
// TODO(cwallez@chromium.org): Implement the WebGPU error handling mechanism.
delete validation.AcquireError();
return nullptr;
}
return maybeSampler.AcquireSuccess();
}
ShaderModuleBuilder* DeviceBase::CreateShaderModuleBuilder() {
return new ShaderModuleBuilder(this);

View File

@ -15,6 +15,7 @@
#ifndef BACKEND_DEVICEBASE_H_
#define BACKEND_DEVICEBASE_H_
#include "backend/Error.h"
#include "backend/Forward.h"
#include "backend/RefCounted.h"
@ -98,7 +99,8 @@ namespace backend {
void Release();
private:
virtual SamplerBase* CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) = 0;
virtual ResultOrError<SamplerBase*> CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) = 0;
// The object caches aren't exposed in the header as they would require a lot of
// additional includes.

View File

@ -298,7 +298,8 @@ namespace backend { namespace d3d12 {
RenderPipelineBase* Device::CreateRenderPipeline(RenderPipelineBuilder* builder) {
return new RenderPipeline(builder);
}
SamplerBase* Device::CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) {
ResultOrError<SamplerBase*> Device::CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) {
return new Sampler(this, descriptor);
}
ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) {

View File

@ -128,7 +128,8 @@ namespace backend { namespace d3d12 {
void ExecuteCommandLists(std::initializer_list<ID3D12CommandList*> commandLists);
private:
SamplerBase* CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) override;
ResultOrError<SamplerBase*> CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) override;
uint64_t mSerial = 0;
ComPtr<ID3D12Fence> mFence;

View File

@ -118,7 +118,8 @@ namespace backend { namespace metal {
ResourceUploader* GetResourceUploader() const;
private:
SamplerBase* CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) override;
ResultOrError<SamplerBase*> CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) override;
void OnCompletedHandler();

View File

@ -117,7 +117,8 @@ namespace backend { namespace metal {
RenderPipelineBase* Device::CreateRenderPipeline(RenderPipelineBuilder* builder) {
return new RenderPipeline(builder);
}
SamplerBase* Device::CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) {
ResultOrError<SamplerBase*> Device::CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) {
return new Sampler(this, descriptor);
}
ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) {

View File

@ -76,7 +76,8 @@ namespace backend { namespace null {
RenderPipelineBase* Device::CreateRenderPipeline(RenderPipelineBuilder* builder) {
return new RenderPipeline(builder);
}
SamplerBase* Device::CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) {
ResultOrError<SamplerBase*> Device::CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) {
return new Sampler(this, descriptor);
}
ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) {

View File

@ -120,7 +120,8 @@ namespace backend { namespace null {
std::vector<std::unique_ptr<PendingOperation>> AcquirePendingOperations();
private:
SamplerBase* CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) override;
ResultOrError<SamplerBase*> CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) override;
std::vector<std::unique_ptr<PendingOperation>> mPendingOperations;
};

View File

@ -86,7 +86,8 @@ namespace backend { namespace opengl {
RenderPipelineBase* Device::CreateRenderPipeline(RenderPipelineBuilder* builder) {
return new RenderPipeline(builder);
}
SamplerBase* Device::CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) {
ResultOrError<SamplerBase*> Device::CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) {
return new Sampler(this, descriptor);
}
ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) {

View File

@ -105,7 +105,8 @@ namespace backend { namespace opengl {
void TickImpl() override;
private:
SamplerBase* CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) override;
ResultOrError<SamplerBase*> CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) override;
};
class BindGroup : public BindGroupBase {

View File

@ -253,7 +253,8 @@ namespace backend { namespace vulkan {
RenderPipelineBase* Device::CreateRenderPipeline(RenderPipelineBuilder* builder) {
return new RenderPipeline(builder);
}
SamplerBase* Device::CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) {
ResultOrError<SamplerBase*> Device::CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) {
return new Sampler(this, descriptor);
}
ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) {

View File

@ -133,7 +133,8 @@ namespace backend { namespace vulkan {
void TickImpl() override;
private:
SamplerBase* CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) override;
ResultOrError<SamplerBase*> CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) override;
bool CreateInstance(VulkanGlobalKnobs* usedKnobs,
const std::vector<const char*>& requiredExtensions);