Jump to content
  • Advertisement
Sign in to follow this  
Mr_Fox

DX12 array of texture of different res and dynamic index into them in shader

This topic is 586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Guys,

IIRC, before dx12, we can create texture array (textures have to be the same format, same reso) and dynamically index into them in shader. But it is impossible to dynamically index 'texture array' which texture have different size (actually you can't create texture array of different reso).

 

Now, from what I know, it seems with Dx12 rootsig, resource heap model, we can dynamically index 'texture array' of different size, format(same channel, same data type), right?  Here is the link talk about that: https://msdn.microsoft.com/en-us/library/windows/desktop/mt186614(v=vs.85).aspx

 

However, the above link only use textures has same format, reso. And it didn't mention whether it support texture array of different reso. So I think it's better first ask here before I write my test code (It will be frustrating if I spend half hour coding only get to know index into texture array of different size is not supported, while you guys already know it)

 

Also if it is supported, is there anythings I should be aware of? 

 

Thanks in advance~

Share this post


Link to post
Share on other sites
Advertisement

The example does use textures of the same resolution, but indeed there is no reason that they need have the same Width, Height, Format or Mip Count. So long as they are an array of 2D Textures, that's fine.

Depending on how many textures you want bound at once, be aware that you may be excluding Resource Binding Tier 1 hardware:

https://msdn.microsoft.com/en-gb/library/windows/desktop/dn899127(v=vs.85).aspx

Note that in order to get truly non-uniform resource indexing you need to tell HLSL + the compiler that the index is non-uniform using the "NonUniformResourceIndex" intrinsic. Failing to do this will likely result in the index from the first thread of the wave deciding which texture to sample from.

https://msdn.microsoft.com/en-us/library/windows/desktop/dn899207(v=vs.85).aspx

Share this post


Link to post
Share on other sites

Excluding tiers 1 resource binding is an easy call, only a few old generation Intel integrated gpu are tiers 1 :)

Yes, tiers 2 can dynamically index textures and buffers, a technique known as bindless.

 

The non uniform intrinsic is useful on AMD, and does nothing on nVidia, BUT, you do not want to use it as it can generate very ugly and not efficient shaders, it is better on AMD to sends draws in a way you can "uniformize" the index. Shader model 6 will also help in that regards with an explicit way to read first lane

Share this post


Link to post
Share on other sites

Note that in order to get truly non-uniform resource indexing you need to tell HLSL + the compiler that the index is non-uniform using the "NonUniformResourceIndex" intrinsic. Failing to do this will likely result in the index from the first thread of the wave deciding which texture to sample from.

Is that the same intrinsic used when you want to use dynamic indexing with instancing?  Or am I thinking of something else?  Also do you need to use a intrinsic when using dynamic indexing with draw indirect? 

Share this post


Link to post
Share on other sites

I think you are confusing with sv_instanceId that is a system semantic.

The bindless intrinsic is used like that

Texture2D<float4> diffuse_[] : register(t1);

uint someIndex = foo(); // coming from something like an interpolator or whatever
Texture2D diffuse = diffuse_[NonUniformResourceIndex(someIndex)];

//then using diffuse

Without the intrinsic, that is more like a tag, as pixels are gather into waves, some hardware ( AMD obviously ) will have bogus result. because a texture descriptor is loaded in scalar registers and if someIndex is divergent, it means that you are crossing flux.

 

The NonUniformResourceIndex will inform the compiler and driver of that and the driver will generate a loop with clever masking to process group of threads per value of someIndex. In simple cases, the overhead may not be significant, but if you multiply the divergent indices, then it will for sure bloater your shader :)

Share this post


Link to post
Share on other sites

I think you are confusing with sv_instanceId that is a system semantic.
 No IIRC one of the MS DX12 videos on youtube mentions explictly that if you want to do dynamic indexing with instancing you need to do something 'special'.  I don't remember what exactly it is but I remember them saying if the index to the texture change within a single 'drawcall' then you have to do something for it to work correctly.

Share this post


Link to post
Share on other sites

 

I think you are confusing with sv_instanceId that is a system semantic.
 No IIRC one of the MS DX12 videos on youtube mentions explictly that if you want to do dynamic indexing with instancing you need to do something 'special'.  I don't remember what exactly it is but I remember them saying if the index to the texture change within a single 'drawcall' then you have to do something for it to work correctly.

 

Ok so yes, this is the NonUniformResourceIndex :)

Share this post


Link to post
Share on other sites

If you'd like to see a more complete example of dynamic indexing, you can check out the deferred texturing demo that I made a while ago. It uses dynamic indexing in both the forward and deferred rendering path to sample material textures, as well as to sample decal textures. There's also an experimental branch where I use bindless techniques throughout the entire rendering framework. Basically all SRV's are persistently allocated from a global descriptor heap, and every shader accesses them using 32-bit indices. However I should warn you that there may be a few bugs on this branch that I haven't fixed yet, and there's also a few issues with dynamic buffers that I have to clean up.

Edited by MJP

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!