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);
65 std::sort(adapters.begin(),
67 [](dawn::native::Adapter
a, dawn::native::Adapter
b) {
68 wgpu::AdapterProperties propA;
69 wgpu::AdapterProperties propB;
70 a.GetProperties(&propA);
71 b.GetProperties(&propB);
72 return std::tuple(propA.adapterType, propA.backendType) <
73 std::tuple(propB.adapterType, propB.backendType);
76 for (
const auto& adapter : adapters) {
77 wgpu::AdapterProperties props;
78 adapter.GetProperties(&props);
79 if (
backend == props.backendType) {
80 matchedAdaptor = adapter;
85 if (!matchedAdaptor) {
90 wgpu::AdapterProperties properties;
91 sAdapter.GetProperties(&properties);
92 SkDebugf(
"GPU: %s\nDriver: %s\n", properties.name, properties.driverDescription);
95 std::vector<wgpu::FeatureName> features;
96 wgpu::Adapter adapter = matchedAdaptor.Get();
97 if (adapter.HasFeature(wgpu::FeatureName::MSAARenderToSingleSampled)) {
98 features.push_back(wgpu::FeatureName::MSAARenderToSingleSampled);
100 if (adapter.HasFeature(wgpu::FeatureName::TransientAttachments)) {
101 features.push_back(wgpu::FeatureName::TransientAttachments);
103 if (adapter.HasFeature(wgpu::FeatureName::Unorm16TextureFormats)) {
104 features.push_back(wgpu::FeatureName::Unorm16TextureFormats);
106 if (adapter.HasFeature(wgpu::FeatureName::DualSourceBlending)) {
107 features.push_back(wgpu::FeatureName::DualSourceBlending);
109 if (adapter.HasFeature(wgpu::FeatureName::FramebufferFetch)) {
110 features.push_back(wgpu::FeatureName::FramebufferFetch);
112 if (adapter.HasFeature(wgpu::FeatureName::BufferMapExtendedUsages)) {
113 features.push_back(wgpu::FeatureName::BufferMapExtendedUsages);
115 if (adapter.HasFeature(wgpu::FeatureName::TextureCompressionETC2)) {
116 features.push_back(wgpu::FeatureName::TextureCompressionETC2);
118 if (adapter.HasFeature(wgpu::FeatureName::TextureCompressionBC)) {
119 features.push_back(wgpu::FeatureName::TextureCompressionBC);
121 if (adapter.HasFeature(wgpu::FeatureName::R8UnormStorage)) {
122 features.push_back(wgpu::FeatureName::R8UnormStorage);
125 wgpu::DeviceDescriptor desc;
126 desc.requiredFeatureCount = features.size();
127 desc.requiredFeatures = features.data();
128 desc.nextInChain = &togglesDesc;
130 wgpu::Device
device = wgpu::Device::Acquire(matchedAdaptor.CreateDevice(&desc));
132 device.SetUncapturedErrorCallback(
133 [](WGPUErrorType
type,
const char*
message,
void*) {
137 device.SetDeviceLostCallback(
138 [](WGPUDeviceLostReason reason,
const char*
message,
void*) {
139 if (reason != WGPUDeviceLostReason_Destroyed) {
146 backendContext.
fInstance = wgpu::Instance(sInstance->Get());
149 return std::unique_ptr<GraphiteTestContext>(
new DawnTestContext(backendContext));
153 wgpu::AdapterProperties props;
155 switch (props.backendType) {
156 case wgpu::BackendType::D3D11:
157 return skgpu::ContextType::kDawn_D3D11;
159 case wgpu::BackendType::D3D12:
160 return skgpu::ContextType::kDawn_D3D12;
162 case wgpu::BackendType::Metal:
163 return skgpu::ContextType::kDawn_Metal;
165 case wgpu::BackendType::Vulkan:
166 return skgpu::ContextType::kDawn_Vulkan;
168 case wgpu::BackendType::OpenGL:
169 return skgpu::ContextType::kDawn_OpenGL;
171 case wgpu::BackendType::OpenGLES:
172 return skgpu::ContextType::kDawn_OpenGLES;
174 SK_ABORT(
"unexpected Dawn backend");
175 return skgpu::ContextType::kMock;
static std::unique_ptr< GraphiteTestContext > Make(wgpu::BackendType backend)
std::unique_ptr< skgpu::graphite::Context > makeContext(const TestOptions &) override
SK_API std::unique_ptr< Context > MakeDawn(const DawnBackendContext &, const ContextOptions &)