Update GrAttachment budgeted and gpu memory size calculation.

This adds the budgeted parameter to the GrAttachment ctors. Currently
we only have stencil and msaa attachments which are always budgeted
but this will soon change as more things get added.

Along the same lines this fixes the gpu memory size calculate on
render target. The msaa attachment was getting double counted in
the RT and the attachment itself.

Bug: skia:10727
Change-Id: I3520de9627eadaa4074f7425df509a6c1ccbe07f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/327337
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Greg Daniel 2020-10-19 13:11:57 -04:00 committed by Skia Commit-Bot
parent f1cd1553b3
commit a670782ed3
4 changed files with 33 additions and 12 deletions

View File

@ -19,11 +19,12 @@ GrVkAttachment::GrVkAttachment(GrVkGpu* gpu,
UsageFlags supportedUsages, UsageFlags supportedUsages,
const GrVkImageInfo& info, const GrVkImageInfo& info,
sk_sp<GrBackendSurfaceMutableStateImpl> mutableState, sk_sp<GrBackendSurfaceMutableStateImpl> mutableState,
sk_sp<const GrVkImageView> view) sk_sp<const GrVkImageView> view,
SkBudgeted budgeted)
: GrAttachment(gpu, dimensions, supportedUsages, info.fSampleCount, info.fProtected) : GrAttachment(gpu, dimensions, supportedUsages, info.fSampleCount, info.fProtected)
, GrVkImage(gpu, info, std::move(mutableState), GrBackendObjectOwnership::kOwned) , GrVkImage(gpu, info, std::move(mutableState), GrBackendObjectOwnership::kOwned)
, fView(std::move(view)) { , fView(std::move(view)) {
this->registerWithCache(SkBudgeted::kYes); this->registerWithCache(budgeted);
} }
sk_sp<GrVkAttachment> GrVkAttachment::MakeStencil(GrVkGpu* gpu, sk_sp<GrVkAttachment> GrVkAttachment::MakeStencil(GrVkGpu* gpu,
@ -33,7 +34,7 @@ sk_sp<GrVkAttachment> GrVkAttachment::MakeStencil(GrVkGpu* gpu,
VkImageUsageFlags vkUsageFlags = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VkImageUsageFlags vkUsageFlags = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
VK_IMAGE_USAGE_TRANSFER_DST_BIT; VK_IMAGE_USAGE_TRANSFER_DST_BIT;
return GrVkAttachment::Make(gpu, dimensions, UsageFlags::kStencil, sampleCnt, format, return GrVkAttachment::Make(gpu, dimensions, UsageFlags::kStencil, sampleCnt, format,
vkUsageFlags, GrProtected::kNo); vkUsageFlags, GrProtected::kNo, SkBudgeted::kYes);
} }
sk_sp<GrVkAttachment> GrVkAttachment::MakeMSAA(GrVkGpu* gpu, sk_sp<GrVkAttachment> GrVkAttachment::MakeMSAA(GrVkGpu* gpu,
@ -47,7 +48,7 @@ sk_sp<GrVkAttachment> GrVkAttachment::MakeMSAA(GrVkGpu* gpu,
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
VK_IMAGE_USAGE_TRANSFER_DST_BIT; VK_IMAGE_USAGE_TRANSFER_DST_BIT;
return GrVkAttachment::Make(gpu, dimensions, UsageFlags::kMSAA, numSamples, format, return GrVkAttachment::Make(gpu, dimensions, UsageFlags::kMSAA, numSamples, format,
vkUsageFlags, isProtected); vkUsageFlags, isProtected, SkBudgeted::kYes);
} }
sk_sp<GrVkAttachment> GrVkAttachment::Make(GrVkGpu* gpu, sk_sp<GrVkAttachment> GrVkAttachment::Make(GrVkGpu* gpu,
@ -56,7 +57,8 @@ sk_sp<GrVkAttachment> GrVkAttachment::Make(GrVkGpu* gpu,
int sampleCnt, int sampleCnt,
VkFormat format, VkFormat format,
VkImageUsageFlags vkUsageFlags, VkImageUsageFlags vkUsageFlags,
GrProtected isProtected) { GrProtected isProtected,
SkBudgeted budgeted) {
GrVkImage::ImageDesc imageDesc; GrVkImage::ImageDesc imageDesc;
imageDesc.fImageType = VK_IMAGE_TYPE_2D; imageDesc.fImageType = VK_IMAGE_TYPE_2D;
imageDesc.fFormat = format; imageDesc.fFormat = format;
@ -92,7 +94,8 @@ sk_sp<GrVkAttachment> GrVkAttachment::Make(GrVkGpu* gpu,
sk_sp<GrBackendSurfaceMutableStateImpl> mutableState( sk_sp<GrBackendSurfaceMutableStateImpl> mutableState(
new GrBackendSurfaceMutableStateImpl(info.fImageLayout, info.fCurrentQueueFamily)); new GrBackendSurfaceMutableStateImpl(info.fImageLayout, info.fCurrentQueueFamily));
return sk_sp<GrVkAttachment>(new GrVkAttachment(gpu, dimensions, attachmentUsages, info, return sk_sp<GrVkAttachment>(new GrVkAttachment(gpu, dimensions, attachmentUsages, info,
std::move(mutableState), std::move(imageView))); std::move(mutableState), std::move(imageView),
budgeted));
} }
GrVkAttachment::~GrVkAttachment() { GrVkAttachment::~GrVkAttachment() {

View File

@ -46,14 +46,16 @@ private:
int sampleCnt, int sampleCnt,
VkFormat format, VkFormat format,
VkImageUsageFlags vkUsageFlags, VkImageUsageFlags vkUsageFlags,
GrProtected isProtected); GrProtected isProtected,
SkBudgeted);
GrVkAttachment(GrVkGpu* gpu, GrVkAttachment(GrVkGpu* gpu,
SkISize dimensions, SkISize dimensions,
UsageFlags supportedUsages, UsageFlags supportedUsages,
const GrVkImageInfo&, const GrVkImageInfo&,
sk_sp<GrBackendSurfaceMutableStateImpl> mutableState, sk_sp<GrBackendSurfaceMutableStateImpl> mutableState,
sk_sp<const GrVkImageView> view); sk_sp<const GrVkImageView> view,
SkBudgeted);
GrVkGpu* getVkGpu() const; GrVkGpu* getVkGpu() const;

View File

@ -123,11 +123,21 @@ protected:
// This accounts for the texture's memory and any MSAA renderbuffer's memory. // This accounts for the texture's memory and any MSAA renderbuffer's memory.
size_t onGpuMemorySize() const override { size_t onGpuMemorySize() const override {
int numColorSamples = this->numSamples(); int numColorSamples = 0;
if (numColorSamples > 1) { if (this->numSamples() > 1) {
// Add one to account for the resolved VkImage. // If we have an msaa attachment then its size will be handled by the attachment itself.
numColorSamples += 1; if (!fMSAAAttachment) {
numColorSamples += this->numSamples();
}
if (fResolveAttachmentView) {
// Add one to account for the resolved VkImage.
numColorSamples += 1;
}
} else {
SkASSERT(!fResolveAttachmentView);
numColorSamples = 1;
} }
return GrSurface::ComputeSize(this->backendFormat(), this->dimensions(), return GrSurface::ComputeSize(this->backendFormat(), this->dimensions(),
numColorSamples, GrMipmapped::kNo); numColorSamples, GrMipmapped::kNo);
} }

View File

@ -660,6 +660,12 @@ bool CreateVkBackendContext(GrVkGetProc getProc,
if (0 != strncmp(deviceExtensions[i].extensionName, "VK_KHX", 6) && if (0 != strncmp(deviceExtensions[i].extensionName, "VK_KHX", 6) &&
0 != strncmp(deviceExtensions[i].extensionName, "VK_NVX", 6)) { 0 != strncmp(deviceExtensions[i].extensionName, "VK_NVX", 6)) {
// This is an nvidia extension that isn't supported by the debug layers so we get lots
// of warnings. We don't actually use it, so it is easiest to just not enable it.
if (0 == strcmp(deviceExtensions[i].extensionName, "VK_NV_low_latency")) {
continue;
}
if (!hasKHRBufferDeviceAddress || if (!hasKHRBufferDeviceAddress ||
0 != strcmp(deviceExtensions[i].extensionName, "VK_EXT_buffer_device_address")) { 0 != strcmp(deviceExtensions[i].extensionName, "VK_EXT_buffer_device_address")) {
deviceExtensionNames.push_back(deviceExtensions[i].extensionName); deviceExtensionNames.push_back(deviceExtensions[i].extensionName);