Skip to content

Commit b611b1d

Browse files
committed
backend: Use a static array for the tile list
Use an array sized to PISP_BACK_END_NUM_TILES for the tile list in the backend object. This removes the use of std::vector which will be needed to ensure class BackEnd is of standard-layout type. Signed-off-by: Naushir Patuck <[email protected]>
1 parent 31cc22a commit b611b1d

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/libpisp/backend/backend.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
namespace libpisp
2626
{
2727

28+
using TileArray = std::array<pisp_tile, PISP_BACK_END_NUM_TILES>;
29+
2830
class BackEnd final
2931
{
3032
public:
@@ -166,7 +168,7 @@ class BackEnd final
166168
void finaliseConfig();
167169
void updateSmartResize();
168170
void updateTiles();
169-
std::vector<pisp_tile> retilePipeline(TilingConfig const &tiling_config);
171+
TileArray retilePipeline(TilingConfig const &tiling_config);
170172
void finaliseTiling();
171173
void getOutputSize(int output_num, uint16_t *width, uint16_t *height, pisp_image_format_config const &ifmt) const;
172174

@@ -179,7 +181,7 @@ class BackEnd final
179181
pisp_image_format_config max_input_;
180182
bool retile_;
181183
bool finalise_tiling_;
182-
std::vector<pisp_tile> tiles_;
184+
TileArray tiles_;
183185
int num_tiles_x_, num_tiles_y_;
184186
mutable ShmMutex mutex_;
185187
std::array<SmartResize, PISP_BACK_END_NUM_OUTPUTS> smart_resize_;

src/libpisp/backend/backend_prepare.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,13 @@ void finalise_output(pisp_be_output_format_config &config)
304304
throw std::runtime_error("finalise_output: image stride should be at least 16-byte aligned");
305305
}
306306

307-
void check_tiles(std::vector<pisp_tile> const &tiles, uint32_t rgb_enables, unsigned int numBranches,
308-
TilingConfig const &tiling_config)
307+
void check_tiles(TileArray const &tiles, uint32_t rgb_enables, unsigned int numBranches, unsigned int num_tiles,
308+
TilingConfig const &tiling_config)
309309
{
310-
int tile_num = 0;
311-
for (auto &tile : tiles)
310+
for (unsigned int tile_num = 0; tile_num < num_tiles; tile_num++)
312311
{
312+
const pisp_tile &tile = tiles[tile_num];
313+
313314
PISP_ASSERT(tile.input_width && tile.input_height); // zero inputs shouldn't be possible
314315

315316
if (tile.input_width < PISP_BACK_END_MIN_TILE_WIDTH || tile.input_height < PISP_BACK_END_MIN_TILE_HEIGHT)
@@ -361,7 +362,6 @@ void check_tiles(std::vector<pisp_tile> const &tiles, uint32_t rgb_enables, unsi
361362
throw std::runtime_error("Tile height too small at output");
362363
}
363364
}
364-
tile_num++;
365365
}
366366
}
367367

@@ -729,7 +729,8 @@ void BackEnd::updateTiles()
729729
// outside the actual image width (and we've chosen not to handle compression like that).
730730
tiling_config.compressed_input = false;
731731
tiles_ = retilePipeline(tiling_config);
732-
check_tiles(tiles_, c.global.rgb_enables, variant_.BackEndNumBranches(0), tiling_config);
732+
check_tiles(tiles_, c.global.rgb_enables, variant_.BackEndNumBranches(0), num_tiles_x_ * num_tiles_y_,
733+
tiling_config);
733734
finalise_tiling_ = true;
734735
}
735736

@@ -740,7 +741,7 @@ void BackEnd::updateTiles()
740741
}
741742
}
742743

743-
std::vector<pisp_tile> BackEnd::retilePipeline(TilingConfig const &tiling_config)
744+
TileArray BackEnd::retilePipeline(TilingConfig const &tiling_config)
744745
{
745746
// The tiling library provides tiles in a SW Tile structure.
746747
Tile tiles[PISP_BACK_END_NUM_TILES];
@@ -750,11 +751,11 @@ std::vector<pisp_tile> BackEnd::retilePipeline(TilingConfig const &tiling_config
750751
num_tiles_x_ = grid.dx;
751752
num_tiles_y_ = grid.dy;
752753

753-
std::vector<pisp_tile> tile_vector(num_tiles_x_ * num_tiles_y_);
754+
TileArray tile_array;
754755
// Finally convert the Tiles into pisp_tiles.
755756
for (int i = 0; i < num_tiles_x_ * num_tiles_y_; i++)
756757
{
757-
pisp_tile &t = tile_vector[i];
758+
pisp_tile &t = tile_array[i];
758759

759760
memset(&t, 0, sizeof(pisp_tile));
760761
t.edge = 0;
@@ -892,14 +893,16 @@ std::vector<pisp_tile> BackEnd::retilePipeline(TilingConfig const &tiling_config
892893
}
893894
}
894895
}
895-
return tile_vector;
896+
return tile_array;
896897
}
897898

898899
void BackEnd::finaliseTiling()
899900
{
900901
// Update tile parameters (offsets/strides) from on the BE pipeline configuration.
901-
for (pisp_tile &t : tiles_)
902+
for (int i = 0; i < num_tiles_x_ * num_tiles_y_; i++)
902903
{
904+
pisp_tile &t = tiles_[i];
905+
903906
calculate_input_addr_offset(t.input_offset_x, t.input_offset_y, be_config_.input_format, &t.input_addr_offset,
904907
&t.input_addr_offset2);
905908
calculate_input_addr_offset(t.input_offset_x, t.input_offset_y, be_config_.tdn_input_format,

0 commit comments

Comments
 (0)