Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: CRT SwitchRes Linux EDID PoC #17197

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
53 changes: 53 additions & 0 deletions gfx/temp-hack/swedid-root
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/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

# 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] [GPU Num] [Display]"
exit 1
fi

# Change $4 to $6 when no longer hardcoding
if [ -n "$4" ]; then
echo "Too many arguments"
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
echo "_tmpdir doesn't exist"
exit 1
fi
cd "$_tmpdir"

switchres $_sw_args --edid $1 $2 $3

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"
15 changes: 6 additions & 9 deletions gfx/video_crt_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -333,15 +334,11 @@ 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 %f", srm.width, srm.height, srm.vfreq);
printf("%s\n", commandbuffer);
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;
Expand Down
Loading