+ struct pipe_rasterizer_state *rast = &ctx->rasterizer->base;
+ const struct panfrost_zsa_state *zsa = ctx->depth_stencil;
+ unsigned rt_count = ctx->pipe_framebuffer.nr_cbufs;
+
+ memset(fragmeta, 0, sizeof(*fragmeta));
+
+ fragmeta->shader = fs->shader;
+ fragmeta->attribute_count = fs->attribute_count;
+ fragmeta->varying_count = fs->varying_count;
+ fragmeta->texture_count = ctx->sampler_view_count[PIPE_SHADER_FRAGMENT];
+ fragmeta->sampler_count = ctx->sampler_count[PIPE_SHADER_FRAGMENT];
+
+ if (dev->quirks & IS_BIFROST) {
+ struct mali_bifrost_properties_packed prop;
+ struct mali_preload_fragment_packed preload;
+
+ bool no_blend = true;
+
+ for (unsigned i = 0; i < rt_count; ++i)
+ no_blend &= (!blend[i].load_dest | blend[i].no_colour);
+
+ pan_pack(&prop, BIFROST_PROPERTIES, cfg) {
+ cfg.unknown = 0x950020; /* XXX */
+ cfg.uniform_buffer_count = panfrost_ubo_count(ctx, PIPE_SHADER_FRAGMENT);
+ cfg.early_z_enable = !fs->can_discard && !fs->writes_depth && no_blend;
+ }
+
+ pan_pack(&preload, PRELOAD_FRAGMENT, cfg) {
+ cfg.uniform_count = fs->uniform_count;
+ cfg.fragment_position = fs->reads_frag_coord;
+ }
+
+ memcpy(&fragmeta->bifrost_props, &prop, sizeof(prop));
+ memcpy(&fragmeta->bifrost_preload, &preload, sizeof(preload));
+ } else {
+ struct mali_midgard_properties_packed prop;
+
+ /* Reasons to disable early-Z from a shader perspective */
+ bool late_z = fs->can_discard || fs->writes_global ||
+ fs->writes_depth || fs->writes_stencil;
+
+ /* Reasons to disable early-Z from a CSO perspective */
+ bool alpha_to_coverage = ctx->blend->base.alpha_to_coverage;
+
+ /* If either depth or stencil is enabled, discard matters */
+ bool zs_enabled =
+ (zsa->base.depth.enabled && zsa->base.depth.func != PIPE_FUNC_ALWAYS) ||
+ zsa->base.stencil[0].enabled;
+
+ bool has_blend_shader = false;
+
+ for (unsigned c = 0; c < rt_count; ++c)
+ has_blend_shader |= blend[c].is_shader;
+
+ pan_pack(&prop, MIDGARD_PROPERTIES, cfg) {
+ cfg.uniform_buffer_count = panfrost_ubo_count(ctx, PIPE_SHADER_FRAGMENT);
+ cfg.uniform_count = fs->uniform_count;
+ cfg.work_register_count = fs->work_reg_count;
+ cfg.writes_globals = fs->writes_global;
+ cfg.suppress_inf_nan = true; /* XXX */
+
+ /* TODO: Reduce this limit? */
+ if (has_blend_shader)
+ cfg.work_register_count = MAX2(cfg.work_register_count, 8);
+
+ cfg.stencil_from_shader = fs->writes_stencil;
+ cfg.helper_invocation_enable = fs->helper_invocations;
+ cfg.depth_source = fs->writes_depth ?
+ MALI_DEPTH_SOURCE_SHADER :
+ MALI_DEPTH_SOURCE_FIXED_FUNCTION;
+
+ /* Depend on other state */
+ cfg.early_z_enable = !(late_z || alpha_to_coverage);
+ cfg.reads_tilebuffer = fs->outputs_read || (!zs_enabled && fs->can_discard);
+ cfg.reads_depth_stencil = zs_enabled && fs->can_discard;
+ }
+
+ memcpy(&fragmeta->midgard_props, &prop, sizeof(prop));
+ }
+
+ bool msaa = rast->multisample;
+ fragmeta->coverage_mask = msaa ? ctx->sample_mask : ~0;