aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2018-06-07 15:07:50 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-07 19:35:01 +0000
commitcd2c3f9055452d413d6be7ea6dc63fd1922fe994 (patch)
treef5040726b08c094f547a85b957814e561b5ba550 /src/gpu
parentc174cc675cbc190c43372d53fb89711663ac945f (diff)
Require mips to be allocated at texture creation time and disable late allocations.
If we get a non-mipped texture for a draw that wants to be use mip map filter, we will copy the texture into a new mipped texture. Clean up of unused code in the GPU backends for reallocating for mips will be done in a follow up CL. Bug: skia: Change-Id: Idab588c1abf4bbbf7eeceb3727d500e5df274188 Reviewed-on: https://skia-review.googlesource.com/132830 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrBackendTextureImageGenerator.cpp6
-rw-r--r--src/gpu/GrBitmapTextureMaker.cpp4
-rw-r--r--src/gpu/GrGpu.cpp15
-rw-r--r--src/gpu/GrSurfacePriv.h1
-rw-r--r--src/gpu/GrTexture.cpp8
-rw-r--r--src/gpu/GrTextureAdjuster.cpp15
-rw-r--r--src/gpu/GrTexturePriv.h4
-rw-r--r--src/gpu/GrTextureProducer.cpp27
-rw-r--r--src/gpu/GrTextureProxyPriv.h5
-rw-r--r--src/gpu/gl/GrGLCaps.cpp15
-rw-r--r--src/gpu/gl/GrGLCaps.h4
-rw-r--r--src/gpu/gl/GrGLGpu.cpp2
-rw-r--r--src/gpu/ops/GrTextureOp.cpp14
-rw-r--r--src/gpu/vk/GrVkGpuCommandBuffer.cpp1
14 files changed, 59 insertions, 62 deletions
diff --git a/src/gpu/GrBackendTextureImageGenerator.cpp b/src/gpu/GrBackendTextureImageGenerator.cpp
index 56826d2857..4147abd2a4 100644
--- a/src/gpu/GrBackendTextureImageGenerator.cpp
+++ b/src/gpu/GrBackendTextureImageGenerator.cpp
@@ -180,12 +180,6 @@ sk_sp<GrTextureProxy> GrBackendTextureImageGenerator::onGenerateTexture(
return nullptr;
}
- // We can't pass the fact that this creates a wrapped texture into createLazyProxy so we need
- // to manually call setDoesNotSupportMipMaps.
- if (GrMipMapped::kNo == mipMapped) {
- proxy->texPriv().setDoesNotSupportMipMaps();
- }
-
if (0 == origin.fX && 0 == origin.fY &&
info.width() == fBackendTexture.width() && info.height() == fBackendTexture.height() &&
(!willNeedMipMaps || GrMipMapped::kYes == proxy->mipMapped())) {
diff --git a/src/gpu/GrBitmapTextureMaker.cpp b/src/gpu/GrBitmapTextureMaker.cpp
index d2a1fbe3e9..4ecd761e37 100644
--- a/src/gpu/GrBitmapTextureMaker.cpp
+++ b/src/gpu/GrBitmapTextureMaker.cpp
@@ -89,10 +89,6 @@ sk_sp<GrTextureProxy> GrBitmapTextureMaker::refOriginalTextureProxy(bool willBeM
}
return mippedProxy;
}
- // We failed to make a mipped proxy with the base copied into it. This could have
- // been from failure to make the proxy or failure to do the copy. Thus we will fall
- // back to just using the non mipped proxy; See skbug.com/7094.
- return proxy;
}
return nullptr;
}
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 5c2864db3c..c72491b3c3 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -56,7 +56,7 @@ bool GrGpu::IsACopyNeededForTextureParams(const GrCaps* caps, GrTextureProxy* te
// those capabilities are required) force a copy.
if ((textureParams.isRepeated() && texProxy->texPriv().isClampOnly()) ||
(GrSamplerState::Filter::kMipMap == textureParams.filter() &&
- texProxy->texPriv().doesNotSupportMipMaps())) {
+ texProxy->mipMapped() == GrMipMapped::kNo)) {
copyParams->fFilter = GrSamplerState::Filter::kNearest;
copyParams->fWidth = texProxy->width();
copyParams->fHeight = texProxy->height();
@@ -138,13 +138,7 @@ sk_sp<GrTexture> GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex,
backendTex.height() > this->caps()->maxTextureSize()) {
return nullptr;
}
- sk_sp<GrTexture> tex = this->onWrapBackendTexture(backendTex, ownership);
- if (tex && !backendTex.hasMipMaps()) {
- // Ganesh will not ever allocate mipmaps for a wrapped resource. By setting this flag here,
- // it will be propagated to any proxy that wraps this texture.
- tex->texturePriv().setDoesNotSupportMipMaps();
- }
- return tex;
+ return this->onWrapBackendTexture(backendTex, ownership);
}
sk_sp<GrTexture> GrGpu::wrapRenderableBackendTexture(const GrBackendTexture& backendTex,
@@ -163,11 +157,6 @@ sk_sp<GrTexture> GrGpu::wrapRenderableBackendTexture(const GrBackendTexture& bac
return nullptr;
}
sk_sp<GrTexture> tex = this->onWrapRenderableBackendTexture(backendTex, sampleCnt, ownership);
- if (tex && !backendTex.hasMipMaps()) {
- // Ganesh will not ever allocate mipmaps for a wrapped resource. By setting this flag here,
- // it will be propagated to any proxy that wraps this texture.
- tex->texturePriv().setDoesNotSupportMipMaps();
- }
SkASSERT(!tex || tex->asRenderTarget());
return tex;
}
diff --git a/src/gpu/GrSurfacePriv.h b/src/gpu/GrSurfacePriv.h
index 5c98e3f773..45a097b780 100644
--- a/src/gpu/GrSurfacePriv.h
+++ b/src/gpu/GrSurfacePriv.h
@@ -40,7 +40,6 @@ public:
GrInternalSurfaceFlags flags() const { return fSurface->fSurfaceFlags; }
- bool doesNotSupportMipMaps() const { return fSurface->doesNotSupportMipMaps(); }
bool isGLTextureRectangleOrExternal() const {
return fSurface->isGLTextureRectangleOrExternal();
}
diff --git a/src/gpu/GrTexture.cpp b/src/gpu/GrTexture.cpp
index cd3e7055ab..0051a225ef 100644
--- a/src/gpu/GrTexture.cpp
+++ b/src/gpu/GrTexture.cpp
@@ -25,14 +25,8 @@ void GrTexture::markMipMapsDirty() {
}
void GrTexture::markMipMapsClean() {
- const bool sizeChanged = GrMipMapsStatus::kNotAllocated == fMipMapsStatus;
+ SkASSERT(GrMipMapsStatus::kNotAllocated != fMipMapsStatus);
fMipMapsStatus = GrMipMapsStatus::kValid;
- if (sizeChanged) {
- // This must not be called until after changing fMipMapsStatus.
- this->didChangeGpuMemorySize();
- // TODO(http://skbug.com/4548) - The desc and scratch key should be
- // updated to reflect the newly-allocated mipmaps.
- }
}
size_t GrTexture::onGpuMemorySize() const {
diff --git a/src/gpu/GrTextureAdjuster.cpp b/src/gpu/GrTextureAdjuster.cpp
index cc61533044..59dd7f5d59 100644
--- a/src/gpu/GrTextureAdjuster.cpp
+++ b/src/gpu/GrTextureAdjuster.cpp
@@ -43,10 +43,11 @@ sk_sp<GrTextureProxy> GrTextureAdjuster::refTextureProxyCopy(const CopyParams& c
GrUniqueKey key;
this->makeCopyKey(copyParams, &key, nullptr);
+ sk_sp<GrTextureProxy> cachedCopy;
if (key.isValid()) {
- sk_sp<GrTextureProxy> cachedCopy =
- proxyProvider->findOrCreateProxyByUniqueKey(key, this->originalProxy()->origin());
- if (cachedCopy) {
+ cachedCopy = proxyProvider->findOrCreateProxyByUniqueKey(key,
+ this->originalProxy()->origin());
+ if (cachedCopy && (!willBeMipped || GrMipMapped::kYes == cachedCopy->mipMapped())) {
return cachedCopy;
}
}
@@ -57,6 +58,14 @@ sk_sp<GrTextureProxy> GrTextureAdjuster::refTextureProxyCopy(const CopyParams& c
if (copy) {
if (key.isValid()) {
SkASSERT(copy->origin() == this->originalProxy()->origin());
+ if (cachedCopy) {
+ SkASSERT(GrMipMapped::kYes == copy->mipMapped() &&
+ GrMipMapped::kNo == cachedCopy->mipMapped());
+ // If we had a cachedProxy, that means there already is a proxy in the cache which
+ // matches the key, but it does not have mip levels and we require them. Thus we
+ // must remove the unique key from that proxy.
+ proxyProvider->removeUniqueKeyFromProxy(key, cachedCopy.get());
+ }
proxyProvider->assignUniqueKeyToProxy(key, copy.get());
this->didCacheCopy(key);
}
diff --git a/src/gpu/GrTexturePriv.h b/src/gpu/GrTexturePriv.h
index 4517e9e076..2979e8bd94 100644
--- a/src/gpu/GrTexturePriv.h
+++ b/src/gpu/GrTexturePriv.h
@@ -44,10 +44,6 @@ public:
return fTexture->fMaxMipMapLevel;
}
- void setDoesNotSupportMipMaps() {
- fTexture->setDoesNotSupportMipMaps();
- }
-
GrSLType samplerType() const { return fTexture->fSamplerType; }
/** The filter used is clamped to this value in GrProcessor::TextureSampler. */
diff --git a/src/gpu/GrTextureProducer.cpp b/src/gpu/GrTextureProducer.cpp
index d9fffbc410..1e9c3acd16 100644
--- a/src/gpu/GrTextureProducer.cpp
+++ b/src/gpu/GrTextureProducer.cpp
@@ -10,6 +10,7 @@
#include "GrProxyProvider.h"
#include "GrRenderTargetContext.h"
#include "GrTextureProxy.h"
+#include "SkGr.h"
#include "SkRectPriv.h"
#include "effects/GrBicubicEffect.h"
#include "effects/GrSimpleTextureEffect.h"
@@ -24,6 +25,24 @@ sk_sp<GrTextureProxy> GrTextureProducer::CopyOnGpu(GrContext* context,
const SkRect dstRect = SkRect::MakeIWH(copyParams.fWidth, copyParams.fHeight);
GrMipMapped mipMapped = dstWillRequireMipMaps ? GrMipMapped::kYes : GrMipMapped::kNo;
+ SkRect localRect = SkRect::MakeWH(inputProxy->width(), inputProxy->height());
+
+ bool needsDomain = false;
+ bool resizing = false;
+ if (copyParams.fFilter != GrSamplerState::Filter::kNearest) {
+ bool resizing = localRect.width() != dstRect.width() ||
+ localRect.height() != dstRect.height();
+ needsDomain = resizing && !GrProxyProvider::IsFunctionallyExact(inputProxy.get());
+ }
+
+ if (copyParams.fFilter == GrSamplerState::Filter::kNearest && !needsDomain && !resizing &&
+ dstWillRequireMipMaps) {
+ sk_sp<GrTextureProxy> proxy = GrCopyBaseMipMapToTextureProxy(context, inputProxy.get());
+ if (proxy) {
+ return proxy;
+ }
+ }
+
sk_sp<GrRenderTargetContext> copyRTC =
context->contextPriv().makeDeferredRenderTargetContextWithFallback(
SkBackingFit::kExact, dstRect.width(), dstRect.height(), inputProxy->config(),
@@ -33,14 +52,6 @@ sk_sp<GrTextureProxy> GrTextureProducer::CopyOnGpu(GrContext* context,
}
GrPaint paint;
- SkRect localRect = SkRect::MakeWH(inputProxy->width(), inputProxy->height());
-
- bool needsDomain = false;
- if (copyParams.fFilter != GrSamplerState::Filter::kNearest) {
- bool resizing = localRect.width() != dstRect.width() ||
- localRect.height() != dstRect.height();
- needsDomain = resizing && !GrProxyProvider::IsFunctionallyExact(inputProxy.get());
- }
if (needsDomain) {
const SkRect domain = localRect.makeInset(0.5f, 0.5f);
diff --git a/src/gpu/GrTextureProxyPriv.h b/src/gpu/GrTextureProxyPriv.h
index cadd2fde63..358369d516 100644
--- a/src/gpu/GrTextureProxyPriv.h
+++ b/src/gpu/GrTextureProxyPriv.h
@@ -31,7 +31,6 @@ public:
// been instantiated or not.
GrMipMapped proxyMipMapped() const { return fTextureProxy->fMipMapped; }
- bool doesNotSupportMipMaps() const { return fTextureProxy->doesNotSupportMipMaps(); }
bool isGLTextureRectangleOrExternal() const {
return fTextureProxy->isGLTextureRectangleOrExternal();
}
@@ -41,10 +40,6 @@ public:
// We only support the clamp wrap mode with gl rectangle or external textures.
bool isClampOnly() const { return fTextureProxy->isGLTextureRectangleOrExternal(); }
- void setDoesNotSupportMipMaps() {
- fTextureProxy->setDoesNotSupportMipMaps();
- }
-
private:
explicit GrTextureProxyPriv(GrTextureProxy* textureProxy) : fTextureProxy(textureProxy) {}
GrTextureProxyPriv(const GrTextureProxyPriv&) {} // unimpl
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index e20d0137e9..45eda9d2aa 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -1338,12 +1338,15 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
bool disableR8TexStorageForANGLEGL = false;
bool disableSRGBRenderWithMSAAForMacAMD = false;
bool disableRGB8ForMali400 = false;
+ bool disableGrayLumFBOForMesa = false;
if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
// ARB_texture_rg is part of OpenGL 3.0, but osmesa doesn't support GL_RED
// and GL_RG on FBO textures.
disableTextureRedForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
+ disableGrayLumFBOForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
+
bool isX86PowerVR = false;
#if defined(SK_CPU_X86)
if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
@@ -1742,17 +1745,15 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
grayRedInfo.fSwizzle = GrSwizzle::RRRA();
grayRedInfo.fFlags = ConfigInfo::kTextureable_Flag;
-#if 0 // Leaving Gray8 as non-renderable, to keep things simple and match raster. Needs to be
- // updated to support Gray8_as_Lum and Gray8_as_red if this is ever enabled.
- if (this->textureRedSupport() ||
- (kDesktop_ARB_MSFBOType == this->msFBOType() &&
- ctxInfo.renderer() != kOSMesa_GrGLRenderer)) {
+ // Leaving Gray8 as non-renderable, to keep things simple and match raster. However, we do
+ // enable the FBOColorAttachment_Flag so that we can bind it to an FBO for copies.
+ grayRedInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
+ if (kStandard_MSFBOType == this->msFBOType() && !disableGrayLumFBOForMesa) {
// desktop ARB extension/3.0+ supports LUMINANCE8 as renderable.
// However, osmesa fails if it used even when GL_ARB_framebuffer_object is present.
// Core profile removes LUMINANCE8 support, but we should have chosen R8 in that case.
- fConfigTable[kGray_8_GrPixelConfig].fFlags |= allRenderFlags;
+ grayLumInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
}
-#endif
if (texStorageSupported && !isCommandBufferES2) {
if (!disableR8TexStorageForANGLEGL) {
grayLumInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index e258eaa57d..1596dfd9de 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -123,8 +123,8 @@ public:
// In GL we have three ways to be able to copy. CopyTexImage, blit, and draw. CopyTexImage
// requires the src to be an FBO attachment, blit requires both src and dst to be FBO
// attachments, and draw requires the dst to be an FBO attachment. Thus to copy from and to
- // the same config, we need that config to be renderable so we can attach it to an FBO.
- return this->isConfigRenderable(config, false);
+ // the same config, we need that config to be bindable to an FBO.
+ return this->canConfigBeFBOColorAttachment(config);
}
bool canConfigBeFBOColorAttachment(GrPixelConfig config) const {
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index b0b55e51f8..214bb70ae7 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -2854,6 +2854,8 @@ void GrGLGpu::generateMipmaps(const GrSamplerState& params, GrGLTexture* texture
return;
}
+ SkASSERT(texture->texturePriv().mipMapped() == GrMipMapped::kYes);
+
// If the mips aren't dirty, we're done:
if (!texture->texturePriv().mipMapsAreDirty()) {
return;
diff --git a/src/gpu/ops/GrTextureOp.cpp b/src/gpu/ops/GrTextureOp.cpp
index 950fe6e26b..22c24f012e 100644
--- a/src/gpu/ops/GrTextureOp.cpp
+++ b/src/gpu/ops/GrTextureOp.cpp
@@ -1052,10 +1052,16 @@ GR_DRAW_OP_TEST_DEFINE(TextureOp) {
desc.fHeight = random->nextULessThan(90) + 10;
desc.fWidth = random->nextULessThan(90) + 10;
auto origin = random->nextBool() ? kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin;
- SkBackingFit fit = random->nextBool() ? SkBackingFit::kApprox : SkBackingFit::kExact;
+ GrMipMapped mipMapped = random->nextBool() ? GrMipMapped::kYes : GrMipMapped::kNo;
+ SkBackingFit fit = SkBackingFit::kExact;
+ if (mipMapped == GrMipMapped::kNo) {
+ fit = random->nextBool() ? SkBackingFit::kApprox : SkBackingFit::kExact;
+ }
GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
- sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(desc, origin, fit, SkBudgeted::kNo);
+ sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(desc, origin, mipMapped, fit,
+ SkBudgeted::kNo,
+ GrInternalSurfaceFlags::kNone);
SkRect rect = GrTest::TestRect(random);
SkRect srcRect;
@@ -1067,6 +1073,10 @@ GR_DRAW_OP_TEST_DEFINE(TextureOp) {
GrColor color = SkColorToPremulGrColor(random->nextU());
GrSamplerState::Filter filter = (GrSamplerState::Filter)random->nextULessThan(
static_cast<uint32_t>(GrSamplerState::Filter::kMipMap) + 1);
+ while (mipMapped == GrMipMapped::kNo && filter == GrSamplerState::Filter::kMipMap) {
+ filter = (GrSamplerState::Filter)random->nextULessThan(
+ static_cast<uint32_t>(GrSamplerState::Filter::kMipMap) + 1);
+ }
auto csxf = GrTest::TestColorXform(random);
GrAAType aaType = GrAAType::kNone;
if (random->nextBool()) {
diff --git a/src/gpu/vk/GrVkGpuCommandBuffer.cpp b/src/gpu/vk/GrVkGpuCommandBuffer.cpp
index 5493dd9890..552e7bc801 100644
--- a/src/gpu/vk/GrVkGpuCommandBuffer.cpp
+++ b/src/gpu/vk/GrVkGpuCommandBuffer.cpp
@@ -621,6 +621,7 @@ static void prepare_sampled_images(const GrResourceIOProcessor& processor,
// Check if we need to regenerate any mip maps
if (GrSamplerState::Filter::kMipMap == sampler.samplerState().filter()) {
+ SkASSERT(vkTexture->texturePriv().mipMapped() == GrMipMapped::kYes);
if (vkTexture->texturePriv().mipMapsAreDirty()) {
gpu->generateMipmap(vkTexture, sampler.proxy()->origin());
vkTexture->texturePriv().markMipMapsClean();