[Mesa-dev] [PATCH v2 5/6] panfrost: Wire up nir_lower_blend
Alyssa Rosenzweig
alyssa at rosenzweig.io
Mon May 13 03:45:59 UTC 2019
This implements blend shaders via nir_lower_blend, by creating dummy
fragment shaders simply passing through the source color and using the
new lowering pass to inject blendability.
Signed-off-by: Alyssa Rosenzweig <alyssa at rosenzweig.io>
---
.../drivers/panfrost/pan_blend_shaders.c | 48 +++++++++++++------
1 file changed, 33 insertions(+), 15 deletions(-)
diff --git a/src/gallium/drivers/panfrost/pan_blend_shaders.c b/src/gallium/drivers/panfrost/pan_blend_shaders.c
index f716e85e3f5..30fc6f3bc7e 100644
--- a/src/gallium/drivers/panfrost/pan_blend_shaders.c
+++ b/src/gallium/drivers/panfrost/pan_blend_shaders.c
@@ -27,7 +27,7 @@
#include "pan_util.h"
#include "midgard/midgard_compile.h"
#include "compiler/nir/nir_builder.h"
-//#include "gallium/auxiliary/nir/nir_lower_blend.h"
+#include "gallium/auxiliary/util/u_blend.h"
/*
* Implements the command stream portion of programmatic blend shaders.
@@ -82,21 +82,40 @@
* (compilation).
*/
-static nir_ssa_def *
-nir_blending_f(const struct pipe_rt_blend_state *blend, nir_builder *b,
- nir_ssa_def *s_src, nir_ssa_def *s_dst, nir_ssa_def *s_con)
+static nir_lower_blend_options
+nir_make_options(const struct pipe_blend_state *blend, unsigned nr_cbufs)
{
- /* Stub, to be replaced by the real implementation when that is
- * upstream (pending on a rewrite to be Gallium agnostic) */
+ nir_lower_blend_options options;
+
+ for (unsigned i = 0; i < nr_cbufs; ++i) {
+ nir_lower_blend_channel rgb = {
+ .func = util_blend_func_to_shader(blend->rt[i].rgb_func),
+ .src_factor = util_blend_factor_to_shader(blend->rt[i].rgb_src_factor),
+ .dst_factor = util_blend_factor_to_shader(blend->rt[i].rgb_dst_factor),
+ .invert_src_factor = util_blend_factor_is_inverted(blend->rt[i].rgb_src_factor),
+ .invert_dst_factor = util_blend_factor_is_inverted(blend->rt[i].rgb_dst_factor)
+ };
+
+ nir_lower_blend_channel alpha = {
+ .func = util_blend_func_to_shader(blend->rt[i].alpha_func),
+ .src_factor = util_blend_factor_to_shader(blend->rt[i].alpha_src_factor),
+ .dst_factor = util_blend_factor_to_shader(blend->rt[i].alpha_dst_factor),
+ .invert_src_factor = util_blend_factor_is_inverted(blend->rt[i].alpha_src_factor),
+ .invert_dst_factor = util_blend_factor_is_inverted(blend->rt[i].alpha_dst_factor)
+ };
+
+ options.rt[i].rgb = rgb;
+ options.rt[i].alpha = alpha;
+
+ options.rt[i].colormask = blend->rt[i].colormask;
+ }
- return s_src;
+ return options;
}
void
panfrost_make_blend_shader(struct panfrost_context *ctx, struct panfrost_blend_state *cso, const struct pipe_blend_color *blend_color)
{
- const struct pipe_rt_blend_state *blend = &cso->base.rt[0];
-
/* Build the shader */
nir_shader *shader = nir_shader_create(NULL, MESA_SHADER_FRAGMENT, &midgard_nir_options, NULL);
@@ -106,12 +125,9 @@ panfrost_make_blend_shader(struct panfrost_context *ctx, struct panfrost_blend_s
/* Create the blend variables */
nir_variable *c_src = nir_variable_create(shader, nir_var_shader_in, glsl_vector_type(GLSL_TYPE_FLOAT, 4), "gl_Color");
- nir_variable *c_dst = nir_variable_create(shader, nir_var_shader_in, glsl_vector_type(GLSL_TYPE_FLOAT, 4), "gl_SecondaryColor");
nir_variable *c_out = nir_variable_create(shader, nir_var_shader_out, glsl_vector_type(GLSL_TYPE_FLOAT, 4), "gl_FragColor");
- nir_variable *c_con = nir_variable_create(shader, nir_var_uniform, glsl_vector_type(GLSL_TYPE_FLOAT, 4), "constant");
c_src->data.location = VARYING_SLOT_COL0;
- c_dst->data.location = VARYING_SLOT_COL1;
c_out->data.location = FRAG_RESULT_COLOR;
/* Setup nir_builder */
@@ -124,11 +140,13 @@ panfrost_make_blend_shader(struct panfrost_context *ctx, struct panfrost_blend_s
/* Setup inputs */
nir_ssa_def *s_src = nir_load_var(b, c_src);
- nir_ssa_def *s_dst = nir_load_var(b, c_dst);
- nir_ssa_def *s_con = nir_load_var(b, c_con);
/* Build a trivial blend shader */
- nir_store_var(b, c_out, nir_blending_f(blend, b, s_src, s_dst, s_con), 0xFF);
+ nir_store_var(b, c_out, s_src, 0xFF);
+
+ nir_lower_blend_options options =
+ nir_make_options(&cso->base, 1);
+ NIR_PASS_V(shader, nir_lower_blend, options);
/* Compile the built shader */
--
2.20.1
More information about the mesa-dev
mailing list