@@ -110,8 +110,40 @@ bool GraphiteGpuContext::isAbandonedOrDeviceLost() {
110110 return mContext ->isDeviceLost ();
111111}
112112
113+ void GraphiteGpuContext::setResourceCacheLimit (size_t maxResourceBytes) {
114+ // Graphite has a separate budget for its Context and its Recorder. For now the majority of
115+ // memory that Graphite will allocate will be on the Recorder and minimal amount on the Context.
116+ // The main allocations on the Context are MSAA buffers (not often, if ever used in
117+ // RenderEngine) and stencil buffers. However, both of these should be "memoryless" in Vulkan on
118+ // tiled GPUs, so they don't actually use GPU memory. However, in Vulkan there are scenarios
119+ // where Vulkan could end up using real memory for them. Skia will regularly query the device to
120+ // get the real memory usage and update the budgeted appropriately. Though for all real usage
121+ // patterns we don't expect to ever trigger the device to allocate real memory.
122+ //
123+ // Therefore, we set the full maxResourceBytes budget on the Recorder. However, in the rare
124+ // chance that the devcies does allocate real memory we don't want to immediately kill device
125+ // performance by constantly trashing allocations on the Context. Thus we set the Context's
126+ // budget to be 50% of the total budget to make sure we allow the MSAA or Stencil buffers to be
127+ // allocated in Skia and not immediately discarded. But even with this extra 50% budget, as
128+ // described above, this shouldn't result in actual GPU memory usage.
129+ //
130+ // TODO: We will need to revise this strategy for GLES which does not have the same memoryless
131+ // textures.
132+ // TODO: Work in Graphite has started to move a lot more of its scratch resources to be owned
133+ // by the Context and not on Recorders. This will mean most memory is actually owned by the
134+ // Context and thus the budgeting here will need to be updated.
135+ mContext ->setMaxBudgetedBytes (maxResourceBytes / 2 );
136+ mRecorder ->setMaxBudgetedBytes (maxResourceBytes);
137+ }
138+
139+ void GraphiteGpuContext::purgeUnlockedScratchResources () {
140+ mContext ->freeGpuResources ();
141+ mRecorder ->freeGpuResources ();
142+ }
143+
113144void GraphiteGpuContext::dumpMemoryStatistics (SkTraceMemoryDump* traceMemoryDump) const {
114145 mContext ->dumpMemoryStatistics (traceMemoryDump);
146+ mRecorder ->dumpMemoryStatistics (traceMemoryDump);
115147}
116148
117149} // namespace android::renderengine::skia
0 commit comments