Remove uses of GrPixelConfig version of GrBytesPerPixel.
Bug: skia:6718 Change-Id: I8421f38644567973f0b8de29b745ca9a471583bf Reviewed-on: https://skia-review.googlesource.com/c/skia/+/247598 Commit-Queue: Greg Daniel <egdaniel@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
66ae304f50
commit
7fd7a8aef0
@ -364,9 +364,6 @@ public:
|
||||
|
||||
void storeVkPipelineCacheData();
|
||||
|
||||
static size_t ComputeTextureSize(SkColorType type, int width, int height, GrMipMapped,
|
||||
bool useNextPow2 = false);
|
||||
|
||||
// Returns the gpu memory size of the the texture that backs the passed in SkImage. Returns 0 if
|
||||
// the SkImage is not texture backed.
|
||||
static size_t ComputeImageSize(sk_sp<SkImage> image, GrMipMapped, bool useNextPow2 = false);
|
||||
|
@ -75,7 +75,8 @@ public:
|
||||
inline GrSurfacePriv surfacePriv();
|
||||
inline const GrSurfacePriv surfacePriv() const;
|
||||
|
||||
static size_t ComputeSize(GrPixelConfig config, int width, int height, int colorSamplesPerPixel,
|
||||
static size_t ComputeSize(GrPixelConfig config, const GrCaps&, const GrBackendFormat&,
|
||||
int width, int height, int colorSamplesPerPixel,
|
||||
GrMipMapped, bool binSize = false);
|
||||
|
||||
/**
|
||||
|
@ -813,43 +813,6 @@ static constexpr GrPixelConfig GrCompressionTypePixelConfig(SkImage::Compression
|
||||
SkUNREACHABLE;
|
||||
}
|
||||
|
||||
static constexpr size_t GrBytesPerPixel(GrPixelConfig config) {
|
||||
switch (config) {
|
||||
case kAlpha_8_GrPixelConfig:
|
||||
case kAlpha_8_as_Alpha_GrPixelConfig:
|
||||
case kAlpha_8_as_Red_GrPixelConfig:
|
||||
case kGray_8_GrPixelConfig:
|
||||
case kGray_8_as_Lum_GrPixelConfig:
|
||||
case kGray_8_as_Red_GrPixelConfig:
|
||||
return 1;
|
||||
case kRGB_565_GrPixelConfig:
|
||||
case kRGBA_4444_GrPixelConfig:
|
||||
case kRG_88_GrPixelConfig:
|
||||
case kAlpha_half_GrPixelConfig:
|
||||
case kAlpha_half_as_Lum_GrPixelConfig:
|
||||
case kAlpha_half_as_Red_GrPixelConfig:
|
||||
case kAlpha_16_GrPixelConfig:
|
||||
return 2;
|
||||
case kRGBA_8888_GrPixelConfig:
|
||||
case kRGB_888_GrPixelConfig: // Assuming GPUs store this 4-byte aligned.
|
||||
case kRGB_888X_GrPixelConfig:
|
||||
case kBGRA_8888_GrPixelConfig:
|
||||
case kSRGBA_8888_GrPixelConfig:
|
||||
case kRGBA_1010102_GrPixelConfig:
|
||||
case kRG_1616_GrPixelConfig:
|
||||
case kRG_half_GrPixelConfig:
|
||||
return 4;
|
||||
case kRGBA_half_GrPixelConfig:
|
||||
case kRGBA_half_Clamped_GrPixelConfig:
|
||||
case kRGBA_16161616_GrPixelConfig:
|
||||
return 8;
|
||||
case kUnknown_GrPixelConfig:
|
||||
case kRGB_ETC1_GrPixelConfig:
|
||||
return 0;
|
||||
}
|
||||
SkUNREACHABLE;
|
||||
}
|
||||
|
||||
static constexpr bool GrPixelConfigIsOpaque(GrPixelConfig config) {
|
||||
switch (config) {
|
||||
case kRGB_565_GrPixelConfig:
|
||||
|
@ -399,7 +399,9 @@ public:
|
||||
|
||||
SkColorType colorType() const override { return GrColorTypeToSkColorType(fColorType); }
|
||||
|
||||
size_t getSize() const override { return fTextureProxy->gpuMemorySize(); }
|
||||
size_t getSize() const override {
|
||||
return fTextureProxy->gpuMemorySize(*fContext->priv().caps());
|
||||
}
|
||||
|
||||
void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override {
|
||||
SkRect dst = SkRect::MakeXYWH(x, y,
|
||||
|
@ -193,6 +193,10 @@ public:
|
||||
// For historical reasons requestedCount==0 is handled identically to requestedCount==1.
|
||||
virtual int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat&) const = 0;
|
||||
|
||||
// Returns the number of bytes per pixel for the given GrBackendFormat. This is only supported
|
||||
// for "normal" formats. For compressed formats this will return 0.
|
||||
virtual size_t bytesPerPixel(const GrBackendFormat&) const = 0;
|
||||
|
||||
/**
|
||||
* Backends may have restrictions on what types of surfaces support GrGpu::writePixels().
|
||||
* If this returns false then the caller should implement a fallback where a temporary texture
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "src/core/SkMakeUnique.h"
|
||||
#include "src/core/SkTaskGroup.h"
|
||||
#include "src/gpu/GrClientMappedBufferManager.h"
|
||||
#include "src/gpu/GrContextPriv.h"
|
||||
#include "src/gpu/GrDrawingManager.h"
|
||||
#include "src/gpu/GrGpu.h"
|
||||
#include "src/gpu/GrMemoryPool.h"
|
||||
@ -31,6 +32,7 @@
|
||||
#include "src/gpu/effects/GrSkSLFP.h"
|
||||
#include "src/gpu/text/GrTextBlobCache.h"
|
||||
#include "src/gpu/text/GrTextContext.h"
|
||||
#include "src/image/SkImage_GpuBase.h"
|
||||
#include "src/image/SkSurface_Gpu.h"
|
||||
#include <atomic>
|
||||
|
||||
@ -232,20 +234,21 @@ size_t GrContext::getResourceCachePurgeableBytes() const {
|
||||
return fResourceCache->getPurgeableBytes();
|
||||
}
|
||||
|
||||
size_t GrContext::ComputeTextureSize(SkColorType type, int width, int height, GrMipMapped mipMapped,
|
||||
bool useNextPow2) {
|
||||
int colorSamplesPerPixel = 1;
|
||||
return GrSurface::ComputeSize(SkColorType2GrPixelConfig(type), width, height,
|
||||
colorSamplesPerPixel, mipMapped, useNextPow2);
|
||||
}
|
||||
|
||||
size_t GrContext::ComputeImageSize(sk_sp<SkImage> image, GrMipMapped mipMapped, bool useNextPow2) {
|
||||
if (!image->isTextureBacked()) {
|
||||
return 0;
|
||||
}
|
||||
SkImage_GpuBase* gpuImage = static_cast<SkImage_GpuBase*>(as_IB(image.get()));
|
||||
GrTextureProxy* proxy = gpuImage->peekProxy();
|
||||
if (!proxy) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const GrCaps& caps = *gpuImage->context()->priv().caps();
|
||||
int colorSamplesPerPixel = 1;
|
||||
return GrSurface::ComputeSize(SkColorType2GrPixelConfig(image->colorType()), image->width(),
|
||||
image->height(), colorSamplesPerPixel, mipMapped, useNextPow2);
|
||||
return GrSurface::ComputeSize(SkColorType2GrPixelConfig(image->colorType()), caps,
|
||||
proxy->backendFormat(), image->width(), image->height(),
|
||||
colorSamplesPerPixel, mipMapped, useNextPow2);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -10,11 +10,13 @@
|
||||
#include "include/gpu/GrContext.h"
|
||||
#include "include/gpu/GrTexture.h"
|
||||
#include "src/gpu/GrContextPriv.h"
|
||||
#include "src/gpu/GrGpu.h"
|
||||
#include "src/gpu/GrOnFlushResourceProvider.h"
|
||||
#include "src/gpu/GrOpFlushState.h"
|
||||
#include "src/gpu/GrProxyProvider.h"
|
||||
#include "src/gpu/GrRectanizer.h"
|
||||
#include "src/gpu/GrResourceProvider.h"
|
||||
#include "src/gpu/GrResourceProviderPriv.h"
|
||||
#include "src/gpu/GrSurfaceProxyPriv.h"
|
||||
#include "src/gpu/GrTracing.h"
|
||||
|
||||
@ -237,8 +239,9 @@ inline bool GrDrawOpAtlas::updatePlot(GrDeferredUploadTarget* target, AtlasID* i
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GrDrawOpAtlas::uploadToPage(unsigned int pageIdx, AtlasID* id, GrDeferredUploadTarget* target,
|
||||
int width, int height, const void* image, SkIPoint16* loc) {
|
||||
bool GrDrawOpAtlas::uploadToPage(const GrCaps& caps, unsigned int pageIdx, AtlasID* id,
|
||||
GrDeferredUploadTarget* target, int width, int height,
|
||||
const void* image, SkIPoint16* loc) {
|
||||
SkASSERT(fProxies[pageIdx] && fProxies[pageIdx]->isInstantiated());
|
||||
|
||||
// look through all allocated plots for one we can share, in Most Recently Refed order
|
||||
@ -246,7 +249,7 @@ bool GrDrawOpAtlas::uploadToPage(unsigned int pageIdx, AtlasID* id, GrDeferredUp
|
||||
plotIter.init(fPages[pageIdx].fPlotList, PlotList::Iter::kHead_IterStart);
|
||||
|
||||
for (Plot* plot = plotIter.get(); plot; plot = plotIter.next()) {
|
||||
SkASSERT(GrBytesPerPixel(fProxies[pageIdx]->config()) == plot->bpp());
|
||||
SkASSERT(caps.bytesPerPixel(fProxies[pageIdx]->backendFormat()) == plot->bpp());
|
||||
|
||||
if (plot->addSubImage(width, height, image, loc)) {
|
||||
return this->updatePlot(target, id, plot);
|
||||
@ -272,11 +275,13 @@ GrDrawOpAtlas::ErrorCode GrDrawOpAtlas::addToAtlas(GrResourceProvider* resourceP
|
||||
return ErrorCode::kError;
|
||||
}
|
||||
|
||||
const GrCaps& caps = *resourceProvider->caps();
|
||||
|
||||
// Look through each page to see if we can upload without having to flush
|
||||
// We prioritize this upload to the first pages, not the most recently used, to make it easier
|
||||
// to remove unused pages in reverse page order.
|
||||
for (unsigned int pageIdx = 0; pageIdx < fNumActivePages; ++pageIdx) {
|
||||
if (this->uploadToPage(pageIdx, id, target, width, height, image, loc)) {
|
||||
if (this->uploadToPage(caps, pageIdx, id, target, width, height, image, loc)) {
|
||||
return ErrorCode::kSucceeded;
|
||||
}
|
||||
}
|
||||
@ -292,7 +297,7 @@ GrDrawOpAtlas::ErrorCode GrDrawOpAtlas::addToAtlas(GrResourceProvider* resourceP
|
||||
SkASSERT(plot);
|
||||
if (plot->lastUseToken() < target->tokenTracker()->nextTokenToFlush()) {
|
||||
this->processEvictionAndResetRects(plot);
|
||||
SkASSERT(GrBytesPerPixel(fProxies[pageIdx]->config()) == plot->bpp());
|
||||
SkASSERT(caps.bytesPerPixel(fProxies[pageIdx]->backendFormat()) == plot->bpp());
|
||||
SkDEBUGCODE(bool verify = )plot->addSubImage(width, height, image, loc);
|
||||
SkASSERT(verify);
|
||||
if (!this->updatePlot(target, id, plot)) {
|
||||
@ -307,7 +312,7 @@ GrDrawOpAtlas::ErrorCode GrDrawOpAtlas::addToAtlas(GrResourceProvider* resourceP
|
||||
return ErrorCode::kError;
|
||||
}
|
||||
|
||||
if (this->uploadToPage(fNumActivePages-1, id, target, width, height, image, loc)) {
|
||||
if (this->uploadToPage(caps, fNumActivePages-1, id, target, width, height, image, loc)) {
|
||||
return ErrorCode::kSucceeded;
|
||||
} else {
|
||||
// If we fail to upload to a newly activated page then something has gone terribly
|
||||
@ -347,7 +352,7 @@ GrDrawOpAtlas::ErrorCode GrDrawOpAtlas::addToAtlas(GrResourceProvider* resourceP
|
||||
newPlot.reset(plot->clone());
|
||||
|
||||
fPages[pageIdx].fPlotList.addToHead(newPlot.get());
|
||||
SkASSERT(GrBytesPerPixel(fProxies[pageIdx]->config()) == newPlot->bpp());
|
||||
SkASSERT(caps.bytesPerPixel(fProxies[pageIdx]->backendFormat()) == newPlot->bpp());
|
||||
SkDEBUGCODE(bool verify = )newPlot->addSubImage(width, height, image, loc);
|
||||
SkASSERT(verify);
|
||||
|
||||
|
@ -372,8 +372,9 @@ private:
|
||||
// the front and remove from the back there is no need for MRU.
|
||||
}
|
||||
|
||||
bool uploadToPage(unsigned int pageIdx, AtlasID* id, GrDeferredUploadTarget* target,
|
||||
int width, int height, const void* image, SkIPoint16* loc);
|
||||
bool uploadToPage(const GrCaps&, unsigned int pageIdx, AtlasID* id,
|
||||
GrDeferredUploadTarget* target, int width, int height, const void* image,
|
||||
SkIPoint16* loc);
|
||||
|
||||
bool createPages(GrProxyProvider*);
|
||||
bool activateNewPage(GrResourceProvider*);
|
||||
|
@ -119,7 +119,7 @@ sk_sp<GrSurface> GrRenderTargetProxy::createSurface(GrResourceProvider* resource
|
||||
return surface;
|
||||
}
|
||||
|
||||
size_t GrRenderTargetProxy::onUninstantiatedGpuMemorySize() const {
|
||||
size_t GrRenderTargetProxy::onUninstantiatedGpuMemorySize(const GrCaps& caps) const {
|
||||
int colorSamplesPerPixel = this->numSamples();
|
||||
if (colorSamplesPerPixel > 1) {
|
||||
// Add one for the resolve buffer.
|
||||
@ -127,8 +127,9 @@ size_t GrRenderTargetProxy::onUninstantiatedGpuMemorySize() const {
|
||||
}
|
||||
|
||||
// TODO: do we have enough information to improve this worst case estimate?
|
||||
return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
|
||||
colorSamplesPerPixel, GrMipMapped::kNo, !this->priv().isExact());
|
||||
return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
|
||||
this->height(), colorSamplesPerPixel, GrMipMapped::kNo,
|
||||
!this->priv().isExact());
|
||||
}
|
||||
|
||||
bool GrRenderTargetProxy::refsWrappedObjects() const {
|
||||
|
@ -151,7 +151,7 @@ private:
|
||||
}
|
||||
bool canChangeStencilAttachment() const;
|
||||
|
||||
size_t onUninstantiatedGpuMemorySize() const override;
|
||||
size_t onUninstantiatedGpuMemorySize(const GrCaps&) const override;
|
||||
SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;)
|
||||
|
||||
// WARNING: Be careful when adding or removing fields here. ASAN is likely to trigger warnings
|
||||
|
@ -16,6 +16,8 @@
|
||||
#include "src/gpu/SkGr.h"
|
||||
|
||||
size_t GrSurface::ComputeSize(GrPixelConfig config,
|
||||
const GrCaps& caps,
|
||||
const GrBackendFormat& format,
|
||||
int width,
|
||||
int height,
|
||||
int colorSamplesPerPixel,
|
||||
@ -30,7 +32,7 @@ size_t GrSurface::ComputeSize(GrPixelConfig config,
|
||||
if (GrPixelConfigIsCompressed(config)) {
|
||||
colorSize = GrCompressedFormatDataSize(config, width, height);
|
||||
} else {
|
||||
colorSize = (size_t)width * height * GrBytesPerPixel(config);
|
||||
colorSize = (size_t)width * height * caps.bytesPerPixel(format);
|
||||
}
|
||||
SkASSERT(colorSize > 0);
|
||||
|
||||
|
@ -273,13 +273,13 @@ public:
|
||||
*
|
||||
* @return the amount of GPU memory used in bytes
|
||||
*/
|
||||
size_t gpuMemorySize() const {
|
||||
size_t gpuMemorySize(const GrCaps& caps) const {
|
||||
SkASSERT(!this->isFullyLazy());
|
||||
if (fTarget) {
|
||||
return fTarget->gpuMemorySize();
|
||||
}
|
||||
if (kInvalidGpuMemorySize == fGpuMemorySize) {
|
||||
fGpuMemorySize = this->onUninstantiatedGpuMemorySize();
|
||||
fGpuMemorySize = this->onUninstantiatedGpuMemorySize(caps);
|
||||
SkASSERT(kInvalidGpuMemorySize != fGpuMemorySize);
|
||||
}
|
||||
return fGpuMemorySize;
|
||||
@ -417,7 +417,7 @@ private:
|
||||
static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0);
|
||||
SkDEBUGCODE(size_t getRawGpuMemorySize_debugOnly() const { return fGpuMemorySize; })
|
||||
|
||||
virtual size_t onUninstantiatedGpuMemorySize() const = 0;
|
||||
virtual size_t onUninstantiatedGpuMemorySize(const GrCaps&) const = 0;
|
||||
|
||||
bool fIgnoredByResourceAllocator = false;
|
||||
GrProtected fIsProtected;
|
||||
|
@ -31,8 +31,9 @@ void GrTexture::markMipMapsClean() {
|
||||
}
|
||||
|
||||
size_t GrTexture::onGpuMemorySize() const {
|
||||
return GrSurface::ComputeSize(this->config(), this->width(), this->height(), 1,
|
||||
this->texturePriv().mipMapped());
|
||||
const GrCaps& caps = *this->getGpu()->caps();
|
||||
return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
|
||||
this->height(), 1, this->texturePriv().mipMapped());
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -143,9 +143,10 @@ GrMipMapped GrTextureProxy::mipMapped() const {
|
||||
return fMipMapped;
|
||||
}
|
||||
|
||||
size_t GrTextureProxy::onUninstantiatedGpuMemorySize() const {
|
||||
return GrSurface::ComputeSize(this->config(), this->width(), this->height(), 1,
|
||||
this->proxyMipMapped(), !this->priv().isExact());
|
||||
size_t GrTextureProxy::onUninstantiatedGpuMemorySize(const GrCaps& caps) const {
|
||||
return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
|
||||
this->height(), 1, this->proxyMipMapped(),
|
||||
!this->priv().isExact());
|
||||
}
|
||||
|
||||
bool GrTextureProxy::ProxiesAreCompatibleAsDynamicState(const GrTextureProxy* first,
|
||||
|
@ -182,7 +182,7 @@ private:
|
||||
// point, the proxy is instantiated, and this data is used to perform an ASAP upload.
|
||||
std::unique_ptr<GrDeferredProxyUploader> fDeferredUploader;
|
||||
|
||||
size_t onUninstantiatedGpuMemorySize() const override;
|
||||
size_t onUninstantiatedGpuMemorySize(const GrCaps&) const override;
|
||||
|
||||
// Methods made available via GrTextureProxy::CacheAccess
|
||||
void setUniqueKey(GrProxyProvider*, const GrUniqueKey&);
|
||||
|
@ -106,7 +106,7 @@ void GrTextureRenderTargetProxy::initSurfaceFlags(const GrCaps& caps) {
|
||||
}
|
||||
}
|
||||
|
||||
size_t GrTextureRenderTargetProxy::onUninstantiatedGpuMemorySize() const {
|
||||
size_t GrTextureRenderTargetProxy::onUninstantiatedGpuMemorySize(const GrCaps& caps) const {
|
||||
int colorSamplesPerPixel = this->numSamples();
|
||||
if (colorSamplesPerPixel > 1) {
|
||||
// Add one to account for the resolve buffer.
|
||||
@ -114,8 +114,8 @@ size_t GrTextureRenderTargetProxy::onUninstantiatedGpuMemorySize() const {
|
||||
}
|
||||
|
||||
// TODO: do we have enough information to improve this worst case estimate?
|
||||
return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
|
||||
colorSamplesPerPixel, this->proxyMipMapped(),
|
||||
return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
|
||||
this->height(), colorSamplesPerPixel, this->proxyMipMapped(),
|
||||
!this->priv().isExact());
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ private:
|
||||
bool instantiate(GrResourceProvider*) override;
|
||||
sk_sp<GrSurface> createSurface(GrResourceProvider*) const override;
|
||||
|
||||
size_t onUninstantiatedGpuMemorySize() const override;
|
||||
size_t onUninstantiatedGpuMemorySize(const GrCaps&) const override;
|
||||
|
||||
SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;)
|
||||
};
|
||||
|
@ -3922,6 +3922,15 @@ int GrGLCaps::maxRenderTargetSampleCount(GrGLFormat format) const {
|
||||
return count;
|
||||
}
|
||||
|
||||
size_t GrGLCaps::bytesPerPixel(GrGLFormat format) const {
|
||||
return this->getFormatInfo(format).fBytesPerPixel;
|
||||
}
|
||||
|
||||
size_t GrGLCaps::bytesPerPixel(const GrBackendFormat& format) const {
|
||||
auto glFormat = format.asGLFormat();
|
||||
return this->bytesPerPixel(glFormat);
|
||||
}
|
||||
|
||||
bool GrGLCaps::canFormatBeFBOColorAttachment(GrGLFormat format) const {
|
||||
return SkToBool(this->getFormatInfo(format).fFlags & FormatInfo::kFBOColorAttachment_Flag);
|
||||
}
|
||||
|
@ -133,6 +133,9 @@ public:
|
||||
}
|
||||
int maxRenderTargetSampleCount(GrGLFormat) const;
|
||||
|
||||
size_t bytesPerPixel(GrGLFormat) const;
|
||||
size_t bytesPerPixel(const GrBackendFormat&) const override;
|
||||
|
||||
bool isFormatCopyable(const GrBackendFormat&) const override;
|
||||
|
||||
bool canFormatBeFBOColorAttachment(GrGLFormat) const;
|
||||
@ -649,7 +652,7 @@ private:
|
||||
GrGLenum fDefaultExternalFormat = 0;
|
||||
GrGLenum fDefaultExternalType = 0;
|
||||
|
||||
// This value is only valid for regular formats. Planar and compressed formats will be 0.
|
||||
// This value is only valid for regular formats. Compressed formats will be 0.
|
||||
GrGLenum fBytesPerPixel = 0;
|
||||
|
||||
enum {
|
||||
|
@ -3620,7 +3620,7 @@ GrBackendTexture GrGLGpu::onCreateBackendTexture(int w, int h,
|
||||
texels.append(mipLevelCount);
|
||||
SkTArray<size_t> individualMipOffsets(mipLevelCount);
|
||||
|
||||
size_t bytesPerPixel = GrBytesPerPixel(config);
|
||||
size_t bytesPerPixel = this->glCaps().bytesPerPixel(glFormat);
|
||||
|
||||
size_t totalSize = GrComputeTightCombinedBufferSize(
|
||||
bytesPerPixel, w, h, &individualMipOffsets, mipLevelCount);
|
||||
|
@ -103,8 +103,9 @@ GrBackendFormat GrGLRenderTarget::backendFormat() const {
|
||||
}
|
||||
|
||||
size_t GrGLRenderTarget::onGpuMemorySize() const {
|
||||
return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
|
||||
fNumSamplesOwnedPerPixel, GrMipMapped::kNo);
|
||||
const GrCaps& caps = *this->getGpu()->caps();
|
||||
return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
|
||||
this->height(), fNumSamplesOwnedPerPixel, GrMipMapped::kNo);
|
||||
}
|
||||
|
||||
bool GrGLRenderTarget::completeStencilAttachment() {
|
||||
@ -220,8 +221,10 @@ void GrGLRenderTarget::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump)
|
||||
|
||||
// Log any renderbuffer's contribution to memory.
|
||||
if (fMSColorRenderbufferID) {
|
||||
size_t size = GrSurface::ComputeSize(this->config(), this->width(), this->height(),
|
||||
this->msaaSamples(), GrMipMapped::kNo);
|
||||
const GrCaps& caps = *this->getGpu()->caps();
|
||||
size_t size = GrSurface::ComputeSize(this->config(), caps, this->backendFormat(),
|
||||
this->width(), this->height(), this->msaaSamples(),
|
||||
GrMipMapped::kNo);
|
||||
|
||||
// Due to this resource having both a texture and a renderbuffer component, dump as
|
||||
// skia/gpu_resources/resource_#/renderbuffer
|
||||
|
@ -72,6 +72,8 @@ sk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped(
|
||||
}
|
||||
|
||||
size_t GrGLTextureRenderTarget::onGpuMemorySize() const {
|
||||
return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
|
||||
this->numSamplesOwnedPerPixel(), this->texturePriv().mipMapped());
|
||||
const GrCaps& caps = *this->getGpu()->caps();
|
||||
return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
|
||||
this->height(), this->numSamplesOwnedPerPixel(),
|
||||
this->texturePriv().mipMapped());
|
||||
}
|
||||
|
@ -113,6 +113,10 @@ public:
|
||||
return this->maxRenderTargetSampleCount(format.asMockColorType());
|
||||
}
|
||||
|
||||
size_t bytesPerPixel(const GrBackendFormat& format) const override {
|
||||
return GrColorTypeBytesPerPixel(format.asMockColorType());
|
||||
}
|
||||
|
||||
SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType,
|
||||
const GrBackendFormat& surfaceFormat,
|
||||
GrColorType srcColorType) const override {
|
||||
|
@ -102,8 +102,9 @@ public:
|
||||
// Add one to account for the resolve buffer.
|
||||
++numColorSamples;
|
||||
}
|
||||
return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
|
||||
numColorSamples, GrMipMapped::kNo);
|
||||
const GrCaps& caps = *this->getGpu()->caps();
|
||||
return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
|
||||
this->height(), numColorSamples, GrMipMapped::kNo);
|
||||
}
|
||||
|
||||
GrBackendRenderTarget getBackendRenderTarget() const override {
|
||||
@ -186,8 +187,9 @@ private:
|
||||
// Add one to account for the resolve buffer.
|
||||
++numColorSamples;
|
||||
}
|
||||
return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
|
||||
numColorSamples,
|
||||
const GrCaps& caps = *this->getGpu()->caps();
|
||||
return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
|
||||
this->height(), numColorSamples,
|
||||
this->texturePriv().mipMapped());
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
int maxRenderTargetSampleCount(const GrBackendFormat&) const override;
|
||||
int maxRenderTargetSampleCount(MTLPixelFormat) const;
|
||||
|
||||
size_t bytesPerPixel(const GrBackendFormat&) const override;
|
||||
size_t bytesPerPixel(MTLPixelFormat) const;
|
||||
|
||||
SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType,
|
||||
@ -143,7 +144,7 @@ private:
|
||||
|
||||
uint16_t fFlags = 0;
|
||||
|
||||
// This value is only valid for regular formats. Planar and compressed formats will be 0.
|
||||
// This value is only valid for regular formats. Compressed formats will be 0.
|
||||
size_t fBytesPerPixel = 0;
|
||||
|
||||
std::unique_ptr<ColorTypeInfo[]> fColorTypeInfos;
|
||||
|
@ -380,6 +380,11 @@ int GrMtlCaps::getRenderTargetSampleCount(int requestedCount, MTLPixelFormat for
|
||||
return 1 == requestedCount ? 1 : 0;
|
||||
}
|
||||
|
||||
size_t GrMtlCaps::bytesPerPixel(const GrBackendFormat& format) const {
|
||||
MTLPixelFormat mtlFormat = GrBackendFormatAsMTLPixelFormat(format);
|
||||
return this->bytesPerPixel(mtlFormat);
|
||||
}
|
||||
|
||||
size_t GrMtlCaps::bytesPerPixel(MTLPixelFormat format) const {
|
||||
return this->getFormatInfo(format).fBytesPerPixel;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "src/gpu/GrRenderTarget.h"
|
||||
|
||||
#include "include/gpu/GrBackendSurface.h"
|
||||
#include "src/gpu/GrGpu.h"
|
||||
|
||||
#import <Metal/Metal.h>
|
||||
|
||||
@ -61,8 +62,9 @@ protected:
|
||||
if (numColorSamples > 1) {
|
||||
++numColorSamples;
|
||||
}
|
||||
return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
|
||||
numColorSamples, GrMipMapped::kNo);
|
||||
const GrCaps& caps = *this->getGpu()->caps();
|
||||
return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
|
||||
this->height(), numColorSamples, GrMipMapped::kNo);
|
||||
}
|
||||
|
||||
id<MTLTexture> fColorTexture;
|
||||
|
@ -77,8 +77,9 @@ private:
|
||||
if (numColorSamples > 1) {
|
||||
++numColorSamples;
|
||||
}
|
||||
return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
|
||||
numColorSamples, GrMipMapped::kNo);
|
||||
const GrCaps& caps = *this->getGpu()->caps();
|
||||
return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
|
||||
this->height(), numColorSamples, GrMipMapped::kNo);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1048,7 +1048,10 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
|
||||
{
|
||||
constexpr VkFormat format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM;
|
||||
auto& info = this->getFormatInfo(format);
|
||||
info.fBytesPerPixel = 0;
|
||||
// Currently we are just over estimating this value to be used in gpu size calculations even
|
||||
// though the actually size is probably less. We should instead treat planar formats similar
|
||||
// to compressed textures that go through their own special query for calculating size.
|
||||
info.fBytesPerPixel = 3;
|
||||
if (fSupportsYcbcrConversion) {
|
||||
info.init(interface, physDev, properties, format);
|
||||
}
|
||||
@ -1069,7 +1072,10 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
|
||||
{
|
||||
constexpr VkFormat format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
|
||||
auto& info = this->getFormatInfo(format);
|
||||
info.fBytesPerPixel = 0;
|
||||
// Currently we are just over estimating this value to be used in gpu size calculations even
|
||||
// though the actually size is probably less. We should instead treat planar formats similar
|
||||
// to compressed textures that go through their own special query for calculating size.
|
||||
info.fBytesPerPixel = 3;
|
||||
if (fSupportsYcbcrConversion) {
|
||||
info.init(interface, physDev, properties, format);
|
||||
}
|
||||
@ -1353,6 +1359,18 @@ int GrVkCaps::maxRenderTargetSampleCount(VkFormat format) const {
|
||||
return table[table.count() - 1];
|
||||
}
|
||||
|
||||
size_t GrVkCaps::bytesPerPixel(const GrBackendFormat& format) const {
|
||||
VkFormat vkFormat;
|
||||
if (!format.asVkFormat(&vkFormat)) {
|
||||
return 0;
|
||||
}
|
||||
return this->bytesPerPixel(vkFormat);
|
||||
}
|
||||
|
||||
size_t GrVkCaps::bytesPerPixel(VkFormat format) const {
|
||||
return this->getFormatInfo(format).fBytesPerPixel;
|
||||
}
|
||||
|
||||
static inline size_t align_to_4(size_t v) {
|
||||
switch (v & 0b11) {
|
||||
// v is already a multiple of 4.
|
||||
|
@ -53,11 +53,8 @@ public:
|
||||
int maxRenderTargetSampleCount(const GrBackendFormat&) const override;
|
||||
int maxRenderTargetSampleCount(VkFormat format) const;
|
||||
|
||||
size_t bytesPerPixel(VkFormat format) const {
|
||||
// We shouldn't be calling this for compressed or planar formats.
|
||||
SkASSERT(this->getFormatInfo(format).fBytesPerPixel);
|
||||
return this->getFormatInfo(format).fBytesPerPixel;
|
||||
}
|
||||
size_t bytesPerPixel(const GrBackendFormat&) const override;
|
||||
size_t bytesPerPixel(VkFormat format) const;
|
||||
|
||||
SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType,
|
||||
const GrBackendFormat& surfaceFormat,
|
||||
@ -273,7 +270,7 @@ private:
|
||||
uint16_t fLinearFlags = 0;
|
||||
|
||||
SkTDArray<int> fColorSampleCounts;
|
||||
// This value is only valid for regular formats. Planar and compressed formats will be 0.
|
||||
// This value is only valid for regular formats. Compressed formats will be 0.
|
||||
size_t fBytesPerPixel = 0;
|
||||
|
||||
std::unique_ptr<ColorTypeInfo[]> fColorTypeInfos;
|
||||
|
@ -117,8 +117,9 @@ protected:
|
||||
// Add one to account for the resolved VkImage.
|
||||
numColorSamples += 1;
|
||||
}
|
||||
return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
|
||||
numColorSamples, GrMipMapped::kNo);
|
||||
const GrCaps& caps = *this->getGpu()->caps();
|
||||
return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
|
||||
this->height(), numColorSamples, GrMipMapped::kNo);
|
||||
}
|
||||
|
||||
void createFramebuffer(GrVkGpu* gpu);
|
||||
|
@ -244,7 +244,8 @@ size_t GrVkTextureRenderTarget::onGpuMemorySize() const {
|
||||
// Add one to account for the resolve VkImage.
|
||||
++numColorSamples;
|
||||
}
|
||||
return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
|
||||
numColorSamples, // TODO: this still correct?
|
||||
const GrCaps& caps = *this->getGpu()->caps();
|
||||
return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
|
||||
this->height(), numColorSamples, // TODO: this still correct?
|
||||
this->texturePriv().mipMapped());
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
|
||||
// instantiated, it checks that the instantiated size is <= to
|
||||
// the pre-computation. If the proxy never computed its
|
||||
// pre-instantiation size then the check is skipped.
|
||||
proxy->gpuMemorySize();
|
||||
proxy->gpuMemorySize(caps);
|
||||
|
||||
check_surface(reporter, proxy.get(), origin,
|
||||
widthHeight, widthHeight, config, budgeted);
|
||||
@ -200,7 +200,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
|
||||
// instantiated, it checks that the instantiated size is <= to
|
||||
// the pre-computation. If the proxy never computed its
|
||||
// pre-instantiation size then the check is skipped.
|
||||
proxy->gpuMemorySize();
|
||||
proxy->gpuMemorySize(caps);
|
||||
|
||||
check_surface(reporter, proxy.get(), origin,
|
||||
widthHeight, widthHeight, config, budgeted);
|
||||
|
@ -1618,13 +1618,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GPUMemorySize, reporter, ctxInfo) {
|
||||
sk_sp<GrTextureProxy> proxy;
|
||||
|
||||
proxy = make_mipmap_proxy(context, GrRenderable::kYes, kSize, kSize, 1);
|
||||
size_t size = proxy->gpuMemorySize();
|
||||
size_t size = proxy->gpuMemorySize(*caps);
|
||||
REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size);
|
||||
|
||||
size_t sampleCount = (size_t)caps->getRenderTargetSampleCount(4, proxy->backendFormat());
|
||||
if (sampleCount >= 4) {
|
||||
proxy = make_mipmap_proxy(context, GrRenderable::kYes, kSize, kSize, sampleCount);
|
||||
size = proxy->gpuMemorySize();
|
||||
size = proxy->gpuMemorySize(*caps);
|
||||
REPORTER_ASSERT(reporter,
|
||||
kSize*kSize*4+(kSize*kSize*4)/3 == size || // msaa4 failed
|
||||
kSize*kSize*4*sampleCount+(kSize*kSize*4)/3 == size || // auto-resolving
|
||||
@ -1632,7 +1632,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GPUMemorySize, reporter, ctxInfo) {
|
||||
}
|
||||
|
||||
proxy = make_mipmap_proxy(context, GrRenderable::kNo, kSize, kSize, 1);
|
||||
size = proxy->gpuMemorySize();
|
||||
size = proxy->gpuMemorySize(*caps);
|
||||
REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user