Skip to content

Commit

Permalink
fix(Hardware Manager): Gracefully detect all GPU's instead of failing.
Browse files Browse the repository at this point in the history
  • Loading branch information
pastaq authored and ShadowApex committed Jan 9, 2025
1 parent 150026f commit 51e6b53
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 34 deletions.
1 change: 1 addition & 0 deletions core/systems/hardware/drm_card_port.gd
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,5 @@ func _to_string() -> String:
+ " Name: (" + str(name) \
+ ") Status: (" + str(status) \
+ ") Enabled: (" + str(enabled) \
+ ") Instance ID: (" + str(self.get_instance_id()) \
+ ")>"
43 changes: 9 additions & 34 deletions core/systems/hardware/hardware_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,13 @@ func get_gpu_info() -> GPUInfo:
# for the currently active GPU. Vulkaninfo can provide data
# on all detected GPU devices.
gpu_info.vendor = RenderingServer.get_video_adapter_vendor()
match gpu_info.vendor:
"AMD", "AuthenticAMD", 'AuthenticAMD Advanced Micro Devices, Inc.', "Advanced Micro Devices, Inc. [AMD/ATI]":
gpu_info.vendor = "AMD"
"Intel", "GenuineIntel", "Intel Corporation":
gpu_info.vendor = "Intel"
"Nvidia":
gpu_info.vendor = "Trash" # :D
logger.info("Nvidia devices are not suppored.")
return null
_:
logger.warn("Device vendor string not recognized:", RenderingServer.get_video_adapter_vendor())
return null

gpu_info.model = RenderingServer.get_video_adapter_name()
gpu_info.driver = RenderingServer.get_video_adapter_api_version()

# Identify all installed GPU's
if cards.size() <= 0:
logger.error("GPU Data could not be derived.")
return null
logger.error("GPU Card subdata could not be derived.")
return gpu_info

var active_gpu_data := get_active_gpu_device()
if active_gpu_data.size() == 0:
Expand Down Expand Up @@ -192,11 +179,13 @@ func get_gpu_card(card_dir: String) -> DRMCardInfo:

if line.begins_with("\t") and not vendor_found:
continue

if line.begins_with(vendor_id):
vendor = line.lstrip(vendor_id).strip_edges()
logger.debug("Found vendor name:", vendor)
vendor_found = true
continue

if vendor_found and not line.begins_with("\t"):
if line.begins_with("#"):
continue
Expand All @@ -221,31 +210,17 @@ func get_gpu_card(card_dir: String) -> DRMCardInfo:
logger.debug("Found subdevice name:", subdevice)
break

# Sanitize the vendor strings so they are standard.
match vendor:
"AMD", "AuthenticAMD", 'AuthenticAMD Advanced Micro Devices, Inc.', "Advanced Micro Devices, Inc. [AMD/ATI]":
vendor = "AMD"
"Intel", "GenuineIntel", "Intel Corporation":
vendor = "Intel"
"Nvidia":
vendor = "Trash"
logger.warn("Nvidia devices are not suppored.")
# TODO: Handle this case
return null
_:
logger.warn("Device vendor string not recognized:", vendor)
# TODO: Handle this case
return null

# Create a new card instance and take over the caching path
var card_info: DRMCardInfo
match vendor:
"AMD":
"AMD", "AuthenticAMD", 'AuthenticAMD Advanced Micro Devices, Inc.', "Advanced Micro Devices, Inc. [AMD/ATI]":
card_info = DRMCardInfoAMD.new(card_dir)
"Intel":
"Intel", "GenuineIntel", "Intel Corporation":
card_info = DRMCardInfoIntel.new(card_dir)
_:
return null
logger.info("Device vendor string is not fully supported:", vendor, ". Using generic implementation.")
card_info = DRMCardInfo.new(card_dir)

card_info.take_over_path(res_path)
card_info.vendor = vendor
card_info.vendor_id = vendor_id
Expand Down
5 changes: 5 additions & 0 deletions core/systems/hardware/hardware_manager_test.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ func test_get_ports() -> void:
for card in cards:
var ports := card.get_ports()
for port in ports:
# Virtual ports will create a new instance each time, so skip their
# consideration for this test
if port.name.begins_with("Virtual"):
continue
gut.p(str(port))
var port_name := "-".join([card.name, port.name])
var other_port := card.get_port(port_name)
assert_eq(port, other_port, "should return the same port instance")
Expand Down

0 comments on commit 51e6b53

Please sign in to comment.