Skip to content

Commit

Permalink
fix(Hardware Manager): Fix Hardware Manager sometimes failing to dico…
Browse files Browse the repository at this point in the history
…ver the GPU.

- Found a bug where FileAccess would throw Unicode errors and not be parsable as a String. Using ca tthrough OS.execute() works around this bug.
  • Loading branch information
pastaq committed Dec 2, 2024
1 parent 2040d5e commit 1ce0440
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions core/systems/hardware/hardware_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func get_gpu_info() -> GPUInfo:
# to look into vulkaninfo as this can only gather the data
# for the currently active GPU. Vulkaninfo can provide data
# on all detected GPU devices.
match RenderingServer.get_video_adapter_vendor():
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":
Expand Down Expand Up @@ -160,11 +161,11 @@ func get_kernel_version() -> String:
## (e.g. get_gpu_card("card1"))
func get_gpu_card(card_dir: String) -> DRMCardInfo:
var file_prefix := "/".join(["/sys/class/drm", card_dir, "device"])
var vendor_id := _get_card_property_from_path("/".join([file_prefix, "vendor"]))
var device_id := _get_card_property_from_path("/".join([file_prefix, "device"]))
var revision_id := _get_card_property_from_path("/".join([file_prefix, "revision"]))
var subvendor_id := _get_card_property_from_path("/".join([file_prefix, "subsystem_vendor"]))
var subdevice_id := _get_card_property_from_path("/".join([file_prefix, "subsystem_device"]))
var vendor_id := _get_card_property_from_cat("/".join([file_prefix, "vendor"]))
var device_id := _get_card_property_from_cat("/".join([file_prefix, "device"]))
var revision_id := _get_card_property_from_cat("/".join([file_prefix, "revision"]))
var subvendor_id := _get_card_property_from_cat("/".join([file_prefix, "subsystem_vendor"]))
var subdevice_id := _get_card_property_from_cat("/".join([file_prefix, "subsystem_device"]))

# Try to load the card info if it already exists
var res_path := "/".join(["drmcardinfo://", vendor_id, device_id, subvendor_id, subdevice_id])
Expand Down Expand Up @@ -272,7 +273,7 @@ func get_gpu_cards() -> Array[DRMCardInfo]:
var card_info := get_gpu_card(card_name)
if not card_info:
continue

found_cards.append(card_info)

var vulkan_info := _get_cards_from_vulkan()
Expand Down Expand Up @@ -378,6 +379,16 @@ func _get_card_property_from_path(path: String) -> String:
return FileAccess.get_file_as_string(path).lstrip("0x").to_lower().strip_escapes()


func _get_card_property_from_cat(path: String) -> String:
var output := []
OS.execute("cat", [path], output)
if output.is_empty():
return ""
var value := output[0] as String
logger.debug("Got cat output:", value)
return value.lstrip("0x").to_lower().strip_escapes()


## Returns a an array of PackedStringArray's that each represent a sing GPU
## identified in vulkaninfo.
func _get_cards_from_vulkan() ->Array[PackedStringArray]:
Expand Down

0 comments on commit 1ce0440

Please sign in to comment.