19#include "dawn/dawn_proc.h"
34 static std::unique_ptr<dawn::native::Instance> sInstance;
37 static constexpr const char* kToggles[] = {
39 "use_user_defined_labels_in_backend",
41 wgpu::DawnTogglesDescriptor togglesDesc;
42 togglesDesc.enabledToggleCount =
std::size(kToggles);
43 togglesDesc.enabledToggles = kToggles;
49 DawnProcTable backendProcs = dawn::native::GetProcs();
50 dawnProcSetProcs(&backendProcs);
51 WGPUInstanceDescriptor
desc{};
53 desc.features.timedWaitAnyEnable =
true;
54 sInstance = std::make_unique<dawn::native::Instance>(&
desc);
57 dawn::native::Adapter matchedAdaptor;
59 wgpu::RequestAdapterOptions
options;
60 options.nextInChain = &togglesDesc;
61 std::vector<dawn::native::Adapter> adapters = sInstance->EnumerateAdapters(&
options);
66 adapters.begin(), adapters.end(), [](dawn::native::Adapter
a, dawn::native::Adapter
b) {
67 wgpu::AdapterInfo infoA;
68 wgpu::AdapterInfo infoB;
71 return std::tuple(infoA.adapterType, infoA.backendType) <
72 std::tuple(infoB.adapterType, infoB.backendType);
75 for (
const auto& adapter : adapters) {
76 wgpu::AdapterInfo props;
77 adapter.GetInfo(&props);
78 if (
backend == props.backendType) {
79 matchedAdaptor = adapter;
84 if (!matchedAdaptor) {
89 wgpu::AdapterInfo
info;
90 sAdapter.GetInfo(&
info);
94 std::vector<wgpu::FeatureName> features;
95 wgpu::Adapter adapter = matchedAdaptor.Get();
96 if (adapter.HasFeature(wgpu::FeatureName::MSAARenderToSingleSampled)) {
97 features.push_back(wgpu::FeatureName::MSAARenderToSingleSampled);
99 if (adapter.HasFeature(wgpu::FeatureName::TransientAttachments)) {
100 features.push_back(wgpu::FeatureName::TransientAttachments);
102 if (adapter.HasFeature(wgpu::FeatureName::Unorm16TextureFormats)) {
103 features.push_back(wgpu::FeatureName::Unorm16TextureFormats);
105 if (adapter.HasFeature(wgpu::FeatureName::DualSourceBlending)) {
106 features.push_back(wgpu::FeatureName::DualSourceBlending);
108 if (adapter.HasFeature(wgpu::FeatureName::FramebufferFetch)) {
109 features.push_back(wgpu::FeatureName::FramebufferFetch);
111 if (adapter.HasFeature(wgpu::FeatureName::BufferMapExtendedUsages)) {
112 features.push_back(wgpu::FeatureName::BufferMapExtendedUsages);
114 if (adapter.HasFeature(wgpu::FeatureName::TextureCompressionETC2)) {
115 features.push_back(wgpu::FeatureName::TextureCompressionETC2);
117 if (adapter.HasFeature(wgpu::FeatureName::TextureCompressionBC)) {
118 features.push_back(wgpu::FeatureName::TextureCompressionBC);
120 if (adapter.HasFeature(wgpu::FeatureName::R8UnormStorage)) {
121 features.push_back(wgpu::FeatureName::R8UnormStorage);
123 if (adapter.HasFeature(wgpu::FeatureName::DawnLoadResolveTexture)) {
124 features.push_back(wgpu::FeatureName::DawnLoadResolveTexture);
127 wgpu::DeviceDescriptor
desc;
128 desc.requiredFeatureCount = features.size();
129 desc.requiredFeatures = features.data();
130 desc.nextInChain = &togglesDesc;
131 desc.deviceLostCallbackInfo.callback =
132 [](WGPUDeviceImpl *
const *, WGPUDeviceLostReason reason,
const char*
message,
void*) {
133 if (reason != WGPUDeviceLostReason_Destroyed) {
138 wgpu::Device
device = wgpu::Device::Acquire(matchedAdaptor.CreateDevice(&
desc));
140 device.SetUncapturedErrorCallback(
141 [](WGPUErrorType
type,
const char*
message,
void*) {
147 backendContext.
fInstance = wgpu::Instance(sInstance->Get());
150 return std::unique_ptr<GraphiteTestContext>(
new DawnTestContext(backendContext));
154 wgpu::AdapterInfo
info;
156 switch (
info.backendType) {
157 case wgpu::BackendType::D3D11:
160 case wgpu::BackendType::D3D12:
163 case wgpu::BackendType::Metal:
166 case wgpu::BackendType::Vulkan:
169 case wgpu::BackendType::OpenGL:
172 case wgpu::BackendType::OpenGLES:
175 SK_ABORT(
"unexpected Dawn backend");
183 if (!
options.fContextOptions.fOptionsPriv) {
184 revisedContextOptions.
fOptionsPriv = &contextOptionsPriv;
190 if (
options.fNeverYieldToWebGPU) {
191 backendContext.
fTick =
nullptr;
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
#define SK_ABORT(message,...)
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static std::vector< SkPDFIndirectReference > sort(const THashSet< SkPDFIndirectReference > &src)
skgpu::graphite::DawnBackendContext fBackendContext
~DawnTestContext() override
static std::unique_ptr< GraphiteTestContext > Make(wgpu::BackendType backend)
skgpu::ContextType contextType() override
skgpu::BackendApi backend() override
DawnTestContext(const skgpu::graphite::DawnBackendContext &backendContext)
std::unique_ptr< skgpu::graphite::Context > makeContext(const TestOptions &) override
DlSurfaceProvider::BackendType BackendType
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
SK_API std::unique_ptr< Context > MakeDawn(const DawnBackendContext &, const ContextOptions &)
@ kDawn_OpenGLES
Dawn on OpenGL.
@ kDawn_Metal
Dawn on Direct3D12.
@ kDawn_D3D12
Dawn on Direct3D11.
@ kDawn_Vulkan
Dawn on Metal.
@ kDawn_OpenGL
Dawn on Vulkan.
@ kDawn_D3D11
Direct3D 12.
@ kMock
Dawn on OpenGL ES.
bool fStoreContextRefInRecorder
ContextOptionsPriv * fOptionsPriv