Skip to content

Resolve C2360 for VS2026 by hoisting switch-local declarations#125

Closed
BinqAdams wants to merge 1 commit intoNVIDIAGameWorks:mainfrom
BinqAdams:refactor/c2360-workgroup-braces
Closed

Resolve C2360 for VS2026 by hoisting switch-local declarations#125
BinqAdams wants to merge 1 commit intoNVIDIAGameWorks:mainfrom
BinqAdams:refactor/c2360-workgroup-braces

Conversation

@BinqAdams
Copy link
Copy Markdown
Contributor

@BinqAdams BinqAdams commented Jan 20, 2026

Summary

Allow DXVK Remix to build cleanly under MSVC 19.x (Visual Studio 2026) with /WX enabled.

Motivation

Three pathtracer dispatch sites declare VkExtent3D workgroups directly under a case: label inside a switch. MSVC 19.x emits C2360 / C2361 ("initialization of workgroups is skipped by case label") and, with /WX, the build aborts. The C++ rule is that a non-trivial initialization cannot be jumped over by other case labels in the same switch.

build_common.ps1 separately rejects VS 2026 because its vswhere query is pinned to [16.0,18.0).

What Changed

  • Hoist const VkExtent3D workgroups = util::computeBlockCount(rayDims, VkExtent3D { 16, 8, 1 }); above the switch in three files:

    • src/dxvk/rtx_render/rtx_pathtracer_gbuffer.cpp
    • src/dxvk/rtx_render/rtx_pathtracer_integrate_direct.cpp
    • src/dxvk/rtx_render/rtx_pathtracer_integrate_indirect.cpp

    Only the RayQuery case uses workgroups (other modes call traceRays); the value is the same expression in all three files. Hoisting kills C2360 / C2361 without adding brace-wrapping inside each case body. The marginal cost of computing workgroups in non-RayQuery modes is an integer divide.

  • Bump build_common.ps1 vswhere version range from [16.0,18.0) to [16.0,19.0) so VS 2026 satisfies the lower-bound check while still rejecting older releases.

Net diff: 4 files, +4 / -4.

Testing

Built _Comp64DebugOptimized end-to-end against VS 2026 + Vulkan SDK 1.4.x, ninja backend; produced d3d9.dll and ran install steps cleanly with no warnings or errors from any of the three modified pathtracer compilation units.

Comment thread build_common.ps1 Outdated
# Get path to Visual Studio installation using vswhere.
#
$vsPath = &$vsWhere -latest -version "[16.0,18.0)" -products * `
$vsPath = &$vsWhere -latest -products * `
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completely removing the version check is probably a bad idea - could cause problems for people with older VS versions installed. Should this just be -version "[16.0,19.0)" instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've put this in :)

@MarkEHenderson
Copy link
Copy Markdown
Collaborator

Please squash your commits.

@BinqAdams BinqAdams force-pushed the refactor/c2360-workgroup-braces branch from b1d6f64 to 8c65bfd Compare January 24, 2026 04:45
@BinqAdams
Copy link
Copy Markdown
Contributor Author

Please squash your commits.

Squashed!

ctx->dispatch(workgroups.width, workgroups.height, workgroups.depth);
}
case RaytraceMode::RayQuery: {
VkExtent3D workgroups = util::computeBlockCount(rayDims, VkExtent3D { 16, 8, 1 });
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(sorry about the long delay, got rather busy for a bit)

Instead of adding large braces like this, a better fix would be to move the VkExtent3D workgroups declarations outside of the switch statements - so it should look like

VkExtent3D workgroups;
switch (blah) {
case RayQuery:
    workgroups = blah;
    ...

@BinqAdams BinqAdams marked this pull request as draft March 19, 2026 21:42
When DXVK Remix is built with MSVC 19.x (Visual Studio 2026) under
/WX, the compiler emits C2360 / C2361 errors for every case body that
declares a local VkExtent3D directly under the case label without an
intervening block. The C++ rule is that a non-trivial initialization
cannot be jumped over by other case labels in the same switch.

Hoist the workgroups computation above the switch in three pathtracer
dispatch sites:

- rtx_pathtracer_gbuffer.cpp
- rtx_pathtracer_integrate_direct.cpp
- rtx_pathtracer_integrate_indirect.cpp

Each switch only ever uses workgroups in its RayQuery case (other
modes call traceRays); the value is the same expression in all
three files. Hoisting makes it const, kills the C2360 / C2361, and
keeps each case body free of brace-wrapping. The computation is
cheap (an integer divide) so the marginal cost in the non-RayQuery
modes is negligible.

build_common.ps1: bump the vswhere version range from [16.0,18.0)
to [16.0,19.0) so VS 2026 satisfies the lower-bound check while
still rejecting older releases.
@BinqAdams BinqAdams force-pushed the refactor/c2360-workgroup-braces branch from 8c65bfd to a253c52 Compare April 29, 2026 11:23
@BinqAdams BinqAdams changed the title Add braces to resolve c2360 - VS2026 compatibility Resolve C2360 for VS2026 by hoisting switch-local declarations Apr 29, 2026
@BinqAdams
Copy link
Copy Markdown
Contributor Author

@MarkEHenderson — apologies for the long delay on this. Force-pushed a rework that addresses your Feb feedback:

  • Moved the VkExtent3D workgroups declarations above each switch instead of brace-wrapping the case bodies. Three files affected (rtx_pathtracer_gbuffer.cpp, rtx_pathtracer_integrate_direct.cpp, rtx_pathtracer_integrate_indirect.cpp). Net diff is now +4/-4 across those three files.
  • Kept the vswhere range bump but as -version "[16.0,19.0)" per your earlier suggestion, rather than removing the lower-bound check.
  • Squashed to a single commit.

Smoke-built _Comp64DebugOptimized against VS 2026 cleanly. Ready for another look when you have a moment.

@BinqAdams BinqAdams marked this pull request as ready for review April 29, 2026 11:24
@MarkEHenderson
Copy link
Copy Markdown
Collaborator

Just merged this internally, it should show up on github soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants