Begin auto generating GPUInfo utilities
This change moves the bulk of the existing GPUInfo functionality into an autogenerated source built from a JSON file that describes the GPU vendor and device IDs, with device IDs broken down by GPU architecture. Also adds the fields needed to implement GPUAdapterInfo in Blink to the AdapterProperties. Bug: dawn:1427 Change-Id: I6a8b1fa7a63ec8d71556fc5bb3ae12cfe5abf28b Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/90962 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Brandon Jones <bajones@chromium.org>
This commit is contained in:
parent
67a4e7d765
commit
8cb8c7add7
|
@ -128,6 +128,8 @@
|
|||
"extensible": "out",
|
||||
"members": [
|
||||
{"name": "vendor ID", "type": "uint32_t"},
|
||||
{"name": "vendor name", "type": "char", "annotation": "const*", "length": "strlen"},
|
||||
{"name": "architecture", "type": "char", "annotation": "const*", "length": "strlen"},
|
||||
{"name": "device ID", "type": "uint32_t"},
|
||||
{"name": "name", "type": "char", "annotation": "const*", "length": "strlen"},
|
||||
{"name": "driver description", "type": "char", "annotation": "const*", "length": "strlen"},
|
||||
|
|
|
@ -0,0 +1,131 @@
|
|||
#!/usr/bin/env python3
|
||||
# Copyright 2022 The Dawn Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import json, os, sys
|
||||
from collections import namedtuple
|
||||
|
||||
from generator_lib import Generator, run_generator, FileRender
|
||||
|
||||
|
||||
class Name:
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.chunks = name.split(' ')
|
||||
|
||||
def get(self):
|
||||
return self.name
|
||||
|
||||
def CamelChunk(self, chunk):
|
||||
return chunk[0].upper() + chunk[1:]
|
||||
|
||||
def canonical_case(self):
|
||||
return (' '.join(self.chunks)).lower()
|
||||
|
||||
def concatcase(self):
|
||||
return ''.join(self.chunks)
|
||||
|
||||
def camelCase(self):
|
||||
return self.chunks[0] + ''.join(
|
||||
[self.CamelChunk(chunk) for chunk in self.chunks[1:]])
|
||||
|
||||
def CamelCase(self):
|
||||
return ''.join([self.CamelChunk(chunk) for chunk in self.chunks])
|
||||
|
||||
def SNAKE_CASE(self):
|
||||
return '_'.join([chunk.upper() for chunk in self.chunks])
|
||||
|
||||
def snake_case(self):
|
||||
return '_'.join(self.chunks)
|
||||
|
||||
def js_enum_case(self):
|
||||
result = self.chunks[0].lower()
|
||||
for chunk in self.chunks[1:]:
|
||||
if not result[-1].isdigit():
|
||||
result += '-'
|
||||
result += chunk.lower()
|
||||
return result
|
||||
|
||||
|
||||
class Architecture:
|
||||
def __init__(self, name, json_data):
|
||||
self.name = Name(name)
|
||||
self.devices = []
|
||||
for device in json_data:
|
||||
self.devices.append(device)
|
||||
|
||||
|
||||
class Vendor:
|
||||
def __init__(self, name, json_data):
|
||||
self.name = Name(name)
|
||||
self.id = json_data['id']
|
||||
|
||||
self.deviceMask = None
|
||||
if 'deviceMask' in json_data:
|
||||
self.deviceMask = json_data['deviceMask']
|
||||
|
||||
self.architectures = []
|
||||
|
||||
if 'architecture' in json_data:
|
||||
for (arch_name, arch_data) in json_data['architecture'].items():
|
||||
# Skip any entries that start with an underscore. Used for comments.
|
||||
if arch_name[0] == '_':
|
||||
continue
|
||||
|
||||
self.architectures.append(Architecture(arch_name, arch_data))
|
||||
|
||||
def maskDeviceId(self):
|
||||
if not self.deviceMask:
|
||||
return ''
|
||||
return ' & ' + self.deviceMask
|
||||
|
||||
|
||||
def parse_json(json):
|
||||
vendors = []
|
||||
|
||||
for (vendor, vendor_data) in json['vendors'].items():
|
||||
vendors.append(Vendor(vendor, vendor_data))
|
||||
|
||||
return {'vendors': vendors}
|
||||
|
||||
|
||||
class DawnGpuInfoGenerator(Generator):
|
||||
def get_description(self):
|
||||
return "Generates GPU Info Dawn code."
|
||||
|
||||
def add_commandline_arguments(self, parser):
|
||||
parser.add_argument('--gpu-info-json',
|
||||
required=True,
|
||||
type=str,
|
||||
help='The GPU Info JSON definition to use.')
|
||||
|
||||
def get_dependencies(self, args):
|
||||
return [os.path.abspath(args.gpu_info_json)]
|
||||
|
||||
def get_file_renders(self, args):
|
||||
with open(args.gpu_info_json) as f:
|
||||
loaded_json = json.loads(f.read())
|
||||
|
||||
params = parse_json(loaded_json)
|
||||
|
||||
return [
|
||||
FileRender("dawn/common/GPUInfo.h",
|
||||
"src/dawn/common/GPUInfo_autogen.h", [params]),
|
||||
FileRender("dawn/common/GPUInfo.cpp",
|
||||
"src/dawn/common/GPUInfo_autogen.cpp", [params]),
|
||||
]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(run_generator(DawnGpuInfoGenerator()))
|
|
@ -0,0 +1,106 @@
|
|||
// Copyright 2022 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
#include "dawn/common/GPUInfo_autogen.h"
|
||||
|
||||
#include "dawn/common/Assert.h"
|
||||
|
||||
namespace gpu_info {
|
||||
|
||||
namespace {
|
||||
|
||||
enum class Architecture {
|
||||
Unknown,
|
||||
{% for vendor in vendors %}
|
||||
{% for architecture in vendor.architectures %}
|
||||
{{vendor.name.CamelCase()}}_{{architecture.name.CamelCase()}},
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
};
|
||||
|
||||
Architecture GetArchitecture(PCIVendorID vendorId, PCIDeviceID deviceId) {
|
||||
switch(vendorId) {
|
||||
{% for vendor in vendors %}
|
||||
{% if len(vendor.architectures) %}
|
||||
|
||||
case kVendorID_{{vendor.name.CamelCase()}}: {
|
||||
switch (deviceId{{vendor.maskDeviceId()}}) {
|
||||
{% for architecture in vendor.architectures %}
|
||||
{% for device in architecture.devices %}
|
||||
case {{device}}:
|
||||
{% endfor %}
|
||||
return Architecture::{{vendor.name.CamelCase()}}_{{architecture.name.CamelCase()}};
|
||||
{% endfor %}
|
||||
}
|
||||
} break;
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
}
|
||||
|
||||
return Architecture::Unknown;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// Vendor checks
|
||||
{% for vendor in vendors %}
|
||||
bool Is{{vendor.name.CamelCase()}}(PCIVendorID vendorId) {
|
||||
return vendorId == kVendorID_{{vendor.name.CamelCase()}};
|
||||
}
|
||||
{% endfor %}
|
||||
|
||||
// Architecture checks
|
||||
|
||||
{% for vendor in vendors %}
|
||||
{% if len(vendor.architectures) %}
|
||||
// {{vendor.name.get()}} architectures
|
||||
{% for architecture in vendor.architectures %}
|
||||
bool Is{{vendor.name.CamelCase()}}{{architecture.name.CamelCase()}}(PCIVendorID vendorId, PCIDeviceID deviceId) {
|
||||
return GetArchitecture(vendorId, deviceId) == Architecture::{{vendor.name.CamelCase()}}_{{architecture.name.CamelCase()}};
|
||||
}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
// GPUAdapterInfo fields
|
||||
std::string GetVendorName(PCIVendorID vendorId) {
|
||||
switch(vendorId) {
|
||||
{% for vendor in vendors %}
|
||||
case kVendorID_{{vendor.name.CamelCase()}}: return "{{vendor.name.js_enum_case()}}";
|
||||
{% endfor %}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string GetArchitectureName(PCIVendorID vendorId, PCIDeviceID deviceId) {
|
||||
Architecture arch = GetArchitecture(vendorId, deviceId);
|
||||
switch(arch) {
|
||||
case Architecture::Unknown:
|
||||
return "";
|
||||
{% for vendor in vendors %}
|
||||
{% for architecture in vendor.architectures %}
|
||||
case Architecture::{{vendor.name.CamelCase()}}_{{architecture.name.CamelCase()}}:
|
||||
return "{{architecture.name.js_enum_case()}}";
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gpu_info
|
|
@ -0,0 +1,52 @@
|
|||
// Copyright 2022 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_DAWN_COMMON_GPUINFO_AUTOGEN_H_
|
||||
#define SRC_DAWN_COMMON_GPUINFO_AUTOGEN_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
using PCIVendorID = uint32_t;
|
||||
using PCIDeviceID = uint32_t;
|
||||
|
||||
namespace gpu_info {
|
||||
|
||||
// Vendor IDs
|
||||
{% for vendor in vendors %}
|
||||
static constexpr PCIVendorID kVendorID_{{vendor.name.CamelCase()}} = {{vendor.id}};
|
||||
{% endfor %}
|
||||
|
||||
// Vendor checks
|
||||
{% for vendor in vendors %}
|
||||
bool Is{{vendor.name.CamelCase()}}(PCIVendorID vendorId);
|
||||
{% endfor %}
|
||||
|
||||
// Architecture checks
|
||||
{% for vendor in vendors %}
|
||||
{% if len(vendor.architectures) %}
|
||||
|
||||
// {{vendor.name.get()}} architectures
|
||||
{% for architecture in vendor.architectures %}
|
||||
bool Is{{vendor.name.CamelCase()}}{{architecture.name.CamelCase()}}(PCIVendorID vendorId, PCIDeviceID deviceId);
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
// GPUAdapterInfo fields
|
||||
std::string GetVendorName(PCIVendorID vendorId);
|
||||
std::string GetArchitectureName(PCIVendorID vendorId, PCIDeviceID deviceId);
|
||||
|
||||
} // namespace gpu_info
|
||||
#endif // SRC_DAWN_COMMON_GPUINFO_AUTOGEN_H_
|
|
@ -0,0 +1,129 @@
|
|||
{
|
||||
"_comment": [
|
||||
"Copyright 2022 The Dawn Authors",
|
||||
"",
|
||||
"Licensed under the Apache License, Version 2.0 (the \"License\");",
|
||||
"you may not use this file except in compliance with the License.",
|
||||
"You may obtain a copy of the License at",
|
||||
"",
|
||||
" http://www.apache.org/licenses/LICENSE-2.0",
|
||||
"",
|
||||
"Unless required by applicable law or agreed to in writing, software",
|
||||
"distributed under the License is distributed on an \"AS IS\" BASIS,",
|
||||
"WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.",
|
||||
"See the License for the specific language governing permissions and",
|
||||
"limitations under the License."
|
||||
],
|
||||
|
||||
"vendors": {
|
||||
|
||||
"AMD": {
|
||||
"id": "0x1002",
|
||||
|
||||
"deviceMask": "0xFFF0",
|
||||
"architecture": {
|
||||
"GCN 1": ["0x6600", "0x6610", "0x6660", "0x6790", "0x6800", "0x6810", "0x6820", "0x6830"],
|
||||
"GCN 2": ["0x1300", "0x1310", "0x6640", "0x6650", "0x67A0", "0x67B0", "0x9830", "0x9850"],
|
||||
"GCN 3": ["0x6900", "0x6920", "0x6930", "0x7300", "0x9870", "0x98E0"],
|
||||
"GCN 4": ["0x67C0", "0x67D0", "0x67E0", "0x67F0", "0x6980", "0x6990"],
|
||||
"GCN 5": ["0x15D0", "0x1630", "0x1640", "0x66A0", "0x6860", "0x6870", "0x6940", "0x69A0"],
|
||||
"RDNA 1": ["0x7310", "0x7340", "0x7360"],
|
||||
"RDNA 2": ["0x73A0", "0x73B0", "0x73D0", "0x73E0", "0x73F0", "0x7420", "0x7430"]
|
||||
}
|
||||
},
|
||||
|
||||
"Apple": {
|
||||
"id": "0x106b"
|
||||
},
|
||||
|
||||
"ARM": {
|
||||
"id": "0x13B5",
|
||||
|
||||
"deviceMask": "0xF0000000",
|
||||
"architecture": {
|
||||
"_comment": [
|
||||
"The Midgard GPUs have device IDs like 0x07______ and 0x08______, but it's easiest to",
|
||||
"mask those values out and simply check for the highest octet being zero, since that",
|
||||
"distinguishes it from the other architectures."
|
||||
],
|
||||
|
||||
"Midgard": ["0x00000000"],
|
||||
"Bifrost": ["0x60000000", "0x70000000"],
|
||||
"Valhall": ["0x90000000", "0xA0000000"]
|
||||
}
|
||||
},
|
||||
|
||||
"Google": {
|
||||
"id": "0x1AE0",
|
||||
|
||||
"architecture": {
|
||||
"Swiftshader": ["0xC0DE"]
|
||||
}
|
||||
},
|
||||
|
||||
"Img Tec": {
|
||||
"id": "0x1010"
|
||||
},
|
||||
|
||||
"Intel": {
|
||||
"id": "0x8086",
|
||||
|
||||
"deviceMask": "0xFF00",
|
||||
"architecture": {
|
||||
"Gen 7": ["0x0100", "0x0400", "0x0A00", "0x0D00", "0x0F00"],
|
||||
"Gen 8": ["0x1600", "0x2200"],
|
||||
"Gen 9": ["0x1900", "0x3100", "0x3E00", "0x5A00", "0x5900", "0x9B00"],
|
||||
"Gen 11": ["0x8A00"],
|
||||
"Xe": ["0x4600", "0x4C00", "0x4900", "0x9A00"]
|
||||
}
|
||||
},
|
||||
|
||||
"Mesa": {
|
||||
"id": "0x10005"
|
||||
},
|
||||
|
||||
"Microsoft": {
|
||||
"id": "0x1414",
|
||||
|
||||
"architecture": {
|
||||
"WARP": ["0x8c"]
|
||||
}
|
||||
},
|
||||
|
||||
"Nvidia": {
|
||||
"id": "0x10DE",
|
||||
|
||||
"deviceMask": "0xFF00",
|
||||
"architecture": {
|
||||
"Fermi": ["0x0D00"],
|
||||
"Kepler": ["0x0F00", "0x1000", "0x1100", "0x1200"],
|
||||
"Maxwell": ["0x1300", "0x1400", "0x1600", "0x1700"],
|
||||
"Pascal": ["0x1500", "0x1B00", "0x1C00", "0x1D00"],
|
||||
"Turing": ["0x1E00", "0x1F00", "0x2100"],
|
||||
"Ampere": ["0x2200", "0x2400", "0x2500"]
|
||||
}
|
||||
},
|
||||
|
||||
"Qualcomm": {
|
||||
"id": "0x5143",
|
||||
|
||||
"deviceMask": "0xFF000000",
|
||||
"architecture": {
|
||||
"Adreno 4xx": ["0x04000000"],
|
||||
"Adreno 5xx": ["0x05000000"],
|
||||
"Adreno 6xx": ["0x06000000"],
|
||||
"Adreno 7xx": ["0x07000000"]
|
||||
}
|
||||
},
|
||||
|
||||
"Samsung": {
|
||||
"id": "0x144d",
|
||||
|
||||
"architecture": {
|
||||
"RDNA 2": ["0x73A0"]
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -185,6 +185,18 @@ dawn_generator("dawn_version_gen") {
|
|||
outputs = [ "src/dawn/common/Version_autogen.h" ]
|
||||
}
|
||||
|
||||
dawn_generator("dawn_gpu_info_gen") {
|
||||
script = "${dawn_root}/generator/dawn_gpu_info_generator.py"
|
||||
args = [
|
||||
"--gpu-info-json",
|
||||
rebase_path("${dawn_root}/gpu_info.json", root_build_dir),
|
||||
]
|
||||
outputs = [
|
||||
"src/dawn/common/GPUInfo_autogen.h",
|
||||
"src/dawn/common/GPUInfo_autogen.cpp",
|
||||
]
|
||||
}
|
||||
|
||||
# This GN file is discovered by all Chromium builds, but common doesn't support
|
||||
# all of Chromium's OSes so we explicitly make the target visible only on
|
||||
# systems we know Dawn is able to compile on.
|
||||
|
@ -241,8 +253,12 @@ if (is_win || is_linux || is_chromeos || is_mac || is_fuchsia || is_android) {
|
|||
"vulkan_platform.h",
|
||||
"xlib_with_undefs.h",
|
||||
]
|
||||
sources += get_target_outputs(":dawn_gpu_info_gen")
|
||||
|
||||
public_deps = [ ":dawn_version_gen" ]
|
||||
public_deps = [
|
||||
":dawn_gpu_info_gen",
|
||||
":dawn_version_gen",
|
||||
]
|
||||
|
||||
if (is_mac) {
|
||||
sources += [ "SystemUtils_mac.mm" ]
|
||||
|
|
|
@ -20,10 +20,19 @@ DawnGenerator(
|
|||
RESULT_VARIABLE "DAWN_VERSION_AUTOGEN_SOURCES"
|
||||
)
|
||||
|
||||
DawnGenerator(
|
||||
SCRIPT "${Dawn_SOURCE_DIR}/generator/dawn_gpu_info_generator.py"
|
||||
PRINT_NAME "Dawn GPU info utilities"
|
||||
ARGS "--gpu-info-json"
|
||||
"${Dawn_SOURCE_DIR}/gpu_info.json"
|
||||
RESULT_VARIABLE "DAWN_GPU_INFO_AUTOGEN_SOURCES"
|
||||
)
|
||||
|
||||
add_library(dawn_common STATIC ${DAWN_PLACEHOLDER_FILE})
|
||||
common_compile_options(dawn_common)
|
||||
target_sources(dawn_common PRIVATE
|
||||
${DAWN_VERSION_AUTOGEN_SOURCES}
|
||||
${DAWN_GPU_INFO_AUTOGEN_SOURCES}
|
||||
"Alloc.h"
|
||||
"Assert.cpp"
|
||||
"Assert.h"
|
||||
|
|
|
@ -12,9 +12,6 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
|
||||
#include "dawn/common/GPUInfo.h"
|
||||
|
||||
#include "dawn/common/Assert.h"
|
||||
|
@ -29,17 +26,6 @@ const std::array<uint32_t, 25> Skylake = {{0x1902, 0x1906, 0x190A, 0x190B, 0x190
|
|||
0x1915, 0x1916, 0x1917, 0x191A, 0x191B, 0x191D, 0x191E,
|
||||
0x1921, 0x1923, 0x1926, 0x1927, 0x192A, 0x192B, 0x192D,
|
||||
0x1932, 0x193A, 0x193B, 0x193D}};
|
||||
// gen9p5
|
||||
const std::array<uint32_t, 20> Kabylake = {{0x5916, 0x5913, 0x5906, 0x5926, 0x5921, 0x5915, 0x590E,
|
||||
0x591E, 0x5912, 0x5917, 0x5902, 0x591B, 0x593B, 0x590B,
|
||||
0x591A, 0x590A, 0x591D, 0x5908, 0x5923, 0x5927}};
|
||||
const std::array<uint32_t, 17> Coffeelake = {{0x87CA, 0x3E90, 0x3E93, 0x3E99, 0x3E9C, 0x3E91,
|
||||
0x3E92, 0x3E96, 0x3E98, 0x3E9A, 0x3E9B, 0x3E94,
|
||||
0x3EA9, 0x3EA5, 0x3EA6, 0x3EA7, 0x3EA8}};
|
||||
const std::array<uint32_t, 5> Whiskylake = {{0x3EA1, 0x3EA4, 0x3EA0, 0x3EA3, 0x3EA2}};
|
||||
const std::array<uint32_t, 21> Cometlake = {
|
||||
{0x9B21, 0x9BA0, 0x9BA2, 0x9BA4, 0x9BA5, 0x9BA8, 0x9BAA, 0x9BAB, 0x9BAC, 0x9B41, 0x9BC0,
|
||||
0x9BC2, 0x9BC4, 0x9BC5, 0x9BC6, 0x9BC8, 0x9BCA, 0x9BCB, 0x9BCC, 0x9BE6, 0x9BF6}};
|
||||
|
||||
// According to Intel graphics driver version schema, build number is generated from the
|
||||
// last two fields.
|
||||
|
@ -51,34 +37,6 @@ uint32_t GetIntelD3DDriverBuildNumber(const D3DDriverVersion& driverVersion) {
|
|||
|
||||
} // anonymous namespace
|
||||
|
||||
bool IsAMD(PCIVendorID vendorId) {
|
||||
return vendorId == kVendorID_AMD;
|
||||
}
|
||||
bool IsARM(PCIVendorID vendorId) {
|
||||
return vendorId == kVendorID_ARM;
|
||||
}
|
||||
bool IsImgTec(PCIVendorID vendorId) {
|
||||
return vendorId == kVendorID_ImgTec;
|
||||
}
|
||||
bool IsIntel(PCIVendorID vendorId) {
|
||||
return vendorId == kVendorID_Intel;
|
||||
}
|
||||
bool IsMesa(PCIVendorID vendorId) {
|
||||
return vendorId == kVendorID_Mesa;
|
||||
}
|
||||
bool IsNvidia(PCIVendorID vendorId) {
|
||||
return vendorId == kVendorID_Nvidia;
|
||||
}
|
||||
bool IsQualcomm(PCIVendorID vendorId) {
|
||||
return vendorId == kVendorID_Qualcomm;
|
||||
}
|
||||
bool IsSwiftshader(PCIVendorID vendorId, PCIDeviceID deviceId) {
|
||||
return vendorId == kVendorID_Google && deviceId == kDeviceID_Swiftshader;
|
||||
}
|
||||
bool IsWARP(PCIVendorID vendorId, PCIDeviceID deviceId) {
|
||||
return vendorId == kVendorID_Microsoft && deviceId == kDeviceID_WARP;
|
||||
}
|
||||
|
||||
int CompareD3DDriverVersion(PCIVendorID vendorId,
|
||||
const D3DDriverVersion& version1,
|
||||
const D3DDriverVersion& version2) {
|
||||
|
@ -97,12 +55,5 @@ int CompareD3DDriverVersion(PCIVendorID vendorId,
|
|||
bool IsSkylake(PCIDeviceID deviceId) {
|
||||
return std::find(Skylake.cbegin(), Skylake.cend(), deviceId) != Skylake.cend();
|
||||
}
|
||||
bool IsKabylake(PCIDeviceID deviceId) {
|
||||
return std::find(Kabylake.cbegin(), Kabylake.cend(), deviceId) != Kabylake.cend();
|
||||
}
|
||||
bool IsCoffeelake(PCIDeviceID deviceId) {
|
||||
return (std::find(Coffeelake.cbegin(), Coffeelake.cend(), deviceId) != Coffeelake.cend()) ||
|
||||
(std::find(Whiskylake.cbegin(), Whiskylake.cend(), deviceId) != Whiskylake.cend()) ||
|
||||
(std::find(Cometlake.cbegin(), Cometlake.cend(), deviceId) != Cometlake.cend());
|
||||
}
|
||||
|
||||
} // namespace gpu_info
|
||||
|
|
|
@ -15,37 +15,12 @@
|
|||
#ifndef SRC_DAWN_COMMON_GPUINFO_H_
|
||||
#define SRC_DAWN_COMMON_GPUINFO_H_
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include "dawn/common/GPUInfo_autogen.h"
|
||||
|
||||
using PCIVendorID = uint32_t;
|
||||
using PCIDeviceID = uint32_t;
|
||||
#include <array>
|
||||
|
||||
namespace gpu_info {
|
||||
|
||||
static constexpr PCIVendorID kVendorID_AMD = 0x1002;
|
||||
static constexpr PCIVendorID kVendorID_ARM = 0x13B5;
|
||||
static constexpr PCIVendorID kVendorID_ImgTec = 0x1010;
|
||||
static constexpr PCIVendorID kVendorID_Intel = 0x8086;
|
||||
static constexpr PCIVendorID kVendorID_Mesa = 0x10005;
|
||||
static constexpr PCIVendorID kVendorID_Nvidia = 0x10DE;
|
||||
static constexpr PCIVendorID kVendorID_Qualcomm = 0x5143;
|
||||
static constexpr PCIVendorID kVendorID_Google = 0x1AE0;
|
||||
static constexpr PCIVendorID kVendorID_Microsoft = 0x1414;
|
||||
|
||||
static constexpr PCIDeviceID kDeviceID_Swiftshader = 0xC0DE;
|
||||
static constexpr PCIDeviceID kDeviceID_WARP = 0x8c;
|
||||
|
||||
bool IsAMD(PCIVendorID vendorId);
|
||||
bool IsARM(PCIVendorID vendorId);
|
||||
bool IsImgTec(PCIVendorID vendorId);
|
||||
bool IsIntel(PCIVendorID vendorId);
|
||||
bool IsMesa(PCIVendorID vendorId);
|
||||
bool IsNvidia(PCIVendorID vendorId);
|
||||
bool IsQualcomm(PCIVendorID vendorId);
|
||||
bool IsSwiftshader(PCIVendorID vendorId, PCIDeviceID deviceId);
|
||||
bool IsWARP(PCIVendorID vendorId, PCIDeviceID deviceId);
|
||||
|
||||
using D3DDriverVersion = std::array<uint16_t, 4>;
|
||||
|
||||
// Do comparison between two driver versions. Currently we only support the comparison between
|
||||
|
@ -59,8 +34,6 @@ int CompareD3DDriverVersion(PCIVendorID vendorId,
|
|||
|
||||
// Intel architectures
|
||||
bool IsSkylake(PCIDeviceID deviceId);
|
||||
bool IsKabylake(PCIDeviceID deviceId);
|
||||
bool IsCoffeelake(PCIDeviceID deviceId);
|
||||
|
||||
} // namespace gpu_info
|
||||
#endif // SRC_DAWN_COMMON_GPUINFO_H_
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <memory>
|
||||
|
||||
#include "dawn/common/Constants.h"
|
||||
#include "dawn/common/GPUInfo.h"
|
||||
#include "dawn/native/Device.h"
|
||||
#include "dawn/native/Instance.h"
|
||||
#include "dawn/native/ValidationUtils_autogen.h"
|
||||
|
@ -43,6 +44,9 @@ MaybeError AdapterBase::Initialize() {
|
|||
"backend=%s type=%s)",
|
||||
mName, mDriverDescription, mVendorId, mDeviceId, mBackend, mAdapterType);
|
||||
|
||||
mVendorName = gpu_info::GetVendorName(mVendorId);
|
||||
mArchitectureName = gpu_info::GetArchitectureName(mVendorId, mDeviceId);
|
||||
|
||||
// Enforce internal Dawn constants.
|
||||
mLimits.v1.maxVertexBufferArrayStride =
|
||||
std::min(mLimits.v1.maxVertexBufferArrayStride, kMaxVertexBufferArrayStride);
|
||||
|
@ -79,6 +83,8 @@ bool AdapterBase::APIGetLimits(SupportedLimits* limits) const {
|
|||
|
||||
void AdapterBase::APIGetProperties(AdapterProperties* properties) const {
|
||||
properties->vendorID = mVendorId;
|
||||
properties->vendorName = mVendorName.c_str();
|
||||
properties->architecture = mArchitectureName.c_str();
|
||||
properties->deviceID = mDeviceId;
|
||||
properties->name = mName.c_str();
|
||||
properties->driverDescription = mDriverDescription.c_str();
|
||||
|
|
|
@ -67,6 +67,8 @@ class AdapterBase : public RefCounted {
|
|||
|
||||
protected:
|
||||
uint32_t mVendorId = 0xFFFFFFFF;
|
||||
std::string mVendorName;
|
||||
std::string mArchitectureName;
|
||||
uint32_t mDeviceId = 0xFFFFFFFF;
|
||||
std::string mName;
|
||||
wgpu::AdapterType mAdapterType = wgpu::AdapterType::Unknown;
|
||||
|
|
|
@ -211,7 +211,7 @@ ResultOrError<Ref<AdapterBase>> InstanceBase::RequestAdapterInternal(
|
|||
mAdapters[i]->APIGetProperties(&properties);
|
||||
|
||||
if (options->forceFallbackAdapter) {
|
||||
if (!gpu_info::IsSwiftshader(properties.vendorID, properties.deviceID)) {
|
||||
if (!gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID)) {
|
||||
continue;
|
||||
}
|
||||
return mAdapters[i];
|
||||
|
|
|
@ -591,9 +591,7 @@ void Device::InitTogglesFromDriver() {
|
|||
|
||||
// Currently this workaround is only needed on Intel Gen9 and Gen9.5 GPUs.
|
||||
// See http://crbug.com/1161355 for more information.
|
||||
if (gpu_info::IsIntel(vendorId) &&
|
||||
(gpu_info::IsSkylake(deviceId) || gpu_info::IsKabylake(deviceId) ||
|
||||
gpu_info::IsCoffeelake(deviceId))) {
|
||||
if (gpu_info::IsIntelGen9(vendorId, deviceId)) {
|
||||
constexpr gpu_info::D3DDriverVersion kFirstDriverVersionWithFix = {30, 0, 100, 9864};
|
||||
if (gpu_info::CompareD3DDriverVersion(vendorId, ToBackend(GetAdapter())->GetDriverVersion(),
|
||||
kFirstDriverVersionWithFix) < 0) {
|
||||
|
|
|
@ -780,7 +780,7 @@ bool DawnTestBase::IsQualcomm() const {
|
|||
}
|
||||
|
||||
bool DawnTestBase::IsSwiftshader() const {
|
||||
return gpu_info::IsSwiftshader(mParam.adapterProperties.vendorID,
|
||||
return gpu_info::IsGoogleSwiftshader(mParam.adapterProperties.vendorID,
|
||||
mParam.adapterProperties.deviceID);
|
||||
}
|
||||
|
||||
|
@ -789,7 +789,8 @@ bool DawnTestBase::IsANGLE() const {
|
|||
}
|
||||
|
||||
bool DawnTestBase::IsWARP() const {
|
||||
return gpu_info::IsWARP(mParam.adapterProperties.vendorID, mParam.adapterProperties.deviceID);
|
||||
return gpu_info::IsMicrosoftWARP(mParam.adapterProperties.vendorID,
|
||||
mParam.adapterProperties.deviceID);
|
||||
}
|
||||
|
||||
bool DawnTestBase::IsWindows() const {
|
||||
|
|
|
@ -68,7 +68,7 @@ TEST(AdapterDiscoveryTests, OnlySwiftShader) {
|
|||
|
||||
EXPECT_EQ(properties.backendType, wgpu::BackendType::Vulkan);
|
||||
EXPECT_EQ(properties.adapterType, wgpu::AdapterType::CPU);
|
||||
EXPECT_TRUE(gpu_info::IsSwiftshader(properties.vendorID, properties.deviceID));
|
||||
EXPECT_TRUE(gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -285,7 +285,7 @@ class AdapterCreationTest : public ::testing::Test {
|
|||
nativeAdapter.GetProperties(&properties);
|
||||
swiftShaderAvailable =
|
||||
swiftShaderAvailable ||
|
||||
gpu_info::IsSwiftshader(properties.vendorID, properties.deviceID);
|
||||
gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID);
|
||||
discreteGPUAvailable = discreteGPUAvailable ||
|
||||
properties.adapterType == wgpu::AdapterType::DiscreteGPU;
|
||||
integratedGPUAvailable = integratedGPUAvailable ||
|
||||
|
@ -364,7 +364,7 @@ TEST_F(AdapterCreationTest, FallbackAdapter) {
|
|||
adapter.GetProperties(&properties);
|
||||
|
||||
EXPECT_EQ(properties.adapterType, wgpu::AdapterType::CPU);
|
||||
EXPECT_TRUE(gpu_info::IsSwiftshader(properties.vendorID, properties.deviceID));
|
||||
EXPECT_TRUE(gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,6 +62,8 @@ class WireAdapterTests : public WireTest {
|
|||
EXPECT_CALL(api, AdapterGetProperties(apiAdapter, NotNull()))
|
||||
.WillOnce(WithArg<1>(Invoke([&](WGPUAdapterProperties* properties) {
|
||||
*properties = {};
|
||||
properties->vendorName = "";
|
||||
properties->architecture = "";
|
||||
properties->name = "";
|
||||
properties->driverDescription = "";
|
||||
})));
|
||||
|
|
|
@ -109,6 +109,8 @@ TEST_F(WireInstanceTests, RequestAdapterSuccess) {
|
|||
|
||||
wgpu::AdapterProperties fakeProperties = {};
|
||||
fakeProperties.vendorID = 0x134;
|
||||
fakeProperties.vendorName = "fake-vendor";
|
||||
fakeProperties.architecture = "fake-architecture";
|
||||
fakeProperties.deviceID = 0x918;
|
||||
fakeProperties.name = "fake adapter";
|
||||
fakeProperties.driverDescription = "hello world";
|
||||
|
@ -161,6 +163,8 @@ TEST_F(WireInstanceTests, RequestAdapterSuccess) {
|
|||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
EXPECT_EQ(properties.vendorID, fakeProperties.vendorID);
|
||||
EXPECT_STREQ(properties.vendorName, fakeProperties.vendorName);
|
||||
EXPECT_STREQ(properties.architecture, fakeProperties.architecture);
|
||||
EXPECT_EQ(properties.deviceID, fakeProperties.deviceID);
|
||||
EXPECT_STREQ(properties.name, fakeProperties.name);
|
||||
EXPECT_STREQ(properties.driverDescription, fakeProperties.driverDescription);
|
||||
|
@ -206,6 +210,8 @@ TEST_F(WireInstanceTests, RequestAdapterWireLacksFeatureSupport) {
|
|||
EXPECT_CALL(api, AdapterGetProperties(apiAdapter, NotNull()))
|
||||
.WillOnce(WithArg<1>(Invoke([&](WGPUAdapterProperties* properties) {
|
||||
*properties = {};
|
||||
properties->vendorName = "";
|
||||
properties->architecture = "";
|
||||
properties->name = "";
|
||||
properties->driverDescription = "";
|
||||
})));
|
||||
|
|
Loading…
Reference in New Issue