Search Unity

Official Unity is adding a new "DXC" HLSL compiler backend option

Discussion in 'Shaders' started by Aras, Apr 2, 2021.

  1. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Hey! So Unity has been using Microsoft's "FXC" HLSL compiler (plus our own HLSLcc when targeting Vulkan/Metal/OpenGL) for years. However FXC has a bunch of issues, like no support for some modern GPU features, extremely slow compile times for some shaders, and so on.

    Over the past year we've been chipping away at integrating Microsoft's "new" HLSL compiler, called "DXC". Right now in 2021.2 alpha builds it kinda mostly works, with a bunch of caveats and gotchas. On the plus side, it does support modern GPU features (like wave/simd-group functions), and overall is about 4x faster at compiling shaders than the old compiler was.

    If you have a bunch of shader code written or are just interested in playing around with it, we'd love your feedback! The new compiler is completely opt-in per-shader.

    Here's a long google doc: DXC shader compiler integration, 2021.2 - with instructions how to use it via a #pragma in a shader, what works (DX12, Vulkan, Metal), what does not work (DX11, GL), what are the various HLSL syntax bits that were supported by the old compiler but not by the new one, and so on.

    At this point due to various gotchas (see the doc above) we would not recommend using DXC in production, but testing your shader codebases with it, or playing around with it would be much appreciated.
     
    Last edited: Apr 2, 2021
    mandisaw, BradZoob, Camarent and 5 others like this.
  2. JiangBaiShi

    JiangBaiShi

    Joined:
    Aug 3, 2019
    Posts:
    27
    I tried to use #pragma require WaveMultiPrefix to enable shder model 6.5 features.
    I'm using Unity2020.2.0b14, URP 11;
    The gfx backend is DX12, on windows platform.

    But these following error occurred:
    • Shader Compiler Socket Exception: Terminating shader compiler process
    • Shader Compiler: Compile StampVertexGenerator.compute - StampVertexGenerator_SpawnStampVertices: Internal error communicating with the shader compiler process. Please report a bug including this shader and the editor log.
     
  3. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    The document says FXC doesn't support ray tracing shaders, but then how did Unity compiled them up to now?
     
    jungduri likes this.
  4. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Unity already used DXC just for the raytracing shaders.
     
  5. TLukas

    TLukas

    Unity Technologies

    Joined:
    Jan 29, 2019
    Posts:
    5
    We could not reproduce this on 2020.2.0b14.3668 by just adding #pragma require WaveMultiPrefix to any shader. Could you file a bug report with the exact shader as the error message mentions, preferably from your exact your version of Unity.

    Note that our DXC backend has been updated multiple times since 2020.2.0b14 so the crash is likely fixed in latest 2021.2

    However,
    in 2021.2 we do now observe that #pragma require WaveMultiPrefix produces "error: validator version 1,4 does not support target profile." which looks like a bug with DXC or with the Windows SDK. We will look into this more.
     
    PutridEx likes this.
  6. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    This is both exciting and terrifying. Having barycentrics available is something I've often hacked around with baking colors into the mesh, being able to get them natively will be really huge. And a 12x compile speedup on a ton of shaders is amazing.

    Currently I'll have to adapt things for a few issues present in the doc. Better Shaders uses VFace instead of SV_IsFrontFace, but that should be an easy switch. The one which is harder is being able to write to a global or cbuffer variable - I use that pattern a lot with Stackables, as coupled with a define it makes it easy for different stackables to leave optional scratchpad data for other stackables to use. However, I can come up with some kind of blackboard concept that builds a struct that gets passed between stackables to get around this I think. To be clear, this means you cannot write to a variable in the global namespace or in the PerMaterial CBuffer from within the shader, correct? Also, another doc mentions a -gec flag - is there a downside to using this flag to maintain backwards compatibility? And could it be enabled somehow from the shader?

    The move to a #pragma require system over shader targets also sounds great - but can the requirements not be inferred from parsing the code? IE: If I use barycentrics, then the requirement is known. (Though I suppose this would require understanding the state of various conditional compiles, which could be involved).

    tex2D is extremely common in shaders and apparently not allowed anymore (and I assume all the old variants as well). That seems like a huge one, especially for people who are quickly porting surface shaders to Better Shaders, since switching every texture sample around is a lot more work (it's almost copy/paste now). Perhaps adding warnings about it to the current compiler would be a good thing to get people to start moving now?

    Given the current state in that doc, it does seem like it'll be a few years before the old compiler can be pulled. Still, I'd like to get BetterShaders in compliance sooner rather than later, as the community using it is still pretty small.
     
  7. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    FWIW barycentrics do require GPU (and the graphics API) to support it, so for example they will never work on DX11 :(

    Yeah, this means you can't write into any cbuffer (including the implicit globals cbuffer, i.e. loose global variables).

    "-gec" flag has downsides in that while it enables this "allow writing into cbuffers" behavior, it disables some of more recent DXC features, so it's kinda neither here nor there.

    The problem is that you need to pass the "which shader target model?" to the DXC (and FXC) compiler before starting compilation, so it's either "compile twice, once to max supported feature set to find the features used, then into the minimal featureset that still has all the features", or to do a text-based search through the shader for what is used or not (and text based searches are extremely brittle).

    That's actually not a problem! We emulate it on DXC just like we emulate lack of it in some console shader compilers. If you look at HLSLSupport.cginc in recent Unity versions, there's like
    Code (CSharp):
    1. // DXC no longer supports DX9-style HLSL syntax of sampler2D, tex2D and friends.
    2. // Emulate those using our own small structs & functions that have a combined sampler & texture.
    3. #if defined(UNITY_COMPILER_DXC) && !defined(DXC_SAMPLER_COMPATIBILITY)
    4. #define DXC_SAMPLER_COMPATIBILITY 1
    5. struct sampler1D            { Texture1D t; SamplerState s; };
    6. struct sampler2D            { Texture2D t; SamplerState s; };
    7. struct sampler3D            { Texture3D t; SamplerState s; };
    8. struct samplerCUBE          { TextureCube t; SamplerState s; };
    9.  
    10. float4 tex1D(sampler1D x, float v)              { return x.t.Sample(x.s, v); }
    11. float4 tex2D(sampler2D x, float2 v)             { return x.t.Sample(x.s, v); }
    12. // ...
    And then the rest of the code can use it and things work out fine.

    Yes quite likely some time until we can pull it. It will have to happen at some point though, which is exactly why we thought it would be good to give a heads up on "hey DXC is coming!".
     
  8. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Damn, so stuffing colors for the next 8 years or so. One day we'll have nice things..

    Great. I switched over from VFace to SV_isFrontFace this morning- does that have any issue on older APIs? I chose VFace because it was the older semantic and potentially supported on more platforms, but wasn't sure if SV_isFrontFace was.

    Which reminds me, it would be very nice if these abstraction layers were included for switch/xbox/ps4 - I suspect they are not for legal reasons, but they are all over the net, even in Unity's own public github hosted projects. So I've managed to hack together my own version for Better Shaders from multiple sources, but I can't know if they are really correct or updated because I don't have hardware access and the sources are from random versions of Unity. (I'm pushing users to write stuff using the newer semantics, so make the same API available on Built In, because it's a much better abstraction layer than the sorta "This is what we needed to wrap" version in Built In)

    But perhaps a solution is just to include them into the engine, so I can reference them there regardless of which render pipeline is used or which consoles are installed. Since SRPs are now tied to Unity versions, having a way to path to them in the engine would make sense- and then when the abstractions are updated with new consoles or whatever, everything keeps working and is updated automatically. Right now I'm stuffing them into every pass of a shader for the built in pipeline because it's the only way to keep the file portable (since I don't want to require any include files be installed). So that would save about 8k lines of cruft if I could just #include them from somewhere.
     
  9. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    If you look at the compiled shaders, Unity's been replacing
    VFACE
    with
    SV_IsFrontFacing
    and adding a ternary to get a -1.0 or +1.0 value for while because GLSL has never supported
    VFACE
    . GLSL used
    gl_FrontFacing
    from the start, which is equivalent to
    SV_IsFrontFacing
    . hlsl2glslfork changed that back in 2014. It's really only Direct3D 9.0 that used
    VFACE
    .
     
    jbooth likes this.
  10. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Yup, various bits of various NDA platforms can't be included everywhere easily.
     
  11. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Right, and that's understandable - but if I could include a file that existed in the engine (not in the packages) which included all the various platforms that are installed on a machine, then it wouldn't matter. Right now, because all of that stuff is shipped in packages, I have to put together my own version of this stuff for the built in pipeline because it doesn't exist as an include in that pipeline (well, it has it's own version- but the macro's are not the same or complete, so you'd end up having to write different code for SRPs vs. standard again). Since SRPs are going to be shipping as part of Unity now, would I be able to include those files from srp core even if the user doesn't have an SRP installed/active?
     
  12. JiangBaiShi

    JiangBaiShi

    Joined:
    Aug 3, 2019
    Posts:
    27
    Hi, Sorry for the late reply, I tried to upgrade Unity from 2020.2.0b14 to 2020.3.4f1c1, and upgraded my graphics dirver & windows OS to the newest version. However this problem still presents in my project:
    I tested both on Quadro M2000 and GTX 1080, both produces "error: validator version 1,4 does not support target profile" when wavemultiprefix is used in shader code. Can I solve this issue by alternating my windows SDK version? Or I can only wait for you guys to fix it:(
     
    Last edited: Apr 18, 2021
  13. Arycama

    Arycama

    Joined:
    May 25, 2014
    Posts:
    185
    This is pretty neat, I'm looking forward to trying it out.

    Any estimates on how long until it's ready for production? I'm working on a project which is still a while away from release, and is targeting console and PC. So I'd have plenty of time to catch any bugs that pop up.

    Will this make it possible to support proper sampler states in shaders, with the full range of features such as anisotropy, border modes, additional filter modes (Such as min/max, which are handy for Hi-Z generation) etc? There's not really a reason to couple textures and sampler states anymore, right? (Performance-wise, it's also better to re-use sampler states within a shader)

    eg:
    Code (CSharp):
    1. SamplerState _LinearSampler
    2. {
    3.     Filter = MIN_MAG_MIP_LINEAR;
    4.     AddressU = Border;
    5.     AddressV = Border;
    6.     BorderColor = float4(1, 0, 0, 1);
    7. };
    Some other features such as being able to sample a read-only depth buffer, stream-out, adjacency topology, and dual source blending are also noticeably absent and would be handy for advanced graphics features, and I'm sure HDRP can utilize some of them too.
     
  14. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    No, that's completely unrelated to the shader compiler backend. So this will not change by itself just because the compiler is different.

    All of these are also not related to the shader compiler being FXC or DXC. If someone from the graphics teams will decide to expose them, then great. But none of them are related to the shader compiler.
     
    Arycama likes this.
  15. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    I finally got around to try this as well, and while I get this to work:

    fixed4 frag (v2f i, float3 PerspectiveBaryWeights : SV_Barycentrics) : SV_Target


    moving the SV_Barycentrics to the v2f struct

    Code (CSharp):
    1. struct v2f
    2. {
    3.   float4 vertex : SV_POSITION;
    4.   float2 uv : TEXCOORD0;
    5.   float3 PerspectiveBaryWeights : SV_Barycentrics;
    6. };
    throws a shader error
    Shader error in 'Unlit/NewUnlitShader': Semantic SV_Barycentrics is invalid for shader model: vs Use /Zi for source location. (on d3d11)


    Is this expected? I'm on DX12 here right now.
     
  16. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    fherbst likes this.
  17. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    Aras and aleksandrk like this.
  18. Arycama

    Arycama

    Joined:
    May 25, 2014
    Posts:
    185
    Although I don't think this is shader compiler related, @fherbst you should be able to wrap the corresponding line in a macro, eg:

    Code (CSharp):
    1. struct v2f
    2. {
    3.   float4 vertex : SV_POSITION;
    4.   float2 uv : TEXCOORD0;
    5. #ifdef SHADER_STAGE_FRAGMENT
    6.   float3 PerspectiveBaryWeights : SV_Barycentrics;
    7. #endif
    8. };
    Similar macros exist for the other shader stages (Vertex, Domain, Hull, Compute) as detailed in the "Shader Stage Being Compiled" section of: https://docs.unity3d.com/Manual/SL-BuiltinMacros.html

    The DX11 documentation has some more info on which semantics are supported as inputs/outputs for each shader stage: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-semantics
     
    Aras likes this.
  19. AquaGeneral

    AquaGeneral

    Joined:
    Oct 30, 2008
    Posts:
    141
    @Aras Are there any plans to export PBD for DXC compiled compute shaders shaders? In both NVIDIA Nsight and Microsoft's PIX it's not seemingly possible to step-by-step debug compute shaders from a Unity project with shaders compiled with DXC. Thanks for exposing the new functionality by the way! It's tremendously useful.
     
  20. TLukas

    TLukas

    Unity Technologies

    Joined:
    Jan 29, 2019
    Posts:
    5
    Thank you for bringing this to our attention. I'm also guessing it doesn't work with non-compute shaders as well? Looking at the code it seems like we might need to add extra compiler flags to embed PDB into the debug data but this is true for both compute and graphics shaders. We'll investigate this shortly.
     
    Last edited: May 3, 2021
    mandisaw, fherbst and AquaGeneral like this.
  21. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    Good idea! Another change I had to do to get that to work was to ifdef the entire fragment shader as well – a bit clunky, but seems to work.

    The DX11 documentation semantics page is missing the SV_Barycentrics semantic entirely and hasn't been updated in a while...
     
    Last edited: May 4, 2021
  22. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    It's missing a lot of semantics. I kind of don't think it should be up to Unity to keep the semantics page up to date with every single option. Even the official Microsoft HLSL documentation isn't able to do that.
     
  23. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    What is "the semantics page"? Is that about our docs, or Microsoft docs, or...?

    (if it's about our docs, then today nothing related to DXC is documented yet -- this thread & the google doc is kinda a "sneak peek" before we make it more public. Still have to solve DX11 issue somehow or otherwise DXC is not terribly useful in the wild)
     
  24. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Yeah, I assumed @fherbst was referring to Unity's own Semantics documentation. Which definitely has not been updated in a long time. The MSDN semantics link is to a page that technically doesn't even exist anymore, though thankfully Microsoft's documentation is generally good about redirecting dead links. However they could have been referring to Microsoft's HLSL Semantics documentation, which also doesn't include SV_Barycentrics ... it's missing a lot of ShaderModel 6.0+ info. They haven't even finished documenting features of DirectX 11.

    The only place I've found any info about SV_Barycentrics is Microsoft's wiki for DXC itself.
    https://github.com/microsoft/DirectXShaderCompiler/wiki/SV_Barycentrics
    Which does have a lot of good documentation on Shader Model 6.0 features.
    https://github.com/microsoft/DirectXShaderCompiler/wiki
     
  25. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    Sorry for the confusion, I was referring to the DX11 Docs Semantics page that Arycama had linked to which seems to be somewhat outdated as bgolus said better than I - updated my post above to make that more clear :)

    @Aras I totally understand this is all Sneak Peek Preview Alpha Experimental Unsupported Land, and super happy you decided to test this "in the wild"!

    @bgolus yes, the DXC Wiki was what I so far read to piece together the few shaders I tried out, I wasn't able to find understandable sample shaders for 6.0+.
     
  26. guoxx_

    guoxx_

    Joined:
    Mar 16, 2021
    Posts:
    55
    Nice to see Unity make progress on shader programming language, is there any plan to support template function/class?
     
  27. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    What do you mean exactly? (FWIW we are not inventing any new shading languages here -- just updating to the new Microsoft's HLSL compiler. Whatever Microsoft decides to add to HLSL the language, is up to them)
     
  28. AquaGeneral

    AquaGeneral

    Joined:
    Oct 30, 2008
    Posts:
    141
    To add to this, there is early experimental support for templates with the DirectX Compiler itself: https://github.com/microsoft/DirectXShaderCompiler/issues/2145
     
  29. Bruzos

    Bruzos

    Joined:
    Aug 30, 2017
    Posts:
    3
    Hi! I'm using #pragma require WaveMultiPrefix to force DXC to enable shader model 6.5 features. My shader uses
    Code (CSharp):
    1. uint shadingRate                 : SV_ShadingRate;
    in order to do primitive shading rate (the required extension is already activated). This seems to compile for D3D but not for Vulkan. Getting the trace "shader is not supported on this GPU (none of subshaders/fallbacks are suitable)". Any tips on how to make this compile for Vulkan? many thanks!
     
  30. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Does Vulkan even have WaveMultiPrefix equivalent?
     
  31. Bruzos

    Bruzos

    Joined:
    Aug 30, 2017
    Posts:
    3
    I use WaveMultiPrefix because there is no other way from Unity (at least that I know) to force DCX to compile using HLSL 6.5. The question then will be, is there any other way of doing that?
    It'd be nice to have a #pragma ShadingRate so SV_ShadingRate semantic could be supported.
     
    Last edited: Dec 14, 2021
  32. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Ah ok! Point taken, we'll look at what can and should be done.
     
    Bruzos likes this.
  33. TLukas

    TLukas

    Unity Technologies

    Joined:
    Jan 29, 2019
    Posts:
    5
    Looking at the VRS docs by Microsoft it seems that adding the ability to use SV_ShadingRate to the compiler won't actually provide any benefit at this point unless VRS is also enabled on the graphics API side "If a VS or GS sets SV_ShadingRate, but VRS is not enabled, then the semantic-setting has no effect."

    We'll likely hold off adding such a pragma unless we have the required VRS APIs in place.
     
  34. Bruzos

    Bruzos

    Joined:
    Aug 30, 2017
    Posts:
    3
    Hi TLukas, thanks for the reply.
    We are using Vulkan and we have easilly activated the FSR extension by using the Rendering Plugin API (intercepting the required calls). FSR can operate at 3 different levels/methods: pipeline, where you set the rate in the graphics pipeline or in a command buffer; attachment, where you can use an attachment image to control the shading rate and primitive, where you can control the shading rate in the vertex shader (or in the last active pre-rasterization stage).

    The pipeline and attachment methods will require a proper implementation provided by Unity, unless you want to do some nasty tricks to intercept the right calls. But, as far as I know, the primitive method could be used just by activating the extension, activate also the primitive method in the physical device (both are easilly doable) and then using the SV_ShadingRate semantic in HLSL, which translates to the appropiate PrimitiveShadingRateKHR SPIR-V decorator according to this document: https://github.com/microsoft/Direct...PIR-V.rst#implicit-location-number-assignment
     
    Last edited: Dec 17, 2021
  35. Przemyslaw_Zaworski

    Przemyslaw_Zaworski

    Joined:
    Jun 9, 2017
    Posts:
    328
  36. guoxx_

    guoxx_

    Joined:
    Mar 16, 2021
    Posts:
    55
    JiangBaiShi likes this.
  37. guoxx_

    guoxx_

    Joined:
    Mar 16, 2021
    Posts:
    55
    I just noticed that in 2021.2.12f1, UNITY_COMPILER_DXC is not defined for ray tracing shaders, I think it's certainly a bug caused some shader code will be shared between graphics and DXR pipeline, and ray tracing shader certainly compiled with DXC.
     
  38. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    727
    I just tried using

    Code (CSharp):
    1. #pragma require Native16Bit
    in our shaders (PC, Vulkan, unity 2021.2.19f1 with URP) - and it crashes the editor with no crash popup :(
     
  39. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,023
    Sounds like it's worth a bug report :)
    It would be great if you could make one.
     
  40. Error-mdl

    Error-mdl

    Joined:
    Nov 12, 2021
    Posts:
    5
    Not sure if this is the right place to post this, but there appears to be a bug with the DXC compiler and the multiview stereo mode used by the Oculus Quest 2 when using vulkan as the graphics api. Specifically, a shader compiled with DXC doesn't get the correct stereo eye index (0 for both eyes) while the same shader compiled with FXC does. Looking at the URP shader include files, in multiview stereo mode the eye index is supposed to be given to the shader in a special cbuffer as gl_ViewID (see com.unity.render-pipelines.universal/ShaderLibrary/UnityInput.hlsl line 176). The DXC doc mentions that the compiler is doing some remapping of resources for Vulkan shaders to match unity's expectations. My uneducated guess is that this cbuffer isn't getting mapped to the correct resource.


     
  41. TLukas

    TLukas

    Unity Technologies

    Joined:
    Jan 29, 2019
    Posts:
    5
    @Error-mdl Thank you for sharing! It would be great if you could file a bug report (If you haven't already), possibly with the simple repro scene you've made here.
     
  42. Error-mdl

    Error-mdl

    Joined:
    Nov 12, 2021
    Posts:
    5
    Yeah, I've already filed a bug report (IN-6122). Attached is the repro project as well, which was made with unity 2021.3.4f1. If you feel like checking it out, you'll need to actually build and run the project on a quest/quest 2 since multiview stereo is a hardware specific rendering mode that only works on those headsets.
     

    Attached Files:

  43. Error-mdl

    Error-mdl

    Joined:
    Nov 12, 2021
    Posts:
    5
    Ok, so I think I've nailed down exactly where the issue lies. FXC seems to treat the constant buffer OVR_multiview in a special way, not actually using the constant buffer and instead replacing it with a uniform bound to the builtin Vulkan variable ViewIndex (shows up as "Decorate ## BuiltIn ViewIndex" in compiled code). DXC doesn't do this. It keeps the dummy constant buffer and does not add a uniform mapped to ViewIndex. I'm guessing the reason this was done with FXC was there is no equivalent in DirectX to this builtin (until SM6.1), so to keep FXC happy a dummy constant of the same name is declared in the shader and somewhere during the hlsl to glsl translation process swapped out with the real builtin uniform.

    Shader model 6.1 added SV_ViewID which is equivalent to ViewIndex (https://github.com/microsoft/DirectXShaderCompiler/wiki/SV_ViewID). DXC maps SV_ViewID to ViewIndex (https://github.com/microsoft/Direct...PIR-V.rst#implicit-location-number-assignment). However, this requires that the shader target model 6.1 to actually use SV_ViewID, even when compiling to SPIR-V. Since it was decided we shouldn't have access to specifying the minimum shader model, the only option is to try to require a feature introduced in the same or later shader model. For example, using #pragma require barycentrics enables SM6.1. Enabling this also makes SV_ViewID a valid semantic. Compiling the shader like this shows that the SV_ViewID gets correctly mapped to the ViewIndex builtin. Unfortunately, its still completely unusable, since enabling barycentrics causes the "shader is not supported on this GPU" in both the editor and on the quest hardware. So close! The only other require that boosts the shader model to higher than 6.0 is the native 16bit storage extension, which is somehow not supported on the quest, and in editor causes the shader to appear completely corrupted. EDIT: The corruption happens because NVidia apparently doesn't support 16 bit types in interpolators.

    I think we need a special pragma require that tells DXC to target 6.1 or greater without enabling any other vulkan extensions. In Vulkan ViewIndex is part of the default 1.1 spec so there is no specific extension to enable, we just need the compiler to target 6.1 so SV_ViewID is a recognized semantic.
     
    Last edited: Jul 10, 2022
  44. Error-mdl

    Error-mdl

    Joined:
    Nov 12, 2021
    Posts:
    5
    EDIT: I was wrong about the ViewIndex builtin being part of the base spec, on account of the vulkan docs being confusing. There is a device and corresponding shader extension for multiview and enabling ViewIndex (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_KHR_multiview.html).

    Multiview stereo is currently used by the Oculus XR plugin for quest/quest 2. If you can, please add a #pragma require for multiview stereo which sets DXC to target 6.1 and adds the SPV_KHR_MULTIVIEW extension so that SV_ViewID can be used to get the eye index.
     
    Last edited: Jul 10, 2022
  45. jg482

    jg482

    Joined:
    Apr 5, 2018
    Posts:
    8
    Hey there!
    Is there any way we can add or alter dxc compiler flags?
    And can you also tell us if and which of the flags are activated during compilation by default?
     
  46. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,023
    Hi!
    Not right now. We want to expose more control over shader compilation, but we're dealing with more pressing issues at the moment.
     
  47. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156
    Hi,
    On Metal M1, the following kernel fails with no error with dxc (does not get appended, no kernel code executed at all as far as user can tell):
    (appendbuffer stride 68)
    Code (CSharp):
    1. struct TestStruct
    2. {
    3.     float4x4 a;
    4.     float b;
    5. };
    6. AppendStructuredBuffer<TestStruct> _testBuffer;
    7. #pragma kernel Test
    8. [numthreads(1, 1, 1)]
    9. void Test (uint3 id : SV_DispatchThreadID)
    10. {
    11.     TestStruct test;
    12.     test.a = 0.0;
    13.     test.b = 0.0;
    14.     _testBuffer.Append(test);
    15. }
    but this executes and works as expected (appendbuffer stride 64):
    Code (CSharp):
    1. struct TestStruct
    2. {
    3.     float4x4 a;
    4. };
    5. AppendStructuredBuffer<TestStruct> _testBuffer;
    6. #pragma kernel Test
    7. [numthreads(1, 1, 1)]
    8. void Test (uint3 id : SV_DispatchThreadID)
    9. {
    10.     TestStruct test;
    11.     test.a = 0.0;
    12.     _testBuffer.Append(test);
    13. }
    float4x4 + float combo seems to mess something up. Without #pragma use_dxc both execute properly.

    Shader compiler outputs:

    Aligned struct works again, is this intended behaviour (To silently fail)?
    Code (CSharp):
    1. struct TestStruct
    2. {
    3.    float4x4 a;
    4.    float b;
    5.    float c;
    6.    float d;
    7.    float e;
    8. };
     
    Last edited: Dec 3, 2022
  48. BradZoob

    BradZoob

    Joined:
    Feb 12, 2014
    Posts:
    66
    ooh this sounds promising, i hope MS have finally fixed their out of control loop unrolling bugs that just tank processing for 10-15 minutes and can totally just be skipped with compilation tags without any perf changes lol.
     
  49. XinYanQiu

    XinYanQiu

    Joined:
    Aug 29, 2020
    Posts:
    1
    I've tried using pragma use_dxc for my custom deferred SRP pipeline. This SRP pipeline also used RenderPass API. It worked well under Android and Vulkan API. But under Metal ios, something went wrong. I can not figure out. Can you guys help me with that? Thx a loto_O
     

    Attached Files:

  50. guoxx_

    guoxx_

    Joined:
    Mar 16, 2021
    Posts:
    55
    Can we have the option to make dxc compile shader with HLSL 2021? HLSL 2021 has so many features to make shader programming more convenient and easy to maintain.