diff --git a/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm b/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm index c7fb3407..2e72198a 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm +++ b/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm @@ -165,6 +165,9 @@ void MVKCmdBlitImage::setContent(VkImage srcImage, // Validate clearConfigurationResult(); + if (_blitKey.isDepthFormat() && renderRegionCount > 0) { + setConfigurationResult(mvkNotifyErrorWithText(VK_ERROR_FEATURE_NOT_PRESENT, "vkCmdBlitImage(): Scaling of depth/stencil images is not supported.")); + } if ((_srcImage->getMTLPixelFormat() != _mtlPixFmt) && mvkMTLPixelFormatIsStencilFormat(_mtlPixFmt)) { setConfigurationResult(mvkNotifyErrorWithText(VK_ERROR_FEATURE_NOT_PRESENT, "vkCmdBlitImage(): The source and destination images must have the same format for depth/stencil images.")); } @@ -292,7 +295,7 @@ void MVKCmdBlitImage::encode(MVKCommandEncoder* cmdEncoder) { } // Perform those BLITs that require rendering to destination texture. - if ( !_mtlTexBlitRenders.empty() ) { + if ( !_mtlTexBlitRenders.empty() && !_blitKey.isDepthFormat() ) { cmdEncoder->endCurrentMetalEncoding(); @@ -300,11 +303,10 @@ void MVKCmdBlitImage::encode(MVKCommandEncoder* cmdEncoder) { id dstMTLTex = _dstImage->getMTLTexture(); if ( !srcMTLTex || !dstMTLTex ) { return; } - bool isDepthFormat = _blitKey.isDepthFormat(); bool isArrayType = _blitKey.isArrayType(); MTLRenderPassColorAttachmentDescriptor* mtlColorAttDesc = _mtlRenderPassDescriptor.colorAttachments[0]; - mtlColorAttDesc.texture = isDepthFormat ? nil : dstMTLTex; + mtlColorAttDesc.texture = dstMTLTex; uint32_t vtxBuffIdx = getDevice()->getMetalBufferIndexForVertexAttributeBinding(kMVKVertexContentBufferIndex); @@ -321,20 +323,11 @@ void MVKCmdBlitImage::encode(MVKCommandEncoder* cmdEncoder) { [mtlRendEnc pushDebugGroup: @"vkCmdBlitImage"]; [mtlRendEnc setRenderPipelineState: cmdEncPool->getCmdBlitImageMTLRenderPipelineState(_blitKey)]; cmdEncoder->setVertexBytes(mtlRendEnc, bltRend.vertices, sizeof(bltRend.vertices), vtxBuffIdx); + [mtlRendEnc setFragmentTexture: srcMTLTex atIndex: 0]; + [mtlRendEnc setFragmentSamplerState: cmdEncPool->getCmdBlitImageMTLSamplerState(_mtlFilter) atIndex: 0]; if (isArrayType) { cmdEncoder->setFragmentBytes(mtlRendEnc, &bltRend, sizeof(bltRend), 0); } - if (isDepthFormat) { - [mtlRendEnc setDepthStencilState: cmdEncPool->getMTLDepthStencilState(isDepthFormat, false)]; - [mtlRendEnc setVertexTexture: srcMTLTex atIndex: 0]; - [mtlRendEnc setVertexSamplerState: cmdEncPool->getCmdBlitImageMTLSamplerState(_mtlFilter) atIndex: 0]; - if (isArrayType) { - cmdEncoder->setVertexBytes(mtlRendEnc, &bltRend, sizeof(bltRend), 0); - } - } else { - [mtlRendEnc setFragmentTexture: srcMTLTex atIndex: 0]; - [mtlRendEnc setFragmentSamplerState: cmdEncPool->getCmdBlitImageMTLSamplerState(_mtlFilter) atIndex: 0]; - } [mtlRendEnc drawPrimitives: MTLPrimitiveTypeTriangleStrip vertexStart: 0 vertexCount: kMVKBlitVertexCount]; [mtlRendEnc popDebugGroup]; [mtlRendEnc endEncoding]; diff --git a/MoltenVK/MoltenVK/Commands/MVKCommandPipelineStateFactoryShaderSource.h b/MoltenVK/MoltenVK/Commands/MVKCommandPipelineStateFactoryShaderSource.h index 26e5381d..3ba543f4 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCommandPipelineStateFactoryShaderSource.h +++ b/MoltenVK/MoltenVK/Commands/MVKCommandPipelineStateFactoryShaderSource.h @@ -41,37 +41,11 @@ typedef struct { float2 v_texCoord; \n\ } VaryingsPosTex; \n\ \n\ -typedef struct { \n\ - uint srcLevel; \n\ - uint srcSlice; \n\ - uint dstLevel; \n\ - uint dstSlice; \n\ -} BlitInfo; \n\ - \n\ vertex VaryingsPosTex vtxCmdBlitImage(AttributesPosTex attributes [[stage_in]]) { \n\ VaryingsPosTex varyings; \n\ varyings.v_position = float4(attributes.a_position, 0.0, 1.0); \n\ varyings.v_texCoord = attributes.a_texCoord; \n\ return varyings; \n\ -} \n\ - \n\ -vertex VaryingsPos vtxCmdBlitImageD(AttributesPosTex attributes [[stage_in]], \n\ - depth2d texture [[texture(0)]], \n\ - sampler sampler [[sampler(0)]]) { \n\ - float depth = texture.sample(sampler, attributes.a_texCoord); \n\ - VaryingsPos varyings; \n\ - varyings.v_position = float4(attributes.a_position, depth, 1.0); \n\ - return varyings; \n\ -} \n\ - \n\ -vertex VaryingsPos vtxCmdBlitImageDA(AttributesPosTex attributes [[stage_in]], \n\ - depth2d_array texture [[texture(0)]], \n\ - sampler sampler [[sampler(0)]], \n\ - constant BlitInfo& blitInfo [[buffer(0)]]) { \n\ - float depth = texture.sample(sampler, attributes.a_texCoord, blitInfo.srcSlice); \n\ - VaryingsPos varyings; \n\ - varyings.v_position = float4(attributes.a_position, depth, 1.0); \n\ - return varyings; \n\ } \n\ \n\ typedef struct { \n\ diff --git a/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm b/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm index 9e5bc7d1..e9af48af 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm +++ b/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm @@ -30,20 +30,13 @@ using namespace std; #pragma mark MVKCommandResourceFactory id MVKCommandResourceFactory::newCmdBlitImageMTLRenderPipelineState(MVKRPSKeyBlitImg& blitKey) { - bool isDepthFormat = blitKey.isDepthFormat(); - bool isArrayType = blitKey.isArrayType(); - MTLRenderPipelineDescriptor* plDesc = [[[MTLRenderPipelineDescriptor alloc] init] autorelease]; plDesc.label = [NSString stringWithFormat: @"CmdBlitImage"]; - plDesc.vertexFunction = getFunctionNamed(isDepthFormat ? (isArrayType ? "vtxCmdBlitImageDA" : "vtxCmdBlitImageD") : "vtxCmdBlitImage"); + plDesc.vertexFunction = getFunctionNamed("vtxCmdBlitImage"); plDesc.fragmentFunction = getBlitFragFunction(blitKey); - if (isDepthFormat) { - plDesc.depthAttachmentPixelFormat = blitKey.getMTLPixelFormat(); - } else { - plDesc.colorAttachments[0].pixelFormat = blitKey.getMTLPixelFormat(); - } + plDesc.colorAttachments[0].pixelFormat = blitKey.getMTLPixelFormat(); MTLVertexDescriptor* vtxDesc = plDesc.vertexDescriptor; @@ -134,7 +127,6 @@ id MVKCommandResourceFactory::newCmdClearMTLRenderPipeli id MVKCommandResourceFactory::getBlitFragFunction(MVKRPSKeyBlitImg& blitKey) { id mtlFunc = nil; - bool isDepthFormat = blitKey.isDepthFormat(); NSString* typeStr = getMTLFormatTypeString(blitKey.getMTLPixelFormat()); bool isArrayType = blitKey.isArrayType(); @@ -164,11 +156,7 @@ id MVKCommandResourceFactory::getBlitFragFunction(MVKRPSKeyBlitImg& NSString* funcName = @"fragBlit"; [msl appendFormat: @"fragment %@4 %@(VaryingsPosTex varyings [[stage_in]],", typeStr, funcName]; [msl appendLineMVK]; - if (isDepthFormat) { - [msl appendFormat: @" depth2d%@ texture [[texture(0)]],", arraySuffix]; - } else { - [msl appendFormat: @" texture2d%@<%@> texture [[texture(0)]],", arraySuffix, typeStr]; - } + [msl appendFormat: @" texture2d%@<%@> texture [[texture(0)]],", arraySuffix, typeStr]; [msl appendLineMVK]; if (isArrayType) { [msl appendLineMVK: @" sampler sampler [[sampler(0)]],"]; @@ -176,11 +164,7 @@ id MVKCommandResourceFactory::getBlitFragFunction(MVKRPSKeyBlitImg& } else { [msl appendLineMVK: @" sampler sampler [[sampler(0)]]) {"]; } - if (isDepthFormat) { - [msl appendFormat: @" return %@4(texture.sample(sampler, varyings.v_texCoord)%@);", typeStr, sliceArg]; - } else { - [msl appendFormat: @" return texture.sample(sampler, varyings.v_texCoord%@);", sliceArg]; - } + [msl appendFormat: @" return texture.sample(sampler, varyings.v_texCoord%@);", sliceArg]; [msl appendLineMVK]; [msl appendLineMVK: @"}"];