Jump to content

  • Log In with Google      Sign In   
  • Create Account

How is it possible for the output register in a pixel shader to differ from PS output?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
16 replies to this topic

#1 relaxok   Members   -  Reputation: 133

Like
0Likes
Like

Posted 26 February 2012 - 09:53 PM

Basically, the topic title is the question... any ideas?

here's the proof:

Posted Image

Sponsor:

#2 Hodgman   Moderators   -  Reputation: 30387

Like
0Likes
Like

Posted 26 February 2012 - 11:13 PM

First thought - is any kind of blend mode enabled?

Also, what kind of render-target is that?

#3 relaxok   Members   -  Reputation: 133

Like
0Likes
Like

Posted 27 February 2012 - 12:09 AM

First thought - is any kind of blend mode enabled?

Also, what kind of render-target is that?


I have a blend state with alpha enabled most of the time, but switch BlendEnable to False for this terrain drawing - and it's just a basic render target setup like in most boilerplate, do you mean some specific parameter it was created with?

The weird thing is it's not all pixels - some pixel shader output is absolutely correct (and the debugger register will match what it says the pixel shader output is in PIX), but then the pixel right next to it will be almost black despite having a similar color in the output register - like the one i pasted.

This is a video where you can see the wrong pixels as a sort of artifact:

http://bh.polpo.org/texture_wtf.wmv

#4 Hodgman   Moderators   -  Reputation: 30387

Like
0Likes
Like

Posted 27 February 2012 - 12:40 AM

Can you post the HLSL?

#5 relaxok   Members   -  Reputation: 133

Like
0Likes
Like

Posted 27 February 2012 - 12:58 AM

Can you post the HLSL?


Here is a simplified version with a bunch of unused and unrelated stuff removed - i used this version with the same problematic result (random black pixels).

http://codepad.org/WAAklQ2G

I will soon be turning the ugly tons-o-texture-registers thing into another Texture2DArray but for now need those helper functions to return the correct one.

My confusion/issue still arises from the fact that I was under the impression the output register o0 is exactly the same as the 'pixel shader output' in PIX. It not being the same kind of breaks my brain/world. So there may very well be an issue with what I'm doing in the shader, but the output register looks correct.

#6 Molle85   Members   -  Reputation: 172

Like
1Likes
Like

Posted 27 February 2012 - 05:19 AM

You are comparing floating points without any epsilon, you might wanna reconsider that

#7 Jason Z   Crossbones+   -  Reputation: 5062

Like
0Likes
Like

Posted 27 February 2012 - 08:02 AM

Can you show in PIX what the OutputMerger state is? Perhaps there is something happening between your pixel shader and the render target writing that you haven't noticed before...

#8 relaxok   Members   -  Reputation: 133

Like
0Likes
Like

Posted 27 February 2012 - 11:04 PM

Can you show in PIX what the OutputMerger state is? Perhaps there is something happening between your pixel shader and the render target writing that you haven't noticed before...


Okay, however isn't the Pixel Shader Output unaffected by the OutputMerger, and post OutputMerger color is shown by the 'Final framebuffer color'?

I'm now drawing JUST the base opaque texture sampled, so no alpha blending at all.. and still getting the following behavior:

Posted Image


Here are the OutputMerger infos:

Posted Image

Posted Image

#9 relaxok   Members   -  Reputation: 133

Like
0Likes
Like

Posted 28 February 2012 - 04:08 AM

A little update on this. I have no idea whats up with the pixel shader output not matching the output register, probably just a PIX bug in the debugger values.

However, I have narrowed down the problem to how the StructuredBuffer is being acessed with the meshNum from the input structure as an index.

I have done a test where I made sure the meshNum was always the same number when writing the vertices to the VB -- 251 in this case, since it was one of the messed up ones e.g. in that video I posted.

However.., amazingly accessing that StructuredBuffer TexIndices, with TexIndices[input.meshNum] returns different things depending on the pixel?? You can see it's almost random corruption in the video I linked above. If i FORCE it to index with the value 251 in the shader, as in specifically calling TexIndices[251] it will always be correct. So somehow the input.meshNum gets altered in the registers in some random fashion. It is NOT the StructuredBuffer itself getting corrupted because like I said it's fine if i index into it with a constant. Even on the pixels it's messed up on, the debugger shows 251 for the meshNum it's going to index with, as does the vertex shader which just copies that value, so it makes no sense.

I really think this must be some sort of dx11 bug or else some very weird behavior from this combination of techniques. I have wrestled with it all week and this is probably the closest I can get to determning the problem without someone way smarter than me suggesting things to try.

#10 relaxok   Members   -  Reputation: 133

Like
0Likes
Like

Posted 28 February 2012 - 04:37 AM

One other tidbit of information.. It 'improves' the performance and reduces artifacts if I directly set the meshNum in the vertexshader to 251 as well?! So it's getting corrupted in the vertex shader as well. If I debug any of the vertices in a PIX frame capture, the meshNum is correctly 251 in all of them even without doing that override. It's like PIX doesn't know what's going on.



The interesting thing is is that with this override, the corruption is much more infrequent - in fact, when i tried to fraps it and the framerate went down to 60 fps, I couldn't get it to happen - but it happens every 0.25 second or so at 1000 fps.



Granted, this doesn't really matter for fixing the problem, because in the end I can't force a value, it needs to be the one it gets from the vertex format.



I wish I could take more video - but anyway the video I posted is pretty similar to what is happening





This sort of thing makes you want to give up programming altogether.

#11 kauna   Crossbones+   -  Reputation: 2514

Like
0Likes
Like

Posted 28 February 2012 - 06:50 AM

This sort of thing makes you want to give up programming altogether.


This sort of thing is usually question of some a little bug in the program. Never give up. Narrow down your problem and find a solution.
Can you post the hlsl shader and the code where you set your textures, constants etc?
Have you made sure that there isn't any NaNs/INFs passed to your shader?

Cheers!

#12 relaxok   Members   -  Reputation: 133

Like
0Likes
Like

Posted 28 February 2012 - 02:24 PM


This sort of thing makes you want to give up programming altogether.


This sort of thing is usually question of some a little bug in the program. Never give up. Narrow down your problem and find a solution.
Can you post the hlsl shader and the code where you set your textures, constants etc?
Have you made sure that there isn't any NaNs/INFs passed to your shader?

Cheers!


Thanks for reminding me not to give up :)

I will post a bunch more relevant info later when I'm at home again, however here's the problem in a nutshell that I can't seem to get my mind around...

If i look in the PostVS vertices in PIX, there is a MESHNUM semantic which is one of the vertex elements, and every single one is 251 - correctly. But the pixel output is somewhat corrupted later as described.

However, I can get rid of much of the artifacts, by explicitly setting input.meshNum to 251 in the vertex shader.

Disregarding anything else, this is broken down to a very specific problem.. how is it possible for that to happen if the debugger is correct?

The only thing I can think of is that the slowwww framerate when you capture a frame in PIX keeps it from happening.

#13 MJP   Moderators   -  Reputation: 11367

Like
1Likes
Like

Posted 28 February 2012 - 03:49 PM

Two things:
  • The PIX debugger is not 100% reliable. It doesn't debug on the hardware, nor does it use the actual microcode executed by the hardware. Consequently it's very possible to get different results in the debugger vs. what actually gets written to memory. Nvidia's Parallel Nsight is capable of hardware debugging, but you need either a second GPU or another PC for remote debugging. It's also for Nvidia only. AMD has a debugging tool which may give you better results than PIX, but it does not use hardware debugging.
  • Driver bugs come up all of the time, in all kinds of weird ways. Sometimes you get weird results from an optimization, or sometimes your app might just crash from some bad combination of shader instructions. The best way to narrow down a driver bug is try using the REF device. If you get correct output from the REF device, then it's very likely that you hit a driver bug. If you have a hit a bug it can be hard to work around...often your best bit is to either start disabling things until you find the problem spot or you can try writing your code in a different way (for instance compiling in a constant value instead of pulling it from a constant buffer) to see if you start getting the correct behavior.


#14 relaxok   Members   -  Reputation: 133

Like
0Likes
Like

Posted 28 February 2012 - 08:57 PM

Two things:

  • The PIX debugger is not 100% reliable. It doesn't debug on the hardware, nor does it use the actual microcode executed by the hardware. Consequently it's very possible to get different results in the debugger vs. what actually gets written to memory. Nvidia's Parallel Nsight is capable of hardware debugging, but you need either a second GPU or another PC for remote debugging. It's also for Nvidia only. AMD has a debugging tool which may give you better results than PIX, but it does not use hardware debugging.
  • Driver bugs come up all of the time, in all kinds of weird ways. Sometimes you get weird results from an optimization, or sometimes your app might just crash from some bad combination of shader instructions. The best way to narrow down a driver bug is try using the REF device. If you get correct output from the REF device, then it's very likely that you hit a driver bug. If you have a hit a bug it can be hard to work around...often your best bit is to either start disabling things until you find the problem spot or you can try writing your code in a different way (for instance compiling in a constant value instead of pulling it from a constant buffer) to see if you start getting the correct behavior.


Thanks, that makes me feel so much better. I wish i had a 2nd card to use Nsight shader debugging with.

I'll check REF when I get a chance later. I *am* using beta drivers, since they are required to use nsight at all, supposedly. so maybe i'll try downgrading to the latest stable driver if REF seems fine.

#15 MJP   Moderators   -  Reputation: 11367

Like
0Likes
Like

Posted 28 February 2012 - 09:17 PM

Also this might be unrelated, but are you actually using alpha to coverage? If not, you could try disabling it to see if it helps.

#16 relaxok   Members   -  Reputation: 133

Like
0Likes
Like

Posted 29 February 2012 - 01:02 AM

Also this might be unrelated, but are you actually using alpha to coverage? If not, you could try disabling it to see if it helps.


OK -- Just tried the REFERENCE driver and it's still happening (albeit at 0.5 fps!) - so a driver bug is not my savior =(

I am using alpha to coverage yeah, however I have tried disabling it and it had no effect.

It's really weird to me that even with the reference driver it's happening, and that PIX debugging is actually incorrect as far as the values it's showing.

I really can't imagine what the issue is, other than some kind of memory corruption/scribbling (but by whom?!) or something related to the multithreading? I don't think the deferred context is doing anything though..

OK, i've VERY much simplified the shader code to show the precise problem now..

here is the current very trimmed down HLSL:

http://codepad.org/1LgyyBhh

here is PIX showing that the MESHNUM variable in the vertex structure is 251 (it's 251 all the way down but this is just a still shot of the top few:)

Pre-VS:
Posted Image

Post-VS:
Posted Image


As you can see for this test I default the pixel color to 'see through' basically (0,0f/0.0f/0.0f/0.0f), so you can see the bad pixels show through to the background.. here is a video:

http://bh.polpo.org/simplify_badpixels.wmv

If you simply comment out lines 108-110 of the shader there, and uncomment line 106, the result SHOULD be identical. A video of this method shows it's perfect:

http://bh.polpo.org/simplify_goodpixels.wmv

So, to my eyes the only possible things that can be happening are:

-- the bytes of memory that contain the last float in the vertex structure are getting corrupted in memory. And it can't be something specific to the videocard because it happens in the REFERENCE device. DirectX is doing it somehow. And it's not affecting the rest of the vertex structure, otherwise there'd be issues with the vertices and texture coords, etc..

OR

-- PIX isn't really showing what the real vertex structure values are, and it's not really 251. If not, why not, and what could possibly be overwriting it.. and is there anything else I can do besides getting a setup that can use NSight and seeing what the hardware shows?

#17 relaxok   Members   -  Reputation: 133

Like
1Likes
Like

Posted 29 February 2012 - 02:00 AM

UPDATE:

Solved!! The person who mentioned the floating point comparisons was on the right track. I needed to be round()-ing the floats, not just casting to int. There were apparently lots of 250.999999 in there (Showing up as 251.000 in PIX) and int was rounding them down to 250 which is a different set of textures in TexIndices... and so on for other areas of the terrain.

Thanks to MaulingMonkey on gamedev irc..

And thanks to all for your suggestions, I learned a lot along the way..




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS