Vulkan backend render targets don't allow client to specify stencil bits

We already always create the stencil buffer even for wrapped RTs.

Make VulkanWindowContext use SkSurface::MakeFromBackendRenderTarget.

Change-Id: I5df429d347331801954ec17cb9d75e323a7af345
Reviewed-on: https://skia-review.googlesource.com/113206
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2018-03-09 12:02:32 -05:00 committed by Skia Commit-Bot
parent 32929e0614
commit afdc6b1ba9
4 changed files with 25 additions and 12 deletions

View File

@ -194,11 +194,13 @@ public:
const GrGLFramebufferInfo& glInfo);
#ifdef SK_VULKAN
/** Deprecated, use version that does not take stencil bits. */
GrBackendRenderTarget(int width,
int height,
int sampleCnt,
int stencilBits,
const GrVkImageInfo& vkInfo);
GrBackendRenderTarget(int width, int height, int sampleCnt, const GrVkImageInfo& vkInfo);
#endif
int width() const { return fWidth; }

View File

@ -153,10 +153,19 @@ GrBackendRenderTarget::GrBackendRenderTarget(int width,
int sampleCnt,
int stencilBits,
const GrVkImageInfo& vkInfo)
: GrBackendRenderTarget(width, height, sampleCnt, vkInfo) {
// This is a deprecated constructor that takes a bogus stencil bits.
SkASSERT(0 == stencilBits);
}
GrBackendRenderTarget::GrBackendRenderTarget(int width,
int height,
int sampleCnt,
const GrVkImageInfo& vkInfo)
: fWidth(width)
, fHeight(height)
, fSampleCnt(SkTMax(1, sampleCnt))
, fStencilBits(stencilBits)
, fStencilBits(0) // We always create stencil buffers internally for vulkan
, fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat))
, fBackend(kVulkan_GrBackend)
, fVkInfo(vkInfo) {}

View File

@ -942,11 +942,13 @@ sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTa
desc.fSampleCnt = 1;
sk_sp<GrVkRenderTarget> tgt = GrVkRenderTarget::MakeWrappedRenderTarget(this, desc, info);
if (tgt && backendRT.stencilBits()) {
if (!createStencilAttachmentForRenderTarget(tgt.get(), desc.fWidth, desc.fHeight)) {
return nullptr;
}
// We don't allow the client to supply a premade stencil buffer. We always create one if needed.
SkASSERT(!backendRT.stencilBits());
if (tgt) {
SkASSERT(tgt->canAttemptStencilAttachment());
}
return tgt;
}

View File

@ -293,14 +293,14 @@ void VulkanWindowContext::createBuffers(VkFormat format, SkColorType colorType)
info.fFormat = format;
info.fLevelCount = 1;
GrBackendTexture backendTex(fWidth, fHeight, info);
GrBackendRenderTarget backendRT(fWidth, fHeight, fSampleCount, info);
fSurfaces[i] = SkSurface::MakeFromBackendTextureAsRenderTarget(fContext.get(), backendTex,
kTopLeft_GrSurfaceOrigin,
fSampleCount,
colorType,
fDisplayParams.fColorSpace,
&fSurfaceProps);
fSurfaces[i] = SkSurface::MakeFromBackendRenderTarget(fContext.get(),
backendRT,
kTopLeft_GrSurfaceOrigin,
colorType,
fDisplayParams.fColorSpace,
&fSurfaceProps);
}
// create the command pool for the command buffers