vkd3d-shader/hlsl: Broaden resources support (draft).
Okay, now the text is correctly written. Please disregard the previous MR I sent by mistake, I already closed it.
ehem
I don't expect this MR to be approved (because it is quite big) but I think it would be good if you review it so I start sending it in partitions, and to avoid working on conflicting patches. But, most importantly, because the patches in the middle of this series contain design decisions pertaining the handling of resource components and register spaces that, I think, are justified by their capability of supporting the many features in the second half of the patch series. Also, in case a different approach is deemed more convenient, it would be good to consider how it would manage the features in these patches.
Most of these design decisions are implemented in the following patches of the series:
vkd3d-shader/hlsl: Span variables across multiple register spaces.
vkd3d-shader/hlsl: Support variables that have multiple-registers in object reg. spaces.
I converged to these implementations by using Zeb's advice and by hitting myself against the wall while trying to implement these features with other approaches.
In short, this patch series includes:
- For SM1, the tex2D and tex3D intrinsics, inferring generic samplers dimension from usage, writing sampler declarations, and writing sample instructions.
- Support for arrays of resources for both SM1 and SM4 (not to be confused with the resource-arrays of SM 5.1, which can have non-constant indexes).
- Support for declaring resources within structs.
- Support for synthetic combined samplers for SM1 and synthetic separated samplers for SM4, considering that they can be arrays or members of structs.
- All of this while imitating the way the native compiler assigns the register indexes of the resources on allocation, which proved to be the most difficult thing, and the main reason behind the design decisions, because the rules are many, and all the previous things have combined effects in the assignment order.
- (There are also many small fixes to corner cases I have stumbled upon, and validations for cases that should not be supported. Most of them are in short patches and in the first half of the MR).
In order to test that the allocated register indexes (in both the sampler and texture spaces) were the same as the native compiler, I did manual tests using ps_4_0, ps_5_0 and ps_3_0 and compared the CTAB/RDEF sections while trying to deduct the assignment rules. Sadly, I cannot be sure that I am covering 100% of the possible scenarios.
I had to do tests manually since it is difficult to test this with the shader_runner which is also limited to SM4, and I haven't learned how to implement C tests that check the reflection data yet (like the ones in wine that Zeb mentioned test_constant_table() in dlls/d3dcompiler_43/tests/hlsl_d3d9.c). Doing these tests automatically is still missing in this MR.
Nevertheless, I could implement some tests for lowering combined samplers for SM4 that also double down as tests to check for the register assignment order in:
tests: Add lowering combined samplers tests.
For reference, these are some of the tests I have been running manually both for SM1 and SM4 (with the -GeC flag):
sm1-separated-samplers-array.hlsl