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

gpu / config / webgpu_blocklist_impl.h [blame]

// Copyright 2023 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_CONFIG_WEBGPU_BLOCKLIST_IMPL_H_
#define GPU_CONFIG_WEBGPU_BLOCKLIST_IMPL_H_

#include <cstdint>
#include <string>

namespace wgpu {
class Adapter;
struct AdapterInfo;
}

// Bitmask of blocklist reasons.
enum class WebGPUBlocklistReason : uint64_t {
  None = 0,
  StringPattern = 1,
  DynamicArrayIndexInStruct = 1 << 1,
  IndirectComputeRootConstants = 1 << 2,
  WindowsARM = 1 << 3,
  AndroidGLES = 1 << 4,
  AndroidLimitedSupport = 1 << 5,
  AMDMissingDrmFormatModifier = 1 << 6,
  CPUAdapter = 1 << 7,
  D3D11 = 1 << 8,
  Consteval22ndBit = 1 << 9,
  // When adding an enum, update kKnownReasons with a description.
};

inline constexpr WebGPUBlocklistReason operator|(WebGPUBlocklistReason l,
                                                 WebGPUBlocklistReason r) {
  return static_cast<WebGPUBlocklistReason>(uint64_t(l) | uint64_t(r));
}

inline constexpr WebGPUBlocklistReason operator&(WebGPUBlocklistReason l,
                                                 WebGPUBlocklistReason r) {
  return static_cast<WebGPUBlocklistReason>(uint64_t(l) & uint64_t(r));
}

inline constexpr WebGPUBlocklistReason operator~(WebGPUBlocklistReason v) {
  return static_cast<WebGPUBlocklistReason>(~uint64_t(v));
}

inline constexpr WebGPUBlocklistReason operator&=(WebGPUBlocklistReason& l,
                                                  WebGPUBlocklistReason r) {
  l = static_cast<WebGPUBlocklistReason>(uint64_t(l) & uint64_t(r));
  return static_cast<WebGPUBlocklistReason>(uint64_t(l));
}

namespace gpu {

struct WebGPUBlocklistResultImpl {
  bool blocked;
  std::string reason;
};

struct WebGPUBlocklistOptions {
  std::string_view blocklist_string = "";
  WebGPUBlocklistReason ignores = WebGPUBlocklistReason::None;
};

namespace detail {
WebGPUBlocklistReason GetWebGPUAdapterBlocklistReason(
    const wgpu::AdapterInfo& info,
    const WebGPUBlocklistOptions& options);
}  // namespace detail

WebGPUBlocklistResultImpl IsWebGPUAdapterBlocklisted(
    const wgpu::Adapter& adapter,
    WebGPUBlocklistOptions options = {});

}  // namespace gpu

#endif  // GPU_CONFIG_WEBGPU_BLOCKLIST_IMPL_H_