Repository navigation
rslc: initialize local constants at their use sites - #19934
Closed
finalpatch wants to merge 1 commit into
Closed
finalpatch wants to merge 1 commit into
finalpatch wants to merge 1 commit into
Conversation
Keep constant-array stores inside the branches that use them instead of initializing every array at function entry. This avoids excessive scratch-memory traffic in Hyllian shaders on Adreno GPUs.
Contributor
|
Thanks, great find! Merged into master with your authorship kept. I added a small follow-up on top: instead of reusing one variable for every read of the same constant, each read now gets its own fresh variable, exactly like glslang's "indexable" temporaries. With one shared variable, a constant read in two places gets written again after it has already been read. Mesa's large-constant pass then stops promoting it to a constant table on RADV/ANV/Turnip/NVK, so the slowdown would have moved to Mesa drivers. With one variable per read, both your Adreno fix and the Mesa fast path hold. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Fix a severe shader performance regression with rslc on Adreno GPUs. On a Samsung Galaxy Z Fold7 (Adreno 830),
presets/crt-hyllian-sinc-smartblur-sgenpt.slangpruns at normal speed with glslang but becomes very slow with rslc. The final pass contains constant mask arrays in mutually exclusive branches.rslc emits these local arrays as initialized Function
OpVariables, which initializes them at function entry even when their branches are not taken. On this GPU, the resulting shader uses 1,168 bytes of scratch memory per shader instance and 216 memory-write instructions.Emit local storage without an initializer and store the constant at each dynamic access instead. This keeps initialization inside the branches that use it and ensures each access has an initialized value. The driver then reports zero scratch memory and zero memory-write instructions for this shader.
Validation
fcfd5bf4eb), selecting glslang or rslc: glslang was fast; rslc was slow.spirv-val --target-env vulkan1.0.rslc_test,rslc_remap_test(GL=0),shader_chain_test, andslang_hlsl_backend_testpass in Android/Termux.Related Issues
[Any issues this pull request may be addressing]
Related Pull Requests
[Any other PRs from related repositories that might be needed for this pull request to work]
Reviewers
[If possible @mention all the people that should review your pull request]