0
\$\begingroup\$

I have a problem with converting my pixel shader to compute shader. The error is in this piece of code:

 [numthreads(32,32,1)]
 void CS_PostDeferredReflex( uint3 nGid : SV_GroupID, 
     uint3 nDTid : SV_DispatchThreadID, uint3 nGTid : SV_GroupThreadID )
 {
   if (any(nDTid.xy >= float2(SM_SCREENX, SM_SCREENY))) return;
   uint Output = UAVDiffuse0[nDTid.xy];
   float4 ColorOut = float4(Output&0x000000FF, (Output&0x0000FF00)>>8,
                       (Output&0x00FF0000)>>16, (Output&0xFF000000)>>24)*INV255;
   float D = txDepth1.Load(uint3(nDTid.xy,0), 0);D=(D==1)0:D;
   if (ColorOut.a*D == 0) return;

Which gives the following:

error X3671: loop termination conditions in varying flow control cannot depend on data read from a UAV

Here the UAV UAVDiffuse0 is a R32UINT that is unpacked as RGBA ColorOut.

If the alpha value is zero (or the Depth not [0<D<1]) I don't need to go further. The compiler is unhappy with the last line where the exit is based on the UAV read. I don't understand why we have this limitation.

\$\endgroup\$
1

2 Answers 2

1
\$\begingroup\$

The answer is effectively to use [allow_uav_condition] but in the right place

what does not work is to place the condition before the if statement even if it is where I need it

 [allow_uav_condition]
 if (ColorOut.a*D == 0) return;

in the code I have a loop so what works is to place the condition before the loop, even if in the loop I have no test against the UAV, just write to it.

 ...code
 if (ColorOut.a*D == 0) return;
 ...code
 [allow_uav_condition]
 for ()
 {
   ....code
 }
\$\endgroup\$
0
\$\begingroup\$

Finally I set the A channel of my UAV into another texture which solve the problem but it is annoying as this needs an extra 8 bit resource and my UAV alpha channel is now useless.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .