Skip to content

ReStreet: FIFA Street (2012) recompiled for Windows PC, with online play, a launcher with friends, chat and rooms. Bring your own game.

ReStreet v1.1: offline release

SamuelitoDaVilaedc078390b84
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 92f68fb..05a930b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,19 @@
# ReStreet - FIFA Street 2012 Recompiled: changelog
+## v1.1
+
+Smoother graphics and VSync, direct play, and a setup and launcher that fit any screen.
+
+### New
+- **New logo: ReStreet.** The main menu and the Press Start screen now show the ReStreet logo. It is applied by a small patch in the new `Mods` folder next to `Game` and `GameData`, which the game applies while reading its files; your game files are not modified. Delete the file in `Mods` to get the original logo back.
+- **Improved "Some" graphics readback, now the default.** The Some readback mode was reworked to remove the graphical garbage it used to cause on some courts (for example floor reflections and flickering floor lines) while keeping its performance. It is now the default in the Balanced and Quality profiles. Occlusion queries are off by default in those profiles. If you prefer the old behaviour, pick Full (compatible) in the Compatibility tab. Settings you already saved are kept.
+- **VSync now works smoothly.** The old VSync made the game run at only a few FPS on some PCs (every wait for the graphics card cost two screen refreshes). VSync now keeps the game locked to your refresh rate and shows each frame without blocking the graphics queue, with no tearing. Turning VSync off still gives an unlocked frame rate.
+- **Direct play.** Start the game without opening the launcher window: run `FifaStreetLauncher.exe --play`, or click the new **Shortcut** button in the launcher to create a desktop shortcut that does exactly that. It uses the settings you last chose in the launcher and closes by itself after the game exits.
+
+### Fixed
+- **Setup and launcher layout on any resolution or Windows scale.** On some screens (for example a 4K TV set to 1080p with Windows scale at 150%) the controls could end up smaller than the window, overlapping the title and cut off. The window, controls and text are now laid out from one scale that follows your monitor's DPI and always fits the screen, including 100% to 200% scale and small laptop screens.
+- The window now follows you when it is moved to a monitor with a different scale.
+
## v1.0
First stable release. This version is offline only: it has no online play.
diff --git a/Installer/FifaStreetSetupTool/FifaStreetSetupTool.csproj b/Installer/FifaStreetSetupTool/FifaStreetSetupTool.csproj
index faaed99..be312d4 100644
--- a/Installer/FifaStreetSetupTool/FifaStreetSetupTool.csproj
+++ b/Installer/FifaStreetSetupTool/FifaStreetSetupTool.csproj
@@ -4,6 +4,8 @@
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
+ <ApplicationHighDpiMode>PerMonitorV2</ApplicationHighDpiMode>
+ <Version>1.1.0</Version>
<AssemblyName>FifaStreetSetup</AssemblyName>
<ApplicationIcon>..\recomp-template\src\fifastreet.ico</ApplicationIcon>
<ImplicitUsings>enable</ImplicitUsings>
diff --git a/Installer/FifaStreetSetupTool/SetupForm.cs b/Installer/FifaStreetSetupTool/SetupForm.cs
index 719fe2c..786dd8e 100644
--- a/Installer/FifaStreetSetupTool/SetupForm.cs
+++ b/Installer/FifaStreetSetupTool/SetupForm.cs
@@ -71,8 +71,11 @@ internal static class Program
}
}
-internal sealed class SetupForm : Form, ISceneHost
+internal sealed class SetupForm : Form, ISceneHost, IUiScaled
{
+ readonly UiScaler scaler;
+ public float UiScale => scaler.Scale;
+
readonly TextBox iso = new();
readonly TextBox destination = new();
readonly TextBox details = new();
@@ -120,7 +123,7 @@ internal sealed class SetupForm : Form, ISceneHost
using (var icon = Assembly.GetExecutingAssembly().GetManifestResourceStream("fifastreet.ico")!)
Icon = new Icon(icon);
ClientSize = new Size(930, 610);
- MinimumSize = MaximumSize = Size;
+ scaler = new UiScaler(this, 930, 610);
StartPosition = FormStartPosition.CenterScreen;
FormBorderStyle = FormBorderStyle.FixedSingle;
MaximizeBox = false;
@@ -129,8 +132,6 @@ internal sealed class SetupForm : Form, ISceneHost
BackColor = StreetTheme.Asphalt;
ForeColor = StreetTheme.Ink;
Font = StreetTheme.Body(10);
- AutoScaleDimensions = new SizeF(96F, 96F);
- AutoScaleMode = AutoScaleMode.Dpi;
HandleCreated += (_, _) => StreetTheme.ApplyDarkTitleBar(Handle);
Controls.Add(Text_(PrecompiledPackage.Enabled
@@ -187,9 +188,7 @@ internal sealed class SetupForm : Form, ISceneHost
{
details.Visible = !details.Visible;
showDetails.Text = details.Visible ? "Hide details" : "Show details";
- MaximumSize = Size.Empty;
- Height += (int)((details.Visible ? 180 : -180) * DeviceDpi / 96f);
- MaximumSize = Size;
+ scaler.DesignHeight = details.Visible ? 790 : 610;
};
Controls.Add(showDetails);
cancel.Kind = SlantKind.Text;
@@ -234,6 +233,7 @@ internal sealed class SetupForm : Form, ISceneHost
};
FormClosed += (_, _) => { timer.Dispose(); scene?.Dispose(); };
RefreshInstallMode();
+ scaler.Capture();
}
protected override void OnPaintBackground(PaintEventArgs e)
@@ -337,8 +337,7 @@ internal sealed class SetupForm : Form, ISceneHost
case "details":
details.Text = "Preparing installation tools…\r\nChecking the ISO…\r\nExtracting the FIFA Street ISO…";
details.Visible = true;
- MaximumSize = Size.Empty;
- Height += (int)(180 * DeviceDpi / 96f);
+ scaler.DesignHeight = 790;
break;
}
Application.DoEvents();
diff --git a/Installer/FifaStreetSetupTool/ThemeKit.cs b/Installer/FifaStreetSetupTool/ThemeKit.cs
index a3d7d42..7722778 100644
--- a/Installer/FifaStreetSetupTool/ThemeKit.cs
+++ b/Installer/FifaStreetSetupTool/ThemeKit.cs
@@ -61,11 +61,9 @@ internal static class StreetTheme
public const int DesignWidth = 930;
- // Extra scale applied by a window that shrinks itself to fit a small screen (1.0 = none).
- public static float FitScale = 1f;
-
- // Pixel size of one design pixel for a control: system DPI (96 = 1.0) times the fit scale.
- public static float K(Control control) => (control.DeviceDpi / 96f) * FitScale;
+ // Pixel size of one design pixel for a control: the scale its window (UiScaler) is using right now.
+ public static float K(Control control) =>
+ control.FindForm() is IUiScaled scaled ? scaled.UiScale : control.DeviceDpi / 96f;
static string? condensed;
@@ -644,3 +642,133 @@ internal sealed class GlassCombo : ComboBox
g.DrawLines(chevron, new[] { new PointF(cx - 4.5f * k, cy - 2.2f * k), new PointF(cx, cy + 2.3f * k), new PointF(cx + 4.5f * k, cy - 2.2f * k) });
}
}
+
+
+// A window that is laid out from design pixels and scaled by one number.
+internal interface IUiScaled { float UiScale { get; } }
+
+// One scale factor drives everything: window size, control bounds and fonts. It is the smaller of the monitor's
+// DPI scale and what fits in the screen's work area, so the layout never depends on WinForms' automatic scaling
+// and can never end up with the window and its controls at different scales. Controls and fonts are captured once
+// (in design pixels) and re-applied from that baseline every time the scale changes.
+internal sealed class UiScaler
+{
+ readonly Form form;
+ readonly int designWidth;
+ int designHeight;
+ readonly List<Item> items = new();
+ float formFontPx = 13.33f;
+ bool applying, captured;
+
+ sealed class Item
+ {
+ public Control Control = null!;
+ public Rectangle Bounds;
+ public float FontPx;
+ public int ItemHeight;
+ public bool KeepBounds;
+ }
+
+ public float Scale { get; private set; } = 1f;
+
+ // Testing and support overrides: RESTREET_UI_DPI=150 (percent) and RESTREET_UI_AREA=1280x680 (work area).
+ static float? DpiOverride => float.TryParse(Environment.GetEnvironmentVariable("RESTREET_UI_DPI"), out float percent) && percent >= 50 ? percent / 100f : null;
+ static Size? AreaOverride
+ {
+ get
+ {
+ var parts = (Environment.GetEnvironmentVariable("RESTREET_UI_AREA") ?? "").Split('x');
+ return parts.Length == 2 && int.TryParse(parts[0], out int w) && int.TryParse(parts[1], out int h) && w > 200 && h > 200 ? new Size(w, h) : null;
+ }
+ }
+
+ public UiScaler(Form form, int designWidth, int designHeight)
+ {
+ this.form = form;
+ this.designWidth = designWidth;
+ this.designHeight = designHeight;
+ form.AutoScaleMode = AutoScaleMode.None;
+ form.DpiChanged += (_, _) => Apply();
+ form.ResizeEnd += (_, _) => Apply();
+ form.Shown += (_, _) => Apply();
+ }
+
+ // Design height of the client area. Changing it resizes the window at the current scale (or a smaller one if it no longer fits).
+ public int DesignHeight
+ {
+ get => designHeight;
+ set { if (value == designHeight) return; designHeight = value; Apply(); }
+ }
+
+ // Records every control's bounds and font as design pixels. Call once, after the whole interface is built.
+ public void Capture()
+ {
+ items.Clear();
+ formFontPx = form.Font.SizeInPoints * 96f / 72f;
+ Walk(form, false);
+ captured = true;
+ Apply();
+ }
+
+ void Walk(Control parent, bool selfLayout)
+ {
+ foreach (Control child in parent.Controls)
+ {
+ items.Add(new Item
+ {
+ Control = child,
+ Bounds = child.Bounds,
+ FontPx = child.Font.SizeInPoints * 96f / 72f,
+ ItemHeight = child is ComboBox combo ? combo.ItemHeight : 0,
+ KeepBounds = selfLayout
+ });
+ // A FieldFrame lays out its own text box, so only the font of that box is scaled.
+ Walk(child, child is FieldFrame);
+ }
+ }
+
+ public void Apply()
+ {
+ if (applying || !captured) return;
+ applying = true;
+ try
+ {
+ var area = AreaOverride is { } forced ? new Rectangle(0, 0, forced.Width, forced.Height)
+ : (form.IsHandleCreated ? Screen.FromControl(form) : Screen.PrimaryScreen ?? Screen.AllScreens[0]).WorkingArea;
+ float dpiScale = DpiOverride ?? form.DeviceDpi / 96f;
+ var chrome = form.IsHandleCreated ? new Size(form.Width - form.ClientSize.Width, form.Height - form.ClientSize.Height)
+ : new Size(16, 39);
+ float fitWidth = (area.Width - chrome.Width) / (float)designWidth;
+ float fitHeight = (area.Height - chrome.Height) / (float)designHeight;
+ float k = Math.Max(0.5f, Math.Min(dpiScale, Math.Min(fitWidth, fitHeight)));
+ k = (float)Math.Floor(k * 1000) / 1000f;
+ Scale = k;
+
+ form.SuspendLayout();
+ form.MinimumSize = form.MaximumSize = Size.Empty;
+ form.Font = new Font(form.Font.FontFamily, Math.Max(7f, formFontPx * k), form.Font.Style, GraphicsUnit.Pixel);
+ form.ClientSize = new Size((int)Math.Round(designWidth * k), (int)Math.Round(designHeight * k));
+ foreach (var item in items)
+ {
+ var c = item.Control;
+ c.Font = new Font(c.Font.FontFamily, Math.Max(7f, item.FontPx * k), c.Font.Style, GraphicsUnit.Pixel);
+ if (c is ComboBox combo && item.ItemHeight > 0) combo.ItemHeight = Math.Max(16, (int)Math.Round(item.ItemHeight * k));
+ if (item.KeepBounds) continue;
+ c.SetBounds((int)Math.Round(item.Bounds.X * k), (int)Math.Round(item.Bounds.Y * k),
+ (int)Math.Round(item.Bounds.Width * k), (int)Math.Round(item.Bounds.Height * k));
+ }
+ form.ResumeLayout(true);
+ form.MinimumSize = form.MaximumSize = form.Size;
+
+ if (form.Visible)
+ {
+ var bounds = form.Bounds;
+ int x = Math.Max(area.Left, Math.Min(bounds.X, area.Right - bounds.Width));
+ int y = Math.Max(area.Top, Math.Min(bounds.Y, area.Bottom - bounds.Height));
+ if (x != bounds.X || y != bounds.Y) form.Location = new Point(x, y);
+ }
+ form.Invalidate(true);
+ }
+ finally { applying = false; }
+ }
+}
diff --git a/Launcher/FifaStreetLauncher/FifaStreetLauncher.csproj b/Launcher/FifaStreetLauncher/FifaStreetLauncher.csproj
index a9431dc..751c476 100644
--- a/Launcher/FifaStreetLauncher/FifaStreetLauncher.csproj
+++ b/Launcher/FifaStreetLauncher/FifaStreetLauncher.csproj
@@ -5,6 +5,8 @@
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
+ <ApplicationHighDpiMode>PerMonitorV2</ApplicationHighDpiMode>
+ <Version>1.1.0</Version>
<ApplicationIcon>fifastreet.ico</ApplicationIcon>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
diff --git a/Launcher/FifaStreetLauncher/LauncherForm.cs b/Launcher/FifaStreetLauncher/LauncherForm.cs
index 2ca2d21..2dc1883 100644
--- a/Launcher/FifaStreetLauncher/LauncherForm.cs
+++ b/Launcher/FifaStreetLauncher/LauncherForm.cs
@@ -12,8 +12,11 @@ using ReStreet.Ui;
namespace FifaStreetLauncher;
-public class LauncherForm : Form, ISceneHost
+public class LauncherForm : Form, ISceneHost, IUiScaled
{
+ private readonly UiScaler scaler;
+ public float UiScale => scaler.Scale;
+
private readonly Color Bg = StreetTheme.Asphalt;
private readonly Color Surface = Color.FromArgb(28, 31, 36);
private readonly Color SurfaceAlt = StreetTheme.Field;
@@ -84,8 +87,7 @@ public class LauncherForm : Form, ISceneHost
using (var icon = typeof(LauncherForm).Assembly.GetManifestResourceStream("fifastreet.ico")!)
Icon = new Icon(icon);
ClientSize = new Size(1250, 720);
- MinimumSize = new Size(1266, 759);
- MaximumSize = new Size(1266, 1100);
+ scaler = new UiScaler(this, 1250, 720);
DoubleBuffered = true;
ResizeRedraw = true;
HandleCreated += (_, _) => StreetTheme.ApplyDarkTitleBar(Handle);
@@ -95,8 +97,6 @@ public class LauncherForm : Form, ISceneHost
BackColor = Bg;
ForeColor = TextPrimary;
Font = new Font("Segoe UI", 10F);
- AutoScaleDimensions = new SizeF(96F, 96F);
- AutoScaleMode = AutoScaleMode.Dpi;
BuildInterface();
WireEvents();
@@ -109,7 +109,7 @@ public class LauncherForm : Form, ISceneHost
UpdateRefreshRates();
UpdateSummary();
UpdateStatus("Ready to play", true);
- FitToScreen();
+ scaler.Capture();
}
// Layout on an 8 px grid (design pixels, window 1250 x 720): left column margin 48; glass sheet
@@ -159,46 +159,13 @@ public class LauncherForm : Form, ISceneHost
using (var bar = new SolidBrush(StreetTheme.Yellow)) g.FillPolygon(bar, StreetTheme.Slant(tag, 12));
using (var tagFont = new Font(StreetTheme.CondensedFamily, 18, FontStyle.Bold, GraphicsUnit.Pixel))
using (var dark = new SolidBrush(StreetTheme.YellowDark))
- StreetTheme.DrawSpaced(g, "V1.0 · OFFLINE", tagFont, dark, new PointF(Left + 14, 246), 2.8f);
+ StreetTheme.DrawSpaced(g, "V1.1 · OFFLINE", tagFont, dark, new PointF(Left + 14, 246), 2.8f);
using var name = new Font("Segoe UI", 15, FontStyle.Regular, GraphicsUnit.Pixel);
StreetTheme.DrawLabelValue(g, "Ported by:", "SamuelitoDaVila", name, StreetTheme.Ink, StreetTheme.Ink, Left, 642);
StreetTheme.DrawLabelValue(g, "Contributions:", "Emran_Ahm3d", name, StreetTheme.Muted, StreetTheme.Muted, Left, 665);
}
- // On a screen too small for the window (for example 1366 x 768 laptops) everything shrinks together:
- // control sizes, fonts and the backdrop, keeping the layout intact.
- private void FitToScreen()
- {
- var area = Screen.PrimaryScreen?.WorkingArea ?? new Rectangle(0, 0, 1920, 1080);
- int availableHeight = area.Height, availableWidth = area.Width;
- if (int.TryParse(Environment.GetEnvironmentVariable("RESTREET_WORKAREA_HEIGHT"), out int forced)) availableHeight = forced;
- int chromeHeight = Height - ClientSize.Height, chromeWidth = Width - ClientSize.Width;
- float f = Math.Min((availableHeight - chromeHeight) / (float)ClientSize.Height, (availableWidth - chromeWidth) / (float)ClientSize.Width);
- if (f >= 0.995f) return;
- f = Math.Max(f, 0.55f);
- SuspendLayout();
- MinimumSize = MaximumSize = Size.Empty;
- ScaleFonts(this, f);
- StreetTheme.FitScale = f;
- Scale(new SizeF(f, f));
- foreach (var combo in Controls.OfType<GlassCombo>().Concat(compatibilityPanel.Controls.OfType<GlassCombo>()))
- combo.ItemHeight = Math.Max(16, (int)(28 * f));
- ResumeLayout(true);
- MinimumSize = new Size(Width, Height);
- MaximumSize = new Size(Width, Height + (int)(380 * f));
- Invalidate(true);
- }
-
- private static void ScaleFonts(Control root, float f)
- {
- foreach (Control child in root.Controls)
- {
- child.Font = new Font(child.Font.FontFamily, child.Font.Size * f, child.Font.Style, child.Font.Unit);
- ScaleFonts(child, f);
- }
- }
-
private void BuildInterface()
{
SuspendLayout();
@@ -254,13 +221,13 @@ public class LauncherForm : Form, ISceneHost
};
Controls.Add(tip);
- // Bottom row: four equal buttons, 126 wide with 10 px gaps (4 x 126 + 3 x 10 = 534).
+ // Bottom row: five equal buttons, 100 wide with 8 px gaps (5 x 100 + 4 x 8 = 532).
void Chip(SlantButton button, string text, int index)
{
button.Kind = SlantKind.Glass;
button.Text = text;
button.Font = StreetTheme.Body(10F);
- button.Bounds = new Rectangle(ContentX + index * 136, 624, 126, 40);
+ button.Bounds = new Rectangle(ContentX + index * 108, 624, 100, 40);
Controls.Add(button);
}
Chip(advancedButton, "Advanced", 0);
@@ -271,6 +238,9 @@ public class LauncherForm : Form, ISceneHost
var folderButton = new SlantButton();
folderButton.Click += (_, _) => OpenGameFolder();
Chip(folderButton, "Open folder", 3);
+ var shortcutButton = new SlantButton();
+ shortcutButton.Click += (_, _) => CreateDesktopShortcut();
+ Chip(shortcutButton, "Shortcut", 4);
ConfigureAdvancedPanel();
Controls.Add(advancedPanel);
@@ -367,7 +337,7 @@ public class LauncherForm : Form, ISceneHost
compatibilityPanel.Controls.Add(new ThemedLabel
{
- Text = "Readback Resolve: Full is the validated mode. Some and Fast give more FPS but may cause graphical corruption.",
+ Text = "Readback Resolve: Some is the recommended mode (more FPS with the validated fixes). Full is the most compatible; Fast gives more FPS but may cause graphical corruption.",
Font = StreetTheme.Body(10F), ForeColor = TextSecondary,
Bounds = new Rectangle(Pad, 204, PanelW - 2 * Pad, 20)
});
@@ -440,13 +410,11 @@ displayModeBox.SelectedIndexChanged += (_, _) => { UpdateRefreshRates(); UpdateS
if (advancedVisible)
{
- float k = ClientSize.Width / DesignW;
- ClientSize = new Size(ClientSize.Width, (int)Math.Round(944 * k));
- advancedPanel.Location = new Point((int)Math.Round(PanelX * k), (int)Math.Round(PanelY * k));
+ scaler.DesignHeight = 944;
}
else
{
- ClientSize = new Size(ClientSize.Width, (int)Math.Round(720 * ClientSize.Width / DesignW));
+ scaler.DesignHeight = 720;
}
}
@@ -466,13 +434,11 @@ displayModeBox.SelectedIndexChanged += (_, _) => { UpdateRefreshRates(); UpdateS
if (compatibilityVisible)
{
- float k = ClientSize.Width / DesignW;
- ClientSize = new Size(ClientSize.Width, (int)Math.Round(1000 * k));
- compatibilityPanel.Location = new Point((int)Math.Round(PanelX * k), (int)Math.Round(PanelY * k));
+ scaler.DesignHeight = 1000;
}
else
{
- ClientSize = new Size(ClientSize.Width, (int)Math.Round(720 * ClientSize.Width / DesignW));
+ scaler.DesignHeight = 720;
}
}
@@ -593,11 +559,11 @@ displayModeBox.SelectedIndexChanged += (_, _) => { UpdateRefreshRates(); UpdateS
readbackResolveBox.Items.AddRange(new object[]
{
"Full (compatible)",
- "Some (balanced)",
+ "Some (recommended)",
"Fast (more FPS, may glitch)",
"None (experimental)"
});
- readbackResolveBox.SelectedIndex = 0;
+ readbackResolveBox.SelectedIndex = 1;
monitorBox.Items.Clear();
foreach (var screen in Screen.AllScreens)
@@ -636,7 +602,7 @@ displayModeBox.SelectedIndexChanged += (_, _) => { UpdateRefreshRates(); UpdateS
readbackMemexportFastBox.Checked = true;
clearMemoryPageStateBox.Checked = false;
logFrameStatsBox.Checked = false;
- occlusionQueryBox.Checked = true;
+ occlusionQueryBox.Checked = false;
asyncShadersBox.Checked = true;
vsyncBox.Checked = false;
@@ -959,6 +925,48 @@ displayModeBox.SelectedIndexChanged += (_, _) => { UpdateRefreshRates(); UpdateS
statusLabel.ForeColor = ok ? TextSecondary : Color.FromArgb(255, 120, 120);
}
+ // Direct play (--play): the window stays invisible, the game starts with the saved settings and the
+ // launcher closes by itself after the game exits (it still restores the display mode first).
+ public void StartDirect()
+ {
+ closeAfterGame = true;
+ ShowInTaskbar = false;
+ Opacity = 0;
+ StartPosition = FormStartPosition.Manual;
+ Location = new Point(-32000, -32000);
+ Shown += (_, _) => LaunchGame();
+ }
+
+ private void CreateDesktopShortcut()
+ {
+ try
+ {
+ SaveSettings();
+ string desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
+ string target = Environment.ProcessPath ?? Application.ExecutablePath;
+ string path = Path.Combine(desktop, "ReStreet (direct play).lnk");
+ Type? shellType = Type.GetTypeFromProgID("WScript.Shell");
+ if (shellType == null) throw new InvalidOperationException("Windows Script Host is not available.");
+ dynamic shell = Activator.CreateInstance(shellType)!;
+ dynamic link = shell.CreateShortcut(path);
+ link.TargetPath = target;
+ link.Arguments = "--play";
+ link.WorkingDirectory = Path.GetDirectoryName(target);
+ link.IconLocation = target + ",0";
+ link.Description = "Start ReStreet directly with the settings saved in the launcher";
+ link.Save();
+ MessageBox.Show(
+ "A shortcut was created on your desktop: ReStreet (direct play)." + Environment.NewLine + Environment.NewLine +
+ "It starts the game straight away with the settings you have now. " +
+ "To change settings later, open the launcher normally and click Shortcut again to refresh it.",
+ "ReStreet Launcher", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Could not create the shortcut", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
private async void LaunchGame()
{
if (gameRunning) {
@@ -1106,8 +1114,10 @@ startInfo.Environment["REX_DRAW_RESOLUTION_SCALE_Y"] =
fullscreen ? "true" : "false";
startInfo.Environment["REX_MONITOR"] = (monitor + 1).ToString();
startInfo.Environment["REX_LAUNCHER_MONITOR_DEVICE"] = Screen.AllScreens[monitor].DeviceName;
- startInfo.Environment["REX_VSYNC"] =
- vsyncBox.Checked ? "true" : "false";
+ // "VSync" is implemented as paced presentation: the game clock stays locked to the refresh rate and
+ // frames are presented without blocking the graphics queue. The real blocking VSync of the host swap chain
+ // made every GPU wait cost two vblanks (a few FPS), and it does not tear because tearing is not requested.
+ startInfo.Environment["REX_VSYNC"] = "false";
startInfo.Environment["REX_NATIVE_2X_MSAA"] =
msaaBox.Checked ? "true" : "false";
startInfo.Environment["REX_SWAP_POST_EFFECT"] = postEffect;
@@ -1132,9 +1142,11 @@ startInfo.Environment["REX_DRAW_RESOLUTION_SCALE_Y"] =
startInfo.Environment["REX_RENDER_TARGET_PATH_VULKAN"] = "fbo";
// Override legacy TOML values: checked means FIFO, unchecked
// requests immediate presentation without display synchronization.
+ // With VSync on, prefer MAILBOX (latest frame wins, no tearing, never blocks the queue).
startInfo.Environment["REX_VULKAN_ALLOW_PRESENT_MODE_IMMEDIATE"] =
vsyncBox.Checked ? "false" : "true";
- startInfo.Environment["REX_VULKAN_ALLOW_PRESENT_MODE_MAILBOX"] = "false";
+ startInfo.Environment["REX_VULKAN_ALLOW_PRESENT_MODE_MAILBOX"] =
+ vsyncBox.Checked ? "true" : "false";
startInfo.Environment["REX_VULKAN_ALLOW_PRESENT_MODE_FIFO_RELAXED"] =
vsyncBox.Checked ? "false" : "true";
}
@@ -1390,8 +1402,8 @@ startInfo.Environment["REX_DRAW_RESOLUTION_SCALE_Y"] =
return;
(int post, int scale, bool msaa, int readback, bool occlusion)? values = profileBox.SelectedIndex switch
{
- 0 => (1, 0, false, 0, true), // Balanced: the shipped defaults
- 1 => (2, 1, true, 0, true), // Quality: 2x internal resolution, FXAA extreme, MSAA
+ 0 => (1, 0, false, 1, false), // Balanced: the shipped defaults (Some readback)
+ 1 => (2, 1, true, 1, false), // Quality: 2x internal resolution, FXAA extreme, MSAA (Some readback)
2 => (0, 0, false, 2, false), // Performance: native resolution, no post, faster readback
_ => null
};
diff --git a/Launcher/FifaStreetLauncher/Program.cs b/Launcher/FifaStreetLauncher/Program.cs
index 51d096e..139bd8d 100644
--- a/Launcher/FifaStreetLauncher/Program.cs
+++ b/Launcher/FifaStreetLauncher/Program.cs
@@ -24,6 +24,14 @@ internal static class Program
bitmap.Save(args[1]);
return;
}
+ if (Array.Exists(args, a => a.Equals("--play", StringComparison.OrdinalIgnoreCase)))
+ {
+ // Direct play: no window, starts the game with the settings saved by the launcher.
+ var direct = new LauncherForm();
+ direct.StartDirect();
+ Application.Run(direct);
+ return;
+ }
Application.Run(new LauncherForm());
}
}
diff --git a/README.md b/README.md
index c9f8ffc..d3f8ed1 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@
### Ported by: SamuelitoDaVila
-[Download](https://github.com/samuelit0davila/fifa-street-pc-port/releases/latest) · [Video](https://www.youtube.com/watch?v=FiwdAOIHGFY) · [Discord](https://discord.gg/CqjYMGKyy2) · [Changelog](CHANGELOG.md) · [Report a bug](https://github.com/samuelit0davila/fifa-street-pc-port/issues) · [Build from source](docs/BUILDING.md)
+[Download](https://github.com/samuelit0davila/fifa-street-pc-port/releases/latest) · [Changelog](CHANGELOG.md) · [Report a bug](https://github.com/samuelit0davila/fifa-street-pc-port/issues) · [Build from source](docs/BUILDING.md)
<img src="docs/images/start-screen.png" alt="ReStreet running on PC" width="1000">
@@ -20,7 +20,16 @@ ReStreet is a Windows PC version of FIFA Street (2012) made by recompiling the X
You need your own copy of the game: an Xbox 360 ISO of FIFA Street (2012). The ISO and the game files are not included.
-**v1.0 is offline only.** It has no online play.
+**v1.1 is offline only.** It has no online play.
+
+## What's new in v1.1
+
+- **ReStreet main menu logo**, applied from the new `Mods` folder without changing your game files.
+- **Improved "Some" graphics readback**, now the default: less graphical garbage on floors and reflections, with the same speed.
+- **VSync works smoothly.** It keeps the game locked to your refresh rate with no tearing.
+- **Direct play:** start the game without the launcher window using `FifaStreetLauncher.exe --play`, or create a desktop shortcut with the new **Shortcut** button.
+- **Launcher and setup fit any screen**, at any resolution and Windows scale.
+- Your saves and settings are kept when you update. See the full [changelog](CHANGELOG.md).
## What's new in v1.0
@@ -33,12 +42,6 @@ You need your own copy of the game: an Xbox 360 ISO of FIFA Street (2012). The I
<img src="docs/images/launcher.png" alt="The ReStreet launcher" width="1000">
-## Gameplay video
-
-[![Watch ReStreet on YouTube](docs/images/gameplay-video.jpg)](https://www.youtube.com/watch?v=FiwdAOIHGFY)
-
-Installation, the new launcher and gameplay at 1440p. [Watch on YouTube](https://www.youtube.com/watch?v=FiwdAOIHGFY).
-
## Download and install
1. Download **FifaStreetSetup.exe** from the [latest release](https://github.com/samuelit0davila/fifa-street-pc-port/releases/latest) and check its SHA-256 against the value on the release page.
@@ -51,10 +54,6 @@ No compiler, Visual Studio or Internet connection is needed.
<img src="docs/images/installer.png" alt="The ReStreet installer" width="900">
-## Community
-
-Join the **[ReStreet Discord](https://discord.gg/CqjYMGKyy2)** for downloads, help installing, bug reports, screenshots and the online beta.
-
## System requirements
These are estimates from my own testing, not guarantees. If you try it on an older PC, tell me your specs and FPS.
diff --git a/docs/GITHUB-PRESENTATION.md b/docs/GITHUB-PRESENTATION.md
index 5f7cb49..fd81f9f 100644
--- a/docs/GITHUB-PRESENTATION.md
+++ b/docs/GITHUB-PRESENTATION.md
@@ -16,7 +16,7 @@ ReStreet - FIFA Street (2012) for Windows PC, recompiled with ReXGlue, with an i
Commit this source folder and its documentation. Upload the installer `.exe` as a Release asset rather than committing it to the source tree. GitHub Releases are designed to contain downloadable binaries and release notes; see [GitHub's documentation](https://docs.github.com/en/repositories/releasing-projects-on-github/about-releases).
-The release asset is `FifaStreetSetup.exe` (v1.0). Its SHA-256 is in `FifaStreetSetup.exe.sha256` and in the release text. Use `docs/RELEASE-NOTES.md` as the release description. Keep the requirements marked as estimates until more hardware reports arrive, and keep the legal note about the generated game binaries.
+The release asset is `FifaStreetSetup.exe` (v1.1). Its SHA-256 is in `FifaStreetSetup.exe.sha256` and in the release text. Use `docs/RELEASE-NOTES.md` as the release description. Keep the requirements marked as estimates until more hardware reports arrive, and keep the legal note about the generated game binaries.
## Images
diff --git a/docs/RELEASE-NOTES.md b/docs/RELEASE-NOTES.md
index 7d0b383..b743709 100644
--- a/docs/RELEASE-NOTES.md
+++ b/docs/RELEASE-NOTES.md
@@ -1,15 +1,18 @@
-# ReStreet - FIFA Street 2012 Recompiled v1.0
+# ReStreet - FIFA Street 2012 Recompiled v1.1
-First stable release of ReStreet, FIFA Street (2012) for Windows PC. This version is offline only.
+Smoother graphics and VSync, direct play, the ReStreet logo, and a setup and launcher that fit any screen. This version is offline only.
-## New in v1.0
+## New in v1.1
-- **Performance profiles** in the launcher: Balanced (default), Quality for strong PCs, Performance for weaker PCs, and Custom. Changing any option by hand switches the profile to Custom.
-- **Shader cache included.** Pre-built shaders ship with the game and are copied on the first run, so the first matches have fewer slow moments. Shaders you already have are never replaced.
-- **FPS counter.** Press Home to show or hide a small FPS number in the top-left corner. It scales with the game's resolution and changes colour: green from 55 FPS, yellow from 30, red below.
-- **Exit shortcut.** Hold START and press B (Xbox layout) or START and Circle (PlayStation layout) on any screen to open "EXIT THE GAME?". A confirms, B cancels. Available in English, German, French, Spanish, Italian and Portuguese.
-- **New launcher and installer design,** with support for the Windows display scale and small screens.
-- **New name:** ReStreet - FIFA Street 2012 Recompiled.
+- **ReStreet logo.** The main menu and the Press Start screen now show the ReStreet logo. It is applied by a small patch in the new `Mods` folder next to `Game` and `GameData`, which the game applies while reading its files. Your game files are not modified: delete the files in `Mods` to get the original logo back.
+- **Improved "Some" graphics readback, now the default.** The Some mode was reworked to remove the graphical garbage it used to cause on some courts (floor reflections, flickering floor lines) while keeping its speed. It is the default in the Balanced and Quality profiles, and occlusion queries are off by default there. Pick "Full (compatible)" in the Compatibility tab if you prefer the old behaviour. Settings you already saved are kept.
+- **VSync works smoothly.** The old VSync made the game run at only a few FPS on some PCs. VSync now keeps the game locked to your refresh rate with no tearing. Turning VSync off still gives an unlocked frame rate.
+- **Direct play.** Start the game without opening the launcher window: run `FifaStreetLauncher.exe --play`, or click the new **Shortcut** button in the launcher to create a desktop shortcut that does exactly that. It uses the settings you last chose in the launcher and closes by itself after the game exits.
+
+## Fixed
+
+- Setup and launcher layout on any resolution or Windows scale. On some screens (for example a 4K TV set to 1080p with Windows scale at 150%) the controls could be smaller than the window, overlap the title and be cut off.
+- The window follows you when it is moved to a monitor with a different scale.
## Unchanged
@@ -31,4 +34,5 @@ Windows 10 or 11 (64-bit), a CPU with SSSE3, a Direct3D 12 or Vulkan GPU (about
- Performance depends on your hardware and drivers; the profiles are starting points, not guarantees.
- The installer includes generated game binaries. The project's MIT licence does not establish the right to redistribute them, and no legal clearance is claimed.
+- The Mods logo patch is derived from the game's own art.
- This is an unofficial community project, with no affiliation to EA, Microsoft or Xbox.
diff --git a/docs/STATUS.md b/docs/STATUS.md
index f6fefbe..c7db2e3 100644
--- a/docs/STATUS.md
+++ b/docs/STATUS.md
@@ -1,40 +1,41 @@
# Validation and known limitations
-Last updated: **8 October 2026**, for **ReStreet v1.0** (offline only). This page separates what was tested from what was not.
+Last updated: **9 October 2026**, for **ReStreet v1.1** (offline only). This page separates what was tested from what was not.
-## What was tested for v1.0
+## What was tested for v1.1
All of this was tested by the developer on one Windows 11 PC with an AMD Radeon RX 9070 XT, at 100% display scale unless stated.
| Check | Result |
|---|---|
-| Clean installation from the original ISO with the final installer | Passed |
-| Update over an existing installation that has a save | Passed, save kept |
-| Direct3D 12: gameplay | Passed |
-| Vulkan: gameplay | Passed |
-| Windows display scale 125% and 150% (launcher and installer) | Passed |
-| Exit shortcut (START + B) and FPS counter (Home) | Passed |
-| Small screens: launcher shrinks to fit a reduced work area | Checked in a simulated 700 px high work area |
+| ReStreet logos on the main menu and the Press Start screen (final installer, default `Mods` folder) | Passed |
+| Direct play (`--play` and the desktop shortcut) | Passed |
+| Direct3D 12: VSync (paced mode) | Passed |
+| Vulkan: gameplay with the new "Some" readback | Passed |
-The game binaries (main module, game module and World Tour module) are the same as in v0.4.1. World Tour, Practice, Direct3D 12 and Vulkan were validated on earlier releases; this release changes the launcher, installer, overlays and performance options.
+Tested on v1.0 and not repeated for v1.1: clean installation from the original ISO, update over an existing installation with a save, Windows display scale 125% and 150%, the exit shortcut and the FPS counter.
+
+**Not yet tested on v1.1:** a clean installation from the ISO with the v1.1 installer, an update of a v1.0 installation with a save using the v1.1 installer, Vulkan with VSync on.
+
+The game binaries (main module, game module and World Tour module) are the same as in v0.4.1. World Tour, Practice, Direct3D 12 and Vulkan were validated on earlier releases; this release changes the graphics readback, VSync, the launcher, the installer and the logo patch.
## Graphics backends
The package contains two validated backend folders, `Game/Backends/D3D12` and `Game/Backends/Vulkan`. The launcher copies the selected backend's `rexruntime.dll` and `rexgpu-xenos.dll` beside `fifastreet.exe` before launch. Direct3D 12 is the default.
-### SHA-256 of the backend files in v1.0
+### SHA-256 of the backend files in v1.1
| Backend | `rexruntime.dll` | `rexgpu-xenos.dll` |
|---|---|---|
-| Direct3D 12 | `941DA42DFBA505F7F011ED81A6C7F6FD31EA2B3ED717810EF8C3E6EF89B56030` | `CC583314A05B11E49910CE0600E69EDD8B51B4C84D63641B7088916BB95551A2` |
-| Vulkan | `E4DD721D6D080705B8685E14F8437583CCE7DE2A35298BEAE04B4A91372E5E0F` | `B53E030B6C41EC017F97D53F657C9B8850BB5BEDFE2A0A034EE4871F182DC688` |
+| Direct3D 12 | `809AFAD3E2DBDCD68C88B39365FF54EECBEF4E1DE4698A936C2F2D1CC368F4E0` | `9DDB0DD0BB4916A16AB4B757261CDF37E0B0EAB16F40DC9EA76233510E453E7C` |
+| Vulkan | `F3FC94EF7EF154A737C7143FA96874C2225FA84D8577DD9428105524E0B5954E` | `BA05650F760A0C768C60C531854A925CB9E600A8C8E7425B160B6C95FF59251B` |
The installer checks its payload against the hashes in its own manifest before installing.
## Performance options
- **Profiles:** Balanced (the launcher defaults), Quality (2x internal resolution, FXAA Extreme, MSAA), Performance (native resolution, no post-processing, Fast readback, occlusion queries off) and Custom. They only set options the launcher already has.
-- **Readback Resolve:** Full is the validated mode and the default. The Performance profile uses Fast, which gives more FPS under heavy GPU load but has not been validated on other hardware. Some can cause visible graphical corruption and is not used by any profile.
+- **Readback Resolve:** Some is the default in the Balanced and Quality profiles since v1.1: it was reworked to avoid the graphical garbage it used to cause, and it was tested on one GPU only. Full (compatible) is the old default. The Performance profile uses Fast, which gives more FPS under heavy GPU load but has not been validated on other hardware.
- **Shader cache:** a small set of pre-built shaders ships in `Game/shader-seed` and is copied into the player's cache on the first run. It never replaces files the player already has.
## Resolution model
@@ -53,7 +54,7 @@ Output resolution and internal rendering scale are independent. Internal resolut
## Known limitations
- No universal hardware, driver or frame-rate guarantee. 3x/4x internal rendering and 4K output are not guaranteed 60 FPS modes.
-- No online play in v1.0.
+- No online play in v1.1.
- The window title of the game itself still reads "FIFA Street PC"; the launcher and installer use the ReStreet name.
- The exit prompt only opens with the START + B (START + Circle) shortcut, not from the main menu.
- The installer expands its details panel by 180 px, which does not fit on screens 768 px high or less.
diff --git a/patches/rexglue-local-changes.patch b/patches/rexglue-local-changes.patch
index a374407..d1011cb 100644
--- a/patches/rexglue-local-changes.patch
+++ b/patches/rexglue-local-changes.patch
@@ -27,7 +27,7 @@ index 9b3cdf5..51cf584 100644
# Sanitizer support for debugging memory corruption and undefined behavior
if(REXGLUE_ENABLE_SANITIZERS)
diff --git a/include/rex/graphics/command_processor.h b/include/rex/graphics/command_processor.h
-index da8e432..0499356 100644
+index da8e432..5ba6484 100644
--- a/include/rex/graphics/command_processor.h
+++ b/include/rex/graphics/command_processor.h
@@ -75,6 +75,7 @@ enum class GammaRampType {
@@ -38,7 +38,46 @@ index da8e432..0499356 100644
enum class SwapPostEffect {
kNone,
kFxaa,
-@@ -244,6 +245,11 @@ class CommandProcessor {
+@@ -230,6 +231,38 @@ class CommandProcessor {
+ // Shared memexport readback enable state with backend legacy-flag override support.
+ bool IsReadbackMemexportEnabled(bool legacy_backend_flag) const;
+
++ // Adaptive "some" readback. `some` copies a resolve into guest memory only once per range, so that
++ // copy goes stale. When the guest later writes to pages overlapping such a range, shared memory
++ // re-uploads those pages from the stale copy over the newer GPU data, which shows up as garbage.
++ // Ranges that see such invalidations are refreshed on every resolve (like `fast`) for a while;
++ // the rest stay cheap.
++ struct SomeDecision {
++ bool refresh = false; // copy this resolve into guest memory
++ bool sync = false; // the copy slots are older than one frame: read the just-written one
++ };
++ // Render thread: counts one resolve of the range and decides whether to copy it into guest memory.
++ SomeDecision DecideSomeRefresh(uint64_t key, uint32_t address, uint32_t length, uint64_t frame);
++ void NoteSomeRangeSkipped(uint64_t key);
++ void NoteSomeRangeRefreshed(uint64_t key);
++ // Guest thread (called from the shared memory invalidation callback).
++ void OnGuestInvalidatedRange(uint32_t start, uint32_t length);
++
++ struct SomeRangeInfo {
++ uint32_t address = 0, length = 0;
++ uint32_t calls = 0, skipped = 0, refreshed = 0, hits = 0;
++ uint64_t hot_until_frame = 0;
++ uint64_t last_frame = 0;
++ uint64_t first_frame = 0;
++ uint32_t streak = 0; // consecutive resolves on successive frames
++ bool stale = false;
++ };
++ std::mutex some_mutex_;
++ std::unordered_map<uint64_t, SomeRangeInfo> some_ranges_;
++ std::atomic<uint64_t> some_frame_{0};
++ uint32_t some_hit_logs_ = 0;
++ uint64_t some_decisions_ = 0;
++ uint64_t some_last_table_frame_ = 0;
++
+ memory::Memory* memory_ = nullptr;
+ system::KernelState* kernel_state_ = nullptr;
+ GraphicsSystem* graphics_system_ = nullptr;
+@@ -244,6 +277,11 @@ class CommandProcessor {
std::vector<uint32_t> me_bin_;
uint32_t counter_ = 0;
@@ -146,6 +185,38 @@ index 3b0fd61..be2c144 100644
enum class DepthStencilMode : uint32_t {
kNoModifiers,
+diff --git a/include/rex/graphics/shared_memory.h b/include/rex/graphics/shared_memory.h
+index 4d85a2b..4a57875 100644
+--- a/include/rex/graphics/shared_memory.h
++++ b/include/rex/graphics/shared_memory.h
+@@ -10,6 +10,7 @@
+ * @modified Tom Clay, 2026 - Adapted for ReXGlue runtime
+ */
+
++#include <functional>
+ #include <cstdint>
+ #include <mutex>
+ #include <utility>
+@@ -79,6 +80,11 @@ class SharedMemory {
+ bool RequestRanges(const std::pair<uint32_t, uint32_t>* ranges, size_t count);
+ bool RequestRange(uint32_t start, uint32_t length);
+
++ // Called (from guest threads) with the page range invalidated by a guest write.
++ void SetInvalidationObserver(std::function<void(uint32_t, uint32_t)> observer) {
++ invalidation_observer_ = std::move(observer);
++ }
++
+ // Marks the range and, if not exact_range, potentially its surroundings
+ // (to up to the first GPU-written page, as an access violation exception
+ // count optimization) as modified by the CPU, also invalidating GPU-written
+@@ -154,6 +160,7 @@ class SharedMemory {
+ uint32_t host_gpu_memory_sparse_allocations_ = 0;
+ uint32_t host_gpu_memory_sparse_used_bytes_ = 0;
+
++ std::function<void(uint32_t, uint32_t)> invalidation_observer_;
+ void* memory_invalidation_callback_handle_ = nullptr;
+ void* memory_data_provider_handle_ = nullptr;
+
diff --git a/include/rex/graphics/vulkan/command_processor.h b/include/rex/graphics/vulkan/command_processor.h
index 696ff48..a2bdd15 100644
--- a/include/rex/graphics/vulkan/command_processor.h
@@ -1255,8 +1326,96 @@ index 536009e..97f15f4 100644
if (!g_csv_file)
return;
+diff --git a/src/filesystem/devices/host_path_file.cpp b/src/filesystem/devices/host_path_file.cpp
+index 4c57a18..c0d97c9 100644
+--- a/src/filesystem/devices/host_path_file.cpp
++++ b/src/filesystem/devices/host_path_file.cpp
+@@ -12,8 +12,64 @@
+ #include <rex/filesystem/devices/host_path_entry.h>
+ #include <rex/filesystem/devices/host_path_file.h>
+
++#include <algorithm>
++#include <cstdio>
++#include <cstdlib>
++#include <cstring>
++#include <filesystem>
++#include <fstream>
++#include <mutex>
++#include <vector>
++
+ namespace rex::filesystem {
+
++namespace {
++
++// Byte patches served on top of game files, loaded from the folder named by FIFASTREET_MODS.
++// A patch is a file called "<game file>@<hex offset>.bin", for example "[email protected]":
++// its bytes replace the bytes of that game file at that offset whenever the game reads them.
++struct FilePatch {
++ std::string file;
++ uint64_t offset = 0;
++ std::vector<uint8_t> bytes;
++};
++
++std::vector<FilePatch>& Patches() {
++ static std::vector<FilePatch> patches;
++ static std::once_flag loaded;
++ std::call_once(loaded, [] {
++ // Folder of byte patches: FIFASTREET_MODS, or "Mods" next to the Game folder (<install>/Mods).
++ std::filesystem::path dir;
++ if (const char* env = std::getenv("FIFASTREET_MODS"); env && *env) {
++ dir = env;
++ } else {
++ dir = rex::filesystem::GetExecutableFolder().parent_path() / "Mods";
++ }
++ std::error_code ec;
++ if (!std::filesystem::is_directory(dir, ec)) return;
++ for (const auto& item : std::filesystem::directory_iterator(dir, ec)) {
++ if (!item.is_regular_file() || item.path().extension() != ".bin") continue;
++ std::string name = item.path().stem().string();
++ size_t at = name.rfind('@');
++ if (at == std::string::npos) continue;
++ FilePatch patch;
++ patch.file = name.substr(0, at);
++ std::transform(patch.file.begin(), patch.file.end(), patch.file.begin(), [](unsigned char c) { return char(std::tolower(c)); });
++ patch.offset = std::strtoull(name.c_str() + at + 1, nullptr, 16);
++ std::ifstream in(item.path(), std::ios::binary);
++ patch.bytes.assign(std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>());
++ if (!patch.bytes.empty()) {
++ std::fprintf(stderr, "[mods] %s @0x%llx (%zu bytes)", patch.file.c_str(), (unsigned long long)patch.offset, patch.bytes.size());
++ std::fputc(10, stderr);
++ patches.push_back(std::move(patch));
++ }
++ }
++ });
++ return patches;
++}
++
++} // namespace
++
+ HostPathFile::HostPathFile(uint32_t file_access, HostPathEntry* entry,
+ std::unique_ptr<rex::filesystem::FileHandle> file_handle)
+ : File(file_access, entry), file_handle_(std::move(file_handle)) {}
+@@ -31,6 +87,18 @@ X_STATUS HostPathFile::ReadSync(std::span<uint8_t> buffer, size_t byte_offset,
+ }
+
+ if (file_handle_->Read(byte_offset, buffer.data(), buffer.size(), out_bytes_read)) {
++ const auto& patches = Patches();
++ if (!patches.empty() && entry_ && out_bytes_read) {
++ std::string name = entry_->name();
++ std::transform(name.begin(), name.end(), name.begin(), [](unsigned char c) { return char(std::tolower(c)); });
++ const uint64_t start = byte_offset, end = byte_offset + *out_bytes_read;
++ for (const auto& patch : patches) {
++ if (patch.file != name) continue;
++ const uint64_t patch_end = patch.offset + patch.bytes.size();
++ const uint64_t from = std::max(start, patch.offset), to = std::min(end, patch_end);
++ if (from < to) std::memcpy(buffer.data() + (from - start), patch.bytes.data() + (from - patch.offset), size_t(to - from));
++ }
++ }
+ return X_STATUS_SUCCESS;
+ } else {
+ return X_STATUS_END_OF_FILE;
diff --git a/src/graphics/command_processor.cpp b/src/graphics/command_processor.cpp
-index a744375..5d1954e 100644
+index a744375..7970596 100644
--- a/src/graphics/command_processor.cpp
+++ b/src/graphics/command_processor.cpp
@@ -37,6 +37,11 @@
@@ -1271,7 +1430,214 @@ index a744375..5d1954e 100644
REXCVAR_DEFINE_BOOL(clear_memory_page_state, true, "GPU",
"Refresh page-valid state from GPU-written memory at frame end. "
"Disable for minor CPU overhead reduction, but may break memory coherency.")
-@@ -930,6 +935,33 @@ bool CommandProcessor::ExecutePacketType3_XE_SWAP(memory::RingBuffer* reader, ui
+@@ -54,6 +59,61 @@ REXCVAR_DEFINE_STRING(readback_resolve, "none", "GPU",
+ .allowed({"none", "fast", "some", "full"})
+ .lifecycle(rex::cvar::Lifecycle::kHotReload);
+
++REXCVAR_DEFINE_BOOL(readback_some_adaptive, true, "GPU",
++ "In 'some' readback mode, refresh the guest-memory copy of a resolved range "
++ "on every resolve once the guest has written to pages overlapping it "
++ "(prevents stale data being re-uploaded over newer GPU data).")
++ .lifecycle(rex::cvar::Lifecycle::kHotReload);
++
++REXCVAR_DEFINE_INT32(readback_some_hot_frames, 900, "GPU",
++ "How many frames a range stays refreshed after the guest last invalidated it.")
++ .range(1, 100000)
++ .lifecycle(rex::cvar::Lifecycle::kHotReload);
++
++REXCVAR_DEFINE_BOOL(readback_some_refresh_sporadic, true, "GPU",
++ "In 'some' readback mode, always refresh ranges that are not resolved on "
++ "every frame (textures the game builds from GPU results, for example while "
++ "loading). Only ranges resolved every frame are skipped.")
++ .lifecycle(rex::cvar::Lifecycle::kHotReload);
++
++REXCVAR_DEFINE_STRING(readback_some_skip_addrs, "", "GPU",
++ "Comma separated hex start addresses of resolve ranges that 'some' readback "
++ "never refreshes (diagnostics).")
++ .lifecycle(rex::cvar::Lifecycle::kHotReload);
++
++REXCVAR_DEFINE_STRING(readback_some_sync_addrs, "1282B000", "GPU",
++ "Comma separated hex start addresses of resolve ranges that 'some' readback "
++ "always refreshes and reads synchronously (diagnostics).")
++ .lifecycle(rex::cvar::Lifecycle::kHotReload);
++
++REXCVAR_DEFINE_INT32(readback_some_sync_below, 3145728, "GPU",
++ "In 'some' readback mode, ranges smaller than this many bytes that are "
++ "refreshed are read synchronously for the current frame (like 'full'), "
++ "instead of one frame late. 0 = off.")
++ .range(0, 1 << 28)
++ .lifecycle(rex::cvar::Lifecycle::kHotReload);
++
++REXCVAR_DEFINE_BOOL(readback_some_sporadic_sync, true, "GPU",
++ "Read sporadic ranges synchronously (current frame), like 'full'. They are "
++ "rare, so this costs almost nothing, and the game may build textures from them.")
++ .lifecycle(rex::cvar::Lifecycle::kHotReload);
++
++REXCVAR_DEFINE_INT32(readback_some_refresh_interval, 0, "GPU",
++ "In 'some' readback mode, also refresh every range once every N resolves "
++ "(0 = never). Bounds how stale the guest copy can get.")
++ .range(0, 100000)
++ .lifecycle(rex::cvar::Lifecycle::kHotReload);
++
++REXCVAR_DEFINE_INT32(readback_some_refresh_below, 3145728, "GPU",
++ "In 'some' readback mode, always refresh ranges smaller than this many bytes "
++ "(cheap to copy). 0 = off.")
++ .range(0, 1 << 28)
++ .lifecycle(rex::cvar::Lifecycle::kHotReload);
++
++REXCVAR_DEFINE_BOOL(readback_some_log, false, "GPU",
++ "Log the adaptive 'some' readback decisions and guest invalidations.")
++ .lifecycle(rex::cvar::Lifecycle::kHotReload);
++
+ REXCVAR_DEFINE_BOOL(readback_resolve_half_pixel_offset, false, "GPU",
+ "When draw resolution scaling is active, sample from the center of each "
+ "scaled block during resolve readback downscale")
+@@ -181,6 +241,144 @@ ReadbackResolveMode CommandProcessor::GetReadbackResolveMode(
+ : ReadbackResolveMode::kDisabled;
+ }
+
++namespace {
++// Parses a comma separated list of hex addresses; cached by string value.
++bool AddressInList(const std::string& list, uint32_t address) {
++ size_t pos = 0;
++ while (pos < list.size()) {
++ size_t end = list.find(',', pos);
++ if (end == std::string::npos) {
++ end = list.size();
++ }
++ if (end > pos) {
++ const uint32_t value = uint32_t(std::strtoul(list.substr(pos, end - pos).c_str(), nullptr, 16));
++ if (value == address) {
++ return true;
++ }
++ }
++ pos = end + 1;
++ }
++ return false;
++}
++} // namespace
++
++CommandProcessor::SomeDecision CommandProcessor::DecideSomeRefresh(uint64_t key, uint32_t address,
++ uint32_t length,
++ uint64_t frame) {
++ some_frame_.store(frame, std::memory_order_relaxed);
++ SomeDecision decision;
++ std::lock_guard<std::mutex> lock(some_mutex_);
++ SomeRangeInfo& info = some_ranges_[key];
++ info.address = address;
++ info.length = length;
++ ++info.calls;
++ // Frame cadence of this range. Several resolves in one frame say nothing, so they keep the streak.
++ if (info.last_frame != 0 && frame > info.last_frame) {
++ if (frame - info.last_frame <= 2) {
++ ++info.streak;
++ } else {
++ info.streak = 0;
++ }
++ }
++ info.last_frame = frame;
++ if (info.first_frame == 0) {
++ info.first_frame = frame;
++ }
++ // Only a range resolved on at least half of all frames since it was first seen counts as "every frame";
++ // one that is merely resolved in bursts keeps being refreshed.
++ const uint64_t age = frame - info.first_frame;
++ const bool every_frame = info.streak >= 8 && age >= 1200 && uint64_t(info.calls) * 2 >= age;
++ const int32_t interval = REXCVAR_GET(readback_some_refresh_interval);
++ const int32_t below = REXCVAR_GET(readback_some_refresh_below);
++ if (REXCVAR_GET(readback_some_adaptive) && frame <= info.hot_until_frame) {
++ decision.refresh = true;
++ } else if (REXCVAR_GET(readback_some_refresh_sporadic) && !every_frame) {
++ decision.refresh = true;
++ decision.sync = REXCVAR_GET(readback_some_sporadic_sync);
++ } else if (interval > 0 && info.calls % uint32_t(interval) == 0) {
++ decision.refresh = true;
++ } else if (below > 0 && length < uint32_t(below)) {
++ decision.refresh = true;
++ }
++ ++some_decisions_;
++ if (REXCVAR_GET(readback_some_log) && frame >= some_last_table_frame_ + 600) {
++ some_last_table_frame_ = frame;
++ std::vector<std::pair<uint64_t, const SomeRangeInfo*>> rows;
++ for (const auto& [row_key, row] : some_ranges_) {
++ rows.emplace_back(row_key, &row);
++ }
++ std::sort(rows.begin(), rows.end(), [](const auto& a, const auto& b) {
++ return uint64_t(a.second->length) * a.second->calls > uint64_t(b.second->length) * b.second->calls;
++ });
++ REXGPU_INFO("[SOMETABLE] frame={} ranges={} (sorted by bytes resolved)", frame, rows.size());
++ for (size_t i = 0; i < rows.size() && i < 40; ++i) {
++ const SomeRangeInfo& row = *rows[i].second;
++ REXGPU_INFO(
++ "[SOMETABLE] {:08X}+{:X} ({:.2f} MB) calls={} skipped={} refreshed={} streak={} hits={} stale={}",
++ row.address, row.length, row.length / 1048576.0, row.calls, row.skipped, row.refreshed,
++ row.streak, row.hits, row.stale);
++ }
++ }
++ // After skipped resolves the double-buffer slots hold old data, so the first refresh must read
++ // the slot that was just written.
++ const int32_t sync_below = REXCVAR_GET(readback_some_sync_below);
++ if (decision.refresh && sync_below > 0 && length < uint32_t(sync_below)) {
++ decision.sync = true;
++ }
++ decision.sync = decision.sync || (decision.refresh && info.stale);
++ const std::string skip_addrs = REXCVAR_GET(readback_some_skip_addrs);
++ const std::string sync_addrs = REXCVAR_GET(readback_some_sync_addrs);
++ if (!skip_addrs.empty() && AddressInList(skip_addrs, address)) {
++ decision = SomeDecision{};
++ } else if (!sync_addrs.empty() && AddressInList(sync_addrs, address)) {
++ decision.refresh = true;
++ decision.sync = true;
++ }
++ return decision;
++}
++
++void CommandProcessor::NoteSomeRangeSkipped(uint64_t key) {
++ std::lock_guard<std::mutex> lock(some_mutex_);
++ SomeRangeInfo& info = some_ranges_[key];
++ ++info.skipped;
++ info.stale = true;
++}
++
++void CommandProcessor::NoteSomeRangeRefreshed(uint64_t key) {
++ std::lock_guard<std::mutex> lock(some_mutex_);
++ SomeRangeInfo& info = some_ranges_[key];
++ ++info.refreshed;
++ info.stale = false;
++}
++
++void CommandProcessor::OnGuestInvalidatedRange(uint32_t start, uint32_t length) {
++ if (!length) {
++ return;
++ }
++ const uint64_t end = uint64_t(start) + length;
++ const uint64_t frame = some_frame_.load(std::memory_order_relaxed);
++ const bool log = REXCVAR_GET(readback_some_log);
++ const uint64_t hot_frames = uint64_t(REXCVAR_GET(readback_some_hot_frames));
++ std::lock_guard<std::mutex> lock(some_mutex_);
++ for (auto& [key, info] : some_ranges_) {
++ if (uint64_t(info.address) >= end || uint64_t(info.address) + info.length <= start) {
++ continue;
++ }
++ ++info.hits;
++ if (info.stale) {
++ info.hot_until_frame = frame + hot_frames;
++ }
++ if (log && some_hit_logs_ < 200) {
++ ++some_hit_logs_;
++ REXGPU_INFO(
++ "[SOME] guest invalidated {:08X}+{:X} over range {:08X}+{:X} (key {:016X}, calls={} "
++ "skipped={} refreshed={} stale={} hits={})",
++ start, length, info.address, info.length, key, info.calls, info.skipped, info.refreshed,
++ info.stale, info.hits);
++ }
++ }
++}
++
+ bool CommandProcessor::IsReadbackMemexportEnabled(bool legacy_backend_flag) const {
+ if (legacy_readback_memexport_cvar_name_ &&
+ rex::cvar::HasNonDefaultValue(legacy_readback_memexport_cvar_name_)) {
+@@ -930,6 +1128,33 @@ bool CommandProcessor::ExecutePacketType3_XE_SWAP(memory::RingBuffer* reader, ui
uint32_t count) {
SCOPE_profile_cpu_f("gpu");
@@ -1305,7 +1671,7 @@ index a744375..5d1954e 100644
#ifdef REXGLUE_ENABLE_PERF_COUNTERS
{
static uint64_t last_frame_tick = 0;
-@@ -943,6 +975,7 @@ bool CommandProcessor::ExecutePacketType3_XE_SWAP(memory::RingBuffer* reader, ui
+@@ -943,6 +1168,7 @@ bool CommandProcessor::ExecutePacketType3_XE_SWAP(memory::RingBuffer* reader, ui
last_frame_tick = now;
}
#endif
@@ -1314,7 +1680,7 @@ index a744375..5d1954e 100644
// Xenia-specific VdSwap hook.
diff --git a/src/graphics/d3d12/command_processor.cpp b/src/graphics/d3d12/command_processor.cpp
-index 19874a5..054a8f3 100644
+index 19874a5..a75c56d 100644
--- a/src/graphics/d3d12/command_processor.cpp
+++ b/src/graphics/d3d12/command_processor.cpp
@@ -10,6 +10,7 @@
@@ -1344,7 +1710,16 @@ index 19874a5..054a8f3 100644
REXCVAR_DEFINE_BOOL(d3d12_readback_memexport, false, "GPU/D3D12",
"Read data written by memory export in shaders on the CPU")
.lifecycle(rex::cvar::Lifecycle::kHotReload);
-@@ -1672,6 +1685,11 @@ void D3D12CommandProcessor::ShutdownContext() {
+@@ -930,6 +943,8 @@ bool D3D12CommandProcessor::SetupContext() {
+ REXGPU_ERROR("Failed to initialize shared memory");
+ return false;
+ }
++ shared_memory_->SetInvalidationObserver(
++ [this](uint32_t start, uint32_t length) { OnGuestInvalidatedRange(start, length); });
+
+ // Initialize the render target cache before configuring binding - need to
+ // know if using rasterizer-ordered views for the bindless root signature.
+@@ -1672,6 +1687,11 @@ void D3D12CommandProcessor::ShutdownContext() {
scratch_buffer_size_ = 0;
resolve_downscale_buffer_size_ = 0;
resolve_downscale_buffer_.Reset();
@@ -1356,7 +1731,17 @@ index 19874a5..054a8f3 100644
for (const std::pair<uint64_t, ID3D12Resource*>& resource_for_deletion :
resources_for_deletion_) {
-@@ -2784,6 +2802,11 @@ bool D3D12CommandProcessor::IssueDraw_MemexportReadbackFastPath(uint32_t total_s
+@@ -1735,6 +1755,9 @@ void D3D12CommandProcessor::ShutdownContext() {
+
+ render_target_cache_.reset();
+
++ if (shared_memory_) {
++ shared_memory_->SetInvalidationObserver(nullptr);
++ }
+ shared_memory_.reset();
+
+ deferred_command_list_.Reset();
+@@ -2784,6 +2807,11 @@ bool D3D12CommandProcessor::IssueDraw_MemexportReadbackFastPath(uint32_t total_s
MakeMemexportReadbackKey(memexport_ranges_.front().base_address_dwords, total_size);
ReadbackBuffer& readback = memexport_readback_buffers_[readback_key];
readback.last_used_frame = frame_current_;
@@ -1368,7 +1753,7 @@ index 19874a5..054a8f3 100644
auto ensure_readback_slot = [&](uint32_t index, uint32_t size) -> bool {
if (readback.buffers[index] && readback.mapped_data[index] && size <= readback.sizes[index]) {
-@@ -2847,11 +2870,13 @@ bool D3D12CommandProcessor::IssueDraw_MemexportReadbackFastPath(uint32_t total_s
+@@ -2847,11 +2875,13 @@ bool D3D12CommandProcessor::IssueDraw_MemexportReadbackFastPath(uint32_t total_s
}
readback.submission_written[write_index] = submission_current_;
readback.written_size[write_index] = total_size;
@@ -1382,7 +1767,7 @@ index 19874a5..054a8f3 100644
readback.submission_written[read_index] &&
readback.submission_written[read_index] <= submission_completed_;
if (!previous_slot_ready) {
-@@ -2887,6 +2912,54 @@ bool D3D12CommandProcessor::IssueCopy() {
+@@ -2887,6 +2917,54 @@ bool D3D12CommandProcessor::IssueCopy() {
}
bool D3D12CommandProcessor::IssueCopy_ReadbackResolvePath() {
@@ -1437,7 +1822,7 @@ index 19874a5..054a8f3 100644
uint32_t written_address, written_length;
if (!render_target_cache_->Resolve(*memory_, *shared_memory_, *texture_cache_, written_address,
written_length)) {
-@@ -2897,14 +2970,34 @@ bool D3D12CommandProcessor::IssueCopy_ReadbackResolvePath() {
+@@ -2897,14 +2975,39 @@ bool D3D12CommandProcessor::IssueCopy_ReadbackResolvePath() {
return true;
}
@@ -1465,14 +1850,19 @@ index 19874a5..054a8f3 100644
+ // Some only copies into guest memory on a cache miss. Once both slots are
+ // initialized, recording another GPU-to-CPU copy cannot change its result.
+ // Keep Resolve above: subsequent draws still need the GPU-side texture data.
-+ if (readback_mode == ReadbackResolveMode::kSome && rb.mapped_data[0] && rb.mapped_data[1] &&
-+ rb.written_size[0] >= written_length && rb.written_size[1] >= written_length) {
-+ return true;
++ SomeDecision some_decision;
++ if (readback_mode == ReadbackResolveMode::kSome) {
++ some_decision = DecideSomeRefresh(resolve_key, written_address, written_length, frame_current_);
++ if (!some_decision.refresh && rb.mapped_data[0] && rb.mapped_data[1] &&
++ rb.written_size[0] >= written_length && rb.written_size[1] >= written_length) {
++ NoteSomeRangeSkipped(resolve_key);
++ return true;
++ }
+ }
uint32_t write_index = rb.current_index;
uint32_t size = AlignReadbackBufferSize(written_length);
-@@ -2922,6 +3015,10 @@ bool D3D12CommandProcessor::IssueCopy_ReadbackResolvePath() {
+@@ -2922,6 +3025,10 @@ bool D3D12CommandProcessor::IssueCopy_ReadbackResolvePath() {
return true;
}
if (rb.buffers[write_index]) {
@@ -1483,7 +1873,7 @@ index 19874a5..054a8f3 100644
if (rb.mapped_data[write_index]) {
rb.buffers[write_index]->Unmap(0, nullptr);
rb.mapped_data[write_index] = nullptr;
-@@ -3055,6 +3152,10 @@ bool D3D12CommandProcessor::IssueCopy_ReadbackResolvePath() {
+@@ -3055,6 +3162,10 @@ bool D3D12CommandProcessor::IssueCopy_ReadbackResolvePath() {
PushTransitionBarrier(resolve_downscale_buffer_.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
D3D12_RESOURCE_STATE_COPY_SOURCE);
SubmitBarriers();
@@ -1494,7 +1884,7 @@ index 19874a5..054a8f3 100644
deferred_command_list_.D3DCopyBufferRegion(rb.buffers[write_index], 0,
resolve_downscale_buffer_.Get(), 0, written_length);
PushTransitionBarrier(resolve_downscale_buffer_.Get(), D3D12_RESOURCE_STATE_COPY_SOURCE,
-@@ -3065,20 +3166,62 @@ bool D3D12CommandProcessor::IssueCopy_ReadbackResolvePath() {
+@@ -3065,23 +3176,65 @@ bool D3D12CommandProcessor::IssueCopy_ReadbackResolvePath() {
shared_memory_->UseAsCopySource();
SubmitBarriers();
ID3D12Resource* shared_memory_buffer = shared_memory_->GetBuffer();
@@ -1558,12 +1948,21 @@ index 19874a5..054a8f3 100644
+ }
+ }
bool is_cache_miss = false;
- if (use_delayed_sync && (!rb.buffers[read_index] || written_length > rb.sizes[read_index] ||
- !rb.mapped_data[read_index])) {
-@@ -3090,6 +3233,13 @@ bool D3D12CommandProcessor::IssueCopy_ReadbackResolvePath() {
+- if (use_delayed_sync && (!rb.buffers[read_index] || written_length > rb.sizes[read_index] ||
+- !rb.mapped_data[read_index])) {
++ if (use_delayed_sync && (some_decision.sync || !rb.buffers[read_index] ||
++ written_length > rb.sizes[read_index] || !rb.mapped_data[read_index])) {
+ is_cache_miss = true;
+ read_index = write_index;
+ if (!AwaitAllQueueOperationsCompletion()) {
+@@ -3089,7 +3242,16 @@ bool D3D12CommandProcessor::IssueCopy_ReadbackResolvePath() {
+ }
}
- bool should_copy = (readback_mode == ReadbackResolveMode::kSome) ? is_cache_miss : true;
+- bool should_copy = (readback_mode == ReadbackResolveMode::kSome) ? is_cache_miss : true;
++ bool should_copy = (readback_mode == ReadbackResolveMode::kSome)
++ ? (is_cache_miss || some_decision.refresh)
++ : true;
+ if (should_copy && rb.submission_written[read_index] &&
+ rb.submission_written[read_index] > submission_completed_) {
+ CheckSubmissionFence(rb.submission_written[read_index]);
@@ -1574,8 +1973,17 @@ index 19874a5..054a8f3 100644
if (should_copy && rb.buffers[read_index] && written_length <= rb.sizes[read_index] &&
rb.mapped_data[read_index]) {
uint8_t* destination = memory_->TranslatePhysical(written_address);
-@@ -3099,10 +3249,67 @@ bool D3D12CommandProcessor::IssueCopy_ReadbackResolvePath() {
+@@ -3097,12 +3259,76 @@ bool D3D12CommandProcessor::IssueCopy_ReadbackResolvePath() {
+ std::memcpy(destination, static_cast<uint8_t*>(rb.mapped_data[read_index]), written_length);
+ }
}
++ if (readback_mode == ReadbackResolveMode::kSome) {
++ if (should_copy) {
++ NoteSomeRangeRefreshed(resolve_key);
++ } else {
++ NoteSomeRangeSkipped(resolve_key);
++ }
++ }
rb.current_index = 1 - rb.current_index;
+ if (measure) {
@@ -1643,7 +2051,7 @@ index 19874a5..054a8f3 100644
if (await_submission >= submission_current_) {
if (submission_open_) {
EndSubmission(false);
-@@ -3114,9 +3321,9 @@ void D3D12CommandProcessor::CheckSubmissionFence(uint64_t await_submission) {
+@@ -3114,9 +3340,9 @@ void D3D12CommandProcessor::CheckSubmissionFence(uint64_t await_submission) {
if (queue_operations_done_since_submission_signal_) {
UINT64 fence_value = ++queue_operations_since_submission_fence_last_;
ID3D12CommandQueue* direct_queue = GetD3D12Provider().GetDirectQueue();
@@ -1656,7 +2064,7 @@ index 19874a5..054a8f3 100644
PROFILE_CMD_BUFFER_STALL();
WaitForSingleObject(fence_completion_event_, INFINITE);
queue_operations_done_since_submission_signal_ = false;
-@@ -3131,8 +3338,22 @@ void D3D12CommandProcessor::CheckSubmissionFence(uint64_t await_submission) {
+@@ -3131,8 +3357,22 @@ void D3D12CommandProcessor::CheckSubmissionFence(uint64_t await_submission) {
await_submission = submission_current_ - 1;
}
@@ -1679,7 +2087,7 @@ index 19874a5..054a8f3 100644
if (submission_completed_ < await_submission) {
if (SUCCEEDED(
submission_fence_->SetEventOnCompletion(await_submission, fence_completion_event_))) {
-@@ -3144,6 +3365,23 @@ void D3D12CommandProcessor::CheckSubmissionFence(uint64_t await_submission) {
+@@ -3144,6 +3384,23 @@ void D3D12CommandProcessor::CheckSubmissionFence(uint64_t await_submission) {
if (submission_completed_ < await_submission) {
REXGPU_ERROR("Failed to await a submission completion Direct3D 12 fence");
}
@@ -1703,7 +2111,7 @@ index 19874a5..054a8f3 100644
if (submission_completed_ <= submission_completed_before) {
// Not updated - no need to reclaim or download things.
return;
-@@ -3302,6 +3540,12 @@ bool D3D12CommandProcessor::BeginSubmission(bool is_guest_command) {
+@@ -3302,6 +3559,12 @@ bool D3D12CommandProcessor::BeginSubmission(bool is_guest_command) {
// end of the submission (when async pipeline creation requests are
// fulfilled).
deferred_command_list_.Reset();
@@ -1716,7 +2124,7 @@ index 19874a5..054a8f3 100644
// Reset cached state of the command list.
ff_viewport_update_needed_ = true;
-@@ -4432,7 +4676,7 @@ bool D3D12CommandProcessor::UpdateBindings(const D3D12Shader* vertex_shader,
+@@ -4432,7 +4695,7 @@ bool D3D12CommandProcessor::UpdateBindings(const D3D12Shader* vertex_shader,
for (size_t i = 0; i < texture_count_pixel; ++i) {
const D3D12Shader::TextureBinding& texture = (*textures_pixel)[i];
descriptor_indices[texture.bindless_descriptor_index] =
@@ -1725,7 +2133,7 @@ index 19874a5..054a8f3 100644
uint32_t(SystemBindlessView::kUnboundedSRVsStart);
}
current_texture_layout_uid_pixel_ = texture_layout_uid_pixel;
-@@ -4755,7 +4999,10 @@ void D3D12CommandProcessor::EvictOldReadbackBuffers(
+@@ -4755,7 +5018,10 @@ void D3D12CommandProcessor::EvictOldReadbackBuffers(
ReadbackBuffer& readback = it->second;
bool evict =
buffer_map.size() > kMaxReadbackBuffers || readback.last_used_frame < eviction_frame_floor;
@@ -2452,6 +2860,22 @@ index 0000000..fb3ad69
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0,
+};
+diff --git a/src/graphics/shared_memory.cpp b/src/graphics/shared_memory.cpp
+index ec0df7c..2ac72b9 100644
+--- a/src/graphics/shared_memory.cpp
++++ b/src/graphics/shared_memory.cpp
+@@ -530,6 +530,11 @@ std::pair<uint32_t, uint32_t> SharedMemory::MemoryInvalidationCallback(
+
+ FireWatches(page_first, page_last, false);
+
++ if (invalidation_observer_) {
++ invalidation_observer_(page_first << page_size_log2_,
++ (page_last - page_first + 1) << page_size_log2_);
++ }
++
+ return std::make_pair(page_first << page_size_log2_, (page_last - page_first + 1)
+ << page_size_log2_);
+ }
diff --git a/src/graphics/util/draw_extent_estimator.cpp b/src/graphics/util/draw_extent_estimator.cpp
index 3027dc8..54f77a9 100644
--- a/src/graphics/util/draw_extent_estimator.cpp
@@ -2466,7 +2890,7 @@ index 3027dc8..54f77a9 100644
REXCVAR_DEFINE_BOOL(execute_unclipped_draw_vs_on_cpu_with_scissor, false, "GPU",
diff --git a/src/graphics/vulkan/command_processor.cpp b/src/graphics/vulkan/command_processor.cpp
-index 001f36b..8f35864 100644
+index 001f36b..71fee31 100644
--- a/src/graphics/vulkan/command_processor.cpp
+++ b/src/graphics/vulkan/command_processor.cpp
@@ -11,6 +11,7 @@
@@ -2507,7 +2931,26 @@ index 001f36b..8f35864 100644
REXCVAR_DEFINE_BOOL(vulkan_readback_resolve, false, "GPU/Vulkan",
"Read render-to-texture results on the CPU")
.lifecycle(rex::cvar::Lifecycle::kHotReload);
-@@ -2059,10 +2073,16 @@ void VulkanCommandProcessor::ShutdownContext() {
+@@ -896,6 +910,8 @@ bool VulkanCommandProcessor::SetupContext() {
+ REXGPU_ERROR("Failed to initialize shared memory");
+ return false;
+ }
++ shared_memory_->SetInvalidationObserver(
++ [this](uint32_t start, uint32_t length) { OnGuestInvalidatedRange(start, length); });
+
+ primitive_processor_ =
+ std::make_unique<VulkanPrimitiveProcessor>(*register_file_, *memory_, *shared_memory_, *this);
+@@ -2026,6 +2042,9 @@ void VulkanCommandProcessor::ShutdownContext() {
+
+ primitive_processor_.reset();
+
++ if (shared_memory_) {
++ shared_memory_->SetInvalidationObserver(nullptr);
++ }
+ shared_memory_.reset();
+
+ ClearTransientDescriptorPools();
+@@ -2059,10 +2078,16 @@ void VulkanCommandProcessor::ShutdownContext() {
deferred_command_buffer_.Reset();
for (const auto& command_buffer_pair : command_buffers_submitted_) {
@@ -2524,7 +2967,7 @@ index 001f36b..8f35864 100644
dfn.vkDestroyCommandPool(device, command_buffer.pool, nullptr);
}
command_buffers_writable_.clear();
-@@ -3822,7 +3842,7 @@ bool VulkanCommandProcessor::IssueDraw(xenos::PrimitiveType prim_type, uint32_t
+@@ -3822,7 +3847,7 @@ bool VulkanCommandProcessor::IssueDraw(xenos::PrimitiveType prim_type, uint32_t
uint64_t sampler_overflow_await_submission =
texture_cache_->GetSubmissionToAwaitOnSamplerOverflow(samplers_overflowed_count);
assert_true(sampler_overflow_await_submission <= GetCurrentSubmission());
@@ -2533,7 +2976,7 @@ index 001f36b..8f35864 100644
}
uint32_t normalized_color_mask =
-@@ -4154,6 +4174,8 @@ bool VulkanCommandProcessor::IssueDraw(xenos::PrimitiveType prim_type, uint32_t
+@@ -4154,6 +4179,8 @@ bool VulkanCommandProcessor::IssueDraw(xenos::PrimitiveType prim_type, uint32_t
0, 0, 0);
}
@@ -2542,7 +2985,7 @@ index 001f36b..8f35864 100644
// Invalidate textures in memexported memory and watch for changes.
if (!memexport_ranges_.empty()) {
for (const draw_util::MemExportRange& memexport_range : memexport_ranges_) {
-@@ -4222,7 +4244,7 @@ bool VulkanCommandProcessor::IssueDraw_MemexportReadbackFullPath(uint32_t total_
+@@ -4222,7 +4249,7 @@ bool VulkanCommandProcessor::IssueDraw_MemexportReadbackFullPath(uint32_t total_
VK_PIPELINE_STAGE_HOST_BIT, VK_ACCESS_TRANSFER_WRITE_BIT,
VK_ACCESS_HOST_READ_BIT);
@@ -2551,7 +2994,7 @@ index 001f36b..8f35864 100644
REXGPU_ERROR("Failed to await completion of Vulkan memexport readback");
dfn.vkDestroyBuffer(device, readback_buffer, nullptr);
dfn.vkFreeMemory(device, readback_memory, nullptr);
-@@ -4297,7 +4319,7 @@ bool VulkanCommandProcessor::IssueDraw_MemexportReadbackFastPath(uint32_t total_
+@@ -4297,7 +4324,7 @@ bool VulkanCommandProcessor::IssueDraw_MemexportReadbackFastPath(uint32_t total_
}
if (readback.buffers[index] != VK_NULL_HANDLE || readback.memories[index] != VK_NULL_HANDLE) {
@@ -2560,7 +3003,7 @@ index 001f36b..8f35864 100644
dfn.vkUnmapMemory(device, new_memory);
dfn.vkDestroyBuffer(device, new_buffer, nullptr);
dfn.vkFreeMemory(device, new_memory, nullptr);
-@@ -4381,6 +4403,11 @@ bool VulkanCommandProcessor::IssueDraw_MemexportReadbackFastPath(uint32_t total_
+@@ -4381,6 +4408,11 @@ bool VulkanCommandProcessor::IssueDraw_MemexportReadbackFastPath(uint32_t total_
return true;
}
@@ -2572,7 +3015,7 @@ index 001f36b..8f35864 100644
bool VulkanCommandProcessor::IssueCopy() {
#if XE_GPU_FINE_GRAINED_DRAW_SCOPES
SCOPE_profile_cpu_f("gpu");
-@@ -4448,7 +4475,7 @@ bool VulkanCommandProcessor::IssueCopy_ReadbackResolvePath() {
+@@ -4448,7 +4480,7 @@ bool VulkanCommandProcessor::IssueCopy_ReadbackResolvePath() {
}
if (readback.buffers[index] != VK_NULL_HANDLE || readback.memories[index] != VK_NULL_HANDLE) {
@@ -2581,7 +3024,18 @@ index 001f36b..8f35864 100644
dfn.vkUnmapMemory(device, new_memory);
dfn.vkDestroyBuffer(device, new_buffer, nullptr);
dfn.vkFreeMemory(device, new_memory, nullptr);
-@@ -4515,7 +4542,20 @@ bool VulkanCommandProcessor::IssueCopy_ReadbackResolvePath() {
+@@ -4476,6 +4508,10 @@ bool VulkanCommandProcessor::IssueCopy_ReadbackResolvePath() {
+ uint64_t resolve_key = MakeReadbackResolveKey(written_address, written_length);
+ ReadbackBuffer& readback = readback_buffers_[resolve_key];
+ readback.last_used_frame = frame_current_;
++ SomeDecision some_decision;
++ if (readback_mode == ReadbackResolveMode::kSome) {
++ some_decision = DecideSomeRefresh(resolve_key, written_address, written_length, frame_current_);
++ }
+ uint32_t write_index = readback.current_index;
+ uint32_t readback_size = AlignReadbackBufferSize(written_length);
+ if (!ensure_readback_slot(readback, write_index, readback_size)) {
+@@ -4515,7 +4551,20 @@ bool VulkanCommandProcessor::IssueCopy_ReadbackResolvePath() {
}
VkBuffer scaled_resolve_buffer = texture_cache_->scaled_resolve_buffer();
@@ -2603,7 +3057,7 @@ index 001f36b..8f35864 100644
return true;
}
-@@ -4533,7 +4573,7 @@ bool VulkanCommandProcessor::IssueCopy_ReadbackResolvePath() {
+@@ -4533,7 +4582,7 @@ bool VulkanCommandProcessor::IssueCopy_ReadbackResolvePath() {
}
if (resolve_downscale_buffer_ != VK_NULL_HANDLE ||
resolve_downscale_buffer_memory_ != VK_NULL_HANDLE) {
@@ -2612,7 +3066,7 @@ index 001f36b..8f35864 100644
dfn.vkDestroyBuffer(device, new_buffer, nullptr);
dfn.vkFreeMemory(device, new_memory, nullptr);
return true;
-@@ -4561,8 +4601,8 @@ bool VulkanCommandProcessor::IssueCopy_ReadbackResolvePath() {
+@@ -4561,8 +4610,8 @@ bool VulkanCommandProcessor::IssueCopy_ReadbackResolvePath() {
VkDescriptorBufferInfo buffer_infos[2] = {};
buffer_infos[0].buffer = scaled_resolve_buffer;
@@ -2623,7 +3077,7 @@ index 001f36b..8f35864 100644
buffer_infos[1].buffer = resolve_downscale_buffer_;
buffer_infos[1].offset = 0;
buffer_infos[1].range = written_length;
-@@ -4601,7 +4641,7 @@ bool VulkanCommandProcessor::IssueCopy_ReadbackResolvePath() {
+@@ -4601,7 +4650,7 @@ bool VulkanCommandProcessor::IssueCopy_ReadbackResolvePath() {
constants.scale_y = texture_cache_->draw_resolution_scale_y();
constants.pixel_size_log2 = pixel_size_log2;
constants.tile_count = tile_count;
@@ -2632,7 +3086,7 @@ index 001f36b..8f35864 100644
constants.half_pixel_offset = (REXCVAR_GET(readback_resolve_half_pixel_offset) &&
(constants.scale_x > 1 || constants.scale_y > 1))
? 1u
-@@ -4649,12 +4689,16 @@ bool VulkanCommandProcessor::IssueCopy_ReadbackResolvePath() {
+@@ -4649,27 +4698,67 @@ bool VulkanCommandProcessor::IssueCopy_ReadbackResolvePath() {
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT,
VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT);
@@ -2650,7 +3104,10 @@ index 001f36b..8f35864 100644
return true;
}
-@@ -4664,11 +4708,38 @@ bool VulkanCommandProcessor::IssueCopy_ReadbackResolvePath() {
+ bool is_cache_miss = false;
+- if (use_delayed_sync && (readback.buffers[read_index] == VK_NULL_HANDLE ||
++ if (use_delayed_sync && (some_decision.sync || readback.buffers[read_index] == VK_NULL_HANDLE ||
+ written_length > readback.sizes[read_index] ||
readback.mapped_data[read_index] == nullptr)) {
is_cache_miss = true;
read_index = write_index;
@@ -2660,6 +3117,7 @@ index 001f36b..8f35864 100644
}
}
+- bool should_copy = (readback_mode == ReadbackResolveMode::kSome) ? is_cache_miss : true;
+ if (measure_resolve_wait && (!use_delayed_sync || is_cache_miss)) {
+ struct ResolveWaitRange {
+ double milliseconds = 0;
@@ -2687,10 +3145,20 @@ index 001f36b..8f35864 100644
+ }
+ }
+
- bool should_copy = (readback_mode == ReadbackResolveMode::kSome) ? is_cache_miss : true;
++ bool should_copy = (readback_mode == ReadbackResolveMode::kSome)
++ ? (is_cache_miss || some_decision.refresh)
++ : true;
++ if (readback_mode == ReadbackResolveMode::kSome) {
++ if (should_copy) {
++ NoteSomeRangeRefreshed(resolve_key);
++ } else {
++ NoteSomeRangeSkipped(resolve_key);
++ }
++ }
if (should_copy && readback.buffers[read_index] != VK_NULL_HANDLE &&
written_length <= readback.sizes[read_index] && readback.mapped_data[read_index] != nullptr) {
-@@ -4682,6 +4753,28 @@ bool VulkanCommandProcessor::IssueCopy_ReadbackResolvePath() {
+ VkMappedMemoryRange readback_memory_range = {};
+@@ -4682,6 +4771,28 @@ bool VulkanCommandProcessor::IssueCopy_ReadbackResolvePath() {
uint8_t* destination = memory_->TranslatePhysical(written_address);
if (destination) {
std::memcpy(destination, readback.mapped_data[read_index], written_length);
@@ -2719,7 +3187,7 @@ index 001f36b..8f35864 100644
}
}
-@@ -4886,7 +4979,7 @@ bool VulkanCommandProcessor::EndGuestOcclusionQuery(uint32_t sample_count_addres
+@@ -4886,7 +4997,7 @@ bool VulkanCommandProcessor::EndGuestOcclusionQuery(uint32_t sample_count_addres
if (!EndSubmission(false)) {
return false;
}
@@ -2728,7 +3196,7 @@ index 001f36b..8f35864 100644
return false;
}
-@@ -4943,7 +5036,8 @@ void VulkanCommandProcessor::WriteGuestOcclusionResult(uint32_t sample_count_add
+@@ -4943,7 +5054,8 @@ void VulkanCommandProcessor::WriteGuestOcclusionResult(uint32_t sample_count_add
sample_counts->StencilFail_B = 0;
}
@@ -2738,7 +3206,7 @@ index 001f36b..8f35864 100644
// Only report once, no need to retry a wait that won't succeed anyway.
if (device_lost_) {
return;
-@@ -4951,7 +5045,12 @@ void VulkanCommandProcessor::CheckSubmissionFenceAndDeviceLoss(uint64_t await_su
+@@ -4951,7 +5063,12 @@ void VulkanCommandProcessor::CheckSubmissionFenceAndDeviceLoss(uint64_t await_su
if (await_submission >= GetCurrentSubmission()) {
if (submission_open_) {
@@ -2751,7 +3219,7 @@ index 001f36b..8f35864 100644
}
// A submission won't be ended if it hasn't been started, or if ending
// has failed - clamp the index.
-@@ -4965,14 +5064,40 @@ void VulkanCommandProcessor::CheckSubmissionFenceAndDeviceLoss(uint64_t await_su
+@@ -4965,14 +5082,40 @@ void VulkanCommandProcessor::CheckSubmissionFenceAndDeviceLoss(uint64_t await_su
size_t fences_total = submissions_in_flight_fences_.size();
size_t fences_awaited = 0;
if (await_submission > submission_completed_) {
@@ -2800,7 +3268,7 @@ index 001f36b..8f35864 100644
if (wait_result == VK_SUCCESS) {
fences_awaited += await_submission - submission_completed_;
} else {
-@@ -5032,11 +5157,35 @@ void VulkanCommandProcessor::CheckSubmissionFenceAndDeviceLoss(uint64_t await_su
+@@ -5032,11 +5175,35 @@ void VulkanCommandProcessor::CheckSubmissionFenceAndDeviceLoss(uint64_t await_su
if (command_buffer_pair.first > submission_completed_) {
break;
}
@@ -2836,7 +3304,7 @@ index 001f36b..8f35864 100644
primitive_processor_->CompletedSubmissionUpdated();
-@@ -5111,7 +5260,7 @@ bool VulkanCommandProcessor::BeginSubmission(bool is_guest_command) {
+@@ -5111,7 +5278,7 @@ bool VulkanCommandProcessor::BeginSubmission(bool is_guest_command) {
// is still available, and whether the await was successful.
uint64_t await_submission =
is_opening_frame ? closed_frame_submissions_[frame_current_ % kMaxFramesInFlight] : 0;
@@ -2845,7 +3313,7 @@ index 001f36b..8f35864 100644
if (device_lost_ || submission_completed_ < await_submission) {
return false;
}
-@@ -5284,6 +5433,9 @@ bool VulkanCommandProcessor::EndSubmission(bool is_swap) {
+@@ -5284,6 +5451,9 @@ bool VulkanCommandProcessor::EndSubmission(bool is_swap) {
if (dfn.vkAllocateCommandBuffers(device, &command_buffer_allocate_info,
&command_buffer.buffer) != VK_SUCCESS) {
REXGPU_ERROR("Failed to allocate a Vulkan command buffer");
@@ -2855,7 +3323,7 @@ index 001f36b..8f35864 100644
dfn.vkDestroyCommandPool(device, command_buffer.pool, nullptr);
return false;
}
-@@ -5372,6 +5524,32 @@ bool VulkanCommandProcessor::EndSubmission(bool is_swap) {
+@@ -5372,6 +5542,32 @@ bool VulkanCommandProcessor::EndSubmission(bool is_swap) {
assert_false(command_buffers_writable_.empty());
CommandBuffer command_buffer = command_buffers_writable_.back();
@@ -2888,7 +3356,7 @@ index 001f36b..8f35864 100644
if (dfn.vkResetCommandPool(device, command_buffer.pool, 0) != VK_SUCCESS) {
REXGPU_ERROR("Failed to reset a Vulkan command pool");
return false;
-@@ -5385,7 +5563,14 @@ bool VulkanCommandProcessor::EndSubmission(bool is_swap) {
+@@ -5385,7 +5581,14 @@ bool VulkanCommandProcessor::EndSubmission(bool is_swap) {
REXGPU_ERROR("Failed to begin a Vulkan command buffer");
return false;
}
@@ -2903,7 +3371,7 @@ index 001f36b..8f35864 100644
if (dfn.vkEndCommandBuffer(command_buffer.buffer) != VK_SUCCESS) {
REXGPU_ERROR("Failed to end a Vulkan command buffer");
return false;
-@@ -5452,7 +5637,7 @@ bool VulkanCommandProcessor::EndSubmission(bool is_swap) {
+@@ -5452,7 +5655,7 @@ bool VulkanCommandProcessor::EndSubmission(bool is_swap) {
// Submission already closed now, so minus 1.
closed_frame_submissions_[(frame_current_++) % kMaxFramesInFlight] = GetCurrentSubmission() - 1;
@@ -2912,7 +3380,7 @@ index 001f36b..8f35864 100644
cache_clear_requested_ = false;
DestroyScratchBuffer();
-@@ -5464,6 +5649,9 @@ bool VulkanCommandProcessor::EndSubmission(bool is_swap) {
+@@ -5464,6 +5667,9 @@ bool VulkanCommandProcessor::EndSubmission(bool is_swap) {
assert_true(command_buffers_submitted_.empty());
for (const CommandBuffer& command_buffer : command_buffers_writable_) {