2018-07-18 09:40:26 +00:00
|
|
|
// Copyright 2017 The Dawn Authors
|
2017-05-31 00:03:44 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2018-07-24 14:42:33 +00:00
|
|
|
#ifndef DAWNNATIVE_DEVICEBASE_H_
|
|
|
|
#define DAWNNATIVE_DEVICEBASE_H_
|
2017-05-31 00:03:44 +00:00
|
|
|
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/Error.h"
|
|
|
|
#include "dawn_native/Forward.h"
|
|
|
|
#include "dawn_native/RefCounted.h"
|
2017-05-31 00:03:44 +00:00
|
|
|
|
2018-07-25 15:03:23 +00:00
|
|
|
#include "dawn_native/dawn_platform.h"
|
2017-05-31 00:03:44 +00:00
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
namespace dawn_native {
|
2017-05-31 00:03:44 +00:00
|
|
|
|
|
|
|
using ErrorCallback = void (*)(const char* errorMessage, void* userData);
|
|
|
|
|
|
|
|
class DeviceBase {
|
2017-11-24 18:59:42 +00:00
|
|
|
public:
|
|
|
|
DeviceBase();
|
|
|
|
virtual ~DeviceBase();
|
|
|
|
|
|
|
|
void HandleError(const char* message);
|
|
|
|
|
2018-07-16 15:40:08 +00:00
|
|
|
bool ConsumedError(MaybeError maybeError) {
|
2018-07-18 11:37:54 +00:00
|
|
|
if (DAWN_UNLIKELY(maybeError.IsError())) {
|
2018-07-16 15:40:08 +00:00
|
|
|
ConsumeError(maybeError.AcquireError());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
// Used by autogenerated code, returns itself
|
|
|
|
DeviceBase* GetDevice();
|
|
|
|
|
|
|
|
virtual BindGroupBase* CreateBindGroup(BindGroupBuilder* builder) = 0;
|
|
|
|
virtual BlendStateBase* CreateBlendState(BlendStateBuilder* builder) = 0;
|
|
|
|
virtual BufferBase* CreateBuffer(BufferBuilder* builder) = 0;
|
|
|
|
virtual BufferViewBase* CreateBufferView(BufferViewBuilder* builder) = 0;
|
|
|
|
virtual CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) = 0;
|
|
|
|
virtual ComputePipelineBase* CreateComputePipeline(ComputePipelineBuilder* builder) = 0;
|
|
|
|
virtual DepthStencilStateBase* CreateDepthStencilState(
|
|
|
|
DepthStencilStateBuilder* builder) = 0;
|
|
|
|
virtual InputStateBase* CreateInputState(InputStateBuilder* builder) = 0;
|
2018-05-11 17:04:44 +00:00
|
|
|
virtual RenderPassDescriptorBase* CreateRenderPassDescriptor(
|
|
|
|
RenderPassDescriptorBuilder* builder) = 0;
|
2017-11-24 18:59:42 +00:00
|
|
|
virtual RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) = 0;
|
|
|
|
virtual SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) = 0;
|
|
|
|
virtual TextureBase* CreateTexture(TextureBuilder* builder) = 0;
|
|
|
|
virtual TextureViewBase* CreateTextureView(TextureViewBuilder* builder) = 0;
|
|
|
|
|
|
|
|
virtual void TickImpl() = 0;
|
|
|
|
|
2018-07-18 13:28:38 +00:00
|
|
|
// Many Dawn objects are completely immutable once created which means that if two
|
2017-11-24 18:59:42 +00:00
|
|
|
// builders are given the same arguments, they can return the same object. Reusing
|
|
|
|
// objects will help make comparisons between objects by a single pointer comparison.
|
|
|
|
//
|
|
|
|
// Technically no object is immutable as they have a reference count, and an
|
|
|
|
// application with reference-counting issues could "see" that objects are reused.
|
|
|
|
// This is solved by automatic-reference counting, and also the fact that when using
|
|
|
|
// the client-server wire every creation will get a different proxy object, with a
|
|
|
|
// different reference count.
|
|
|
|
//
|
|
|
|
// When trying to create an object, we give both the builder and an example of what
|
|
|
|
// the built object will be, the "blueprint". The blueprint is just a FooBase object
|
|
|
|
// instead of a backend Foo object. If the blueprint doesn't match an object in the
|
|
|
|
// cache, then the builder is used to make a new object.
|
2018-07-10 19:23:50 +00:00
|
|
|
ResultOrError<BindGroupLayoutBase*> GetOrCreateBindGroupLayout(
|
2018-07-25 15:03:23 +00:00
|
|
|
const BindGroupLayoutDescriptor* descriptor);
|
2017-11-24 18:59:42 +00:00
|
|
|
void UncacheBindGroupLayout(BindGroupLayoutBase* obj);
|
|
|
|
|
2018-07-18 13:20:28 +00:00
|
|
|
// Dawn API
|
2017-11-24 18:59:42 +00:00
|
|
|
BindGroupBuilder* CreateBindGroupBuilder();
|
2018-07-25 15:03:23 +00:00
|
|
|
BindGroupLayoutBase* CreateBindGroupLayout(const BindGroupLayoutDescriptor* descriptor);
|
2017-11-24 18:59:42 +00:00
|
|
|
BlendStateBuilder* CreateBlendStateBuilder();
|
|
|
|
BufferBuilder* CreateBufferBuilder();
|
|
|
|
CommandBufferBuilder* CreateCommandBufferBuilder();
|
|
|
|
ComputePipelineBuilder* CreateComputePipelineBuilder();
|
|
|
|
DepthStencilStateBuilder* CreateDepthStencilStateBuilder();
|
|
|
|
InputStateBuilder* CreateInputStateBuilder();
|
2018-07-25 15:03:23 +00:00
|
|
|
PipelineLayoutBase* CreatePipelineLayout(const PipelineLayoutDescriptor* descriptor);
|
2018-06-15 00:26:27 +00:00
|
|
|
QueueBase* CreateQueue();
|
2018-05-11 17:04:44 +00:00
|
|
|
RenderPassDescriptorBuilder* CreateRenderPassDescriptorBuilder();
|
2017-11-24 18:59:42 +00:00
|
|
|
RenderPipelineBuilder* CreateRenderPipelineBuilder();
|
2018-07-25 15:03:23 +00:00
|
|
|
SamplerBase* CreateSampler(const SamplerDescriptor* descriptor);
|
2018-08-20 15:01:20 +00:00
|
|
|
ShaderModuleBase* CreateShaderModule(const ShaderModuleDescriptor* descriptor);
|
2017-11-24 18:59:42 +00:00
|
|
|
SwapChainBuilder* CreateSwapChainBuilder();
|
|
|
|
TextureBuilder* CreateTextureBuilder();
|
|
|
|
|
|
|
|
void Tick();
|
2018-07-18 09:38:11 +00:00
|
|
|
void SetErrorCallback(dawn::DeviceErrorCallback callback, dawn::CallbackUserdata userdata);
|
2017-11-24 18:59:42 +00:00
|
|
|
void Reference();
|
|
|
|
void Release();
|
|
|
|
|
|
|
|
private:
|
2018-07-10 19:23:50 +00:00
|
|
|
virtual ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
|
2018-07-25 15:03:23 +00:00
|
|
|
const BindGroupLayoutDescriptor* descriptor) = 0;
|
2018-06-27 23:21:39 +00:00
|
|
|
virtual ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
|
2018-07-25 15:03:23 +00:00
|
|
|
const PipelineLayoutDescriptor* descriptor) = 0;
|
2018-06-15 00:26:27 +00:00
|
|
|
virtual ResultOrError<QueueBase*> CreateQueueImpl() = 0;
|
2018-05-28 19:40:41 +00:00
|
|
|
virtual ResultOrError<SamplerBase*> CreateSamplerImpl(
|
2018-07-25 15:03:23 +00:00
|
|
|
const SamplerDescriptor* descriptor) = 0;
|
2018-08-20 15:01:20 +00:00
|
|
|
virtual ResultOrError<ShaderModuleBase*> CreateShaderModuleImpl(
|
|
|
|
const ShaderModuleDescriptor* descriptor) = 0;
|
2018-05-17 21:09:07 +00:00
|
|
|
|
2018-07-16 15:40:08 +00:00
|
|
|
MaybeError CreateBindGroupLayoutInternal(BindGroupLayoutBase** result,
|
2018-07-25 15:03:23 +00:00
|
|
|
const BindGroupLayoutDescriptor* descriptor);
|
2018-07-16 15:40:08 +00:00
|
|
|
MaybeError CreatePipelineLayoutInternal(PipelineLayoutBase** result,
|
2018-07-25 15:03:23 +00:00
|
|
|
const PipelineLayoutDescriptor* descriptor);
|
2018-07-16 15:40:08 +00:00
|
|
|
MaybeError CreateQueueInternal(QueueBase** result);
|
2018-07-25 15:03:23 +00:00
|
|
|
MaybeError CreateSamplerInternal(SamplerBase** result, const SamplerDescriptor* descriptor);
|
2018-08-20 15:01:20 +00:00
|
|
|
MaybeError CreateShaderModuleInternal(ShaderModuleBase** result,
|
|
|
|
const ShaderModuleDescriptor* descriptor);
|
2018-07-16 15:40:08 +00:00
|
|
|
|
|
|
|
void ConsumeError(ErrorData* error);
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
// The object caches aren't exposed in the header as they would require a lot of
|
|
|
|
// additional includes.
|
|
|
|
struct Caches;
|
|
|
|
Caches* mCaches = nullptr;
|
|
|
|
|
2018-07-18 09:38:11 +00:00
|
|
|
dawn::DeviceErrorCallback mErrorCallback = nullptr;
|
|
|
|
dawn::CallbackUserdata mErrorUserdata = 0;
|
2017-11-24 18:59:42 +00:00
|
|
|
uint32_t mRefCount = 1;
|
2017-05-31 00:03:44 +00:00
|
|
|
};
|
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
} // namespace dawn_native
|
2017-05-31 00:03:44 +00:00
|
|
|
|
2018-07-24 14:42:33 +00:00
|
|
|
#endif // DAWNNATIVE_DEVICEBASE_H_
|