Skip to content

Commit

Permalink
Add: KHR_format_feature_flags2
Browse files Browse the repository at this point in the history
  • Loading branch information
spnda committed Dec 29, 2023
1 parent 22427b8 commit b817d0c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
18 changes: 17 additions & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,22 @@

void MVKPhysicalDevice::getFormatProperties(VkFormat format, VkFormatProperties2KHR* pFormatProperties) {
pFormatProperties->sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2_KHR;

for (auto* next = (VkBaseOutStructure*)pFormatProperties->pNext; next; next = next->pNext) {
switch (next->sType) {
case VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_3_KHR: {
auto* properties3 = (VkFormatProperties3*)next;
auto& properties = _pixelFormats.getVkFormatProperties3(format);
properties3->linearTilingFeatures = properties.linearTilingFeatures;
properties3->optimalTilingFeatures = properties.optimalTilingFeatures;
properties3->bufferFeatures = properties.bufferFeatures;
break;
}
default:
break;
}
}

getFormatProperties(format, &pFormatProperties->formatProperties);
}

Expand Down Expand Up @@ -2530,7 +2546,7 @@
} else {
alignment = [_mtlDevice minimumLinearTextureAlignmentForPixelFormat: mtlFmt];
}
VkFormatProperties& props = _pixelFormats.getVkFormatProperties(vk);
VkFormatProperties props = _pixelFormats.getVkFormatProperties(vk);
// For uncompressed formats, this is the size of a single texel.
// Note that no implementations of Metal support compressed formats
// in a linear texture (including texture buffers). It's likely that even
Expand Down
9 changes: 5 additions & 4 deletions MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ typedef struct MVKVkFormatDesc {
VkExtent2D blockTexelSize;
uint32_t bytesPerBlock;
MVKFormatType formatType;
VkFormatProperties properties;
VkFormatProperties3 properties;
VkComponentMapping componentMapping;
const char* name;
bool hasReportedSubstitution;
Expand Down Expand Up @@ -344,7 +344,8 @@ class MVKPixelFormats : public MVKBaseObject {
MTLTextureSwizzleChannels getMTLTextureSwizzleChannels(VkFormat vkFormat);

/** Returns the default properties for the specified Vulkan format. */
VkFormatProperties& getVkFormatProperties(VkFormat vkFormat);
VkFormatProperties getVkFormatProperties(VkFormat format);
VkFormatProperties3& getVkFormatProperties3(VkFormat vkFormat);

/** Returns the Metal format capabilities supported by the specified Vulkan format, without substitution. */
MVKMTLFmtCaps getCapabilities(VkFormat vkFormat, bool isExtended = false);
Expand Down Expand Up @@ -404,8 +405,8 @@ class MVKPixelFormats : public MVKBaseObject {
* Vulkan VkFormat as used as a vertex attribute format.
*/
MTLVertexFormat getMTLVertexFormat(VkFormat vkFormat);


static VkFormatFeatureFlags convertFormatPropertiesFlagBits(VkFormatFeatureFlags2 flags);
#pragma mark Construction

MVKPixelFormats(MVKPhysicalDevice* physicalDevice = nullptr);
Expand Down
22 changes: 18 additions & 4 deletions MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,19 @@
return mvkMTLTextureSwizzleChannelsFromVkComponentMapping(getVkComponentMapping(vkFormat));
}

VkFormatProperties& MVKPixelFormats::getVkFormatProperties(VkFormat vkFormat) {
VkFormatProperties3& MVKPixelFormats::getVkFormatProperties3(VkFormat vkFormat) {
return getVkFormatDesc(vkFormat).properties;
}

VkFormatProperties MVKPixelFormats::getVkFormatProperties(VkFormat vkFormat) {
auto& properties = getVkFormatProperties3(vkFormat);
VkFormatProperties ret;
ret.linearTilingFeatures = MVKPixelFormats::convertFormatPropertiesFlagBits(properties.linearTilingFeatures);
ret.optimalTilingFeatures = MVKPixelFormats::convertFormatPropertiesFlagBits(properties.optimalTilingFeatures);
ret.bufferFeatures = MVKPixelFormats::convertFormatPropertiesFlagBits(properties.bufferFeatures);
return ret;
}

MVKMTLFmtCaps MVKPixelFormats::getCapabilities(VkFormat vkFormat, bool isExtended) {
return getCapabilities(getVkFormatDesc(vkFormat).mtlPixelFormat, isExtended);
}
Expand Down Expand Up @@ -460,7 +469,7 @@
}

void MVKPixelFormats::enumerateSupportedFormats(VkFormatProperties properties, bool any, std::function<bool(VkFormat)> func) {
static const auto areFeaturesSupported = [any](uint32_t a, uint32_t b) {
static const auto areFeaturesSupported = [any](VkFlags64 a, VkFlags64 b) {
if (b == 0) return true;
if (any)
return mvkIsAnyFlagEnabled(a, b);
Expand Down Expand Up @@ -792,6 +801,11 @@
return _mtlVertexFormatDescriptions[fmtIdx];
}

VkFormatFeatureFlags MVKPixelFormats::convertFormatPropertiesFlagBits(VkFormatFeatureFlags2 flags) {
// Truncate to 32-bits and just return. All current values are identical.
return static_cast<VkFormatFeatureFlags>(flags);
}


#pragma mark Construction

Expand All @@ -811,7 +825,7 @@
#define addVkFormatDescFull(VK_FMT, MTL_FMT, MTL_FMT_ALT, MTL_VTX_FMT, MTL_VTX_FMT_ALT, CSPC, CSCB, BLK_W, BLK_H, BLK_BYTE_CNT, MVK_FMT_TYPE, SWIZ_R, SWIZ_G, SWIZ_B, SWIZ_A) \
MVKAssert(fmtIdx < _vkFormatCount, "Attempting to describe %d VkFormats, but only have space for %d. Increase the value of _vkFormatCount", fmtIdx + 1, _vkFormatCount); \
_vkFormatDescriptions[fmtIdx++] = { VK_FORMAT_ ##VK_FMT, MTLPixelFormat ##MTL_FMT, MTLPixelFormat ##MTL_FMT_ALT, MTLVertexFormat ##MTL_VTX_FMT, MTLVertexFormat ##MTL_VTX_FMT_ALT, \
CSPC, CSCB, { BLK_W, BLK_H }, BLK_BYTE_CNT, kMVKFormat ##MVK_FMT_TYPE, { 0, 0, 0 }, \
CSPC, CSCB, { BLK_W, BLK_H }, BLK_BYTE_CNT, kMVKFormat ##MVK_FMT_TYPE, { VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_3, nullptr, 0, 0, 0 }, \
{ VK_COMPONENT_SWIZZLE_ ##SWIZ_R, VK_COMPONENT_SWIZZLE_ ##SWIZ_G, VK_COMPONENT_SWIZZLE_ ##SWIZ_B, VK_COMPONENT_SWIZZLE_ ##SWIZ_A }, \
"VK_FORMAT_" #VK_FMT, false }

Expand Down Expand Up @@ -2119,7 +2133,7 @@
mvkEnableFlags(VK_FEATS, kMVKVkFormatFeatureFlags ##TYPE ##CAP); \
}

VkFormatProperties& vkProps = vkDesc.properties;
VkFormatProperties3& vkProps = vkDesc.properties;
MVKMTLFmtCaps mtlPixFmtCaps = getMTLPixelFormatDesc(vkDesc.mtlPixelFormat).mtlFmtCaps;
vkProps.optimalTilingFeatures = kMVKVkFormatFeatureFlagsTexNone;
vkProps.linearTilingFeatures = kMVKVkFormatFeatureFlagsTexNone;
Expand Down
1 change: 1 addition & 0 deletions MoltenVK/MoltenVK/Layers/MVKExtensions.def
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ MVK_EXTENSION(KHR_external_memory_capabilities, KHR_EXTERNAL_MEMORY_CAPABI
MVK_EXTENSION(KHR_external_semaphore, KHR_EXTERNAL_SEMAPHORE, DEVICE, 10.11, 8.0, 1.0)
MVK_EXTENSION(KHR_external_semaphore_capabilities, KHR_EXTERNAL_SEMAPHORE_CAPABILITIES, INSTANCE, 10.11, 8.0, 1.0)
MVK_EXTENSION(KHR_fragment_shader_barycentric, KHR_FRAGMENT_SHADER_BARYCENTRIC, DEVICE, 10.15, 14.0, 1.0)
MVK_EXTENSION(KHR_format_feature_flags2, KHR_FORMAT_FEATURE_FLAGS_2, DEVICE, 10.11, 8.0, 1.0)
MVK_EXTENSION(KHR_get_memory_requirements2, KHR_GET_MEMORY_REQUIREMENTS_2, DEVICE, 10.11, 8.0, 1.0)
MVK_EXTENSION(KHR_get_physical_device_properties2, KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2, INSTANCE, 10.11, 8.0, 1.0)
MVK_EXTENSION(KHR_get_surface_capabilities2, KHR_GET_SURFACE_CAPABILITIES_2, INSTANCE, 10.11, 8.0, 1.0)
Expand Down

0 comments on commit b817d0c

Please sign in to comment.