Sign in to follow this  
Alundra

Get texture infos in the shader, is it bad ?

Recommended Posts

Hi,
In different things like for example select the mipmap or the cubemap lookup calcule, you need to have the size and the number of mipmaps.
HLSL for example contains the GetDimensions function, is it bad to use it and better to send the infos in a constant buffer ?
Thanks

Edited by Alundra

Share this post


Link to post
Share on other sites
I'm not sure about every vendor, but the way that texturing works on AMD is, for each texture in your HLSL code (e.g. Texture2D variable), this basically gets replaced with a cbuffer along the lines of:
struct Texture2D {
void* data;
uint width, height, mips, format;
}

When you perform a Sample instruction, it has to read the data out of this 'hidden cbuffer' to know where and how to perform the texture sampling.

So, I would assume that querying the texture dimensions would be exactly the same speed as reading a value from a 'normal' cbuffer.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this