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
|
|
|
|
2020-08-20 13:29:39 +00:00
|
|
|
#include "dawn_native/Commands.h"
|
2021-10-13 04:19:26 +00:00
|
|
|
#include "dawn_native/ComputePipeline.h"
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/Error.h"
|
2021-10-04 11:30:02 +00:00
|
|
|
#include "dawn_native/Features.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"
|
2021-09-13 18:49:09 +00:00
|
|
|
#include "dawn_native/Limits.h"
|
2018-10-15 12:54:30 +00:00
|
|
|
#include "dawn_native/ObjectBase.h"
|
2021-09-28 15:40:01 +00:00
|
|
|
#include "dawn_native/ObjectType_autogen.h"
|
|
|
|
#include "dawn_native/StagingBuffer.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
|
|
|
|
2021-09-28 15:40:01 +00:00
|
|
|
#include <mutex>
|
2021-04-08 01:22:22 +00:00
|
|
|
#include <utility>
|
2018-09-06 13:26:48 +00:00
|
|
|
|
2022-01-11 02:10:53 +00:00
|
|
|
namespace dawn::platform {
|
2021-06-04 05:12:06 +00:00
|
|
|
class WorkerTaskPool;
|
2022-01-11 02:10:53 +00:00
|
|
|
} // namespace dawn::platform
|
2021-06-04 05:12:06 +00:00
|
|
|
|
2022-01-12 09:17:35 +00:00
|
|
|
namespace dawn::native {
|
2019-01-10 10:50:54 +00:00
|
|
|
class AdapterBase;
|
2021-06-04 05:12:06 +00:00
|
|
|
class AsyncTaskManager;
|
2019-07-26 19:08:18 +00:00
|
|
|
class AttachmentState;
|
2019-08-13 22:12:54 +00:00
|
|
|
class AttachmentStateBlueprint;
|
2020-03-20 21:56:30 +00:00
|
|
|
class BindGroupLayoutBase;
|
2021-05-02 03:22:30 +00:00
|
|
|
class CallbackTaskManager;
|
2020-03-20 21:56:30 +00:00
|
|
|
class DynamicUploader;
|
2021-02-19 18:17:22 +00:00
|
|
|
class ErrorScopeStack;
|
2021-04-01 20:46:42 +00:00
|
|
|
class ExternalTextureBase;
|
2021-04-08 04:25:11 +00:00
|
|
|
class OwnedCompilationMessages;
|
2020-11-20 20:38:37 +00:00
|
|
|
class PersistentCache;
|
2019-01-29 00:10:07 +00:00
|
|
|
class StagingBufferBase;
|
2021-06-04 05:12:06 +00:00
|
|
|
struct CallbackTask;
|
2020-11-04 02:30:16 +00:00
|
|
|
struct InternalPipelineStore;
|
2020-12-07 18:12:13 +00:00
|
|
|
struct ShaderModuleParseResult;
|
2018-12-03 16:57:34 +00:00
|
|
|
|
2021-03-25 23:50:24 +00:00
|
|
|
class DeviceBase : public RefCounted {
|
2017-11-24 18:59:42 +00:00
|
|
|
public:
|
2021-12-22 19:02:23 +00:00
|
|
|
DeviceBase(AdapterBase* adapter, const DeviceDescriptor* descriptor);
|
2017-11-24 18:59:42 +00:00
|
|
|
virtual ~DeviceBase();
|
|
|
|
|
2020-04-01 12:07:43 +00:00
|
|
|
void HandleError(InternalErrorType 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-10-09 10:11:00 +00:00
|
|
|
template <typename T>
|
|
|
|
bool ConsumedError(ResultOrError<T> resultOrError, T* result) {
|
|
|
|
if (DAWN_UNLIKELY(resultOrError.IsError())) {
|
|
|
|
ConsumeError(resultOrError.AcquireError());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
*result = resultOrError.AcquireSuccess();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-01 18:15:40 +00:00
|
|
|
template <typename... Args>
|
|
|
|
bool ConsumedError(MaybeError maybeError, const char* formatStr, const Args&... args) {
|
|
|
|
if (DAWN_UNLIKELY(maybeError.IsError())) {
|
|
|
|
std::unique_ptr<ErrorData> error = maybeError.AcquireError();
|
|
|
|
if (error->GetType() == InternalErrorType::Validation) {
|
|
|
|
std::string out;
|
|
|
|
absl::UntypedFormatSpec format(formatStr);
|
|
|
|
if (absl::FormatUntyped(&out, format, {absl::FormatArg(args)...})) {
|
|
|
|
error->AppendContext(std::move(out));
|
2021-11-03 01:31:19 +00:00
|
|
|
} else {
|
|
|
|
error->AppendContext(
|
|
|
|
absl::StrFormat("[Failed to format error: \"%s\"]", formatStr));
|
2021-10-01 18:15:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ConsumeError(std::move(error));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-29 18:39:23 +00:00
|
|
|
template <typename T, typename... Args>
|
|
|
|
bool ConsumedError(ResultOrError<T> resultOrError,
|
|
|
|
T* result,
|
|
|
|
const char* formatStr,
|
|
|
|
const Args&... args) {
|
|
|
|
if (DAWN_UNLIKELY(resultOrError.IsError())) {
|
|
|
|
std::unique_ptr<ErrorData> error = resultOrError.AcquireError();
|
|
|
|
if (error->GetType() == InternalErrorType::Validation) {
|
|
|
|
std::string out;
|
|
|
|
absl::UntypedFormatSpec format(formatStr);
|
|
|
|
if (absl::FormatUntyped(&out, format, {absl::FormatArg(args)...})) {
|
|
|
|
error->AppendContext(std::move(out));
|
2021-11-03 01:31:19 +00:00
|
|
|
} else {
|
|
|
|
error->AppendContext(
|
|
|
|
absl::StrFormat("[Failed to format error: \"%s\"]", formatStr));
|
2021-09-29 18:39:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ConsumeError(std::move(error));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
*result = resultOrError.AcquireSuccess();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-28 15:40:01 +00:00
|
|
|
MaybeError ValidateObject(const ApiObjectBase* object) const;
|
2019-02-13 13:09:18 +00:00
|
|
|
|
2019-01-30 16:07:48 +00:00
|
|
|
AdapterBase* GetAdapter() const;
|
2022-01-11 02:10:53 +00:00
|
|
|
dawn::platform::Platform* GetPlatform() const;
|
2019-01-30 16:07:48 +00:00
|
|
|
|
2019-10-23 11:57:41 +00:00
|
|
|
// Returns the Format corresponding to the wgpu::TextureFormat or an error if the format
|
|
|
|
// isn't a valid wgpu::TextureFormat or isn't supported by this device.
|
2019-07-18 09:25:04 +00:00
|
|
|
// The pointer returned has the same lifetime as the device.
|
2019-10-23 11:57:41 +00:00
|
|
|
ResultOrError<const Format*> GetInternalFormat(wgpu::TextureFormat format) const;
|
2019-07-18 09:25:04 +00:00
|
|
|
|
2019-10-23 11:57:41 +00:00
|
|
|
// Returns the Format corresponding to the wgpu::TextureFormat and assumes the format is
|
2019-07-18 09:25:04 +00:00
|
|
|
// valid and supported.
|
|
|
|
// The reference returned has the same lifetime as the device.
|
2019-10-23 11:57:41 +00:00
|
|
|
const Format& GetValidInternalFormat(wgpu::TextureFormat format) const;
|
2019-07-18 09:25:04 +00:00
|
|
|
|
2021-03-31 18:36:32 +00:00
|
|
|
virtual ResultOrError<Ref<CommandBufferBase>> CreateCommandBuffer(
|
2019-11-13 17:00:37 +00:00
|
|
|
CommandEncoder* encoder,
|
2019-07-10 20:43:13 +00:00
|
|
|
const CommandBufferDescriptor* descriptor) = 0;
|
2017-11-24 18:59:42 +00:00
|
|
|
|
2020-09-28 19:35:14 +00:00
|
|
|
ExecutionSerial GetCompletedCommandSerial() const;
|
|
|
|
ExecutionSerial GetLastSubmittedCommandSerial() const;
|
2020-10-15 16:21:03 +00:00
|
|
|
ExecutionSerial GetFutureSerial() const;
|
2020-09-28 19:35:14 +00:00
|
|
|
ExecutionSerial GetPendingCommandSerial() const;
|
2017-11-24 18:59:42 +00:00
|
|
|
|
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.
|
2020-07-01 13:09:46 +00:00
|
|
|
ResultOrError<Ref<BindGroupLayoutBase>> GetOrCreateBindGroupLayout(
|
2021-09-01 22:15:41 +00:00
|
|
|
const BindGroupLayoutDescriptor* descriptor,
|
|
|
|
PipelineCompatibilityToken pipelineCompatibilityToken = PipelineCompatibilityToken(0));
|
2017-11-24 18:59:42 +00:00
|
|
|
void UncacheBindGroupLayout(BindGroupLayoutBase* obj);
|
|
|
|
|
2020-07-01 13:09:46 +00:00
|
|
|
BindGroupLayoutBase* GetEmptyBindGroupLayout();
|
2020-06-29 11:13:43 +00:00
|
|
|
|
2019-05-01 13:48:47 +00:00
|
|
|
void UncacheComputePipeline(ComputePipelineBase* obj);
|
|
|
|
|
2021-03-31 18:36:32 +00:00
|
|
|
ResultOrError<Ref<PipelineLayoutBase>> GetOrCreatePipelineLayout(
|
2019-05-01 12:57:27 +00:00
|
|
|
const PipelineLayoutDescriptor* descriptor);
|
|
|
|
void UncachePipelineLayout(PipelineLayoutBase* obj);
|
|
|
|
|
2019-05-02 15:30:56 +00:00
|
|
|
void UncacheRenderPipeline(RenderPipelineBase* obj);
|
|
|
|
|
2021-03-31 18:36:32 +00:00
|
|
|
ResultOrError<Ref<SamplerBase>> GetOrCreateSampler(const SamplerDescriptor* descriptor);
|
2019-05-20 18:16:34 +00:00
|
|
|
void UncacheSampler(SamplerBase* obj);
|
|
|
|
|
2021-03-31 18:36:32 +00:00
|
|
|
ResultOrError<Ref<ShaderModuleBase>> GetOrCreateShaderModule(
|
2020-12-07 18:12:13 +00:00
|
|
|
const ShaderModuleDescriptor* descriptor,
|
2021-06-18 13:29:39 +00:00
|
|
|
ShaderModuleParseResult* parseResult,
|
|
|
|
OwnedCompilationMessages* compilationMessages);
|
2019-05-01 13:27:07 +00:00
|
|
|
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);
|
|
|
|
|
2021-04-19 08:52:35 +00:00
|
|
|
// Object creation methods that be used in a reentrant manner.
|
|
|
|
ResultOrError<Ref<BindGroupBase>> CreateBindGroup(const BindGroupDescriptor* descriptor);
|
|
|
|
ResultOrError<Ref<BindGroupLayoutBase>> CreateBindGroupLayout(
|
2021-07-02 09:51:18 +00:00
|
|
|
const BindGroupLayoutDescriptor* descriptor,
|
|
|
|
bool allowInternalBinding = false);
|
2021-04-19 08:52:35 +00:00
|
|
|
ResultOrError<Ref<BufferBase>> CreateBuffer(const BufferDescriptor* descriptor);
|
|
|
|
ResultOrError<Ref<ComputePipelineBase>> CreateComputePipeline(
|
|
|
|
const ComputePipelineDescriptor* descriptor);
|
|
|
|
MaybeError CreateComputePipelineAsync(
|
|
|
|
const ComputePipelineDescriptor* descriptor,
|
|
|
|
WGPUCreateComputePipelineAsyncCallback callback,
|
|
|
|
void* userdata);
|
|
|
|
ResultOrError<Ref<ExternalTextureBase>> CreateExternalTexture(
|
|
|
|
const ExternalTextureDescriptor* descriptor);
|
|
|
|
ResultOrError<Ref<PipelineLayoutBase>> CreatePipelineLayout(
|
|
|
|
const PipelineLayoutDescriptor* descriptor);
|
|
|
|
ResultOrError<Ref<QuerySetBase>> CreateQuerySet(const QuerySetDescriptor* descriptor);
|
|
|
|
ResultOrError<Ref<RenderBundleEncoder>> CreateRenderBundleEncoder(
|
|
|
|
const RenderBundleEncoderDescriptor* descriptor);
|
|
|
|
ResultOrError<Ref<RenderPipelineBase>> CreateRenderPipeline(
|
2021-05-21 05:01:38 +00:00
|
|
|
const RenderPipelineDescriptor* descriptor);
|
2021-08-26 00:39:14 +00:00
|
|
|
MaybeError CreateRenderPipelineAsync(const RenderPipelineDescriptor* descriptor,
|
|
|
|
WGPUCreateRenderPipelineAsyncCallback callback,
|
|
|
|
void* userdata);
|
2021-04-19 08:52:35 +00:00
|
|
|
ResultOrError<Ref<SamplerBase>> CreateSampler(const SamplerDescriptor* descriptor);
|
|
|
|
ResultOrError<Ref<ShaderModuleBase>> CreateShaderModule(
|
|
|
|
const ShaderModuleDescriptor* descriptor,
|
2021-06-18 13:29:39 +00:00
|
|
|
OwnedCompilationMessages* compilationMessages = nullptr);
|
2021-04-19 08:52:35 +00:00
|
|
|
ResultOrError<Ref<SwapChainBase>> CreateSwapChain(Surface* surface,
|
|
|
|
const SwapChainDescriptor* descriptor);
|
|
|
|
ResultOrError<Ref<TextureBase>> CreateTexture(const TextureDescriptor* descriptor);
|
|
|
|
ResultOrError<Ref<TextureViewBase>> CreateTextureView(
|
|
|
|
TextureBase* texture,
|
|
|
|
const TextureViewDescriptor* descriptor);
|
|
|
|
|
|
|
|
// Implementation of API object creation methods. DO NOT use them in a reentrant manner.
|
2021-03-29 14:02:05 +00:00
|
|
|
BindGroupBase* APICreateBindGroup(const BindGroupDescriptor* descriptor);
|
|
|
|
BindGroupLayoutBase* APICreateBindGroupLayout(const BindGroupLayoutDescriptor* descriptor);
|
|
|
|
BufferBase* APICreateBuffer(const BufferDescriptor* descriptor);
|
|
|
|
CommandEncoder* APICreateCommandEncoder(const CommandEncoderDescriptor* descriptor);
|
|
|
|
ComputePipelineBase* APICreateComputePipeline(const ComputePipelineDescriptor* descriptor);
|
|
|
|
PipelineLayoutBase* APICreatePipelineLayout(const PipelineLayoutDescriptor* descriptor);
|
|
|
|
QuerySetBase* APICreateQuerySet(const QuerySetDescriptor* descriptor);
|
|
|
|
void APICreateComputePipelineAsync(const ComputePipelineDescriptor* descriptor,
|
|
|
|
WGPUCreateComputePipelineAsyncCallback callback,
|
|
|
|
void* userdata);
|
2021-05-21 05:01:38 +00:00
|
|
|
void APICreateRenderPipelineAsync(const RenderPipelineDescriptor* descriptor,
|
2021-03-29 14:02:05 +00:00
|
|
|
WGPUCreateRenderPipelineAsyncCallback callback,
|
|
|
|
void* userdata);
|
|
|
|
RenderBundleEncoder* APICreateRenderBundleEncoder(
|
2019-08-13 22:12:54 +00:00
|
|
|
const RenderBundleEncoderDescriptor* descriptor);
|
2021-03-29 14:02:05 +00:00
|
|
|
RenderPipelineBase* APICreateRenderPipeline(const RenderPipelineDescriptor* descriptor);
|
2021-04-01 20:46:42 +00:00
|
|
|
ExternalTextureBase* APICreateExternalTexture(const ExternalTextureDescriptor* descriptor);
|
2021-03-29 14:02:05 +00:00
|
|
|
SamplerBase* APICreateSampler(const SamplerDescriptor* descriptor);
|
|
|
|
ShaderModuleBase* APICreateShaderModule(const ShaderModuleDescriptor* descriptor);
|
|
|
|
SwapChainBase* APICreateSwapChain(Surface* surface, const SwapChainDescriptor* descriptor);
|
|
|
|
TextureBase* APICreateTexture(const TextureDescriptor* descriptor);
|
2021-04-19 08:52:35 +00:00
|
|
|
|
2020-11-04 02:30:16 +00:00
|
|
|
InternalPipelineStore* GetInternalPipelineStore();
|
2017-11-24 18:59:42 +00:00
|
|
|
|
2020-06-15 23:42:13 +00:00
|
|
|
// For Dawn Wire
|
2021-03-29 14:02:05 +00:00
|
|
|
BufferBase* APICreateErrorBuffer();
|
2020-06-15 23:42:13 +00:00
|
|
|
|
2021-03-29 14:02:05 +00:00
|
|
|
QueueBase* APIGetQueue();
|
2020-04-17 16:45:17 +00:00
|
|
|
|
2021-12-15 00:12:30 +00:00
|
|
|
bool APIGetLimits(SupportedLimits* limits) const;
|
|
|
|
bool APIHasFeature(wgpu::FeatureName feature) const;
|
2022-01-06 22:11:28 +00:00
|
|
|
size_t APIEnumerateFeatures(wgpu::FeatureName* features) const;
|
2021-03-29 14:02:05 +00:00
|
|
|
void APIInjectError(wgpu::ErrorType type, const char* message);
|
|
|
|
bool APITick();
|
2018-12-01 03:20:19 +00:00
|
|
|
|
2021-03-29 14:02:05 +00:00
|
|
|
void APISetDeviceLostCallback(wgpu::DeviceLostCallback callback, void* userdata);
|
|
|
|
void APISetUncapturedErrorCallback(wgpu::ErrorCallback callback, void* userdata);
|
Add the user-visible logging interface.
Details:
- Add the logging level type WGPULoggingType, including levels verbose,
info, warning, and error,
- Add the API SetLoggingCallback, which bind the callback to deal with
logging string,
- Add the return command DeviceLoggingCallback and related code,
- Add DeviceBase::EmitLog(WGPULoggingType, const char*) , and
DeviceBase::EmitLog(const char*) use WGPULoggingType_info as default,
to post logging from native or server device to bound callback
via CallbackTaskManager.
BUG: dawn:792
Change-Id: I107b9134ff8567a46fa452509799e10b6862b8d3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/52200
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
2021-06-04 07:10:56 +00:00
|
|
|
void APISetLoggingCallback(wgpu::LoggingCallback callback, void* userdata);
|
2021-03-29 14:02:05 +00:00
|
|
|
void APIPushErrorScope(wgpu::ErrorFilter filter);
|
|
|
|
bool APIPopErrorScope(wgpu::ErrorCallback callback, void* userdata);
|
2020-01-15 19:02:13 +00:00
|
|
|
|
|
|
|
MaybeError ValidateIsAlive() const;
|
|
|
|
|
2020-11-20 20:38:37 +00:00
|
|
|
PersistentCache* GetPersistentCache();
|
|
|
|
|
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;
|
2020-08-20 13:29:39 +00:00
|
|
|
virtual MaybeError CopyFromStagingToTexture(const StagingBufferBase* source,
|
|
|
|
const TextureDataLayout& src,
|
|
|
|
TextureCopy* dst,
|
|
|
|
const Extent3D& copySizePixels) = 0;
|
2019-01-29 00:10:07 +00:00
|
|
|
|
2019-09-18 22:06:41 +00:00
|
|
|
DynamicUploader* GetDynamicUploader() const;
|
2019-02-15 21:18:40 +00:00
|
|
|
|
2020-04-07 16:19:47 +00:00
|
|
|
// The device state which is a combination of creation state and loss state.
|
|
|
|
//
|
|
|
|
// - BeingCreated: the device didn't finish creation yet and the frontend cannot be used
|
|
|
|
// (both for the application calling WebGPU, or re-entrant calls). No work exists on
|
|
|
|
// the GPU timeline.
|
|
|
|
// - Alive: the device is usable and might have work happening on the GPU timeline.
|
|
|
|
// - BeingDisconnected: the device is no longer usable because we are waiting for all
|
|
|
|
// work on the GPU timeline to finish. (this is to make validation prevent the
|
|
|
|
// application from adding more work during the transition from Available to
|
|
|
|
// Disconnected)
|
|
|
|
// - Disconnected: there is no longer work happening on the GPU timeline and the CPU data
|
|
|
|
// structures can be safely destroyed without additional synchronization.
|
2021-12-01 17:55:30 +00:00
|
|
|
// - Destroyed: the device is disconnected and resources have been reclaimed.
|
2020-04-07 16:19:47 +00:00
|
|
|
enum class State {
|
|
|
|
BeingCreated,
|
|
|
|
Alive,
|
|
|
|
BeingDisconnected,
|
|
|
|
Disconnected,
|
2021-12-01 17:55:30 +00:00
|
|
|
Destroyed,
|
2020-04-07 16:19:47 +00:00
|
|
|
};
|
|
|
|
State GetState() const;
|
|
|
|
bool IsLost() const;
|
2021-10-12 17:46:26 +00:00
|
|
|
void TrackObject(ApiObjectBase* object);
|
2021-09-28 15:40:01 +00:00
|
|
|
std::mutex* GetObjectListMutex(ObjectType type);
|
2020-04-07 16:19:47 +00:00
|
|
|
|
2019-04-26 07:52:57 +00:00
|
|
|
std::vector<const char*> GetTogglesUsed() const;
|
2021-10-04 11:30:02 +00:00
|
|
|
bool IsFeatureEnabled(Feature feature) const;
|
2019-04-26 07:52:57 +00:00
|
|
|
bool IsToggleEnabled(Toggle toggle) const;
|
2019-11-21 00:48:39 +00:00
|
|
|
bool IsValidationEnabled() const;
|
2020-07-01 21:37:57 +00:00
|
|
|
bool IsRobustnessEnabled() const;
|
2019-07-26 17:54:48 +00:00
|
|
|
size_t GetLazyClearCountForTesting();
|
|
|
|
void IncrementLazyClearCountForTesting();
|
2020-04-17 16:45:17 +00:00
|
|
|
size_t GetDeprecationWarningCountForTesting();
|
|
|
|
void EmitDeprecationWarning(const char* warning);
|
Add the user-visible logging interface.
Details:
- Add the logging level type WGPULoggingType, including levels verbose,
info, warning, and error,
- Add the API SetLoggingCallback, which bind the callback to deal with
logging string,
- Add the return command DeviceLoggingCallback and related code,
- Add DeviceBase::EmitLog(WGPULoggingType, const char*) , and
DeviceBase::EmitLog(const char*) use WGPULoggingType_info as default,
to post logging from native or server device to bound callback
via CallbackTaskManager.
BUG: dawn:792
Change-Id: I107b9134ff8567a46fa452509799e10b6862b8d3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/52200
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
2021-06-04 07:10:56 +00:00
|
|
|
void EmitLog(const char* message);
|
|
|
|
void EmitLog(WGPULoggingType loggingType, const char* message);
|
2021-03-29 14:02:05 +00:00
|
|
|
void APILoseForTesting();
|
2021-03-29 15:40:55 +00:00
|
|
|
QueueBase* GetQueue() const;
|
2020-10-15 16:21:03 +00:00
|
|
|
|
|
|
|
// AddFutureSerial is used to update the mFutureSerial with the max serial needed to be
|
|
|
|
// ticked in order to clean up all pending callback work or to execute asynchronous resource
|
|
|
|
// writes. It should be given the serial that a callback is tracked with, so that once that
|
|
|
|
// serial is completed, it can be resolved and cleaned up. This is so that when there is no
|
|
|
|
// gpu work (the last submitted serial has not moved beyond the completed serial), Tick can
|
|
|
|
// still check if we have pending work to take care of, rather than hanging and never
|
|
|
|
// reaching the serial the work will be executed on.
|
|
|
|
void AddFutureSerial(ExecutionSerial serial);
|
2020-11-13 02:11:12 +00:00
|
|
|
// Check for passed fences and set the new completed serial
|
2021-04-07 18:09:21 +00:00
|
|
|
MaybeError CheckPassedSerials();
|
2019-04-26 07:52:57 +00:00
|
|
|
|
2021-03-30 10:21:36 +00:00
|
|
|
MaybeError Tick();
|
|
|
|
|
2021-11-17 05:00:44 +00:00
|
|
|
// TODO(crbug.com/dawn/839): Organize the below backend-specific parameters into the struct
|
|
|
|
// BackendMetadata that we can query from the device.
|
2020-08-20 13:29:39 +00:00
|
|
|
virtual uint32_t GetOptimalBytesPerRowAlignment() const = 0;
|
|
|
|
virtual uint64_t GetOptimalBufferToTextureCopyOffsetAlignment() const = 0;
|
|
|
|
|
2021-01-05 02:39:18 +00:00
|
|
|
virtual float GetTimestampPeriodInNS() const = 0;
|
|
|
|
|
2021-11-17 05:00:44 +00:00
|
|
|
virtual bool ShouldDuplicateNumWorkgroupsForDispatchIndirect(
|
|
|
|
ComputePipelineBase* computePipeline) const;
|
|
|
|
|
2021-10-13 18:57:18 +00:00
|
|
|
const CombinedLimits& GetLimits() const;
|
|
|
|
|
2021-06-04 05:12:06 +00:00
|
|
|
AsyncTaskManager* GetAsyncTaskManager() const;
|
|
|
|
CallbackTaskManager* GetCallbackTaskManager() const;
|
2022-01-11 02:10:53 +00:00
|
|
|
dawn::platform::WorkerTaskPool* GetWorkerTaskPool() const;
|
2021-06-04 05:12:06 +00:00
|
|
|
|
|
|
|
void AddComputePipelineAsyncCallbackTask(Ref<ComputePipelineBase> pipeline,
|
|
|
|
std::string errorMessage,
|
|
|
|
WGPUCreateComputePipelineAsyncCallback callback,
|
2021-10-13 00:43:05 +00:00
|
|
|
void* userdata);
|
2021-09-17 07:39:00 +00:00
|
|
|
void AddRenderPipelineAsyncCallbackTask(Ref<RenderPipelineBase> pipeline,
|
|
|
|
std::string errorMessage,
|
|
|
|
WGPUCreateRenderPipelineAsyncCallback callback,
|
2021-09-29 00:49:01 +00:00
|
|
|
void* userdata);
|
2021-06-04 05:12:06 +00:00
|
|
|
|
2021-09-01 22:15:41 +00:00
|
|
|
PipelineCompatibilityToken GetNextPipelineCompatibilityToken();
|
|
|
|
|
2021-09-23 21:26:33 +00:00
|
|
|
const std::string& GetLabel() const;
|
|
|
|
void APISetLabel(const char* label);
|
2021-12-01 17:55:30 +00:00
|
|
|
void APIDestroy();
|
2021-09-23 21:26:33 +00:00
|
|
|
|
2019-02-15 21:18:40 +00:00
|
|
|
protected:
|
2021-10-12 18:53:57 +00:00
|
|
|
// Constructor used only for mocking and testing.
|
|
|
|
DeviceBase();
|
|
|
|
|
2019-04-26 07:52:57 +00:00
|
|
|
void SetToggle(Toggle toggle, bool isEnabled);
|
2020-04-06 16:55:22 +00:00
|
|
|
void ForceSetToggle(Toggle toggle, bool isEnabled);
|
2020-04-07 15:10:17 +00:00
|
|
|
|
2020-04-17 16:45:17 +00:00
|
|
|
MaybeError Initialize(QueueBase* defaultQueue);
|
2021-10-12 17:46:26 +00:00
|
|
|
void DestroyObjects();
|
|
|
|
void Destroy();
|
2019-02-15 21:18:40 +00:00
|
|
|
|
2020-05-07 21:52:54 +00:00
|
|
|
// Incrememt mLastSubmittedSerial when we submit the next serial
|
|
|
|
void IncrementLastSubmittedCommandSerial();
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
private:
|
2021-03-31 18:36:32 +00:00
|
|
|
virtual ResultOrError<Ref<BindGroupBase>> CreateBindGroupImpl(
|
2018-12-05 07:18:30 +00:00
|
|
|
const BindGroupDescriptor* descriptor) = 0;
|
2021-03-31 18:36:32 +00:00
|
|
|
virtual ResultOrError<Ref<BindGroupLayoutBase>> CreateBindGroupLayoutImpl(
|
2021-09-01 22:15:41 +00:00
|
|
|
const BindGroupLayoutDescriptor* descriptor,
|
|
|
|
PipelineCompatibilityToken pipelineCompatibilityToken) = 0;
|
2020-07-08 19:45:40 +00:00
|
|
|
virtual ResultOrError<Ref<BufferBase>> CreateBufferImpl(
|
|
|
|
const BufferDescriptor* descriptor) = 0;
|
2021-03-31 18:36:32 +00:00
|
|
|
virtual ResultOrError<Ref<PipelineLayoutBase>> CreatePipelineLayoutImpl(
|
2018-07-25 15:03:23 +00:00
|
|
|
const PipelineLayoutDescriptor* descriptor) = 0;
|
2021-03-31 18:36:32 +00:00
|
|
|
virtual ResultOrError<Ref<QuerySetBase>> CreateQuerySetImpl(
|
2020-06-11 00:34:14 +00:00
|
|
|
const QuerySetDescriptor* descriptor) = 0;
|
2021-03-31 18:36:32 +00:00
|
|
|
virtual ResultOrError<Ref<SamplerBase>> CreateSamplerImpl(
|
2018-07-25 15:03:23 +00:00
|
|
|
const SamplerDescriptor* descriptor) = 0;
|
2021-03-31 18:36:32 +00:00
|
|
|
virtual ResultOrError<Ref<ShaderModuleBase>> CreateShaderModuleImpl(
|
2020-12-07 18:12:13 +00:00
|
|
|
const ShaderModuleDescriptor* descriptor,
|
|
|
|
ShaderModuleParseResult* parseResult) = 0;
|
2021-03-31 18:36:32 +00:00
|
|
|
virtual ResultOrError<Ref<SwapChainBase>> CreateSwapChainImpl(
|
2019-02-15 11:15:58 +00:00
|
|
|
const SwapChainDescriptor* descriptor) = 0;
|
2020-01-25 10:05:40 +00:00
|
|
|
// Note that previousSwapChain may be nullptr, or come from a different backend.
|
2021-03-31 18:36:32 +00:00
|
|
|
virtual ResultOrError<Ref<NewSwapChainBase>> CreateSwapChainImpl(
|
2020-01-23 17:20:38 +00:00
|
|
|
Surface* surface,
|
2020-01-25 10:05:40 +00:00
|
|
|
NewSwapChainBase* previousSwapChain,
|
2020-01-23 17:20:38 +00:00
|
|
|
const SwapChainDescriptor* descriptor) = 0;
|
2020-04-23 19:47:12 +00:00
|
|
|
virtual ResultOrError<Ref<TextureBase>> CreateTextureImpl(
|
2018-08-27 00:44:48 +00:00
|
|
|
const TextureDescriptor* descriptor) = 0;
|
2021-03-31 18:36:32 +00:00
|
|
|
virtual ResultOrError<Ref<TextureViewBase>> CreateTextureViewImpl(
|
2018-10-12 08:32:58 +00:00
|
|
|
TextureBase* texture,
|
|
|
|
const TextureViewDescriptor* descriptor) = 0;
|
2021-10-13 00:43:05 +00:00
|
|
|
virtual Ref<ComputePipelineBase> CreateUninitializedComputePipelineImpl(
|
|
|
|
const ComputePipelineDescriptor* descriptor) = 0;
|
|
|
|
virtual Ref<RenderPipelineBase> CreateUninitializedRenderPipelineImpl(
|
|
|
|
const RenderPipelineDescriptor* descriptor) = 0;
|
2021-09-23 21:26:33 +00:00
|
|
|
virtual void SetLabelImpl();
|
2018-05-17 21:09:07 +00:00
|
|
|
|
2021-03-30 10:21:36 +00:00
|
|
|
virtual MaybeError TickImpl() = 0;
|
2021-07-21 08:59:09 +00:00
|
|
|
void FlushCallbackTaskQueue();
|
2021-03-30 10:21:36 +00:00
|
|
|
|
2020-07-01 13:09:46 +00:00
|
|
|
ResultOrError<Ref<BindGroupLayoutBase>> CreateEmptyBindGroupLayout();
|
|
|
|
|
2021-10-13 00:43:05 +00:00
|
|
|
Ref<ComputePipelineBase> GetCachedComputePipeline(
|
|
|
|
ComputePipelineBase* uninitializedComputePipeline);
|
2021-09-29 00:49:01 +00:00
|
|
|
Ref<RenderPipelineBase> GetCachedRenderPipeline(
|
|
|
|
RenderPipelineBase* uninitializedRenderPipeline);
|
2021-08-26 00:39:14 +00:00
|
|
|
Ref<ComputePipelineBase> AddOrGetCachedComputePipeline(
|
2021-10-13 00:43:05 +00:00
|
|
|
Ref<ComputePipelineBase> computePipeline);
|
2021-09-29 00:49:01 +00:00
|
|
|
Ref<RenderPipelineBase> AddOrGetCachedRenderPipeline(
|
|
|
|
Ref<RenderPipelineBase> renderPipeline);
|
2021-10-13 00:43:05 +00:00
|
|
|
virtual void InitializeComputePipelineAsyncImpl(
|
|
|
|
Ref<ComputePipelineBase> computePipeline,
|
|
|
|
WGPUCreateComputePipelineAsyncCallback callback,
|
|
|
|
void* userdata);
|
2021-09-29 00:49:01 +00:00
|
|
|
virtual void InitializeRenderPipelineAsyncImpl(
|
|
|
|
Ref<RenderPipelineBase> renderPipeline,
|
|
|
|
WGPUCreateRenderPipelineAsyncCallback callback,
|
|
|
|
void* userdata);
|
2021-04-08 01:22:22 +00:00
|
|
|
|
2021-12-22 19:02:23 +00:00
|
|
|
void ApplyToggleOverrides(const DawnTogglesDeviceDescriptor* togglesDescriptor);
|
|
|
|
void ApplyFeatures(const DeviceDescriptor* deviceDescriptor);
|
2019-08-02 00:06:38 +00:00
|
|
|
|
2019-06-11 18:11:05 +00:00
|
|
|
void SetDefaultToggles();
|
2018-07-16 15:40:08 +00:00
|
|
|
|
2020-01-10 17:58:28 +00:00
|
|
|
void ConsumeError(std::unique_ptr<ErrorData> error);
|
2019-09-18 21:03:41 +00:00
|
|
|
|
2020-05-07 21:52:54 +00:00
|
|
|
// Each backend should implement to check their passed fences if there are any and return a
|
|
|
|
// completed serial. Return 0 should indicate no fences to check.
|
2021-04-07 18:09:21 +00:00
|
|
|
virtual ResultOrError<ExecutionSerial> CheckAndUpdateCompletedSerials() = 0;
|
2020-06-04 02:26:46 +00:00
|
|
|
// During shut down of device, some operations might have been started since the last submit
|
|
|
|
// and waiting on a serial that doesn't have a corresponding fence enqueued. Fake serials to
|
|
|
|
// make all commands look completed.
|
|
|
|
void AssumeCommandsComplete();
|
2020-10-15 16:21:03 +00:00
|
|
|
bool IsDeviceIdle();
|
|
|
|
|
2020-05-07 21:52:54 +00:00
|
|
|
// mCompletedSerial tracks the last completed command serial that the fence has returned.
|
|
|
|
// mLastSubmittedSerial tracks the last submitted command serial.
|
|
|
|
// During device removal, the serials could be artificially incremented
|
|
|
|
// to make it appear as if commands have been compeleted. They can also be artificially
|
|
|
|
// incremented when no work is being done in the GPU so CPU operations don't have to wait on
|
|
|
|
// stale serials.
|
2020-10-15 16:21:03 +00:00
|
|
|
// mFutureSerial tracks the largest serial we need to tick to for asynchronous commands or
|
|
|
|
// callbacks to fire
|
2020-09-28 19:35:14 +00:00
|
|
|
ExecutionSerial mCompletedSerial = ExecutionSerial(0);
|
|
|
|
ExecutionSerial mLastSubmittedSerial = ExecutionSerial(0);
|
2020-10-15 16:21:03 +00:00
|
|
|
ExecutionSerial mFutureSerial = ExecutionSerial(0);
|
2020-05-07 21:52:54 +00:00
|
|
|
|
2021-10-12 17:46:26 +00:00
|
|
|
// DestroyImpl is used to clean up and release resources used by device, does not wait for
|
2020-04-07 16:19:47 +00:00
|
|
|
// GPU or check errors.
|
2021-10-12 17:46:26 +00:00
|
|
|
virtual void DestroyImpl() = 0;
|
2019-12-16 23:36:16 +00:00
|
|
|
|
|
|
|
// WaitForIdleForDestruction waits for GPU to finish, checks errors and gets ready for
|
|
|
|
// destruction. This is only used when properly destructing the device. For a real
|
|
|
|
// device loss, this function doesn't need to be called since the driver already closed all
|
|
|
|
// resources.
|
|
|
|
virtual MaybeError WaitForIdleForDestruction() = 0;
|
|
|
|
|
2021-02-19 18:17:22 +00:00
|
|
|
wgpu::ErrorCallback mUncapturedErrorCallback = nullptr;
|
|
|
|
void* mUncapturedErrorUserdata = nullptr;
|
|
|
|
|
Add the user-visible logging interface.
Details:
- Add the logging level type WGPULoggingType, including levels verbose,
info, warning, and error,
- Add the API SetLoggingCallback, which bind the callback to deal with
logging string,
- Add the return command DeviceLoggingCallback and related code,
- Add DeviceBase::EmitLog(WGPULoggingType, const char*) , and
DeviceBase::EmitLog(const char*) use WGPULoggingType_info as default,
to post logging from native or server device to bound callback
via CallbackTaskManager.
BUG: dawn:792
Change-Id: I107b9134ff8567a46fa452509799e10b6862b8d3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/52200
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
2021-06-04 07:10:56 +00:00
|
|
|
wgpu::LoggingCallback mLoggingCallback = nullptr;
|
|
|
|
void* mLoggingUserdata = nullptr;
|
|
|
|
|
2019-12-18 18:59:20 +00:00
|
|
|
wgpu::DeviceLostCallback mDeviceLostCallback = nullptr;
|
2020-04-07 16:19:47 +00:00
|
|
|
void* mDeviceLostUserdata = nullptr;
|
2019-12-18 18:59:20 +00:00
|
|
|
|
2021-02-19 18:17:22 +00:00
|
|
|
std::unique_ptr<ErrorScopeStack> mErrorScopeStack;
|
|
|
|
|
2021-01-13 17:54:37 +00:00
|
|
|
// The Device keeps a ref to the Instance so that any live Device keeps the Instance alive.
|
|
|
|
// The Instance shouldn't need to ref child objects so this shouldn't introduce ref cycles.
|
|
|
|
// The Device keeps a simple pointer to the Adapter because the Adapter is owned by the
|
|
|
|
// Instance.
|
|
|
|
Ref<InstanceBase> mInstance;
|
2019-01-10 10:50:54 +00:00
|
|
|
AdapterBase* mAdapter = nullptr;
|
|
|
|
|
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
|
|
|
|
2020-06-29 11:13:43 +00:00
|
|
|
Ref<BindGroupLayoutBase> mEmptyBindGroupLayout;
|
|
|
|
|
2020-04-07 16:19:47 +00:00
|
|
|
std::unique_ptr<DynamicUploader> mDynamicUploader;
|
2021-06-04 05:12:06 +00:00
|
|
|
std::unique_ptr<AsyncTaskManager> mAsyncTaskManager;
|
2021-02-04 15:33:42 +00:00
|
|
|
Ref<QueueBase> mQueue;
|
2020-04-17 16:45:17 +00:00
|
|
|
|
|
|
|
struct DeprecationWarnings;
|
|
|
|
std::unique_ptr<DeprecationWarnings> mDeprecationWarnings;
|
2018-12-03 16:57:34 +00:00
|
|
|
|
2020-04-07 16:19:47 +00:00
|
|
|
State mState = State::BeingCreated;
|
2019-04-26 07:52:57 +00:00
|
|
|
|
2021-09-28 15:40:01 +00:00
|
|
|
// Encompasses the mutex and the actual list that contains all live objects "owned" by the
|
|
|
|
// device.
|
|
|
|
struct ApiObjectList {
|
|
|
|
std::mutex mutex;
|
|
|
|
LinkedList<ApiObjectBase> objects;
|
|
|
|
};
|
|
|
|
PerObjectType<ApiObjectList> mObjectLists;
|
|
|
|
|
2019-07-18 09:25:04 +00:00
|
|
|
FormatTable mFormatTable;
|
|
|
|
|
2020-04-06 08:32:01 +00:00
|
|
|
TogglesSet mEnabledToggles;
|
2020-04-06 16:55:22 +00:00
|
|
|
TogglesSet mOverridenToggles;
|
2019-07-26 17:54:48 +00:00
|
|
|
size_t mLazyClearCountForTesting = 0;
|
2021-09-01 22:15:41 +00:00
|
|
|
std::atomic_uint64_t mNextPipelineCompatibilityToken;
|
2019-08-02 00:06:38 +00:00
|
|
|
|
2021-09-13 18:49:09 +00:00
|
|
|
CombinedLimits mLimits;
|
2021-10-04 11:30:02 +00:00
|
|
|
FeaturesSet mEnabledFeatures;
|
2020-11-04 02:30:16 +00:00
|
|
|
|
|
|
|
std::unique_ptr<InternalPipelineStore> mInternalPipelineStore;
|
2020-11-20 20:38:37 +00:00
|
|
|
|
|
|
|
std::unique_ptr<PersistentCache> mPersistentCache;
|
2021-06-04 05:12:06 +00:00
|
|
|
|
|
|
|
std::unique_ptr<CallbackTaskManager> mCallbackTaskManager;
|
2022-01-11 02:10:53 +00:00
|
|
|
std::unique_ptr<dawn::platform::WorkerTaskPool> mWorkerTaskPool;
|
2021-09-23 21:26:33 +00:00
|
|
|
std::string mLabel;
|
2017-05-31 00:03:44 +00:00
|
|
|
};
|
|
|
|
|
2022-01-12 09:17:35 +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_
|