Skip to content

Commit

Permalink
Adding D3d12FeatureLevel and VulkanVersion UMA histogram for Windows
Browse files Browse the repository at this point in the history
In addition to GPU.SupportsDX12 and GPU.SupportsVulkan, two more UMA_HISTOGRAM_ENUMERATION,
GPU.D3d12FeatureLevel and GPU.VulkanVersion, are added in this CL to record the supported
D3D12 and Vulkan version in the GPU drivers.

The only valid D3D12 versions are 12.0 and 12.1.The only valid Vulkan version are 1.0.0 and 1.0.1

For the about:gpu page, "Supports DX12" and "Supports Vulkan" are removed after
"Driver D3D12 feature level" and "Driver Vulkan API version" are added.

BUG=775983
TEST=manual,Chrome://histograms
R=zmo@chromium.org

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I7e1d1c2b676a0bf1862ac9f7e53884d61d28bb7e
Reviewed-on: https://chromium-review.googlesource.com/1012752
Commit-Queue: Maggie Chen <magchen@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Ilya Sherman <isherman@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551916}
  • Loading branch information
Maggie Chen authored and Commit Bot committed Apr 19, 2018
1 parent 96ea5a7 commit ddea63e
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 41 deletions.
2 changes: 1 addition & 1 deletion components/viz/service/gl/gpu_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ void GpuServiceImpl::UpdateGpuInfoPlatform(
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
DCHECK(command_line->HasSwitch("disable-gpu-sandbox") || in_host_process());

gpu::GetGpuSupportedD3DVersion(&gpu_info_);
gpu::GetGpuSupportedD3D12Version(&gpu_info_);
gpu::GetGpuSupportedVulkanVersion(&gpu_info_);

// We can continue on shutdown here because we're not writing any critical
Expand Down
13 changes: 13 additions & 0 deletions content/browser/gpu/gpu_data_manager_impl_private.cc
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,26 @@ void GpuDataManagerImplPrivate::UnblockDomainFrom3DAPIs(const GURL& url) {

void GpuDataManagerImplPrivate::UpdateGpuInfo(const gpu::GPUInfo& gpu_info) {
bool sandboxed = gpu_info_.sandboxed;
#if defined(OS_WIN)
uint32_t d3d12_feature_level = gpu_info_.d3d12_feature_level;
uint32_t vulkan_version = gpu_info_.vulkan_version;
#endif
gpu_info_ = gpu_info;
#if defined(OS_WIN)
// On Windows, complete GPUInfo is collected through an unsandboxed
// GPU process. If the regular GPU process is sandboxed, it should
// not be overwritten.
if (sandboxed)
gpu_info_.sandboxed = true;

if (d3d12_feature_level) {
gpu_info_.d3d12_feature_level = d3d12_feature_level;
gpu_info_.supports_dx12 = true;
}
if (vulkan_version) {
gpu_info_.vulkan_version = vulkan_version;
gpu_info_.supports_vulkan = true;
}
#else
(void)sandboxed;
#endif // OS_WIN
Expand Down
30 changes: 26 additions & 4 deletions content/browser/gpu/gpu_internals_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,27 @@ std::unique_ptr<base::ListValue> DxDiagNodeToList(const gpu::DxDiagNode& node) {
}
return list;
}

std::string D3dFeaturelevelToString(uint32_t d3d_feature_level) {
if (d3d_feature_level == 0) {
return "Not supported";
} else {
return base::StringPrintf("D3D %d.%d", (d3d_feature_level >> 12) & 0xF,
(d3d_feature_level >> 8) & 0xF);
}
}

std::string VulkanVersionToString(uint32_t vulkan_version) {
if (vulkan_version == 0) {
return "Not supported";
} else {
// Vulkan version number VK_MAKE_VERSION(major, minor, patch)
// (((major) << 22) | ((minor) << 12) | (patch))
return base::StringPrintf(
"Vulkan API %d.%d.%d", (vulkan_version >> 22) & 0x3FF,
(vulkan_version >> 12) & 0x3FF, vulkan_version & 0xFFF);
}
}
#endif

std::string GPUDeviceToString(const gpu::GPUInfo::GPUDevice& gpu) {
Expand Down Expand Up @@ -177,11 +198,12 @@ std::unique_ptr<base::DictionaryValue> GpuInfoAsDictionaryValue() {
}

basic_info->Append(NewDescriptionValuePair(
"DX12", std::make_unique<base::Value>(gpu_info.supports_dx12)));

basic_info->Append(NewDescriptionValuePair(
"Vulkan", std::make_unique<base::Value>(gpu_info.supports_vulkan)));
"Driver D3D12 feature level",
D3dFeaturelevelToString(gpu_info.d3d12_feature_level)));

basic_info->Append(
NewDescriptionValuePair("Driver Vulkan API version",
VulkanVersionToString(gpu_info.vulkan_version)));
#endif

std::string disabled_extensions;
Expand Down
4 changes: 4 additions & 0 deletions gpu/config/gpu_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ void GPUInfo::EnumerateFields(Enumerator* enumerator) const {
DxDiagNode dx_diagnostics;
bool supports_dx12;
bool supports_vulkan;
uint32_t d3d12_feature_level;
uint32_t vulkan_version;
#endif

VideoDecodeAcceleratorCapabilities video_decode_accelerator_capabilities;
Expand Down Expand Up @@ -195,6 +197,8 @@ void GPUInfo::EnumerateFields(Enumerator* enumerator) const {
#if defined(OS_WIN)
enumerator->AddBool("supportsDX12", supports_dx12);
enumerator->AddBool("supportsVulkan", supports_vulkan);
enumerator->AddInt("d3dFeatureLevel", d3d12_feature_level);
enumerator->AddInt("vulkanVersion", vulkan_version);
#endif
enumerator->AddInt("videoDecodeAcceleratorFlags",
video_decode_accelerator_capabilities.flags);
Expand Down
6 changes: 6 additions & 0 deletions gpu/config/gpu_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ struct GPU_EXPORT GPUInfo {

// True if the GPU driver supports Vulkan.
bool supports_vulkan = false;

// The supported d3d feature level in the gpu driver;
uint32_t d3d12_feature_level = 0;

// The support Vulkan API version in the gpu driver;
uint32_t vulkan_version = 0;
#endif

VideoDecodeAcceleratorCapabilities video_decode_accelerator_capabilities;
Expand Down
2 changes: 1 addition & 1 deletion gpu/config/gpu_info_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ GPU_EXPORT bool CollectContextGraphicsInfo(GPUInfo* gpu_info);
// Collect the DirectX Disagnostics information about the attached displays.
GPU_EXPORT bool GetDxDiagnostics(DxDiagNode* output);
GPU_EXPORT void RecordGpuSupportedRuntimeVersionHistograms(GPUInfo* gpu_info);
GPU_EXPORT void GetGpuSupportedD3DVersion(GPUInfo* gpu_info);
GPU_EXPORT void GetGpuSupportedD3D12Version(GPUInfo* gpu_info);
GPU_EXPORT void GetGpuSupportedVulkanVersion(GPUInfo* gpu_info);
#endif // OS_WIN

Expand Down
138 changes: 105 additions & 33 deletions gpu/config/gpu_info_collector_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,54 @@ void DeviceIDToVendorAndDevice(const std::wstring& id,
*device_id = device;
}

// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
// This should match enum D3DFeatureLevel in \tools\metrics\histograms\enums.xml
enum class D3D12FeatureLevel {
kD3DFeatureLevelUnknown = 0,
kD3DFeatureLevel_12_0 = 1,
kD3DFeatureLevel_12_1 = 2,
kMaxValue = kD3DFeatureLevel_12_1,
};

inline D3D12FeatureLevel ConvertToHistogramFeatureLevel(
uint32_t d3d_feature_level) {
switch (d3d_feature_level) {
case 0:
return D3D12FeatureLevel::kD3DFeatureLevelUnknown;
case D3D_FEATURE_LEVEL_12_0:
return D3D12FeatureLevel::kD3DFeatureLevel_12_0;
case D3D_FEATURE_LEVEL_12_1:
return D3D12FeatureLevel::kD3DFeatureLevel_12_1;
default:
NOTREACHED();
return D3D12FeatureLevel::kD3DFeatureLevelUnknown;
}
}

// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
// This should match enum VulkanVersion in \tools\metrics\histograms\enums.xml
enum class VulkanVersion {
kVulkanVersionUnknown = 0,
kVulkanVersion_1_0_0 = 1,
kVulkanVersion_1_1_0 = 2,
kMaxValue = kVulkanVersion_1_1_0,
};

inline VulkanVersion ConvertToHistogramVulkanVersion(uint32_t vulkan_version) {
switch (vulkan_version) {
case 0:
return VulkanVersion::kVulkanVersionUnknown;
case VK_MAKE_VERSION(1, 0, 0):
return VulkanVersion::kVulkanVersion_1_0_0;
case VK_MAKE_VERSION(1, 1, 0):
return VulkanVersion::kVulkanVersion_1_1_0;
default:
NOTREACHED();
return VulkanVersion::kVulkanVersionUnknown;
}
}
} // namespace anonymous

#if defined(GOOGLE_CHROME_BUILD) && defined(OFFICIAL_BUILD)
Expand Down Expand Up @@ -229,61 +277,77 @@ bool CollectDriverInfoD3D(const std::wstring& device_id, GPUInfo* gpu_info) {
return found;
}

void GetGpuSupportedD3DVersion(GPUInfo* gpu_info) {
TRACE_EVENT0("gpu", "GetGpuSupportedD3DVersion");

// DirectX 12 are included with Windows 10 and Server 2016.
void GetGpuSupportedD3D12Version(GPUInfo* gpu_info) {
TRACE_EVENT0("gpu", "GetGpuSupportedD3D12Version");
gpu_info->supports_dx12 = false;
gpu_info->d3d12_feature_level = 0;

base::NativeLibrary d3d12_library =
base::LoadNativeLibrary(base::FilePath(L"d3d12.dll"), nullptr);
if (!d3d12_library) {
return;
}

if (d3d12_library) {
PFN_D3D12_CREATE_DEVICE D3D12CreateDevice =
reinterpret_cast<PFN_D3D12_CREATE_DEVICE>(
GetProcAddress(d3d12_library, "D3D12CreateDevice"));

if (D3D12CreateDevice) {
// For the default adapter only. (*pAdapter == nullptr)
// Check to see if the adapter supports Direct3D 12, but don't create the
// actual device yet. (**ppDevice == nullptr)
if (SUCCEEDED(D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_12_0,
_uuidof(ID3D12Device), nullptr))) {
// The order of feature levels to attempt to create in D3D CreateDevice
const D3D_FEATURE_LEVEL feature_levels[] = {D3D_FEATURE_LEVEL_12_1,
D3D_FEATURE_LEVEL_12_0};

PFN_D3D12_CREATE_DEVICE D3D12CreateDevice =
reinterpret_cast<PFN_D3D12_CREATE_DEVICE>(
GetProcAddress(d3d12_library, "D3D12CreateDevice"));
if (D3D12CreateDevice) {
// For the default adapter only. (*pAdapter == nullptr)
// Check to see if the adapter supports Direct3D 12, but don't create the
// actual device yet. (**ppDevice == nullptr)
for (auto level : feature_levels) {
if (SUCCEEDED(D3D12CreateDevice(nullptr, level, _uuidof(ID3D12Device),
nullptr))) {
gpu_info->d3d12_feature_level = level;
gpu_info->supports_dx12 = true;
break;
}
}
base::UnloadNativeLibrary(d3d12_library);
}

base::UnloadNativeLibrary(d3d12_library);
}

void GetGpuSupportedVulkanVersion(GPUInfo* gpu_info) {
TRACE_EVENT0("gpu", "GetGpuSupportedVulkanVersion");

gpu_info->supports_vulkan = false;
gpu_info->vulkan_version = 0;

base::NativeLibrary vulkan_library =
base::LoadNativeLibrary(base::FilePath(L"vulkan-1.dll"), nullptr);

if (vulkan_library) {
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
reinterpret_cast<PFN_vkGetInstanceProcAddr>(
GetProcAddress(vulkan_library, "vkGetInstanceProcAddr"));
if (!vulkan_library) {
return;
}

PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
reinterpret_cast<PFN_vkGetInstanceProcAddr>(
GetProcAddress(vulkan_library, "vkGetInstanceProcAddr"));

if (vkGetInstanceProcAddr) {
PFN_vkCreateInstance vkCreateInstance =
reinterpret_cast<PFN_vkCreateInstance>(
vkGetInstanceProcAddr(nullptr, "vkCreateInstance"));

if (vkGetInstanceProcAddr) {
PFN_vkCreateInstance vkCreateInstance =
reinterpret_cast<PFN_vkCreateInstance>(
vkGetInstanceProcAddr(nullptr, "vkCreateInstance"));
if (vkCreateInstance) {
VkApplicationInfo app_info = {};
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;

if (vkCreateInstance) {
VkApplicationInfo app_info = {};
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
app_info.apiVersion = VK_API_VERSION_1_0;
VkInstanceCreateInfo create_info = {};
create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
create_info.pApplicationInfo = &app_info;

VkInstanceCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInfo.pApplicationInfo = &app_info;
for (int minor_version = 1; minor_version >= 0; --minor_version) {
app_info.apiVersion = VK_MAKE_VERSION(1, minor_version, 0);

VkInstance vk_instance;
VkResult result = vkCreateInstance(&createInfo, nullptr, &vk_instance);
VkResult result = vkCreateInstance(&create_info, nullptr, &vk_instance);
if (result == VK_SUCCESS) {
PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices =
reinterpret_cast<PFN_vkEnumeratePhysicalDevices>(
Expand All @@ -296,21 +360,29 @@ void GetGpuSupportedVulkanVersion(GPUInfo* gpu_info) {
vk_instance, &physical_device_count, nullptr);
if (result == VK_SUCCESS && physical_device_count > 0) {
gpu_info->supports_vulkan = true;
gpu_info->vulkan_version = app_info.apiVersion;
break;
}
}
}
}
}
base::UnloadNativeLibrary(vulkan_library);
}
base::UnloadNativeLibrary(vulkan_library);
}

void RecordGpuSupportedRuntimeVersionHistograms(GPUInfo* gpu_info) {
GetGpuSupportedD3DVersion(gpu_info);
GetGpuSupportedD3D12Version(gpu_info);
GetGpuSupportedVulkanVersion(gpu_info);

UMA_HISTOGRAM_BOOLEAN("GPU.SupportsDX12", gpu_info->supports_dx12);
UMA_HISTOGRAM_BOOLEAN("GPU.SupportsVulkan", gpu_info->supports_vulkan);
UMA_HISTOGRAM_ENUMERATION(
"GPU.D3D12FeatureLevel",
ConvertToHistogramFeatureLevel(gpu_info->d3d12_feature_level));
UMA_HISTOGRAM_ENUMERATION(
"GPU.VulkanVersion",
ConvertToHistogramVulkanVersion(gpu_info->vulkan_version));
}

bool CollectContextGraphicsInfo(GPUInfo* gpu_info) {
Expand Down
4 changes: 4 additions & 0 deletions gpu/ipc/common/gpu_info.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ struct GpuInfo {
bool supports_dx12;
[EnableIf=is_win]
bool supports_vulkan;
[EnableIf=is_win]
uint32 d3d12_feature_level;
[EnableIf=is_win]
uint32 vulkan_version;
VideoDecodeAcceleratorCapabilities video_decode_accelerator_capabilities;
array<VideoEncodeAcceleratorSupportedProfile>
video_encode_accelerator_supported_profiles;
Expand Down
4 changes: 2 additions & 2 deletions gpu/ipc/common/gpu_info_struct_traits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ bool StructTraits<gpu::mojom::GpuInfoDataView, gpu::GPUInfo>::Read(
#endif

#if defined(OS_WIN)
out->supports_dx12 = data.supports_dx12();
out->supports_vulkan = data.supports_vulkan();
out->d3d12_feature_level = data.d3d12_feature_level();
out->vulkan_version = data.vulkan_version();
#endif

return data.ReadInitializationTime(&out->initialization_time) &&
Expand Down
9 changes: 9 additions & 0 deletions gpu/ipc/common/gpu_info_struct_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,18 @@ struct StructTraits<gpu::mojom::GpuInfoDataView, gpu::GPUInfo> {
static bool supports_dx12(const gpu::GPUInfo& input) {
return input.supports_dx12;
}

static bool supports_vulkan(const gpu::GPUInfo& input) {
return input.supports_vulkan;
}

static uint32_t d3d12_feature_level(const gpu::GPUInfo& input) {
return input.d3d12_feature_level;
}

static uint32_t vulkan_version(const gpu::GPUInfo& input) {
return input.vulkan_version;
}
#endif

static const gpu::VideoDecodeAcceleratorCapabilities&
Expand Down
12 changes: 12 additions & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8387,6 +8387,12 @@ Called by update_net_error_codes.py.-->
<int value="14" label="D3D11CreateDevice returned DXGI_ERROR_DEVICE_HUNG"/>
</enum>

<enum name="D3D12FeatureLevel">
<int value="0" label="D3D_FEATURE_LEVEL_UNKNOWN"/>
<int value="1" label="D3D_FEATURE_LEVEL_12_0"/>
<int value="2" label="D3D_FEATURE_LEVEL_12_1"/>
</enum>

<enum name="D3D9InitializeResult">
<int value="0" label="Success"/>
<int value="1" label="Error initializing compiler"/>
Expand Down Expand Up @@ -46520,6 +46526,12 @@ Full version information for the fingerprint enum values:
<int value="5" label="Unsupported Stream"/>
</enum>

<enum name="VulkanVersion">
<int value="0" label="VULKAN_API_VERSION_UNKNOWN"/>
<int value="1" label="VULKAN_API_VERSION_1_0_0"/>
<int value="2" label="VULKAN_API_VERSION_1_1_0"/>
</enum>

<enum name="WaitForVBlankErrorCode">
<int value="0" label="Success"/>
<int value="1" label="Failed to get monitor info"/>
Expand Down
Loading

0 comments on commit ddea63e

Please sign in to comment.