From a4dcf1c8432bbc61309b0ba58a7d3aab998151f8 Mon Sep 17 00:00:00 2001 From: Syboxez Blank <@Syboxez:matrix.org> Date: Sat, 23 Nov 2024 17:47:40 -0600 Subject: [PATCH 1/3] DO NOT MERGE: Extremely hacky PoC for using CRT CwitchRes to generate a single-use EDID and apply that EDID to a specific display. --- gfx/temp-hack/swedid-root | 34 ++++++++++++++++++++++++++++++++++ gfx/video_crt_switch.c | 14 +++++--------- 2 files changed, 39 insertions(+), 9 deletions(-) create mode 100755 gfx/temp-hack/swedid-root diff --git a/gfx/temp-hack/swedid-root b/gfx/temp-hack/swedid-root new file mode 100755 index 000000000000..1a383f2883a8 --- /dev/null +++ b/gfx/temp-hack/swedid-root @@ -0,0 +1,34 @@ +#!/bin/bash + +# This script requires running as root. "sudo" is called from "gfx/video_crt_switch.c", thus requiring a sudoers rule to non-interactively grant root permissions when running "/usr/local/bin/swedid-root" (this script) +# switchres binary must be in root's PATH + +# Hardcoding Display for now as DP-1 +if [ -z "$3" ]; then + echo "Usage: $0 [HRes] [VRes] [VFreq] [Display]" + exit 1 +fi + +# Hardcoding Display +if [ -n "$4" ]; then + echo "Too many arguments" + echo "Usage: $0 [HRes] [VRes] [VFreq] [Display]" + exit 1 +fi + +# Generate temperary working directory to generate EDID binary, then delete after applying +_tmpdir=$(mktemp -d) +if [ -z "$_tmpdir" ]; then + echo "_tmpdir doesn't exist" + exit 1 +fi +cd "$_tmpdir" + +switchres --ini /home/syboxez/.config/retroarch/config/switchres.ini --edid $1 $2 $3 + +#Replace "1" with GPU number, replace "DP-1" with display +cat "$_tmpdir"/custom.bin > /sys/kernel/debug/dri/1/DP-1/edid_override +echo 1 > /sys/kernel/debug/dri/1/DP-1/trigger_hotplug + +cd /tmp +rm -rf "$_tmpdir" diff --git a/gfx/video_crt_switch.c b/gfx/video_crt_switch.c index 352538ac41c1..3dfa8072acfe 100644 --- a/gfx/video_crt_switch.c +++ b/gfx/video_crt_switch.c @@ -293,6 +293,7 @@ static void switch_res_crt( { int w = native_width; int h = height; + char commandbuffer[256]; /* Check if SR2 is loaded, if not, load it */ if (crt_sr2_init(p_switch, monitor_index, crt_mode, super_width)) @@ -333,15 +334,10 @@ static void switch_res_crt( ret = sr_add_mode(w, h, rr, flags, &srm); if (!ret) RARCH_ERR("[CRT]: SR failed to add mode\n"); - if (p_switch->kms_ctx) - { - get_modeline_for_kms(p_switch, &srm); - video_driver_set_video_mode(srm.width, srm.height, true); - } - else if (p_switch->khr_ctx) - RARCH_WARN("[CRT]: Vulkan -> Can't modeswitch for now\n"); - else - ret = sr_set_mode(srm.id); + + snprintf(commandbuffer, sizeof(commandbuffer), "/usr/bin/sudo /usr/local/bin/swedid-root %d %d %d", srm.width, srm.height, srm.vfreq); + ret = system(commandbuffer); + if (!p_switch->kms_ctx && !ret) RARCH_ERR("[CRT]: SR failed to switch mode\n"); p_switch->sr_core_hz = (float)srm.vfreq; From 372425738bcf4d65c540e921a2f818735797597f Mon Sep 17 00:00:00 2001 From: Syboxez Blank <@Syboxez:matrix.org> Date: Tue, 26 Nov 2024 19:33:44 -0600 Subject: [PATCH 2/3] Fix command formatting and echo command before execution --- gfx/video_crt_switch.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gfx/video_crt_switch.c b/gfx/video_crt_switch.c index 3dfa8072acfe..0debde461dfb 100644 --- a/gfx/video_crt_switch.c +++ b/gfx/video_crt_switch.c @@ -335,7 +335,8 @@ static void switch_res_crt( if (!ret) RARCH_ERR("[CRT]: SR failed to add mode\n"); - snprintf(commandbuffer, sizeof(commandbuffer), "/usr/bin/sudo /usr/local/bin/swedid-root %d %d %d", srm.width, srm.height, srm.vfreq); + snprintf(commandbuffer, sizeof(commandbuffer), "/usr/bin/sudo /usr/local/bin/swedid-root %d %d %f", srm.width, srm.height, srm.vfreq); + printf("%s\n", commandbuffer); ret = system(commandbuffer); if (!p_switch->kms_ctx && !ret) From 62fe8600e7e386edc13aac1b3d60a41855c6650c Mon Sep 17 00:00:00 2001 From: Syboxez Blank <@Syboxez:matrix.org> Date: Wed, 27 Nov 2024 13:20:16 -0600 Subject: [PATCH 3/3] Hardcoded variables at top of script instead of spreading throughout. Backup EDID, but no restore yet --- gfx/temp-hack/swedid-root | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/gfx/temp-hack/swedid-root b/gfx/temp-hack/swedid-root index 1a383f2883a8..9283205e5afe 100755 --- a/gfx/temp-hack/swedid-root +++ b/gfx/temp-hack/swedid-root @@ -3,19 +3,39 @@ # This script requires running as root. "sudo" is called from "gfx/video_crt_switch.c", thus requiring a sudoers rule to non-interactively grant root permissions when running "/usr/local/bin/swedid-root" (this script) # switchres binary must be in root's PATH -# Hardcoding Display for now as DP-1 +# TODO: Get below values from RetroArch's video output settings instead of hardcoding. + +# Hardcode GPU number and Display name. Change these before running. +_display="DP-1" +_gpu="1" + +# Hardcode ini path or switchres monitor preset. Change this before running +_sw_args="--ini /home/syboxez/.config/retroarch/config/switchres.ini" + +# Change $3 to $5 when no longer hardcoding Display or GPU if [ -z "$3" ]; then - echo "Usage: $0 [HRes] [VRes] [VFreq] [Display]" + echo "Usage: $0 [HRes] [VRes] [VFreq] [GPU Num] [Display]" exit 1 fi -# Hardcoding Display +# Change $4 to $6 when no longer hardcoding if [ -n "$4" ]; then echo "Too many arguments" - echo "Usage: $0 [HRes] [VRes] [VFreq] [Display]" + echo "Usage: $0 [HRes] [VRes] [VFreq] [GPU Num] [Display]" exit 1 fi +# Backup EDID if backup doesn't exist +# Currently hardcoding GPU number and display name. Change this before running! +if [ ! -f /tmp/edid.bak ]; then + echo "Backing up EDID to /tmp/edid.bak" + dd if=/sys/class/drm/card"$_gpu"-"$_display"/edid of=/tmp/edid.bak bs=256 +else + echo "EDID already backed up to /tmp/edid.bak. Skipping backup." +fi + +# TODO: Restore EDID after RA closes instead of attempting to use xrandr, which is what happens now. + # Generate temperary working directory to generate EDID binary, then delete after applying _tmpdir=$(mktemp -d) if [ -z "$_tmpdir" ]; then @@ -24,11 +44,10 @@ if [ -z "$_tmpdir" ]; then fi cd "$_tmpdir" -switchres --ini /home/syboxez/.config/retroarch/config/switchres.ini --edid $1 $2 $3 +switchres $_sw_args --edid $1 $2 $3 -#Replace "1" with GPU number, replace "DP-1" with display -cat "$_tmpdir"/custom.bin > /sys/kernel/debug/dri/1/DP-1/edid_override -echo 1 > /sys/kernel/debug/dri/1/DP-1/trigger_hotplug +cat "$_tmpdir"/custom.bin > /sys/kernel/debug/dri/"$_gpu"/"$_display"/edid_override +echo 1 > /sys/kernel/debug/dri/"$_gpu"/"$_display"/trigger_hotplug cd /tmp rm -rf "$_tmpdir"