Skip to content

Commit

Permalink
Merge pull request #2238 from billhollings/VK_KHR_portability_subset-…
Browse files Browse the repository at this point in the history
…final

Add support for final version of VK_KHR_portability_subset extension.
  • Loading branch information
billhollings authored May 13, 2024
2 parents bf097ed + 9ad95b8 commit ffdfc11
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 1 deletion.
3 changes: 3 additions & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ class MVKPhysicalDevice : public MVKDispatchableVulkanAPIObject {
/** Populates the specified structure with the features of this device. */
void getFeatures(VkPhysicalDeviceFeatures2* features);

/** Populates a list of Vulkan features that are NOT supported by this device. */
VkResult getMissingFeatures(uint32_t* pMissingFeatureCount, VkPortabilitySubsetMissingFeatureKHR* pMissingFeatures);

/** Populates the specified structure with the properties of this device. */
void getProperties(VkPhysicalDeviceProperties* properties);

Expand Down
61 changes: 60 additions & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@

#define supportsMTLGPUFamily(GPUF) ([_mtlDevice respondsToSelector: @selector(supportsFamily:)] && [_mtlDevice supportsFamily: MTLGPUFamily ##GPUF])

#define makeMissingFeature(feat) VK_PORTABILITY_SUBSET_MISSING_FEATURE_## feat ##_KHR

// Suppress unused variable warnings to allow us to define these all in one place,
// but use them in platform-conditional code blocks.
#pragma clang diagnostic push
Expand Down Expand Up @@ -509,6 +511,32 @@
}
}

VkResult MVKPhysicalDevice::getMissingFeatures(uint32_t* pMissingFeatureCount, VkPortabilitySubsetMissingFeatureKHR* pMissingFeatures) {
#define addMissingFeature(feat) \
if (pMissingFeatures) { \
if (mfCnt < *pMissingFeatureCount) { \
pMissingFeatures[mfCnt] = makeMissingFeature(feat); \
} else { \
return VK_INCOMPLETE; \
} \
} \
mfCnt++;

uint32_t mfCnt = 0;
addMissingFeature(IMAGE_VIEW_2D_ON_3D_IMAGE);
addMissingFeature(RASTERIZATION_DYNAMIC_POLYGON_MODE_POINTS);
addMissingFeature(SAMPLER_MIP_LOD_BIAS);
addMissingFeature(SHADER_ATOMIC_ORDERING_STRONG);
addMissingFeature(SHADER_NON_UNIFORM_MEMORY_BARRIERS);
addMissingFeature(SHADER_SAMPLE_RATE_INTERPOLATION_FUNCTIONS);
addMissingFeature(SHADER_TESSELLATION_ISOLINES);
addMissingFeature(SHADER_TESSELLATION_POINT_MODE);

// Return the count of missing features.
*pMissingFeatureCount = mfCnt;
return VK_SUCCESS;
}

void MVKPhysicalDevice::getProperties(VkPhysicalDeviceProperties* properties) {
updateTimestampPeriod();
*properties = _properties;
Expand Down Expand Up @@ -3470,6 +3498,26 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope
}
}

static const char* getMissingFeatureName(VkPortabilitySubsetMissingFeatureKHR missingFeat) {
#define STR_IMPL(sym) #sym
#define STR(sym) STR_IMPL(sym)
#define CASE_STRINGIFY(sym) case sym: return STR(sym)
switch (missingFeat) {
CASE_STRINGIFY(makeMissingFeature(IMAGE_VIEW_2D_ON_3D_IMAGE));
CASE_STRINGIFY(makeMissingFeature(RASTERIZATION_DYNAMIC_POLYGON_MODE_POINTS));
CASE_STRINGIFY(makeMissingFeature(SAMPLER_MIP_LOD_BIAS));
CASE_STRINGIFY(makeMissingFeature(SHADER_ATOMIC_ORDERING_STRONG));
CASE_STRINGIFY(makeMissingFeature(SHADER_NON_UNIFORM_MEMORY_BARRIERS));
CASE_STRINGIFY(makeMissingFeature(SHADER_SAMPLE_RATE_INTERPOLATION_FUNCTIONS));
CASE_STRINGIFY(makeMissingFeature(SHADER_TESSELLATION_ISOLINES));
CASE_STRINGIFY(makeMissingFeature(SHADER_TESSELLATION_POINT_MODE));
default: return STR(makeMissingFeature(UNKNOWN));
}
#undef CASE_STRINGIFY
#undef STR
#undef STR_IMPL
}

void MVKPhysicalDevice::logGPUInfo() {
string logMsg = "GPU device:";
logMsg += "\n\t\tmodel: %s";
Expand All @@ -3479,7 +3527,7 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope
logMsg += "\n\t\tpipelineCacheUUID: %s";
logMsg += "\n\t\tGPU memory available: %llu MB";
logMsg += "\n\t\tGPU memory used: %llu MB";
logMsg += "\n\tsupports the following Metal Versions, GPU's and Feature Sets:";
logMsg += "\n\tsupports the following Metal features:";
logMsg += "\n\t\tMetal Shading Language %s";

#if MVK_XCODE_15 && (MVK_IOS || MVK_MACOS)
Expand Down Expand Up @@ -3564,6 +3612,17 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope
}
#endif

logMsg += "\n\tconforms to all supported Vulkan features";
uint32_t missingFeatCnt = 0;
getMissingFeatures(&missingFeatCnt, nullptr);
VkPortabilitySubsetMissingFeatureKHR missingFeats[missingFeatCnt];
getMissingFeatures(&missingFeatCnt, missingFeats);
for (uint32_t missingFeatIdx = 0; missingFeatIdx < missingFeatCnt; missingFeatIdx++) {
if (missingFeatIdx == 0) { logMsg += " except the following:"; }
logMsg += "\n\t\t";
logMsg += getMissingFeatureName(missingFeats[missingFeatIdx]);
}

string devTypeStr;
switch (_properties.deviceType) {
case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
Expand Down
16 changes: 16 additions & 0 deletions MoltenVK/MoltenVK/Vulkan/vulkan.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3099,6 +3099,22 @@ MVK_PUBLIC_VULKAN_SYMBOL VkResult vkUnmapMemory2KHR(
}


#pragma mark -
#pragma mark VK_KHR_portability_subset extension

MVK_PUBLIC_VULKAN_SYMBOL VkResult vkGetPhysicalDevicePortabilitySubsetMissingFeaturesKHR(
VkPhysicalDevice physicalDevice,
uint32_t* pMissingFeatureCount,
VkPortabilitySubsetMissingFeatureKHR* pMissingFeatures) {

MVKTraceVulkanCallStart();
MVKPhysicalDevice* mvkPD = MVKPhysicalDevice::getMVKPhysicalDevice(physicalDevice);
VkResult rslt = mvkPD->getMissingFeatures(pMissingFeatureCount, pMissingFeatures);
MVKTraceVulkanCallEnd();
return rslt;
}


#pragma mark -
#pragma mark VK_KHR_push_descriptor extension

Expand Down
12 changes: 12 additions & 0 deletions fetchDependencies
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,18 @@ else
update_repo ${REPO_NAME} ${REPO_URL} ${REPO_REV}
fi

# Temporary patch to fetch dev versions of header files that support
# VK_KHR_portability_subset_metal header and copy them to Vulkan-Headers repo.
# This requires password access to private Khronos member dev repos.
REPO_URL="https://gitlab.khronos.org/vulkan/vulkan.git"
REPO_REV="78b1dc7cb54714f8f7ce639b336277a861c6f059"
update_repo "vulkan" ${REPO_URL} ${REPO_REV}
cd "vulkan/xml"
make clean install
cd - > /dev/null
cp -a "vulkan/gen/include/vulkan/vulkan_core.h" "${REPO_NAME}/include/vulkan/"
cp -a "vulkan/gen/include/vulkan/vulkan_beta.h" "${REPO_NAME}/include/vulkan/"


# ----------------- SPIRV-Cross -------------------

Expand Down

0 comments on commit ffdfc11

Please sign in to comment.