Skip to content

Commit 2683cfe

Browse files
committed
extension enabled
1 parent c9b2a6a commit 2683cfe

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

src/Tests.cpp

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8258,15 +8258,50 @@ static void TestWin32Handles()
82588258
{
82598259
#if VMA_EXTERNAL_MEMORY_WIN32
82608260
wprintf(L"Test Win32 handles\n");
8261-
VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
8262-
bufCreateInfo.size = 1024;
8263-
bufCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8264-
VmaAllocationCreateInfo allocCreateInfo = {};
8265-
allocCreateInfo.usage = VMA_MEMORY_USAGE_AUTO;
8261+
constexpr static VkExportMemoryAllocateInfoKHR exportInfo{
8262+
VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR,
8263+
nullptr,
8264+
VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT
8265+
};
8266+
constexpr static VkExternalMemoryBufferCreateInfoKHR externalInfo{
8267+
VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR,
8268+
nullptr,
8269+
VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT
8270+
};
8271+
8272+
VkBufferCreateInfo sampleBufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
8273+
sampleBufCreateInfo.size = 0x1000; // Doesn't matter.
8274+
sampleBufCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8275+
sampleBufCreateInfo.pNext = &externalInfo;
8276+
8277+
VmaAllocationCreateInfo sampleAllocCreateInfo = {};
8278+
sampleAllocCreateInfo.usage = VMA_MEMORY_USAGE_AUTO;
8279+
sampleAllocCreateInfo.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT;
8280+
8281+
uint32_t memTypeIndex;
8282+
TEST(vmaFindMemoryTypeIndexForBufferInfo(g_hAllocator,
8283+
&sampleBufCreateInfo, &sampleAllocCreateInfo, &memTypeIndex) == VK_SUCCESS);
8284+
// Check res...
8285+
8286+
8287+
// Create a pool that can have at most 2 blocks, 128 MiB each.
8288+
VmaPoolCreateInfo poolCreateInfo = {};
8289+
poolCreateInfo.memoryTypeIndex = memTypeIndex;
8290+
poolCreateInfo.blockSize = 128ull * 1024 * 1024;
8291+
poolCreateInfo.maxBlockCount = 2;
8292+
poolCreateInfo.pMemoryAllocateNext = (void*)&exportInfo;
8293+
8294+
8295+
VmaPool pool;
8296+
TEST(vmaCreatePool(g_hAllocator, &poolCreateInfo, &pool) == VK_SUCCESS);
8297+
8298+
8299+
sampleAllocCreateInfo.pool = pool;
8300+
82668301
VkBuffer buf;
82678302
VmaAllocation alloc;
82688303
VmaAllocationInfo allocInfo;
8269-
TEST(vmaCreateBuffer(g_hAllocator, &bufCreateInfo, &allocCreateInfo, &buf, &alloc, &allocInfo) == VK_SUCCESS);
8304+
TEST(vmaCreateBuffer(g_hAllocator, &sampleBufCreateInfo, &sampleAllocCreateInfo, &buf, &alloc, &allocInfo) == VK_SUCCESS);
82708305
HANDLE handle;
82718306
HANDLE handle2;
82728307
TEST(vmaGetMemoryWin32HandleKHR(g_hAllocator, alloc, nullptr, &handle) == VK_SUCCESS);

src/VulkanSample.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ bool VK_KHR_buffer_device_address_enabled = false;
6969
bool VK_EXT_memory_priority_enabled = false;
7070
bool VK_EXT_debug_utils_enabled = false;
7171
bool VK_KHR_maintenance5_enabled = false;
72+
bool VK_KHR_external_memory_win32_enabled = false;
7273
bool g_SparseBindingEnabled = false;
7374

7475
// # Pointers to functions from extensions
@@ -1449,6 +1450,7 @@ static void PrintEnabledFeatures()
14491450
}
14501451
wprintf(L"VK_EXT_memory_priority: %d\n", VK_EXT_memory_priority_enabled ? 1 : 0);
14511452
wprintf(L"VK_KHR_maintenance5: %d\n", VK_KHR_maintenance5_enabled? 1 : 0);
1453+
wprintf(L"VK_KHR_external_memory_win32: %d\n", VK_KHR_external_memory_win32_enabled ? 1 : 0);
14521454
}
14531455

14541456
void SetAllocatorCreateInfo(VmaAllocatorCreateInfo& outInfo)
@@ -1494,6 +1496,11 @@ void SetAllocatorCreateInfo(VmaAllocatorCreateInfo& outInfo)
14941496
outInfo.flags |= VMA_ALLOCATOR_CREATE_KHR_MAINTENANCE5_BIT;
14951497
}
14961498

1499+
if(VK_KHR_external_memory_win32_enabled)
1500+
{
1501+
outInfo.flags |= VMA_ALLOCATOR_CREATE_KHR_EXTERNAL_MEMORY_WIN32_BIT;
1502+
}
1503+
14971504
if(USE_CUSTOM_CPU_ALLOCATION_CALLBACKS)
14981505
{
14991506
outInfo.pAllocationCallbacks = &g_CpuAllocationCallbacks;
@@ -1876,6 +1883,8 @@ static void InitializeApplication()
18761883
VK_EXT_memory_priority_enabled = true;
18771884
else if(strcmp(physicalDeviceExtensionProperties[i].extensionName, VK_KHR_MAINTENANCE_5_EXTENSION_NAME) == 0)
18781885
VK_KHR_maintenance5_enabled = true;
1886+
else if (strcmp(physicalDeviceExtensionProperties[i].extensionName, VK_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME) == 0)
1887+
VK_KHR_external_memory_win32_enabled = true;
18791888
}
18801889

18811890
if(GetVulkanApiVersion() >= VK_API_VERSION_1_2)
@@ -2036,6 +2045,8 @@ static void InitializeApplication()
20362045
enabledDeviceExtensions.push_back(VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME);
20372046
if(VK_KHR_maintenance5_enabled)
20382047
enabledDeviceExtensions.push_back(VK_KHR_MAINTENANCE_5_EXTENSION_NAME);
2048+
if (VK_KHR_external_memory_win32_enabled)
2049+
enabledDeviceExtensions.push_back(VK_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME);
20392050

20402051
VkPhysicalDeviceFeatures2 deviceFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2 };
20412052
deviceFeatures.features.samplerAnisotropy = VK_TRUE;

0 commit comments

Comments
 (0)