Greetings.
I'm working on GUI. I have a parent-child relationship and I want to make parent "maskable", i.e. every child pixel outside parent should be discarded. The problem is that I render my GUI in single pass and can't figure out how to use stencil (I think it's not possible in my case). Also my elements are semi-transparent.
I render all elements without depth test - I submit geometry in order - from deepest to nearest. And I'm trying to achieve the following:
I numerated the quads by order. 1 - deepest one, next 2, 3 is a child of 2 and should be clipped, 4 is above 2 (and 3 since it's a child). All quads are semi-transparent.
As you can see - stenciling will not help here. I tried different approach - every element have an id. Every child also have parent id. In fragment shader when I render a parent I write to a RWTexture an id. Next when I render a child - I check if a RWTexture have a parent id. If no - discard pixel. That worked amazingly well! But here http://www.gamedev.net/topic/665588-does-gpu-guaranties-order-of-execution/ clever guys told me that pixel shader executes in random order and writes to RWTexture happens randomly. So it's possible that child will try to write before parent (thought I never see this in my tests). And I can't rely any more on this technique. And right now I don't have any ideas how to achieve clipping in single draw call.
P.S.: the layout and number of element is not known at compile time. Also elements can be transformed and have round corners so there's no way to analytically calculate child pixel position relative to parent.