aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2016-11-07 08:23:48 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-11-07 14:34:47 +0000
commitd6214d4f4664ce47861dc690b0ddbea3b7a07855 (patch)
treebf32d321ac4395222b9ce5e878618757513cb217 /src
parent44b36a210462dbc8c62bf705d002dbba591c8e7f (diff)
Further centralize computation of GrSurface VRAM consumption - take 2
This is the same as https://skia-review.googlesource.com/c/4383/ (Further centralize computation of GrSurface VRAM consumption) but with a suppression for Vulkan in the new test and removal of an assert Chromium was triggering. GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4450 Change-Id: Ie87d32fd5f0d35c21326b066a0c733cb6f8a5bea Reviewed-on: https://skia-review.googlesource.com/4450 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrRenderTarget.cpp11
-rw-r--r--src/gpu/GrRenderTargetProxy.cpp2
-rw-r--r--src/gpu/GrSurface.cpp37
-rw-r--r--src/gpu/GrTexture.cpp23
-rw-r--r--src/gpu/GrTextureProxy.cpp2
-rw-r--r--src/gpu/gl/GrGLGpu.cpp12
-rw-r--r--src/gpu/gl/GrGLRenderTarget.cpp4
-rw-r--r--src/gpu/gl/GrGLRenderTarget.h5
-rw-r--r--src/gpu/gl/GrGLTexture.cpp5
-rw-r--r--src/gpu/gl/GrGLTexture.h2
-rw-r--r--src/gpu/gl/GrGLTextureRenderTarget.cpp2
-rw-r--r--src/gpu/gl/GrGLTextureRenderTarget.h16
-rw-r--r--src/gpu/vk/GrVkRenderTarget.h3
-rw-r--r--src/gpu/vk/GrVkTextureRenderTarget.h6
14 files changed, 70 insertions, 60 deletions
diff --git a/src/gpu/GrRenderTarget.cpp b/src/gpu/GrRenderTarget.cpp
index 2828866435..f15e3b01bf 100644
--- a/src/gpu/GrRenderTarget.cpp
+++ b/src/gpu/GrRenderTarget.cpp
@@ -84,17 +84,6 @@ void GrRenderTarget::onAbandon() {
INHERITED::onAbandon();
}
-size_t GrRenderTarget::ComputeSize(const GrSurfaceDesc& desc, int colorValuesPerPixel) {
- SkASSERT(kUnknown_GrPixelConfig != desc.fConfig);
- SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig));
- size_t colorBytes = GrBytesPerPixel(desc.fConfig);
- SkASSERT(colorBytes > 0);
-
- size_t rtSize = colorValuesPerPixel * desc.fWidth * desc.fHeight * colorBytes;
- SkASSERT(rtSize <= WorstCaseSize(desc));
- return rtSize;
-}
-
///////////////////////////////////////////////////////////////////////////////
bool GrRenderTargetPriv::attachStencilAttachment(GrStencilAttachment* stencil) {
diff --git a/src/gpu/GrRenderTargetProxy.cpp b/src/gpu/GrRenderTargetProxy.cpp
index ac8f5edb76..eb750847d2 100644
--- a/src/gpu/GrRenderTargetProxy.cpp
+++ b/src/gpu/GrRenderTargetProxy.cpp
@@ -82,7 +82,7 @@ size_t GrRenderTargetProxy::onGpuMemorySize() const {
}
// TODO: do we have enough information to improve this worst case estimate?
- return GrRenderTarget::ComputeSize(fDesc, fDesc.fSampleCnt+1);
+ return GrSurface::ComputeSize(fDesc, fDesc.fSampleCnt+1, false);
}
sk_sp<GrRenderTargetProxy> GrRenderTargetProxy::Make(const GrCaps& caps,
diff --git a/src/gpu/GrSurface.cpp b/src/gpu/GrSurface.cpp
index 9fe00ded5d..f2318793d2 100644
--- a/src/gpu/GrSurface.cpp
+++ b/src/gpu/GrSurface.cpp
@@ -38,15 +38,19 @@ size_t GrSurface::WorstCaseSize(const GrSurfaceDesc& desc) {
}
SkASSERT(kUnknown_GrPixelConfig != desc.fConfig);
SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig));
- size_t colorBytes = GrBytesPerPixel(desc.fConfig);
- SkASSERT(colorBytes > 0);
+ size_t colorBytes = desc.fWidth * desc.fHeight * GrBytesPerPixel(desc.fConfig);
- size = (size_t) colorValuesPerPixel * desc.fWidth * desc.fHeight * colorBytes;
+ // This would be a nice assert to have (i.e., we aren't creating 0 width/height surfaces).
+ // Unfortunately Chromium seems to want to do this.
+ //SkASSERT(colorBytes > 0);
+
+ size = colorValuesPerPixel * colorBytes;
+ size += colorBytes/3; // in case we have to mipmap
} else {
if (GrPixelConfigIsCompressed(desc.fConfig)) {
size = GrCompressedFormatDataSize(desc.fConfig, desc.fWidth, desc.fHeight);
} else {
- size = (size_t) desc.fWidth * desc.fHeight * GrBytesPerPixel(desc.fConfig);
+ size = desc.fWidth * desc.fHeight * GrBytesPerPixel(desc.fConfig);
}
size += size/3; // in case we have to mipmap
@@ -55,6 +59,31 @@ size_t GrSurface::WorstCaseSize(const GrSurfaceDesc& desc) {
return size;
}
+size_t GrSurface::ComputeSize(const GrSurfaceDesc& desc,
+ int colorSamplesPerPixel,
+ bool hasMIPMaps) {
+ size_t colorSize;
+
+ SkASSERT(kUnknown_GrPixelConfig != desc.fConfig);
+ if (GrPixelConfigIsCompressed(desc.fConfig)) {
+ colorSize = GrCompressedFormatDataSize(desc.fConfig, desc.fWidth, desc.fHeight);
+ } else {
+ colorSize = desc.fWidth * desc.fHeight * GrBytesPerPixel(desc.fConfig);
+ }
+ SkASSERT(colorSize > 0);
+
+ size_t finalSize = colorSamplesPerPixel * colorSize;
+
+ if (hasMIPMaps) {
+ // We don't have to worry about the mipmaps being a different size than
+ // we'd expect because we never change fDesc.fWidth/fHeight.
+ finalSize += colorSize/3;
+ }
+
+ SkASSERT(finalSize <= WorstCaseSize(desc));
+ return finalSize;
+}
+
template<typename T> static bool adjust_params(int surfaceWidth,
int surfaceHeight,
size_t bpp,
diff --git a/src/gpu/GrTexture.cpp b/src/gpu/GrTexture.cpp
index 91036bc156..de1135a1eb 100644
--- a/src/gpu/GrTexture.cpp
+++ b/src/gpu/GrTexture.cpp
@@ -35,29 +35,8 @@ void GrTexture::dirtyMipMaps(bool mipMapsDirty) {
}
}
-size_t GrTexture::ComputeSize(const GrSurfaceDesc& desc, bool hasMipMaps) {
- size_t textureSize;
-
- if (GrPixelConfigIsCompressed(desc.fConfig)) {
- textureSize = GrCompressedFormatDataSize(desc.fConfig, desc.fWidth, desc.fHeight);
- } else {
- textureSize = (size_t) desc.fWidth * desc.fHeight * GrBytesPerPixel(desc.fConfig);
- }
-
- if (hasMipMaps) {
- // We don't have to worry about the mipmaps being a different size than
- // we'd expect because we never change fDesc.fWidth/fHeight.
- textureSize += textureSize/3;
- }
-
- SkASSERT(!SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag));
- SkASSERT(textureSize <= WorstCaseSize(desc));
-
- return textureSize;
-}
-
size_t GrTexture::onGpuMemorySize() const {
- return ComputeSize(fDesc, this->texturePriv().hasMipMaps());
+ return GrSurface::ComputeSize(fDesc, 1, this->texturePriv().hasMipMaps());
}
void GrTexture::validateDesc() const {
diff --git a/src/gpu/GrTextureProxy.cpp b/src/gpu/GrTextureProxy.cpp
index d60bf90ba4..0a7f767fa7 100644
--- a/src/gpu/GrTextureProxy.cpp
+++ b/src/gpu/GrTextureProxy.cpp
@@ -46,7 +46,7 @@ size_t GrTextureProxy::onGpuMemorySize() const {
static const bool kHasMipMaps = true;
// TODO: add tracking of mipmap state to improve the estimate
- return GrTexture::ComputeSize(fDesc, kHasMipMaps);
+ return GrSurface::ComputeSize(fDesc, 1, kHasMipMaps);
}
sk_sp<GrTextureProxy> GrTextureProxy::Make(GrTextureProvider* texProvider,
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index d8f383a196..9af3acc474 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -1642,6 +1642,11 @@ GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc,
return return_null_texture();
}
+ bool wasMipMapDataProvided = false;
+ if (texels.count() > 1) {
+ wasMipMapDataProvided = true;
+ }
+
GrGLTexture* tex;
if (renderTarget) {
// unbind the texture from the texture unit before binding it to the frame buffer
@@ -1652,12 +1657,9 @@ GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc,
GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID));
return return_null_texture();
}
- tex = new GrGLTextureRenderTarget(this, budgeted, desc, idDesc, rtIDDesc);
+ tex = new GrGLTextureRenderTarget(this, budgeted, desc, idDesc, rtIDDesc,
+ wasMipMapDataProvided);
} else {
- bool wasMipMapDataProvided = false;
- if (texels.count() > 1) {
- wasMipMapDataProvided = true;
- }
tex = new GrGLTexture(this, budgeted, desc, idDesc, wasMipMapDataProvided);
}
tex->setCachedTexParams(initialTexParams, this->getResetTimestamp());
diff --git a/src/gpu/gl/GrGLRenderTarget.cpp b/src/gpu/gl/GrGLRenderTarget.cpp
index 2f92e0a82d..5af5e67676 100644
--- a/src/gpu/gl/GrGLRenderTarget.cpp
+++ b/src/gpu/gl/GrGLRenderTarget.cpp
@@ -82,7 +82,7 @@ sk_sp<GrGLRenderTarget> GrGLRenderTarget::MakeWrapped(GrGLGpu* gpu,
}
size_t GrGLRenderTarget::onGpuMemorySize() const {
- return GrRenderTarget::ComputeSize(fDesc, fNumSamplesOwnedPerPixel);
+ return GrSurface::ComputeSize(fDesc, fNumSamplesOwnedPerPixel, false);
}
bool GrGLRenderTarget::completeStencilAttachment() {
@@ -183,7 +183,7 @@ void GrGLRenderTarget::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump)
// Log any renderbuffer's contribution to memory. We only do this if we own the renderbuffer
// (have a fMSColorRenderbufferID).
if (fMSColorRenderbufferID) {
- size_t size = GrRenderTarget::ComputeSize(fDesc, this->msaaSamples());
+ size_t size = GrSurface::ComputeSize(fDesc, this->msaaSamples(), false);
// Due to this resource having both a texture and a renderbuffer component, dump as
// skia/gpu_resources/resource_#/renderbuffer
diff --git a/src/gpu/gl/GrGLRenderTarget.h b/src/gpu/gl/GrGLRenderTarget.h
index fc18e30437..11b23473cf 100644
--- a/src/gpu/gl/GrGLRenderTarget.h
+++ b/src/gpu/gl/GrGLRenderTarget.h
@@ -77,8 +77,7 @@ protected:
void onAbandon() override;
void onRelease() override;
- // In protected because subclass GrGLTextureRenderTarget calls this version.
- size_t onGpuMemorySize() const override;
+ int numSamplesOwnedPerPixel() const { return fNumSamplesOwnedPerPixel; }
private:
// Constructor for instances wrapping backend objects.
@@ -89,6 +88,8 @@ private:
GrGLGpu* getGLGpu() const;
bool completeStencilAttachment() override;
+ size_t onGpuMemorySize() const override;
+
int msaaSamples() const;
// The number total number of samples, including both MSAA and resolve texture samples.
int totalSamples() const;
diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp
index 4653c5bce7..ec0ad3b7f3 100644
--- a/src/gpu/gl/GrGLTexture.cpp
+++ b/src/gpu/gl/GrGLTexture.cpp
@@ -50,9 +50,10 @@ GrGLTexture::GrGLTexture(GrGLGpu* gpu, Wrapped, const GrSurfaceDesc& desc, const
this->registerWithCacheWrapped();
}
-GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc)
+GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc,
+ bool wasMipMapDataProvided)
: GrSurface(gpu, desc)
- , INHERITED(gpu, desc, sampler_type(idDesc, gpu), false) {
+ , INHERITED(gpu, desc, sampler_type(idDesc, gpu), wasMipMapDataProvided) {
this->init(desc, idDesc);
}
diff --git a/src/gpu/gl/GrGLTexture.h b/src/gpu/gl/GrGLTexture.h
index ee027d790d..029fd87a1a 100644
--- a/src/gpu/gl/GrGLTexture.h
+++ b/src/gpu/gl/GrGLTexture.h
@@ -59,7 +59,7 @@ public:
static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
protected:
// Constructor for subclasses.
- GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
+ GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, bool wasMipMapDataProvided);
enum Wrapped { kWrapped };
// Constructor for instances wrapping backend objects.
diff --git a/src/gpu/gl/GrGLTextureRenderTarget.cpp b/src/gpu/gl/GrGLTextureRenderTarget.cpp
index 9b37fbb343..9c350f89ae 100644
--- a/src/gpu/gl/GrGLTextureRenderTarget.cpp
+++ b/src/gpu/gl/GrGLTextureRenderTarget.cpp
@@ -49,5 +49,5 @@ sk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped(
const GrGLTexture::IDDesc& texIDDesc, const GrGLRenderTarget::IDDesc& rtIDDesc)
{
return sk_sp<GrGLTextureRenderTarget>(
- new GrGLTextureRenderTarget(gpu, desc, texIDDesc, rtIDDesc));
+ new GrGLTextureRenderTarget(gpu, desc, texIDDesc, rtIDDesc, false));
}
diff --git a/src/gpu/gl/GrGLTextureRenderTarget.h b/src/gpu/gl/GrGLTextureRenderTarget.h
index c5c020fef6..7ff8d490e0 100644
--- a/src/gpu/gl/GrGLTextureRenderTarget.h
+++ b/src/gpu/gl/GrGLTextureRenderTarget.h
@@ -12,6 +12,7 @@
#include "GrGLGpu.h"
#include "GrGLTexture.h"
#include "GrGLRenderTarget.h"
+#include "GrTexturePriv.h"
class GrGLGpu;
@@ -29,9 +30,10 @@ public:
SkBudgeted budgeted,
const GrSurfaceDesc& desc,
const GrGLTexture::IDDesc& texIDDesc,
- const GrGLRenderTarget::IDDesc& rtIDDesc)
+ const GrGLRenderTarget::IDDesc& rtIDDesc,
+ bool wasMipMapDataProvided)
: GrSurface(gpu, desc)
- , GrGLTexture(gpu, desc, texIDDesc)
+ , GrGLTexture(gpu, desc, texIDDesc, wasMipMapDataProvided)
, GrGLRenderTarget(gpu, desc, rtIDDesc) {
this->registerWithCache(budgeted);
}
@@ -59,16 +61,18 @@ private:
GrGLTextureRenderTarget(GrGLGpu* gpu,
const GrSurfaceDesc& desc,
const GrGLTexture::IDDesc& texIDDesc,
- const GrGLRenderTarget::IDDesc& rtIDDesc)
+ const GrGLRenderTarget::IDDesc& rtIDDesc,
+ bool wasMipMapDataProvided)
: GrSurface(gpu, desc)
- , GrGLTexture(gpu, desc, texIDDesc)
+ , GrGLTexture(gpu, desc, texIDDesc, wasMipMapDataProvided)
, GrGLRenderTarget(gpu, desc, rtIDDesc) {
this->registerWithCacheWrapped();
}
- // GrGLRenderTarget accounts for the texture's memory and any MSAA renderbuffer's memory.
size_t onGpuMemorySize() const override {
- return GrGLRenderTarget::onGpuMemorySize();
+ return GrSurface::ComputeSize(fDesc,
+ this->numSamplesOwnedPerPixel(),
+ this->texturePriv().hasMipMaps());
}
};
diff --git a/src/gpu/vk/GrVkRenderTarget.h b/src/gpu/vk/GrVkRenderTarget.h
index 2e2f60a5fd..3e5c5eab17 100644
--- a/src/gpu/vk/GrVkRenderTarget.h
+++ b/src/gpu/vk/GrVkRenderTarget.h
@@ -100,7 +100,8 @@ 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.
- return GrRenderTarget::ComputeSize(fDesc, fDesc.fSampleCnt+1); // TODO: this still correct?
+ // TODO: is this still correct?
+ return GrSurface::ComputeSize(fDesc, fDesc.fSampleCnt+1, false);
}
void createFramebuffer(GrVkGpu* gpu);
diff --git a/src/gpu/vk/GrVkTextureRenderTarget.h b/src/gpu/vk/GrVkTextureRenderTarget.h
index daa168758d..2877a36265 100644
--- a/src/gpu/vk/GrVkTextureRenderTarget.h
+++ b/src/gpu/vk/GrVkTextureRenderTarget.h
@@ -13,6 +13,8 @@
#include "GrVkRenderTarget.h"
#include "GrVkGpu.h"
+#include "GrTexturePriv.h"
+
#ifdef SK_BUILD_FOR_WIN
// Windows gives bogus warnings about inheriting asTexture/asRenderTarget via dominance.
#pragma warning(push)
@@ -112,7 +114,9 @@ private:
// GrGLRenderTarget accounts for the texture's memory and any MSAA renderbuffer's memory.
size_t onGpuMemorySize() const override {
- return GrVkRenderTarget::onGpuMemorySize();
+ // The plus 1 is to account for the resolve texture.
+ return GrSurface::ComputeSize(fDesc, fDesc.fSampleCnt+1, // TODO: this still correct?
+ this->texturePriv().hasMipMaps());
}
};