Skip to main content
GameDev.net gamedev.net
🔒 Locked

Why is sampling from large textures so slow?

Started by daVinci Jul 18, 2010 at 2:35 AM 2 replies 2.7k views
Original Post
daVinci
daVinci
Hello.

I have a pixel shader which just samples from a texture and return the value.
Depending from size of the texture, performance is degraded dramatically (sure, the output size is constant). I used 640x480px and 3800x2800px textures.

Why? And how I can improve the performance?

P.S. I have tried to generate mipmaps, but it doesn't helps.
Thanks, Daniel
Hodgman
Hodgman
What kind of sampling pattern does your shader use? Does each pixel sample a different part of the texture? Are the samples randomly distributed? Is there a 1-to-1 mapping between pixels and texture-samples?

What format is your texture? Is it compressed (e.g. DXT)?


It's possibly to do with the texture cache. When you fetch a texel, a section of that texture (nearby the fetched texel) is pulled into the texture cache. If you subsequently fetch the same texel, or nearby texels, it's much faster as they're already in the cache.

When using smaller textures, you're much more likely to get a cache-hit, because a larger percentage of the texture will be resident in the cache at any one time.
daVinci
daVinci
I use the following shader:

// Input image
Texture2D inputImage : register(t0);
SamplerState inputImageSampler : register(s0);

float4 main(float2 nonused : TEXCOORD0, float2 uv : TEXCOORD1) : COLOR
{
return inputImage.Sample(inputImageSampler, uv);
}

This is 1-to-1 mapping between pixels and texture-samples (uv are calculated to make it). Format is BGRA 32bit, not compressed.

Can it occur due to large amount of GPU memory.. I mean maybe GPU has to move the texture in memory in case of large textures before sampling?
rubicondev
rubicondev
It's based on two things. One is the cache as mentioned previously and the other is the dimensions. Non pow2 dimensions are stored in a linear fashion that is also not at all cache friendly, especially when bilnear is filtering them.

There's a good chance that if you round them up and make them bigger then you'd see a small win, but the best thing to do is use smaller pow2 textures
------------------------------Great Little War Game

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.