Fix crashes for Metal 3.0 capabilities.

Don't allocate MTLHeap of zero size.
MVKImage check for device memory when accessing MTLCPUCacheMode..
This commit is contained in:
Bill Hollings 2019-10-16 18:50:01 -04:00
parent c6ea99e4db
commit b5b103e75c
3 changed files with 8 additions and 1 deletions

View File

@ -178,6 +178,9 @@ bool MVKDeviceMemory::ensureMTLHeap() {
// Don't bother if we don't have placement heaps.
if (!getDevice()->_pMetalFeatures->placementHeaps) { return true; }
// Can't create MTLHeaps of zero size.
if (_allocationSize == 0) { return true; }
#if MVK_MACOS
// MTLHeaps on Mac must use private storage for now.
if (_mtlStorageMode != MTLStorageModePrivate) { return true; }

View File

@ -216,7 +216,7 @@ public:
MTLStorageMode getMTLStorageMode();
/** Returns the Metal CPU cache mode used by this image. */
inline MTLCPUCacheMode getMTLCPUCacheMode() { return _deviceMemory->getMTLCPUCacheMode(); }
MTLCPUCacheMode getMTLCPUCacheMode();
/**
* Returns whether the memory is automatically coherent between device and host.

View File

@ -487,6 +487,10 @@ MTLStorageMode MVKImage::getMTLStorageMode() {
return stgMode;
}
MTLCPUCacheMode MVKImage::getMTLCPUCacheMode() {
return _deviceMemory ? _deviceMemory->getMTLCPUCacheMode() : MTLCPUCacheModeDefaultCache;
}
bool MVKImage::isMemoryHostCoherent() {
return (getMTLStorageMode() == MTLStorageModeShared);
}