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

VK_EXT_external_memory_metal validation #8498

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

aitor-lunarg
Copy link
Contributor

There are some UNASSIGNED VUIDs that I thought would be useful for the user but I'm not sure under which struct they should be. Any suggestions are more than welcome!

I believe there could be a best effort check on certain VUIDs that are not implemented like The memory from which handle was exported must have been created on the same underlying physical device as device but would require adding support for having Objective-C files in the repository, unsure if there's something like this at the moment (happy to learn if there's any so I can do some testing).

I believe there's a few missing tests for some VUIDs. I'll double check everything tomorrow. Just want to start getting some eyes into this so we can move it forward for extension release. Not looking for approval for merge since that can't happen until the extension is released.

@aitor-lunarg aitor-lunarg requested a review from a team as a code owner September 5, 2024 11:29
@ci-tester-lunarg
Copy link
Collaborator

CI Vulkan-ValidationLayers build queued with queue ID 249962.

@ci-tester-lunarg
Copy link
Collaborator

CI Vulkan-ValidationLayers build # 17383 running.

@ci-tester-lunarg
Copy link
Collaborator

CI Vulkan-ValidationLayers build # 17383 failed.

"VK_EXTERNAL_MEMORY_HANDLE_TYPE_MTLTEXTURE_BIT_EXT requires textures to be imported as a dedicated"
"allocation.");
}
return skip;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so if there is any VkExportMemoryAllocateInfo we just early return?

I would change the logic to

if (const auto export_memory_info = vku::FindStructInPNextChain<VkExportMemoryAllocateInfo>(allocate_info.pNext)) {
    // ... code
     
    return skip; // explain
}

Copy link
Contributor Author

@aitor-lunarg aitor-lunarg Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's 2 potential cases when allocating a VkDeviceMemory object:

  1. Allocate with the intent to export it.
  2. Allocate via import.

The VUIDs checked below this point apply to point 2. While this small segment applies to point 1. This is the main reason for the early return. Although now that I think about it more, there's nothing preventing the user from a 3rd option which would be: Allocate via import with the intent to export it. Kind of redundant, but I'm not sure if there's anything in Vulkan that forbids this (I don't think so, there may be even CTS tests testing this, need to double check).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I guess my only ask is to put some of this github comment information into a code comment, the external memory is already a black-box enough, any extra info is helpful

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const ErrorObject& error_obj) const {
bool skip = false;
const Location get_metal_handle_info = error_obj.location.dot(Field::pGetMetalHandleInfo);
auto memory = Get<vvl::DeviceMemory>(pGetMetalHandleInfo->memory);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto memory = Get<vvl::DeviceMemory>(pGetMetalHandleInfo->memory);
auto memory = Get<vvl::DeviceMemory>(pGetMetalHandleInfo->memory);
ASSERT_AND_RETURN_SKIP(memory)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if ((pGetMetalHandleInfo->handleType != VK_EXTERNAL_MEMORY_HANDLE_TYPE_MTLBUFFER_BIT_EXT) &&
(pGetMetalHandleInfo->handleType != VK_EXTERNAL_MEMORY_HANDLE_TYPE_MTLTEXTURE_BIT_EXT)) {
skip |= LogError("VUID-VK_EXT_external_memory-get-handle-incorrect-handle-type", device,
get_metal_handle_info.dot(Struct::VkImportMemoryMetalHandleInfoEXT, Field::handleType),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
get_metal_handle_info.dot(Struct::VkImportMemoryMetalHandleInfoEXT, Field::handleType),
get_metal_handle_info.dot(Field::handleType),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

*
* http://www.apache.org/licenses/LICENSE-2.0
*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file needs to wrapped in a #ifdef VK_USE_PLATFORM_METAL_EXT

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@ci-tester-lunarg
Copy link
Collaborator

CI Vulkan-ValidationLayers build queued with queue ID 252306.

@ci-tester-lunarg
Copy link
Collaborator

CI Vulkan-ValidationLayers build # 17412 running.

// Case 1 and partially 3
if (const auto export_memory_info = vku::FindStructInPNextChain<VkExportMemoryAllocateInfo>(allocate_info.pNext)) {
if ((export_memory_info->handleTypes == VK_EXTERNAL_MEMORY_HANDLE_TYPE_MTLTEXTURE_BIT_EXT) && dedicated_allocation_info == nullptr) {
skip |= LogError("VUID-UNASSIGNED-VK_EXT_external_memory-no-VkMemoryDedicatedAllocateInfo-export", device,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spencer-lunarg thoughts on where this VUID should go? Part of VkExportMemoryAllocateInfo or VkMemoryDedicatedAllocateInfo? I'm inclined towards the former since it also requires VkExportMemoryAllocateInfo::handleTypes to be VK_EXTERNAL_MEMORY_HANDLE_TYPE_MTLTEXTURE_BIT_EXT, but I'm not sure how cases where a struct is required by another struct are handled in the spec.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say VkExportMemoryAllocateInfo

Also not there are things such as VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT, there are some extra VUs for some handleTypes that do requires VkMemoryDedicatedAllocateInfo, but its not for all to my knowledge

// operations on buffers.
if(import_memory_metal_info->handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_MTLTEXTURE_BIT_EXT) {
if (dedicated_allocation_info == nullptr) {
skip |= LogError("VUID-UNASSIGNED-VK_EXT_external_memory-no-VkMemoryDedicatedAllocateInfo-import", device,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spencer-lunarg similar situation as the previous one


// Unsure if there should be a VUID that enforces image to not be NULL when importing a MTLTEXTURE type
if (dedicated_allocation_info->image == VK_NULL_HANDLE) {
skip |= LogError("VUID-UNASSIGNED-VK_EXT_external_memory-dedicated-null-image-import", device,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above 2

DispatchGetPhysicalDeviceFormatProperties2(physical_device, image_format, &format_properties);

if ((external_image_format_properties.externalMemoryProperties.externalMemoryFeatures & VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT) == 0u) {
skip |= LogError("VUID-UNASSIGNED-VK_EXT_external_memory-unsupported-format-import", device,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

m_errorMonitor->VerifyFound();
}

TEST_F(NegativeExternalMemoryMetal, GetResourceHandleWithoutExportStructAtCreation) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New tests I forgot to add in the initial PR start here

@ci-tester-lunarg
Copy link
Collaborator

CI Vulkan-ValidationLayers build # 17412 failed.

@ci-tester-lunarg
Copy link
Collaborator

CI Vulkan-ValidationLayers build queued with queue ID 263839.

@ci-tester-lunarg
Copy link
Collaborator

CI Vulkan-ValidationLayers build # 17585 running.

@ci-tester-lunarg
Copy link
Collaborator

CI Vulkan-ValidationLayers build # 17585 failed.

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