vkd3d-shader/hlsl: Get SM4 texture allocation order and RDEF bind count for lowered combined samplers right.
First, we have to distinguish between the "bind count" and the "allocation size" of variables.
The "allocation size" affects the starting register id for the resource to be allocated next, while the "bind count" is determined by the last field actually used. The former may be larger than the latter.
Currently we are calling hlsl_reg.bind_count
to what should be hlsl_reg.allocation_size
.
So it is renamed in 2/4.
The proper "bind count" (now computed when needed in 3/4) is important because it is what should appear in the RDEF table and some resource allocation rules depend on it
For instance, for this shader:
texture2D texs[3];
texture2D tex;
float4 main() : sv_target
{
return texs[0].Load(int3(0, 0, 0)) + tex.Load(int3(0, 0, 0));
}
the variable "texs" should show a "bind count" of 1, even though its "allocation size" is 3:
// Resource Bindings:
//
// Name Type Format Dim HLSL Bind Count
// ------------------------------ ---------- ------- ----------- -------------- ------
// texs texture float4 2d t0 1
// tex texture float4 2d t3 1
In particular, as shown in the tests in 1/4, textures go in this order:
- Textures created from SM1-style samples. Those whose "bind count" is larger than 1, in the order of the tex1D/tex2D/tex3D/texCube instructions that create them.
- Textures created from SM1-style samples. Those whose "bind count" is equal to 1, in the order of the tex1D/tex2D/tex3D/texCube instructions that create them.
- Regular textures in order of declaration.
Note that the difference between 1 and 2 is not given by the "allocation size" but the "bind count". This order is enforced in 4/4.