Commit 4c76ab02 authored by Kramer Ge's avatar Kramer Ge Committed by Commit Bot

SkiaOutputDeviceVulkan tracks backendTexture of GrBackendRenderTarget

OS API creates vulkan swapchain images as render targets. Estimate the allocated
GPU resource with vkGetImageMemoryRequirements.

Bug: 899905
Change-Id: I162ab641c3e13a10fa29e8e8860dee06b2598a79
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1967552Reviewed-by: default avatarPeng Huang <penghuang@chromium.org>
Commit-Queue: Kramer Ge <fangzhoug@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726586}
parent 3affb50a
...@@ -8,8 +8,10 @@ ...@@ -8,8 +8,10 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "components/viz/common/gpu/vulkan_context_provider.h" #include "components/viz/common/gpu/vulkan_context_provider.h"
#include "gpu/command_buffer/service/memory_tracking.h"
#include "gpu/ipc/common/gpu_surface_lookup.h" #include "gpu/ipc/common/gpu_surface_lookup.h"
#include "gpu/vulkan/vulkan_fence_helper.h" #include "gpu/vulkan/vulkan_fence_helper.h"
#include "gpu/vulkan/vulkan_function_pointers.h"
#include "gpu/vulkan/vulkan_implementation.h" #include "gpu/vulkan/vulkan_implementation.h"
#include "gpu/vulkan/vulkan_surface.h" #include "gpu/vulkan/vulkan_surface.h"
#include "third_party/skia/include/core/SkSurface.h" #include "third_party/skia/include/core/SkSurface.h"
...@@ -41,6 +43,10 @@ SkiaOutputDeviceVulkan::~SkiaOutputDeviceVulkan() { ...@@ -41,6 +43,10 @@ SkiaOutputDeviceVulkan::~SkiaOutputDeviceVulkan() {
fence_helper->EnqueueVulkanObjectCleanupForSubmittedWork( fence_helper->EnqueueVulkanObjectCleanupForSubmittedWork(
std::move(vulkan_surface_)); std::move(vulkan_surface_));
} }
for (auto it = sk_surface_size_pairs_.begin();
it != sk_surface_size_pairs_.end(); ++it) {
memory_type_tracker_->TrackMemFree(it->bytes_allocated);
}
} }
bool SkiaOutputDeviceVulkan::Reshape(const gfx::Size& size, bool SkiaOutputDeviceVulkan::Reshape(const gfx::Size& size,
...@@ -64,8 +70,12 @@ bool SkiaOutputDeviceVulkan::Reshape(const gfx::Size& size, ...@@ -64,8 +70,12 @@ bool SkiaOutputDeviceVulkan::Reshape(const gfx::Size& size,
if (vulkan_surface_->swap_chain_generation() != generation || if (vulkan_surface_->swap_chain_generation() != generation ||
!SkColorSpace::Equals(sk_color_space.get(), sk_color_space_.get())) { !SkColorSpace::Equals(sk_color_space.get(), sk_color_space_.get())) {
// swapchain is changed, we need recreate all cached sk surfaces. // swapchain is changed, we need recreate all cached sk surfaces.
sk_surfaces_.clear(); for (auto it = sk_surface_size_pairs_.begin();
sk_surfaces_.resize(vulkan_surface_->swap_chain()->num_images()); it != sk_surface_size_pairs_.end(); ++it) {
memory_type_tracker_->TrackMemFree(it->bytes_allocated);
}
sk_surface_size_pairs_.clear();
sk_surface_size_pairs_.resize(vulkan_surface_->swap_chain()->num_images());
sk_color_space_ = std::move(sk_color_space); sk_color_space_ = std::move(sk_color_space);
} }
return true; return true;
...@@ -93,7 +103,8 @@ SkSurface* SkiaOutputDeviceVulkan::BeginPaint() { ...@@ -93,7 +103,8 @@ SkSurface* SkiaOutputDeviceVulkan::BeginPaint() {
scoped_write_.reset(); scoped_write_.reset();
return nullptr; return nullptr;
} }
auto& sk_surface = sk_surfaces_[scoped_write_->image_index()]; auto& sk_surface =
sk_surface_size_pairs_[scoped_write_->image_index()].sk_surface;
if (!sk_surface) { if (!sk_surface) {
SkSurfaceProps surface_props = SkSurfaceProps surface_props =
...@@ -112,6 +123,16 @@ SkSurface* SkiaOutputDeviceVulkan::BeginPaint() { ...@@ -112,6 +123,16 @@ SkSurface* SkiaOutputDeviceVulkan::BeginPaint() {
GrBackendRenderTarget render_target(vk_image_size.width(), GrBackendRenderTarget render_target(vk_image_size.width(),
vk_image_size.height(), vk_image_size.height(),
0 /* sample_cnt */, vk_image_info); 0 /* sample_cnt */, vk_image_info);
// Estimate size of GPU memory needed for the GrBackendRenderTarget.
VkMemoryRequirements requirements;
vkGetImageMemoryRequirements(
context_provider_->GetDeviceQueue()->GetVulkanDevice(),
vk_image_info.fImage, &requirements);
sk_surface_size_pairs_[scoped_write_->image_index()].bytes_allocated =
requirements.size;
memory_type_tracker_->TrackMemAlloc(requirements.size);
auto sk_color_type = surface_format == VK_FORMAT_B8G8R8A8_UNORM auto sk_color_type = surface_format == VK_FORMAT_B8G8R8A8_UNORM
? kBGRA_8888_SkColorType ? kBGRA_8888_SkColorType
: kRGBA_8888_SkColorType; : kRGBA_8888_SkColorType;
...@@ -138,7 +159,8 @@ SkSurface* SkiaOutputDeviceVulkan::BeginPaint() { ...@@ -138,7 +159,8 @@ SkSurface* SkiaOutputDeviceVulkan::BeginPaint() {
void SkiaOutputDeviceVulkan::EndPaint(const GrBackendSemaphore& semaphore) { void SkiaOutputDeviceVulkan::EndPaint(const GrBackendSemaphore& semaphore) {
DCHECK(scoped_write_); DCHECK(scoped_write_);
auto& sk_surface = sk_surfaces_[scoped_write_->image_index()]; auto& sk_surface =
sk_surface_size_pairs_[scoped_write_->image_index()].sk_surface;
auto backend = sk_surface->getBackendRenderTarget( auto backend = sk_surface->getBackendRenderTarget(
SkSurface::kFlushRead_BackendHandleAccess); SkSurface::kFlushRead_BackendHandleAccess);
GrVkImageInfo vk_image_info; GrVkImageInfo vk_image_info;
...@@ -176,4 +198,9 @@ bool SkiaOutputDeviceVulkan::CreateVulkanSurface() { ...@@ -176,4 +198,9 @@ bool SkiaOutputDeviceVulkan::CreateVulkanSurface() {
return true; return true;
} }
SkiaOutputDeviceVulkan::SkSurfaceSizePair::SkSurfaceSizePair() = default;
SkiaOutputDeviceVulkan::SkSurfaceSizePair::SkSurfaceSizePair(
const SkSurfaceSizePair& other) = default;
SkiaOutputDeviceVulkan::SkSurfaceSizePair::~SkSurfaceSizePair() = default;
} // namespace viz } // namespace viz
...@@ -43,6 +43,15 @@ class SkiaOutputDeviceVulkan final : public SkiaOutputDevice { ...@@ -43,6 +43,15 @@ class SkiaOutputDeviceVulkan final : public SkiaOutputDevice {
void EndPaint(const GrBackendSemaphore& semaphore) override; void EndPaint(const GrBackendSemaphore& semaphore) override;
private: private:
struct SkSurfaceSizePair {
public:
SkSurfaceSizePair();
SkSurfaceSizePair(const SkSurfaceSizePair& other);
~SkSurfaceSizePair();
sk_sp<SkSurface> sk_surface;
uint64_t bytes_allocated = 0u;
};
bool CreateVulkanSurface(); bool CreateVulkanSurface();
void CreateSkSurface(); void CreateSkSurface();
...@@ -54,7 +63,7 @@ class SkiaOutputDeviceVulkan final : public SkiaOutputDevice { ...@@ -54,7 +63,7 @@ class SkiaOutputDeviceVulkan final : public SkiaOutputDevice {
base::Optional<gpu::VulkanSwapChain::ScopedWrite> scoped_write_; base::Optional<gpu::VulkanSwapChain::ScopedWrite> scoped_write_;
// SkSurfaces for swap chain images. // SkSurfaces for swap chain images.
std::vector<sk_sp<SkSurface>> sk_surfaces_; std::vector<SkSurfaceSizePair> sk_surface_size_pairs_;
sk_sp<SkColorSpace> sk_color_space_; sk_sp<SkColorSpace> sk_color_space_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment