Repository navigation
Mat queue mode #213
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
+2,776
−598
Merged
Mat queue mode #213
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
923087c
Split render context state into MatRenderContextBase
ZehMatt 243ebe3
Implement MatCallQueue
ZehMatt 9e4b857
Guard occlusion query objects with a mutex
ZehMatt d3c718f
Port the queued render context for mat_queue_mode
ZehMatt 7b38900
Queue dynamic lightmap builds while rendering is queued
ZehMatt b60cee6
Fix queued tone mapping by running it in the base render context
ZehMatt 653b638
Fix render target allocation reloading every texture after the first
ZehMatt 000aa7f
Fix render context storage by making it thread static
ZehMatt 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 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 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 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,89 @@ | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace Source.MaterialSystem; | ||
|
|
||
| public sealed unsafe class MatMemoryStack(int blockSize, int alignment) : IDisposable | ||
| { | ||
| struct Block | ||
| { | ||
| public byte* Base; | ||
| public int Size; | ||
| public int Used; | ||
| } | ||
|
|
||
| readonly List<Block> Blocks = []; | ||
| int CurrentBlock = -1; | ||
| int TotalUsed; | ||
|
|
||
| public int GetUsed() => TotalUsed; | ||
|
|
||
| static int AlignValue(int value, int alignment) => (value + alignment - 1) & ~(alignment - 1); | ||
|
|
||
| public byte* Alloc(int size) { | ||
| if (size <= 0) | ||
| return null; | ||
|
|
||
| int alignedSize = AlignValue(size, alignment); | ||
|
|
||
| while (CurrentBlock >= 0 && CurrentBlock < Blocks.Count) { | ||
| Block block = Blocks[CurrentBlock]; | ||
| if (block.Size - block.Used >= alignedSize) { | ||
| byte* result = block.Base + block.Used; | ||
| block.Used += alignedSize; | ||
| Blocks[CurrentBlock] = block; | ||
| TotalUsed += alignedSize; | ||
| return result; | ||
| } | ||
|
|
||
| if (CurrentBlock + 1 >= Blocks.Count) | ||
| break; | ||
| CurrentBlock++; | ||
| } | ||
|
|
||
| int newSize = Math.Max(blockSize, alignedSize); | ||
| Block newBlock = new() { | ||
| Base = (byte*)NativeMemory.AlignedAlloc((nuint)newSize, (nuint)alignment), | ||
| Size = newSize, | ||
| Used = alignedSize | ||
| }; | ||
| Blocks.Add(newBlock); | ||
| CurrentBlock = Blocks.Count - 1; | ||
| TotalUsed += alignedSize; | ||
| return newBlock.Base; | ||
| } | ||
|
|
||
| public void ShrinkLast(byte* ptr, int oldSize, int newSize) { | ||
| if (ptr == null || CurrentBlock < 0) | ||
| return; | ||
|
|
||
| Block block = Blocks[CurrentBlock]; | ||
| int oldAligned = AlignValue(oldSize, alignment); | ||
| if (block.Base + block.Used - oldAligned != ptr) | ||
| return; | ||
|
|
||
| int newAligned = AlignValue(newSize, alignment); | ||
| block.Used -= oldAligned - newAligned; | ||
| TotalUsed -= oldAligned - newAligned; | ||
| Blocks[CurrentBlock] = block; | ||
| } | ||
|
|
||
| public void FreeAll() { | ||
| for (int i = 0; i < Blocks.Count; i++) { | ||
| Block block = Blocks[i]; | ||
| block.Used = 0; | ||
| Blocks[i] = block; | ||
| } | ||
| CurrentBlock = Blocks.Count > 0 ? 0 : -1; | ||
| TotalUsed = 0; | ||
| } | ||
|
|
||
| public void Term() { | ||
| for (int i = 0; i < Blocks.Count; i++) | ||
| NativeMemory.AlignedFree(Blocks[i].Base); | ||
| Blocks.Clear(); | ||
| CurrentBlock = -1; | ||
| TotalUsed = 0; | ||
| } | ||
|
|
||
| public void Dispose() => Term(); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.