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>
diff --git a/src/gpu/vk/GrVkAttachment.cpp b/src/gpu/vk/GrVkAttachment.cpp
index ac5f1e8..cefd207 100644
--- a/src/gpu/vk/GrVkAttachment.cpp
+++ b/src/gpu/vk/GrVkAttachment.cpp
@@ -19,11 +19,12 @@
                                UsageFlags supportedUsages,
                                const GrVkImageInfo& info,
                                sk_sp<GrBackendSurfaceMutableStateImpl> mutableState,
-                               sk_sp<const GrVkImageView> view)
+                               sk_sp<const GrVkImageView> view,
+                               SkBudgeted budgeted)
         : GrAttachment(gpu, dimensions, supportedUsages, info.fSampleCount, info.fProtected)
         , GrVkImage(gpu, info, std::move(mutableState), GrBackendObjectOwnership::kOwned)
         , fView(std::move(view)) {
-    this->registerWithCache(SkBudgeted::kYes);
+    this->registerWithCache(budgeted);
 }
 
 sk_sp<GrVkAttachment> GrVkAttachment::MakeStencil(GrVkGpu* gpu,
@@ -33,7 +34,7 @@
     VkImageUsageFlags vkUsageFlags = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
                                      VK_IMAGE_USAGE_TRANSFER_DST_BIT;
     return GrVkAttachment::Make(gpu, dimensions, UsageFlags::kStencil, sampleCnt, format,
-                                vkUsageFlags, GrProtected::kNo);
+                                vkUsageFlags, GrProtected::kNo, SkBudgeted::kYes);
 }
 
 sk_sp<GrVkAttachment> GrVkAttachment::MakeMSAA(GrVkGpu* gpu,
@@ -47,7 +48,7 @@
                                      VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
                                      VK_IMAGE_USAGE_TRANSFER_DST_BIT;
     return GrVkAttachment::Make(gpu, dimensions, UsageFlags::kMSAA, numSamples, format,
-                                vkUsageFlags, isProtected);
+                                vkUsageFlags, isProtected, SkBudgeted::kYes);
 }
 
 sk_sp<GrVkAttachment> GrVkAttachment::Make(GrVkGpu* gpu,
@@ -56,7 +57,8 @@
                                            int sampleCnt,
                                            VkFormat format,
                                            VkImageUsageFlags vkUsageFlags,
-                                           GrProtected isProtected) {
+                                           GrProtected isProtected,
+                                           SkBudgeted budgeted) {
     GrVkImage::ImageDesc imageDesc;
     imageDesc.fImageType = VK_IMAGE_TYPE_2D;
     imageDesc.fFormat = format;
@@ -92,7 +94,8 @@
     sk_sp<GrBackendSurfaceMutableStateImpl> mutableState(
             new GrBackendSurfaceMutableStateImpl(info.fImageLayout, info.fCurrentQueueFamily));
     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() {
diff --git a/src/gpu/vk/GrVkAttachment.h b/src/gpu/vk/GrVkAttachment.h
index 1185e43..4b93266 100644
--- a/src/gpu/vk/GrVkAttachment.h
+++ b/src/gpu/vk/GrVkAttachment.h
@@ -46,14 +46,16 @@
                                       int sampleCnt,
                                       VkFormat format,
                                       VkImageUsageFlags vkUsageFlags,
-                                      GrProtected isProtected);
+                                      GrProtected isProtected,
+                                      SkBudgeted);
 
     GrVkAttachment(GrVkGpu* gpu,
                    SkISize dimensions,
                    UsageFlags supportedUsages,
                    const GrVkImageInfo&,
                    sk_sp<GrBackendSurfaceMutableStateImpl> mutableState,
-                   sk_sp<const GrVkImageView> view);
+                   sk_sp<const GrVkImageView> view,
+                   SkBudgeted);
 
     GrVkGpu* getVkGpu() const;
 
diff --git a/src/gpu/vk/GrVkRenderTarget.h b/src/gpu/vk/GrVkRenderTarget.h
index 730606b..331d370 100644
--- a/src/gpu/vk/GrVkRenderTarget.h
+++ b/src/gpu/vk/GrVkRenderTarget.h
@@ -123,11 +123,21 @@
 
     // This accounts for the texture's memory and any MSAA renderbuffer's memory.
     size_t onGpuMemorySize() const override {
-        int numColorSamples = this->numSamples();
-        if (numColorSamples > 1) {
-            // Add one to account for the resolved VkImage.
-            numColorSamples += 1;
+        int numColorSamples = 0;
+        if (this->numSamples() > 1) {
+            // If we have an msaa attachment then its size will be handled by the attachment itself.
+            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(),
                                       numColorSamples, GrMipmapped::kNo);
     }
diff --git a/tools/gpu/vk/VkTestUtils.cpp b/tools/gpu/vk/VkTestUtils.cpp
index caadcda..a3b386b 100644
--- a/tools/gpu/vk/VkTestUtils.cpp
+++ b/tools/gpu/vk/VkTestUtils.cpp
@@ -660,6 +660,12 @@
         if (0 != strncmp(deviceExtensions[i].extensionName, "VK_KHX", 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 ||
                 0 != strcmp(deviceExtensions[i].extensionName, "VK_EXT_buffer_device_address")) {
                 deviceExtensionNames.push_back(deviceExtensions[i].extensionName);