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.
|
|
|
|
|
2019-01-04 10:30:40 +00:00
|
|
|
#ifndef DAWNNATIVE_DEVICE_H_
|
|
|
|
#define DAWNNATIVE_DEVICE_H_
|
2017-05-31 00:03:44 +00:00
|
|
|
|
2018-12-01 03:20:19 +00:00
|
|
|
#include "common/Serial.h"
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/Error.h"
|
2019-08-02 00:06:38 +00:00
|
|
|
#include "dawn_native/Extensions.h"
|
2019-07-18 09:25:04 +00:00
|
|
|
#include "dawn_native/Format.h"
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/Forward.h"
|
2018-10-15 12:54:30 +00:00
|
|
|
#include "dawn_native/ObjectBase.h"
|
2019-04-26 07:52:57 +00:00
|
|
|
#include "dawn_native/Toggles.h"
|
2017-05-31 00:03:44 +00:00
|
|
|
|
2018-09-19 00:32:52 +00:00
|
|
|
#include "dawn_native/DawnNative.h"
|
2018-07-25 15:03:23 +00:00
|
|
|
#include "dawn_native/dawn_platform.h"
|
2017-05-31 00:03:44 +00:00
|
|
|
|
2018-09-06 13:26:48 +00:00
|
|
|
#include <memory>
|
|
|
|
|
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);
|
|
|
|
|
2019-01-10 10:50:54 +00:00
|
|
|
class AdapterBase;
|
2019-07-26 19:08:18 +00:00
|
|
|
class AttachmentState;
|
2019-08-13 22:12:54 +00:00
|
|
|
class AttachmentStateBlueprint;
|
2019-09-10 23:19:11 +00:00
|
|
|
class ErrorScope;
|
2019-09-17 18:24:07 +00:00
|
|
|
class ErrorScopeTracker;
|
2018-12-03 16:57:34 +00:00
|
|
|
class FenceSignalTracker;
|
2019-01-29 00:10:07 +00:00
|
|
|
class DynamicUploader;
|
|
|
|
class StagingBufferBase;
|
2018-12-03 16:57:34 +00:00
|
|
|
|
2017-05-31 00:03:44 +00:00
|
|
|
class DeviceBase {
|
2017-11-24 18:59:42 +00:00
|
|
|
public:
|
2019-04-26 07:52:57 +00:00
|
|
|
DeviceBase(AdapterBase* adapter, const DeviceDescriptor* descriptor);
|
2017-11-24 18:59:42 +00:00
|
|
|
virtual ~DeviceBase();
|
|
|
|
|
2019-08-27 21:41:56 +00:00
|
|
|
void HandleError(dawn::ErrorType type, const char* message);
|
2017-11-24 18:59:42 +00:00
|
|
|
|
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())) {
|
2019-09-18 21:03:41 +00:00
|
|
|
ConsumeError(maybeError.AcquireError());
|
2018-07-16 15:40:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-13 13:09:18 +00:00
|
|
|
MaybeError ValidateObject(const ObjectBase* object) const;
|
|
|
|
|
2019-01-30 16:07:48 +00:00
|
|
|
AdapterBase* GetAdapter() const;
|
2019-08-13 19:00:34 +00:00
|
|
|
dawn_platform::Platform* GetPlatform() const;
|
2019-01-30 16:07:48 +00:00
|
|
|
|
2019-09-17 18:24:07 +00:00
|
|
|
ErrorScopeTracker* GetErrorScopeTracker() const;
|
2018-12-03 16:57:34 +00:00
|
|
|
FenceSignalTracker* GetFenceSignalTracker() const;
|
|
|
|
|
2019-07-18 09:25:04 +00:00
|
|
|
// Returns the Format corresponding to the dawn::TextureFormat or an error if the format
|
|
|
|
// isn't a valid dawn::TextureFormat or isn't supported by this device.
|
|
|
|
// The pointer returned has the same lifetime as the device.
|
|
|
|
ResultOrError<const Format*> GetInternalFormat(dawn::TextureFormat format) const;
|
|
|
|
|
|
|
|
// Returns the Format corresponding to the dawn::TextureFormat and assumes the format is
|
|
|
|
// valid and supported.
|
|
|
|
// The reference returned has the same lifetime as the device.
|
|
|
|
const Format& GetValidInternalFormat(dawn::TextureFormat format) const;
|
|
|
|
|
2019-07-10 20:43:13 +00:00
|
|
|
virtual CommandBufferBase* CreateCommandBuffer(
|
|
|
|
CommandEncoderBase* encoder,
|
|
|
|
const CommandBufferDescriptor* descriptor) = 0;
|
2017-11-24 18:59:42 +00:00
|
|
|
|
2018-12-01 03:20:19 +00:00
|
|
|
virtual Serial GetCompletedCommandSerial() const = 0;
|
|
|
|
virtual Serial GetLastSubmittedCommandSerial() const = 0;
|
2019-01-29 00:10:07 +00:00
|
|
|
virtual Serial GetPendingCommandSerial() const = 0;
|
2017-11-24 18:59:42 +00:00
|
|
|
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
|
2019-04-01 21:48:38 +00:00
|
|
|
// creations are given the same arguments, they can return the same object. Reusing
|
2017-11-24 18:59:42 +00:00
|
|
|
// 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.
|
|
|
|
//
|
2019-04-01 21:48:38 +00:00
|
|
|
// When trying to create an object, we give both the descriptor and an example of what
|
|
|
|
// the created object will be, the "blueprint". The blueprint is just a FooBase object
|
2017-11-24 18:59:42 +00:00
|
|
|
// instead of a backend Foo object. If the blueprint doesn't match an object in the
|
2019-04-01 21:48:38 +00:00
|
|
|
// cache, then the descriptor 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);
|
|
|
|
|
2019-05-01 13:48:47 +00:00
|
|
|
ResultOrError<ComputePipelineBase*> GetOrCreateComputePipeline(
|
|
|
|
const ComputePipelineDescriptor* descriptor);
|
|
|
|
void UncacheComputePipeline(ComputePipelineBase* obj);
|
|
|
|
|
2019-05-01 12:57:27 +00:00
|
|
|
ResultOrError<PipelineLayoutBase*> GetOrCreatePipelineLayout(
|
|
|
|
const PipelineLayoutDescriptor* descriptor);
|
|
|
|
void UncachePipelineLayout(PipelineLayoutBase* obj);
|
|
|
|
|
2019-05-02 15:30:56 +00:00
|
|
|
ResultOrError<RenderPipelineBase*> GetOrCreateRenderPipeline(
|
|
|
|
const RenderPipelineDescriptor* descriptor);
|
|
|
|
void UncacheRenderPipeline(RenderPipelineBase* obj);
|
|
|
|
|
2019-05-20 18:16:34 +00:00
|
|
|
ResultOrError<SamplerBase*> GetOrCreateSampler(const SamplerDescriptor* descriptor);
|
|
|
|
void UncacheSampler(SamplerBase* obj);
|
|
|
|
|
2019-05-01 13:27:07 +00:00
|
|
|
ResultOrError<ShaderModuleBase*> GetOrCreateShaderModule(
|
|
|
|
const ShaderModuleDescriptor* descriptor);
|
|
|
|
void UncacheShaderModule(ShaderModuleBase* obj);
|
|
|
|
|
2019-08-13 22:12:54 +00:00
|
|
|
Ref<AttachmentState> GetOrCreateAttachmentState(AttachmentStateBlueprint* blueprint);
|
|
|
|
Ref<AttachmentState> GetOrCreateAttachmentState(
|
|
|
|
const RenderBundleEncoderDescriptor* descriptor);
|
2019-08-07 21:47:24 +00:00
|
|
|
Ref<AttachmentState> GetOrCreateAttachmentState(const RenderPipelineDescriptor* descriptor);
|
|
|
|
Ref<AttachmentState> GetOrCreateAttachmentState(const RenderPassDescriptor* descriptor);
|
2019-07-26 19:08:18 +00:00
|
|
|
void UncacheAttachmentState(AttachmentState* obj);
|
|
|
|
|
2018-07-18 13:20:28 +00:00
|
|
|
// Dawn API
|
2018-12-05 07:18:30 +00:00
|
|
|
BindGroupBase* CreateBindGroup(const BindGroupDescriptor* descriptor);
|
2018-07-25 15:03:23 +00:00
|
|
|
BindGroupLayoutBase* CreateBindGroupLayout(const BindGroupLayoutDescriptor* descriptor);
|
2018-08-22 13:37:29 +00:00
|
|
|
BufferBase* CreateBuffer(const BufferDescriptor* descriptor);
|
2019-05-15 18:55:22 +00:00
|
|
|
DawnCreateBufferMappedResult CreateBufferMapped(const BufferDescriptor* descriptor);
|
2019-06-14 17:35:56 +00:00
|
|
|
void CreateBufferMappedAsync(const BufferDescriptor* descriptor,
|
|
|
|
dawn::BufferCreateMappedCallback callback,
|
|
|
|
void* userdata);
|
2019-07-10 20:43:13 +00:00
|
|
|
CommandEncoderBase* CreateCommandEncoder(const CommandEncoderDescriptor* descriptor);
|
2018-08-27 21:12:56 +00:00
|
|
|
ComputePipelineBase* CreateComputePipeline(const ComputePipelineDescriptor* descriptor);
|
2018-07-25 15:03:23 +00:00
|
|
|
PipelineLayoutBase* CreatePipelineLayout(const PipelineLayoutDescriptor* descriptor);
|
2018-06-15 00:26:27 +00:00
|
|
|
QueueBase* CreateQueue();
|
2019-08-13 22:12:54 +00:00
|
|
|
RenderBundleEncoderBase* CreateRenderBundleEncoder(
|
|
|
|
const RenderBundleEncoderDescriptor* descriptor);
|
2018-12-10 19:47:22 +00:00
|
|
|
RenderPipelineBase* CreateRenderPipeline(const RenderPipelineDescriptor* descriptor);
|
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);
|
2019-02-15 11:15:58 +00:00
|
|
|
SwapChainBase* CreateSwapChain(const SwapChainDescriptor* descriptor);
|
2018-08-27 00:44:48 +00:00
|
|
|
TextureBase* CreateTexture(const TextureDescriptor* descriptor);
|
2018-10-12 08:32:58 +00:00
|
|
|
TextureViewBase* CreateTextureView(TextureBase* texture,
|
|
|
|
const TextureViewDescriptor* descriptor);
|
2017-11-24 18:59:42 +00:00
|
|
|
|
|
|
|
void Tick();
|
2018-12-01 03:20:19 +00:00
|
|
|
|
2019-08-27 21:43:56 +00:00
|
|
|
void SetUncapturedErrorCallback(dawn::ErrorCallback callback, void* userdata);
|
2019-09-04 22:54:03 +00:00
|
|
|
void PushErrorScope(dawn::ErrorFilter filter);
|
|
|
|
bool PopErrorScope(dawn::ErrorCallback callback, void* userdata);
|
2019-09-17 18:24:07 +00:00
|
|
|
ErrorScope* GetCurrentErrorScope();
|
2019-09-04 22:54:03 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
void Reference();
|
|
|
|
void Release();
|
|
|
|
|
2019-01-29 00:10:07 +00:00
|
|
|
virtual ResultOrError<std::unique_ptr<StagingBufferBase>> CreateStagingBuffer(
|
|
|
|
size_t size) = 0;
|
|
|
|
virtual MaybeError CopyFromStagingToBuffer(StagingBufferBase* source,
|
2019-04-05 20:51:29 +00:00
|
|
|
uint64_t sourceOffset,
|
2019-01-29 00:10:07 +00:00
|
|
|
BufferBase* destination,
|
2019-04-05 20:51:29 +00:00
|
|
|
uint64_t destinationOffset,
|
|
|
|
uint64_t size) = 0;
|
2019-01-29 00:10:07 +00:00
|
|
|
|
2019-02-15 21:18:40 +00:00
|
|
|
ResultOrError<DynamicUploader*> GetDynamicUploader() const;
|
|
|
|
|
2019-08-02 00:06:38 +00:00
|
|
|
std::vector<const char*> GetEnabledExtensions() const;
|
2019-04-26 07:52:57 +00:00
|
|
|
std::vector<const char*> GetTogglesUsed() const;
|
2019-08-02 00:06:38 +00:00
|
|
|
bool IsExtensionEnabled(Extension extension) const;
|
2019-04-26 07:52:57 +00:00
|
|
|
bool IsToggleEnabled(Toggle toggle) const;
|
2019-07-26 17:54:48 +00:00
|
|
|
size_t GetLazyClearCountForTesting();
|
|
|
|
void IncrementLazyClearCountForTesting();
|
2019-04-26 07:52:57 +00:00
|
|
|
|
2019-02-15 21:18:40 +00:00
|
|
|
protected:
|
2019-04-26 07:52:57 +00:00
|
|
|
void SetToggle(Toggle toggle, bool isEnabled);
|
|
|
|
void ApplyToggleOverrides(const DeviceDescriptor* deviceDescriptor);
|
|
|
|
|
2019-02-15 21:18:40 +00:00
|
|
|
std::unique_ptr<DynamicUploader> mDynamicUploader;
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
private:
|
2018-12-05 07:18:30 +00:00
|
|
|
virtual ResultOrError<BindGroupBase*> CreateBindGroupImpl(
|
|
|
|
const BindGroupDescriptor* descriptor) = 0;
|
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-08-22 13:37:29 +00:00
|
|
|
virtual ResultOrError<BufferBase*> CreateBufferImpl(const BufferDescriptor* descriptor) = 0;
|
2018-08-27 21:12:56 +00:00
|
|
|
virtual ResultOrError<ComputePipelineBase*> CreateComputePipelineImpl(
|
|
|
|
const ComputePipelineDescriptor* 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-12-10 19:47:22 +00:00
|
|
|
virtual ResultOrError<RenderPipelineBase*> CreateRenderPipelineImpl(
|
|
|
|
const RenderPipelineDescriptor* descriptor) = 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;
|
2019-02-15 11:15:58 +00:00
|
|
|
virtual ResultOrError<SwapChainBase*> CreateSwapChainImpl(
|
|
|
|
const SwapChainDescriptor* descriptor) = 0;
|
2018-08-27 00:44:48 +00:00
|
|
|
virtual ResultOrError<TextureBase*> CreateTextureImpl(
|
|
|
|
const TextureDescriptor* descriptor) = 0;
|
2018-10-12 08:32:58 +00:00
|
|
|
virtual ResultOrError<TextureViewBase*> CreateTextureViewImpl(
|
|
|
|
TextureBase* texture,
|
|
|
|
const TextureViewDescriptor* descriptor) = 0;
|
2018-05-17 21:09:07 +00:00
|
|
|
|
2018-12-05 07:18:30 +00:00
|
|
|
MaybeError CreateBindGroupInternal(BindGroupBase** result,
|
|
|
|
const BindGroupDescriptor* descriptor);
|
2018-07-16 15:40:08 +00:00
|
|
|
MaybeError CreateBindGroupLayoutInternal(BindGroupLayoutBase** result,
|
2018-07-25 15:03:23 +00:00
|
|
|
const BindGroupLayoutDescriptor* descriptor);
|
2018-08-22 13:37:29 +00:00
|
|
|
MaybeError CreateBufferInternal(BufferBase** result, const BufferDescriptor* descriptor);
|
2018-08-27 21:12:56 +00:00
|
|
|
MaybeError CreateComputePipelineInternal(ComputePipelineBase** result,
|
|
|
|
const ComputePipelineDescriptor* 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);
|
2019-08-13 22:12:54 +00:00
|
|
|
MaybeError CreateRenderBundleEncoderInternal(
|
|
|
|
RenderBundleEncoderBase** result,
|
|
|
|
const RenderBundleEncoderDescriptor* descriptor);
|
2018-12-10 19:47:22 +00:00
|
|
|
MaybeError CreateRenderPipelineInternal(RenderPipelineBase** result,
|
|
|
|
const RenderPipelineDescriptor* descriptor);
|
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);
|
2019-02-15 11:15:58 +00:00
|
|
|
MaybeError CreateSwapChainInternal(SwapChainBase** result,
|
|
|
|
const SwapChainDescriptor* descriptor);
|
2018-08-27 00:44:48 +00:00
|
|
|
MaybeError CreateTextureInternal(TextureBase** result, const TextureDescriptor* descriptor);
|
2018-10-12 08:32:58 +00:00
|
|
|
MaybeError CreateTextureViewInternal(TextureViewBase** result,
|
|
|
|
TextureBase* texture,
|
|
|
|
const TextureViewDescriptor* descriptor);
|
2018-07-16 15:40:08 +00:00
|
|
|
|
2019-08-02 00:06:38 +00:00
|
|
|
void ApplyExtensions(const DeviceDescriptor* deviceDescriptor);
|
|
|
|
|
2019-06-11 18:11:05 +00:00
|
|
|
void SetDefaultToggles();
|
2018-07-16 15:40:08 +00:00
|
|
|
|
2019-09-18 21:03:41 +00:00
|
|
|
void ConsumeError(ErrorData* error);
|
|
|
|
|
2019-01-10 10:50:54 +00:00
|
|
|
AdapterBase* mAdapter = nullptr;
|
|
|
|
|
2019-09-10 23:19:11 +00:00
|
|
|
Ref<ErrorScope> mRootErrorScope;
|
|
|
|
Ref<ErrorScope> mCurrentErrorScope;
|
|
|
|
|
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;
|
2018-09-06 13:26:48 +00:00
|
|
|
std::unique_ptr<Caches> mCaches;
|
2017-11-24 18:59:42 +00:00
|
|
|
|
2019-06-14 17:35:56 +00:00
|
|
|
struct DeferredCreateBufferMappedAsync {
|
|
|
|
dawn::BufferCreateMappedCallback callback;
|
|
|
|
DawnBufferMapAsyncStatus status;
|
|
|
|
DawnCreateBufferMappedResult result;
|
|
|
|
void* userdata;
|
|
|
|
};
|
|
|
|
|
2019-09-17 18:24:07 +00:00
|
|
|
std::unique_ptr<ErrorScopeTracker> mErrorScopeTracker;
|
2018-12-03 16:57:34 +00:00
|
|
|
std::unique_ptr<FenceSignalTracker> mFenceSignalTracker;
|
2019-06-14 17:35:56 +00:00
|
|
|
std::vector<DeferredCreateBufferMappedAsync> mDeferredCreateBufferMappedAsyncResults;
|
2018-12-03 16:57:34 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
uint32_t mRefCount = 1;
|
2019-04-26 07:52:57 +00:00
|
|
|
|
2019-07-18 09:25:04 +00:00
|
|
|
FormatTable mFormatTable;
|
|
|
|
|
2019-04-26 07:52:57 +00:00
|
|
|
TogglesSet mTogglesSet;
|
2019-07-26 17:54:48 +00:00
|
|
|
size_t mLazyClearCountForTesting = 0;
|
2019-08-02 00:06:38 +00:00
|
|
|
|
|
|
|
ExtensionsSet mEnabledExtensions;
|
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
|
|
|
|
2019-01-04 10:30:40 +00:00
|
|
|
#endif // DAWNNATIVE_DEVICE_H_
|