You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUILD-1938: validate sandbox render arguments before Vulkan - #6012
Claimed in the coordination issue as: BUILD-1938, render-argument slice of this three-part claim, carried into #5934.
Depends on: #5830, #4119, #4436 (shared-file conflicts / merge ordering; this patch builds independently on main).
What and why
vk_sandbox parses numeric options with atoi/atof. Inputs such as --size -1 64, --size 0 64, --fov nan and --cam 0 0 0 oops 0 reach Vulkan instead of reporting a usage error. Negative dimensions wrap to unsigned values, numeric prefixes are accepted and non-finite camera values can enter the projection.
Parse complete, representable values before scene loading or Vulkan. Require positive 32-bit signed-range dimensions/frame counts, finite camera values, a finite projection scale with 0 < fov < 180, and a known camera mode. After device selection, reject image dimensions exceeding image/framebuffer/viewport limits before allocating render targets. Invalid input exits 2. The default scene-centred camera remains available when --cam is omitted.
Tested
Base 561b65a832218fbb9e6d2effd392a8eef093a3f8; patch head 109924e4a87433346851ef106ca8972adb9f7905.
Built vk_sandbox with CMake/Ninja, GCC 16.2.1 and project-pinned Vulkan headers on Arch Linux.
ctest --test-dir out/arguments-build --no-tests=error -R '^sandbox_cli$' --output-on-failure: passes. The CMake test runs the actual executable, checks malformed/missing/overflowing numbers in each argument position and verifies valid options reach scene loading. No Vulkan instance, GPU or game file is needed for this test. The original executable fails it.
On RTX 3080 Ti and RTX 3090, NVIDIA 615.78.08, rendered the original synthetic 1,003-draw fixture at three camera poses with both the base renderer and this patch: complete PPMs are byte-identical for each pose on both cards. --size 2147483647 1 exits 2 with the render-target-limit diagnostic on both cards and writes no image.
Documentation-path checks, the game-data guard and git diff --check pass. Native Windows/windowed rendering and real-scene performance have not been tested for this patch. No validation-layer-cleanliness claim.
Tested 109924e4a87433346851ef106ca8972adb9f7905 on NVIDIA GeForce RTX 4070 SUPER (Ada), driver 621.14, Windows 11 (build 26200): pass. AI-assisted run, no game files.
Build: MSVC 14.44 (VS 2022), Ninja, RelWithDebInfo, Vulkan SDK 1.4.363.0, --target vk_sandbox. It compiles and links with no warnings. The PR body lists native Windows as untested; this run covers the Windows build, the CLI test and the limit check, but not rendering (see below).
ctest -R "^sandbox_cli$": passed (0.59 s), and again with LEONIDA_VK_VALIDATION=1 (0.56 s; the test never reaches Vulkan). So all the script's cases also pass with MSVC's strtof and from_chars, including 1e-100, nan, inf, 1e100, --fov 1e-37 and the leading +.
Device-limit check, using a 32-byte empty scene (no textures, meshes or draws). --size 2147483647 1, --size 32769 64 and --size 64 32769 each exit 2 and write no image:
device: NVIDIA GeForce RTX 4070 SUPER
--size exceeds the selected device's render-target limits
vulkaninfo reports 32768 for maxImageDimension2D, maxFramebufferWidth/Height and maxViewportDimensions on this GPU. As a control, --size 32768 64 passes the check, gets past render-target and framebuffer creation, and stops later at the missing shader (cannot read unused-vs, exit 1). So a size equal to the limit is accepted.
The same four runs with LEONIDA_VK_VALIDATION=1 give identical results. vk_sandbox doesn't read that variable, so I also ran them with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. The three over-limit runs exit 2 before vkCreateDevice, and the layer prints nothing for them. The 32768x64 control prints one error, from vkCreateSampler:
Validation Error: [ VUID-VkSamplerCreateInfo-anisotropyEnable-01070 ] | MessageID = 0x56f192bc
vkCreateSampler(): pCreateInfo->anisotropyEnable is VK_TRUE but the samplerAnisotropy feature was not enabled.
vk_sandbox from main (561b65a8, same build) prints the same error, so it doesn't come from this PR. Nothing was reported for the 32768x64 render-target or framebuffer creation.
Regression check: this PR's check_sandbox_cli.cmake run against main's vk_sandbox (561b65a8) fails on its first case with --size : expected usage error before scene/Vulkan, got 2, because main prints bad scene file first. Against this head the same script passes (the ctest above).
Extra parser probes on Windows (47 runs against an invalid scene file, so none reaches Vulkan). As camera values, 1e-46 and 1e-100 are rejected, while the subnormal values 1e-45, 1e-40 and 1e-38 are accepted. The test script has no subnormal case, so its result doesn't depend on this. --size rejects 0x40, " 64", ++64, -0 and 2147483648, and accepts 064 and +64. --mode Fly is rejected.
Not covered: a real render or --window (both need translated game shaders, which this run didn't use), a byte-for-byte PPM comparison against the base renderer, and performance.
Checked head 109924e4a on Windows 11, MSVC 19.44, RTX 3070 (621.24), merged onto main 561b65a8 with no conflicts. sandbox_cli passes, 1/1. hazben's check above is Ada. I added hand probes against the built vk_sandbox.exe with a bad scene file, so each one either hits the usage error or reaches "bad scene file":
Accepted as valid: --size 007 08, --size 00000000000000000064 64, --fov 1e-30, --fov 179.99999, --fov 0x1p6 (hex float), --cam 1e-40 0 0 0 0 (denormal; MSVC's strtof does not flag it ERANGE), --cam 0 0 0 -0 -0.
Inconsistent:--cam " 1" 0 0 0 0 is accepted (strtof skips leading whitespace) but --frames " 5" and --size " 64" 64 are rejected (from_chars does not). Harmless, but "requires a valid value" means two things.
Finite is not safe:--cam 3e38 3e38 3e38 0 0 passes finite_float, but the view matrix then subtracts and multiplies 3e38-sized values in float, so the view-projection rows can become inf/NaN. The test list only has 1e100 (rejected via ERANGE), so nothing covers a finite value that overflows later. I did not render with it (no GPU scene in this run), so I can't say what the image looks like. If it matters, a bound like |coordinate| below some limit, or checking std::isfinite on the computed rows, would close it.
No failing case, so none of this blocks the PR. No game data. AI-assisted (Claude Code).
The reason will be displayed to describe this comment to others. Learn more.
Approved based on local Windows 11 / MSVC test pass and independent audit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claimed in the coordination issue as: BUILD-1938, render-argument slice of this three-part claim, carried into #5934.
Depends on: #5830, #4119, #4436 (shared-file conflicts / merge ordering; this patch builds independently on main).
What and why
vk_sandboxparses numeric options withatoi/atof. Inputs such as--size -1 64,--size 0 64,--fov nanand--cam 0 0 0 oops 0reach Vulkan instead of reporting a usage error. Negative dimensions wrap to unsigned values, numeric prefixes are accepted and non-finite camera values can enter the projection.Parse complete, representable values before scene loading or Vulkan. Require positive 32-bit signed-range dimensions/frame counts, finite camera values, a finite projection scale with
0 < fov < 180, and a known camera mode. After device selection, reject image dimensions exceeding image/framebuffer/viewport limits before allocating render targets. Invalid input exits 2. The default scene-centred camera remains available when--camis omitted.Tested
Base
561b65a832218fbb9e6d2effd392a8eef093a3f8; patch head109924e4a87433346851ef106ca8972adb9f7905.vk_sandboxwith CMake/Ninja, GCC 16.2.1 and project-pinned Vulkan headers on Arch Linux.ctest --test-dir out/arguments-build --no-tests=error -R '^sandbox_cli$' --output-on-failure: passes. The CMake test runs the actual executable, checks malformed/missing/overflowing numbers in each argument position and verifies valid options reach scene loading. No Vulkan instance, GPU or game file is needed for this test. The original executable fails it.--size 2147483647 1exits 2 with the render-target-limit diagnostic on both cards and writes no image.vk_sandbox.cppconflict, resolved and tested in the integration checkout. The older deferred/shadow refactors also overlap the shared code and already conflict with main.git diff --checkpass. Native Windows/windowed rendering and real-scene performance have not been tested for this patch. No validation-layer-cleanliness claim.Reproduce the CPU CLI check after building:
cmake --build runtime/build --target vk_sandbox ctest --test-dir runtime/build --no-tests=error -R '^sandbox_cli$' --output-on-failureAll fixtures and shaders used are original synthetic inputs; no game data.
AI-assisted: yes, Codex.
Checklist