#ifndef GPU_CONFIG_GPU_CONTROL_LIST_H_
#define GPU_CONFIG_GPU_CONTROL_LIST_H_
#include <stddef.h>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#include "base/containers/span.h"
#include "base/memory/raw_ptr_exclusion.h"
#include "base/memory/raw_span.h"
#include "base/values.h"
#include "gpu/config/gpu_config_export.h"
#include "gpu/config/gpu_info.h"
namespace gpu {
struct GPUInfo;
class GPU_CONFIG_EXPORT GpuControlList {
public:
typedef std::unordered_map<int, std::string> FeatureMap;
enum OsType {
kOsLinux,
kOsMacosx,
kOsWin,
kOsChromeOS,
kOsAndroid,
kOsFuchsia,
kOsIOS,
kOsOHOS,
kOsAny
};
enum OsFilter {
kCurrentOsOnly,
kAllOs
};
enum NumericOp {
kBetween,
kEQ,
kLT,
kLE,
kGT,
kGE,
kAny,
kUnknown
};
enum MultiGpuStyle {
kMultiGpuStyleOptimus,
kMultiGpuStyleAMDSwitchable,
kMultiGpuStyleAMDSwitchableIntegrated,
kMultiGpuStyleAMDSwitchableDiscrete,
kMultiGpuStyleNone
};
enum MultiGpuCategory {
kMultiGpuCategoryPrimary,
kMultiGpuCategorySecondary,
kMultiGpuCategoryNpu,
kMultiGpuCategoryActive,
kMultiGpuCategoryAny,
kMultiGpuCategoryNone
};
enum GLType {
kGLTypeGLES,
kGLTypeANGLE_GL,
kGLTypeANGLE_GLES,
kGLTypeANGLE_VULKAN,
kGLTypeNone
};
enum VersionStyle {
kVersionStyleNumerical,
kVersionStyleLexical,
kVersionStyleUnknown
};
enum VersionSchema {
kVersionSchemaCommon,
kVersionSchemaIntelDriver,
kVersionSchemaNvidiaDriver,
};
enum SupportedOrNot {
kSupported,
kUnsupported,
kDontCare,
};
struct GPU_CONFIG_EXPORT Version {
NumericOp op;
VersionStyle style;
VersionSchema schema;
const char* value1;
const char* value2;
bool IsSpecified() const { return op != kUnknown; }
bool Contains(const std::string& version_string, char splitter) const;
bool Contains(const std::string& version_string) const {
return Contains(version_string, '.');
}
static int Compare(const std::vector<std::string>& version,
const std::vector<std::string>& version_ref,
VersionStyle version_style);
};
struct GPU_CONFIG_EXPORT DriverInfo {
const char* driver_vendor;
Version driver_version;
bool Contains(const std::vector<GPUInfo::GPUDevice>& gpus) const;
};
struct GPU_CONFIG_EXPORT GLStrings {
const char* gl_vendor;
const char* gl_renderer;
const char* gl_extensions;
const char* gl_version;
bool Contains(const GPUInfo& gpu_info) const;
};
struct GPU_CONFIG_EXPORT MachineModelInfo {
base::raw_span<const char* const> machine_model_names;
Version machine_model_version;
bool Contains(const GPUInfo& gpu_info) const;
};
struct GPU_CONFIG_EXPORT More {
GLType gl_type;
Version gl_version;
Version pixel_shader_version;
Version d3d11_feature_level;
bool in_process_gpu;
uint32_t gl_reset_notification_strategy;
Version direct_rendering_version;
Version gpu_count;
SupportedOrNot hardware_overlay;
uint32_t test_group;
SupportedOrNot subpixel_font_rendering;
bool GLVersionInfoMismatch(const std::string& gl_version_string) const;
bool Contains(const GPUInfo& gpu_info) const;
};
struct GPU_CONFIG_EXPORT Device {
uint32_t device_id;
uint32_t revision = 0u;
};
struct GPU_CONFIG_EXPORT IntelConditions {
base::raw_span<const IntelGpuSeriesType> intel_gpu_series_list;
Version intel_gpu_generation;
bool Contains(const std::vector<GPUInfo::GPUDevice>& candidates,
const GPUInfo& gpu_info) const;
};
struct GPU_CONFIG_EXPORT Conditions {
OsType os_type;
Version os_version;
uint32_t vendor_id;
RAW_PTR_EXCLUSION base::span<const Device> devices;
MultiGpuCategory multi_gpu_category;
MultiGpuStyle multi_gpu_style;
RAW_PTR_EXCLUSION const DriverInfo* driver_info;
RAW_PTR_EXCLUSION const GLStrings* gl_strings;
RAW_PTR_EXCLUSION const MachineModelInfo* machine_model_info;
RAW_PTR_EXCLUSION const IntelConditions* intel_conditions;
RAW_PTR_EXCLUSION const More* more;
Conditions(OsType os_type,
Version os_version,
uint32_t vendor_id,
base::span<const Device> devices,
MultiGpuCategory multi_gpu_category,
MultiGpuStyle multi_gpu_style,
const DriverInfo* driver_info,
const GLStrings* gl_strings,
const MachineModelInfo* machine_model_info,
const IntelConditions* intel_conditions,
const More* more);
Conditions(const Conditions& other);
bool Contains(OsType os_type,
const std::string& os_version,
const GPUInfo& gpu_info) const;
bool NeedsMoreInfo(const GPUInfo& gpu_info) const;
};
struct GPU_CONFIG_EXPORT Entry {
uint32_t id;
const char* description;
RAW_PTR_EXCLUSION base::span<const int> features;
RAW_PTR_EXCLUSION base::span<const char* const> disabled_extensions;
RAW_PTR_EXCLUSION base::span<const char* const> disabled_webgl_extensions;
RAW_PTR_EXCLUSION base::span<const uint32_t> cr_bugs;
Conditions conditions;
RAW_PTR_EXCLUSION base::span<const Conditions> exceptions;
bool Contains(OsType os_type,
const std::string& os_version,
const GPUInfo& gpu_info) const;
bool AppliesToTestGroup(uint32_t target_test_group) const;
bool NeedsMoreInfo(const GPUInfo& gpu_info, bool consider_exceptions) const;
base::Value::List GetFeatureNames(const FeatureMap& feature_map) const;
void LogControlListMatch(
const std::string& control_list_logging_name) const;
};
explicit GpuControlList(base::span<const GpuControlList::Entry> data);
virtual ~GpuControlList();
std::set<int32_t> MakeDecision(OsType os,
const std::string& os_version,
const GPUInfo& gpu_info);
std::set<int32_t> MakeDecision(OsType os,
const std::string& os_version,
const GPUInfo& gpu_info,
uint32_t target_test_group);
const std::vector<uint32_t>& GetActiveEntries() const;
std::vector<uint32_t> GetEntryIDsFromIndices(
const std::vector<uint32_t>& entry_indices) const;
std::vector<std::string> GetDisabledExtensions();
std::vector<std::string> GetDisabledWebGLExtensions();
void GetReasons(base::Value::List& problem_list,
const std::string& tag,
const std::vector<uint32_t>& entries) const;
uint32_t max_entry_id() const;
bool needs_more_info() const { return needs_more_info_; }
size_t num_entries() const;
void AddSupportedFeature(const std::string& feature_name, int feature_id);
void EnableControlListLogging(const std::string& control_list_logging_name) {
control_list_logging_enabled_ = true;
control_list_logging_name_ = control_list_logging_name;
}
protected:
static bool AreEntryIndicesValid(const std::vector<uint32_t>& entry_indices,
size_t total_entries);
private:
static GLType ProcessANGLEGLRenderer(const std::string& gl_renderer,
std::string* vendor = nullptr,
std::string* renderer = nullptr,
std::string* version = nullptr);
friend class GpuControlListEntryTest;
friend class VersionInfoTest;
friend class GpuControlListTest;
static OsType GetOsType();
base::raw_span<const Entry> entries_;
std::vector<uint32_t> active_entries_;
uint32_t max_entry_id_ = 0;
bool needs_more_info_ = false;
FeatureMap feature_map_;
bool control_list_logging_enabled_ = false;
std::string control_list_logging_name_;
};
}
#endif