From 1c361ac579b435cbe9d3d90734cf32d30af94d5d Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Fri, 16 Feb 2024 10:39:50 -0800 Subject: [PATCH] Remove comment (#7922) Per https://github.com/zed-industries/zed/pull/7814, this is more trouble than it's worth. As these functions are never exposed to the user of GPUI, we can just manually audit and enforce the relevant rules. Release Notes: - N/A --- crates/gpui/src/platform/linux/blade_atlas.rs | 2 +- crates/gpui/src/platform/linux/blade_belt.rs | 4 ++-- .../gpui/src/platform/linux/blade_renderer.rs | 20 ++++++++++++------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/crates/gpui/src/platform/linux/blade_atlas.rs b/crates/gpui/src/platform/linux/blade_atlas.rs index 188a554dbe..4615666488 100644 --- a/crates/gpui/src/platform/linux/blade_atlas.rs +++ b/crates/gpui/src/platform/linux/blade_atlas.rs @@ -200,7 +200,7 @@ impl BladeAtlasState { } fn upload_texture(&mut self, id: AtlasTextureId, bounds: Bounds, bytes: &[u8]) { - let data = self.upload_belt.alloc_data(bytes, &self.gpu); + let data = unsafe { self.upload_belt.alloc_data(bytes, &self.gpu) }; self.uploads.push(PendingUpload { id, bounds, data }); } diff --git a/crates/gpui/src/platform/linux/blade_belt.rs b/crates/gpui/src/platform/linux/blade_belt.rs index 7145ce2d2c..88f8cf8d80 100644 --- a/crates/gpui/src/platform/linux/blade_belt.rs +++ b/crates/gpui/src/platform/linux/blade_belt.rs @@ -75,8 +75,8 @@ impl BladeBelt { chunk.into() } - //todo!(linux): enforce T: bytemuck::Zeroable - pub fn alloc_data(&mut self, data: &[T], gpu: &gpu::Context) -> gpu::BufferPiece { + // SAFETY: T should be zeroable and ordinary data, no references, pointers, cells or other complicated data type. + pub unsafe fn alloc_data(&mut self, data: &[T], gpu: &gpu::Context) -> gpu::BufferPiece { assert!(!data.is_empty()); let type_alignment = mem::align_of::() as u64; debug_assert_eq!( diff --git a/crates/gpui/src/platform/linux/blade_renderer.rs b/crates/gpui/src/platform/linux/blade_renderer.rs index 35f2765506..5a9beec598 100644 --- a/crates/gpui/src/platform/linux/blade_renderer.rs +++ b/crates/gpui/src/platform/linux/blade_renderer.rs @@ -340,7 +340,7 @@ impl BladeRenderer { pad: [0; 2], }; - let vertex_buf = self.instance_belt.alloc_data(&vertices, &self.gpu); + let vertex_buf = unsafe { self.instance_belt.alloc_data(&vertices, &self.gpu) }; let mut pass = self.command_encoder.render(gpu::RenderTargetSet { colors: &[gpu::RenderTarget { view: tex_info.raw_view, @@ -389,7 +389,8 @@ impl BladeRenderer { for batch in scene.batches() { match batch { PrimitiveBatch::Quads(quads) => { - let instance_buf = self.instance_belt.alloc_data(quads, &self.gpu); + let instance_buf = + unsafe { self.instance_belt.alloc_data(quads, &self.gpu) }; let mut encoder = pass.with(&self.pipelines.quads); encoder.bind( 0, @@ -401,7 +402,8 @@ impl BladeRenderer { encoder.draw(0, 4, 0, quads.len() as u32); } PrimitiveBatch::Shadows(shadows) => { - let instance_buf = self.instance_belt.alloc_data(shadows, &self.gpu); + let instance_buf = + unsafe { self.instance_belt.alloc_data(shadows, &self.gpu) }; let mut encoder = pass.with(&self.pipelines.shadows); encoder.bind( 0, @@ -428,7 +430,8 @@ impl BladeRenderer { tile: (*tile).clone(), }]; - let instance_buf = self.instance_belt.alloc_data(&sprites, &self.gpu); + let instance_buf = + unsafe { self.instance_belt.alloc_data(&sprites, &self.gpu) }; encoder.bind( 0, &ShaderPathsData { @@ -442,7 +445,8 @@ impl BladeRenderer { } } PrimitiveBatch::Underlines(underlines) => { - let instance_buf = self.instance_belt.alloc_data(underlines, &self.gpu); + let instance_buf = + unsafe { self.instance_belt.alloc_data(underlines, &self.gpu) }; let mut encoder = pass.with(&self.pipelines.underlines); encoder.bind( 0, @@ -458,7 +462,8 @@ impl BladeRenderer { sprites, } => { let tex_info = self.atlas.get_texture_info(texture_id); - let instance_buf = self.instance_belt.alloc_data(sprites, &self.gpu); + let instance_buf = + unsafe { self.instance_belt.alloc_data(sprites, &self.gpu) }; let mut encoder = pass.with(&self.pipelines.mono_sprites); encoder.bind( 0, @@ -476,7 +481,8 @@ impl BladeRenderer { sprites, } => { let tex_info = self.atlas.get_texture_info(texture_id); - let instance_buf = self.instance_belt.alloc_data(sprites, &self.gpu); + let instance_buf = + unsafe { self.instance_belt.alloc_data(sprites, &self.gpu) }; let mut encoder = pass.with(&self.pipelines.poly_sprites); encoder.bind( 0,