forked from 1b-agent/opencadstudio-upstream
fix: no GPU allocation path maps, however small the buffer
The previous commit converted the allocations that scale with the
drawing and deliberately left the small fixed-size ones -- uniforms, the
viewcube's static geometry, per-image and per-wipeout quads -- reasoning
that an allocation failure was not a realistic outcome for a few dozen
bytes.
That reasoning was wrong, and the log says so precisely. On the
reproducer the vertex buffers degraded exactly as intended:
[gpu] uncaptured ... Out of Memory
[gpu] uncaptured ... In Queue::write_buffer
Buffer with 'block_wire.vertices' label is invalid
... errors #4 #8 #16 #32 #64 #128, session kept alive
and then the process died here:
thread 'main' panicked at wgpu_core.rs:2253:
Error in Buffer::get_mapped_range: Validation Error
Caused by: Buffer with 'block_wire.const' label is invalid
'block_wire.const' is a single uniform struct. Once the device is out of
memory every allocation fails, including a 32-byte one, and
create_buffer_init maps it and panics. Size was never the relevant
property -- whether the path maps is.
So every remaining allocation goes through gpu_upload too: block-wire
const, the viewcube's seven buffers, the blit and clip-boundary buffers,
image instances/params/vertices, mesh material params and surface and the
empty index stub, the texture-hatch uniform, and all five wipeout
buffers. `grep -r create_buffer_init src` now finds only a comment, and
no mapped_at_creation:true remains outside gpu_upload's own docs.
`queue` is threaded through the last holdouts: upload_wipeouts,
upload_clip_boundary, MeshBatchStubs::new and
create_material_bind_group_from_resources.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0d11421dea
commit
6747d7125e
8 files changed
+181
-129
No files matched your search
@@ -1078,43 +1078,54 @@ pub struct ViewCubePipeline {
|
||||
|
||||
impl ViewCubePipeline {
|
||||
pub fn new(device: &wgpu::Device, queue: &wgpu::Queue, format: wgpu::TextureFormat) -> Self {
|
||||
use wgpu::util::DeviceExt;
|
||||
let (verts, idxs) = build_geometry();
|
||||
let line_verts = surface_edge_lines(&verts, &idxs);
|
||||
let (ring_verts, ring_idxs) = build_ring_geometry();
|
||||
let ring_line_verts = surface_edge_lines(&ring_verts, &ring_idxs);
|
||||
let cube_px = VIEWCUBE_PX;
|
||||
let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("vc.vb"),
|
||||
contents: bytemuck::cast_slice(&verts),
|
||||
usage: wgpu::BufferUsages::VERTEX,
|
||||
});
|
||||
let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("vc.ib"),
|
||||
contents: bytemuck::cast_slice(&idxs),
|
||||
usage: wgpu::BufferUsages::INDEX,
|
||||
});
|
||||
let line_vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("vc.line_vb"),
|
||||
contents: bytemuck::cast_slice(&line_verts),
|
||||
usage: wgpu::BufferUsages::VERTEX,
|
||||
});
|
||||
let ring_vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("vc.ring_vb"),
|
||||
contents: bytemuck::cast_slice(&ring_verts),
|
||||
usage: wgpu::BufferUsages::VERTEX,
|
||||
});
|
||||
let ring_index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("vc.ring_ib"),
|
||||
contents: bytemuck::cast_slice(&ring_idxs),
|
||||
usage: wgpu::BufferUsages::INDEX,
|
||||
});
|
||||
let vertex_buffer = super::gpu_upload::upload_buffer(
|
||||
device,
|
||||
queue,
|
||||
"vc.vb",
|
||||
&verts,
|
||||
wgpu::BufferUsages::VERTEX,
|
||||
);
|
||||
let index_buffer = super::gpu_upload::upload_buffer(
|
||||
device,
|
||||
queue,
|
||||
"vc.ib",
|
||||
&idxs,
|
||||
wgpu::BufferUsages::INDEX,
|
||||
);
|
||||
let line_vertex_buffer = super::gpu_upload::upload_buffer(
|
||||
device,
|
||||
queue,
|
||||
"vc.line_vb",
|
||||
&line_verts,
|
||||
wgpu::BufferUsages::VERTEX,
|
||||
);
|
||||
let ring_vertex_buffer = super::gpu_upload::upload_buffer(
|
||||
device,
|
||||
queue,
|
||||
"vc.ring_vb",
|
||||
&ring_verts,
|
||||
wgpu::BufferUsages::VERTEX,
|
||||
);
|
||||
let ring_index_buffer = super::gpu_upload::upload_buffer(
|
||||
device,
|
||||
queue,
|
||||
"vc.ring_ib",
|
||||
&ring_idxs,
|
||||
wgpu::BufferUsages::INDEX,
|
||||
);
|
||||
let ring_line_vertex_buffer =
|
||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("vc.ring_line_vb"),
|
||||
contents: bytemuck::cast_slice(&ring_line_verts),
|
||||
usage: wgpu::BufferUsages::VERTEX,
|
||||
});
|
||||
super::gpu_upload::upload_buffer(
|
||||
device,
|
||||
queue,
|
||||
"vc.ring_line_vb",
|
||||
&ring_line_verts,
|
||||
wgpu::BufferUsages::VERTEX,
|
||||
);
|
||||
let uniform_buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: Some("vc.ub"),
|
||||
size: std::mem::size_of::<CubeUniforms>() as u64,
|
||||
@@ -1291,11 +1302,13 @@ impl ViewCubePipeline {
|
||||
],
|
||||
});
|
||||
let composite_uniform_buffer =
|
||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("vc.composite_uniform"),
|
||||
contents: bytemuck::cast_slice(&[1.0f32, 1.0, 0.0, 0.0]),
|
||||
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||
});
|
||||
super::gpu_upload::upload_buffer(
|
||||
device,
|
||||
queue,
|
||||
"vc.composite_uniform",
|
||||
&[1.0f32, 1.0, 0.0, 0.0],
|
||||
wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||
);
|
||||
let composite_sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||
label: Some("vc.composite_sampler"),
|
||||
mag_filter: wgpu::FilterMode::Nearest,
|
||||
|
||||
Reference in new issue
Block a user