Skip to content

Commit ffb4406

Browse files
authored
Merge pull request #373 from cdavis5e/bind-memory2
Support the VK_KHR_bind_memory2 extension.
2 parents 1d8a95e + 89aaaee commit ffb4406

File tree

6 files changed

+58
-0
lines changed

6 files changed

+58
-0
lines changed

Docs/MoltenVK_Runtime_UserGuide.md

+1
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ In addition to the core *Vulkan* API, **MoltenVK** also supports the following
223223

224224
- `VK_KHR_16bit_storage`
225225
- `VK_KHR_8bit_storage`
226+
- `VK_KHR_bind_memory2`
226227
- `VK_KHR_dedicated_allocation`
227228
- `VK_KHR_descriptor_update_template`
228229
- `VK_KHR_get_memory_requirements2`

MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm

+2
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@
283283
ADD_PROC_ADDR(vkCmdExecuteCommands);
284284

285285
// Supported extensions:
286+
ADD_PROC_ADDR(vkBindBufferMemory2KHR);
287+
ADD_PROC_ADDR(vkBindImageMemory2KHR);
286288
ADD_PROC_ADDR(vkCreateDescriptorUpdateTemplateKHR);
287289
ADD_PROC_ADDR(vkDestroyDescriptorUpdateTemplateKHR);
288290
ADD_PROC_ADDR(vkUpdateDescriptorSetWithTemplateKHR);

MoltenVK/MoltenVK/GPUObjects/MVKResource.h

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class MVKResource : public MVKRefCountedDeviceObject {
4747
/** Binds this resource to the specified offset within the specified memory allocation. */
4848
virtual VkResult bindDeviceMemory(MVKDeviceMemory* mvkMem, VkDeviceSize memOffset);
4949

50+
/** Binds this resource according to the specified bind information. */
51+
virtual VkResult bindDeviceMemory2(const void* pBindInfo);
52+
5053
/** Returns the device memory underlying this resource. */
5154
inline MVKDeviceMemory* getDeviceMemory() { return _deviceMemory; }
5255

MoltenVK/MoltenVK/GPUObjects/MVKResource.mm

+17
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@
2020
#include "MVKCommandBuffer.h"
2121

2222

23+
struct MVKBindDeviceMemoryInfo {
24+
VkStructureType sType;
25+
void* pNext;
26+
union {
27+
VkBuffer buffer;
28+
VkImage image;
29+
};
30+
VkDeviceMemory memory;
31+
VkDeviceSize memoryOffset;
32+
};
33+
34+
2335
#pragma mark MVKResource
2436

2537
VkResult MVKResource::bindDeviceMemory(MVKDeviceMemory* mvkMem, VkDeviceSize memOffset) {
@@ -33,6 +45,11 @@
3345
return VK_SUCCESS;
3446
}
3547

48+
VkResult MVKResource::bindDeviceMemory2(const void* pBindInfo) {
49+
auto* mvkBindInfo = (const MVKBindDeviceMemoryInfo*)pBindInfo;
50+
return bindDeviceMemory((MVKDeviceMemory*)mvkBindInfo->memory, mvkBindInfo->memoryOffset);
51+
}
52+
3653
// Returns whether the specified global memory barrier requires a sync between this
3754
// texture and host memory for the purpose of the host reading texture memory.
3855
bool MVKResource::needsHostReadSync(VkPipelineStageFlags srcStageMask,

MoltenVK/MoltenVK/Layers/MVKExtensions.def

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
MVK_EXTENSION(KHR_16bit_storage, KHR_16BIT_STORAGE)
3434
MVK_EXTENSION(KHR_8bit_storage, KHR_8BIT_STORAGE)
35+
MVK_EXTENSION(KHR_bind_memory2, KHR_BIND_MEMORY_2)
3536
MVK_EXTENSION(KHR_dedicated_allocation, KHR_DEDICATED_ALLOCATION)
3637
MVK_EXTENSION(KHR_descriptor_update_template, KHR_DESCRIPTOR_UPDATE_TEMPLATE)
3738
MVK_EXTENSION(KHR_get_memory_requirements2, KHR_GET_MEMORY_REQUIREMENTS_2)

MoltenVK/MoltenVK/Vulkan/vulkan.mm

+34
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,40 @@ MVK_PUBLIC_SYMBOL void vkCmdExecuteCommands(
14741474
}
14751475

14761476

1477+
#pragma mark -
1478+
#pragma mark VK_KHR_bind_memory2 extension
1479+
1480+
MVK_PUBLIC_SYMBOL VkResult vkBindBufferMemory2KHR(
1481+
VkDevice device,
1482+
uint32_t bindInfoCount,
1483+
const VkBindBufferMemoryInfoKHR* pBindInfos) {
1484+
VkResult res;
1485+
for (uint32_t i = 0; i < bindInfoCount; ++i) {
1486+
MVKBuffer* mvkBuff = (MVKBuffer*)pBindInfos[i].buffer;
1487+
res = mvkBuff->bindDeviceMemory2(&pBindInfos[i]);
1488+
if (res != VK_SUCCESS) {
1489+
break;
1490+
}
1491+
}
1492+
return res;
1493+
}
1494+
1495+
MVK_PUBLIC_SYMBOL VkResult vkBindImageMemory2KHR(
1496+
VkDevice device,
1497+
uint32_t bindInfoCount,
1498+
const VkBindImageMemoryInfoKHR* pBindInfos) {
1499+
VkResult res;
1500+
for (uint32_t i = 0; i < bindInfoCount; ++i) {
1501+
MVKImage* mvkImg = (MVKImage*)pBindInfos[i].image;
1502+
res = mvkImg->bindDeviceMemory2(&pBindInfos[i]);
1503+
if (res != VK_SUCCESS) {
1504+
break;
1505+
}
1506+
}
1507+
return res;
1508+
}
1509+
1510+
14771511
#pragma mark -
14781512
#pragma mark VK_KHR_descriptor_update_template extension
14791513

0 commit comments

Comments
 (0)