Forum

Writing to Depth Buffer with Structured Buffer

I have a pixel shader that is writing to both color & depth (SV_TARGET & SV_DEPTH).

If use any value derived from a structured buffer it’s fine with the color, but not with the depth. Any clues? Simplified patch & shader attached.

// load a vaule from SB
	float myValue = valueDefault;
	uint vCount, dummy;	
	valueBuffer.GetDimensions(vCount, dummy);
	if (vCount > 0)  myValue = valueBuffer[0](0);
	
	Out.Color = float4(In.TexCd.xy,0,1);
	Out.Depth = In.PosWVP.z/In.PosWVP.w;
	
	//error here, writing to color is fine, but depth is not happy
	Out.Color += myValue; //ok
	//Out.Depth += myValue; // not ok
	
    return Out;

DepthWrite.zip (3.5 kB)

https://msdn.microsoft.com/en-us/library/windows/desktop/bb509647(v=vs.85).aspx

I guess this is related? Still don’t understand though tbh. If it’s not possible can use an extra render target for the depth instead of the SV (boo!).

hey man i checked your line of code… all fine here

anyways few stuff i wanted to mention
valueBuffer.GetDimensions(vCount, dummy); <-- Bad idea for a pixelshader (too expensive)

second one, what MS statements means on my taste, that depth get written only in the area ur object covers on the screen

Hey man! Thanks for having a look.

If you uncomment this line you should see the error:
//Out.Depth += myValue; // not ok

that what i did, no errors, i can offset depth whatever i like…

oh! interesting… Here’s what I get if I try to enable that line:

Card / driver difference perhaps?

you’re quite right about asking every pixel to check the buffersize! Don’t think that’s the problem, good point though.

u can also try to change SV_TARGET with SV_Target0 and SV_DEPTH with SV_Depth don’t think there is difference thought, are u on latest DX Build?

No joy changing the naming, also tried driver updates. Not sure about latest DX build- I’m on Windows 8.1 and thought it was already included (correct me here, that’s just from googling).

hmmm how annoying.

I guess he means vux’s dx latest build

i’m on GTX 960, w10
just double checked…
i’m using dx11 build from contributions btw

Ok thanks I’m using that one too. Can anyone else on windows 8 say if this works for them?

cannot reproduce error

win 10, 770 gtx, beta34.2

Seems it is indeed a compiler error.

Was in in fact reported to MS a couple of years ago, and they seem to have kindly fixed it with the newer compiler shipping with windows10.