ability to fetch memory usage by the graphics server

This commit is contained in:
Dmitry Stepanov
2025-06-19 23:52:04 +03:00
parent a40704ce80
commit ea3d0914ac
5 changed files with 89 additions and 50 deletions
+3 -2
View File
@@ -497,14 +497,15 @@ define_as_any_trait!(GpuTextureAsAny => GpuTextureTrait);
/// ```
pub trait GpuTextureTrait: GpuTextureAsAny {
/// Sets the new data of the texture. This method is also able to change the kind of the texture
/// and its pixel kind.
/// and its pixel kind. Returns the number of bytes occupied by the texture in the video memory.
/// If there's no data specified, the texture will still take the space defined by its metrics.
fn set_data(
&self,
kind: GpuTextureKind,
pixel_kind: PixelKind,
mip_count: usize,
data: Option<&[u8]>,
) -> Result<(), FrameworkError>;
) -> Result<usize, FrameworkError>;
/// Returns kind of the texture.
fn kind(&self) -> GpuTextureKind;
+15
View File
@@ -51,6 +51,18 @@ pub struct ServerCapabilities {
pub max_lod_bias: f32,
}
/// Contains information about used memory per each category of GPU resource. This is not precise
/// data; it only calculates total requested memory by the user of a graphics server and does not
/// include additional memory overhead in the video driver. Yet this information could still be
/// useful.
#[derive(Default, Debug, Clone)]
pub struct ServerMemoryUsage {
/// Total number of bytes used by all textures (including render targets).
pub textures: usize,
/// Total number of bytes used by all buffers (vertex, index, uniform, etc.)
pub buffers: usize,
}
/// A shared reference to a graphics server.
pub type SharedGraphicsServer = Rc<dyn GraphicsServer>;
@@ -168,6 +180,9 @@ pub trait GraphicsServer: GraphicsServerAsAny {
/// way of mipmaps generation, depending on the underlying GAPI capabilities.
fn generate_mipmap(&self, texture: &GpuTexture);
/// Fetches the total amount of memory used by the graphics server.
fn memory_usage(&self) -> ServerMemoryUsage;
/// A shortcut for [`Self::create_texture`], that creates a rectangular texture with the given
/// size and pixel kind.
fn create_2d_render_target(