Skip to content
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

naga-agal: Fix handling of sampler overrides #14164

Merged
merged 1 commit into from
Dec 16, 2023

Conversation

Aaron1011
Copy link
Member

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).

@Lord-McSweeney Lord-McSweeney added the waiting-on-author Waiting on the PR author to make the requested changes label Dec 9, 2023
@Aaron1011 Aaron1011 added waiting-on-review Waiting on review from a Ruffle team member and removed waiting-on-author Waiting on the PR author to make the requested changes labels Dec 9, 2023
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).
@Aaron1011 Aaron1011 enabled auto-merge (rebase) December 16, 2023 04:52
@Aaron1011 Aaron1011 merged commit 837143b into ruffle-rs:master Dec 16, 2023
13 checks passed
@Lord-McSweeney Lord-McSweeney removed the waiting-on-review Waiting on review from a Ruffle team member label Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants