Skip to content

Commit

Permalink
Show memory report in debug builds (#187)
Browse files Browse the repository at this point in the history
* Show memory report in debug builds

log::debug!() after wgpuSwapChainPresent(); assumed to be called roughly once
per frame; useful for detecting memory leaks

* wgpuGetResourceUsageString()

Returns resource usage as C string
  • Loading branch information
sqaxomonophonen authored May 8, 2022
1 parent 1a47510 commit 3a6d1d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ffi/wgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ void wgpuSetLogLevel(WGPULogLevel level);

uint32_t wgpuGetVersion(void);

// Returns resource usage C string; caller owns the string and must free() it
char* wgpuGetResourceUsageString();

void wgpuRenderPassEncoderSetPushConstants(WGPURenderPassEncoder encoder, WGPUShaderStageFlags stages, uint32_t offset, uint32_t sizeBytes, void* const data);

void wgpuBufferDrop(WGPUBuffer buffer);
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ pub extern "C" fn wgpuCreateInstance(
8 as native::WGPUInstance
}

#[no_mangle]
pub extern "C" fn wgpuGetResourceUsageString() -> *const std::os::raw::c_char {
let c_string = CString::new(format!("{:?}", GLOBAL.generate_report())).unwrap();
let ptr = c_string.as_ptr();
std::mem::forget(c_string);
ptr
}

#[no_mangle]
pub unsafe extern "C" fn wgpuInstanceCreateSurface(
_: native::WGPUInstance,
Expand Down

0 comments on commit 3a6d1d9

Please sign in to comment.