PDA

View Full Version : order of texture sampling



SirKnight
05-20-2005, 12:18 PM
Been a while since I started a topic on here. Anyhoo...

Would it make any difference when sampling textures in a fragment program if you did them like this:

a) sample all textures
b) do all math

or mixing it around like this:

a) sample a texture or two
b) do math with needing those textures
c) sample more textures
d) do more math
e) etc...

???

Usually I sample when it's needed like in exhibit-B.

I know when doing vertex texture fetches there is a large amount of latency there so it's The Right Thing to fetch the vertex texture, do math that doesn't need the texture result, then do math that uses the texture. This is done to "cover up" the VTF latency.

Just wondering if anyone has came across a problem where this made a difference or not.

-SirKnight

dorbie
05-20-2005, 05:21 PM
My money is on; if you know what the sample is then fetch it early, at worst the fetches are queued. The whole thing is pipelined but it's the latency of the fetch that hurts the most(and any unpredictability/unoptmizability like dependent reads), anything you can do minimize that latency might help.

Fetching anything late is only going to work against completing a shader before you stall the shader on a fetch. Most of the time I'd bet it makes no difference and optimizers will do the right thing even where it could make a difference (either way).

M/\dm/\n
05-21-2005, 02:41 AM
If that's NV GLSL compiler, errrm... Cg, then I think they had that operation reorganizing trick mentioned somwhere. Moreover there was a talk about drivers doing rescheaduling operations for fragment/vertex asm sources too (esspeicially for FX generation), I'd say don't bother. ATI, Matrox ... dunno ...

SirKnight
05-21-2005, 09:02 AM
Yeah that's true, the compilers/drivers will probably shift things around to get the best performance knowing what the arch likes and dislikes. I remember looking at ASM outputs of my HLSL shaders and seeing the order at which things were done to be pretty much completely different than what I programmed.

So I guess it's safe to say just acess textures whenever you feel/need and latency/scheduling issues will be taken care of by compilers/optimizers as best they can.

-SirKnight