Skip to content

Commit d1e333b

Browse files
committed
graphics/autotesting: skip backbuffer-clamp-to-window under autotesting
ConfirmRenderingSettings clamps the requested back-buffer size to fit Window.ClientBounds — fine for dev, wrong for headless CI capture (a portrait 640x1136 sample gets clipped to 640x749 on a shorter desktop). Adds SkipBackBufferClampToWindow on GraphicsDeviceManager (copied to PresentationParameters in ChangeOrCreateDevice). ConfirmRenderingSettings honours it; the Vulkan swap-chain creation also bypasses surfaceCapabilities.currentExtent when set. The autotesting harness sets the flag in OnGameStarted, before device creation.
1 parent 0b13c0b commit d1e333b

4 files changed

Lines changed: 21 additions & 4 deletions

File tree

sources/engine/Stride.Engine/Engine/Game.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,15 @@ public override void ConfirmRenderingSettings(bool gameCreation)
310310

311311
var deviceManager = (GraphicsDeviceManager)graphicsDeviceManager;
312312

313-
if (gameCreation)
313+
if (gameCreation && !deviceManager.SkipBackBufferClampToWindow)
314314
{
315315
//if our device width or height is actually smaller then requested we use the device one
316316
deviceManager.PreferredBackBufferWidth = Context.RequestedWidth = Math.Min(deviceManager.PreferredBackBufferWidth, Window.ClientBounds.Width);
317317
deviceManager.PreferredBackBufferHeight = Context.RequestedHeight = Math.Min(deviceManager.PreferredBackBufferHeight, Window.ClientBounds.Height);
318318
}
319319

320320
//these might get triggered even during game runtime, resize, orientation change
321-
if (renderingSettings != null && renderingSettings.AdaptBackBufferToScreen)
321+
if (!deviceManager.SkipBackBufferClampToWindow && renderingSettings != null && renderingSettings.AdaptBackBufferToScreen)
322322
{
323323
var deviceAr = Window.ClientBounds.Width / (float)Window.ClientBounds.Height;
324324

sources/engine/Stride.Games/GraphicsDeviceManager.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,13 @@ private void GameOnWindowCreated(object sender, EventArgs eventArgs)
191191
/// </value>
192192
public string RequiredAdapterUid { get; set; }
193193

194+
/// <summary>
195+
/// When set, the requested back-buffer size is honoured as-is and any clamp to the host
196+
/// window's client area is skipped (both in <see cref="GameBase.ConfirmRenderingSettings"/>
197+
/// and in the <see cref="GraphicsPresenter"/>'s swap-chain creation).
198+
/// </summary>
199+
public bool SkipBackBufferClampToWindow { get; set; }
200+
194201
/// <summary>
195202
/// Gets or sets the preferred color space for the Back-Buffers.
196203
/// </summary>
@@ -1185,6 +1192,7 @@ void ChangeOrCreateDevice()
11851192

11861193
// Find the best device configuration based on the current settings
11871194
var graphicsDeviceInformation = FindBestDevice(forceCreate);
1195+
graphicsDeviceInformation.PresentationParameters.SkipBackBufferClampToWindow = SkipBackBufferClampToWindow;
11881196
// Give a chance to the game to modify the device settings before the device is created or reset
11891197
OnPreparingDeviceSettings(this, new PreparingDeviceSettingsEventArgs(graphicsDeviceInformation));
11901198

sources/engine/Stride.Graphics/PresentationParameters.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ public sealed class PresentationParameters : IEquatable<PresentationParameters>
194194
/// </remarks>
195195
public ColorSpace ColorSpace;
196196

197+
/// <summary>
198+
/// When set, the presenter honours <see cref="BackBufferWidth"/> / <see cref="BackBufferHeight"/>
199+
/// as-is and skips any clamp to the host window's client area.
200+
/// </summary>
201+
public bool SkipBackBufferClampToWindow;
202+
197203
/// <summary>
198204
/// The color space type used for the Graphics Presenter output.
199205
/// </summary>

sources/engine/Stride.Graphics/Vulkan/SwapChainGraphicsPresenter.Vulkan.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,11 @@ private unsafe void CreateSwapChain(int width, int height, PixelFormat desiredFo
432432
// Create swapchain
433433
GraphicsDevice.NativeInstanceApi.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(GraphicsDevice.NativePhysicalDevice, surface, out var surfaceCapabilities);
434434

435-
Description.BackBufferWidth = (int)surfaceCapabilities.currentExtent.width;
436-
Description.BackBufferHeight = (int)surfaceCapabilities.currentExtent.height;
435+
if (!Description.SkipBackBufferClampToWindow)
436+
{
437+
Description.BackBufferWidth = (int)surfaceCapabilities.currentExtent.width;
438+
Description.BackBufferHeight = (int)surfaceCapabilities.currentExtent.height;
439+
}
437440

438441
// Buffer count
439442
uint desiredImageCount = Math.Max(surfaceCapabilities.minImageCount, 2);

0 commit comments

Comments
 (0)