Skip to content

Commit

Permalink
Report error only on the first time a format substitution is made.
Browse files Browse the repository at this point in the history
  • Loading branch information
billhollings committed Sep 10, 2019
1 parent 1a0bf64 commit 5636233
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
1 change: 1 addition & 0 deletions Docs/Whats_New.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Released 2019/09/10
- Support optional use of `MTLFence` for Vulkan semaphores via the `MVK_ALLOW_METAL_FENCES` environment variable.
- Remove error logging on `VK_TIMEOUT` of `VkSemaphore` and `VkFence`.
- Remove log message warning of obsolescence of `vkCreateMacOSSurfaceMVK()` and `vkCreateIOSSurfaceMVK()` functions.
- Report error only on the first time a format substitution is made.
- Streamline design and use of `MVKSemaphore`.
- Consolidate the various linkable objects into a `MVKLinkableMixin` template base class.
- Use `MVKVector` whenever possible in MoltenVK, especially within render loop.
Expand Down
53 changes: 29 additions & 24 deletions MoltenVK/MoltenVK/Vulkan/mvk_datatypes.mm
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
#define MVK_FMT_NO_FEATS 0

#define MVK_MAKE_FMT_STRUCT(VK_FMT, MTL_FMT, MTL_FMT_ALT, IOS_SINCE, MACOS_SINCE, BLK_W, BLK_H, BLK_BYTE_CNT, MTL_VTX_FMT, MTL_VTX_FMT_ALT, VTX_IOS_SINCE, VTX_MACOS_SINCE, CLR_TYPE, PIXEL_FEATS, BUFFER_FEATS) \
{ VK_FMT, MTL_FMT, MTL_FMT_ALT, IOS_SINCE, MACOS_SINCE, { BLK_W, BLK_H }, BLK_BYTE_CNT, MTL_VTX_FMT, MTL_VTX_FMT_ALT, VTX_IOS_SINCE, VTX_MACOS_SINCE, CLR_TYPE, { (PIXEL_FEATS & MVK_FMT_LINEAR_TILING_FEATS), PIXEL_FEATS, BUFFER_FEATS }, #VK_FMT, #MTL_FMT }
{ VK_FMT, MTL_FMT, MTL_FMT_ALT, IOS_SINCE, MACOS_SINCE, { BLK_W, BLK_H }, BLK_BYTE_CNT, MTL_VTX_FMT, MTL_VTX_FMT_ALT, VTX_IOS_SINCE, VTX_MACOS_SINCE, CLR_TYPE, { (PIXEL_FEATS & MVK_FMT_LINEAR_TILING_FEATS), PIXEL_FEATS, BUFFER_FEATS }, #VK_FMT, #MTL_FMT, false }

#pragma mark Texture formats

Expand All @@ -117,6 +117,7 @@
VkFormatProperties properties;
const char* vkName;
const char* mtlName;
bool hasReportedSubstitution;

inline double bytesPerTexel() const { return (double)bytesPerBlock / (double)(blockTexelSize.width * blockTexelSize.height); };

Expand Down Expand Up @@ -569,31 +570,35 @@ MVK_PUBLIC_SYMBOL MTLPixelFormat mvkMTLPixelFormatFromVkFormat(VkFormat vkFormat
}

MTLPixelFormat mvkMTLPixelFormatFromVkFormatInObj(VkFormat vkFormat, MVKBaseObject* mvkObj) {
MTLPixelFormat mtlPixFmt = MTLPixelFormatInvalid;
MTLPixelFormat mtlPixFmt = MTLPixelFormatInvalid;

const MVKFormatDesc& fmtDesc = formatDescForVkFormat(vkFormat);
if (fmtDesc.isSupported()) {
mtlPixFmt = fmtDesc.mtl;
} else if (vkFormat != VK_FORMAT_UNDEFINED) {
// If the MTLPixelFormat is not supported but VkFormat is valid,
// report an error, and possibly substitute a different MTLPixelFormat.
string errMsg;
errMsg += "VkFormat ";
errMsg += (fmtDesc.vkName) ? fmtDesc.vkName : to_string(fmtDesc.vk);
errMsg += " is not supported on this device.";

if (fmtDesc.isSupportedOrSubstitutable()) {
mtlPixFmt = fmtDesc.mtlSubstitute;

const MVKFormatDesc& fmtDescSubs = formatDescForMTLPixelFormat(mtlPixFmt);
errMsg += " Using VkFormat ";
errMsg += (fmtDescSubs.vkName) ? fmtDescSubs.vkName : to_string(fmtDescSubs.vk);
errMsg += " instead.";
}
MVKBaseObject::reportError(mvkObj, VK_ERROR_FORMAT_NOT_SUPPORTED, "%s", errMsg.c_str());
}
const MVKFormatDesc& fmtDesc = formatDescForVkFormat(vkFormat);
if (fmtDesc.isSupported()) {
mtlPixFmt = fmtDesc.mtl;
} else if (vkFormat != VK_FORMAT_UNDEFINED) {
// If the MTLPixelFormat is not supported but VkFormat is valid, attempt to substitute a different format.
mtlPixFmt = fmtDesc.mtlSubstitute;

// Report an error if there is no substitute, or the first time a substitution is made.
if ( !mtlPixFmt || !fmtDesc.hasReportedSubstitution ) {
string errMsg;
errMsg += "VkFormat ";
errMsg += (fmtDesc.vkName) ? fmtDesc.vkName : to_string(fmtDesc.vk);
errMsg += " is not supported on this device.";

if (mtlPixFmt) {
((MVKFormatDesc*)&fmtDesc)->hasReportedSubstitution = true;

const MVKFormatDesc& fmtDescSubs = formatDescForMTLPixelFormat(mtlPixFmt);
errMsg += " Using VkFormat ";
errMsg += (fmtDescSubs.vkName) ? fmtDescSubs.vkName : to_string(fmtDescSubs.vk);
errMsg += " instead.";
}
MVKBaseObject::reportError(mvkObj, VK_ERROR_FORMAT_NOT_SUPPORTED, "%s", errMsg.c_str());
}
}

return mtlPixFmt;
return mtlPixFmt;
}

MVK_PUBLIC_SYMBOL VkFormat mvkVkFormatFromMTLPixelFormat(MTLPixelFormat mtlFormat) {
Expand Down

0 comments on commit 5636233

Please sign in to comment.