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

Use range-based state tracking for SyncCommandBuffer #1862

Merged
merged 3 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Use range-based state tracking for SyncCommandBufferBuilder
  • Loading branch information
Rua committed Mar 18, 2022
commit 68a63b36036547e4f58302cc598c4feb324d4f5d
18 changes: 13 additions & 5 deletions vulkano/src/buffer/cpu_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ where
T: BufferContents + ?Sized,
{
// Inner content.
inner: UnsafeBuffer,
inner: Arc<UnsafeBuffer>,

// The memory held by the buffer.
memory: A,
Expand Down Expand Up @@ -324,7 +324,11 @@ where
pub fn read(&self) -> Result<ReadLock<T, A>, ReadLockError> {
let mut state = self.inner.state();
let buffer_range = self.inner().offset..self.inner().offset + self.size();
state.try_cpu_read(buffer_range.clone())?;

unsafe {
state.check_cpu_read(buffer_range.clone())?;
state.cpu_read_lock(buffer_range.clone());
}

let mapped_memory = self.memory.mapped_memory().unwrap();
let offset = self.memory.offset();
Expand Down Expand Up @@ -362,7 +366,11 @@ where
pub fn write(&self) -> Result<WriteLock<T, A>, WriteLockError> {
let mut state = self.inner.state();
let buffer_range = self.inner().offset..self.inner().offset + self.size();
state.try_cpu_write(buffer_range.clone())?;

unsafe {
state.check_cpu_write(buffer_range.clone())?;
state.cpu_write_lock(buffer_range.clone());
}

let mapped_memory = self.memory.mapped_memory().unwrap();
let offset = self.memory.offset();
Expand Down Expand Up @@ -492,7 +500,7 @@ where
fn drop(&mut self) {
unsafe {
let mut state = self.inner.inner.state();
state.cpu_unlock(self.buffer_range.clone(), false);
state.cpu_read_unlock(self.buffer_range.clone());
}
}
}
Expand Down Expand Up @@ -542,7 +550,7 @@ where
.unwrap();

let mut state = self.inner.inner.state();
state.cpu_unlock(self.buffer_range.clone(), true);
state.cpu_write_unlock(self.buffer_range.clone());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion vulkano/src/buffer/cpu_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ where
A: MemoryPool,
{
// Inner content.
inner: UnsafeBuffer,
inner: Arc<UnsafeBuffer>,

// The memory held by the buffer.
memory: PotentialDedicatedAllocation<A::Alloc>,
Expand Down
4 changes: 2 additions & 2 deletions vulkano/src/buffer/device_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ where
T: BufferContents + ?Sized,
{
// Inner content.
inner: UnsafeBuffer,
inner: Arc<UnsafeBuffer>,

// The memory held by the buffer.
memory: A,
Expand Down Expand Up @@ -237,7 +237,7 @@ where
size: DeviceSize,
usage: BufferUsage,
queue_families: &SmallVec<[u32; 4]>,
) -> Result<(UnsafeBuffer, MemoryRequirements), DeviceMemoryAllocationError> {
) -> Result<(Arc<UnsafeBuffer>, MemoryRequirements), DeviceMemoryAllocationError> {
let buffer = {
match UnsafeBuffer::new(
device.clone(),
Expand Down
2 changes: 1 addition & 1 deletion vulkano/src/buffer/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ where
T: BufferContents + ?Sized,
{
// Inner content.
inner: UnsafeBuffer,
inner: Arc<UnsafeBuffer>,

// Memory allocated for the buffer.
memory: A,
Expand Down
Loading