KhronosGroup / MoltenVK

MoltenVK is a Vulkan Portability implementation. It layers a subset of the high-performance, industry-standard Vulkan graphics and compute API over Apple's Metal graphics framework, enabling Vulkan applications to run on macOS, iOS and tvOS.
Apache License 2.0
4.79k stars 422 forks source link

error: property 'presentedTime' not found on object of type 'id<MTLDrawable>' #1187

Closed sl1pkn07 closed 3 years ago

sl1pkn07 commented 3 years ago
CompileC /private/tmp/moltenvk-20201227-93071-1b4erxt/build/MoltenVK.build/Release/MoltenVK-macOS.build/Objects-normal/x86_64/MVKImage.o /tmp/moltenvk-20201227-93071-1b4erxt/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm normal x86_64 objective-c++ com.apple.compilers.llvm.clang.1_0.compiler (in target 'MoltenVK-macOS' from project 'MoltenVK')
    cd /tmp/moltenvk-20201227-93071-1b4erxt/MoltenVK
    export LANG=en_US.US-ASCII
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c++ -target x86_64-apple-macos10.11 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=c++11 -stdlib=libc++ -Wno-trigraphs -fpascal-strings -Ofast -fno-common -Wmissing-field-initializers -Wmissing-prototypes -Wunreachable-code -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Wno-objc-interface-ivars -Werror=objc-root-class -Wno-arc-repeated-use-of-weak -Wimplicit-retain-self -Wnon-virtual-dtor -Woverloaded-virtual -Wno-exit-time-destructors -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wconditional-uninitialized -Wno-unknown-pragmas -Wshadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wshorten-64-to-32 -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wno-deprecated-implementations -Wc++11-extensions -DSPIRV_CROSS_NAMESPACE_OVERRIDE=MVK_spirv_cross -DNS_BLOCK_ASSERTIONS=1 -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -Winvalid-offsetof -fvisibility=hidden -fvisibility-inlines-hidden -Wno-sign-conversion -Winfinite-recursion -Wmove -Wno-comma -Wno-block-capture-autoreleasing -Wno-strict-prototypes -Wno-range-loop-analysis -Wno-semicolon-before-method-body -Wno-unguarded-availability -iquote /private/tmp/moltenvk-20201227-93071-1b4erxt/build/MoltenVK.build/Release/MoltenVK-macOS.build/MoltenVK-generated-files.hmap -I/private/tmp/moltenvk-20201227-93071-1b4erxt/build/MoltenVK.build/Release/MoltenVK-macOS.build/MoltenVK-own-target-headers.hmap -I/private/tmp/moltenvk-20201227-93071-1b4erxt/build/MoltenVK.build/Release/MoltenVK-macOS.build/MoltenVK-all-target-headers.hmap -iquote /private/tmp/moltenvk-20201227-93071-1b4erxt/build/MoltenVK.build/Release/MoltenVK-macOS.build/MoltenVK-project-headers.hmap -I/private/tmp/moltenvk-20201227-93071-1b4erxt/build/Release/include -I/tmp/moltenvk-20201227-93071-1b4erxt/MoltenVK/include -I/tmp/moltenvk-20201227-93071-1b4erxt/MoltenVKShaderConverter -I/usr/local/opt/cereal/include -I/private/tmp/moltenvk-20201227-93071-1b4erxt/build/Release -I/private/tmp/moltenvk-20201227-93071-1b4erxt/build/MoltenVK.build/Release/MoltenVK-macOS.build/DerivedSources-normal/x86_64 -I/private/tmp/moltenvk-20201227-93071-1b4erxt/build/MoltenVK.build/Release/MoltenVK-macOS.build/DerivedSources/x86_64 -I/private/tmp/moltenvk-20201227-93071-1b4erxt/build/MoltenVK.build/Release/MoltenVK-macOS.build/DerivedSources -F/private/tmp/moltenvk-20201227-93071-1b4erxt/build/Release -MMD -MT dependencies -MF /private/tmp/moltenvk-20201227-93071-1b4erxt/build/MoltenVK.build/Release/MoltenVK-macOS.build/Objects-normal/x86_64/MVKImage.d --serialize-diagnostics /private/tmp/moltenvk-20201227-93071-1b4erxt/build/MoltenVK.build/Release/MoltenVK-macOS.build/Objects-normal/x86_64/MVKImage.dia -c /tmp/moltenvk-20201227-93071-1b4erxt/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm -o /private/tmp/moltenvk-20201227-93071-1b4erxt/build/MoltenVK.build/Release/MoltenVK-macOS.build/Objects-normal/x86_64/MVKImage.o
/tmp/moltenvk-20201227-93071-1b4erxt/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm:1322:41: warning: undeclared selector 'addPresentedHandler:' [-Wundeclared-selector]
                if ([mtlDrawable respondsToSelector: @selector(addPresentedHandler:)]) {
                                                      ^
/tmp/moltenvk-20201227-93071-1b4erxt/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm:1326:63: error: property 'presentedTime' not found on object of type 'id<MTLDrawable>'
                                _swapchain->recordPresentTime(presentTimingInfo, drawable.presentedTime * 1.0e9);
                                                                                          ^
/tmp/moltenvk-20201227-93071-1b4erxt/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm:1325:17: warning: instance method '-addPresentedHandler:' not found (return type defaults to 'id') [-Wobjc-method-access]
                        [mtlDrawable addPresentedHandler: ^(id<MTLDrawable> drawable) {
                                     ^~~~~~~~~~~~~~~~~~~
2 warnings and 1 error generated.

script used (Brew formula)

class Moltenvk < Formula
  desc "Implementation of the Vulkan 1.0 API, that runs on Apple's Metal API"
  homepage "https://github.com/KhronosGroup/MoltenVK"
  url "https://github.com/KhronosGroup/MoltenVK/archive/v1.1.1.tar.gz"
  sha256 "cd1712c571d4155f4143c435c8551a5cb8cbb311ad7fff03595322ab971682c0"

  depends_on "cereal" => :build
  depends_on "cmake" =>  :build
  depends_on "ninja" => :build
  depends_on "python" => :build
  depends_on xcode: :build

  ver = "v#{version}"

  resource "moltenvk-git" do
    url "https://github.com/KhronosGroup/MoltenVK.git",
    tag: ver
  end
  resource "Vulkan-Headers" do
    revi = Utils.popen_read("cat #{HOMEBREW_CACHE}/moltenvk--moltenvk-git--git/ExternalRevisions/Vulkan-Headers_repo_revision").chomp
    url "https://github.com/KhronosGroup/Vulkan-Headers.git",
    revision: revi
  end
  resource "SPIRV-Cross" do
    revi = Utils.popen_read("cat #{HOMEBREW_CACHE}/moltenvk--moltenvk-git--git/ExternalRevisions/SPIRV-Cross_repo_revision").chomp
    url "https://github.com/KhronosGroup/SPIRV-Cross.git",
    revision: revi
  end
  resource "glslang" do
    revi = Utils.popen_read("cat #{HOMEBREW_CACHE}/moltenvk--moltenvk-git--git/ExternalRevisions/glslang_repo_revision").chomp
    url "https://github.com/KhronosGroup/glslang.git",
    revision: revi
  end
  resource "Vulkan-Tools" do
    revi = Utils.popen_read("cat #{HOMEBREW_CACHE}/moltenvk--moltenvk-git--git/ExternalRevisions/Vulkan-Tools_repo_revision").chomp
    url "https://github.com/KhronosGroup/Vulkan-Tools.git",
    revision: revi
  end
  resource "glslang_SPIRV-Headers" do
    revi = Utils.popen_read("cat #{HOMEBREW_CACHE}/moltenvk--glslang--git/known_good.json | grep -m2 'commit\"' | tail -n1 | cut -d '\"' -f4").chomp
    url "https://github.com/KhronosGroup/SPIRV-Headers.git",
    revision: revi
  end
  resource "glslang_SPIRV-Tools" do
    revi = Utils.popen_read("cat #{HOMEBREW_CACHE}/moltenvk--glslang--git/known_good.json | grep -m2 'commit\"' | head -n1 | cut -d '\"' -f4").chomp
    url "https://github.com/KhronosGroup/SPIRV-Tools.git",
    revision: revi
  end

  def install
    %w[Vulkan-Headers SPIRV-Cross glslang Vulkan-Tools].each do |r|
      resource(r).stage(Pathname.pwd/"External"/r)
    end

    resource("glslang_SPIRV-Tools").stage(Pathname.pwd/"External/glslang/External/spirv-tools")
    resource("glslang_SPIRV-Headers").stage(Pathname.pwd/"External/glslang/External/spirv-tools/external/spirv-headers")

    inreplace "Scripts/package_ext_libs_finish.sh",
              "make --quiet clean",
              ""

    inreplace "MoltenVK/MoltenVK.xcodeproj/project.pbxproj",
              '"\"$(SRCROOT)/../External/cereal/include\"",',
              "\"#{Formula["cereal"].opt_include}\","

    cd "External/glslang/External/spirv-tools" do
      # "Building SPIRV-Tools"
      args = std_cmake_args
      args << "-DPYTHON_EXECUTABLE=#{Formula["python"].opt_bin}/python3"
      args << "-DCMAKE_SKIP_RPATH=ON"

      mkdir "build" do
        system "cmake", "-G", "Ninja", "..", *args
        system "ninja"
      end
    end

    cd "External/glslang" do
      system "#{Formula["python"].opt_bin}/python3",
       "./build_info.py",
       ".",
       "-i", "./build_info.h.tmpl",
       "-o", "./build/include/glslang/build_info.h"
    end

    xcodebuild "-project", "ExternalDependencies.xcodeproj",
               "-scheme", "ExternalDependencies-macOS",
               "-derivedDataPath", "External/build",
               "SYMROOT=External/build",
               "OBJROOT=External/build",
               "build"

    xcodebuild "-create-xcframework",
               "-output", "External/build/Latest/SPIRVTools.xcframework",
               "-library", "External/build/Release/libSPIRVTools.a"
    xcodebuild "-create-xcframework",
               "-output", "External/build/Latest/SPIRVCross.xcframework",
               "-library", "External/build/Release/libSPIRVCross.a"
    xcodebuild "-create-xcframework",
               "-output", "External/build/Latest/glslang.xcframework",
               "-library", "External/build/Release/libglslang.a"

    xcodebuild "-project", "MoltenVKPackaging.xcodeproj",
               "-scheme", "MoltenVK Package (macOS only)",
               "-derivedDataPath", "#{buildpath}/build",
               "SYMROOT=#{buildpath}/build",
               "OBJROOT=#{buildpath}/build",
               "build"

    xcodebuild "-create-xcframework",
               "-output", "External/build/Latest/MoltenVK.xcframework",
               "-library", "External/build/Release/libMoltenVK.a"

    include.install Dir["Package/Release/MoltenVK/include/*"]
    lib.install "Package/Release/MoltenVK/macOS/dynamic/libMoltenVK.dylib"
    lib.install "Package/Release/MoltenVK/macOS/static/libMoltenVK.a"
    frameworks.install "Package/Release/MoltenVK/macOS/framework/MoltenVK.framework"
    (share/"vulkan/icd.d").install "MoltenVK/icd/MoltenVK_icd.json"

    include.install Dir["Package/Release/MoltenVKShaderConverter/include/*"]
    lib.install "Package/Release/MoltenVKShaderConverter/MoltenVKGLSLToSPIRVConverter/macOS/dynamic/libMoltenVKGLSLToSPIRVConverter.dylib"
    lib.install "Package/Release/MoltenVKShaderConverter/MoltenVKGLSLToSPIRVConverter/macOS/static/libMoltenVKGLSLToSPIRVConverter.a"
    frameworks.install "Package/Release/MoltenVKShaderConverter/MoltenVKGLSLToSPIRVConverter/macOS/framework/MoltenVKGLSLToSPIRVConverter.framework"

    lib.install "Package/Release/MoltenVKShaderConverter/MoltenVKSPIRVToMSLConverter/macOS/dynamic/libMoltenVKSPIRVToMSLConverter.dylib"
    lib.install "Package/Release/MoltenVKShaderConverter/MoltenVKSPIRVToMSLConverter/macOS/static/libMoltenVKSPIRVToMSLConverter.a"
    frameworks.install "Package/Release/MoltenVKShaderConverter/MoltenVKSPIRVToMSLConverter/macOS/framework/MoltenVKSPIRVToMSLConverter.framework"

    bin.install "Package/Release/MoltenVKShaderConverter/Tools/MoltenVKShaderConverter"
  end

  test do
    (testpath/"test.cpp").write <<~EOS
      #include <vulkan/vulkan.h>
      int main(void)
      {
          const char *extensionNames[] = { "VK_KHR_surface" };
          VkInstanceCreateInfo instanceCreateInfo = {
              VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, NULL,
              0, NULL,
              0, NULL,
              1, extensionNames,
          };
          VkInstance inst;
          vkCreateInstance(&instanceCreateInfo, NULL, &inst);
          return 0;
      }
    EOS
    system ENV.cc, "-o", "test", "test.cpp", "-L#{lib}", "-lMoltenVK"
    system "./test"
  end
end

fails in this step

    xcodebuild "-project", "MoltenVKPackaging.xcodeproj",
               "-scheme", "MoltenVK Package (macOS only)",
               "-derivedDataPath", "#{buildpath}/build",
               "SYMROOT=#{buildpath}/build",
               "OBJROOT=#{buildpath}/build",
               "build"

complete step log

https://gist.github.com/sl1pkn07/b1ccc27c73753a8821b5476a12c7283f

Mojave 10.14.6 in x86_64 environment Xcode 11.3.1 (11C505) MoltenVK 1.1.1. master not tested FS case sensitive

greetings

billhollings commented 3 years ago

Looks like you are using a version of Xcode that is about 12 months old.

presentedTime and addPresentedHandler: were introduced in macOS 10.15.4, about 9 months ago, so your version of Xcode isn't aware of them.

MoltenVK strives to support older versions of macOS at runtime, but we do not attempt to support significantly older versions of Xcode for building MoltenVK.

Please upgrade your version of Xcode.

sl1pkn07 commented 3 years ago

Thanks. But i think can't. Because the latest version of vscode for mojave is the version i have

im not sure if i can force the installation

Greetings

sl1pkn07 commented 3 years ago

Ok, i manage to install Xcode 11.7 with a little hacky

now build ok

please add in the readme an advise with the what version is need as minimun to build moltenvk

greetings

billhollings commented 3 years ago

please add in the readme an advise with the what version is need as minimun to build moltenvk

The Building MoltenVK section of the README.md already starts with...

During building, MoltenVK references the latest Apple SDK frameworks. To access these frameworks, and to avoid build errors, be sure to use the latest publicly available version of Xcode.

...which is accurate, since MoltenVK intentionally makes use of the latest production API at build time, specifically to make use of the latest and greatest Metal functionality (with runtime workarounds as mentioned above).

sl1pkn07 commented 3 years ago

not at all, because this is the list of compatible Xcode by each version of macOS

https://xcodereleases.com/

for example, in the readme, say the minimum macos compatible for moltenvk is

At runtime, MoltenVK requires at least macOS 10.11,

but the xcode compatible with macos 10.11 is Xcode 8.2.1,

so you cant build moltenvk in this version. because the minimum (i test, because i'm in mojave, and fail build with xcode 11.3.1 wich is the latest xcode for my macos version) is Xcode 11.7, wich requres macos 10.15.2+ and cross fingers, because is only installable by hacking

https://izziswift.com/how-to-run-xcode-11-4-on-macos-mojave-10-14-6/ (tested method 3 and 5)

so yes. you need update and add the advise the minimum version of macos and xcode for build moltenvk

greetings

billhollings commented 3 years ago

At runtime, MoltenVK requires at least macOS 10.11, but the xcode compatible with macos 10.11 is Xcode 8.2.1, so you cant build moltenvk in this version

There is a difference between run-time requirements and build-time requirements.

A MoltenVK binary will run on macOS 10.11. But that binary can't be built from source code on anything before Xcode 12 now.

The reason for this is that at build-time, Xcode needs to be aware of any symbols that are in the MoltenVK source code (like the addPresentedHandler: you encountered). If a symbol was introduced in a recent SDK, MoltenVK needs to be built with that SDK (Xcode), or a later SDK, otherwise it produces compile errors like the ones you encountered above. And as mentioned above, to make use of the latest Metal features, MoltenVK does consistently reference symbols in the latest production SDK, hence the instructions in README.md.

However, at run-time, MoltenVK can test and bypass those symbols when running on a version of macOS that doesn't support them. That's the purpose of code like:

if ([mtlDrawable respondsToSelector: @selector(addPresentedHandler:)]) {
   ...
}

When running on something like macOS 10.11, which does not support addPresentedHandler:, this code will cause use of addPresentedHandler: to be avoided.

sl1pkn07 commented 3 years ago

is a requirement of apple that i can use it in old systems but you can't build it on it?

is a weird requirement, if you want add or fix things in older systems but you can't build it in them

greetings

SpaceIm commented 3 years ago

@billhollings I'm creating a MoltenVK recipe for conan, and I've encountered this issue since the latest Macos agent in conan-center CI has XCode 11 only. Downloading a binany outside of conan workflow is not an option.

Anyway I would to ask: MoltenVK 1.1.1 requires at least XCode 12 at build time. MoltenVK runtime can run with older Macos versions, but is it possible to link a static MoltenVK 1.1.1 (built with XCode >= 12) with XCode < 12? I guess the answer is no, but I would like a confirmation.