Skip to content

Commit

Permalink
Refactor defining MTLPixelFormat and GPU capabilities.
Browse files Browse the repository at this point in the history
- Add MVKMTLDeviceCapabilities to encapsulate Metal GPU family
  capabilities, and use it in MVKPhysicalDevice and MVKPixelFormats
  to identify GPU capabilities.
- Remove all references to MTLGPUFamily and MTLFeatureSet
  outside MVKMTLDeviceCapabilities.
- Blend or select AppleGPU and MacGPU format capabilities.
- Simplify MVKPixelFormats::modifyMTLFormatCapabilities()
  based on MVKMTLDeviceCapabilities.
- Add guard code to ensure MTLPixelFormatInvalid &
  MTLVertexFormatInvalid capabilities are not overwritten
  by other formats that don't exist on some platforms.
- Update MTLPixelFormat capabilities based on latest Metal docs.
- Remove some variations tied to very older OS versions,
  or MTLFeatureSets that have the same GPU family, including
  setting MSL 2.0 as the earliest supported version.
- Enable VkPhysicalDeviceFeatures::vertexPipelineStoresAndAtomics
  & fragmentStoresAndAtomics on all platforms.
- During startup, only log the highest GPU family.
  • Loading branch information
billhollings committed Aug 14, 2024
1 parent 3b9e335 commit 5afeaa4
Show file tree
Hide file tree
Showing 6 changed files with 610 additions and 1,155 deletions.
1 change: 1 addition & 0 deletions Docs/Whats_New.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Released TBD
return `VK_ERROR_FRAGMENTED_POOL` if failure was due to pool fragmentation.
- `vkUpdateDescriptorSets()`: Per Vulkan spec, allow write or copy beyond the
end of a descriptor binding count, including inline uniform block descriptors.
- Update `VkFormat` capabilities based on latest Metal docs.
- Fix rendering issue with render pass that immediately follows a kernel dispatch.
- Ensure all MoltenVK config info set by `VK_EXT_layer_settings` is used.
- Move primitive-restart-disabled warning from renderpass to pipeline creation, to reduce voluminous log noise.
Expand Down
55 changes: 38 additions & 17 deletions MoltenVK/MoltenVK/GPUObjects/MVKDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,37 @@ static constexpr VkExtent2D kMVKSampleLocationPixelGridSizeNotSupported = { 0, 0
typedef NSUInteger MTLTimestamp;
#endif


#pragma mark -
#pragma mark MVKMTLDeviceCapabilities

typedef struct MVKMTLDeviceCapabilities {
bool supportsApple1;
bool supportsApple2;
bool supportsApple3;
bool supportsApple4;
bool supportsApple5;
bool supportsApple6;
bool supportsApple7;
bool supportsApple8;
bool supportsApple9;
bool supportsMac1;
bool supportsMac2;
bool supportsMetal3;

bool isAppleGPU;
bool supportsBCTextureCompression;
bool supportsDepth24Stencil8;
bool supports32BitFloatFiltering;
bool supports32BitMSAA;

uint8_t getHighestAppleGPU() const;
uint8_t getHighestMacGPU() const;

MVKMTLDeviceCapabilities(id<MTLDevice> mtlDev);
} MVKMTLDeviceCapabilities;


#pragma mark -
#pragma mark MVKPhysicalDevice

Expand Down Expand Up @@ -355,6 +386,9 @@ class MVKPhysicalDevice : public MVKDispatchableVulkanAPIObject {
/** Returns the MTLStorageMode that matches the Vulkan memory property flags. */
MTLStorageMode getMTLStorageModeFromVkMemoryPropertyFlags(VkMemoryPropertyFlags vkFlags);

/** Returns the MTLDevice capabilities. */
const MVKMTLDeviceCapabilities getMTLDeviceCapabilities() { return _gpuCapabilities; }


#pragma mark Construction

Expand Down Expand Up @@ -413,17 +447,18 @@ class MVKPhysicalDevice : public MVKDispatchableVulkanAPIObject {
void populateHostImageCopyProperties(VkPhysicalDeviceHostImageCopyPropertiesEXT* pHostImageCopyProps);
void logGPUInfo();

id<MTLDevice> _mtlDevice;
MVKInstance* _mvkInstance;
id<MTLDevice> _mtlDevice;
const MVKMTLDeviceCapabilities _gpuCapabilities;
const MVKExtensionList _supportedExtensions;
MVKPixelFormats _pixelFormats;
VkPhysicalDeviceFeatures _features;
MVKPhysicalDeviceVulkan12FeaturesNoExt _vulkan12FeaturesNoExt;
MVKPhysicalDeviceMetalFeatures _metalFeatures;
VkPhysicalDeviceProperties _properties;
VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT _texelBuffAlignProperties;
VkPhysicalDeviceMemoryProperties _memoryProperties;
MVKSmallVector<MVKQueueFamily*, kMVKQueueFamilyCount> _queueFamilies;
MVKPixelFormats _pixelFormats;
VkExternalMemoryProperties _hostPointerExternalMemoryProperties;
VkExternalMemoryProperties _mtlBufferExternalMemoryProperties;
VkExternalMemoryProperties _mtlTextureExternalMemoryProperties;
Expand All @@ -437,7 +472,6 @@ class MVKPhysicalDevice : public MVKDispatchableVulkanAPIObject {
uint32_t _privateMemoryTypes;
uint32_t _lazilyAllocatedMemoryTypes;
bool _hasUnifiedMemory = true;
bool _isAppleGPU = true;
bool _isUsingMetalArgumentBuffers = true;
};

Expand Down Expand Up @@ -896,7 +930,7 @@ class MVKDeviceTrackingMixin {
bool isUnifiedMemoryGPU() { return _device->_physicalDevice->_hasUnifiedMemory; }

/** Returns whether the GPU is Apple Silicon. */
bool isAppleGPU() { return _device->_physicalDevice->_isAppleGPU; }
bool isAppleGPU() { return _device->_physicalDevice->_gpuCapabilities.isAppleGPU; }

/** Returns whether this device is using one Metal argument buffer for each descriptor set, on multiple pipeline and pipeline stages. */
virtual bool isUsingMetalArgumentBuffers() { return _device->_physicalDevice->_isUsingMetalArgumentBuffers; };
Expand Down Expand Up @@ -1068,16 +1102,3 @@ uint64_t mvkGetRegistryID(id<MTLDevice> mtlDevice);
* the returned value will be zero.
*/
uint64_t mvkGetLocationID(id<MTLDevice> mtlDevice);

/** Returns whether the MTLDevice supports BC texture compression. */
bool mvkSupportsBCTextureCompression(id<MTLDevice> mtlDevice);

/** Redefinitions because Mac Catalyst doesn't support feature sets. */
#if MVK_MACCAT
#define MTLFeatureSet_macOS_GPUFamily1_v1 MTLGPUFamilyMacCatalyst1
#define MTLFeatureSet_macOS_GPUFamily1_v2 MTLGPUFamilyMacCatalyst1
#define MTLFeatureSet_macOS_GPUFamily1_v3 MTLGPUFamilyMacCatalyst1
#define MTLFeatureSet_macOS_GPUFamily1_v4 MTLGPUFamilyMacCatalyst1

#define MTLFeatureSet_macOS_GPUFamily2_v1 MTLGPUFamilyMacCatalyst2
#endif
Loading

0 comments on commit 5afeaa4

Please sign in to comment.