naga-agal: Fix handling of sampler overrides #14164
Merged
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.
After some testing, and looking at OpenFL, I believe I've determined the correct behavior for AGAL sampling:
Each time a Context3D.setProgram or Context3D.setSamplerStateAt call is made, the sampler config for the used texture slot(s) is updated with the new wrapping/filter behavior. For setProgram, this comes from all of the 'tex' opcodes used within the program.
However, when the 'ignoresampler' flag is set in a 'tex' opcode, the setProgram call does not override the existing sampler config. As a result, that program will sample with the behavior determined by the most recent setSamplerStateAt or setProgram call involving the used texture slot(s).
Previously, we were always overriding the opcode sampler config with the values from Context3D.setSamplerStateAt. However, I didn't realize that the order of the calls matter, so none of my tests ended up observing the effect of 'ignoresampler'.
We now need to process AGAL bytecode twice - a quick initial parse to determine the sampler configs (which need to be updated when we call 'setProgram'), and a second time when to build the Naga module (which needs to wait until we have the vertex attributes available, which can be changed by ActionScript after setting the program).