Skip to content

Commit

Permalink
tests: Cleanup VkBindMemoryStatus tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-lunarg committed Jan 6, 2025
1 parent fb67878 commit 46d886a
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 60 deletions.
8 changes: 4 additions & 4 deletions layers/core_checks/cc_device_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2092,15 +2092,15 @@ bool CoreChecks::PreCallValidateBindImageMemory2(VkDevice device, uint32_t bindI

void CoreChecks::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfo *pBindInfos,
const RecordObject &record_obj) {
// Don't check |record_obj.result| as some bind might be valid
// Don't check |record_obj.result| as some binds might still be valid
BaseClass::PostCallRecordBindImageMemory2(device, bindInfoCount, pBindInfos, record_obj);

for (uint32_t i = 0; i < bindInfoCount; i++) {
if (auto image_state = Get<vvl::Image>(pBindInfos[i].image)) {
// Need to protect if some VkBindMemoryStatus are not VK_SUCCESS
if (image_state->MemState()) {
image_state->SetInitialLayoutMap();
}
if (!image_state->HasBeenBound()) continue;

image_state->SetInitialLayoutMap();
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions layers/gpu/descriptor_validation/gpuav_image_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,15 +668,15 @@ void Validator::PostCallRecordBindImageMemory(VkDevice device, VkImage image, Vk

void Validator::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfo *pBindInfos,
const RecordObject &record_obj) {
// Don't check |record_obj.result| as some bind might be valid
// Don't check |record_obj.result| as some binds might still be valid
BaseClass::PostCallRecordBindImageMemory2(device, bindInfoCount, pBindInfos, record_obj);

for (uint32_t i = 0; i < bindInfoCount; i++) {
if (auto image_state = Get<vvl::Image>(pBindInfos[i].image)) {
// Need to protect if some VkBindMemoryStatus are not VK_SUCCESS
if (image_state->MemState()) {
image_state->SetInitialLayoutMap();
}
if (!image_state->HasBeenBound()) continue;

image_state->SetInitialLayoutMap();
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions layers/state_tracker/image_state.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Copyright (c) 2015-2024 The Khronos Group Inc.
* Copyright (c) 2015-2024 Valve Corporation
* Copyright (c) 2015-2024 LunarG, Inc.
* Copyright (C) 2015-2024 Google Inc.
/* Copyright (c) 2015-2025 The Khronos Group Inc.
* Copyright (c) 2015-2025 Valve Corporation
* Copyright (c) 2015-2025 LunarG, Inc.
* Copyright (C) 2015-2025 Google Inc.
* Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
* Modifications Copyright (C) 2022 RasterGrid Kft.
*
Expand Down Expand Up @@ -148,6 +148,9 @@ class Image : public Bindable {

bool IsSwapchainImage() const { return create_from_swapchain != VK_NULL_HANDLE; }

// TODO - need to understand if VkBindImageMemorySwapchainInfoKHR counts as "bound"
bool HasBeenBound() const { return (MemState() != nullptr) || (bind_swapchain); }

inline bool IsImageTypeEqual(const VkImageCreateInfo &other_create_info) const {
return create_info.imageType == other_create_info.imageType;
}
Expand Down
4 changes: 2 additions & 2 deletions layers/state_tracker/state_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,7 @@ void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, ui
// if bindInfoCount is 1, we know for sure if that single buffer was bound or not
if (bindInfoCount > 1) {
for (uint32_t i = 0; i < bindInfoCount; i++) {
// If user passed in VkBindMemoryStatus, we can update which buffers are good or not
// If user passed in VkBindMemoryStatus, we can update which buffers are valid or not
if (auto *bind_memory_status = vku::FindStructInPNextChain<VkBindMemoryStatus>(pBindInfos[i].pNext)) {
if (bind_memory_status->pResult && *bind_memory_status->pResult == VK_SUCCESS) {
UpdateBindBufferMemoryState(pBindInfos[i]);
Expand Down Expand Up @@ -3737,7 +3737,7 @@ void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uin
// if bindInfoCount is 1, we know for sure if that single image was bound or not
if (bindInfoCount > 1) {
for (uint32_t i = 0; i < bindInfoCount; i++) {
// If user passed in VkBindMemoryStatus, we can update which buffers are good or not
// If user passed in VkBindMemoryStatus, we can update which images are valid or not
if (auto *bind_memory_status = vku::FindStructInPNextChain<VkBindMemoryStatus>(pBindInfos[i].pNext)) {
if (bind_memory_status->pResult && *bind_memory_status->pResult == VK_SUCCESS) {
UpdateBindImageMemoryState(pBindInfos[i]);
Expand Down
4 changes: 2 additions & 2 deletions layers/sync/sync_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void SyncValidator::UpdateSyncImageMemoryBindState(uint32_t count, const VkBindI
auto image_state = Get<ImageState>(info.image);

// Need to protect if some VkBindMemoryStatus are not VK_SUCCESS
if (!image_state->MemState()) continue;
if (!image_state->HasBeenBound()) continue;

if (image_state->IsTiled()) {
image_state->SetOpaqueBaseAddress(*this);
Expand Down Expand Up @@ -2975,7 +2975,7 @@ void SyncValidator::PostCallRecordBindImageMemory(VkDevice device, VkImage image

void SyncValidator::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfo *pBindInfos,
const RecordObject &record_obj) {
// Don't check |record_obj.result| as some bind might be valid
// Don't check |record_obj.result| as some binds might still be valid
BaseClass::PostCallRecordBindImageMemory2(device, bindInfoCount, pBindInfos, record_obj);

UpdateSyncImageMemoryBindState(bindInfoCount, pBindInfos);
Expand Down
36 changes: 0 additions & 36 deletions tests/unit/buffer_positive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,39 +280,3 @@ TEST_F(PositiveBuffer, BufferUsageFlags2Usage) {
buffer_ci.usage = 0xBAD0000;
CreateBufferTest(*this, &buffer_ci, {});
}

TEST_F(PositiveBuffer, BindMemoryStatus) {
TEST_DESCRIPTION("Use VkBindMemoryStatus when binding buffer to memory.");

SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredFeature(vkt::Feature::maintenance6);
AddRequiredExtensions(VK_KHR_MAINTENANCE_6_EXTENSION_NAME);
RETURN_IF_SKIP(Init());
if (IsPlatformMockICD()) {
GTEST_SKIP() << "Test not supported by MockICD, skipping";
}

VkBufferCreateInfo buffer_ci = vku::InitStructHelper();
buffer_ci.size = 32u;
buffer_ci.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;

vkt::Buffer buffer;
buffer.InitNoMemory(*m_device, buffer_ci);

VkMemoryAllocateInfo alloc_info = vku::InitStructHelper();
alloc_info.allocationSize = 32u;
vkt::DeviceMemory memory(*m_device, alloc_info);

VkResult result = VK_RESULT_MAX_ENUM;

VkBindMemoryStatus bind_memory_status = vku::InitStructHelper();
bind_memory_status.pResult = &result;

VkBindBufferMemoryInfo bindInfo = vku::InitStructHelper(&bind_memory_status);
bindInfo.buffer = buffer.handle();
bindInfo.memory = memory.handle();
bindInfo.memoryOffset = 0u;
vk::BindBufferMemory2(device(), 1u, &bindInfo);

ASSERT_NE(result, VK_RESULT_MAX_ENUM);
}
8 changes: 4 additions & 4 deletions tests/unit/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2296,11 +2296,11 @@ TEST_F(NegativeMemory, DISABLED_PartialBoundBuffer) {

VkBindBufferMemoryInfo bind_buffer_infos[2];
bind_buffer_infos[0] = vku::InitStructHelper();
bind_buffer_infos[0].buffer = buffer_0.handle();
bind_buffer_infos[0].memory = buffer_memory.handle();
bind_buffer_infos[0].buffer = buffer_0;
bind_buffer_infos[0].memory = buffer_memory;
bind_buffer_infos[1] = vku::InitStructHelper();
bind_buffer_infos[1].buffer = buffer_1.handle();
bind_buffer_infos[1].memory = buffer_memory.handle();
bind_buffer_infos[1].buffer = buffer_1;
bind_buffer_infos[1].memory = buffer_memory;

VkResult result = vk::BindBufferMemory2KHR(device(), 2, bind_buffer_infos);
if (result == VK_SUCCESS) {
Expand Down
73 changes: 69 additions & 4 deletions tests/unit/memory_positive.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright (c) 2023-2024 The Khronos Group Inc.
* Copyright (c) 2023-2024 Valve Corporation
* Copyright (c) 2023-2024 LunarG, Inc.
* Copyright (c) 2023-2024 Collabora, Inc.
* Copyright (c) 2023-2025 The Khronos Group Inc.
* Copyright (c) 2023-2025 Valve Corporation
* Copyright (c) 2023-2025 LunarG, Inc.
* Copyright (c) 2023-2025 Collabora, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -556,3 +556,68 @@ TEST_F(PositiveMemory, BindMemoryDX12Handle) {
vk::BindImageMemory(device(), image, memory, 0);
}
#endif // VK_USE_PLATFORM_WIN32_KHR

TEST_F(PositiveMemory, BindMemoryStatusBuffer) {
TEST_DESCRIPTION("Use VkBindMemoryStatus when binding buffer to memory.");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredFeature(vkt::Feature::maintenance6);
AddRequiredExtensions(VK_KHR_MAINTENANCE_6_EXTENSION_NAME);
RETURN_IF_SKIP(Init());
if (IsPlatformMockICD()) {
GTEST_SKIP() << "Test not supported by MockICD, skipping";
}

VkBufferCreateInfo buffer_ci = vku::InitStructHelper();
buffer_ci.size = 32u;
buffer_ci.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;

vkt::Buffer buffer;
buffer.InitNoMemory(*m_device, buffer_ci);

VkMemoryAllocateInfo alloc_info = vku::InitStructHelper();
alloc_info.allocationSize = 32u;
vkt::DeviceMemory memory(*m_device, alloc_info);

VkResult result = VK_RESULT_MAX_ENUM;

VkBindMemoryStatus bind_memory_status = vku::InitStructHelper();
bind_memory_status.pResult = &result;

VkBindBufferMemoryInfo bind_info = vku::InitStructHelper(&bind_memory_status);
bind_info.buffer = buffer;
bind_info.memory = memory;
bind_info.memoryOffset = 0u;
vk::BindBufferMemory2(device(), 1u, &bind_info);

ASSERT_NE(result, VK_RESULT_MAX_ENUM);
}

TEST_F(PositiveMemory, BindMemoryStatusImage) {
TEST_DESCRIPTION("Use VkBindMemoryStatus when binding image to memory.");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredFeature(vkt::Feature::maintenance6);
AddRequiredExtensions(VK_KHR_MAINTENANCE_6_EXTENSION_NAME);
RETURN_IF_SKIP(Init());
if (IsPlatformMockICD()) {
GTEST_SKIP() << "Test not supported by MockICD, skipping";
}

auto image_ci = vkt::Image::ImageCreateInfo2D(32, 32, 1, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT);
vkt::Image image(*m_device, image_ci, vkt::no_mem);

vkt::DeviceMemory memory;
memory.init(*m_device, vkt::DeviceMemory::GetResourceAllocInfo(*m_device, image.MemoryRequirements(), 0));

VkResult result = VK_RESULT_MAX_ENUM;

VkBindMemoryStatus bind_memory_status = vku::InitStructHelper();
bind_memory_status.pResult = &result;

VkBindImageMemoryInfo bind_info = vku::InitStructHelper(&bind_memory_status);
bind_info.image = image;
bind_info.memory = memory;
bind_info.memoryOffset = 0u;
vk::BindImageMemory2(device(), 1u, &bind_info);

ASSERT_NE(result, VK_RESULT_MAX_ENUM);
}

0 comments on commit 46d886a

Please sign in to comment.