d3d12: Fix MinGW cross-build error in resource_state_if_promoted
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

When cross-compiling with MinGW, d3d12_resource_state.cpp fails to
compile with:

  d3d12_resource_state.cpp:161:83: error: call to non-'constexpr'
  function 'D3D12_RESOURCE_STATES operator|(D3D12_RESOURCE_STATES,
  D3D12_RESOURCE_STATES)'
    161 |       D3D12_RESOURCE_STATE_ALL_SHADER_RESOURCE |
        |       D3D12_RESOURCE_STATE_COPY_SOURCE | D3D12_RESOURCE_STATE_COPY_DEST;
        |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  In file included from /usr/share/mingw-w64/include/minwindef.h:163,
                   from /usr/share/mingw-w64/include/windef.h:9,
                   from /usr/share/mingw-w64/include/windows.h:69,
                   from /usr/share/mingw-w64/include/rpc.h:16,
                   from /usr/share/mingw-w64/include/unknwn.h:7,
                   from ../subprojects/DirectX-Headers-1.0/include/wsl/winadapter.h:6,
                   from ../src/gallium/drivers/d3d12/d3d12_common.h:29,
                   from ../src/gallium/drivers/d3d12/d3d12_bufmgr.h:31,
                   from ../src/gallium/drivers/d3d12/d3d12_resource_state.cpp:24:
  ../subprojects/DirectX-Headers-1.0/include/directx/d3d12.h:3540:1:
  note: 'D3D12_RESOURCE_STATES operator|(D3D12_RESOURCE_STATES,
  D3D12_RESOURCE_STATES)' declared here
   3540 | DEFINE_ENUM_FLAG_OPERATORS( D3D12_RESOURCE_STATES )
        | ^~~~~~~~~~~~~~~~~~~~~~~~~~

The DEFINE_ENUM_FLAG_OPERATORS macro in the MinGW winnt.h header
defines operator| for D3D12_RESOURCE_STATES as inline but not
constexpr.  (The DirectX-Headers WSL stubs do define it as constexpr,
but when building with MinGW, windows.h is pulled in via winadapter.h
and its non-constexpr definition wins.)  Calling a non-constexpr
function to initialize a constexpr variable is ill-formed in C++.

Fix by changing static constexpr to static const, which avoids the
constexpr context while still giving the variable static storage
duration.

Fixes: fe48cd7c5a ("d3d12: Allow state promotion for non-simultaneous access textures")
Signed-off-by: Vinson Lee <vlee@freedesktop.org>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40880>
This commit is contained in:
Vinson Lee 2026-04-08 23:51:15 -07:00
parent f92cfe9a74
commit 2443f3608a

View file

@ -157,7 +157,7 @@ resource_state_if_promoted(D3D12_RESOURCE_STATES desired_state,
bool simultaneous_access,
const d3d12_subresource_state *current_state)
{
static constexpr D3D12_RESOURCE_STATES promotable_states =
static const D3D12_RESOURCE_STATES promotable_states =
D3D12_RESOURCE_STATE_ALL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_COPY_SOURCE | D3D12_RESOURCE_STATE_COPY_DEST;
if (simultaneous_access || (desired_state & ~promotable_states) == D3D12_RESOURCE_STATE_COMMON) {