bkaradzic / bgfx

Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
https://bkaradzic.github.io/bgfx/overview.html
BSD 2-Clause "Simplified" License
14.58k stars 1.92k forks source link

Metal renderer compiler error in XCode version 15.0 and 15.1 #3314

Open bwrsandman opened 1 week ago

bwrsandman commented 1 week ago

Describe the bug The VISION_OS_MINIMUM define in renderer_mtl.mm causes a compilation error if you use XCode 15 before 15.2. This is particularly a problem because, at the time of this writing, the github action runner macos-13 has XCode 15.0.1 installed.

The issue stems from the BX_XCODE_15 define not being granular enough and that the visionOS SDK being released in XCode 15.2. https://github.com/bkaradzic/bgfx/blob/00fa5ad179f5aa13c1e44d0bcbccdc535aba2d00/src/renderer_mtl.mm#L456-L461

Xcode 15 launched without these features, which were eventually added in Xcode 15.2 on January 8, 2024

https://en.wikipedia.org/wiki/VisionOS#Developer_tools

To Reproduce Steps to reproduce the behavior:

  1. Install XCode 15.0.1 or any between 15.0 and 15.2 (non tail-inclusive). Or, using the macos-13 runner (as of Jun 15 2024).
  2. Build with the metal renderer.

Expected behavior VISION_OS_MINIMUM is an empty define and there are no compilation errors.

Screenshots https://github.com/openblack/openblack/actions/runs/9531646671/job/26272798609?pr=759

  In file included from /Users/runner/work/openblack/openblack/vcpkg/buildtrees/bgfx/src/fadeae919b-3cb7278020.clean/src/amalgamated.mm:7:
  Error: /Users/runner/work/openblack/openblack/vcpkg/buildtrees/bgfx/src/fadeae919b-3cb7278020.clean/src/renderer_mtl.mm:501:98: error: unrecognized platform name visionOS
    501 |                         CHECK_FEATURE_AVAILABLE(m_usesMTLBindings, macOS 13.0, iOS 16.0, tvOS 16.0, macCatalyst 16.0, VISION_OS_MINIMUM *);
        |                                                                                                                       ^
  /Users/runner/work/openblack/openblack/vcpkg/buildtrees/bgfx/src/fadeae919b-3cb7278020.clean/src/renderer_mtl.mm:466:28: note: expanded from macro 'VISION_OS_MINIMUM'
    466 | #       define VISION_OS_MINIMUM visionOS 1.0,
        |                                  ^
  Error: /Users/runner/work/openblack/openblack/vcpkg/buildtrees/bgfx/src/fadeae919b-3cb7278020.clean/src/renderer_mtl.mm:502:113: error: unrecognized platform name visionOS
    502 |                         CHECK_FEATURE_AVAILABLE(m_hasCPUCacheModesAndStorageModes, iOS 9.0, macOS 10.11, macCatalyst 13.1, tvOS 9.0, VISION_OS_MINIMUM *);
        |                                                                                                                                      ^
  /Users/runner/work/openblack/openblack/vcpkg/buildtrees/bgfx/src/fadeae919b-3cb7278020.clean/src/renderer_mtl.mm:466:28: note: expanded from macro 'VISION_OS_MINIMUM'
    466 | #       define VISION_OS_MINIMUM visionOS 1.0,
        |                                  ^

Additional context bgfx.cmake: https://github.com/bkaradzic/bgfx.cmake/commit/c0ce1388cc8750894127c56daaa22063aa88bd70 bx: https://github.com/bkaradzic/bx/commit/24527eabfd135dca569904baff1bdfd004ef8b41 bimg: https://github.com/bkaradzic/bimg/commit/59f188a6add2c9ac4b986ccf9724575d3c41da9b bgfx: d1feabe3194b4b41ffd9c5747536acfadeae919b Xcode: 15.0.1

mcourteaux commented 1 week ago

@bkaradzic There are many compile-time dependencies for visionOS right now, so I believe there is no point in trying to determine wether or not to enable visionOS in that macro expansion based on the XCode version. Bgfx doesn't support having a single binary for macOS, iOS, and visionOS at this point either way. All of those preprocessor macros checking for BX_PLATFORM_VISION_OS would need to become runtime checks if we want a single cross-Apple-ecosystem binary. As long as we don't have that, replacing the check on BX_XCODE_15 with BX_PLATFORM_VISION_OS should do the trick.

@okwasniewski Thoughts on the single-cross-platform bgfx library binary? You worked on the visionOS support. Is it feasible and/or potentially desirable to have one bgfx library?

@bwrsandman You can meanwhile try this:

#if BX_PLATFORM_VISION_OS
#   define VISION_OS_MINIMUM visionOS 1.0,
#else
#   define VISION_OS_MINIMUM
#   warning "XCode 15 is required for visionOS"
#endif
okwasniewski commented 3 days ago

@mcourteaux Yeah, you are right it's not possible to have a single cross-platform binary with bgfx currently.

Probably we could also check using this macros:

CleanShot 2024-06-25 at 14 39 33@2x

#ifndef __VISION_OS_VERSION_MAX_ALLOWED
#define __VISION_OS_VERSION_MAX_ALLOWED 0
#endif

#if __VISION_OS_VERSION_MAX_ALLOWED >= 10000 
#   define VISION_OS_MINIMUM visionOS 1.0,
#else
#   define VISION_OS_MINIMUM
#   warning "XCode 15 is required for visionOS"
#endif