diff options
Diffstat (limited to 'src/gpu/vk')
-rw-r--r-- | src/gpu/vk/GrVkCaps.cpp | 24 | ||||
-rw-r--r-- | src/gpu/vk/GrVkCaps.h | 9 | ||||
-rw-r--r-- | src/gpu/vk/GrVkGpu.cpp | 33 | ||||
-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, 61 insertions, 50 deletions
diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp index 0ae7c00995..8af81190af 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,34 @@ void GrVkCaps::ConfigInfo::init(const GrVkInterface* interface, } } -int GrVkCaps::getSampleCount(int requestedCount, GrPixelConfig config) const { +int GrVkCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const { + requestedCount = SkTMax(1, requestedCount); int count = fConfigTable[config].fColorSampleCounts.count(); - if (!count || !this->isConfigRenderable(config, true)) { + + if (!count) { 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; +} + +int GrVkCaps::maxRenderTargetSampleCount(GrPixelConfig config) const { + const auto& table = fConfigTable[config].fColorSampleCounts; + if (!table.count()) { + return 0; + } + return table[table.count() - 1]; } 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..3449dd2ccc 100644 --- a/src/gpu/vk/GrVkCaps.h +++ b/src/gpu/vk/GrVkCaps.h @@ -29,20 +29,17 @@ public: GrVkCaps(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface, VkPhysicalDevice device, uint32_t featureFlags, uint32_t extensionFlags); - int getSampleCount(int requestedCount, GrPixelConfig config) const override; - bool isConfigTexturable(GrPixelConfig config) const override { 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 isConfigCopyable(GrPixelConfig config) const override { return true; } + int getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const override; + int maxRenderTargetSampleCount(GrPixelConfig config) const override; + bool isConfigTexturableLinearly(GrPixelConfig config) const { return SkToBool(ConfigInfo::kTextureable_Flag & fConfigTable[config].fLinearFlags); } diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index f7e3d47dd9..362ac1fa2b 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) { @@ -777,17 +777,7 @@ sk_sp<GrTexture> GrVkGpu::onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); VkFormat pixelFormat; - if (!GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat)) { - return nullptr; - } - - if (!fVkCaps->isConfigTexturable(desc.fConfig)) { - return nullptr; - } - - if (renderTarget && !fVkCaps->isConfigRenderable(desc.fConfig, false)) { - return nullptr; - } + SkAssertResult(GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat)); VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_SAMPLED_BIT; if (renderTarget) { @@ -914,7 +904,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()); } @@ -932,7 +922,7 @@ sk_sp<GrTexture> GrVkGpu::onWrapRenderableBackendTexture(const GrBackendTexture& surfDesc.fWidth = backendTex.width(); surfDesc.fHeight = backendTex.height(); surfDesc.fConfig = backendTex.config(); - surfDesc.fSampleCnt = this->caps()->getSampleCount(sampleCnt, backendTex.config()); + surfDesc.fSampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, backendTex.config()); return GrVkTextureRenderTarget::MakeWrappedTextureRenderTarget(this, surfDesc, ownership, backendTex.getVkImageInfo()); @@ -943,7 +933,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 +951,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()) { @@ -989,7 +979,10 @@ sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendTextureAsRenderTarget(const GrBacken desc.fWidth = tex.width(); desc.fHeight = tex.height(); desc.fConfig = tex.config(); - desc.fSampleCnt = this->caps()->getSampleCount(sampleCnt, tex.config()); + desc.fSampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, tex.config()); + if (!desc.fSampleCnt) { + return nullptr; + } sk_sp<GrVkRenderTarget> tgt = GrVkRenderTarget::MakeWrappedRenderTarget(this, desc, info); return tgt; @@ -1188,7 +1181,7 @@ GrBackendTexture GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w, return GrBackendTexture(); // invalid } - if (isRenderTarget && !fVkCaps->isConfigRenderable(config, false)) { + if (isRenderTarget && !fVkCaps->isConfigRenderable(config)) { return GrBackendTexture(); // invalid } @@ -1796,7 +1789,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 +1887,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..02d4add455 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; |