Search Unity

Feedback AssetBundles with shaders for all standalone platforms

Discussion in 'Asset Bundles' started by Alloc, Jun 17, 2019.

  1. Alloc

    Alloc

    Joined:
    Jun 5, 2013
    Posts:
    241
    Hi,

    one of our biggest gripes with the current system to build AssetBundles is that we have to select one of the BuildTargets, i.e. Windows/Linux/macOS for us. It looks like the only difference between them are the shaders though that are obviously missing if the selected target did not have the rendering API as the platform that is using the bundle (e.g. building a Windows bundle and running on macOS + Metal). Everything else seems to be fine though, e.g. having a Windows bundle and the Windows settings include DX, Vulkan, GLCore and then use it on Linux with either the GLCore or Vulkan backend.

    Now for us ourselves we could obviously change our build process to create our bundles three times, one for each target platform. That's really mostly just an annoyance as it would take a while longer for a build to be created, but not hurt us any further.

    The bigger issue is coming up when we look at modders. We want our game to be as modding friendly as possible and that includes our users to be able to build new assets, and the only feasible way for that seems to be having them create bundles. But for one they will likely not be aware of that issue, furthermore not even interested in supporting all platforms. Also it would be an issue for distribution and making sure every user of such a mod would get the appropriate bundles.


    It would be really nice if we could select multiple BuildTargets at once or specify the graphics APIs when building so the other shaders get included too. At least for the PC platforms it seems that's the only issue with sharing the same bundles.

    TLDR: Please add an option to the BuildPipeline.BuildAssetBundles methods to either specify multiple BuildTargets or allow specifying the GraphicsDeviceTypes so that we can include more shader targets in a single bundle for (standalone) platform compatibility :)

    Regards,
    Chris
     
  2. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,279
    This is a terrible area of asset bundles - we use them for models and just load one bundle on any standalone platform then do a material replace by name. This kind of works but you can get shader warnings on loading before assigning new materials.
    If the shaders have to be stored in a compiled state then they should indeed be stored for all possible platforms, better for models would be to store the materials as simple descriptions and then create the materials the other end.
     
  3. pdinklag

    pdinklag

    Joined:
    Jan 24, 2017
    Posts:
    154
    I'd like to second this, also with modding in mind.
    I compiled an AssetBundle on Windows and loaded it in Linux and vice versa. Everything works - even compiled scripts. The only thing that breaks are materials, due to shaders not being cross-platform.

    There should be some option to have them compiled on the client at the cost of extra loading time.
     
  4. Alloc

    Alloc

    Joined:
    Jun 5, 2013
    Posts:
    241
    Well, compiling on the client (wonder how long that would take considering the game should know the exact variant it would have to compile) or just as I suggested let us include more shader target platforms than just those of a single build target platform :)
     
    pdinklag likes this.
  5. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    A work around to reduce compile times / bundle variants using the Scriptable Build Pipeline:
    - Assign all & only content that is platform specific only (in your case shaders) to 1 or more common bundles.
    - Rebuild for each platform

    SBP caches build data and in this case should only rebuild the platform specific bundle you created. Once it is built, take the bundle and rename the file with _mac, or _win and load the necessary one at runtime. Since they all contain the same layout, but different data, they can be swapped out at load time while all the other bundles remain the same.
     
  6. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,279
    The documention doesn't actually specify what is unique per platform or why you can build 3 versions for windows (normal, 64bit WSA - what is the difference?)
    I suggest the best system in future would be mesh files with material names and separate material libraries
     
  7. Alloc

    Alloc

    Joined:
    Jun 5, 2013
    Posts:
    241
    Hi @Ryanc_unity ,

    I'm glad to know that a Unity dev actually noticed this thread :)
    What you suggested sounds like a possible workaround, though I think it will put quite a bit of additional workload on a lot of devs as everyone would have to basically reimplement the same stuff over and over again. Also it would either require bundles depending on one another (we haven't done that yet, so not sure to what extent this works) or assigning the shaders to the gameobjects at runtime by manual code.

    Supporting building bundles with a specific set of target graphic APIs (or those defined from multiple target platforms as defined through the project settings) would completely resolve this issue for every dev at once, including people that use Unity in combination with modding for games, without getting into any cross-bundle reference and platform dependent loading stuff. I suppose adding that should not be much of an issue either, as multiple shader targets are already included in bundles if you build for a target platform that has multiple APIs selected.

    Is there any chance something like this is provided by Unity in the (foreseeable) future? :)

    Regards,
    Chris
     
  8. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    Probably not, Unity is moving in a direction where built data is becoming more and more platform specific, for one, some platforms have restrictions that require us to only produce certain data layouts, and for two, to improve performance, executable size, and scaling on all platforms. To handle the complexity this entails more and more tooling is being developed to assist with building (Scriptable Build Pipeline, DOTS Conversion Pipeline), managing, and loading (Addressables, DOTS binary formats) the appropriate data.