[Mesa-dev] [PATCH 3/6] isl: Refactor row pitch calculation
Chad Versace
chadversary at chromium.org
Mon Mar 6 18:12:10 UTC 2017
The calculations of row_pitch, surface size, and base_alignment were
mixed together. Extract the calculation of row pitch into a new
function, isl_calc_row_pitch(), and call it before calculating
surface_size and base_alignment.
This simplifies a follow-on patch that adds a new member, 'row_pitch',
to struct isl_surf_init_info.
---
src/intel/isl/isl.c | 60 ++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 43 insertions(+), 17 deletions(-)
diff --git a/src/intel/isl/isl.c b/src/intel/isl/isl.c
index 189330b723d..a91c3f92bcf 100644
--- a/src/intel/isl/isl.c
+++ b/src/intel/isl/isl.c
@@ -1080,6 +1080,45 @@ isl_calc_linear_row_pitch(const struct isl_device *dev,
return row_pitch;
}
+static uint32_t
+isl_calc_tiled_row_pitch(const struct isl_device *dev,
+ const struct isl_surf_init_info *info,
+ const struct isl_tile_info *tile_info,
+ const struct isl_extent2d *phys_slice0_sa)
+{
+ const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
+
+ assert(fmtl->bpb % tile_info->format_bpb == 0);
+ assert(phys_slice0_sa->w % fmtl->bw == 0);
+
+ const uint32_t tile_el_scale = fmtl->bpb / tile_info->format_bpb;
+ const uint32_t total_w_el = phys_slice0_sa->width / fmtl->bw;
+ const uint32_t total_w_tl =
+ isl_align_div(total_w_el * tile_el_scale,
+ tile_info->logical_extent_el.width);
+
+ uint32_t row_pitch = total_w_tl * tile_info->phys_extent_B.width;
+ if (row_pitch < info->min_row_pitch) {
+ row_pitch = isl_align_npot(info->min_row_pitch,
+ tile_info->phys_extent_B.width);
+ }
+
+ return row_pitch;
+}
+
+static uint32_t
+isl_calc_row_pitch(const struct isl_device *dev,
+ const struct isl_surf_init_info *info,
+ const struct isl_tile_info *tile_info,
+ const struct isl_extent2d *phys_slice0_sa)
+{
+ if (tile_info->tiling == ISL_TILING_LINEAR) {
+ return isl_calc_linear_row_pitch(dev, info, phys_slice0_sa);
+ } else {
+ return isl_calc_tiled_row_pitch(dev, info, tile_info, phys_slice0_sa);
+ }
+}
+
/**
* Calculate and apply any padding required for the surface.
*
@@ -1252,9 +1291,11 @@ isl_surf_init_s(const struct isl_device *dev,
uint32_t pad_bytes;
isl_apply_surface_padding(dev, info, &tile_info, &total_h_el, &pad_bytes);
- uint32_t row_pitch, size, base_alignment;
+ const uint32_t row_pitch = isl_calc_row_pitch(dev, info, &tile_info,
+ &phys_slice0_sa);
+
+ uint32_t size, base_alignment;
if (tiling == ISL_TILING_LINEAR) {
- row_pitch = isl_calc_linear_row_pitch(dev, info, &phys_slice0_sa);
size = row_pitch * total_h_el + pad_bytes;
/* From the Broadwell PRM Vol 2d, RENDER_SURFACE_STATE::SurfaceBaseAddress:
@@ -1276,21 +1317,6 @@ isl_surf_init_s(const struct isl_device *dev,
}
base_alignment = isl_round_up_to_power_of_two(base_alignment);
} else {
- assert(fmtl->bpb % tile_info.format_bpb == 0);
- const uint32_t tile_el_scale = fmtl->bpb / tile_info.format_bpb;
-
- assert(phys_slice0_sa.w % fmtl->bw == 0);
- const uint32_t total_w_el = phys_slice0_sa.width / fmtl->bw;
- const uint32_t total_w_tl =
- isl_align_div(total_w_el * tile_el_scale,
- tile_info.logical_extent_el.width);
-
- row_pitch = total_w_tl * tile_info.phys_extent_B.width;
- if (row_pitch < info->min_row_pitch) {
- row_pitch = isl_align_npot(info->min_row_pitch,
- tile_info.phys_extent_B.width);
- }
-
total_h_el += isl_align_div_npot(pad_bytes, row_pitch);
const uint32_t total_h_tl =
isl_align_div(total_h_el, tile_info.logical_extent_el.height);
--
2.12.0
More information about the mesa-dev
mailing list