PDA

View Full Version : Debugging a specific variable inside a nested functions



FrankBoltzmann
05-21-2015, 10:21 AM
Hi,

I'm currently doing a large shader where I need functions to create layers of abstraction. I have some loops (I know, bad) in some of my functions and I implement a loopbreaker to prevent infinite loops. I don't know if this is good or bad practise, but I'd like to check if my loopbreakers are being hit and for what fragments this happens. Is there an easier way to do this than propagating some kind of out bool loopbreaking parameter up until my main() catches it and outputs an ultragreen color for those fragments? (that's how I debug my shader code most of the times) Maybe altering the output register and jumping to program exit? (can I actually go into assembly and do this? safely?)

Thank you

Alfonse Reinheart
05-21-2015, 11:50 AM
Is there an easier way to do this than propagating some kind of out bool loopbreaking parameter up until my main() catches it and outputs an ultragreen color for those fragments? (that's how I debug my shader code most of the times)

You could just have that function write to a global out variable (https://www.opengl.org/wiki/Fragment_Shader#Outputs). You can write multiple colors, after all; outputs don't have to be written from `main`.

But if you're going to conditionally write to this variable, you need to make sure that you unconditionally write to it first. That can happen in `main`.

Or you could use Image Load/Store (https://www.opengl.org/wiki/Image_Load_Store), which isn't all that different.


Maybe altering the output register and jumping to program exit?

No. That's not how fragment shader's work.


(can I actually go into assembly and do this? safely?)

No.

FrankBoltzmann
05-21-2015, 12:31 PM
Nice to see you at the forums again! Thanks for the answer, very helpful. I forgot I could just output to the global out variable! However, if in my main I have something that does alter that same global out variable, I could make it check the global out variable first to see if it has not been changed before, right? That or I could use something like an atomic counter to flag any fragments that need a different color.