<div dir="ltr"><div>I think the hardware doesn't care what the border color type is. I think the border color is "fetched" from the sampler state, which should be a memcpy. If no texels are fetched from the texture, the border color is copied to the destination register. If I set the texture hardware format to "invalid", the texture fetch instructions always return the border color, which suggests the hardware really does not care about the type.<br>
<br></div><div>OpenGL also doesn't care what the border color type is after it is set, because the state is a union type.<br></div><div><br></div><div>Marek<br></div><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Sun, Apr 14, 2013 at 6:20 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">
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>
<div class="HOEnZb"><div class="h5">> Yeah it is ok for OpenGL. I guess for d3d10 we'd probably need to 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 sample<br>
> code (but making it work both for opengl and d3d would be ugly). 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 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 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 border color<br>
>> to the destination register (if there is swizzling, just do what 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 <<a href="mailto:jfonseca@vmware.com">jfonseca@vmware.com</a><br>
>> <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>
>> > >><br>
>> > >> This is the only sane solution for nv50 and nvc0 (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 added a cap.<br>
>> > >><br>
>> > >> The name of the cap could be changed to be more 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 swizzle twice.<br>
>> > >><br>
>> > >> More detailed explanation of driver situation:<br>
>> > >><br>
>> > >> No, really, don't suggest doing this in the driver. The driver has<br>
>> > >> elegantly separated texture view and sampler states (which are each<br>
>> > >> a structure in a table in VRAM and should not be updated to avoid<br>
>> > >> performance loss), and table are bound to the independent (!)<br>
>> > > I wonder if this is modeled after D3D10, where sampler 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 indexable<br>
>> > >> indirectly).<br>
>> > >> So, if I was to do this in the driver, I'd have to add separate<br>
>> sampler<br>
>> > >> state object instances for each texture view with appropriately<br>
>> swizzled<br>
>> > >> border color, and there's only 16 slots, so I'd be limited to 4<br>
>> texture<br>
>> > >> units.<br>
>> > >> Not to mention the sheer insanity, ugliness and emotional pain<br>
>> incurred<br>
>> > >> when writing that code when it COULD be so easy and simple in<br>
>> the state<br>
>> > >> tracker where you know that textures and samplers are 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 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 require more<br>
>> effort.<br>
>> ><br>
>> > The emphasize being on "IF I knew" (that they're tighly 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 index, and<br>
>> > validate them together.<br>
>> > However, that only applies to 3D, not to COMPUTE (which means that GL<br>
>> > compute shaders will still have the problem), and I'd have to support<br>
>> > both variants for state trackers that do not allow the 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 -- 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 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 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 ZERO/ONE swizzles<br>
>> > do affect the border color. As far as I can tell, it looks 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 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 going<br>
>> through<br>
>> > RGBA, it is assigned the SAMPLER_BORDER_COLOR component 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 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 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 color union<br>
>> depends<br>
>> > > on the format in the sampler view state (whether it's a pure integer<br>
>> > > format or not).<br>
>> > ><br>
>> > > So, I wonder how integer vs float texture border colors will fit<br>
>> in your<br>
>> > > driver's "elegantly separated texture view and sampler states",<br>
>> or any<br>
>> > > other driver for that matter. That is, will the world need a<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 integer border<br>
>> > colors with a float texture view (which doesn't happen in OpenGL) or<br>
>> > vice versa is not SUPPOSED to work (or even, supposed to not work),<br>
>> > while texture swizzle IS, it has no such incompatibility.<br>
>><br>
>> Fair enough. But note that Gallium pipe_sampler_state's 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, from one<br>
>> with (0x3f800000U, 0x3f800000U, 0x3f800000U, 0x3f800000U), it 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> <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>
>> <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><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><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</div></div></blockquote></div><br></div>