feat(deno): Associate external memory with GPUDevice

Enable some tests that previously OOMed in CI.
This commit is contained in:
Andy Leiserson committed 2026-01-27 13:11:40 -08:00
1 parent 77c614c628
commit 965b7cbe79
3 files changed
+38 -13

No files matched your search

+6 -8
View File
@@ -17,7 +17,6 @@ fails-if(vulkan) webgpu:api,operation,command_buffer,copyTextureToTexture:copy_d
fails-if(vulkan) webgpu:api,operation,command_buffer,copyTextureToTexture:copy_depth_stencil:format="depth32float"
fails-if(vulkan) webgpu:api,operation,command_buffer,copyTextureToTexture:copy_depth_stencil:format="depth32float-stencil8"
webgpu:api,operation,command_buffer,copyTextureToTexture:copy_depth_stencil:format="stencil8"
// Fails with OOM in CI.
fails-if(dx12) webgpu:api,operation,command_buffer,image_copy:offsets_and_sizes:*
webgpu:api,operation,command_buffer,image_copy:undefined_params:initMethod="CopyB2T";checkMethod="FullCopyT2B";dimension="1d"
webgpu:api,operation,command_buffer,image_copy:undefined_params:initMethod="CopyB2T";checkMethod="FullCopyT2B";dimension="2d"
@@ -54,12 +53,12 @@ webgpu:api,operation,vertex_state,correctness:setVertexBuffer_offset_and_attribu
webgpu:api,validation,buffer,create:*
webgpu:api,validation,buffer,destroy:*
// Limit tests fail with OOM in CI.
fails-if(dx12) webgpu:api,validation,capability_checks,limits,maxBindGroups:setBindGroup,*
webgpu:api,validation,capability_checks,limits,maxBindGroups:setBindGroup,*
//FAIL: other `maxInterStageShaderVariables` cases w/ limitTest ∈ [underDefault, overMaximum]
fails-if(dx12) webgpu:api,validation,capability_checks,limits,maxInterStageShaderVariables:createRenderPipeline,at_over:limitTest="atDefault";*
fails-if(dx12) webgpu:api,validation,capability_checks,limits,maxInterStageShaderVariables:createRenderPipeline,at_over:limitTest="atMaximum";*
fails-if(dx12) webgpu:api,validation,capability_checks,limits,maxInterStageShaderVariables:createRenderPipeline,at_over:limitTest="betweenDefaultAndMaximum";*
// https://github.com/gfx-rs/wgpu/issues/8945
webgpu:api,validation,capability_checks,limits,maxInterStageShaderVariables:createRenderPipeline,at_over:limitTest="atDefault";*
webgpu:api,validation,capability_checks,limits,maxInterStageShaderVariables:createRenderPipeline,at_over:limitTest="atMaximum";*
webgpu:api,validation,capability_checks,limits,maxInterStageShaderVariables:createRenderPipeline,at_over:limitTest="betweenDefaultAndMaximum";*
webgpu:api,validation,createBindGroup:binding_must_contain_resource_defined_in_layout:*
webgpu:api,validation,createBindGroup:buffer_offset_and_size_for_bind_groups_match:*
webgpu:api,validation,createBindGroup:buffer,effective_buffer_binding_size:*
@@ -150,8 +149,7 @@ fails-if(dx12) webgpu:api,validation,image_copy,buffer_texture_copies:offset_and
webgpu:api,validation,image_copy,buffer_texture_copies:sample_count:*
webgpu:api,validation,image_copy,buffer_texture_copies:texture_buffer_usages:*
webgpu:api,validation,image_copy,layout_related:copy_end_overflows_u64:*
// Fails with OOM in CI.
fails-if(dx12) webgpu:api,validation,image_copy,layout_related:offset_alignment:*
webgpu:api,validation,image_copy,layout_related:offset_alignment:*
webgpu:api,validation,image_copy,texture_related:*
webgpu:api,validation,queue,buffer_mapped:copyBufferToBuffer:*
webgpu:api,validation,queue,buffer_mapped:copyBufferToTexture:*
+23 -5
View File
@@ -13,6 +13,7 @@ use deno_core::V8TaskSpawner;
use deno_core::WebIDL;
use super::device::GPUDevice;
use super::device::DEVICE_EXTERNAL_MEMORY_SIZE;
use super::queue::GPUQueue;
use crate::error::GPUGenericError;
use crate::webidl::features_to_feature_names;
@@ -161,6 +162,11 @@ impl GPUAdapter {
None,
)?;
// Associate external memory with the device to encourage V8 to garbage
// collect devices promptly.
scope
.adjust_amount_of_external_allocated_memory(DEVICE_EXTERNAL_MEMORY_SIZE);
let spawner = state.borrow::<V8TaskSpawner>().clone();
let lost_resolver = v8::PromiseResolver::new(scope).unwrap();
let lost_promise = lost_resolver.get_promise(scope);
@@ -195,6 +201,7 @@ impl GPUAdapter {
lost_promise: v8::Global::new(scope, lost_promise),
limits: SameObject::new(),
features: SameObject::new(),
weak: std::sync::OnceLock::new(),
};
let device = deno_core::cppgc::make_cppgc_object(scope, device);
let weak_device = v8::Weak::new(scope, device);
@@ -207,13 +214,24 @@ impl GPUAdapter {
let null = v8::null(scope);
set_event_target_data.call(scope, null.into(), &[device.into()]);
let finalizer = v8::Weak::with_finalizer(
scope,
device,
Box::new(move |isolate| {
isolate.adjust_amount_of_external_allocated_memory(
-DEVICE_EXTERNAL_MEMORY_SIZE,
);
}),
);
// Now that the device is fully constructed, give the error handler a
// weak reference to it.
// weak reference to it, and store the finalizer weak reference.
let device = device.cast::<v8::Value>();
deno_core::cppgc::try_unwrap_cppgc_object::<GPUDevice>(scope, device)
.unwrap()
.error_handler
.set_device(weak_device);
let device_ref =
deno_core::cppgc::try_unwrap_cppgc_object::<GPUDevice>(scope, device)
.unwrap();
device_ref.error_handler.set_device(weak_device);
device_ref.weak.set(finalizer).unwrap();
Ok(v8::Global::new(scope, device))
}
+9
View File
@@ -37,6 +37,12 @@ use crate::shader::GPUCompilationInfo;
use crate::webidl::features_to_feature_names;
use crate::Instance;
/// External memory associated with device and queue, to encourage V8 to garbage
/// collect devices promptly. This seems to be particularly important when
/// running CTS tests under `webgpu:api,validation,capability_checks,limits,*`
/// on DX12 in wgpu CI, where any smaller power of two results in OOM errors.
pub(crate) const DEVICE_EXTERNAL_MEMORY_SIZE: i64 = 1 << 24; // 16 MB
pub struct GPUDevice {
pub instance: Instance,
pub id: wgpu_core::id::DeviceId,
@@ -52,6 +58,9 @@ pub struct GPUDevice {
pub error_handler: super::error::ErrorHandler,
pub lost_promise: v8::Global<v8::Promise>,
// Weak reference to the JS object so we can attach a finalizer.
pub(crate) weak: std::sync::OnceLock<v8::Weak<v8::Object>>,
}
impl Drop for GPUDevice {