<div dir="ltr"><div>Qiang,</div><div><br></div><div>Sorry things got so side-tracked....</div><div><br></div><div>Going back to the original conversation, I mentioned that there are two general methods to solve this: Making glsl_to_nir generate int-free NIR and doing some sort of lowering. I believe Jonathan is attempting the first in which case the patch you linked to below is what you want. You likely want more of the patches in his series as well.</div><div><br></div><div>If, on the other hand, someone wanted to attempt the lowering approach, I just sent out something which is my idea of what an after-the-fact type-assignment pass would look like. Be warned that I haven't even compiled it much less tested it but it should give some idea of what needs to be done to figure out the types of SSA values.</div><div><br></div><div>--Jason<br></div><br><div><div class="gmail_quote"><div dir="ltr">On Fri, Jan 4, 2019 at 9:03 PM Qiang Yu <<a href="mailto:yuq825@gmail.com">yuq825@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Thanks for your guys' information, although it's much deeper than my<br>
question and also my understanding of the NIR and compiler knowledge.<br>
<br>
This patch fix my problem:<br>
<a href="https://patchwork.freedesktop.org/patch/268946/" rel="noreferrer" target="_blank">https://patchwork.freedesktop.org/patch/268946/</a><br>
But seems it's not the final solution, right? And I'm not sure if we will<br>
have other integer problem besides constant for non-integer-gpu, do we?<br>
<br>
To be honest, as a backend developer, NIR non-integer-gpu support is<br>
out of my ability. So maybe I have to take this patch temporarily and work<br>
on other topic for sometime to see if any progress of this support in NIR<br>
in the future.<br>
<br>
Thanks,<br>
Qiang<br>
<br>
On Sat, Jan 5, 2019 at 12:40 AM Ilia Mirkin <<a href="mailto:imirkin@alum.mit.edu" target="_blank">imirkin@alum.mit.edu</a>> wrote:<br>
><br>
> On Fri, Jan 4, 2019 at 10:46 AM Jason Ekstrand <<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>> wrote:<br>
> ><br>
> > On Fri, Jan 4, 2019 at 4:07 AM Erik Faye-Lund <<a href="mailto:erik.faye-lund@collabora.com" target="_blank">erik.faye-lund@collabora.com</a>> wrote:<br>
> >><br>
> >> On Thu, 2019-01-03 at 11:58 -0600, Jason Ekstrand wrote:<br>
> >> > On Thu, Jan 3, 2019 at 3:39 AM Erik Faye-Lund <<br>
> >> > <a href="mailto:erik.faye-lund@collabora.com" target="_blank">erik.faye-lund@collabora.com</a>> wrote:<br>
> >> > > On Wed, 2019-01-02 at 10:16 -0600, Jason Ekstrand wrote:<br>
> >> > > > On Wed, Jan 2, 2019 at 9:43 AM Ilia Mirkin <<a href="mailto:imirkin@alum.mit.edu" target="_blank">imirkin@alum.mit.edu</a>><br>
> >> > > > wrote:<br>
> >> > > > > Have a look at the first 4 patches in the series from Jonathan<br>
> >> > > > > Marek<br>
> >> > > > > to address some of these issues:<br>
> >> > > > ><br>
> >> > > > > <a href="https://patchwork.freedesktop.org/series/54295/" rel="noreferrer" target="_blank">https://patchwork.freedesktop.org/series/54295/</a><br>
> >> > > > ><br>
> >> > > > > Not sure exactly what state that work is in, but I've added<br>
> >> > > > > Jonathan<br>
> >> > > > > to CC, perhaps he can provide an update.<br>
> >> > > > ><br>
> >> > > > > Cheers,<br>
> >> > > > ><br>
> >> > > > > -ilia<br>
> >> > > > ><br>
> >> > > > > On Wed, Jan 2, 2019 at 6:28 AM Qiang Yu <<a href="mailto:yuq825@gmail.com" target="_blank">yuq825@gmail.com</a>><br>
> >> > > wrote:<br>
> >> > > > > ><br>
> >> > > > > > Hi guys,<br>
> >> > > > > ><br>
> >> > > > > > I found the problem with this test fragment shader when lima<br>
> >> > > > > development:<br>
> >> > > > > > uniform int color;<br>
> >> > > > > > void main() {<br>
> >> > > > > > if (color > 1)<br>
> >> > > > > > gl_FragColor = vec4(1.0, 0.0, 0.0, 1);<br>
> >> > > > > > else<br>
> >> > > > > > gl_FragColor = vec4(0.0, 1.0, 0.0, 1);<br>
> >> > > > > > }<br>
> >> > > > > ><br>
> >> > > > > > nir_print_shader output:<br>
> >> > > > > > impl main {<br>
> >> > > > > > block block_0:<br>
> >> > > > > > /* preds: */<br>
> >> > > > > > vec1 32 ssa_0 = load_const (0x00000001 /* 0.000000<br>
> >> > > */)<br>
> >> > > > > > vec4 32 ssa_1 = load_const (0x3f800000 /* 1.000000<br>
> >> > > */,<br>
> >> > > > > > 0x00000000 /* 0.000000 */, 0x00000000 /* 0.000000 */,<br>
> >> > > 0x3f800000<br>
> >> > > > > /*<br>
> >> > > > > > 1.000000 */)<br>
> >> > > > > > vec4 32 ssa_2 = load_const (0x00000000 /* 0.000000<br>
> >> > > */,<br>
> >> > > > > > 0x3f800000 /* 1.000000 */, 0x00000000 /* 0.000000 */,<br>
> >> > > 0x3f800000<br>
> >> > > > > /*<br>
> >> > > > > > 1.000000 */)<br>
> >> > > > > > vec1 32 ssa_3 = load_const (0x00000000 /* 0.000000<br>
> >> > > */)<br>
> >> > > > > > vec1 32 ssa_4 = intrinsic load_uniform (ssa_3) (0, 1,<br>
> >> > > 0)<br>
> >> > > > > /*<br>
> >> > > > > > base=0 */ /* range=1 */ /* component=0 */ /* color */<br>
> >> > > > > > vec1 32 ssa_5 = slt ssa_0, ssa_4<br>
> >> > > > > > vec1 32 ssa_6 = fnot ssa_5<br>
> >> > > > > > vec4 32 ssa_7 = bcsel ssa_6.xxxx, ssa_2, ssa_1<br>
> >> > > > > > intrinsic store_output (ssa_7, ssa_3) (0, 15, 0) /*<br>
> >> > > > > base=0 */<br>
> >> > > > > > /* wrmask=xyzw */ /* component=0 */ /* gl_FragColor */<br>
> >> > > > > > /* succs: block_1 */<br>
> >> > > > > > block block_1:<br>
> >> > > > > > }<br>
> >> > > > > ><br>
> >> > > > > > ssa0 is not converted to float when glsl to nir. I see<br>
> >> > > > > glsl_to_nir.cpp<br>
> >> > > > > > will create flt/ilt/ult<br>
> >> > > > > > based on source type for gpu support native integer, but for<br>
> >> > > gpu<br>
> >> > > > > not<br>
> >> > > > > > support native<br>
> >> > > > > > integer, just create slt for all source type. And in<br>
> >> > > > > > nir_lower_constant_initializers,<br>
> >> > > > > > there's also no type conversion for integer constant.<br>
> >> > > ><br>
> >> > > > This is a generally sticky issue. In NIR, we have no concept of<br>
> >> > > > types on SSA values which has proven perfectly reasonable and<br>
> >> > > > actually very powerful in a world where integers are supported<br>
> >> > > > natively. Unfortunately, it causes significant problems for<br>
> >> > > float-<br>
> >> > > > only architectures.<br>
> >> > ><br>
> >> > > I would like to take this chance to say that this untyped SSA-value<br>
> >> > > choice has lead to issues in both radeon_si (because LLVM values<br>
> >> > > are<br>
> >> > > typed) and zink (similarly, because SPIR-V values are typed), where<br>
> >> > > we<br>
> >> > > need to to bitcasts on every access because there's just not enough<br>
> >> > > information available to emit variables with the right type.<br>
> >> ><br>
> >> > I'm not sure if I agree that the two problems are the same or not...<br>
> >> > More on that in a bit.<br>
> >> ><br>
> >> > > It took us a lot of time to realize that the meta-data from the<br>
> >> > > opcodes<br>
> >> > > doesn't *really* provide this, because the rest of nir doesn't<br>
> >> > > treat<br>
> >> > > values consistently. In fact, this feels arguably more like buggy<br>
> >> > > behavior; why do we even have fmov when all of the time the<br>
> >> > > compiler<br>
> >> > > will emit imovs for floating-point values...? Or why do we have<br>
> >> > > bitcast<br>
> >> ><br>
> >> > Why do we have different mov opcodes? Because they have different<br>
> >> > behavior in the presence of source/destination modifiers.<br>
> >><br>
> >> Is this general NIR-behavior (i.e will this be honored by constant<br>
> >> folding etc), or is it Intel specific? If it's NIR-behavior, is it<br>
> >> documented somewhere?<br>
> ><br>
> ><br>
> > No, constant folding doesn't do modifiers. I had completely forgotten about this fact until we started this discussion.<br>
> ><br>
> >><br>
> >> In either case, I have a feeling that this is a mis-design; the<br>
> >> modifiers apply to the operands, not the opcodes. It sounds a bit like<br>
> >> imov shouldn't have been an ALU instruction, but perhaps some other,<br>
> >> new type. Or perhaps the concept we have should have been a bit finer<br>
> >> granularity. It's a bit hard to tell without more details, and I can't<br>
> >> seem to find any on my own.<br>
> ><br>
> ><br>
> > I'm very unclear about what you mean by this remark. Why do you think imov is so special? It's the simplest of all ALU ops because it just passes through it's value. Source modifiers (if you have them) modify the source as per the opcode's stated source type and destination modifiers modify the destination as per the opcode's stated destination type. It's not that complicated. Also, you don't want and shouldn't have source/destination modifiers for a translator like Zink so you shouldn't have to care about them. Nothin in NIR will produce them by default; you have to explicitly call the pass that adds them.<br>
> ><br>
> >><br>
> >> Generally, I wish we had some more of the details here written down.<br>
> >> Implementing support for NIR for a new architecture is currently quite<br>
> >> tricky, mostly because chasing down the details are hard.<br>
> ><br>
> ><br>
> > Yeah... Patches welcome? There have been many attempts by Connor and myself to better document NIR. They all end up in /dev/null due to EBIGGERFIRES. :-(<br>
> ><br>
> > That said, if you ever want to know how something works, I'm logged into IRC 24/7 and will happily answer questions.<br>
> ><br>
> >><br>
> >> > You likely don't use those in radeon or Zink but we do use them on<br>
> >> > Intel. That being said, I've very seriously considered adding a<br>
> >> > generic nir_op_mov which is entirely typeless and doesn't support<br>
> >> > modifiers at all and make most of core NIR use that. For that<br>
> >> > matter, there's no real reason why we need fmov with modifiers at all<br>
> >> > when we could we could easily replace "ssa1 = fmov.sat |x|" with<br>
> >> > "ssa1 = fsat |x|" or "ssa1 = fabs.sat x". If we had a generic<br>
> >> > nir_op_mov to deal with swizzling etc., the only thing having i/fmov<br>
> >> > would really accomplish is lowering the number of different ways you<br>
> >> > can write "fmov.sat |x|". The only reason I haven't added this<br>
> >> > nir_op_mov opcode is because it's a pile of work and anyone who can't<br>
> >> > do integers can just implement imov as fmov and it's not a big deal.<br>
> >><br>
> >> That sounds reasonable enough, and I understand that this hasn't been a<br>
> >> priority so far.<br>
> >><br>
> >> > > I would really love it if we could at least consider making this<br>
> >> > > "we<br>
> >> > > can just treat floats as ints without bitcasts if we feel like it"-<br>
> >> > > design optional for the backend somehow.<br>
> >> > ><br>
> >> > > I guess the assumption is that bitcasts are for free? They aren't<br>
> >> > > once<br>
> >> > > you have to emit them and have a back-end remove a bunch of<br>
> >> > > redundant<br>
> >> > > ones... We should already have all the information to trivially<br>
> >> > > place<br>
> >> > > casts for backends that care, yet we currently make it hard (unless<br>
> >> > > your HW/backend happens to be untyped)...<br>
> >> > ><br>
> >> > > Is there some way we can perhaps improve this for backends that<br>
> >> > > care?<br>
> >> ><br>
> >> > That's an interesting question...<br>
> >> ><br>
> >> > Before answering that question, let's back up and ask why. From a<br>
> >> > hardware perspective, I know of no graphics hardware that puts types<br>
> >> > on registers. On Intel, we assign types to sources and destinations<br>
> >> > of instructions but outside a specific instruction, a register is<br>
> >> > just a bag of bits. I suspect most other hardware is the same. In<br>
> >> > the hardware that his particular thread was originally about, you<br>
> >> > could argue that they have a type and it's always float. The real<br>
> >> > issue that the GLES2 people are having is that constants have a bag<br>
> >> > of bits value which may need to be interpreted as integer or float<br>
> >> > depending on context which they do not have when lowering. They<br>
> >> > don't care, for instance, about the fact that imov or bcsel take<br>
> >> > integers because they know that the sources will either be floats or<br>
> >> > integers that they've lowered to floats and so they know that the<br>
> >> > result will be a float.<br>
> >> ><br>
> >> > The problem you're describing is in converting from NIR to another<br>
> >> > IR, not to hardware.<br>
> >><br>
> >> Yes; NIR serves *both* as an LLIR *and* as a HIR. Your analysis above<br>
> >> seems to only make sense when it's used as an LLIR, though.<br>
> ><br>
> ><br>
> > NIR is not and never has claimed to be a HIR. lossless GLSL -> NIR -> GLSL translation has never been a goal of NIR. I'm sorry if that sounds like a fairly dogmatic and abrupt claim; I'll explain what I mean a bit lower down.<br>
> ><br>
> >><br>
> >> What I'm trying to say, is that since we *have* this information when<br>
> >> moving from GLSL, perhaps we could find a way of preserving it so a<br>
> >> backend that needs it could use it without having to recompute it.<br>
> >> Which turns out to be a lot trickier than it sounds, more on this<br>
> >> later.<br>
> ><br>
> ><br>
> > I think the best response to this is to give you a bit of this wonderful and useful GLSL:<br>
> ><br>
> > r4.y = intBitsToFloat(float(0.00000000f) < idx_uniforms4_cs.cb4[10 + floatBitsToInt(r5.x)].w ? int(0xffffffff) : int(0x00000000));<br>
> > r4.z = intBitsToFloat(idx_uniforms4_cs.cb4[10 + floatBitsToInt(r5.x)].w < float(0.00000000f) ? int(0xffffffff) : int(0x00000000));<br>
> > r4.y = intBitsToFloat(-floatBitsToInt(r4.y) + floatBitsToInt(r4.z));<br>
> > r4.y = float(floatBitsToInt(r4.y));<br>
> > r4.z = float(0.00999999978f) * idx_uniforms4_cs.cb4[10 + floatBitsToInt(r5.x)].w;<br>
> > r4.w = float(1.00000000f) + -idx_uniforms1_cs.cb1[32 + floatBitsToInt(r2.w)].y;<br>
> ><br>
> > That is an excerpt from an actual shader in a fairly popular steam tilte. Looking through our shader database, I can find at least a dozen games where every line of every single shader looks like that.<br>
> ><br>
> > What's my point with this, admittedly somewhat tongue-in-cheek, example? Three things:<br>
> ><br>
> > 1. The information in GLSL which you claim to want in the back-end is only really useful in applications which have been written in GLSL from the start. It works great for TuxRacer, piglit/CTS tests, and even some real games. However, for applications that come from translators (especially D3D10/11), types on variables are all lies and should be ignored. If you read the above carefully, you can see that they use <a href="http://r4.zw" rel="noreferrer" target="_blank">r4.zw</a> as a float and r4.y as both a float and an int.<br>
> ><br>
> > 2. NIR will eat this shader for breakfast and produce something very sensible precisely because it doesn't care about types. In this e-mail thread, I feel like you've been treating the lack of full types like some accidental omission. It was an intentional feature precisely because of this kind of garbage that we have to deal with.<br>
> ><br>
> > 3. Transpilers do all sorts of nasty things to turn some (possibly low-level) thing into another (possibly high-level) thing. Zink isn't hardware. It is, effectively, an emulator and/or translation layer and you should expect some of this sort of horror.<br>
> ><br>
> >><br>
> >> > In LLVM they made a choice to put types on SSA values but then to<br>
> >> > have the actual semantics be based on the instruction itself. This<br>
> >> > leads to lots of redundancy in the IR but also lots of things you can<br>
> >> > validate which is kind-of nice. Is that redundancy really useful?<br>
> >> > In our experience with NIR, we haven't found it to be other than<br>
> >> > booleans (now sorted), this one constant issue, and translating to<br>
> >> > IRs that have that redundancy. Then why did they add it? I'm really<br>
> >> > not sure but it may, at least somewhat, be related to the fact that<br>
> >> > they allow arrays and structs in their SSA values and so need full<br>
> >> > types. This is another design decision in LLVM which I find highly<br>
> >> > questionable. What you're is more-or-less that NIR should carry,<br>
> >> > maintain, and validate extra useless information just so we can pass<br>
> >> > it on to LLVM which is going to use it for what, exactly? Sorry if<br>
> >> > I'm extremely reluctant to make fairly fundamental changes to NIR<br>
> >> > with no better reason than "LLVM did it that way".<br>
> >> ><br>
> >> > There's a second reason why I don't like the idea of putting types on<br>
> >> > SSA values: It's extremely deceptive. In SPIR-V you're allowed to do<br>
> >> > an OpSConvert with a source that is an unsigned 16-bit integer and a<br>
> >> > destination that is an unsigned 32-bit integer. What happens? Your<br>
> >> > uint -> uint cast sign extends! Yup.... That's what happens. No<br>
> >> > joke. The same is true of signed vs. unsigned division or modulus.<br>
> >> > The end result is that the types in SPIR-V are useless and you can't<br>
> >> > actually trust them for anything except bit-size and sometimes<br>
> >> > labelling something as a float vs. int.<br>
> >><br>
> >> Right. I believe it's already been pointed out in this thread that it<br>
> >> might actually be useful to differentiate between integers and float<br>
> >> values, at least for some CPU architectures. For signed vs unsigned,<br>
> >> it'd be no problem for zink to treat these as the same.<br>
> ><br>
> ><br>
> > As was also pointed out in that thread, LLVM has been moving away from using types to decide registers on x86 and similar platforms and towards just looking at the opcodes because the types overly restrict the SSE opcodes they can use for various things such as shuffles.<br>
> ><br>
> >><br>
> >> In my use-case, it's not because *I* think it's perticularly useful in<br>
> >> itself, but because it's a requirement for generating valid SPIR-V. I<br>
> >> guess SPIR-V inherited this from LLVM?<br>
> ><br>
> ><br>
> > And here inlies the crux of the problem you're trying to solve. Zink is not hardware, it's a translation layer. You're hitting the same set of issues as virgil, vmware, DXVK, dolphin, and any other translator/emulator. In particular, you're having to jump from a low-level thing to a high-level thing and, oops, we lost some information. That information isn't actually needed/useful as the driver Zink is running on top of is going to translate it back into NIR and throw the types away again. However, we have to have them in order to make the high-level language happy.<br>
> ><br>
> > I'm not trying to belittle the problem you're having in any way. I'm simply pointing out that it's a translation/emulation problem and not a problem for actual hardware drivers. Most hardware has some notion of types but those types are on sources/destinations and not registers and they exist purely to reduce the combinatorial explosion of opcodes. Yes, it's a bit of an issue on radeon thanks to LLVM but Bas seemed happy enough with the status quo in his reply so I don't think it's causing them too much grief.<br>
> ><br>
> >><br>
> >> I'm not particularly worried about adding a couple of bits (or perhaps<br>
> >> even one?) per nir_ssa_def (what you seem to call "faily fundamental<br>
> >> changes to NIR" above), if that helps here.<br>
> ><br>
> ><br>
> > It's not adding a couple bits to a data structure that concerns me, it's maintenance. As I pointed out with the shader example above, NIR is extremely good at chewing through DXBC -> GLSL translated garbage and part of that power comes from ignoring types. As such, I don't want NIR to suddenly have to start respecting them in any reasonable sense. When we mutate the IR to perform optimizations, we don't want respecting types to tie us down. We could potentially continue to mostly ignore them and then have some very clever helpers that figure out what type we need at the end and stick it on but it's not at all clear to me what that would look like.<br>
> ><br>
> > If you think you can make it work in a non-intrusive and unhindering way, go for it. However, as someone who knows NIR inside and out and who has done quite a bit of deep NIR surgery recently, I don't think you have any idea what you're in for. :-) These types of changes are very difficult and time-consuming to get right and what you're suggesting is, in my view, the deepest change anyone has ever made to the IR post-landing. Am I trying to scare you away? Maybe a little bit but mostly I'm just being entirely honest.<br>
> ><br>
> >><br>
> >> > So how do we deal with the mismatch? My recommendation would be to<br>
> >> > use the source/destination types of the ALU ops where needed/useful,<br>
> >> > add special cases for things like imov and bcsel where you can pass<br>
> >> > the source type through, and insert extra bitcasts whenever they're<br>
> >> > needed. This is obvious enough that I'm going to guess you're<br>
> >> > already more-or-less doing exactly that.<br>
> >><br>
> >> We tried this approach for a while, but we couldn't get it to work.<br>
> >> There were too many situations where we couldn't know the type early<br>
> >> enough to avoid crawling through piles of old instructions to figure it<br>
> >> out, for instance when reading a constant value (untyped), constructing<br>
> >> some vector with it (still untyped). It's not until we read it that we<br>
> >> know what type we needed.<br>
> >><br>
> >> In fact, vectors itself cause major headache here, because they need to<br>
> >> have consistent types in it, and NIR can easily let you create a vector<br>
> >> with floats and ints in it, side by side. Perhaps that could be<br>
> >> considered a feature... I wouldn't, at least not on a HIR level. Once<br>
> >> the code hits a backend, perhaps.<br>
> ><br>
> ><br>
> > You're writing a back-end. :-P Sorry, snarky again... Must be a first-email-of-the-day problem...<br>
> ><br>
> > I'm not at all surprised that assigning types after-the-fact involves lots of crawling. However, as you can see from the example above, stashing ints and floats in the same vector is a real thing that applications actually do. In the end, then, we have three options:<br>
> ><br>
> > 1. Status quo: Ignore types while optimizing and figure out types after-the-fact<br>
> ><br>
> > 2. Put in types and enforce them using bitcast opcodes where needed. Optimizations which would break established types wouldn't be allowed.<br>
> ><br>
> > 3. Put in types but make them mostly ignorable by optimizations and do something clever to make everything consistent.<br>
> ><br>
> > I am very strongly against option 2 for all of the reasons I've already said. I don't see a real path to option 3 that makes any sense to me. I'm not saying we can't get there but I fear that the exact same set of problems you're experiencing trying to translate from NIR to SPIR-V would have to be scattered throughout the entire IR. That doesn't mean that it can't be done or that I'll NAK a successful solution. I just don't see a successful solution.<br>
> ><br>
> > Assuming I'm not missing the obvious, that leaves us back at 1. Is it really so bad? I completely agree that it involves lots of chasing but I don't see a way around that. Perhaps part of why it's so painful is that you're doing it on-the-fly? Would it help if we had a nir_assign_ssa_types pass that kicks out a bitset which says which things are floats? Then the only thing your NIR -> SPIR-V pass would have to concern itself with is on-the-fly adding bitcasts here-and-there to respect the pre-assigned types. That doesn't sound so bad.<br>
> ><br>
> > How would such a pass work? I can immagine a fiew different implementations. One would assume everything is an integer and walk the IR backwards assigning things "float" status based on their variable type (for loads/stores), ALU type (most ALU ops), or the float status of the SSA def's uses. To handle phis, you'd have to do some sort of fixed-point algorithm like we do for dataflow analysis. It'd be a bit fiddly but it doesn't sound terrible. And, yes, it's a heuristic but, with shaders like the pristine example I gave above, that's the best you'll ever be able to do.<br>
> ><br>
> > Wow, that got long. :-/<br>
><br>
> You know, after being in such disagreement over totally unrelated<br>
> issues, it's refreshing to be in total agreement again. I was going to<br>
> write a long email this morning about how shaders to terrible things<br>
> with intBitsToFloat and back again, but you appear to have beat me to<br>
> it... again. The moral of that story is that people will write the<br>
> code that they want to write and tell the compiler to STFU in whatever<br>
> way possible. That's the reality we have to live with.<br>
><br>
> The view that TGSI takes (and DX10/DX11 AFAIK, hence all the dirty<br>
> shaders translated to GLSL) is that values are bags of bits. They<br>
> receive meaning from the instruction. fadd treats it as a bag of float<br>
> bits. iadd treats it as a bag of int bits. While I was not involved in<br>
> the creation of TGSI nor nv50_ir, the latter does associate a type<br>
> with its values. As I've been maintaining nv50_ir, this type<br>
> information has been nothing but trouble -- it's basically always<br>
> wrong. Let's say you have a sequence like<br>
><br>
> int i = 1<br>
> float y = fmul x, i<br>
><br>
> you might be tempted to think that because the immediate has an<br>
> integer type, and its value is 1, that you can just eliminate this<br>
> multiply. But you can't. You always have to consider what the<br>
> operation is doing, and how it will interpret the bits that are given<br>
> to it. And if you keep the bitcasts in place, then you lose a lot of<br>
> opportunities to simplify conditionals/etc. In the end, I think I've<br>
> eliminated almost all instances of looking at the specific type of a<br>
> value, except for its bitsize.<br>
><br>
> I think the solution for you to just give up and do what the DX -><br>
> GLSL translators do -- make everything an int, and add tons of<br>
> bitcasts -- they get ignored by the backends anyways.<br>
><br>
> One shortcoming of the "value is a bag of bits" approach is that it<br>
> complicates things like value-range analysis. Types definitely have a<br>
> place in this world, but they have to be determined empirically from<br>
> how the values are used, not from what it says in the language.<br>
><br>
> This has all strayed considerably from the original topic of<br>
> non-integer-gpu support in nir, which I think should definitely be<br>
> done, and can be relatively straightforward. We definitely had no<br>
> trouble with it in the GLSL -> TGSI translator.<br>
><br>
> Cheers,<br>
><br>
> -ilia<br>
</blockquote></div></div></div>