Skip to content

Commit 842a14b

Browse files
committed
feat(deck): Add DeckHD patch to gamescope
1 parent 7975627 commit 842a14b

File tree

2 files changed

+237
-0
lines changed

2 files changed

+237
-0
lines changed

spec_files/gamescope/deckhd.patch

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
diff --git a/src/drm.cpp b/src/drm.cpp
2+
index c2694f0..3a876ba 100644
3+
--- a/src/drm.cpp
4+
+++ b/src/drm.cpp
5+
@@ -40,6 +40,12 @@ extern "C" {
6+
7+
#include "gamescope-control-protocol.h"
8+
9+
+#define JUPITER_BOE_PID 0x3001
10+
+#define JUPITER_B_PID 0x3002
11+
+#define JUPITER_DHD_PID 0x4001
12+
+#define GALILEO_SDC_PID 0x3003
13+
+#define GALILEO_BOE_PID 0x3004
14+
+
15+
struct drm_t g_DRM = {};
16+
17+
uint32_t g_nDRMFormat = DRM_FORMAT_INVALID;
18+
@@ -521,7 +527,7 @@ drm_hdr_parse_edid(drm_t *drm, struct connector *connector, const struct di_edid
19+
drm_log.errorf("[colorimetry]: GAMESCOPE_INTERNAL_COLORIMETRY_OVERRIDE specified, but could not parse \"rx ry gx gy bx by wx wy\"");
20+
}
21+
}
22+
- else if (connector->is_steam_deck_display && !connector->is_galileo_display)
23+
+ else if (connector->steam_deck_display_pid == JUPITER_BOE_PID || connector->steam_deck_display_pid == JUPITER_B_PID)
24+
{
25+
drm_log.infof("[colorimetry]: Steam Deck (internal display) detected.");
26+
27+
@@ -827,9 +833,6 @@ void drm_update_patched_edid( drm_t *drm )
28+
create_patched_edid(drm->connector->edid_data.data(), drm->connector->edid_data.size(), drm, drm->connector);
29+
}
30+
31+
-#define GALILEO_SDC_PID 0x3003
32+
-#define GALILEO_BOE_PID 0x3004
33+
-
34+
static void parse_edid( drm_t *drm, struct connector *conn)
35+
{
36+
memset(conn->make_pnp, 0, sizeof(conn->make_pnp));
37+
@@ -892,21 +895,29 @@ static void parse_edid( drm_t *drm, struct connector *conn)
38+
}
39+
}
40+
41+
- drm_log.infof("Connector make %s model %s", conn->make_pnp, conn->model );
42+
+ drm_log.infof("Connector make %s model %s pid 0x%x", conn->make_pnp, conn->model, vendor_product->product);
43+
44+
- conn->is_steam_deck_display =
45+
+ bool is_steam_deck_display =
46+
(strcmp(conn->make_pnp, "WLC") == 0 && strcmp(conn->model, "ANX7530 U") == 0) ||
47+
(strcmp(conn->make_pnp, "ANX") == 0 && strcmp(conn->model, "ANX7530 U") == 0) ||
48+
(strcmp(conn->make_pnp, "VLV") == 0 && strcmp(conn->model, "ANX7530 U") == 0) ||
49+
- (strcmp(conn->make_pnp, "VLV") == 0 && strcmp(conn->model, "Jupiter") == 0);
50+
+ (strcmp(conn->make_pnp, "VLV") == 0 && strcmp(conn->model, "Jupiter") == 0) ||
51+
+ (strcmp(conn->make_pnp, "DHD") == 0 && strcmp(conn->model, "DeckHD-1200p") == 0);
52+
53+
- if ((vendor_product->product == GALILEO_SDC_PID) || (vendor_product->product == GALILEO_BOE_PID)) {
54+
- conn->is_galileo_display = vendor_product->product;
55+
- conn->valid_display_rates = std::span(galileo_display_rates);
56+
- } else {
57+
- conn->is_galileo_display = 0;
58+
- if ( conn->is_steam_deck_display )
59+
+ if (is_steam_deck_display) {
60+
+ if ((strcmp(conn->make_pnp, "DHD") == 0 && strcmp(conn->model, "DeckHD-1200p") == 0)) {
61+
+ // Hardcode the pid to support old DeckHD BIOS build where the pid matches to JUPITER_BOE_PID
62+
+ conn->steam_deck_display_pid = JUPITER_DHD_PID;
63+
+ } else {
64+
+ conn->steam_deck_display_pid = vendor_product->product;
65+
+ }
66+
+ if (conn->steam_deck_display_pid == GALILEO_SDC_PID || conn->steam_deck_display_pid == GALILEO_BOE_PID) {
67+
+ conn->valid_display_rates = std::span(galileo_display_rates);
68+
+ } else {
69+
conn->valid_display_rates = std::span(steam_deck_display_rates);
70+
+ }
71+
+ } else {
72+
+ conn->steam_deck_display_pid = 0;
73+
}
74+
75+
drm_hdr_parse_edid(drm, conn, edid);
76+
@@ -3072,7 +3083,7 @@ bool drm_set_refresh( struct drm_t *drm, int refresh )
77+
case DRM_MODE_GENERATE_FIXED:
78+
{
79+
const drmModeModeInfo *preferred_mode = find_mode(connector, 0, 0, 0);
80+
- generate_fixed_mode( &mode, preferred_mode, refresh, drm->connector->is_steam_deck_display, drm->connector->is_galileo_display );
81+
+ generate_fixed_mode( &mode, preferred_mode, refresh, drm->connector->steam_deck_display_pid );
82+
break;
83+
}
84+
}
85+
@@ -3272,4 +3283,4 @@ std::span<uint32_t> drm_get_valid_refresh_rates( struct drm_t *drm )
86+
return drm->connector->valid_display_rates;
87+
88+
return std::span<uint32_t>{};
89+
-}
90+
+}
91+
\ No newline at end of file
92+
diff --git a/src/drm.hpp b/src/drm.hpp
93+
index 6810797..7f80c5e 100644
94+
--- a/src/drm.hpp
95+
+++ b/src/drm.hpp
96+
@@ -177,9 +177,8 @@ struct connector {
97+
char make_pnp[4];
98+
char *make;
99+
char *model;
100+
- bool is_steam_deck_display;
101+
+ uint16_t steam_deck_display_pid;
102+
std::span<uint32_t> valid_display_rates{};
103+
- uint16_t is_galileo_display;
104+
105+
int target_refresh;
106+
bool vrr_capable;
107+
@@ -414,4 +413,4 @@ extern bool g_bSupportsAsyncFlips;
108+
const char* drm_get_patched_edid_path();
109+
void drm_update_patched_edid(drm_t *drm);
110+
111+
-void drm_send_gamescope_control(wl_resource *control, struct drm_t *drm);
112+
+void drm_send_gamescope_control(wl_resource *control, struct drm_t *drm);
113+
\ No newline at end of file
114+
diff --git a/src/modegen.cpp b/src/modegen.cpp
115+
index 197641c..faaafe5 100644
116+
--- a/src/modegen.cpp
117+
+++ b/src/modegen.cpp
118+
@@ -293,6 +293,21 @@ unsigned int galileo_boe_vfp[] =
119+
172,152,136,120,100,84,68,52,36,20,8
120+
};
121+
122+
+#define JUPITER_BOE_PID 0x3001
123+
+#define JUPITER_B_PID 0x3002
124+
+#define JUPITER_HFP 40
125+
+#define JUPITER_HSYNC 4
126+
+#define JUPITER_HBP 0
127+
+#define JUPITER_VFP 30
128+
+#define JUPITER_VSYNC 4
129+
+#define JUPITER_VBP 8
130+
+#define JUPITER_DHD_PID 0x4001
131+
+#define JUPITER_DHD_HFP 40
132+
+#define JUPITER_DHD_HSYNC 20
133+
+#define JUPITER_DHD_HBP 40
134+
+#define JUPITER_DHD_VFP 18
135+
+#define JUPITER_DHD_VSYNC 2
136+
+#define JUPITER_DHD_VBP 20
137+
#define GALILEO_MIN_REFRESH 45
138+
#define GALILEO_SDC_PID 0x3003
139+
#define GALILEO_SDC_VSYNC 1
140+
@@ -312,16 +327,37 @@ unsigned int get_galileo_vfp( int vrefresh, unsigned int * vfp_array, unsigned i
141+
return 0;
142+
}
143+
144+
-void generate_fixed_mode(drmModeModeInfo *mode, const drmModeModeInfo *base, int vrefresh,
145+
- bool use_tuned_clocks, unsigned int use_vfp )
146+
+void generate_fixed_mode(drmModeModeInfo *mode, const drmModeModeInfo *base, int vrefresh, uint16_t display_pid)
147+
{
148+
*mode = *base;
149+
if (!vrefresh)
150+
vrefresh = 60;
151+
- if ( use_vfp ) {
152+
- unsigned int vfp, vsync, vbp = 0;
153+
- if (GALILEO_SDC_PID == use_vfp) {
154+
- vfp = get_galileo_vfp( vrefresh, galileo_sdc_vfp, ARRAY_SIZE(galileo_sdc_vfp) );
155+
+ if (display_pid) {
156+
+ unsigned int vfp = 0, vsync = 0, vbp = 0;
157+
+ if (display_pid == JUPITER_BOE_PID || display_pid == JUPITER_B_PID) {
158+
+ mode->hdisplay = 800;
159+
+ mode->hsync_start = mode->hdisplay + JUPITER_HFP;
160+
+ mode->hsync_end = mode->hsync_start + JUPITER_HSYNC;
161+
+ mode->htotal = mode->hsync_end + JUPITER_HBP;
162+
+
163+
+ mode->vdisplay = 1280;
164+
+ vfp = 30;
165+
+ vsync = JUPITER_VSYNC;
166+
+ vbp = JUPITER_VBP;
167+
+ mode->clock = ( ( mode->htotal * mode->vtotal * vrefresh ) + 999 ) / 1000;
168+
+ } else if (display_pid == JUPITER_DHD_PID) {
169+
+ mode->hdisplay = 1200;
170+
+ mode->hsync_start = mode->hdisplay + JUPITER_DHD_HFP;
171+
+ mode->hsync_end = mode->hsync_start + JUPITER_DHD_HSYNC;
172+
+ mode->htotal = mode->hsync_end + JUPITER_DHD_HBP;
173+
+
174+
+ mode->vdisplay = 1920;
175+
+ vfp = JUPITER_DHD_VFP;
176+
+ vsync = JUPITER_DHD_VSYNC;
177+
+ vbp = JUPITER_DHD_VBP;
178+
+ mode->clock = ( ( mode->htotal * mode->vtotal * vrefresh ) + 999 ) / 1000;
179+
+ } else if (display_pid == GALILEO_SDC_PID) {
180+
+ unsigned int vfp = get_galileo_vfp( vrefresh, galileo_sdc_vfp, ARRAY_SIZE(galileo_sdc_vfp) );
181+
// if we did not find a matching rate then we default to 60 Hz
182+
if ( !vfp ) {
183+
vrefresh = 60;
184+
@@ -329,8 +365,8 @@ void generate_fixed_mode(drmModeModeInfo *mode, const drmModeModeInfo *base, int
185+
}
186+
vsync = GALILEO_SDC_VSYNC;
187+
vbp = GALILEO_SDC_VBP;
188+
- } else { // BOE Panel
189+
- vfp = get_galileo_vfp( vrefresh, galileo_boe_vfp, ARRAY_SIZE(galileo_boe_vfp) );
190+
+ } else if (display_pid == GALILEO_BOE_PID) {
191+
+ unsigned int vfp = get_galileo_vfp( vrefresh, galileo_boe_vfp, ARRAY_SIZE(galileo_boe_vfp) );
192+
// if we did not find a matching rate then we default to 60 Hz
193+
if ( !vfp ) {
194+
vrefresh = 60;
195+
@@ -338,28 +374,14 @@ void generate_fixed_mode(drmModeModeInfo *mode, const drmModeModeInfo *base, int
196+
}
197+
vsync = GALILEO_BOE_VSYNC;
198+
vbp = GALILEO_BOE_VBP;
199+
- }
200+
+ }
201+
mode->vsync_start = mode->vdisplay + vfp;
202+
mode->vsync_end = mode->vsync_start + vsync;
203+
mode->vtotal = mode->vsync_end + vbp;
204+
} else {
205+
- if ( use_tuned_clocks )
206+
- {
207+
- mode->hdisplay = 800;
208+
- mode->hsync_start = 840;
209+
- mode->hsync_end = 844;
210+
- mode->htotal = 884;
211+
-
212+
- mode->vdisplay = 1280;
213+
- mode->vsync_start = 1310;
214+
- mode->vsync_end = 1314;
215+
- mode->vtotal = 1322;
216+
- }
217+
-
218+
mode->clock = ( ( mode->htotal * mode->vtotal * vrefresh ) + 999 ) / 1000;
219+
}
220+
mode->vrefresh = (1000 * mode->clock) / (mode->htotal * mode->vtotal);
221+
222+
snprintf(mode->name, sizeof(mode->name), "%dx%d@%d.00", mode->hdisplay, mode->vdisplay, vrefresh);
223+
}
224+
-
225+
diff --git a/src/modegen.hpp b/src/modegen.hpp
226+
index 2513d34..17605b5 100644
227+
--- a/src/modegen.hpp
228+
+++ b/src/modegen.hpp
229+
@@ -9,4 +9,4 @@
230+
void generate_cvt_mode(drmModeModeInfo *mode, int hdisplay, int vdisplay,
231+
float vrefresh, bool reduced, bool interlaced);
232+
void generate_fixed_mode(drmModeModeInfo *mode, const drmModeModeInfo *base,
233+
- int vrefresh, bool use_tuned_clocks, unsigned int use_vfp);
234+
+ int vrefresh, uint16_t display_pid);
235+
\ No newline at end of file

spec_files/gamescope/gamescope.spec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ URL: https://github.com/ValveSoftware/gamescope
1111
# Create stb.pc to satisfy dependency('stb')
1212
Source1: stb.pc
1313
Source2: remove-720p-restrict.patch
14+
Source3: deckhd.patch
1415

1516
BuildRequires: meson >= 0.54.0
1617
BuildRequires: ninja-build
@@ -74,6 +75,7 @@ git submodule update --init --recursive
7475
mkdir -p pkgconfig
7576
cp %{SOURCE1} pkgconfig/stb.pc
7677
patch -Np1 < %{SOURCE2}
78+
patch -Np1 < %{SOURCE3}
7779

7880
%build
7981
cd gamescope

0 commit comments

Comments
 (0)