Search Unity

Question Determine Metal API version?

Discussion in 'macOS' started by zezba9000, Jul 1, 2023.

  1. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    Does Unity expose what Metal API its using?
    Version 1, 2 or 3 etc?

    Something I can programmatically check.
     
  2. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    there is no such thing as "metal API" version (while this numbering is not exactly marketing - by itself it is not very well defined). You should directly check for what is needed instead
     
    zezba9000 likes this.
  3. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,086
    Whilst technically correct, when the API is added as a suffix, there are versions of Metal, which is what this question is trying to ask. Probably.

    Could you answer that question: Which version of Metal?
     
  4. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    > Could you answer that question: Which version of Metal?
    i did answer:
    > You should directly check for what is needed instead
     
  5. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,429
    https://developer.apple.com/documen...ting_gpu_features_and_metal_software_versions

    As Alexey is saying, "version N" may support different subsets depending on the hardware available. It doesn't seem to be like GL where the software is a fallback for missing hardware. It sucks, because it's not too fun having to write a list of things like "doesn't return an error when attempting quad-scoped permute operations" on your app's Minimum System Requirements.
     
    zezba9000 likes this.
  6. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,086
    On behalf of the world of more considered peoples, I apologise for the second guessing going on above. I think it's about avoidance.

    Near as I can tell, Unity is using version 2 of Metal, and nothing of the wonders of Metal 3, despite it providing all sorts of means to do better on Mac, iPhones, iPads, Apple TVs and now VisionOS. hence the reticence, I suppose.

    But I think the real source of touchiness is that they're likely not upgrading either the editor for Silicon, nor the builds for VisionOS, etc... because they've instead decided to rely on a bridge (of some sort) to Apple's Materials/Shaders rather than port their own and give us an ability to ShaderGraph or HLSL our ways to excellence in the new Virtual Realities of ARKit and RealityKit.

    Would love nothing more than to be able to make Metal Shaders in Unity... but that's not going to be possible, for VisionOS, probably because they've stalled at Metal 2.
     
  7. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    > Near as I can tell, Unity is using version 2 of Metal, and nothing of the wonders of Metal 3
    > but that's not going to be possible, for VisionOS, probably because they've stalled at Metal 2.

    do you realize that what you are saying doesn't make any sense? There is no such thing as "using version 2 of metal". What *exactly* are you missing?

    > Would love nothing more than to be able to make Metal Shaders in Unity..
    there is some support
    https://github.com/Unity-Technologies/iOSNativeCodeSamples/tree/2019-dev/Graphics/MetalNativeShader
    but again - this is limited because there is no a lot of demand for this
     
  8. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,086
    I'm going to guess two things, from the above:

    1. You don't own any Apple gear, nor appreciate their ways
    2. You're not familiar with "the chicken and the egg" metaphor
     
  9. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    Looks like there are GPU families and there is one specifically for Metal3 feature set.
    https://developer.apple.com/documentation/metal/mtlgpufamily

    Given Apple defines what features exist in Metal 1,2,3 it seems like a enum could be defined (but maybe Metal 1,2 not so much?)

    I've done work with native graphics APIs such as D3D9,10,11,12 OpenGL, GLES1,2,3 Vulkan etc for years. But have never done native Metal, so I'm a little more fuzzy here.

    Seems like Apple is doing something akin to D3D11,12 features levels but more complex.

    Anyway thanks for answer.
     

    Attached Files:

    Unifikation likes this.
  10. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    > Looks like there are GPU families and there is one specifically for Metal3 feature set.
    > https://developer.apple.com/documentation/metal/mtlgpufamily

    yeah it was added in xcode 14.smth
    https://developer.apple.com/documentation/metal/mtlgpufamily/mtlgpufamilymetal3?language=objc
    you can totally use it in native plugin - but the question remains - why exactly this needs to be checked?

    > Given Apple defines what features exist in Metal 1,2,3 it seems like a enum could be defined
    so on one hand we can go combing through apple marketing material to determine what is "Metal 2" or we can ask what exactly do you need to be checked (that is not yet available in our api) and why?
     
  11. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    No reason outside simplifying graphic tier levels maybe.
    I'm making a custom render pipeline and thought it might come in handy later. But seeing as how they're doing stuff probably doesn't matter.
     
  12. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,723
    Ray Tracing?

    Although I believe I already know the answer.
     
  13. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    > No reason outside simplifying graphic tier levels maybe.
    oh that's actually fair: "metal level 3" is kinda like "performant hw", but yeah - i would say adding native plugin will be easier (note to self: check if macos trampoline supports ios-like "just add this file to project")

    > Ray Tracing?
    but
    https://docs.unity3d.com/ScriptReference/SystemInfo-supportsRayTracing.html
    *sure* currently "unity metal" does not support ray tracing (not implemented on our end)
     
  14. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,086
  15. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,141
    Metal doesn't work like modern DirectX. For a hardware device to advertise support for a tier of DirectX it has to support a minimum set of features. Metal doesn't have that requirement. Metal 3 supports devices as far back as 2017 which means just looking at the main API version won't tell you what features a device has.

    https://support.apple.com/en-us/HT205073
     
    Last edited: Jul 9, 2023
  16. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    Well this actually is more fragmented even in D3D12 than one might imagine.
    For example on 4th gen Intel GPUs RWTextures don't work in D3D12. While they do work in D3D11.
    And D3D11 has features levels that go all the way down to 9.1 and those hardware sets need their own hardware CAPS checked.

    btw does Unity have a way to detect if pixel-shader thread locking is supported in Metal? I know this isn't supported in Metal 1 or 2. But is it supported in Metal 3? Its required for OIT (aka Order Independent Transparency) effects.
     
    Unifikation likes this.
  17. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    > But is it supported in Metal 3? Its required for OIT (aka Order Independent Transparency) effects.
    i dont think there is "pixel-shader thread locking" in metal. As far as i understand they want to do this with image blocks
    https://developer.apple.com/documen..._transparency_with_image_blocks?language=objc
    and the problem here is that we are absolutely not sure how to implement the support for this in a "sane way"
     
    zezba9000 likes this.
  18. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,086
    Given your new partnership with Apple for VisionOS, do you think you could find someone over there (at Apple) to help you with this?

    I'd love to see DOF recognise transparency. That'd be another game changer.
     
  19. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    Man what the heck Apple. Just give us pixel locking control.
    So they want you to partition tile memory and then hack around that with with a limited number of layers defined by "kNumLayers" ? If this is only 4 thats not nearly enough for OIT to be useful in almost any context. This also seems to only be for forward rendering which also isn't useful as I'm making something I'm calling Deferred+ where transparent objects are deferred lit just like opaque ones are using ArrayTextures.

    However to support this in Unity though you maybe would need to have a Unity RenderTexture desc store data about what this "RenderPassDescriptor" will need as RenderTextures are usally part of this state in the pipeline anyway. Then this allows a Unity script to set the custom values as needed. Now just some minor HLSL updates to support "TransparentFragmentStore" type. Seems like this approach might work with Unity to support the feature?

    The fact GPUs from 2007 with D3D11 support pixel locking yet Apple still wont support this feature is just pathetic at this point. Even for CAD software this puts Apple hardware way behind. Absolutely unexpectable Apple.

    If Unity has any weight with Apple I would push them to update their dumb drivers to support pixel locking (if the hardware is able to do this).
     
  20. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    If "kNumLayers" can be more than 4 and you can also write out to an Array-RWTexture it might be possible to use to replicate this on Apple hardware. Maybe you can just not write out to the tile memory at all and just use this as the alternative to pixel ordering.

    If so, it does seem like a feature worth investigating for Unity.
     
  21. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,086
    How about the improvements to using scaling for performance, the addition of mesh shaders, the improved ray tracing, faster texture loading, precompiling of shaders etc?
     
  22. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    > How about the improvements to using scaling for performance, the addition of mesh shaders, the improved ray tracing, faster texture loading, precompiling of shaders etc?

    again - you are speaking about "unity should implement new things", not about "can we check the availability of features"

    anyway:
    scaling for performance - AFAIK people are doing something with VRR - i am not sure about the timeline but this is coming. We also have adaptive resolution support (though done in "old ways")
    the addition of mesh shaders - well we need "whole unity support" for this - i am not sure if it is done, but when it exists in unity it should be also available for metal
    the improved ray tracing - thats a good question - we had some "raytracing on metal" experiments (i even saw pictures) but i dunno about exact plans, sorry
    faster texture loading - by itself these changes are irrelevant and we already have threaded texture loading, i am nost sure what exactly do you want to see - some "it became magically faster"?
    precompiling of shaders - yes that's planned (as in - i did remove some of the last obstacles to have fully precompiled shaders last week, so we can start thinking about this) [EDIT: this is not related to metal3 AT ALL]
     
    Last edited: Jul 13, 2023
  23. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,086
    all needed!
     
  24. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    i assume you have some issues with English: this thread is NOT about "aaah i want this feature", but (at least was) about checking in c# what things are supported by gpu
     
  25. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,086
    Are you a good programmer? I hope so.

    Because I'd like you to be adding Metal 3 support to the Editor and Builds.

    Not for me. For everyone making Apple targeting games and apps.