Skip to content

Commit

Permalink
Implement vkGetMemoryMetalHandlePropertiesEXT
Browse files Browse the repository at this point in the history
  • Loading branch information
aitor-lunarg committed Aug 26, 2024
1 parent 75f35e8 commit 0dbc5be
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
14 changes: 9 additions & 5 deletions MoltenVK/MoltenVK/GPUObjects/MVKDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,38 +336,40 @@ class MVKPhysicalDevice : public MVKDispatchableVulkanAPIObject {
* Returns a bit mask of all memory type indices.
* Each bit [0..31] in the returned bit mask indicates a distinct memory type.
*/
uint32_t getAllMemoryTypes() { return _allMemoryTypes; }
uint32_t getAllMemoryTypes() const { return _allMemoryTypes; }

/**
* Returns a bit mask of all memory type indices that allow host visibility to the memory.
* Each bit [0..31] in the returned bit mask indicates a distinct memory type.
*/
uint32_t getHostVisibleMemoryTypes() { return _hostVisibleMemoryTypes; }
uint32_t getHostVisibleMemoryTypes() const { return _hostVisibleMemoryTypes; }

/**
* Returns a bit mask of all memory type indices that are coherent between host and device.
* Each bit [0..31] in the returned bit mask indicates a distinct memory type.
*/
uint32_t getHostCoherentMemoryTypes() { return _hostCoherentMemoryTypes; }
uint32_t getHostCoherentMemoryTypes() const { return _hostCoherentMemoryTypes; }

/**
* Returns a bit mask of all memory type indices that do NOT allow host visibility to the memory.
* Each bit [0..31] in the returned bit mask indicates a distinct memory type.
*/
uint32_t getPrivateMemoryTypes() { return _privateMemoryTypes; }
uint32_t getPrivateMemoryTypes() const { return _privateMemoryTypes; }

/**
* Returns a bit mask of all memory type indices that are lazily allocated.
* Each bit [0..31] in the returned bit mask indicates a distinct memory type.
*/
uint32_t getLazilyAllocatedMemoryTypes() { return _lazilyAllocatedMemoryTypes; }
uint32_t getLazilyAllocatedMemoryTypes() const { return _lazilyAllocatedMemoryTypes; }

/** Returns the external memory properties supported for buffers for the handle type. */
VkExternalMemoryProperties& getExternalBufferProperties(VkExternalMemoryHandleTypeFlagBits handleType);

/** Returns the external memory properties supported for images for the handle type. */
VkExternalMemoryProperties& getExternalImageProperties(VkFormat format, VkExternalMemoryHandleTypeFlagBits handleType);

uint32_t getExternalResourceMemoryTypeBits(MTLResource_id handle) const;


#pragma mark Metal

Expand Down Expand Up @@ -503,6 +505,8 @@ class MVKDevice : public MVKDispatchableVulkanAPIObject {
/** Returns a pointer to the Vulkan instance. */
MVKInstance* getInstance() override { return _physicalDevice->_mvkInstance; }

const MVKPhysicalDevice* getPhysicalDevice() const { return _physicalDevice; }

/** Returns the name of this device. */
const char* getName() { return _physicalDevice->_properties.deviceName; }

Expand Down
24 changes: 24 additions & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,30 @@
}
}

uint32_t MVKPhysicalDevice::getExternalResourceMemoryTypeBits(MTLResource_id handle) const {
uint32_t memoryTypeBits = 0u;
switch (handle.storageMode) {
case MTLStorageModeShared:
memoryTypeBits = _hostCoherentMemoryTypes;
break;
#if !MVK_IOS && !MVK_TVOS
case MTLStorageModeManaged:
memoryTypeBits = _hostVisibleMemoryTypes;
break;
#endif
case MTLStorageModePrivate:
memoryTypeBits = _privateMemoryTypes;
break;
case MTLStorageModeMemoryless:
memoryTypeBits = _lazilyAllocatedMemoryTypes;
break;
default:
// This should never be reached, but just to be future-proof
break;
};
return memoryTypeBits;
}

static const VkExternalFenceProperties _emptyExtFenceProps = {VK_STRUCTURE_TYPE_EXTERNAL_FENCE_PROPERTIES, nullptr, 0, 0, 0};

void MVKPhysicalDevice::getExternalFenceProperties(const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo,
Expand Down
3 changes: 2 additions & 1 deletion MoltenVK/MoltenVK/Vulkan/vulkan.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3056,7 +3056,8 @@ MVK_PUBLIC_VULKAN_SYMBOL VkResult vkGetMemoryMetalHandlePropertiesEXT(
VkMemoryMetalHandlePropertiesEXT* pMemoryMetalHandleProperties) {

MVKTraceVulkanCallStart();
// TODO
MVKDevice* mvkDvc = MVKDevice::getMVKDevice(device);
pMemoryMetalHandleProperties->memoryTypeBits = mvkDvc->getPhysicalDevice()->getExternalResourceMemoryTypeBits(handle);
MVKTraceVulkanCallEnd();
return VK_SUCCESS;
}
Expand Down

0 comments on commit 0dbc5be

Please sign in to comment.