-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
369b856
commit 9074423
Showing
12 changed files
with
851 additions
and
306 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use glace::std::bindless::RenderResourceTag; | ||
use crate::gpu::GpuDescriptors; | ||
|
||
pub use glace::std::bindless::RenderResourceHandle as CpuDescriptor; | ||
|
||
type CpuDescriptors = Vec<CpuDescriptor>; | ||
|
||
pub struct Descriptors { | ||
free_handle: usize, | ||
tag: RenderResourceTag, | ||
|
||
cpu: CpuDescriptors, | ||
pub(crate) gpu: GpuDescriptors, | ||
} | ||
|
||
impl Descriptors { | ||
pub fn new(tag: RenderResourceTag, len: usize, gpu: GpuDescriptors) -> Self { | ||
let mut cpu = CpuDescriptors::with_capacity(len); | ||
for i in 0..len { | ||
cpu.push(CpuDescriptor::new(0, tag, i as u32 + 1)); | ||
} | ||
|
||
Self { | ||
free_handle: 0, | ||
tag, | ||
cpu, | ||
gpu, | ||
} | ||
} | ||
|
||
fn invalid_index(&self) -> usize { | ||
self.cpu.len() | ||
} | ||
|
||
pub unsafe fn create(&mut self) -> CpuDescriptor { | ||
assert_ne!(self.free_handle, self.invalid_index()); // out of memory | ||
|
||
let idx = self.free_handle; | ||
let handle = self.cpu[self.free_handle]; | ||
|
||
let version = (handle.version() + 1) % 64; | ||
let index = handle.index() as usize; | ||
|
||
assert_ne!(index, self.free_handle); | ||
self.free_handle = index; | ||
|
||
let handle = CpuDescriptor::new(version as _, self.tag, idx as _); | ||
self.cpu[idx] = handle; | ||
|
||
handle | ||
} | ||
|
||
pub unsafe fn is_valid(&self, handle: CpuDescriptor) -> bool { | ||
let idx = handle.index() as usize; | ||
if idx >= self.cpu.len() { | ||
return false; | ||
} | ||
|
||
self.cpu[idx] == handle | ||
} | ||
} |
Oops, something went wrong.