• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Chris_F

Array of samplers vs. texture array

10 posts in this topic

I'm curious as to what the tradeoffs would be for using an array of samplers with the bindless texture extension over using texture arrays. It seems like there would likely be more overhead with sampler arrays. On the other hand, with texture arrays you are limited to 2048 slices on a lot of modern GPUs. You could potentially have a lot more than that with bindless, and each texture can have it's own dimensions and sampler properties.

1

Share this post


Link to post
Share on other sites
The main issue with 'bindless' is that extra fetch/indirection to get the data to look up the texture; when something is bound that cost is paid up front and shoved somewhere shared.

As to the OP's question;
If you take something like AMD's GCN then a 'texture' is nothing more than a header block of 128 or 256 bytes in size which contains a pointer to the real texture data. When you sample the instructions are issued to query that block and then go off the fetch the data.

When it comes to a TextureArray then the index into a layer is part of the address generated and you are only going via one resource handle; textureHandle->Fetch(i, x , y); in C++-like code.

When it comes to an array of samplers/textures then you are effectively indexing into an array of multiple resource handles; textureHandles[i]->Fetch(x,y); at which point, as Hodgman mentions, you enter a world of divergent flow with multiple if-else chaining happening and the normal issues that brings.

While the above is based on the public AMD GCN Southern Islands data I would be surprised if NV didn't work in a similar manner.

Bindless, as mentioned, slots into this with an indirection on the texture data handle as it'll have to come from another source instead of pre-loaded into a local cache.

Where it really gets fun is when you combine bindless, sparse and array textures to reserve a large uncommitted address space and just page data in and out on demand (16k * 16k * 2048 is a HUGE address range!) - with the recently released (but unspec'd!) AMD_sparse_texture_pool extension you can even control where the backing store is pulled from and limit the size smile.png
1

Share this post


Link to post
Share on other sites

A texture array is a native resource type designed to let you access pixels in a big 3d volume of mip-mapped 2d slices.

 

An array of samplers is syntactic sugar over declaring a large number of individual samplers.

It's the same as having sampler0, sampler1, sampler2, etc... If you're using them in a loop that the compiler can unroll, then they're fine. If you're randomly indexing into the array, then I'd expect waterfalling to occur (i.e. if(i==0) use sampler0 elif(i==1) use sampler1, etc...)

 

I'm sure on old hardware that is the case. Old hardware doesn't even support bindless textures, so that is not really an issue anyway.

 

A quick experiment that renders 1024 random sprites per frame from an array of 32 images shows a performance difference of about 0.05ms when comparing a TEXTURE_2D_ARRAY to an array of bindless handles stored in a SSBO.

 

Edit: I just changed the SSBO to a UBO and now there is no performance difference at all.

Edited by Chris_F
2

Share this post


Link to post
Share on other sites

 

A texture array is a native resource type designed to let you access pixels in a big 3d volume of mip-mapped 2d slices.

 

An array of samplers is syntactic sugar over declaring a large number of individual samplers.

It's the same as having sampler0, sampler1, sampler2, etc... If you're using them in a loop that the compiler can unroll, then they're fine. If you're randomly indexing into the array, then I'd expect waterfalling to occur (i.e. if(i==0) use sampler0 elif(i==1) use sampler1, etc...)

 

I'm sure on old hardware that is the case. Old hardware doesn't even support bindless textures, so that is not really an issue anyway.

 

A quick experiment that renders 1024 random sprites per frame from an array of 32 images shows a performance difference of about 0.05ms when comparing a TEXTURE_2D_ARRAY to an array of bindless handles stored in a SSBO.

 

Edit: I just changed the SSBO to a UBO and now there is no performance difference at all.

 

That's really cool. What kind of GPU are you using?

I'd be interested to see what your shader code looks like... You've got an array of samplers inside a UBO, and then you just index that array when fetching texture samples?

 

I wonder if these performance characteristics are reliable for all vendors that support the necessary extensions... Which vendors do support bindless; is it just nVidia?

1

Share this post


Link to post
Share on other sites

Which vendors do support bindless; is it just nVidia?


Currently, yes... I believe AMD have support 'coming' in the same sense they have full GL4.4 coming.
0

Share this post


Link to post
Share on other sites

 

 

A texture array is a native resource type designed to let you access pixels in a big 3d volume of mip-mapped 2d slices.

 

An array of samplers is syntactic sugar over declaring a large number of individual samplers.

It's the same as having sampler0, sampler1, sampler2, etc... If you're using them in a loop that the compiler can unroll, then they're fine. If you're randomly indexing into the array, then I'd expect waterfalling to occur (i.e. if(i==0) use sampler0 elif(i==1) use sampler1, etc...)

 

I'm sure on old hardware that is the case. Old hardware doesn't even support bindless textures, so that is not really an issue anyway.

 

A quick experiment that renders 1024 random sprites per frame from an array of 32 images shows a performance difference of about 0.05ms when comparing a TEXTURE_2D_ARRAY to an array of bindless handles stored in a SSBO.

 

Edit: I just changed the SSBO to a UBO and now there is no performance difference at all.

 

That's really cool. What kind of GPU are you using?

I'd be interested to see what your shader code looks like... You've got an array of samplers inside a UBO, and then you just index that array when fetching texture samples?

 

I wonder if these performance characteristics are reliable for all vendors that support the necessary extensions... Which vendors do support bindless; is it just nVidia?

 

 

basically

layout(binding = 0, std430) readonly buffer texture_buffer
{
    sampler2D textures[];
};
 
in vec2 tex_coord;
flat in int id;
out vec4 frag_color;

void main()
{
    frag_color = texture(textures[id], tex_coord);
}
GLuint textures[32] = { 0 };
GLuint64 texture_handles[32] = { 0 };
glGenTextures(32, textures);

for (int i = 0; i < 32; ++i) {
    GLuint texture = textures[i];
    glTextureStorage2DEXT(texture, GL_TEXTURE_2D, 8, GL_SRGB8_ALPHA8, 128, 128);
    glTextureSubImage2DEXT(texture, GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, image_buffer + i * 65536);
    glGenerateTextureMipmapEXT(texture, GL_TEXTURE_2D);
    glTextureParameteriEXT(texture, GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTextureParameteriEXT(texture, GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTextureParameteriEXT(texture, GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTextureParameteriEXT(texture, GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    GLuint64 handle = glGetTextureHandleARB(texture);
    glMakeTextureHandleResidentARB(handle);
    texture_handles[i] = handle;
}
 
glNamedBufferStorageEXT(buffer, sizeof(texture_handles), texture_handles, 0);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, buffer);

Tested this on a GTX 760 which is based on the GK104 version of Kepler. To my knowledge Kepler is the only thing which currently supports bindless textures, but AMD and Intel could have it soon enough. It probably will never be available on older GPUs, as it is really more of an OpenGL 5 hardware feature.

Edited by Chris_F
2

Share this post


Link to post
Share on other sites

 

A texture array is a native resource type designed to let you access pixels in a big 3d volume of mip-mapped 2d slices.

 

An array of samplers is syntactic sugar over declaring a large number of individual samplers.

It's the same as having sampler0, sampler1, sampler2, etc... If you're using them in a loop that the compiler can unroll, then they're fine. If you're randomly indexing into the array, then I'd expect waterfalling to occur (i.e. if(i==0) use sampler0 elif(i==1) use sampler1, etc...)

 

I'm sure on old hardware that is the case. Old hardware doesn't even support bindless textures, so that is not really an issue anyway.

 

A quick experiment that renders 1024 random sprites per frame from an array of 32 images shows a performance difference of about 0.05ms when comparing a TEXTURE_2D_ARRAY to an array of bindless handles stored in a SSBO.

 

Edit: I just changed the SSBO to a UBO and now there is no performance difference at all.

 

 

I'm quite sure that the cost will go up if you were to have divergence within a single warp. Try randomizing your index based on the pixel coordinate and see how it fares.

1

Share this post


Link to post
Share on other sites

I'm quite sure that the cost will go up if you were to have divergence within a single warp. Try randomizing your index based on the pixel coordinate and see how it fares.

 

Just tried rendering a full screen quad that uses a hash of the screen coordinates to pick a random number to index an array of 262,144 sampler handles to 1x1 textures. Was only getting 8 fps. Would liked to have tried and even larger array, but I was getting GL_INVALID_OPERATION at 521,728 textures. With 256 textures I get 22 fps. My understanding is that Kepler supports this while AMD's GCN flat out does not.

Edited by Chris_F
0

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  
Followers 0