intel: Use a system value for gl_FragCoord
authorJason Ekstrand <jason@jlekstrand.net>
Thu, 18 Jul 2019 14:59:44 +0000 (09:59 -0500)
committerJason Ekstrand <jason@jlekstrand.net>
Mon, 29 Jul 2019 23:30:26 +0000 (23:30 +0000)
It's kind-of an anomaly that the Intel drivers are still treating
gl_FragCoord as an input.  It also makes zero sense because we have to
special-case it in the back-end.

Because ANV is the only user of nir_lower_wpos_center, we go ahead and
just update it to look for nir_intrinsic_load_frag_coord as part of this
patch.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/compiler/nir/nir_lower_wpos_center.c
src/gallium/drivers/iris/iris_screen.c
src/intel/blorp/blorp_blit.c
src/intel/blorp/blorp_clear.c
src/intel/blorp/blorp_nir_builder.h
src/intel/compiler/brw_fs.cpp
src/intel/compiler/brw_fs_nir.cpp
src/intel/compiler/brw_wm_iz.cpp
src/intel/vulkan/anv_pipeline.c
src/mesa/drivers/dri/i965/brw_context.c
src/mesa/drivers/dri/i965/brw_program.c

index 3c114936f7e8aba5ca2d2022b15cb482064e50a7..56a392768b9312e6adae4463bfa7b53bb46281e4 100644 (file)
@@ -80,19 +80,9 @@ lower_wpos_center_block(nir_builder *b, nir_block *block,
    nir_foreach_instr(instr, block) {
       if (instr->type == nir_instr_type_intrinsic) {
          nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
-         if (intr->intrinsic == nir_intrinsic_load_deref) {
-            nir_deref_instr *deref = nir_src_as_deref(intr->src[0]);
-            if (deref->mode != nir_var_shader_in)
-               continue;
-
-            nir_variable *var = nir_deref_instr_get_variable(deref);
-
-            if (var->data.location == VARYING_SLOT_POS) {
-               /* gl_FragCoord should not have array/struct derefs: */
-               assert(deref->deref_type == nir_deref_type_var);
-               update_fragcoord(b, intr, for_sample_shading);
-               progress = true;
-            }
+         if (intr->intrinsic == nir_intrinsic_load_frag_coord) {
+            update_fragcoord(b, intr, for_sample_shading);
+            progress = true;
          }
       }
    }
index 2a1a95a2414e40ba8e56e8a5dc274a62f9c1dedf..2b0136d04d377f02fdb1daa1d12d5124d1acf49a 100644 (file)
@@ -190,6 +190,7 @@ iris_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
    case PIPE_CAP_LOAD_CONSTBUF:
    case PIPE_CAP_NIR_COMPACT_ARRAYS:
    case PIPE_CAP_DRAW_PARAMETERS:
+   case PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL:
    case PIPE_CAP_TGSI_FS_FACE_IS_INTEGER_SYSVAL:
    case PIPE_CAP_COMPUTE_SHADER_DERIVATIVES:
    case PIPE_CAP_INVALIDATE_BUFFER:
index 78a47c9cbe52a67a4826b7c4c3ad29e344ec0ab7..323e94e3d2801762a6f6226db93fa1e4442d71e0 100644 (file)
@@ -60,9 +60,6 @@ struct brw_blorp_blit_vars {
    nir_variable *v_dst_offset;
    nir_variable *v_src_inv_size;
 
-   /* gl_FragCoord */
-   nir_variable *frag_coord;
-
    /* gl_FragColor */
    nir_variable *color_out;
 };
@@ -84,10 +81,6 @@ brw_blorp_blit_vars_init(nir_builder *b, struct brw_blorp_blit_vars *v,
 
 #undef LOAD_INPUT
 
-   v->frag_coord = nir_variable_create(b->shader, nir_var_shader_in,
-                                       glsl_vec4_type(), "gl_FragCoord");
-   v->frag_coord->data.location = VARYING_SLOT_POS;
-
    v->color_out = nir_variable_create(b->shader, nir_var_shader_out,
                                       glsl_vec4_type(), "gl_FragColor");
    v->color_out->data.location = FRAG_RESULT_COLOR;
@@ -98,7 +91,7 @@ blorp_blit_get_frag_coords(nir_builder *b,
                            const struct brw_blorp_blit_prog_key *key,
                            struct brw_blorp_blit_vars *v)
 {
-   nir_ssa_def *coord = nir_f2i32(b, nir_load_var(b, v->frag_coord));
+   nir_ssa_def *coord = nir_f2i32(b, nir_load_frag_coord(b));
 
    /* Account for destination surface intratile offset
     *
index 7e77e80565fa1ddd6d9d94183a5cdddcbf9b0dc4..af7c0d506f3d5873f70b76114885cb427712df87 100644 (file)
@@ -70,12 +70,7 @@ blorp_params_get_clear_kernel(struct blorp_batch *batch,
    nir_ssa_def *color = nir_load_var(&b, v_color);
 
    if (clear_rgb_as_red) {
-      nir_variable *frag_coord =
-         nir_variable_create(b.shader, nir_var_shader_in,
-                             glsl_vec4_type(), "gl_FragCoord");
-      frag_coord->data.location = VARYING_SLOT_POS;
-
-      nir_ssa_def *pos = nir_f2i32(&b, nir_load_var(&b, frag_coord));
+      nir_ssa_def *pos = nir_f2i32(&b, nir_load_frag_coord(&b));
       nir_ssa_def *comp = nir_umod(&b, nir_channel(&b, pos, 0),
                                        nir_imm_int(&b, 3));
       nir_ssa_def *color_component =
@@ -976,7 +971,7 @@ blorp_params_get_mcs_partial_resolve_kernel(struct blorp_batch *batch,
 
    /* Do an MCS fetch and check if it is equal to the magic clear value */
    nir_ssa_def *mcs =
-      blorp_nir_txf_ms_mcs(&b, nir_f2i32(&b, blorp_nir_frag_coord(&b)),
+      blorp_nir_txf_ms_mcs(&b, nir_f2i32(&b, nir_load_frag_coord(&b)),
                                nir_load_layer_id(&b));
    nir_ssa_def *is_clear =
       blorp_nir_mcs_is_clear_color(&b, mcs, blorp_key.num_samples);
index 9664bdbcd2765e4c811e75da6b6b5d9b9cb7705b..0ba855fcd663da4bf69344d575e8311702e10ee3 100644 (file)
@@ -36,18 +36,6 @@ blorp_nir_init_shader(nir_builder *b,
       b->shader->info.fs.origin_upper_left = true;
 }
 
-static inline nir_ssa_def *
-blorp_nir_frag_coord(nir_builder *b)
-{
-   nir_variable *frag_coord =
-      nir_variable_create(b->shader, nir_var_shader_in,
-                          glsl_vec4_type(), "gl_FragCoord");
-
-   frag_coord->data.location = VARYING_SLOT_POS;
-
-   return nir_load_var(b, frag_coord);
-}
-
 static inline nir_ssa_def *
 blorp_nir_txf_ms_mcs(nir_builder *b, nir_ssa_def *xy_pos, nir_ssa_def *layer)
 {
index 493b9fdf8bb28934cddd09c5400d7ea165f32f86..c8dae0c85d9640817fa5b96d109324d41a9126a7 100644 (file)
@@ -6822,7 +6822,7 @@ fs_visitor::setup_fs_payload_gen6()
    assert(devinfo->gen >= 6);
 
    prog_data->uses_src_depth = prog_data->uses_src_w =
-      (nir->info.inputs_read & (1 << VARYING_SLOT_POS)) != 0;
+      (nir->info.system_values_read & (1ull << SYSTEM_VALUE_FRAG_COORD)) != 0;
 
    prog_data->uses_sample_mask =
       (nir->info.system_values_read & SYSTEM_BIT_SAMPLE_MASK_IN) != 0;
@@ -7601,6 +7601,7 @@ fs_visitor::run_fs(bool allow_spilling, bool do_rep_send)
          emit_shader_time_begin();
 
       if (nir->info.inputs_read > 0 ||
+          (nir->info.system_values_read & (1ull << SYSTEM_VALUE_FRAG_COORD)) ||
           (nir->info.outputs_read > 0 && !wm_key->coherent_fb_fetch)) {
          if (devinfo->gen < 6)
             emit_interpolation_setup_gen4();
@@ -7707,10 +7708,7 @@ is_used_in_not_interp_frag_coord(nir_ssa_def *def)
          return true;
 
       nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(src->parent_instr);
-      if (intrin->intrinsic != nir_intrinsic_load_interpolated_input)
-         return true;
-
-      if (nir_intrinsic_base(intrin) != VARYING_SLOT_POS)
+      if (intrin->intrinsic != nir_intrinsic_load_frag_coord)
          return true;
    }
 
index 0b3982737dd2c86394dba75fa3b237dc19867f6b..2451fbf0349c851250dc6e20eadc07ba4cb584b9 100644 (file)
@@ -3829,12 +3829,11 @@ fs_visitor::nir_emit_fs_intrinsic(const fs_builder &bld,
       break;
    }
 
-   case nir_intrinsic_load_interpolated_input: {
-      if (nir_intrinsic_base(instr) == VARYING_SLOT_POS) {
-         emit_fragcoord_interpolation(dest);
-         break;
-      }
+   case nir_intrinsic_load_frag_coord:
+      emit_fragcoord_interpolation(dest);
+      break;
 
+   case nir_intrinsic_load_interpolated_input: {
       assert(instr->src[0].ssa &&
              instr->src[0].ssa->parent_instr->type == nir_instr_type_intrinsic);
       nir_intrinsic_instr *bary_intrinsic =
index b9b7e70a0f3729ce5eb6448835a8a64f33cc7525..c2ea4aafd2b6bdeff4df8b441147b01a6e4811fb 100644 (file)
@@ -145,7 +145,7 @@ void fs_visitor::setup_fs_payload_gen4()
    payload.subspan_coord_reg[0] = reg++;
 
    prog_data->uses_src_depth =
-      (nir->info.inputs_read & (1 << VARYING_SLOT_POS)) != 0;
+      (nir->info.system_values_read & (1ull << SYSTEM_VALUE_FRAG_COORD)) != 0;
    if (wm_iz_table[lookup].sd_present || prog_data->uses_src_depth ||
        kill_stats_promoted_workaround) {
       payload.source_depth_reg[0] = reg;
index c2a164cc802af972f94edb4838937b3ed1905f7e..a9a403f123323e694edc4a196909000e74c4d0aa 100644 (file)
@@ -167,6 +167,7 @@ anv_shader_compile_to_nir(struct anv_device *device,
    };
    struct spirv_to_nir_options spirv_options = {
       .lower_workgroup_access_to_offsets = true,
+      .frag_coord_is_sysval = true,
       .caps = {
          .demote_to_helper_invocation = true,
          .derivative_group = true,
@@ -652,7 +653,7 @@ anv_pipeline_lower_nir(struct anv_pipeline *pipeline,
 
    if (nir->info.stage == MESA_SHADER_FRAGMENT) {
       NIR_PASS_V(nir, nir_lower_wpos_center, pipeline->sample_shading_enable);
-      NIR_PASS_V(nir, nir_lower_input_attachments, false);
+      NIR_PASS_V(nir, nir_lower_input_attachments, true);
    }
 
    NIR_PASS_V(nir, anv_nir_lower_ycbcr_textures, layout);
index 3783d1532e9b1ea6961bc0b3af203e147311e6b4..91053842aa11dda3d6c9bae7c60d94e2ebe2e6d7 100644 (file)
@@ -621,6 +621,7 @@ brw_initialize_context_constants(struct brw_context *brw)
    if (devinfo->gen >= 5 || devinfo->is_g4x)
       ctx->Const.MaxClipPlanes = 8;
 
+   ctx->Const.GLSLFragCoordIsSysVal = true;
    ctx->Const.GLSLTessLevelsAsInputs = true;
    ctx->Const.PrimitiveRestartForPatches = true;
 
index 0e91612d845f49fdd8ae2fb9395c92dc44bb1bee..b69b032a9c2c933891dc267d37703ed06b7ae49b 100644 (file)
@@ -262,6 +262,7 @@ brwProgramStringNotify(struct gl_context *ctx,
 
       if (newFP == curFP)
         brw->ctx.NewDriverState |= BRW_NEW_FRAGMENT_PROGRAM;
+      _mesa_program_fragment_position_to_sysval(&newFP->program);
       newFP->id = get_new_program_id(brw->screen);
 
       prog->nir = brw_create_nir(brw, NULL, prog, MESA_SHADER_FRAGMENT, true);