[Intel-gfx] [PATCH 18/23] drm/i915: Shrink the size of intel_remapped_plane_info struct

Imre Deak imre.deak at intel.com
Thu Mar 11 22:19:42 UTC 2021


On Thu, Mar 11, 2021 at 09:45:14PM +0200, Ville Syrjälä wrote:
> On Thu, Mar 11, 2021 at 12:17:31AM +0200, Imre Deak wrote:
> > Save some place in the GTT VMAs by using a u16 instead of unsigned int
> > to store the view dimensions. The maximum FB stride is 256kB which is
> > 4096 tiles in the worst case (yf-tiles), the maximum FB height is 16k
> > pixels, which is 2048 tiles in the worst case (x-tiles).
> 
> Actually I think the worst case for height is remapping linear fbs
> since we more or less treat it as 4kx1 tiles. But 16k is still< 64k
> so should be all good.

Yes, thanks for catching that. Will fix the commit message.

> Integer promotion stuff/etc. is what worried me the most here, but
> looks like rotate_pages()/remap_pages() at least gets everything
> passed in as unsigned int, so we're not in danger of sign bit
> shenanigans there at least.

Yes. Fwiw I can think only of the following kind of sign-extension
problem scenario with u16:

u16 v1=-1;
int i=v1;

So if u16 stored a negative result, we'd miss the expected
sign-extension, but I can't see a way we wanted to store a negative
value to these fields. So for instance in remap_pages() the

	offset += src_stride - width;

would be still correct even if src_stride/width would be u16 and
src_stride was less than width.

> Reviewed-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
> 
> > 
> > Signed-off-by: Imre Deak <imre.deak at intel.com>
> > ---
> >  drivers/gpu/drm/i915/display/intel_fb.c | 15 ++++++++++++---
> >  drivers/gpu/drm/i915/i915_vma_types.h   | 12 ++++++++----
> >  2 files changed, 20 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/i915/display/intel_fb.c b/drivers/gpu/drm/i915/display/intel_fb.c
> > index 16a1b5c922bb..51c56f0a4a99 100644
> > --- a/drivers/gpu/drm/i915/display/intel_fb.c
> > +++ b/drivers/gpu/drm/i915/display/intel_fb.c
> > @@ -619,13 +619,22 @@ static u32 calc_plane_remap_info(const struct intel_framebuffer *fb, int color_p
> >  	unsigned int tile_width = dims->tile_width;
> >  	unsigned int tile_height = dims->tile_height;
> >  	unsigned int tile_size = intel_tile_size(i915);
> > +	unsigned int stride_tiles = plane_view_stride_tiles(fb, color_plane, dims);
> > +	unsigned int width_tiles = DIV_ROUND_UP(x + dims->width, dims->tile_width);
> > +	unsigned int height_tiles = plane_view_tile_rows(fb, color_plane, dims, y);
> >  	unsigned int pitch_tiles;
> >  	struct drm_rect r;
> >  
> > +	drm_WARN_ON(&i915->drm,
> > +		    overflows_type(obj_offset, gtt_remap_info->offset) ||
> > +		    overflows_type(stride_tiles, gtt_remap_info->stride) ||
> > +		    overflows_type(width_tiles, gtt_remap_info->width) ||
> > +		    overflows_type(height_tiles, gtt_remap_info->height));
> > +
> >  	gtt_remap_info->offset = obj_offset;
> > -	gtt_remap_info->width = DIV_ROUND_UP(x + dims->width, dims->tile_width);
> > -	gtt_remap_info->height = plane_view_tile_rows(fb, color_plane, dims, y);
> > -	gtt_remap_info->stride = plane_view_stride_tiles(fb, color_plane, dims);
> > +	gtt_remap_info->stride = stride_tiles;
> > +	gtt_remap_info->width = width_tiles;
> > +	gtt_remap_info->height = height_tiles;
> >  
> >  	if (view_type == I915_GGTT_VIEW_ROTATED) {
> >  		/* rotate the x/y offsets to match the GTT view */
> > diff --git a/drivers/gpu/drm/i915/i915_vma_types.h b/drivers/gpu/drm/i915/i915_vma_types.h
> > index f5cb848b7a7e..358b4306fc00 100644
> > --- a/drivers/gpu/drm/i915/i915_vma_types.h
> > +++ b/drivers/gpu/drm/i915/i915_vma_types.h
> > @@ -97,12 +97,16 @@ enum i915_cache_level;
> >  
> >  struct intel_remapped_plane_info {
> >  	/* in gtt pages */
> > -	unsigned int width, height, stride, offset;
> > +	u32 offset;
> > +	u16 width;
> > +	u16 height;
> > +	u16 stride;
> > +	u16 unused_mbz;
> >  } __packed;
> >  
> >  struct intel_remapped_info {
> >  	struct intel_remapped_plane_info plane[2];
> > -	unsigned int unused_mbz;
> > +	u32 unused_mbz;
> >  } __packed;
> >  
> >  struct intel_rotation_info {
> > @@ -123,9 +127,9 @@ enum i915_ggtt_view_type {
> >  
> >  static inline void assert_i915_gem_gtt_types(void)
> >  {
> > -	BUILD_BUG_ON(sizeof(struct intel_rotation_info) != 8*sizeof(unsigned int));
> > +	BUILD_BUG_ON(sizeof(struct intel_rotation_info) != 2 * sizeof(u32) + 8 * sizeof(u16));
> >  	BUILD_BUG_ON(sizeof(struct intel_partial_info) != sizeof(u64) + sizeof(unsigned int));
> > -	BUILD_BUG_ON(sizeof(struct intel_remapped_info) != 9*sizeof(unsigned int));
> > +	BUILD_BUG_ON(sizeof(struct intel_remapped_info) != 3 * sizeof(u32) + 8 * sizeof(u16));
> >  
> >  	/* Check that rotation/remapped shares offsets for simplicity */
> >  	BUILD_BUG_ON(offsetof(struct intel_remapped_info, plane[0]) !=
> > -- 
> > 2.25.1
> > 
> > _______________________________________________
> > Intel-gfx mailing list
> > Intel-gfx at lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/intel-gfx
> 
> -- 
> Ville Syrjälä
> Intel


More information about the Intel-gfx mailing list