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

Fix handle allocation #539

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion rend3/src/managers/skeleton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ impl SkeletonManager {
})
}

#[allow(clippy::too_many_arguments)]
pub fn add(&mut self, handle: &SkeletonHandle, internal: InternalSkeleton) {
self.global_joint_count += internal.joint_matrices.len();

Expand Down
18 changes: 12 additions & 6 deletions rend3/src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,12 @@ impl Renderer {
/// the mesh alive.
#[track_caller]
pub fn add_mesh(self: &Arc<Self>, mesh: Mesh) -> Result<MeshHandle, MeshCreationError> {
let handle = self.resource_handle_allocators.mesh.allocate(self);

let mut encoder = self.device.create_command_encoder(&CommandEncoderDescriptor::default());
let internal_mesh = self.mesh_manager.add(&self.device, &self.queue, &mut encoder, mesh)?;

// Handle allocation must be done _after_ any validation to prevent deletion of a handle that never gets fully added.
let handle = self.resource_handle_allocators.mesh.allocate(self);

self.instructions.push(
InstructionKind::AddMesh {
handle: handle.clone(),
Expand All @@ -165,11 +166,12 @@ impl Renderer {
/// references alive.
#[track_caller]
pub fn add_skeleton(self: &Arc<Self>, skeleton: Skeleton) -> Result<SkeletonHandle, SkeletonCreationError> {
let handle = self.resource_handle_allocators.skeleton.allocate(self);

let mut encoder = self.device.create_command_encoder(&CommandEncoderDescriptor::default());
let internal = SkeletonManager::validate_skeleton(&self.device, &mut encoder, &self.mesh_manager, skeleton)?;

// Handle allocation must be done _after_ any validation to prevent deletion of a handle that never gets fully added.
let handle = self.resource_handle_allocators.skeleton.allocate(self);

self.instructions.push(
InstructionKind::AddSkeleton {
handle: handle.clone(),
Expand All @@ -189,9 +191,11 @@ impl Renderer {
pub fn add_texture_2d(self: &Arc<Self>, texture: Texture) -> Result<Texture2DHandle, TextureCreationError> {
profiling::scope!("Add Texture 2D");

let handle = self.resource_handle_allocators.d2_texture.allocate(self);
let (cmd_buf, internal_texture) = TextureManager::<Texture2DTag>::add(self, texture, false)?;

// Handle allocation must be done _after_ any validation to prevent deletion of a handle that never gets fully added.
let handle = self.resource_handle_allocators.d2_texture.allocate(self);

self.instructions.push(
InstructionKind::AddTexture2D {
handle: handle.clone(),
Expand Down Expand Up @@ -234,9 +238,11 @@ impl Renderer {
pub fn add_texture_cube(self: &Arc<Self>, texture: Texture) -> Result<TextureCubeHandle, TextureCreationError> {
profiling::scope!("Add Texture Cube");

let handle = self.resource_handle_allocators.d2c_texture.allocate(self);
let (cmd_buf, internal_texture) = TextureManager::<TextureCubeTag>::add(self, texture, true)?;

// Handle allocation must be done _after_ any validation to prevent deletion of a handle that never gets fully added.
let handle = self.resource_handle_allocators.d2c_texture.allocate(self);

self.instructions.push(
InstructionKind::AddTextureCube {
handle: handle.clone(),
Expand Down
Loading