-
Notifications
You must be signed in to change notification settings - Fork 664
Scalar replacement on descriptor arrays #2740
Description
Consider the following hlsl code,
#define COUNT 5
Texture2D MyTextures[COUNT] : register(t0);
Texture2D NextTexture;
SamplerState MySampler;
float4 main(float2 TexCoord : TexCoord) : SV_Target0
{
float4 result =
MyTextures[0].Sample(MySampler, TexCoord) +
MyTextures[1].Sample(MySampler, TexCoord) +
MyTextures[2].Sample(MySampler, TexCoord) +
MyTextures[3].Sample(MySampler, TexCoord) +
MyTextures[4].Sample(MySampler, TexCoord) +
NextTexture.Sample(MySampler, TexCoord);
return result;
}
If you look at the output from dxc when generating dxil, you will notice that MyTextures takes up 5 binding t0 to t4. Then NextTexture is placed in t5. The dxbc from FXC is similar.
For the spirv, MyTextures is a single array at binding 0, and NextTexture is at binding 1.
This can make it conceptually difficult for code that wants to work with Vulkan and DirectX. It becomes hard to keep track of where everything is bound.
To help with this DXC will be adding an option to have texture map the same way. However, the front-end cannot convert the array of textures into separate variables until after legalization because it may require optimizations to determine fold the index in the use to a literal.
To this end, we will add a pass that will do scalar replacement on descriptor arrays. It will be an error it the pass is unable to the scalar replacement.