I don't like the idea very much. We often would want (in this MR patches and later) to iterate over the elements in a specific regset.
How many such cases are there? I can't easily think of cases where we need to know the register offset and haven't already gotten that information from RA.
The larger loop looks pretty reasonable to me; if nothing else, it's quite clear what it's doing.
Okay, it is not as bad as I imagine. Perhaps I should do the cost assessments when I am fresh in the morning and not when I tired.
Still, there are 5 places where it would be better to iterate over a regset: track_object_components_usage(), calculate_resource_register_counts(), write_sm1_sampler_dcls(), write_sm4_dcl_samplers(), and write_sm4_dcl_textures(); but iteration per-component it is useful for promoting resource components into separate variables for SM 5.1.
In fact, we could potentially expand this in the future to store other per-component logic. One particularly salient thing that comes to mind is tracking whether we need to use a bool / int variable for sm1 uniforms—which itself determines the size of each register set.
I think that in this case we would rather store this information variable-wise. Since we only need the maximum register index used, and no information for every component, as we do for samplers (sampler_dim), and textures in SM 5 (we need to write a resource entry for every used component).
I don't understand, how can this information be stored per variable? IIRC sm1 cares about things like int and bool on a per-register basis, or at least a per-struct-field basis.
I probably didn't understood this the first time, I thought you were referring to the register range that's allocated, which goes from 0 to the maximum used component (which can be stored in var->regs[HLSL_REGSET_NUMERIC].count).
If I understand correctly, you are saying that in SM1 there are cases where a uniform variable (or field) can require the size of a bool or a int according to how it is used. I am not familiarized with this behavior. Can you provide an example?