• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
relaxok

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

16 posts in this topic

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

here's the proof:

[img]http://bh.polpo.org/pixelshader_wtf.png[/img]
0

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1330319591' post='4916893']
First thought - is any kind of blend mode enabled?

Also, what kind of render-target is that?
[/quote]

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
0

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1330324853' post='4916904']
Can you post the HLSL?
[/quote]

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).

[url="http://codepad.org/WAAklQ2G"]http://codepad.org/WAAklQ2G[/url]

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.
0

Share this post


Link to post
Share on other sites
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...
0

Share this post


Link to post
Share on other sites
[quote name='Jason Z' timestamp='1330351353' post='4916988']
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...
[/quote]

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:

[img]http://bh.polpo.org/pixelshader_wtf4.png[/img]


Here are the OutputMerger infos:

[img]http://bh.polpo.org/pixelshader_wtf4b.png[/img]

[img]http://bh.polpo.org/pixelshader_wtf4c.png[/img]
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
One other tidbit of information.. i get rid of 80% of the problem if i force output.meshNum to 251 in the vertex shader! 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 251 in all of them even without doing that, but it's like PIX doesn't know what's up.

The interesting thing is is that with 80% of the problem removed, 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 wasn't really 'getting rid' of 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.
0

Share this post


Link to post
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]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.[/left][/size][/font][/color]

[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]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.[/left][/size][/font][/color]

[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]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.[/left][/size][/font][/color]

[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]I wish I could take more video - but anyway the video I posted is pretty similar to what is happening[/left][/size][/font][/color]



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

Share this post


Link to post
Share on other sites
[quote name='relaxok' timestamp='1330425453' post='4917358']
This sort of thing makes you want to give up programming altogether.
[/quote]

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!
0

Share this post


Link to post
Share on other sites
[quote name='kauna' timestamp='1330433404' post='4917373']
[quote name='relaxok' timestamp='1330425453' post='4917358']
This sort of thing makes you want to give up programming altogether.
[/quote]

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!
[/quote]

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.
0

Share this post


Link to post
Share on other sites
Two things:[list=1]
[*]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.
[/list]
1

Share this post


Link to post
Share on other sites
[quote name='MJP' timestamp='1330465740' post='4917518']
Two things:[list=1]
[*]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.
[/list]
[/quote]

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.
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
[quote name='MJP' timestamp='1330485457' post='4917608']
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.
[/quote]

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:

[url="http://codepad.org/1LgyyBhh"]http://codepad.org/1LgyyBhh[/url]

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:
[img]http://bh.polpo.org/pixelshader_wtf10.png[/img]

Post-VS:
[img]http://bh.polpo.org/pixelshader_wtf10b.png[/img]


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:

[url="http://bh.polpo.org/simplify_badpixels.wmv"]http://bh.polpo.org/simplify_badpixels.wmv[/url]

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:

[url="http://bh.polpo.org/simplify_goodpixels.wmv"]http://bh.polpo.org/simplify_goodpixels.wmv[/url]

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?
0

Share this post


Link to post
Share on other sites
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..
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0