aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers
diff options
context:
space:
mode:
authorDave Airlie <[email protected]>2020-03-20 19:28:59 +1000
committerMarge Bot <[email protected]>2020-05-06 06:20:37 +0000
commit66a92e5d923a2e6b948c71f37a6b109a00938e9f (patch)
tree2bdf2b15349feb8e85e5d1460eba4a70916a96c5 /src/gallium/drivers
parent38e81938b65ebc32654f20a65fa8c3673c0c1cf6 (diff)
llvmpipe: add multisample alpha to coverage support.
Converts alpha into coverage mask. Reviewed-by: Roland Scheidegger <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4122>
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r--src/gallium/drivers/llvmpipe/lp_state_fs.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c
index 7a35960c3c3..15ec9048052 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c
@@ -293,6 +293,32 @@ lp_build_depth_clamp(struct gallivm_state *gallivm,
return lp_build_clamp(&f32_bld, z, min_depth, max_depth);
}
+static void
+lp_build_sample_alpha_to_coverage(struct gallivm_state *gallivm,
+ struct lp_type type,
+ unsigned coverage_samples,
+ LLVMValueRef num_loop,
+ LLVMValueRef loop_counter,
+ LLVMValueRef coverage_mask_store,
+ LLVMValueRef alpha)
+{
+ struct lp_build_context bld;
+ LLVMBuilderRef builder = gallivm->builder;
+ float step = 1.0 / coverage_samples;
+
+ lp_build_context_init(&bld, gallivm, type);
+ for (unsigned s = 0; s < coverage_samples; s++) {
+ LLVMValueRef alpha_ref_value = lp_build_const_vec(gallivm, type, step * s);
+ LLVMValueRef test = lp_build_cmp(&bld, PIPE_FUNC_GREATER, alpha, alpha_ref_value);
+
+ LLVMValueRef s_mask_idx = LLVMBuildMul(builder, lp_build_const_int32(gallivm, s), num_loop, "");
+ s_mask_idx = LLVMBuildAdd(builder, s_mask_idx, loop_counter, "");
+ LLVMValueRef s_mask_ptr = LLVMBuildGEP(builder, coverage_mask_store, &s_mask_idx, 1, "");
+ LLVMValueRef s_mask = LLVMBuildLoad(builder, s_mask_ptr, "");
+ s_mask = LLVMBuildAnd(builder, s_mask, test, "");
+ LLVMBuildStore(builder, s_mask, s_mask_ptr);
+ }
+}
/**
* Generate the fragment shader, depth/stencil test, and alpha tests.
@@ -653,9 +679,15 @@ generate_fs_loop(struct gallivm_state *gallivm,
if (color0 != -1 && outputs[color0][3]) {
LLVMValueRef alpha = LLVMBuildLoad(builder, outputs[color0][3], "alpha");
- lp_build_alpha_to_coverage(gallivm, type,
- &mask, alpha,
- (depth_mode & LATE_DEPTH_TEST) != 0);
+ if (!key->multisample) {
+ lp_build_alpha_to_coverage(gallivm, type,
+ &mask, alpha,
+ (depth_mode & LATE_DEPTH_TEST) != 0);
+ } else {
+ lp_build_sample_alpha_to_coverage(gallivm, type, key->coverage_samples, num_loop,
+ loop_state.counter,
+ mask_store, alpha);
+ }
}
}