<div dir="ltr"><div>If the border color is 1.0f and the format is integer, I'm not sure if the behavior is defined in GL, but I think r600 will return 0x3f800000, which is fine.<br><br></div><div>No, I cannot convert the border color to any other type, because the original type is UNKNOWN after glTexParameter returns. Also, the border color is not clamped in GL.<br>
</div><div><br></div>Marek<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Apr 14, 2013 at 7:32 PM, Roland Scheidegger <span dir="ltr"><<a href="mailto:sroland@vmware.com" target="_blank">sroland@vmware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Am 14.04.2013 18:55, schrieb Marek Olšák:<br>
<div class="im">> I think the hardware doesn't care what the border color type is. I think<br>
> the border color is "fetched" from the sampler state, which should be a<br>
> memcpy. If no texels are fetched from the texture, the border color is<br>
> copied to the destination register. If I set the texture hardware format<br>
> to "invalid", the texture fetch instructions always return the border<br>
> color, which suggests the hardware really does not care about the type.<br>
</div>But d3d always sets border color as float. So if your border color is<br>
1.0, I doubt setting the fetched texel value of a int texture to<br>
0x3f800000 when you hit the border is the right thing to do (but it<br>
would obviously be correct for a float texture). You certainly can<br>
convert those float values to int type in your driver, but it will not<br>
work if the same sampler is used both for int and float textures.<br>
Though actually the spec also says<br>
(<a href="http://msdn.microsoft.com/de-ch/library/windows/desktop/bb172415%28v=vs.85%29.aspx" target="_blank">http://msdn.microsoft.com/de-ch/library/windows/desktop/bb172415%28v=vs.85%29.aspx</a>)<br>
border color must be between 0.0 and 1.0. Doesn't make a whole lot of<br>
sense for integer textures (as the only possible values when converting<br>
to int would be 0 and 1). So something's clearly missing here...<br>
<div class="im"><br>
<br>
><br>
> OpenGL also doesn't care what the border color type is after it is set,<br>
> because the state is a union type.<br>
</div>Yes of course.<br>
<br>
Roland<br>
<div class="im"><br>
<br>
><br>
> Marek<br>
><br>
><br>
><br>
> On Sun, Apr 14, 2013 at 6:20 PM, Roland Scheidegger <<a href="mailto:sroland@vmware.com">sroland@vmware.com</a><br>
</div><div><div class="h5">> <mailto:<a href="mailto:sroland@vmware.com">sroland@vmware.com</a>>> wrote:<br>
><br>
> Oh and btw how does this work for real hw, if the hardware indeed<br>
> interpets the border color value according to format?<br>
> Are there some bits to set that the border color value is either<br>
> interpreted according to format (useful for opengl) or always as float<br>
> (useful for d3d10)? Or how else do you use the same sampler for<br>
> different int/float textures?<br>
> This discrepancy between OpenGL and d3d10 is quite a mess.<br>
><br>
> Roland<br>
><br>
><br>
><br>
> Am 14.04.2013 17:45, schrieb Roland Scheidegger:<br>
> > Yeah it is ok for OpenGL. I guess for d3d10 we'd probably need to<br>
> create<br>
> > another sampler if the same sampler is used for both int and float<br>
> > textures. Or just supply both int and float border colors to the<br>
> sample<br>
> > code (but making it work both for opengl and d3d would be ugly).<br>
> FWIW it<br>
> > looks like some intel hw also seems to require multiple border color<br>
> > values (and 6!!! ones at that), and the hw just picks the right value<br>
> > based on format. Though for some reason the only border color<br>
> format it<br>
> > does _not_ have is 32bit int, so it looks this does absolutely nothing<br>
> > to make both float and 32bit int colors work with the same sampler<br>
> > simultaneously (and I guess 32bit int is probably the reason opengl<br>
> > specifies those as ints, since you can't get accurate values with<br>
> floats).<br>
> > The swizzling looks like an orthogonal issue to that, however.<br>
> ><br>
> > Roland<br>
> ><br>
> ><br>
> > Am 14.04.2013 16:18, schrieb Marek Olšák:<br>
> >> The border color in the sampler state is untyped and that's okay. The<br>
> >> type is irrelevant with nearest filtering - just memcpy the<br>
> border color<br>
> >> to the destination register (if there is swizzling, just do what<br>
> you do<br>
> >> for texels). With linear filtering, you can always assume it's float<br>
> >> (regardless of the sampler view).<br>
> >><br>
> >> Marek<br>
> >><br>
> >><br>
> >> On Sun, Apr 14, 2013 at 3:34 PM, Jose Fonseca<br>
> <<a href="mailto:jfonseca@vmware.com">jfonseca@vmware.com</a> <mailto:<a href="mailto:jfonseca@vmware.com">jfonseca@vmware.com</a>><br>
</div></div><div class="im">> >> <mailto:<a href="mailto:jfonseca@vmware.com">jfonseca@vmware.com</a> <mailto:<a href="mailto:jfonseca@vmware.com">jfonseca@vmware.com</a>>>> wrote:<br>
> >><br>
> >><br>
> >><br>
> >> ----- Original Message -----<br>
> >> > On 14.04.2013 13:44, Jose Fonseca wrote:<br>
> >> > > ----- Original Message -----<br>
> >> > >> From: Christoph Bumiller <<a href="mailto:christoph.bumiller@speed.at">christoph.bumiller@speed.at</a><br>
> <mailto:<a href="mailto:christoph.bumiller@speed.at">christoph.bumiller@speed.at</a>><br>
</div><div><div class="h5">> >> <mailto:<a href="mailto:christoph.bumiller@speed.at">christoph.bumiller@speed.at</a><br>
> <mailto:<a href="mailto:christoph.bumiller@speed.at">christoph.bumiller@speed.at</a>>>><br>
> >> > >><br>
> >> > >> This is the only sane solution for nv50 and nvc0<br>
> (really, trust<br>
> >> me),<br>
> >> > >> but since on other hardware the border colour is tightly<br>
> >> coupled with<br>
> >> > >> texture state they'd have to undo the swizzle, so I've<br>
> added a cap.<br>
> >> > >><br>
> >> > >> The name of the cap could be changed to be more<br>
> descriptive, like<br>
> >> > >> PIPE_CAP_TEXTURE_SWIZZLE_AFFECTS_BORDER_COLOR.<br>
> >> > > Yes, please.<br>
> >> > ><br>
> >> > >> The dependency of update_sampler on the texture updates was<br>
> >> > >> introduced to avoid doing the apply_depthmode to the<br>
> swizzle twice.<br>
> >> > >><br>
> >> > >> More detailed explanation of driver situation:<br>
> >> > >><br>
> >> > >> No, really, don't suggest doing this in the driver. The<br>
> driver has<br>
> >> > >> elegantly separated texture view and sampler states<br>
> (which are each<br>
> >> > >> a structure in a table in VRAM and should not be updated<br>
> to avoid<br>
> >> > >> performance loss), and table are bound to the<br>
> independent (!)<br>
> >> > > I wonder if this is modeled after D3D10, where sampler<br>
> state is<br>
> >> independent<br>
> >> > > from resource view state. Though as far as I known, D3D10's<br>
> >> interpretation<br>
> >> > > of texture border color does not depend on the swizzle...<br>
> >> > ><br>
> >> > >> texture<br>
> >> > >> and sampler slots in shaders which must be separately<br>
> indexable<br>
> >> > >> indirectly).<br>
> >> > >> So, if I was to do this in the driver, I'd have to add<br>
> separate<br>
> >> sampler<br>
> >> > >> state object instances for each texture view with<br>
> appropriately<br>
> >> swizzled<br>
> >> > >> border color, and there's only 16 slots, so I'd be<br>
> limited to 4<br>
> >> texture<br>
> >> > >> units.<br>
> >> > >> Not to mention the sheer insanity, ugliness and<br>
> emotional pain<br>
> >> incurred<br>
> >> > >> when writing that code when it COULD be so easy and<br>
> simple in<br>
> >> the state<br>
> >> > >> tracker where you know that textures and samplers are<br>
> tightly<br>
> >> coupled,<br>
> >> > >> while in gallium I cannot assume that to be the case.<br>
> >> > > You wouldn't really need to create all state combinations: if<br>
> >> you known<br>
> >> > > that textures and samplers are tightly coupled, then<br>
> caching the<br>
> >> actually<br>
> >> > > used combinations will get you exactly the same behavior,<br>
> >> without losing<br>
> >> > > performance or generality. But granted, this would<br>
> require more<br>
> >> effort.<br>
> >> ><br>
> >> > The emphasize being on "IF I knew" (that they're tighly<br>
> coupled). If I<br>
> >> > did, I could switch to linked mode where the card automatically<br>
> >> uses the<br>
> >> > view index as sampler index, ignoring the actual sampler<br>
> index, and<br>
> >> > validate them together.<br>
> >> > However, that only applies to 3D, not to COMPUTE (which<br>
> means that GL<br>
> >> > compute shaders will still have the problem), and I'd have<br>
> to support<br>
> >> > both variants for state trackers that do not allow the<br>
> coupling,<br>
> >> and we<br>
> >> > need a way for the state tracker to actually tell us what it<br>
> >> wants. All<br>
> >> > that makes it even quirkier.<br>
> >> ><br>
> >> > > Also please spare a thought for other state trackers --<br>
> and I'm<br>
> >> not even<br>
> >> > > talking about a potential D3D10 state tracker for which your<br>
> >> driver would<br>
> >> > > be unusable --, even inside Mesa: it seems like<br>
> >> > > src/gallium/state_trackers/vega uses both texture border and<br>
> >> swizzle,<br>
> >> > > probably vl state tracker too, so your driver will be<br>
> busted on<br>
> >> those<br>
> >> > > state trackers. These need to be<br>
> >> ><br>
> >> > It already is busted. It's also busted on r600 where making<br>
> border<br>
> >> color<br>
> >> > + swizzle work properly isn't even POSSIBLE (according to the<br>
> >> radeon guys).<br>
> >> ><br>
> >> > Maybe not for vega, it doesn't use a permutational swizzle, it<br>
> >> just sets<br>
> >> > components to PIPE_SWIZZLE_ONE, and incidentally the<br>
> ZERO/ONE swizzles<br>
> >> > do affect the border color. As far as I can tell, it looks<br>
> something<br>
> >> > like this (if you're interested; the exact behaviour seems not<br>
> >> supposed<br>
> >> > to be made use of):<br>
> >> ><br>
> >> > ===<br>
> >> > In the format description (including swizzle), each color<br>
> component of<br>
> >> > RGBA (as seen by the shader) gets mapped a memory component<br>
> >> > {C0,C1,C2,C3} or {ZERO,ONE_INT,ONE_FLOAT}.<br>
> >> ><br>
> >> > When a memory (!) component (Cx) is first encountered when<br>
> going<br>
> >> through<br>
> >> > RGBA, it is assigned the SAMPLER_BORDER_COLOR component<br>
> value for that<br>
> >> > component, and if the memory component is encountered again<br>
> >> (because of<br>
> >> > swizzle), that same value will be used.<br>
> >> ><br>
> >> > So, assuming memory format RGBA and the swizzle 1RBG:<br>
> >> > R = ONE<br>
> >> > G = C0<br>
> >> > B = C2<br>
> >> > A = C1<br>
> >> > the border colour will be SAMPLER_BORDER_COLOR.1GBA.<br>
> >> ><br>
> >> > The resulting border colour with swizzle applied to the sampler<br>
> >> would be<br>
> >> > (lowercase being user values):<br>
> >> > R=1<br>
> >> > G=r<br>
> >> > B=b<br>
> >> > A=g<br>
> >> ><br>
> >> > resulting in 1rbg, which works out.<br>
> >> > ===<br>
> >> ><br>
> >> > > updated -- maybe the burden of considering this state can be<br>
> >> lifted onto<br>
> >> > > some helper functinons -- if not, these state trackers<br>
> should<br>
> >> at least be<br>
> >> > > updated to abort/warn when the cap is set.<br>
> >> > ><br>
> >> > > But I'm not really objecting -- as texture border seems<br>
> >> fundamentally<br>
> >> > > quirky state. But before proceeding with this I'd like us to<br>
> >> consider<br>
> >> > > another texture border quirk while we are at it.<br>
> >> > ><br>
> >> > > The other quirk is the integer vs float texture border<br>
> colors.<br>
> >> Roland can<br>
> >> > > probably talk a bit more about it as he was the one who came<br>
> >> across it.<br>
> >> > > In a few words, the interpretation of texture border<br>
> color union<br>
> >> depends<br>
> >> > > on the format in the sampler view state (whether it's a<br>
> pure integer<br>
> >> > > format or not).<br>
> >> > ><br>
> >> > > So, I wonder how integer vs float texture border colors<br>
> will fit<br>
> >> in your<br>
> >> > > driver's "elegantly separated texture view and sampler<br>
> states",<br>
> >> or any<br>
> >> > > other driver for that matter. That is, will the world need a<br>
> >> > ><br>
> PIPE_CAP_SAMPLER_VIEW_FORMAT_VIEW_AFFECTS_TEXTURE_BORDER_COLOR<br>
> >> too? If so<br>
> >> > > then maybe we want to lump these two things together.<br>
> >> ><br>
> >> > No, you can relax there, because using a sampler with<br>
> integer border<br>
> >> > colors with a float texture view (which doesn't happen in<br>
> OpenGL) or<br>
> >> > vice versa is not SUPPOSED to work (or even, supposed to<br>
> not work),<br>
> >> > while texture swizzle IS, it has no such incompatibility.<br>
> >><br>
> >> Fair enough. But note that Gallium pipe_sampler_state's<br>
> border_color<br>
> >> member doesn't describe whether it is float or integer.<br>
> >><br>
> >> Furthermore, given that cso module is not able to distinguish a<br>
> >> sampler state with (1.0f, 1.0f, 1.0f, 1.0f) border color,<br>
> from one<br>
> >> with (0x3f800000U, 0x3f800000U, 0x3f800000U, 0x3f800000U), it<br>
> would<br>
> >> happily create the same driver handle for both.<br>
> >><br>
> >> That is, even if this situation doesn't happen with OpenGL, it's<br>
> >> still not clear how will drivers handle it.<br>
> >><br>
> >> Also D3D10 does allow using sample sampler state with both<br>
> >> integer/float texture views, although D3D10's texture borders are<br>
> >> always float regardless (even for integer formats), so it has no<br>
> >> ambiguities either.<br>
> >><br>
> >> Jose<br>
> >> _______________________________________________<br>
> >> mesa-dev mailing list<br>
> >> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> <mailto:<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a>><br>
</div></div>> <mailto:<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<div class="im">> <mailto:<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a>>><br>
> >> <a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
> >><br>
> >><br>
> >><br>
> >><br>
> >> _______________________________________________<br>
> >> mesa-dev mailing list<br>
> >> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> <mailto:<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a>><br>
> >> <a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
> >><br>
> > _______________________________________________<br>
> > mesa-dev mailing list<br>
> > <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a> <mailto:<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a>><br>
> > <a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
> ><br>
> _______________________________________________<br>
> mesa-dev mailing list<br>
</div>> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a> <mailto:<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a>><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
><br>
><br>
</blockquote></div><br></div>