-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[0004] Are struct and array layouts specified by HLSL? #50
Comments
FYI: @llvm-beanz |
The Unions spec is not fully specified, but it does say:
In practice, the We do need to specify that and the memory layout in the spec. Each union member's layout starts at the start of the union, but that doesn't necessarily guarantee strict overlapping. In the example you provided in the issue the fields all overlap, but padding, alignment or other constraints can impact how they overlap. |
Based on what you said above, I would expect the following to be undefined:
However, this statement in the proposal (emphasis mine) seems to suggest that you expect to be able to do this.
|
I think you're misunderstanding (or I'm mis-speaking). First we need to answer #43 to define whether or not punning is allowed. By C++ rules, punning is always undefined behavior regardless of the layouts (which are fairly well defined). I think the layout rules from C that we'll inherit do define the memory overlap. In HLSL, a struct of 4 floats has no padding between members and an array of floats had no padding between members. If the union members are defined to start at the same offset, the overlap is well defined and understood. Where it gets complicated is if you have structures of different members where padding gets involved or you had more unusual data packing. We do still need to explore #43 to figure out the answer and behavior there. |
thanks. That was the part I was missing. I did not see where that was said. |
To piggy-back on this issue, it'd be helpful if layouts were specified with respect to inheritance. AFAICT, HLSL restricts inheritance such that derived records may only have one concrete base (concrete meaning a record with fields, i.e. not an interface). However, I wasn't able to find information on:
Technically, I'm not sure where the "one concrete base" rule comes from either, but I remember this was a restriction back in SM5 also, so I assume it's a carryover from there (and would be probably useful to spell out as a rule). |
I'd be fine with The only "useful" place I'd want to see P.S. |
Which proposal does this relate to?
Unions
Describe the issue or outstanding question.
To implement unions, SPIR-V will have to know the size of the union. I do not know if that is specified by HLSL or if the compiler can decide for itself. Depending on which features are going to be used, the entire layout must be specific.
Additional context
See #49 for the limitations on how to represent unions in spir-v.
To create a variable that is large enough to hold the entire union, the size of the union has to be known by the compiler.
Related to this, consider the example from the proposal:
Can the user assume that
v.x
,v.r
, andv.f[0]
are the same memory location? If so, where in the HLSL spec does it say that the members of the struct and the elements of the array must be at the same offset? I cannot find it, but my search was not extensive.The text was updated successfully, but these errors were encountered: