-
Notifications
You must be signed in to change notification settings - Fork 37
Simple VRAM Allocator #60
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
Merged
overdrivenpotato
merged 6 commits into
overdrivenpotato:master
from
MrAwesome:vram_alloc
Jul 9, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
056c26a
Create a very simple VRAM allocator, with a trait future allocators c…
MrAwesome a11500e
Fix dealloc
MrAwesome 6775694
Fix dealloc (actually)
MrAwesome c02d23c
Just use struct for now, can pull out trait later if needed
MrAwesome 0702bef
Remove gu_utils, dealloc, and realloc
MrAwesome 3586376
Remove comment
MrAwesome File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,81 @@ | ||
| use crate::sys::TexturePixelFormat; | ||
| use crate::sys::sceGeEdramGetSize; | ||
| use core::mem::size_of; | ||
|
|
||
| pub struct VramMemChunk { | ||
| start: u32, | ||
| len: u32, | ||
| } | ||
|
|
||
| impl VramMemChunk { | ||
| fn new(start: u32, len: u32) -> Self { | ||
| Self { start, len } | ||
| } | ||
|
|
||
| pub fn start(&self) -> u32 { | ||
| self.start | ||
| } | ||
|
|
||
| pub fn len(&self) -> u32 { | ||
| self.len | ||
| } | ||
| } | ||
|
|
||
| // A dead-simple VRAM bump allocator. | ||
| pub struct SimpleVramAllocator { | ||
| offset: u32, | ||
| } | ||
|
|
||
| impl SimpleVramAllocator { | ||
| pub fn new() -> Self { | ||
| Self { offset: 0 } | ||
| } | ||
|
|
||
| pub fn alloc(&mut self, size: u32) -> VramMemChunk { | ||
| let old_offset = self.offset; | ||
| self.offset += size; | ||
|
|
||
| if self.offset > self.total_mem() { | ||
| panic!("Total VRAM size exceeded!"); | ||
| } | ||
|
|
||
| VramMemChunk::new(old_offset, size) | ||
| } | ||
|
|
||
| pub fn alloc_sized<T: Sized>(&mut self, count: u32) -> VramMemChunk { | ||
| let size = size_of::<T>() as u32; | ||
| self.alloc(count * size) | ||
| } | ||
|
|
||
| pub fn alloc_texture_pixels( | ||
| &mut self, | ||
| width: u32, | ||
| height: u32, | ||
| psm: TexturePixelFormat, | ||
| ) -> VramMemChunk { | ||
| let size = get_memory_size(width, height, psm); | ||
| self.alloc(size) | ||
| } | ||
|
|
||
| fn total_mem(&self) -> u32 { | ||
| unsafe { | ||
| sceGeEdramGetSize() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn get_memory_size(width: u32, height: u32, psm: TexturePixelFormat) -> u32 { | ||
| match psm { | ||
| TexturePixelFormat::PsmT4 => (width * height) >> 1, | ||
| TexturePixelFormat::PsmT8 => width * height, | ||
|
|
||
| TexturePixelFormat::Psm5650 | ||
| | TexturePixelFormat::Psm5551 | ||
| | TexturePixelFormat::Psm4444 | ||
| | TexturePixelFormat::PsmT16 => 2 * width * height, | ||
|
|
||
| TexturePixelFormat::Psm8888 | TexturePixelFormat::PsmT32 => 4 * width * height, | ||
|
|
||
| _ => unimplemented!(), | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.