Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

[Feature request] UAV write in cloesesthit and multi pass support for RayTracingShader.SetShaderPass

Discussion in 'General Graphics' started by guoxx_, Mar 7, 2022.

  1. guoxx_

    guoxx_

    Joined:
    Mar 16, 2021
    Posts:
    55
  2. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    176
    Hi!

    You can write to UAVs from a closest hit shader only if they are declared as global resources. Global resources have a special declaration:

    E.g.

    RWTexture2D<float4> g_Output0 : register(u0, space1);
    RWTexture2D<float> g_Output1 : register(u1, space1);

    Notice the 'register' usage here. Normally if not declared, DXC uses register space 0 and the register indices are automatically assigned by the compiler.

    If you want to use global resources then it's better to make a header file and put all global resource declarations there and include the header in your shader code.

    If UNITY_RAY_TRACING_GLOBAL_RESOURCES shader define is 1 then you can use global resources in your version.

    To bind global resources you can use Shader.SetGlobalTexture or CommandBuffer.SetGlobalTexture if you use command buffers.

    There are no plans to add multi pass support.
     
  3. guoxx_

    guoxx_

    Joined:
    Mar 16, 2021
    Posts:
    55
    Hi, thank you very much for the reply! One more questions, does Unity has plan to support bindless resources?
     
  4. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    176
  5. guoxx_

    guoxx_

    Joined:
    Mar 16, 2021
    Posts:
    55

    Hi, I tried your suggestions in Unity 2021.2.12, UAV write to RWBuffer is fine, however RWTexture2D is not supported, Unity engine report following errors:

    d3d12: Couldn't bind a global Compute Buffer resource in a Ray Tracing Shader from "Custom/DXRSubsurface". Compute Buffer "_DepthTexture" was not set.
     
  6. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    176
    Hi! Is _DepthTexture a RenderTexture? The message suggests that is not.
    Do you set it as I suggested using SetGlobalTexture? This should happen before the DispatchRays call.

    Could you paste a snipped of you code here where you bind the RenderTexture and do the DispatchRays. If not you can file a bug report and I'll be happy to take a look.
     
  7. guoxx_

    guoxx_

    Joined:
    Mar 16, 2021
    Posts:
    55
    HLSL code:

    RWTexture2D<float> _DepthTexture : register(u0, space1);

    void someFunction()
    {
    _DepthTexture[int2(0,0)] = 0;
    }

    C# code:

    cmd.SetGlobalTexture("_DepthTexture", myRenderTexture)
    cmd.DispatchRays(...)


    /
     
  8. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    176
    This issue has been fixed in 2022.2.0a10 and backported to 2021.3.2f1.