-
Notifications
You must be signed in to change notification settings - Fork 61
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
Improve material system data packing #1473
Open
VReaperV
wants to merge
11
commits into
DaemonEngine:master
Choose a base branch
from
VReaperV:material-stages-pack
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+799
−568
Conversation
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
VReaperV
added
T-Improvement
Improvement for an existing feature
A-Renderer
T-Performance
labels
Dec 25, 2024
VReaperV
force-pushed
the
material-stages-pack
branch
6 times, most recently
from
December 26, 2024 08:06
1332e02
to
981f302
Compare
Is there any way to split this up into multiple PRs? |
I believe so, yes. |
This was referenced Dec 26, 2024
Closed
VReaperV
force-pushed
the
material-stages-pack
branch
2 times, most recently
from
January 8, 2025 10:20
f4a4702
to
3045e47
Compare
Thought I fixed those, gonna need to recheck it then. |
VReaperV
force-pushed
the
material-stages-pack
branch
from
January 11, 2025 11:48
3045e47
to
217028e
Compare
Nevermind, that does not fix it. It's an issue with dynamic lights though. |
VReaperV
force-pushed
the
material-stages-pack
branch
from
January 11, 2025 14:17
f7c1c76
to
92ceaa8
Compare
Both issues fixed now. |
VReaperV
force-pushed
the
material-stages-pack
branch
from
January 12, 2025 00:07
92ceaa8
to
232b0b3
Compare
VReaperV
force-pushed
the
material-stages-pack
branch
2 times, most recently
from
January 17, 2025 01:56
575522b
to
b8531e7
Compare
Allocate memory for each stage of used shaders rather than for each stage in all used shaders for each surface that uses them. Change some of the material system functions to use `shaderStage_t*` instead of `drawSurf_t*` etc as input. Textures are put into a different storage buffer, following the structure of `textureBundle_t`. This allows decreasing the total amount of memory used, and changing the material buffer to be a UBO instead. The lightmap and deluxemap handles are put into another UBO, because they're per-surface, rather than per-shader-stage. Also moved some duplicate code into a function.
Only these 6 components (0, 1, 4, 5, 12, 13) actually have an effect. This largely reduces the amount of data being transferred for texture matrices, as well as some useless computations. .
Also removed some now useless code.
Also fixes an incorrect matrix constructor in shaders.
The UBO bindings were conflicting with light UBO.
VReaperV
force-pushed
the
material-stages-pack
branch
from
January 18, 2025 19:42
b8531e7
to
66f2299
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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.
Partially implements #1448.
Stage data is allocated for stages rather than
surface * stage
, which greatly reduces the amount of required data. Texture handles and texture matrix are moved into a different buffer, since stage data ends up being often under 1kb this way. Lightmap/deluxemap handles are moved into a different UBO, because they depend on thedrawSurf
rather than on shader stage. All 3 are encoded intobaseInstance
(12 bits for shader stage, 12 bits for textures, and 8 more for lightmaps).Optimised
u_Color
by changing it from avec4
to auint
(the colors we use only have 8-bit precision in engine).Also added
u_ColorModulateColorGen
for use with shaders other thancameraEffects
: these only use 12 distinct states, encoded as 5 bits, which also allows using auint
here instead of avec4
. AddedunpackUnorm4x8()
define for devices that don't supportARB_gpu_shader5
.Changed
u_TextureMatrix
from amat4
tomat3x2
, reducing its size from 16 to just 6 components since only these 6 components have any actual effect, which allows making theTexData
struct be exactly 64 bytes.All of the above combined reduces the memory usage of material system by ~50-100x, and improves its performance and load times.
Also added
r_materialSystemSkip
cvar, which allows instantaneously switching between core and material renderer (as long as the latter is enabled in the first place), for much faster debugging and performance comparison.