vkCmdBlitImage() remove broken support for depth/stencil scaling.

This commit is contained in:
Bill Hollings 2018-06-13 15:55:33 -04:00
parent 84ffa1844e
commit 1b9946c15d
3 changed files with 11 additions and 60 deletions

View File

@ -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<MTLTexture> 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];

View File

@ -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<float> 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<float> 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\

View File

@ -30,20 +30,13 @@ using namespace std;
#pragma mark MVKCommandResourceFactory
id<MTLRenderPipelineState> 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<MTLRenderPipelineState> MVKCommandResourceFactory::newCmdClearMTLRenderPipeli
id<MTLFunction> MVKCommandResourceFactory::getBlitFragFunction(MVKRPSKeyBlitImg& blitKey) {
id<MTLFunction> mtlFunc = nil;
bool isDepthFormat = blitKey.isDepthFormat();
NSString* typeStr = getMTLFormatTypeString(blitKey.getMTLPixelFormat());
bool isArrayType = blitKey.isArrayType();
@ -164,11 +156,7 @@ id<MTLFunction> MVKCommandResourceFactory::getBlitFragFunction(MVKRPSKeyBlitImg&
NSString* funcName = @"fragBlit";
[msl appendFormat: @"fragment %@4 %@(VaryingsPosTex varyings [[stage_in]],", typeStr, funcName];
[msl appendLineMVK];
if (isDepthFormat) {
[msl appendFormat: @" depth2d%@<float> 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<MTLFunction> 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: @"}"];