Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion tests/test_translator_checks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path
import unittest

from tools.check_translator_gpu import CHECKS, ROOT, command_for, printed_block, vulkan_device_name
from tools.check_translator_gpu import CHECKS, ROOT, command_for, device_filter, printed_block, vulkan_device, vulkan_device_name


class TranslatorCheckListTests(unittest.TestCase):
Expand Down Expand Up @@ -32,6 +32,25 @@ def test_names_the_vulkan_device_for_an_adapter(self):
self.assertEqual(vulkan_device_name("1002:13C0", summary), "AMD Radeon Graphics (RADV RAPHAEL_MENDOCINO)")
self.assertIsNone(vulkan_device_name("10de:2705", summary))

def test_filters_by_the_device_uuid(self):
# A Proton guest can see the device under another name, so the name cannot select it.
summary = ("Devices:\n========\nGPU0:\n\tvendorID = 0x1002\n\tdeviceID = 0x73bf\n"
"\tdeviceName = AMD Radeon RX 6900 XT (RADV NAVI21)\n"
"\tdeviceUUID = 00000000-0300-0000-0000-000000000000\n"
"GPU1:\n\tvendorID = 0x1002\n\tdeviceID = 0x164e\n"
"\tdeviceName = AMD Ryzen 9 7900X 12-Core Processor (RADV RAPHAEL_MENDOCINO)\n"
"\tdeviceUUID = 00000000-1300-0000-0000-000000000000\n")
self.assertEqual(device_filter(vulkan_device("1002:73bf", summary)),
{"DXVK_FILTER_DEVICE_UUID": "00000000030000000000000000000000"})
self.assertEqual(device_filter(vulkan_device("1002:164e", summary)),
{"DXVK_FILTER_DEVICE_UUID": "00000000130000000000000000000000"})
self.assertIsNone(vulkan_device("10de:2705", summary))
# Without a UUID in the summary, the name is all there is.
self.assertEqual(device_filter({"deviceName": "NVIDIA GeForce RTX 5090"}),
{"VKD3D_FILTER_DEVICE_NAME": "NVIDIA GeForce RTX 5090",
"DXVK_FILTER_DEVICE_NAME": "NVIDIA GeForce RTX 5090"})
self.assertEqual(device_filter({}), {})

def test_reads_the_program_a_unit_test_prints(self):
output = "running 1 test\nBEGIN_HLSL\nvoid main() {}\n\nEND_HLSL\ntest ok\nBEGIN_HLSL\nsecond\nEND_HLSL\n"
self.assertEqual(printed_block(output), "void main() {}\n\n")
Expand Down
40 changes: 31 additions & 9 deletions tools/check_translator_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,39 @@ def command_for(name, emitters, tools, host, work):
return command + ["--work", str(work / name), "--output", str(work / f"{name}.json")]


def vulkan_device_name(adapter, summary):
"""The device name `vulkaninfo --summary` lists for a PCI vendor:device ID, or None."""
def vulkan_device(adapter, summary):
"""The fields `vulkaninfo --summary` lists for a PCI vendor:device ID, or None."""
wanted = tuple(int(part, 16) for part in adapter.split(":"))
for block in re.split(r"^GPU\d+:\s*$", summary, flags=re.MULTILINE)[1:]:
fields = dict(re.findall(r"^\s*(vendorID|deviceID|deviceName)\s*=\s*(.+?)\s*$", block, re.MULTILINE))
fields = dict(re.findall(r"^\s*(vendorID|deviceID|deviceName|deviceUUID)\s*=\s*(.+?)\s*$", block, re.MULTILINE))
if (int(fields.get("vendorID", "-1"), 16), int(fields.get("deviceID", "-1"), 16)) == wanted:
return fields.get("deviceName")
return fields
return None


def vulkan_device_name(adapter, summary):
"""The device name `vulkaninfo --summary` lists for a PCI vendor:device ID, or None."""
return (vulkan_device(adapter, summary) or {}).get("deviceName")


def device_filter(fields):
"""The environment that makes DXVK expose only this device.

A Proton guest can see a device under another name than the host prints:
"AMD Radeon RX 6900 XT (RADV NAVI21)" on the host was
"Radeon RX 6800/6800 XT / 6900 XT" in the guest. The device UUID is the
same on both sides, so filter by it. DXVK compares the UUID as 32 hex
digits. Without a UUID, fall back to the name.
"""
uuid = re.sub(r"[^0-9a-f]", "", fields.get("deviceUUID", "").lower())
if len(uuid) == 32:
return {"DXVK_FILTER_DEVICE_UUID": uuid}
name = fields.get("deviceName")
return {"VKD3D_FILTER_DEVICE_NAME": name, "DXVK_FILTER_DEVICE_NAME": name} if name else {}


def select_adapter(adapter):
"""Have vkd3d-proton and DXVK expose only the requested adapter.
"""Have DXVK expose only the requested adapter.

The guests create their device on the default adapter, so on a machine
with several GPUs they would otherwise run on whichever one comes first.
Expand All @@ -139,10 +160,11 @@ def select_adapter(adapter):
timeout=60).stdout
except (OSError, subprocess.SubprocessError):
return None
name = vulkan_device_name(adapter, summary)
if name:
os.environ.update(VKD3D_FILTER_DEVICE_NAME=name, DXVK_FILTER_DEVICE_NAME=name)
return name
fields = vulkan_device(adapter, summary)
if not fields:
return None
os.environ.update(device_filter(fields))
return fields.get("deviceName")


def main(argv=None):
Expand Down
Loading