#ifndef GPU_CONFIG_GPU_INFO_H_
#define GPU_CONFIG_GPU_INFO_H_
#include <stdint.h>
#include <string>
#include <vector>
#include "base/clang_profiling_buildflags.h"
#include "base/containers/flat_map.h"
#include "base/containers/span.h"
#include "base/time/time.h"
#include "base/version.h"
#include "build/build_config.h"
#include "gpu/config/dx_diag_node.h"
#include "gpu/gpu_export.h"
#include "gpu/vulkan/buildflags.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gpu_preference.h"
#if BUILDFLAG(IS_WIN)
#include <dxgi.h>
#include "base/win/windows_types.h"
#endif
#if BUILDFLAG(ENABLE_VULKAN)
#include "gpu/config/vulkan_info.h"
#endif
namespace gpu {
enum class IntelGpuSeriesType {
kUnknown = 0,
kBroadwater = 16,
kEaglelake = 17,
kIronlake = 18,
kSandybridge = 1,
kBaytrail = 2,
kIvybridge = 3,
kHaswell = 4,
kCherrytrail = 5,
kBroadwell = 6,
kApollolake = 7,
kSkylake = 8,
kGeminilake = 9,
kKabylake = 10,
kAmberlake = 23,
kCoffeelake = 11,
kWhiskeylake = 12,
kCometlake = 13,
kCannonlake = 14,
kIcelake = 15,
kElkhartlake = 19,
kJasperlake = 20,
kTigerlake = 21,
kRocketlake = 24,
kDG1 = 25,
kAlderlake = 22,
kAlchemist = 26,
kRaptorlake = 27,
kMaxValue = kRaptorlake,
};
enum VideoCodecProfile {
VIDEO_CODEC_PROFILE_UNKNOWN = -1,
VIDEO_CODEC_PROFILE_MIN = VIDEO_CODEC_PROFILE_UNKNOWN,
H264PROFILE_BASELINE = 0,
H264PROFILE_MAIN,
H264PROFILE_EXTENDED,
H264PROFILE_HIGH,
H264PROFILE_HIGH10PROFILE,
H264PROFILE_HIGH422PROFILE,
H264PROFILE_HIGH444PREDICTIVEPROFILE,
H264PROFILE_SCALABLEBASELINE,
H264PROFILE_SCALABLEHIGH,
H264PROFILE_STEREOHIGH,
H264PROFILE_MULTIVIEWHIGH,
VP8PROFILE_ANY,
VP9PROFILE_PROFILE0,
VP9PROFILE_PROFILE1,
VP9PROFILE_PROFILE2,
VP9PROFILE_PROFILE3,
HEVCPROFILE_MAIN,
HEVCPROFILE_MAIN10,
HEVCPROFILE_MAIN_STILL_PICTURE,
DOLBYVISION_PROFILE0,
DOLBYVISION_PROFILE4,
DOLBYVISION_PROFILE5,
DOLBYVISION_PROFILE7,
THEORAPROFILE_ANY,
AV1PROFILE_PROFILE_MAIN,
AV1PROFILE_PROFILE_HIGH,
AV1PROFILE_PROFILE_PRO,
DOLBYVISION_PROFILE8,
DOLBYVISION_PROFILE9,
HEVCPROFILE_REXT,
HEVCPROFILE_HIGH_THROUGHPUT,
HEVCPROFILE_MULTIVIEW_MAIN,
HEVCPROFILE_SCALABLE_MAIN,
HEVCPROFILE_3D_MAIN,
HEVCPROFILE_SCREEN_EXTENDED,
HEVCPROFILE_SCALABLE_REXT,
HEVCPROFILE_HIGH_THROUGHPUT_SCREEN_EXTENDED,
VIDEO_CODEC_PROFILE_MAX = HEVCPROFILE_HIGH_THROUGHPUT_SCREEN_EXTENDED,
};
struct GPU_EXPORT VideoDecodeAcceleratorSupportedProfile {
VideoCodecProfile profile;
gfx::Size max_resolution;
gfx::Size min_resolution;
bool encrypted_only;
};
using VideoDecodeAcceleratorSupportedProfiles =
std::vector<VideoDecodeAcceleratorSupportedProfile>;
struct GPU_EXPORT VideoDecodeAcceleratorCapabilities {
VideoDecodeAcceleratorCapabilities();
VideoDecodeAcceleratorCapabilities(
const VideoDecodeAcceleratorCapabilities& other);
~VideoDecodeAcceleratorCapabilities();
VideoDecodeAcceleratorSupportedProfiles supported_profiles;
uint32_t flags;
};
struct GPU_EXPORT VideoEncodeAcceleratorSupportedProfile {
VideoCodecProfile profile;
gfx::Size min_resolution;
gfx::Size max_resolution;
uint32_t max_framerate_numerator;
uint32_t max_framerate_denominator;
bool is_software_codec;
};
using VideoEncodeAcceleratorSupportedProfiles =
std::vector<VideoEncodeAcceleratorSupportedProfile>;
enum class ImageDecodeAcceleratorType {
kUnknown = 0,
kJpeg = 1,
#if BUILDFLAG(ENABLE_HEIF_DECODER)
kHeif = 2,
kWebP = 3,
#else
kWebP = 2,
#endif
kMaxValue = kWebP,
};
enum class ImageDecodeAcceleratorSubsampling {
k420 = 0,
k422 = 1,
k444 = 2,
kMaxValue = k444,
};
struct GPU_EXPORT ImageDecodeAcceleratorSupportedProfile {
ImageDecodeAcceleratorSupportedProfile();
ImageDecodeAcceleratorSupportedProfile(
const ImageDecodeAcceleratorSupportedProfile& other);
ImageDecodeAcceleratorSupportedProfile(
ImageDecodeAcceleratorSupportedProfile&& other);
~ImageDecodeAcceleratorSupportedProfile();
ImageDecodeAcceleratorSupportedProfile& operator=(
const ImageDecodeAcceleratorSupportedProfile& other);
ImageDecodeAcceleratorSupportedProfile& operator=(
ImageDecodeAcceleratorSupportedProfile&& other);
ImageDecodeAcceleratorType image_type;
gfx::Size min_encoded_dimensions;
gfx::Size max_encoded_dimensions;
std::vector<ImageDecodeAcceleratorSubsampling> subsamplings;
};
using ImageDecodeAcceleratorSupportedProfiles =
std::vector<ImageDecodeAcceleratorSupportedProfile>;
#if BUILDFLAG(IS_WIN)
enum class OverlaySupport {
kNone = 0,
kDirect = 1,
kScaling = 2,
kSoftware = 3
};
GPU_EXPORT const char* OverlaySupportToString(OverlaySupport support);
struct GPU_EXPORT OverlayInfo {
OverlayInfo() = default;
OverlayInfo(const OverlayInfo& other) = default;
OverlayInfo& operator=(const OverlayInfo& other) = default;
bool operator==(const OverlayInfo& other) const {
return direct_composition == other.direct_composition &&
supports_overlays == other.supports_overlays &&
yuy2_overlay_support == other.yuy2_overlay_support &&
nv12_overlay_support == other.nv12_overlay_support &&
bgra8_overlay_support == other.bgra8_overlay_support &&
rgb10a2_overlay_support == other.rgb10a2_overlay_support;
}
bool operator!=(const OverlayInfo& other) const { return !(*this == other); }
bool direct_composition = false;
bool supports_overlays = false;
OverlaySupport yuy2_overlay_support = OverlaySupport::kNone;
OverlaySupport nv12_overlay_support = OverlaySupport::kNone;
OverlaySupport bgra8_overlay_support = OverlaySupport::kNone;
OverlaySupport rgb10a2_overlay_support = OverlaySupport::kNone;
};
#endif
#if BUILDFLAG(IS_MAC)
GPU_EXPORT bool ValidateMacOSSpecificTextureTarget(int target);
#endif
struct GPU_EXPORT GPUInfo {
struct GPU_EXPORT GPUDevice {
GPUDevice();
GPUDevice(const GPUDevice& other);
GPUDevice(GPUDevice&& other) noexcept;
~GPUDevice() noexcept;
GPUDevice& operator=(const GPUDevice& other);
GPUDevice& operator=(GPUDevice&& other) noexcept;
bool IsSoftwareRenderer() const;
uint32_t vendor_id = 0u;
uint32_t device_id = 0u;
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS)
uint32_t revision = 0u;
#endif
#if BUILDFLAG(IS_WIN)
uint32_t sub_sys_id = 0u;
CHROME_LUID luid;
#endif
uint64_t system_device_id = 0ULL;
bool active = false;
std::string vendor_string;
std::string device_string;
std::string driver_vendor;
std::string driver_version;
int cuda_compute_capability_major = 0;
gl::GpuPreference gpu_preference = gl::GpuPreference::kNone;
};
GPUInfo();
GPUInfo(const GPUInfo& other);
~GPUInfo();
GPUDevice& active_gpu();
const GPUDevice& active_gpu() const;
bool IsInitialized() const;
bool UsesSwiftShader() const;
unsigned int GpuCount() const;
const GPUDevice* GetGpuByPreference(gl::GpuPreference preference) const;
#if BUILDFLAG(IS_WIN)
GPUDevice* FindGpuByLuid(DWORD low_part, LONG high_part);
#endif
base::TimeDelta initialization_time;
bool optimus;
bool amd_switchable;
GPUDevice gpu;
std::vector<GPUDevice> secondary_gpus;
std::string pixel_shader_version;
std::string vertex_shader_version;
std::string max_msaa_samples;
std::string machine_model_name;
std::string machine_model_version;
std::string display_type;
std::string gl_version;
std::string gl_vendor;
std::string gl_renderer;
std::string gl_extensions;
std::string gl_ws_vendor;
std::string gl_ws_version;
std::string gl_ws_extensions;
uint32_t gl_reset_notification_strategy;
gl::GLImplementationParts gl_implementation_parts;
std::string direct_rendering_version;
bool sandboxed;
bool in_process_gpu;
bool passthrough_cmd_decoder;
bool can_support_threaded_texture_mailbox = false;
#if defined(ADDRESS_SANITIZER)
bool is_asan = true;
#else
bool is_asan = false;
#endif
#if BUILDFLAG(USE_CLANG_COVERAGE) || BUILDFLAG(CLANG_PROFILING)
bool is_clang_coverage = true;
#else
bool is_clang_coverage = false;
#endif
#if defined(ARCH_CPU_64_BITS)
uint32_t target_cpu_bits = 64;
#elif defined(ARCH_CPU_32_BITS)
uint32_t target_cpu_bits = 32;
#elif defined(ARCH_CPU_31_BITS)
uint32_t target_cpu_bits = 31;
#endif
#if BUILDFLAG(IS_MAC)
uint32_t macos_specific_texture_target;
#endif
#if BUILDFLAG(IS_WIN)
DxDiagNode dx_diagnostics;
uint32_t d3d12_feature_level = 0;
uint32_t vulkan_version = 0;
OverlayInfo overlay_info;
bool shared_image_d3d = false;
#endif
VideoDecodeAcceleratorSupportedProfiles
video_decode_accelerator_supported_profiles;
VideoEncodeAcceleratorSupportedProfiles
video_encode_accelerator_supported_profiles;
bool jpeg_decode_accelerator_supported;
ImageDecodeAcceleratorSupportedProfiles
image_decode_accelerator_supported_profiles;
bool subpixel_font_rendering;
uint32_t visibility_callback_call_count = 0;
#if BUILDFLAG(ENABLE_VULKAN)
absl::optional<VulkanInfo> vulkan_info;
#endif
class Enumerator {
public:
virtual void AddInt64(const char* name, int64_t value) = 0;
virtual void AddInt(const char* name, int value) = 0;
virtual void AddString(const char* name, const std::string& value) = 0;
virtual void AddBool(const char* name, bool value) = 0;
virtual void AddTimeDeltaInSecondsF(const char* name,
const base::TimeDelta& value) = 0;
virtual void AddBinary(const char* name,
const base::span<const uint8_t>& blob) = 0;
virtual void BeginGPUDevice() = 0;
virtual void EndGPUDevice() = 0;
virtual void BeginVideoDecodeAcceleratorSupportedProfile() = 0;
virtual void EndVideoDecodeAcceleratorSupportedProfile() = 0;
virtual void BeginVideoEncodeAcceleratorSupportedProfile() = 0;
virtual void EndVideoEncodeAcceleratorSupportedProfile() = 0;
virtual void BeginImageDecodeAcceleratorSupportedProfile() = 0;
virtual void EndImageDecodeAcceleratorSupportedProfile() = 0;
virtual void BeginAuxAttributes() = 0;
virtual void EndAuxAttributes() = 0;
virtual void BeginOverlayInfo() = 0;
virtual void EndOverlayInfo() = 0;
protected:
virtual ~Enumerator() = default;
};
void EnumerateFields(Enumerator* enumerator) const;
};
}
#endif