intel/blorp: Handle NIR clear inputs the same way as blit inputs
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 21 Oct 2016 21:15:03 +0000 (14:15 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Wed, 16 Nov 2016 18:11:29 +0000 (10:11 -0800)
By using offsetof() we can ensure that adding fiels to wm_inputs is always
safe as long as we maintain alignment.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
src/intel/blorp/blorp_blit.c
src/intel/blorp/blorp_clear.c
src/intel/blorp/blorp_priv.h

index 893a4bc4b160159d0c779264ad4970018a79b12e..27af21f2548198696a92b036a142faf6b982b724 100644 (file)
@@ -67,13 +67,7 @@ brw_blorp_blit_vars_init(nir_builder *b, struct brw_blorp_blit_vars *v,
     assert(!key->use_kill || !(key->blend && key->blit_scaled));
 
 #define LOAD_INPUT(name, type)\
-   v->v_##name = nir_variable_create(b->shader, nir_var_shader_in, \
-                                     type, #name); \
-   v->v_##name->data.interpolation = INTERP_MODE_FLAT; \
-   v->v_##name->data.location = VARYING_SLOT_VAR0 + \
-      offsetof(struct brw_blorp_wm_inputs, name) / (4 * sizeof(float)); \
-   v->v_##name->data.location_frac = \
-      (offsetof(struct brw_blorp_wm_inputs, name) / sizeof(float)) % 4;
+   v->v_##name = BLORP_CREATE_NIR_INPUT(b->shader, name, type);
 
    LOAD_INPUT(discard_rect, glsl_vec4_type())
    LOAD_INPUT(rect_grid, glsl_vec4_type())
index 2b8af18019dd6784ecbb3339d599a26e23b5dd42..e4a4acb1f08c615f8edc3bb031de7e1c1e6f54e0 100644 (file)
@@ -60,10 +60,8 @@ blorp_params_get_clear_kernel(struct blorp_context *blorp,
    nir_builder_init_simple_shader(&b, mem_ctx, MESA_SHADER_FRAGMENT, NULL);
    b.shader->info->name = ralloc_strdup(b.shader, "BLORP-clear");
 
-   nir_variable *v_color = nir_variable_create(b.shader, nir_var_shader_in,
-                                               glsl_vec4_type(), "v_color");
-   v_color->data.location = VARYING_SLOT_VAR0;
-   v_color->data.interpolation = INTERP_MODE_FLAT;
+   nir_variable *v_color =
+      BLORP_CREATE_NIR_INPUT(b.shader, clear_color, glsl_vec4_type());
 
    nir_variable *frag_color = nir_variable_create(b.shader, nir_var_shader_out,
                                                   glsl_vec4_type(),
index 1258fa96f1a4984e2d92113ea4c376f76e1c56d1..04aa152193d6acfdf7c180b97e68b562040ce334 100644 (file)
@@ -122,6 +122,8 @@ struct blorp_surf_offset {
 
 struct brw_blorp_wm_inputs
 {
+   uint32_t clear_color[4];
+
    struct brw_blorp_discard_rect discard_rect;
    struct brw_blorp_rect_grid rect_grid;
    struct brw_blorp_coord_transform coord_transform[2];
@@ -138,6 +140,18 @@ struct brw_blorp_wm_inputs
    uint32_t pad[1];
 };
 
+#define BLORP_CREATE_NIR_INPUT(shader, name, type) ({ \
+   nir_variable *input = nir_variable_create((shader), nir_var_shader_in, \
+                                             type, #name); \
+   if ((shader)->stage == MESA_SHADER_FRAGMENT) \
+      input->data.interpolation = INTERP_MODE_FLAT; \
+   input->data.location = VARYING_SLOT_VAR0 + \
+      offsetof(struct brw_blorp_wm_inputs, name) / (4 * sizeof(float)); \
+   input->data.location_frac = \
+      (offsetof(struct brw_blorp_wm_inputs, name) / sizeof(float)) % 4; \
+   input; \
+})
+
 static inline unsigned
 brw_blorp_get_urb_length(const struct brw_wm_prog_data *prog_data)
 {