-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[Vulkan] Track image layout internally #5597
[Vulkan] Track image layout internally #5597
Conversation
✅ Deploy Preview for docsite-preview canceled.
|
Why do you need to track the layout? |
For the user, you do not need to know about the layout, you can always assume they are in "undefined" A Moreover, on desktop GPUs, layouts are not a thing. They are purely here for tiled GPUs such as mobile chips. A layout transition on desktop is simply a memory barrier, so it doesn't matter which layout you specify. ---- edit here: For mobile it does matter... But this is not the correct way to track layout due to the problem we will have with ordering that I mentioned in the next post. You only know all the layouts when the user submit the command buffer, at which point you can't really modify the commands you have recorded. Thus it is better to just establish a consistent convention in terms of API, where when the user provide the image to the system, it will need to assume Taichi takes full control of that image until execution completes. The user might need to specify a final layout as well If the tracking is really just for validation purposes (where an incorrect initial layout results in an error), then we should let Vulkan validation layer to do its job. It doesn't really simplify the API in any way. |
Furthermore, this tracking is flawed. We have async compute queues in Vulkan, and we can and do submit multiple command buffers instead of just one big one for the entire frame. If other command buffers have their layout transition run first, it will simply break this and be invalid. The order we record the command list is not guaranteed to be the same order when it's executed on the GPU. |
I understand your concerns but your reasoning is only valid when the images are always write-only, so there is no need to preserve existing data during layout transition. The image layout actually cannot be assumed undefined, as described in the Vulkan specification.
Logically, regardless of any specific implementation, the layout transition involves an inplace R/W of the existing texel data to relocate the texels in memory to serve certain needs of hardware design. So
I do have considered this in the design of the tracking mechanism; and that's why I proposed double tracking on both |
aa8f824
to
5b8995c
Compare
So I have adapted the impl to track image layouts on a runtime level. @bobcao3 , any comments? |
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.
LGTM
/rebase |
98a4ac5
to
6aaed60
Compare
/rebase |
7345a24
to
34481ad
Compare
/rebase |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
34481ad
to
e199ec5
Compare
For a same reason as discussed in #5540 (comment) this PR propose a mechanism to track image layouts internally:
VK_IMAGE_LAYOUT_UNDEFINED
;VulkanDevice
tracks a global state for each image;VulkanCommandList::image_transition
, the command list tracks the initial layout of the image when it's first referred by any command, and a pending image layout that will be realized after the execution of the command list.VulkanDevice
; errors are raised if those records mismatch, because a previously submitted command list has invalidated the layouts assumed by the current list.VulkanDevice
are updated with pending layouts inVulkanCommandList
.