Files
test/source/blender/gpu/intern/gpu_backend.hh
Jason Fielder 81f9df606a Fix #130700: Release Metal resources after each frame when rendering Python animations.
Rendering animations from Python scripts via `bpy.ops.render.opengl()`
did not trigger any of the notifications in the Metal back-end to
indicate a frame had been rendered and that the associated resources
could be released. This adds a call to GPU_render_step() after each
render. For the original asset in the bug report this reduces the high
memory watermark from 30gb to 13gb for 500 frames. 13gb is likely
still too high and therefore it is likely there are additional leaks
that need to be addressed so this should only be considered a partial
fix.

Authored by Apple: James McCarthy

Co-authored-by: James McCarthy <jamesmccarthy@apple.com>
Co-authored-by: Clément Foucault <foucault.clem@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/131085
2024-12-12 20:30:18 +01:00

99 lines
2.7 KiB
C++

/* SPDX-FileCopyrightText: 2020 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup gpu
*
* GPUBackend derived class contain allocators that do not need a context bound.
* The backend is init at startup and is accessible using GPU_backend_get() */
#pragma once
#include "BLI_color.hh"
#include "BLI_string_ref.hh"
#include "GPU_vertex_buffer.hh"
namespace blender::gpu {
class Context;
class Batch;
class Fence;
class FrameBuffer;
class IndexBuf;
class PixelBuffer;
class QueryPool;
class Shader;
class Texture;
class UniformBuf;
class StorageBuf;
class VertBuf;
class GPUBackend {
public:
virtual ~GPUBackend() = default;
virtual void delete_resources() = 0;
static GPUBackend *get();
virtual void samplers_update() = 0;
virtual void compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len) = 0;
virtual void compute_dispatch_indirect(StorageBuf *indirect_buf) = 0;
virtual Context *context_alloc(void *ghost_window, void *ghost_context) = 0;
virtual Batch *batch_alloc() = 0;
virtual Fence *fence_alloc() = 0;
virtual FrameBuffer *framebuffer_alloc(const char *name) = 0;
virtual IndexBuf *indexbuf_alloc() = 0;
virtual PixelBuffer *pixelbuf_alloc(size_t size) = 0;
virtual QueryPool *querypool_alloc() = 0;
virtual Shader *shader_alloc(const char *name) = 0;
virtual Texture *texture_alloc(const char *name) = 0;
virtual UniformBuf *uniformbuf_alloc(size_t size, const char *name) = 0;
virtual StorageBuf *storagebuf_alloc(size_t size, GPUUsageType usage, const char *name) = 0;
virtual VertBuf *vertbuf_alloc() = 0;
virtual void shader_cache_dir_clear_old() = 0;
/* Render Frame Coordination --
* Used for performing per-frame actions globally */
virtual void render_begin() = 0;
virtual void render_end() = 0;
virtual void render_step(bool force_resource_release = false) = 0;
};
namespace debug {
static blender::ColorTheme4f GPU_DEBUG_GROUP_COLOR_DEFAULT = {};
static inline ColorTheme4f get_debug_group_color(StringRefNull name)
{
if (name == "EEVEE") {
return ColorTheme4f(1.0, 0.5, 0.0, 1.0);
}
else if (name == "External") {
return ColorTheme4f(0.0, 0.0, 1.0, 1.0);
}
else if (name == "GpencilMode") {
return ColorTheme4f(1.0, 1.0, 0.0, 1.0);
}
else if (name == "UV/Image") {
return ColorTheme4f(0.0, 1.0, 1.0, 1.0);
}
else if (name == "Overlay") {
return ColorTheme4f(0.0, 1.0, 0.5, 1.0);
}
else if (name == "Workbench") {
return ColorTheme4f(0.0, 0.7, 1.0, 1.0);
}
else if (name == "Cycles") {
return ColorTheme4f(0.0, 0.5, 1.0, 1.0);
}
else {
return GPU_DEBUG_GROUP_COLOR_DEFAULT;
}
}
} // namespace debug
} // namespace blender::gpu