diff options
author | Danylo Piliaiev <[email protected]> | 2019-02-20 19:39:18 +0200 |
---|---|---|
committer | Francisco Jerez <[email protected]> | 2019-03-25 13:54:55 -0700 |
commit | c8abe03f3b65505d2c1c165d88efb3bb62e06db1 (patch) | |
tree | 46249f3280a70e6d703589fd54561df6d32b69d2 /src/mesa/drivers | |
parent | 3bd54576415130465f096d73b7940dfbe02bb71b (diff) |
i965,iris,anv: Make alpha to coverage work with sample mask
From "Alpha Coverage" section of SKL PRM Volume 7:
"If Pixel Shader outputs oMask, AlphaToCoverage is disabled in
hardware, regardless of the state setting for this feature."
From OpenGL spec 4.6, "15.2 Shader Execution":
"The built-in integer array gl_SampleMask can be used to change
the sample coverage for a fragment from within the shader."
From OpenGL spec 4.6, "17.3.1 Alpha To Coverage":
"If SAMPLE_ALPHA_TO_COVERAGE is enabled, a temporary coverage value
is generated where each bit is determined by the alpha value at the
corresponding sample location. The temporary coverage value is then
ANDed with the fragment coverage value to generate a new fragment
coverage value."
Similar wording could be found in Vulkan spec 1.1.100
"25.6. Multisample Coverage"
Thus we need to compute alpha to coverage dithering manually in shader
and replace sample mask store with the bitwise-AND of sample mask and
alpha to coverage dithering.
The following formula is used to compute final sample mask:
m = int(16.0 * clamp(src0_alpha, 0.0, 1.0))
dither_mask = 0x1111 * ((0xfea80 >> (m & ~3)) & 0xf) |
0x0808 * (m & 2) | 0x0100 * (m & 1)
sample_mask = sample_mask & dither_mask
Credits to Francisco Jerez <[email protected]> for creating it.
It gives a number of ones proportional to the alpha for 2, 4, 8 or 16
least significant bits of the result.
GEN6 hardware does not have issue with simultaneous usage of sample mask
and alpha to coverage however due to the wrong sending order of oMask
and src0_alpha it is still affected by it.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=109743
Signed-off-by: Danylo Piliaiev <[email protected]>
Reviewed-by: Francisco Jerez <[email protected]>
Diffstat (limited to 'src/mesa/drivers')
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_wm.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c index 47905ca5549..d2d7974e841 100644 --- a/src/mesa/drivers/dri/i965/brw_wm.c +++ b/src/mesa/drivers/dri/i965/brw_wm.c @@ -93,8 +93,11 @@ brw_wm_debug_recompile(struct brw_context *brw, struct gl_program *prog, old_key->flat_shade, key->flat_shade); found |= key_debug(brw, "number of color buffers", old_key->nr_color_regions, key->nr_color_regions); - found |= key_debug(brw, "MRT alpha test or alpha-to-coverage", - old_key->replicate_alpha, key->replicate_alpha); + found |= key_debug(brw, "MRT alpha test", + old_key->alpha_test_replicate_alpha, + key->alpha_test_replicate_alpha); + found |= key_debug(brw, "alpha to coverage", + old_key->alpha_to_coverage, key->alpha_to_coverage); found |= key_debug(brw, "fragment color clamping", old_key->clamp_fragment_color, key->clamp_fragment_color); found |= key_debug(brw, "per-sample interpolation", @@ -569,10 +572,13 @@ brw_wm_populate_key(struct brw_context *brw, struct brw_wm_prog_key *key) key->force_dual_color_blend = brw->dual_color_blend_by_location && (ctx->Color.BlendEnabled & 1) && ctx->Color.Blend[0]._UsesDualSrc; - /* _NEW_MULTISAMPLE, _NEW_COLOR, _NEW_BUFFERS */ - key->replicate_alpha = ctx->DrawBuffer->_NumColorDrawBuffers > 1 && - (_mesa_is_alpha_test_enabled(ctx) || - _mesa_is_alpha_to_coverage_enabled(ctx)); + /* _NEW_MULTISAMPLE, _NEW_BUFFERS */ + key->alpha_to_coverage = _mesa_is_alpha_to_coverage_enabled(ctx); + + /* _NEW_COLOR, _NEW_BUFFERS */ + key->alpha_test_replicate_alpha = + ctx->DrawBuffer->_NumColorDrawBuffers > 1 && + _mesa_is_alpha_test_enabled(ctx); /* _NEW_BUFFERS _NEW_MULTISAMPLE */ /* Ignore sample qualifier while computing this flag. */ |