Don't enable PixelFormatView just in case we need it to copy
Not worth the performance hit to everything else
This commit is contained in:
parent
8820c53666
commit
d0e00ad3be
@ -133,12 +133,17 @@ void MVKCmdCopyImage<N>::encode(MVKCommandEncoder* cmdEncoder, MVKCommandUse com
|
|||||||
|
|
||||||
MTLPixelFormat srcMTLPixFmt = _srcImage->getMTLPixelFormat(srcPlaneIndex);
|
MTLPixelFormat srcMTLPixFmt = _srcImage->getMTLPixelFormat(srcPlaneIndex);
|
||||||
bool isSrcCompressed = _srcImage->getIsCompressed();
|
bool isSrcCompressed = _srcImage->getIsCompressed();
|
||||||
|
bool canReinterpretSrc = _srcImage->hasPixelFormatView(srcPlaneIndex);
|
||||||
|
|
||||||
MTLPixelFormat dstMTLPixFmt = _dstImage->getMTLPixelFormat(dstPlaneIndex);
|
MTLPixelFormat dstMTLPixFmt = _dstImage->getMTLPixelFormat(dstPlaneIndex);
|
||||||
bool isDstCompressed = _dstImage->getIsCompressed();
|
bool isDstCompressed = _dstImage->getIsCompressed();
|
||||||
|
bool canReinterpretDst = _dstImage->hasPixelFormatView(dstPlaneIndex);
|
||||||
|
|
||||||
// If source and destination have different formats and at least one is compressed, use a temporary intermediary buffer
|
bool isEitherCompressed = isSrcCompressed || isDstCompressed;
|
||||||
bool useTempBuffer = (srcMTLPixFmt != dstMTLPixFmt) && (isSrcCompressed || isDstCompressed);
|
bool canReinterpret = canReinterpretSrc || canReinterpretDst;
|
||||||
|
|
||||||
|
// If source and destination can't be reinterpreted to matching formats use a temporary intermediary buffer
|
||||||
|
bool useTempBuffer = (srcMTLPixFmt != dstMTLPixFmt) && (isEitherCompressed || !canReinterpret);
|
||||||
|
|
||||||
if (useTempBuffer) {
|
if (useTempBuffer) {
|
||||||
// Add copy from source image to temp buffer.
|
// Add copy from source image to temp buffer.
|
||||||
@ -177,12 +182,13 @@ void MVKCmdCopyImage<N>::encode(MVKCommandEncoder* cmdEncoder, MVKCommandUse com
|
|||||||
|
|
||||||
size_t bytesPerRow = pixFmts->getBytesPerRow(srcMTLPixFmt, vkIC.extent.width);
|
size_t bytesPerRow = pixFmts->getBytesPerRow(srcMTLPixFmt, vkIC.extent.width);
|
||||||
size_t bytesPerRegion = pixFmts->getBytesPerLayer(srcMTLPixFmt, bytesPerRow, vkIC.extent.height);
|
size_t bytesPerRegion = pixFmts->getBytesPerLayer(srcMTLPixFmt, bytesPerRow, vkIC.extent.height);
|
||||||
tmpBuffSize += bytesPerRegion;
|
tmpBuffSize += bytesPerRegion * vkIC.extent.depth;
|
||||||
} else {
|
} else {
|
||||||
// Map the source pixel format to the dest pixel format through a texture view on the source texture.
|
// Map the source pixel format to the dest pixel format through a texture view on the reinterpretable texture.
|
||||||
// If the source and dest pixel formats are the same, this will simply degenerate to the source texture itself.
|
// If the source and dest pixel formats are the same, this will simply degenerate to the texture itself.
|
||||||
id<MTLTexture> srcMTLTex = _srcImage->getMTLTexture(srcPlaneIndex, _dstImage->getMTLPixelFormat(dstPlaneIndex));
|
MTLPixelFormat fmt = (canReinterpretSrc ? _dstImage : _srcImage)->getMTLPixelFormat(canReinterpretSrc ? dstPlaneIndex : srcPlaneIndex);
|
||||||
id<MTLTexture> dstMTLTex = _dstImage->getMTLTexture(dstPlaneIndex);
|
id<MTLTexture> srcMTLTex = _srcImage->getMTLTexture(srcPlaneIndex, fmt);
|
||||||
|
id<MTLTexture> dstMTLTex = _dstImage->getMTLTexture(dstPlaneIndex, fmt);
|
||||||
if ( !srcMTLTex || !dstMTLTex ) { return; }
|
if ( !srcMTLTex || !dstMTLTex ) { return; }
|
||||||
|
|
||||||
id<MTLBlitCommandEncoder> mtlBlitEnc = cmdEncoder->getMTLBlitEncoder(commandUse);
|
id<MTLBlitCommandEncoder> mtlBlitEnc = cmdEncoder->getMTLBlitEncoder(commandUse);
|
||||||
|
@ -311,6 +311,9 @@ public:
|
|||||||
*/
|
*/
|
||||||
inline bool hasExpectedTexelSize() { return _hasExpectedTexelSize; }
|
inline bool hasExpectedTexelSize() { return _hasExpectedTexelSize; }
|
||||||
|
|
||||||
|
/** Returns whether the texture has the PixelFormatView usage flag, allowing it to be reinterpreted. */
|
||||||
|
inline bool hasPixelFormatView(uint32_t planeIndex) { return mvkIsAnyFlagEnabled(getMTLTexture(planeIndex).usage, MTLTextureUsagePixelFormatView); }
|
||||||
|
|
||||||
/** Returns the Metal resource options for this image. */
|
/** Returns the Metal resource options for this image. */
|
||||||
MTLStorageMode getMTLStorageMode();
|
MTLStorageMode getMTLStorageMode();
|
||||||
|
|
||||||
|
@ -1763,6 +1763,13 @@ VkResult MVKImageViewPlane::initSwizzledMTLPixelFormat(const VkImageViewCreateIn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_imageView->_image->hasPixelFormatView(_planeIndex)) {
|
||||||
|
if (!enableSwizzling()) {
|
||||||
|
MVKAssert(0, "Image without PixelFormatView usage couldn't enable swizzling!");
|
||||||
|
}
|
||||||
|
return VK_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
switch (_mtlPixFmt) {
|
switch (_mtlPixFmt) {
|
||||||
case MTLPixelFormatR8Unorm:
|
case MTLPixelFormatR8Unorm:
|
||||||
if (SWIZZLE_MATCHES(ZERO, ANY, ANY, R)) {
|
if (SWIZZLE_MATCHES(ZERO, ANY, ANY, R)) {
|
||||||
|
@ -737,23 +737,23 @@ MTLTextureUsage MVKPixelFormats::getMTLTextureUsage(VkImageUsageFlags vkImageUsa
|
|||||||
mvkEnableFlags(mtlUsage, samples == VK_SAMPLE_COUNT_1_BIT ? MTLTextureUsageShaderWrite : MTLTextureUsageShaderRead);
|
mvkEnableFlags(mtlUsage, samples == VK_SAMPLE_COUNT_1_BIT ? MTLTextureUsageShaderWrite : MTLTextureUsageShaderRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create view on, but only on color formats, or combined depth-stencil formats if supported by the GPU...
|
bool pfv = false;
|
||||||
if ((mvkIsAnyFlagEnabled(vkImageUsageFlags, (VK_IMAGE_USAGE_TRANSFER_SRC_BIT)) || // May use temp view if transfer involves format change
|
|
||||||
(needsReinterpretation &&
|
// Swizzle emulation may need to reinterpret
|
||||||
|
needsReinterpretation |= !_physicalDevice->getMetalFeatures()->nativeTextureSwizzle;
|
||||||
|
|
||||||
|
pfv |= isColorFormat && needsReinterpretation &&
|
||||||
mvkIsAnyFlagEnabled(vkImageUsageFlags, (VK_IMAGE_USAGE_SAMPLED_BIT |
|
mvkIsAnyFlagEnabled(vkImageUsageFlags, (VK_IMAGE_USAGE_SAMPLED_BIT |
|
||||||
VK_IMAGE_USAGE_STORAGE_BIT |
|
VK_IMAGE_USAGE_STORAGE_BIT |
|
||||||
VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT |
|
VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT |
|
||||||
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)))) &&
|
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT));
|
||||||
isColorFormat) {
|
pfv |= isCombinedDepthStencilFmt && supportsStencilViews &&
|
||||||
|
mvkIsAnyFlagEnabled(vkImageUsageFlags, (VK_IMAGE_USAGE_TRANSFER_SRC_BIT | // May use temp view if transfer involves format change
|
||||||
mvkEnableFlags(mtlUsage, MTLTextureUsagePixelFormatView);
|
|
||||||
}
|
|
||||||
if (mvkIsAnyFlagEnabled(vkImageUsageFlags, (VK_IMAGE_USAGE_TRANSFER_SRC_BIT | // May use temp view if transfer involves format change
|
|
||||||
VK_IMAGE_USAGE_SAMPLED_BIT |
|
VK_IMAGE_USAGE_SAMPLED_BIT |
|
||||||
VK_IMAGE_USAGE_STORAGE_BIT |
|
VK_IMAGE_USAGE_STORAGE_BIT |
|
||||||
VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) &&
|
VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT));
|
||||||
isCombinedDepthStencilFmt && supportsStencilViews) {
|
|
||||||
|
|
||||||
|
if (pfv) {
|
||||||
mvkEnableFlags(mtlUsage, MTLTextureUsagePixelFormatView);
|
mvkEnableFlags(mtlUsage, MTLTextureUsagePixelFormatView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user