Skip to content
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 memoryMapPlaced and memoryMapRangePlaced features of VK_EXT_map_memory_placed extension #2514

Merged
merged 47 commits into from
Jun 7, 2024
Merged

add memoryMapPlaced and memoryMapRangePlaced features of VK_EXT_map_memory_placed extension #2514

merged 47 commits into from
Jun 7, 2024

Conversation

0xcaff
Copy link
Contributor

@0xcaff 0xcaff commented Apr 8, 2024

Overview

Implements the memoryMapPlaced and memoryMapRangePlaced features of the VK_EXT_map_memory_placed extension (docs, proposal).

Adds a field, MemoryMapInfo.placed_address for use with DeviceMemory::map and DeviceMemory::map_unchecked specifying an address.

Testing

As VK_EXT_map_memory_placed is currently not yet released in any implementation, I've tested this using a trunk revision of mesa (https://gitlab.freedesktop.org/mesa/mesa/-/commit/6b383ca810bb853f11c127d9e1d284dc4dcb0992). Mesa 24.1 coming out in the beginning of May is scheduled to include this extension.

Here are the instructions I used to run the tests locally. These will not make global system changes.

$ git clone git@gitlab.freedesktop.org:mesa/mesa.git
$ cd mesa
$ mkdir builddir
$ meson setup builddir/
$ meson compile -C builddir/
$ meson devenv -C builddir
[mesa] $ vkinfo # validate extension available on host
[mesa] $ cd ~/projects/vulkano
[mesa] $ cargo test

Questions

  • Do we care about the tests running in CI? It seems like currently gfx_dev_and_queue will early return, silently passing if a feature or extension requested is not available.
  • Would adding a field to a struct (in this case MemoryMapInfo.placed_address) be considered a breaking change? Wasn't sure so I erred on the conservative side and am assuming yes. The non-exhaustive allows for non-breaking change.
  • Am I using the right vuids? See the inline comments for specifics. Discussing in inline comments.

Changelog

### Additions
* Support for the `ext_map_memory_placed` extension.

implements the memoryMapPlaced and memoryMapRangePlaced features
0xcaff added 2 commits April 8, 2024 15:46
I don't love these tests, they probably fail silently in CI
0xcaff added 6 commits April 8, 2024 17:24
intersects does not do what I thought it does
I don't think this is correct. The offset and size are both DeviceSize or u64. They are added together as positive numbers.
@0xcaff 0xcaff marked this pull request as ready for review April 9, 2024 02:53
@marc0246
Copy link
Contributor

marc0246 commented Apr 9, 2024

The idea with non-exhaustive structs is that we can add fields without it being a breaking change.

@marc0246
Copy link
Contributor

marc0246 commented Apr 9, 2024

Can you please fix the string literals spanning more than 100 columns? You can see examples of how to do it in the same file.

@0xcaff
Copy link
Contributor Author

0xcaff commented Apr 9, 2024

I've updated the interface to no longer use DeviceSize::MAX

@0xcaff 0xcaff requested a review from marc0246 April 9, 2024 20:31
@0xcaff
Copy link
Contributor Author

0xcaff commented Apr 10, 2024

I've updated the PR but seems like the windows actions has crashed and its blocking the check from completing.

@marc0246
Copy link
Contributor

I guess that is also more self-documenting, true that.

@0xcaff
Copy link
Contributor Author

0xcaff commented Apr 12, 2024

Updated to remove the extra branch. Kept the feature gate.

I did do

if size == self.allocation_size() {
    size = ash::vk::WHOLE_SIZE;
}

instead of

if offset + size == self.allocation_size() {
    size = ash::vk::WHOLE_SIZE;
}

as a non-zero offset is invalid when features.memory_map_range_placed is not available.

https://github.com/0xcaff/vulkano/blob/955dc3ebdf0abc0e9eb84dfd2b5caf41037df8ea/vulkano/src/memory/device_memory.rs#L1543-L1550

@marc0246
Copy link
Contributor

I'm afraid that that condition is incorrect, because those sets of features can be en/disabled without using MemoryMapFlags::PLACED. So either it needs to be what I suggested, or you have to check for the flag instead of those features.

@marc0246
Copy link
Contributor

marc0246 commented Apr 12, 2024

Err, more specifically, you would have to check that memory_map_range_placed is disabled and MemoryMapFlags::PLACED is enabled. (You can't enable the flag without memory_map_placed anyway.)

@0xcaff
Copy link
Contributor Author

0xcaff commented Apr 12, 2024

Yes, I believe this is correct. Previously, placed_address implied the flag and memory_map_placed, now the flag implies memory_map_placed and placed_address implies nothing. The feature is a global thing and the flag is call specific.

@marc0246
Copy link
Contributor

That made me realize, VK_WHOLE_SIZE is the only acceptable value both when map_memory_range_placed is enabled and disabled. So really the check needs to be what I sent initially because of VUID-VkMemoryMapInfoKHR-flags-09574:

flags.contains(MemoryMapFlags::PLACED) && offset + size == self.allocation_size()

@0xcaff
Copy link
Contributor Author

0xcaff commented Apr 12, 2024

What if map_memory_range_placed is enabled and you want to pass allocation_size instead of VK_WHOLE_SIZE? I think its a good idea to avoid transforming this value unless it is invalid. allocation_size might be sometimes valid for map_memory_range_placed but is never valid for map_memory_range_placed disabled.

Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com>
@marc0246
Copy link
Contributor

allocation_size is never valid regardless of whether memory_map_range_placed is enabled or not (except by chance). That's why we need to translate the rest of the size to VK_WHOLE_SIZE in all cases.

@marc0246
Copy link
Contributor

marc0246 commented Apr 12, 2024

In case you are talking about the case when allocation_size is valid by chance when map_memory_range_placed is enabled, it still wouldn't change functionality. Let's not overcomplicate this any more than it already is. You don't even need to check for the flag like I mentioned because this is always a valid transformation to make, at least currently.

0xcaff added 2 commits April 12, 2024 16:46
i've concluded that this choice is roughly semantically equivalent and this comes down to opinion. I can't be bothered to have an opinion here, imo this is a bikeshed.

also it is temporary. until the docs are updated and the impls are updated. also i don't even really care about the ranged version of this feature, implemented it mostly for completeness than anything else
@0xcaff
Copy link
Contributor Author

0xcaff commented Apr 12, 2024

Ultimately I've concluded this decision is an opinion and I care more about merging than having a debate. Updated to exactly what you asked for.

If there are further minor changes, the branch has maintainer edits on, please feel free to edit directly.

Really curious what the docs ppl end up concluding.

@marc0246
Copy link
Contributor

Yes, I can't wait to see what will come of it. My gut tells me that they'll make it consistent. Worst case is they refuse and we have to expose VK_WHOLE_SIZE including the inconsistencies.

@marc0246
Copy link
Contributor

marc0246 commented Jun 1, 2024

I updated the PR in light of the latest updates to the spec and fixed the last remaining unresolved comment since you seemed a bit defeated. I opted for the additional map_placed function as much as I hate it because we overlooked the most obvious: it is (very) unsafe.

@0xcaff
Copy link
Contributor Author

0xcaff commented Jun 2, 2024

Ah hey yeah @marc0246 no worries, honestly I tried the copy way you suggested and was finding the performance to be acceptable. I decided to focus on correctness for now in my emulation project and worry about performance later. I was planning to come back and update this eventually but it kept getting pushed below the cutline.

If this is important to you I'm happy for you to take it over. If its not, I'll get to it eventually.

@Rua
Copy link
Contributor

Rua commented Jun 4, 2024

Could you merge in the changes from the latest master? I'm encountering a bug that you fixed in another PR, and that's preventing me from testing this currently.

@Rua Rua merged commit 64f3b1e into vulkano-rs:master Jun 7, 2024
5 checks passed
@Rua
Copy link
Contributor

Rua commented Jun 7, 2024

Thank you! Sorry it took so long.

Rua added a commit that referenced this pull request Jun 7, 2024
@0xcaff
Copy link
Contributor Author

0xcaff commented Jun 9, 2024

No worries! Thank you!

@0xcaff 0xcaff deleted the martin/placed-memory-ext branch June 9, 2024 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants