-
Notifications
You must be signed in to change notification settings - Fork 212
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
Add documentation for buffer types #5410
Conversation
source/slang/hlsl.meta.slang
Outdated
@@ -4216,6 +4364,10 @@ struct $(item.name) | |||
} | |||
} | |||
|
|||
/// Load two 32-bit unsigned integers from the buffer at the specified location with alignment | |||
/// of `uint2`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Speak out what the alignment is, I. This case it is 8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems still 8.
I just checked:
source/slang/slang-ir-layout.cpp:236
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the alignments for LoadAligned is not correct: 2-vector should be 8 bytes (offset must be multiple of 8 too), and 4-vector should be 16.
source/slang/hlsl.meta.slang
Outdated
} | ||
} | ||
|
||
/// Load two 32-bit unsigned integers from the buffer at the specified location with alignment | ||
/// of `uint2`, which is 4. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is 8?
} | ||
} | ||
|
||
/// Load four 32-bit unsigned integers from the buffer at the specified location. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be 16.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint4 is four 16bits integer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is four 32 bit integers, and LoadAlign will align to the vector boundary, which is 16 bytes.
I think offset is different from alignment. Alignment put the restriction on the address. Also, I checked the alignment by looking at our code at source/slang/slang-ir-layout.cpp:236
outSizeAndAlignment does show that uint{2,3,4} have alignment of 4. |
/// Load two 32-bit unsigned integers from the buffer at the specified location | ||
/// with additional alignment. | ||
///@param location The input address in bytes. | ||
///@param alignment Specifies the alignment of the location, which must be a multiple of 4. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8
} | ||
} | ||
|
||
/// Load four 32-bit unsigned integers from the buffer at the specified location. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is four 32 bit integers, and LoadAlign will align to the vector boundary, which is 16 bytes.
OK, I think the current behavior is LoadAligned will treat the buffer as an array of T, and the offset must be at the boundary of T's stride. Therefore, the result will be undefined if you do You can use slang-playground to compile this code to spirv:
You can see in the spirv we have:
Which is treating |
Looks like we are generating wrong code for composite types...
The load for the |
Let's put in the document that this currently only works for scalar, vector and matrix types. |
and the semantics is that it assumes the address to load/store is aligned at the stride boundary of the vector type. |
OK, I will update the document accordingly. |
I tried the code like:
and it generates:
and you can see that, we treat the whole buffer as uint type, so the alignment is always 4. But if I give an input location that is aligned to size of the vector, it will treat the buffer as the expecting types, e.g.
so it looks to me that, as long as the minimum alignment is met (which is 4), it can still generate the correct result. |
So as long as we define that
is an unexpected behavior, otherwise, alignment of 4 should be valid statement. |
Update the doc for all Load{2,3,4}Aligned and LoadxAligned<T> functions of buffer type. We assume that those aligned version of Load{2,3,4} and Load<T> will treat the whole buffer as type of unit{2,3,4} or T, so the address must be aligned to size of the loaded type.
@csyonghe add a new commit to update all the aligned version of load and store, please review. |
The preview page can be found here: https://kaizhangnv.github.io/stdlib-reference/types/buffer_types.html