Use shared gpu memory size for all GrAttachments.
Bug: skia:10727 Change-Id: I07ad4684c7a09963aa4be60e08877dde1c5ca192 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/325663 Commit-Queue: Greg Daniel <egdaniel@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
387fd62a12
commit
c89a7ee628
@ -8,7 +8,19 @@
|
||||
#include "src/gpu/GrAttachment.h"
|
||||
|
||||
#include "include/private/GrResourceKey.h"
|
||||
#include "src/gpu/GrBackendUtils.h"
|
||||
#include "src/gpu/GrCaps.h"
|
||||
#include "src/gpu/GrDataUtils.h"
|
||||
|
||||
size_t GrAttachment::onGpuMemorySize() const {
|
||||
GrBackendFormat format = this->backendFormat();
|
||||
SkImage::CompressionType compression = GrBackendFormatToCompressionType(format);
|
||||
|
||||
uint64_t size = GrNumBlocks(compression, this->dimensions());
|
||||
size *= GrBackendFormatBytesPerBlock(this->backendFormat());
|
||||
size *= this->numSamples();
|
||||
return size;
|
||||
}
|
||||
|
||||
static void build_key(GrResourceKey::Builder* builder,
|
||||
const GrCaps& caps,
|
||||
|
@ -70,6 +70,8 @@ protected:
|
||||
, fSampleCnt(sampleCnt) {}
|
||||
|
||||
private:
|
||||
size_t onGpuMemorySize() const final;
|
||||
|
||||
const char* getResourceType() const override {
|
||||
// TODO: Once attachments can have multiple usages this needs to be updated
|
||||
switch (fSupportedUsages) {
|
||||
|
@ -152,6 +152,22 @@ static void create_BC1_block(SkColor col0, SkColor col1, BC1Block* block) {
|
||||
}
|
||||
}
|
||||
|
||||
size_t GrNumBlocks(SkImage::CompressionType type, SkISize baseDimensions) {
|
||||
switch (type) {
|
||||
case SkImage::CompressionType::kNone:
|
||||
return baseDimensions.width() * baseDimensions.height();
|
||||
case SkImage::CompressionType::kETC2_RGB8_UNORM:
|
||||
case SkImage::CompressionType::kBC1_RGB8_UNORM:
|
||||
case SkImage::CompressionType::kBC1_RGBA8_UNORM: {
|
||||
int numBlocksWidth = num_4x4_blocks(baseDimensions.width());
|
||||
int numBlocksHeight = num_4x4_blocks(baseDimensions.height());
|
||||
|
||||
return numBlocksWidth * numBlocksHeight;
|
||||
}
|
||||
}
|
||||
SkUNREACHABLE;
|
||||
}
|
||||
|
||||
size_t GrCompressedRowBytes(SkImage::CompressionType type, int width) {
|
||||
switch (type) {
|
||||
case SkImage::CompressionType::kNone:
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
class GrImageInfo;
|
||||
|
||||
size_t GrNumBlocks(SkImage::CompressionType, SkISize baseDimensions);
|
||||
|
||||
// Returns a value that can be used to set rowBytes for a transfer function.
|
||||
size_t GrCompressedRowBytes(SkImage::CompressionType, int w);
|
||||
|
||||
|
@ -62,14 +62,6 @@ sk_sp<GrD3DAttachment> GrD3DAttachment::MakeStencil(GrD3DGpu* gpu,
|
||||
std::move(state), view));
|
||||
}
|
||||
|
||||
size_t GrD3DAttachment::onGpuMemorySize() const {
|
||||
uint64_t size = this->width();
|
||||
size *= this->height();
|
||||
size *= GrD3DCaps::GetStencilFormatTotalBitCount(this->dxgiFormat());
|
||||
size *= this->numSamples();
|
||||
return static_cast<size_t>(size / 8);
|
||||
}
|
||||
|
||||
void GrD3DAttachment::onRelease() {
|
||||
GrD3DGpu* gpu = this->getD3DGpu();
|
||||
this->releaseResource(gpu);
|
||||
|
@ -34,8 +34,6 @@ protected:
|
||||
void onAbandon() override;
|
||||
|
||||
private:
|
||||
size_t onGpuMemorySize() const override;
|
||||
|
||||
GrD3DAttachment(GrD3DGpu* gpu,
|
||||
SkISize dimensions,
|
||||
UsageFlags supportedUsages,
|
||||
|
@ -47,14 +47,6 @@ sk_sp<GrDawnAttachment> GrDawnAttachment::MakeStencil(GrDawnGpu* gpu,
|
||||
|
||||
GrDawnAttachment::~GrDawnAttachment() {}
|
||||
|
||||
size_t GrDawnAttachment::onGpuMemorySize() const {
|
||||
uint64_t size = this->width();
|
||||
size *= this->height();
|
||||
size *= 32;
|
||||
size *= std::max(1, this->numSamples());
|
||||
return static_cast<size_t>(size / 8);
|
||||
}
|
||||
|
||||
void GrDawnAttachment::onRelease() { GrAttachment::onRelease(); }
|
||||
|
||||
void GrDawnAttachment::onAbandon() { GrAttachment::onAbandon(); }
|
||||
|
@ -29,8 +29,6 @@ protected:
|
||||
void onAbandon() override;
|
||||
|
||||
private:
|
||||
size_t onGpuMemorySize() const override;
|
||||
|
||||
GrDawnAttachment(GrDawnGpu* gpu,
|
||||
SkISize dimensions,
|
||||
UsageFlags supportedUsages,
|
||||
|
@ -10,14 +10,6 @@
|
||||
#include "include/core/SkTraceMemoryDump.h"
|
||||
#include "src/gpu/gl/GrGLGpu.h"
|
||||
|
||||
size_t GrGLAttachment::onGpuMemorySize() const {
|
||||
uint64_t size = this->width();
|
||||
size *= this->height();
|
||||
size *= GrGLFormatBytesPerBlock(fFormat);
|
||||
size *= this->numSamples();
|
||||
return static_cast<size_t>(size);
|
||||
}
|
||||
|
||||
void GrGLAttachment::onRelease() {
|
||||
if (0 != fRenderbufferID) {
|
||||
GrGLGpu* gpuGL = (GrGLGpu*)this->getGpu();
|
||||
|
@ -42,8 +42,6 @@ protected:
|
||||
const SkString& dumpName) const override;
|
||||
|
||||
private:
|
||||
size_t onGpuMemorySize() const override;
|
||||
|
||||
GrGLFormat fFormat;
|
||||
|
||||
// may be zero for external SBs associated with external RTs
|
||||
|
@ -26,11 +26,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
size_t onGpuMemorySize() const override {
|
||||
int bpp = GrBackendFormatBytesPerBlock(this->backendFormat());
|
||||
return std::max(1, (int)(bpp)) * this->width() * this->height();
|
||||
}
|
||||
|
||||
using INHERITED = GrAttachment;
|
||||
};
|
||||
|
||||
|
@ -37,8 +37,6 @@ protected:
|
||||
void onAbandon() override;
|
||||
|
||||
private:
|
||||
size_t onGpuMemorySize() const override;
|
||||
|
||||
GrMtlAttachment(GrMtlGpu* gpu,
|
||||
SkISize dimensions,
|
||||
UsageFlags supportedUsages,
|
||||
|
@ -50,14 +50,6 @@ GrMtlAttachment::~GrMtlAttachment() {
|
||||
SkASSERT(!fView);
|
||||
}
|
||||
|
||||
size_t GrMtlAttachment::onGpuMemorySize() const {
|
||||
uint64_t size = this->width();
|
||||
size *= this->height();
|
||||
size *= GrMtlFormatBytesPerBlock(this->mtlFormat());
|
||||
size *= this->numSamples();
|
||||
return static_cast<size_t>(size);
|
||||
}
|
||||
|
||||
void GrMtlAttachment::onRelease() {
|
||||
fView = nullptr;
|
||||
GrAttachment::onRelease();
|
||||
|
@ -100,14 +100,6 @@ GrVkAttachment::~GrVkAttachment() {
|
||||
SkASSERT(!fView);
|
||||
}
|
||||
|
||||
size_t GrVkAttachment::onGpuMemorySize() const {
|
||||
uint64_t size = this->width();
|
||||
size *= this->height();
|
||||
size *= GrVkCaps::GetStencilFormatTotalBitCount(this->imageFormat());
|
||||
size *= this->numSamples();
|
||||
return static_cast<size_t>(size / 8);
|
||||
}
|
||||
|
||||
void GrVkAttachment::onRelease() {
|
||||
this->releaseImage();
|
||||
fView.reset();
|
||||
|
@ -40,8 +40,6 @@ protected:
|
||||
void onAbandon() override;
|
||||
|
||||
private:
|
||||
size_t onGpuMemorySize() const override;
|
||||
|
||||
static sk_sp<GrVkAttachment> Make(GrVkGpu* gpu,
|
||||
SkISize dimensions,
|
||||
UsageFlags attachmentUsages,
|
||||
|
Loading…
Reference in New Issue
Block a user