<p dir="ltr"><br>
On Jul 5, 2016 11:13 PM, "Pohjolainen, Topi" <<a href="mailto:topi.pohjolainen@intel.com">topi.pohjolainen@intel.com</a>> wrote:<br>
><br>
> On Tue, Jul 05, 2016 at 07:12:49AM -0700, Jason Ekstrand wrote:<br>
> > On Jul 5, 2016 6:32 AM, "Pohjolainen, Topi"<br>
> > <[1]<a href="mailto:topi.pohjolainen@intel.com">topi.pohjolainen@intel.com</a>> wrote:<br>
> > ><br>
> > > On Wed, Jun 29, 2016 at 05:14:51PM -0700, Jason Ekstrand wrote:<br>
> > > > Reviewed-by: Topi Pohjolainen <[2]<a href="mailto:topi.pohjolainen@intel.com">topi.pohjolainen@intel.com</a>><br>
> > > ><br>
> > > > v3: Stomp more surface state fields<br>
> > > > ---<br>
> > > > src/mesa/drivers/dri/i965/brw_blorp.c | 163<br>
> > ++++++++++++++++++++++++++++++++++<br>
> > > > src/mesa/drivers/dri/i965/brw_blorp.h | 6 ++<br>
> > > > 2 files changed, 169 insertions(+)<br>
> > > ><br>
> > > > diff --git a/src/mesa/drivers/dri/i965/brw_blorp.c<br>
> > b/src/mesa/drivers/dri/i965/brw_blorp.c<br>
> > > > index 9590968..275f10c 100644<br>
> > > > --- a/src/mesa/drivers/dri/i965/brw_blorp.c<br>
> > > > +++ b/src/mesa/drivers/dri/i965/brw_blorp.c<br>
> > > > @@ -240,6 +240,169 @@ brw_blorp_compile_nir_shader(struct<br>
> > brw_context *brw, struct nir_shader *nir,<br>
> > > > return program;<br>
> > > > }<br>
> > > ><br>
> > > > +static enum isl_msaa_layout<br>
> > > > +get_isl_msaa_layout(enum intel_msaa_layout layout)<br>
> > > > +{<br>
> > > > + switch (layout) {<br>
> > > > + case INTEL_MSAA_LAYOUT_NONE:<br>
> > > > + return ISL_MSAA_LAYOUT_NONE;<br>
> > > > + case INTEL_MSAA_LAYOUT_IMS:<br>
> > > > + return ISL_MSAA_LAYOUT_INTERLEAVED;<br>
> > > > + case INTEL_MSAA_LAYOUT_UMS:<br>
> > > > + case INTEL_MSAA_LAYOUT_CMS:<br>
> > > > + return ISL_MSAA_LAYOUT_ARRAY;<br>
> > > > + default:<br>
> > > > + unreachable("Invalid MSAA layout");<br>
> > > > + }<br>
> > > > +}<br>
> > > > +<br>
> > > > +struct surface_state_info {<br>
> > > > + unsigned num_dwords;<br>
> > > > + unsigned ss_align; /* Required alignment of<br>
> > RENDER_SURFACE_STATE in bytes */<br>
> > > > + unsigned reloc_dw;<br>
> > > > + unsigned aux_reloc_dw;<br>
> > > > + unsigned tex_mocs;<br>
> > > > + unsigned rb_mocs;<br>
> > > > +};<br>
> > > > +<br>
> > > > +static const struct surface_state_info surface_state_infos[] = {<br>
> > > > + [6] = {6, 32, 1, 0},<br>
> > > > + [7] = {8, 32, 1, 6, GEN7_MOCS_L3, GEN7_MOCS_L3},<br>
> > > > + [8] = {13, 64, 8, 10, BDW_MOCS_WB, BDW_MOCS_PTE},<br>
> > > > + [9] = {16, 64, 8, 10, SKL_MOCS_WB, SKL_MOCS_PTE},<br>
> > > > +};<br>
> > > > +<br>
> > > > +uint32_t<br>
> > > > +brw_blorp_emit_surface_state(struct brw_context *brw,<br>
> > > > + const struct brw_blorp_surface_info<br>
> > *surface,<br>
> > > > + uint32_t read_domains, uint32_t<br>
> > write_domain,<br>
> > > > + bool is_render_target)<br>
> > > > +{<br>
> > > > + /* TODO: This should go in the context */<br>
> > > > + struct isl_device isl_dev;<br>
> > > > + isl_device_init(&isl_dev, brw->intelScreen->devinfo,<br>
> > brw->has_swizzling);<br>
> > > > +<br>
> > > > + const struct surface_state_info ss_info =<br>
> > surface_state_infos[brw->gen];<br>
> > > > +<br>
> > > > + struct isl_surf surf;<br>
> > > > + intel_miptree_get_isl_surf(brw, surface->mt, &surf);<br>
> > > > +<br>
> > > > + /* Stomp surface dimensions and tiling (if needed) with info<br>
> > from blorp */<br>
> > > > + surf.dim = ISL_SURF_DIM_2D;<br>
> > > > + surf.dim_layout = ISL_DIM_LAYOUT_GEN4_2D;<br>
> > > > + surf.msaa_layout = get_isl_msaa_layout(surface->msaa_layout);<br>
> > > > + surf.logical_level0_px.width = surface->width;<br>
> > > > + surf.logical_level0_px.height = surface->height;<br>
> > > > + surf.logical_level0_px.depth = 1;<br>
> > > > + surf.logical_level0_px.array_len = 1;<br>
> > ><br>
> > > You added these two lines which make sense. You didn't need them<br>
> > before, did<br>
> > > anything change or just assertions firing?<br>
> ><br>
> > The newly added X/YOffset assertions require this.<br>
> ><br>
> > > > + surf.levels = 1;<br>
> > > > + surf.samples = MAX2(surface->num_samples, 1);<br>
> > > > +<br>
> > > > + /* Alignment doesn't matter since we have 1 miplevel and 1<br>
> > array slice so<br>
> > > > + * just pick something that works for everybody.<br>
> > > > + */<br>
> > > > + surf.image_alignment_el = isl_extent3d(4, 4, 1);<br>
> > ><br>
> > > Same here, looks sane but makes me womnder what made you add this?<br>
> ><br>
> > There are two cases where we can end up with an alignment which is<br>
> > invalid for 3D surfaces: gen6 stencil and gen9 1D. In<br>
> > Intel_mipmap_tree, gen9 1D surfaces have an invalid halign value and we<br>
> > just special-case gen9 1D to use 64 everywhere. When I started using<br>
> > ISL for offset calculations in blorp, I needed image_alignment_el to<br>
> > have the correct value of (64, 1, 1) so I had to add that to<br>
> > miptree_get_isl_surf which meant we now had to undo it here.<br>
><br>
> But this patch would still work without this, or am I misunderstanding? We<br>
> still call brw_blorp_compute_tile_offsets() down below. In fact, I don't<br>
> really understand why setting image_alignment_el in miptree_get_isl_surf()<br>
> would help isl-based offset calculation either. That is going to replace<br>
> the blorp specific call below, and we are overriding the calculation<br>
> of miptree_get_isl_surf() here.</p>
<p dir="ltr">As part of the blorp transition, we need isl_surf_get_image_offset_el to work. That requires that we have assignments. Another way to think about this is just that this gets the resulting isl_surf closer to what isl itself would produce.</p>
<p dir="ltr">> I suppose there is just too many things happening the same time for me to keep<br>
> track. Some preparing for future patches and some needed locally...</p>
<p dir="ltr">Yeah... This mess is tricky...</p>
<p dir="ltr">> ><br>
> > > > +<br>
> > > > + if (brw->gen == 6 && surface->num_samples > 1) {<br>
> > > > + /* Since gen6 uses INTEL_MSAA_LAYOUT_IMS, width and height<br>
> > are measured<br>
> > > > + * in samples. But SURFACE_STATE wants them in pixels, so<br>
> > we need to<br>
> > > > + * divide them each by 2.<br>
> > > > + */<br>
> > > > + surf.logical_level0_px.width /= 2;<br>
> > > > + surf.logical_level0_px.height /= 2;<br>
> > > > + }<br>
> > > > +<br>
> > > > + if (brw->gen == 6 && surf.image_alignment_el.height > 4) {<br>
> > > > + /* This can happen on stencil buffers on Sandy Bridge due to<br>
> > the<br>
> > > > + * single-LOD work-around. It's fairly harmless as long as<br>
> > we don't<br>
> > > > + * pass a bogus value into isl_surf_fill_state().<br>
> > > > + */<br>
> > > > + surf.image_alignment_el = isl_extent3d(4, 2, 1);<br>
> > ><br>
> > > Earlier you set this unconditionally to isl_extent3d(4, 4, 1), isn't<br>
> > that<br>
> > > valid?<br>
> ><br>
> > Yes, I believe this can go now.<br>
> ><br>
> > > > + }<br>
> > > > +<br>
> > > > + if (surface->map_stencil_as_y_tiled) {<br>
> > > > + /* We need to fake W-tiling with Y-tiling */<br>
> > > > + surf.tiling = ISL_TILING_Y0;<br>
> > > > + surf.row_pitch *= 2;<br>
> > > > + }<br>
> > > > +<br>
> > > > + union isl_color_value clear_color = { .u32 = { 0, 0, 0, 0 } };<br>
> > > > +<br>
> > > > + struct isl_surf *aux_surf = NULL, aux_surf_s;<br>
> > > > + uint64_t aux_offset = 0;<br>
> > > > + enum isl_aux_usage aux_usage = ISL_AUX_USAGE_NONE;<br>
> > > > + if (surface->mt->mcs_mt) {<br>
> > > > + /* We should probably to similar stomping to above but most<br>
> > of the aux<br>
> > > > + * surf gets ignored when we fill out the surface state<br>
> > anyway so<br>
> > > > + * there's no point.<br>
> > > > + */<br>
> > > > + intel_miptree_get_aux_isl_surf(brw, surface->mt,<br>
> > &aux_surf_s, &aux_usage);<br>
> > > > + aux_surf = &aux_surf_s;<br>
> > > > + assert(surface->mt->mcs_mt->offset == 0);<br>
> > > > + aux_offset = surface->mt->mcs_mt->bo->offset64;<br>
> > > > +<br>
> > > > + /* We only really need a clear color if we also have an<br>
> > auxiliary<br>
> > > > + * surface. Without one, it does nothing.<br>
> > > > + */<br>
> > > > + clear_color = intel_miptree_get_isl_clear_color(brw,<br>
> > surface->mt);<br>
> > > > + }<br>
> > > > +<br>
> > > > + struct isl_view view = {<br>
> > > > + .format = surface->brw_surfaceformat,<br>
> > > > + .base_level = 0,<br>
> > > > + .levels = 1,<br>
> > > > + .base_array_layer = 0,<br>
> > > > + .array_len = 1,<br>
> > > > + .channel_select = {<br>
> > > > + ISL_CHANNEL_SELECT_RED,<br>
> > > > + ISL_CHANNEL_SELECT_GREEN,<br>
> > > > + ISL_CHANNEL_SELECT_BLUE,<br>
> > > > + ISL_CHANNEL_SELECT_ALPHA,<br>
> > > > + },<br>
> > > > + .usage = is_render_target ? ISL_SURF_USAGE_RENDER_TARGET_BIT<br>
> > :<br>
> > > > + ISL_SURF_USAGE_TEXTURE_BIT,<br>
> > > > + };<br>
> > > > +<br>
> > > > + uint32_t offset, tile_x, tile_y;<br>
> > > > + offset = brw_blorp_compute_tile_offsets(surface, &tile_x,<br>
> > &tile_y);<br>
> > > > +<br>
> > > > + uint32_t surf_offset;<br>
> > > > + uint32_t *dw = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE,<br>
> > > > + ss_info.num_dwords * 4,<br>
> > ss_info.ss_align,<br>
> > > > + &surf_offset);<br>
> > > > +<br>
> > > > + const uint32_t mocs = is_render_target ? ss_info.rb_mocs :<br>
> > ss_info.tex_mocs;<br>
> > > > +<br>
> > > > + isl_surf_fill_state(&isl_dev, dw, .surf = &surf, .view = &view,<br>
> > > > + .address = surface->mt->bo->offset64 +<br>
> > offset,<br>
> > > > + .aux_surf = aux_surf, .aux_usage =<br>
> > aux_usage,<br>
> > > > + .aux_address = aux_offset,<br>
> > > > + .mocs = mocs, .clear_color = clear_color,<br>
> > > > + .x_offset_sa = tile_x, .y_offset_sa =<br>
> > tile_y);<br>
> > > > +<br>
> > > > + /* Emit relocation to surface contents */<br>
> > > > + drm_intel_bo_emit_reloc(brw->[3]<a href="http://batch.bo">batch.bo</a>,<br>
> > > > + surf_offset + ss_info.reloc_dw * 4,<br>
> > > > + surface->mt->bo,<br>
> > > > + dw[ss_info.reloc_dw] -<br>
> > surface->mt->bo->offset64,<br>
> > > > + read_domains, write_domain);<br>
> > > > +<br>
> > > > + if (aux_surf) {<br>
> > > > + /* On gen7 and prior, the bottom 12 bits of the MCS base<br>
> > address are<br>
> > > > + * used to store other information. This should be ok,<br>
> > however, because<br>
> > > > + * surface buffer addresses are always 4K page alinged.<br>
> > > > + */<br>
> > > > + assert((aux_offset & 0xfff) == 0);<br>
> > > > + drm_intel_bo_emit_reloc(brw->[4]<a href="http://batch.bo">batch.bo</a>,<br>
> > > > + surf_offset + ss_info.aux_reloc_dw *<br>
> > 4,<br>
> > > > + surface->mt->mcs_mt->bo,<br>
> > > > + dw[ss_info.aux_reloc_dw] & 0xfff,<br>
> > > > + read_domains, write_domain);<br>
> > > > + }<br>
> > > > +<br>
> > > > + return surf_offset;<br>
> > > > +}<br>
> > > > +<br>
> > > > /**<br>
> > > > * Perform a HiZ or depth resolve operation.<br>
> > > > *<br>
> > > > diff --git a/src/mesa/drivers/dri/i965/brw_blorp.h<br>
> > b/src/mesa/drivers/dri/i965/brw_blorp.h<br>
> > > > index 7ec5875..bacdecb 100644<br>
> > > > --- a/src/mesa/drivers/dri/i965/brw_blorp.h<br>
> > > > +++ b/src/mesa/drivers/dri/i965/brw_blorp.h<br>
> > > > @@ -372,6 +372,12 @@ brw_blorp_compile_nir_shader(struct<br>
> > brw_context *brw, struct nir_shader *nir,<br>
> > > > struct brw_blorp_prog_data<br>
> > *prog_data,<br>
> > > > unsigned *program_size);<br>
> > > ><br>
> > > > +uint32_t<br>
> > > > +brw_blorp_emit_surface_state(struct brw_context *brw,<br>
> > > > + const struct brw_blorp_surface_info<br>
> > *surface,<br>
> > > > + uint32_t read_domains, uint32_t<br>
> > write_domain,<br>
> > > > + bool is_render_target);<br>
> > > > +<br>
> > > > void<br>
> > > > gen6_blorp_init(struct brw_context *brw);<br>
> > > ><br>
> > > > --<br>
> > > > 2.5.0.400.gff86faf<br>
> > > ><br>
> > > > _______________________________________________<br>
> > > > mesa-dev mailing list<br>
> > > > [5]<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> > > > [6]<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
> ><br>
> > References<br>
> ><br>
> > 1. mailto:<a href="mailto:topi.pohjolainen@intel.com">topi.pohjolainen@intel.com</a><br>
> > 2. mailto:<a href="mailto:topi.pohjolainen@intel.com">topi.pohjolainen@intel.com</a><br>
> > 3. <a href="http://batch.bo/">http://batch.bo/</a><br>
> > 4. <a href="http://batch.bo/">http://batch.bo/</a><br>
> > 5. mailto:<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> > 6. <a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</p>