// 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.

module webnn.mojom.features;

// Enables the Web Machine Learning Neural Network API. Explainer:
// https://github.com/webmachinelearning/webnn/blob/main/explainer.md
// Note: This feature is unsafe and not currently accepting security reports.
feature kWebMachineLearningNeuralNetwork {
  const string name = "WebMachineLearningNeuralNetwork";
  const bool default_state = false;
};

// Enables experimental Web Machine Learning Neural Network API features.
// Note: This feature is unsafe and not currently accepting security reports.
feature kExperimentalWebMachineLearningNeuralNetwork {
  const string name = "ExperimentalWebMachineLearningNeuralNetwork";
  const bool default_state = false;
};

// Enables the Core ML backend for WebNN.
[EnableIf=is_apple]
feature kWebNNCoreML {
  const string name = "WebNNCoreML";

  // macOS default state is enabled.
  [EnableIf=is_mac]
  const bool default_state = true;

  // iOS default state is disabled since there are sandbox issues
  // with using CoreML in the GPU process, we are waiting to hear back
  // from Apple. https://crbug.com/417496826
  [EnableIf=is_ios]
  const bool default_state = false;
};

// Passes MLComputeUnitsCPUAndGPU or MLComputeUnitsCPUAndNPU to Core ML instead
// of MLComputeUnitsAll when the "gpu" or "npu" device types are passed.
[EnableIf=is_apple]
feature kWebNNCoreMLExplicitGPUOrNPU {
  const string name = "WebNNCoreMLExplicitGPUOrNPU";
  // Disabled by default due to https://crbug.com/344935458.
  const bool default_state = false;
};

// Enables the ONNX Runtime backend for WebNN.
[EnableIf=is_win]
feature kWebNNOnnxRuntime {
  const string name = "WebNNOnnxRuntime";
  const bool default_state = true;
};


// Enables offloading graph construction/compilation to an out-of-process
// WebNN Compiler process, isolated from the GPU process. When disabled,
// graph construction runs in the GPU process as before.
[EnableIf=is_win|is_apple]
feature kWebNNCompilerProcess {
  const string name = "WebNNCompilerProcess";
  const bool default_state = false;
};
