Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Shader model 6.0 or vendor intrinsics

Discussion in '2020.2 Beta' started by DekkerC, Sep 26, 2020.

  1. DekkerC

    DekkerC

    Joined:
    Oct 7, 2017
    Posts:
    17
    Hi,

    How can I use shader model 6.0 intrinsics or vendor specific intrinsics in Unity?
    I need the intrinsics for cross thread communication within the warp.
    Or is is possible to inject asm into the HLSL code?
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,818
    Hi!
    If you're on Unity 2020.2.0a8 or later, you can add
    #pragma use_dxc
    in your shader.
     
  3. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    389
    Unity has support for DXC starting from 2020.2?
    This is really big. Why isn't it default for now though?
     
  4. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,818
    We have to make sure it works for all required platforms before doing that.
     
  5. DekkerC

    DekkerC

    Joined:
    Oct 7, 2017
    Posts:
    17
    Thnx!
    That's awesome.
    I'll be upgrading today.
     
    aleksandrk likes this.
  6. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,818
    Please don't forget to backup :)
     
    Peter77 likes this.
  7. AquaGeneral

    AquaGeneral

    Joined:
    Oct 30, 2008
    Posts:
    141
    I'm using 2020.2.0b4 and it seems like Shader Model 6.0 intrinsics aren't yet working in compute shaders? Even adding "#pragma target 6.0" (like what is done for older versions) and that doesn't work either.

    Edit: Actually, it seems to be working fine. The compiler was confused because of the type (I had an array).
     
    Last edited: Oct 2, 2020
  8. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,818
    There's no such target right now :)
     
  9. AquaGeneral

    AquaGeneral

    Joined:
    Oct 30, 2008
    Posts:
    141
    It was a last ditch effort xD I thought to be experimental since the only reference at all of #pragma use_dxc is this thread.
     
  10. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,818
    And it is :)
     
    AquaGeneral likes this.
  11. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
  12. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Yeah DXC is not advertised yet because the current state still comes with a massive ton of gotchas. For example, today using it will only make it do something on DX12, etc. etc. It also does not "just work" on all shaders, some of the old HLSL syntax that was accepted by FXC is not actually accepted by DXC. Open questions what to even do about things like DX11, since DXC does not support that at all. So yeah... in progress, but nowhere near being "done" yet.
     
    Egad_McDad and AquaGeneral like this.
  13. DekkerC

    DekkerC

    Joined:
    Oct 7, 2017
    Posts:
    17
    Works like a charm for my shader!:)
    Used it for a radix sort.
    Only gotcha that I have found is that you should stay clear of using [unroll].
    It fills my local variables with random values *ouch*
     
  14. JiangBaiShi

    JiangBaiShi

    Joined:
    Aug 3, 2019
    Posts:
    27
    Hi, I used #pragma use_dxc but it still reports wave intrinsics as undefined identifiers.:
    "use of undeclared identifier 'WaveGetLaneIndex' at kernel XXX"
    My Unity version is 2020.2.0a19, URP Version 8.1.0.
    Could you share some of your experience?
     
    Last edited: Oct 27, 2020
  15. JiangBaiShi

    JiangBaiShi

    Joined:
    Aug 3, 2019
    Posts:
    27
    Hi, I used #pragma use_dxc but it still reports wave intrinsics as undefined identifiers.
    My Unity version is 2020.2.0a19, URP Version 8.1.0.
    Could you share some of your experience?
     
    Last edited: Oct 27, 2020
  16. DekkerC

    DekkerC

    Joined:
    Oct 7, 2017
    Posts:
    17
    I might have a few pointers for you:
    -I think you need to render with DX12.
    -Also #pragma does not work in include files.
    Another thing that you can try is to upgrade to the latest 2020.2 version (I'm using 2020.2.0b8).

    I haven't done anything special with my shader. So for the rest it should just work.
    Haven't personally used WaveGetLaneIndex though. Only WavePrefixSum & WaveReadLaneAt.

    Hope this information helps.
     
    Singtaa likes this.
  17. JiangBaiShi

    JiangBaiShi

    Joined:
    Aug 3, 2019
    Posts:
    27
    Thanks! I tried to switch backend to DX12, it turns out to be my mistake 'cause RenderDoc is crappy with DX12... Everything works, for now.
     
  18. a-chambriat

    a-chambriat

    Joined:
    Apr 27, 2014
    Posts:
    26
    Hello,
    #pragma use_dxc broke shaders in dx11, is there a way to know if its DX12 please ?
    since dx11/dx12 got his one SHADER_API_D3D11, is there some trick ?
    Regards.
     
  19. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,818
    Hi!
    DXC works only for DX12, and there's no trick that will fix it.
    We have a task in the backlog to make shaders for DX11 and DX12 be separate.