File: dawn_context_provider.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (113 lines) | stat: -rw-r--r-- 4,054 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef GPU_COMMAND_BUFFER_SERVICE_DAWN_CONTEXT_PROVIDER_H_
#define GPU_COMMAND_BUFFER_SERVICE_DAWN_CONTEXT_PROVIDER_H_

#include <dawn/platform/DawnPlatform.h>

#include <memory>
#include <optional>

#include "base/functional/function_ref.h"
#include "base/memory/raw_ptr.h"
#include "build/build_config.h"
#include "gpu/command_buffer/common/constants.h"
#include "gpu/command_buffer/service/dawn_caching_interface.h"
#include "gpu/command_buffer/service/graphite_shared_context.h"
#include "gpu/config/gpu_driver_bug_workarounds.h"
#include "gpu/config/gpu_preferences.h"
#include "gpu/gpu_gles2_export.h"
#include "third_party/dawn/include/dawn/native/DawnNative.h"
#include "third_party/skia/include/gpu/graphite/ContextOptions.h"
#include "third_party/skia/include/gpu/graphite/dawn/DawnTypes.h"

#if BUILDFLAG(IS_WIN)
#include <d3d11.h>
#include <wrl/client.h>
#endif

namespace gpu {

class DawnSharedContext;
class GpuProcessShmCount;

class GPU_GLES2_EXPORT DawnContextProvider {
 public:
  using ValidateAdapterFn =
      base::FunctionRef<bool(wgpu::BackendType, wgpu::Adapter)>;

  // `validate_adapter_fn` will be called after the wgpu::Adapter is available
  // to check if it should be used. If the function returns false creation will
  // fail.
  static std::unique_ptr<DawnContextProvider> Create(
      const GpuPreferences& gpu_preferences,
      ValidateAdapterFn validate_adapter_fn = DefaultValidateAdapterFn,
      const GpuDriverBugWorkarounds& gpu_driver_workarounds =
          GpuDriverBugWorkarounds());
  static std::unique_ptr<DawnContextProvider> CreateWithBackend(
      wgpu::BackendType backend_type,
      bool force_fallback_adapter,
      const GpuPreferences& gpu_preferences,
      ValidateAdapterFn validate_adapter_fn = DefaultValidateAdapterFn,
      const GpuDriverBugWorkarounds& gpu_driver_workarounds =
          GpuDriverBugWorkarounds());

  // Creates a new context provider for use on a different thread that shares
  // the wgpu::Device/Adapter/Instance with `existing`.
  static std::unique_ptr<DawnContextProvider> CreateWithSharedDevice(
      const DawnContextProvider* existing);

  static wgpu::BackendType GetDefaultBackendType();
  static bool DefaultForceFallbackAdapter();

  // Default function that will say adapter is supported.
  static bool DefaultValidateAdapterFn(wgpu::BackendType, wgpu::Adapter);

  DawnContextProvider(const DawnContextProvider&) = delete;
  DawnContextProvider& operator=(const DawnContextProvider&) = delete;
  ~DawnContextProvider();

  wgpu::Device GetDevice() const;
  wgpu::BackendType backend_type() const;
  bool is_vulkan_swiftshader_adapter() const;
  wgpu::Adapter GetAdapter() const;
  wgpu::Instance GetInstance() const;

  // Sets the caching interface. This must be called before graphite context
  // is created and before device is shared with any other threads.
  void SetCachingInterface(
      std::unique_ptr<webgpu::DawnCachingInterface> caching_interface);

  bool use_thread_safe_shared_context() const;

  void InitializeThreadSafeGraphiteContext(
      const skgpu::graphite::ContextOptions& options,
      GpuProcessShmCount* use_shader_cache_shm_count);

  bool InitializeGraphiteContext(
      const skgpu::graphite::ContextOptions& options,
      GpuProcessShmCount* use_shader_cache_shm_count);

  GraphiteSharedContext* GetGraphiteSharedContext() const;

#if BUILDFLAG(IS_WIN)
  Microsoft::WRL::ComPtr<ID3D11Device> GetD3D11Device() const;
#endif

  bool SupportsFeature(wgpu::FeatureName feature);

  std::optional<error::ContextLostReason> GetResetStatus() const;

 private:
  explicit DawnContextProvider(
      scoped_refptr<DawnSharedContext> dawn_shared_context);

  scoped_refptr<DawnSharedContext> dawn_shared_context_;
  std::unique_ptr<gpu::GraphiteSharedContext> graphite_shared_context_;
};

}  // namespace gpu

#endif  // GPU_COMMAND_BUFFER_SERVICE_DAWN_CONTEXT_PROVIDER_H_