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

Posted in another sub-forum, please move all discussion into another thread

https://forum.unity.com/threads/feature-request-raytracingshader-setshaderpass-support-multiple-passes.1246894/

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 g_Output0 : register(u0, space1);
RWTexture2D 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.

Hi, thank you very much for the reply! One more questions, does Unity has plan to support bindless resources?

No.

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.

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.

HLSL code:

RWTexture2D _DepthTexture : register(u0, space1);

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

C# code:

cmd.SetGlobalTexture(“_DepthTexture”, myRenderTexture)
cmd.DispatchRays(…)

/

This issue has been fixed in 2022.2.0a10 and backported to 2021.3.2f1.