diff options
author | 2018-02-01 14:16:02 -0500 | |
---|---|---|
committer | 2018-02-01 21:15:39 +0000 | |
commit | d0d7270fcc32546005b8e847df516cb11592cd30 (patch) | |
tree | 032f102536ecb8e665c348b733b230a062a1c010 /src/gpu/vk | |
parent | 2331c82e0d10ee519d9afb3f9e85485c6cf0b3c3 (diff) |
Revert "Revert "Redefine the meaning of sample counts in GPU backend.""
Fixes gpu config default samples to be 1 and updates config parsing test accordingly.
This reverts commit c1ce2f7966babaae0deb150f93f1227ee5af9285.
Bug: skia:
Change-Id: I456973b1f52ced85a2011ea10fc49449bfc5846f
Reviewed-on: https://skia-review.googlesource.com/102147
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/vk')
-rw-r--r-- | src/gpu/vk/GrVkCaps.cpp | 27 | ||||
-rw-r--r-- | src/gpu/vk/GrVkCaps.h | 4 | ||||
-rw-r--r-- | src/gpu/vk/GrVkGpu.cpp | 15 | ||||
-rw-r--r-- | src/gpu/vk/GrVkRenderTarget.cpp | 19 | ||||
-rw-r--r-- | src/gpu/vk/GrVkRenderTarget.h | 7 | ||||
-rw-r--r-- | src/gpu/vk/GrVkStencilAttachment.cpp | 2 | ||||
-rw-r--r-- | src/gpu/vk/GrVkTextureRenderTarget.cpp | 15 | ||||
-rw-r--r-- | src/gpu/vk/GrVkUtil.cpp | 2 |
8 files changed, 59 insertions, 32 deletions
diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp index 0ae7c00995..e9f239c294 100644 --- a/src/gpu/vk/GrVkCaps.cpp +++ b/src/gpu/vk/GrVkCaps.cpp @@ -346,7 +346,7 @@ void GrVkCaps::ConfigInfo::initSampleCounts(const GrVkInterface* interface, &properties)); VkSampleCountFlags flags = properties.sampleCounts; if (flags & VK_SAMPLE_COUNT_1_BIT) { - fColorSampleCounts.push(0); + fColorSampleCounts.push(1); } if (kImagination_VkVendor == physProps.vendorID) { // MSAA does not work on imagination @@ -386,18 +386,39 @@ void GrVkCaps::ConfigInfo::init(const GrVkInterface* interface, } } +bool GrVkCaps::isConfigRenderable(GrPixelConfig config, bool withMSAA) const { + if (!SkToBool(ConfigInfo::kRenderable_Flag & fConfigTable[config].fOptimalFlags)) { + return false; + } + if (withMSAA && fConfigTable[config].fColorSampleCounts.count() < 2) { + // We expect any renderable config to support non-MSAA rendering. + SkASSERT(1 == fConfigTable[config].fColorSampleCounts.count()); + SkASSERT(1 == fConfigTable[config].fColorSampleCounts[0]); + return false; + } + return true; +} + int GrVkCaps::getSampleCount(int requestedCount, GrPixelConfig config) const { + requestedCount = SkTMax(1, requestedCount); int count = fConfigTable[config].fColorSampleCounts.count(); - if (!count || !this->isConfigRenderable(config, true)) { + + if (!count || !this->isConfigRenderable(config, requestedCount > 1)) { return 0; } + if (1 == requestedCount) { + SkASSERT(fConfigTable[config].fColorSampleCounts.count() && + fConfigTable[config].fColorSampleCounts[0] == 1); + return 1; + } + for (int i = 0; i < count; ++i) { if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) { return fConfigTable[config].fColorSampleCounts[i]; } } - return fConfigTable[config].fColorSampleCounts[count-1]; + return 0; } bool validate_image_info(const GrVkImageInfo* imageInfo, SkColorType ct, GrPixelConfig* config) { diff --git a/src/gpu/vk/GrVkCaps.h b/src/gpu/vk/GrVkCaps.h index d63c2ba9b5..4468d89697 100644 --- a/src/gpu/vk/GrVkCaps.h +++ b/src/gpu/vk/GrVkCaps.h @@ -35,9 +35,7 @@ public: return SkToBool(ConfigInfo::kTextureable_Flag & fConfigTable[config].fOptimalFlags); } - bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { - return SkToBool(ConfigInfo::kRenderable_Flag & fConfigTable[config].fOptimalFlags); - } + bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override; bool isConfigCopyable(GrPixelConfig config) const override { return true; diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index f7e3d47dd9..4550dfe1ed 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -352,7 +352,7 @@ bool GrVkGpu::onGetWritePixelsInfo(GrSurface* dstSurface, GrSurfaceOrigin dstOri tempDrawInfo->fTempSurfaceDesc.fConfig = srcConfig; tempDrawInfo->fTempSurfaceDesc.fWidth = width; tempDrawInfo->fTempSurfaceDesc.fHeight = height; - tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0; + tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 1; tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; if (dstSurface->config() == srcConfig) { @@ -914,7 +914,7 @@ sk_sp<GrTexture> GrVkGpu::onWrapBackendTexture(const GrBackendTexture& backendTe surfDesc.fWidth = backendTex.width(); surfDesc.fHeight = backendTex.height(); surfDesc.fConfig = backendTex.config(); - surfDesc.fSampleCnt = 0; + surfDesc.fSampleCnt = 1; return GrVkTexture::MakeWrappedTexture(this, surfDesc, ownership, backendTex.getVkImageInfo()); } @@ -943,7 +943,7 @@ sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTa // general this is not an issue since swapchain images in vulkan are never multisampled. Thus if // you want a multisampled RT it is best to wrap the swapchain images and then let Skia handle // creating and owning the MSAA images. - if (backendRT.sampleCnt()) { + if (backendRT.sampleCnt() > 1) { return nullptr; } @@ -961,7 +961,7 @@ sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTa desc.fWidth = backendRT.width(); desc.fHeight = backendRT.height(); desc.fConfig = backendRT.config(); - desc.fSampleCnt = 0; + desc.fSampleCnt = 1; sk_sp<GrVkRenderTarget> tgt = GrVkRenderTarget::MakeWrappedRenderTarget(this, desc, info); if (tgt && backendRT.stencilBits()) { @@ -990,6 +990,9 @@ sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendTextureAsRenderTarget(const GrBacken desc.fHeight = tex.height(); desc.fConfig = tex.config(); desc.fSampleCnt = this->caps()->getSampleCount(sampleCnt, tex.config()); + if (!desc.fSampleCnt) { + return nullptr; + } sk_sp<GrVkRenderTarget> tgt = GrVkRenderTarget::MakeWrappedRenderTarget(this, desc, info); return tgt; @@ -1796,7 +1799,7 @@ inline bool can_copy_as_resolve(const GrSurface* dst, GrSurfaceOrigin dstOrigin, const GrSurface* src, GrSurfaceOrigin srcOrigin, const GrVkGpu* gpu) { // Our src must be a multisampled render target - if (!src->asRenderTarget() || src->asRenderTarget()->numColorSamples() <= 1) { + if (!src->asRenderTarget() || 1 == src->asRenderTarget()->numColorSamples()) { return false; } @@ -1894,7 +1897,7 @@ bool GrVkGpu::onGetReadPixelsInfo(GrSurface* srcSurface, GrSurfaceOrigin srcOrig tempDrawInfo->fTempSurfaceDesc.fFlags = kRenderTarget_GrSurfaceFlag; tempDrawInfo->fTempSurfaceDesc.fWidth = width; tempDrawInfo->fTempSurfaceDesc.fHeight = height; - tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0; + tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 1; tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; // no CPU y-flip for TL. tempDrawInfo->fTempSurfaceFit = SkBackingFit::kApprox; diff --git a/src/gpu/vk/GrVkRenderTarget.cpp b/src/gpu/vk/GrVkRenderTarget.cpp index c5a8628cc4..2a745ed51c 100644 --- a/src/gpu/vk/GrVkRenderTarget.cpp +++ b/src/gpu/vk/GrVkRenderTarget.cpp @@ -39,7 +39,7 @@ GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, , fResolveAttachmentView(resolveAttachmentView) , fFramebuffer(nullptr) , fCachedSimpleRenderPass(nullptr) { - SkASSERT(desc.fSampleCnt); + SkASSERT(desc.fSampleCnt > 1); this->createFramebuffer(gpu); this->registerWithCache(budgeted); } @@ -62,7 +62,7 @@ GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, , fResolveAttachmentView(resolveAttachmentView) , fFramebuffer(nullptr) , fCachedSimpleRenderPass(nullptr) { - SkASSERT(desc.fSampleCnt); + SkASSERT(desc.fSampleCnt > 1); this->createFramebuffer(gpu); } @@ -82,7 +82,7 @@ GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, , fResolveAttachmentView(nullptr) , fFramebuffer(nullptr) , fCachedSimpleRenderPass(nullptr) { - SkASSERT(!desc.fSampleCnt); + SkASSERT(1 == desc.fSampleCnt); this->createFramebuffer(gpu); this->registerWithCache(budgeted); } @@ -102,7 +102,7 @@ GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, , fResolveAttachmentView(nullptr) , fFramebuffer(nullptr) , fCachedSimpleRenderPass(nullptr) { - SkASSERT(!desc.fSampleCnt); + SkASSERT(1 == desc.fSampleCnt); this->createFramebuffer(gpu); } @@ -121,7 +121,7 @@ GrVkRenderTarget::Create(GrVkGpu* gpu, // create msaa surface if necessary GrVkImageInfo msInfo; const GrVkImageView* resolveAttachmentView = nullptr; - if (desc.fSampleCnt) { + if (desc.fSampleCnt > 1) { GrVkImage::ImageDesc msImageDesc; msImageDesc.fImageType = VK_IMAGE_TYPE_2D; msImageDesc.fFormat = pixelFormat; @@ -158,7 +158,7 @@ GrVkRenderTarget::Create(GrVkGpu* gpu, const GrVkImageView* colorAttachmentView = GrVkImageView::Create(gpu, colorImage, pixelFormat, GrVkImageView::kColor_Type, 1); if (!colorAttachmentView) { - if (desc.fSampleCnt) { + if (desc.fSampleCnt > 1) { resolveAttachmentView->unref(gpu); GrVkImage::DestroyImageInfo(gpu, &msInfo); } @@ -166,7 +166,7 @@ GrVkRenderTarget::Create(GrVkGpu* gpu, } GrVkRenderTarget* texRT; - if (desc.fSampleCnt) { + if (desc.fSampleCnt > 1) { texRT = new GrVkRenderTarget(gpu, budgeted, desc, info, msInfo, colorAttachmentView, resolveAttachmentView, ownership); } else { @@ -237,11 +237,10 @@ void GrVkRenderTarget::createFramebuffer(GrVkGpu* gpu) { void GrVkRenderTarget::getAttachmentsDescriptor( GrVkRenderPass::AttachmentsDescriptor* desc, GrVkRenderPass::AttachmentFlags* attachmentFlags) const { - int colorSamples = this->numColorSamples(); VkFormat colorFormat; GrPixelConfigToVkFormat(this->config(), &colorFormat); desc->fColor.fFormat = colorFormat; - desc->fColor.fSamples = colorSamples ? colorSamples : 1; + desc->fColor.fSamples = this->numColorSamples(); *attachmentFlags = GrVkRenderPass::kColor_AttachmentFlag; uint32_t attachmentCount = 1; @@ -249,7 +248,7 @@ void GrVkRenderTarget::getAttachmentsDescriptor( if (stencil) { const GrVkStencilAttachment* vkStencil = static_cast<const GrVkStencilAttachment*>(stencil); desc->fStencil.fFormat = vkStencil->vkFormat(); - desc->fStencil.fSamples = vkStencil->numSamples() ? vkStencil->numSamples() : 1; + desc->fStencil.fSamples = vkStencil->numSamples(); // Currently in vulkan stencil and color attachments must all have same number of samples SkASSERT(desc->fColor.fSamples == desc->fStencil.fSamples); *attachmentFlags |= GrVkRenderPass::kStencil_AttachmentFlag; diff --git a/src/gpu/vk/GrVkRenderTarget.h b/src/gpu/vk/GrVkRenderTarget.h index eb297a8a1d..bea90a759b 100644 --- a/src/gpu/vk/GrVkRenderTarget.h +++ b/src/gpu/vk/GrVkRenderTarget.h @@ -99,8 +99,11 @@ protected: // This accounts for the texture's memory and any MSAA renderbuffer's memory. size_t onGpuMemorySize() const override { - // The plus 1 is to account for the resolve texture or if not using msaa the RT itself - int numColorSamples = this->numColorSamples() + 1; + int numColorSamples = this->numColorSamples(); + if (numColorSamples > 1) { + // Add one to account for the resolved VkImage. + numColorSamples += 1; + } return GrSurface::ComputeSize(this->config(), this->width(), this->height(), numColorSamples, GrMipMapped::kNo); } diff --git a/src/gpu/vk/GrVkStencilAttachment.cpp b/src/gpu/vk/GrVkStencilAttachment.cpp index 5348885a6b..139c00f3b2 100644 --- a/src/gpu/vk/GrVkStencilAttachment.cpp +++ b/src/gpu/vk/GrVkStencilAttachment.cpp @@ -72,7 +72,7 @@ size_t GrVkStencilAttachment::onGpuMemorySize() const { uint64_t size = this->width(); size *= this->height(); size *= fFormat.fTotalBits; - size *= SkTMax(1,this->numSamples()); + size *= this->numSamples(); return static_cast<size_t>(size / 8); } diff --git a/src/gpu/vk/GrVkTextureRenderTarget.cpp b/src/gpu/vk/GrVkTextureRenderTarget.cpp index 9a211e208a..ee31f2364a 100644 --- a/src/gpu/vk/GrVkTextureRenderTarget.cpp +++ b/src/gpu/vk/GrVkTextureRenderTarget.cpp @@ -106,7 +106,7 @@ sk_sp<GrVkTextureRenderTarget> GrVkTextureRenderTarget::Make(GrVkGpu* gpu, // create msaa surface if necessary GrVkImageInfo msInfo; const GrVkImageView* resolveAttachmentView = nullptr; - if (desc.fSampleCnt) { + if (desc.fSampleCnt > 1) { GrVkImage::ImageDesc msImageDesc; msImageDesc.fImageType = VK_IMAGE_TYPE_2D; msImageDesc.fFormat = pixelFormat; @@ -145,7 +145,7 @@ sk_sp<GrVkTextureRenderTarget> GrVkTextureRenderTarget::Make(GrVkGpu* gpu, const GrVkImageView* colorAttachmentView = GrVkImageView::Create(gpu, colorImage, pixelFormat, GrVkImageView::kColor_Type, 1); if (!colorAttachmentView) { - if (desc.fSampleCnt) { + if (desc.fSampleCnt > 1) { resolveAttachmentView->unref(gpu); GrVkImage::DestroyImageInfo(gpu, &msInfo); } @@ -154,7 +154,7 @@ sk_sp<GrVkTextureRenderTarget> GrVkTextureRenderTarget::Make(GrVkGpu* gpu, } sk_sp<GrVkTextureRenderTarget> texRT; - if (desc.fSampleCnt) { + if (desc.fSampleCnt > 1) { if (!isWrapped) { texRT = sk_sp<GrVkTextureRenderTarget>(new GrVkTextureRenderTarget( gpu, budgeted, desc, @@ -232,7 +232,7 @@ GrVkTextureRenderTarget::MakeWrappedTextureRenderTarget(GrVkGpu* gpu, bool GrVkTextureRenderTarget::updateForMipmap(GrVkGpu* gpu, const GrVkImageInfo& newInfo) { VkFormat pixelFormat; GrPixelConfigToVkFormat(this->config(), &pixelFormat); - if (this->numStencilSamples()) { + if (this->numStencilSamples() > 1) { const GrVkImageView* resolveAttachmentView = GrVkImageView::Create(gpu, newInfo.fImage, @@ -262,8 +262,11 @@ bool GrVkTextureRenderTarget::updateForMipmap(GrVkGpu* gpu, const GrVkImageInfo& } size_t GrVkTextureRenderTarget::onGpuMemorySize() const { - // The plus 1 is to account for the resolve texture. - int numColorSamples = this->numColorSamples() + 1; + int numColorSamples = this->numColorSamples(); + if (numColorSamples > 1) { + // Add one to account for the resolve VkImage. + ++numColorSamples; + } return GrSurface::ComputeSize(this->config(), this->width(), this->height(), numColorSamples, // TODO: this still correct? this->texturePriv().mipMapped()); diff --git a/src/gpu/vk/GrVkUtil.cpp b/src/gpu/vk/GrVkUtil.cpp index cb0046e58c..12db4c111e 100644 --- a/src/gpu/vk/GrVkUtil.cpp +++ b/src/gpu/vk/GrVkUtil.cpp @@ -263,8 +263,8 @@ bool GrVkFormatIsSRGB(VkFormat format, VkFormat* linearFormat) { } bool GrSampleCountToVkSampleCount(uint32_t samples, VkSampleCountFlagBits* vkSamples) { + SkASSERT(samples >= 1); switch (samples) { - case 0: // fall through case 1: *vkSamples = VK_SAMPLE_COUNT_1_BIT; return true; |