File: gpu_adapter.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (104 lines) | stat: -rw-r--r-- 3,872 bytes parent folder | download | duplicates (5)
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
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGPU_GPU_ADAPTER_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGPU_GPU_ADAPTER_H_

#include "base/memory/scoped_refptr.h"
#include "gpu/command_buffer/client/webgpu_interface.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/modules/webgpu/dawn_object.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"

namespace blink {

class GPU;
class GPUAdapterInfo;
class GPUDevice;
class GPUDeviceDescriptor;
class GPURequestAdapterOptions;
class GPUSupportedFeatures;
class GPUSupportedLimits;

class GPUAdapter final : public ScriptWrappable, DawnObject<wgpu::Adapter> {
  DEFINE_WRAPPERTYPEINFO();

 public:
  GPUAdapter(GPU* gpu,
             wgpu::Adapter handle,
             scoped_refptr<DawnControlClientHolder> dawn_control_client,
             const GPURequestAdapterOptions* options);

  GPUAdapter(const GPUAdapter&) = delete;
  GPUAdapter& operator=(const GPUAdapter&) = delete;

  void Trace(Visitor* visitor) const override;

  GPU* gpu() const { return gpu_.Get(); }
  GPUSupportedFeatures* features() const;
  GPUSupportedLimits* limits() const { return limits_.Get(); }
  GPUAdapterInfo* info() const;
  bool isFallbackAdapter() const;
  wgpu::BackendType backendType() const;
  bool SupportsMultiPlanarFormats() const;

  ScriptPromise<GPUDevice> requestDevice(ScriptState* script_state,
                                         GPUDeviceDescriptor* descriptor);

  // Console warnings should generally be attributed to a GPUDevice, but in
  // cases where there is no device warnings can be surfaced here. It's expected
  // that very few warning will need to be shown for a given adapter, and as a
  // result the maximum allowed warnings is lower than the per-device count.
  void AddConsoleWarning(ExecutionContext* execution_context,
                         const char* message);

  GPUAdapterInfo* CreateAdapterInfoForAdapter();

  bool IsXRCompatible() const { return is_xr_compatible_; }

 private:
  void OnRequestDeviceCallback(GPUDevice* device,
                               const GPUDeviceDescriptor* descriptor,
                               ScriptPromiseResolver<GPUDevice>* resolver,
                               wgpu::RequestDeviceStatus status,
                               wgpu::Device dawn_device,
                               wgpu::StringView error_message);

  void SetLabelImpl(const String&) override {
    // There isn't a wgpu::Adapter::SetLabel, just skip.
  }

  Member<GPU> gpu_;
  bool is_fallback_adapter_;
  wgpu::BackendType backend_type_;
  wgpu::AdapterType adapter_type_;
  bool is_consumed_ = false;
  bool is_xr_compatible_ = false;
  Member<GPUSupportedLimits> limits_;
  Member<GPUSupportedFeatures> features_;
  Member<GPUAdapterInfo> info_;

  String vendor_;
  String architecture_;
  String device_;
  String description_;
  uint32_t subgroup_min_size_;
  uint32_t subgroup_max_size_;
  String driver_;
  std::optional<uint32_t> d3d_shader_model_;
  std::optional<uint32_t> vk_driver_version_;
  wgpu::PowerPreference power_preference_;
  wgpu::AdapterPropertiesMemoryHeaps memory_heaps_ = {};
  wgpu::AdapterPropertiesSubgroupMatrixConfigs subgroup_matrix_configs_ = {};

  static constexpr int kMaxAllowedConsoleWarnings = 50;
  int allowed_console_warnings_remaining_ = kMaxAllowedConsoleWarnings;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGPU_GPU_ADAPTER_H_