Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move more code into methods on wgpu-core objects #6391

Merged
merged 15 commits into from
Oct 14, 2024
Merged
1 change: 0 additions & 1 deletion deno_webgpu/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ pub fn op_webgpu_surface_get_current_texture(
let rid = state.resource_table.add(crate::texture::WebGpuTexture {
instance: instance.clone(),
id,
owned: false,
});
Ok(WebGpuResult::rid(rid))
}
Expand Down
8 changes: 2 additions & 6 deletions deno_webgpu/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use super::error::WebGpuResult;
pub(crate) struct WebGpuTexture {
pub(crate) instance: crate::Instance,
pub(crate) id: wgpu_core::id::TextureId,
pub(crate) owned: bool,
}

impl Resource for WebGpuTexture {
Expand All @@ -22,10 +21,8 @@ impl Resource for WebGpuTexture {
}

fn close(self: Rc<Self>) {
if self.owned {
let instance = &self.instance;
instance.texture_drop(self.id);
}
let instance = &self.instance;
instance.texture_drop(self.id);
}
}

Expand Down Expand Up @@ -85,7 +82,6 @@ pub fn op_webgpu_create_texture(
let rid = state.resource_table.add(WebGpuTexture {
instance: instance.clone(),
id: val,
owned: true,
});

Ok(WebGpuResult::rid_err(rid, maybe_err))
Expand Down
12 changes: 5 additions & 7 deletions wgpu-core/src/command/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ pub enum TransferError {
MissingBufferUsage(#[from] MissingBufferUsageError),
#[error(transparent)]
MissingTextureUsage(#[from] MissingTextureUsageError),
#[error("Destination texture is missing the `RENDER_ATTACHMENT` usage flag")]
MissingRenderAttachmentUsageFlag(TextureId),
#[error("Copy of {start_offset}..{end_offset} would end up overrunning the bounds of the {side:?} buffer of size {buffer_size}")]
BufferOverrun {
start_offset: BufferAddress,
Expand All @@ -72,7 +70,7 @@ pub enum TransferError {
#[error("Unable to select texture mip level {level} out of {total}")]
InvalidTextureMipLevel { level: u32, total: u32 },
#[error("Texture dimension must be 2D when copying from an external texture")]
InvalidDimensionExternal(TextureId),
InvalidDimensionExternal,
#[error("Buffer offset {0} is not aligned to block size or `COPY_BUFFER_ALIGNMENT`")]
UnalignedBufferOffset(BufferAddress),
#[error("Copy size {0} does not respect `COPY_BUFFER_ALIGNMENT`")]
Expand Down Expand Up @@ -156,8 +154,8 @@ impl From<DeviceError> for CopyError {
}
}

pub(crate) fn extract_texture_selector(
copy_texture: &ImageCopyTexture,
pub(crate) fn extract_texture_selector<T>(
copy_texture: &wgt::ImageCopyTexture<T>,
copy_size: &Extent3d,
texture: &Texture,
) -> Result<(TextureSelector, hal::TextureCopyBase), TransferError> {
Expand Down Expand Up @@ -314,8 +312,8 @@ pub(crate) fn validate_linear_texture_data(
/// Returns the HAL copy extent and the layer count.
///
/// [vtcr]: https://gpuweb.github.io/gpuweb/#validating-texture-copy-range
pub(crate) fn validate_texture_copy_range(
texture_copy_view: &ImageCopyTexture,
pub(crate) fn validate_texture_copy_range<T>(
texture_copy_view: &wgt::ImageCopyTexture<T>,
desc: &wgt::TextureDescriptor<(), Vec<wgt::TextureFormat>>,
texture_side: CopySide,
copy_size: &Extent3d,
Expand Down
Loading