Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pispbe/port to mainline pisp be #30

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libpisp/backend/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
#pragma once

#include <cstdint>
#include <string>
#include <type_traits>
#include <utility>
Expand Down
2 changes: 1 addition & 1 deletion src/libpisp/backend/backend_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ std::string BackEnd::GetJsonConfig(pisp_be_tiles_config *config)
j["config"].push_back(b);
}

for (int t = 0; t < config->num_tiles; t++)
for (unsigned int t = 0; t < config->num_tiles; t++)
{
json b;
for (auto const &field : tiles_config.fields)
Expand Down
120 changes: 74 additions & 46 deletions src/libpisp/backend/backend_prepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void check_stride(pisp_image_format_config const &config)
if (config.stride % PISP_BACK_END_OUTPUT_MIN_ALIGN || config.stride2 % PISP_BACK_END_OUTPUT_MIN_ALIGN)
throw std::runtime_error("Output stride values not sufficiently aligned");

if (PISP_IMAGE_FORMAT_wallpaper(config.format) && (config.stride % 128 || config.stride2 % 128))
if (PISP_IMAGE_FORMAT_WALLPAPER(config.format) && (config.stride % 128 || config.stride2 % 128))
throw std::runtime_error("Wallpaper format should have 128-byte aligned rolls");

pisp_image_format_config check = config;
Expand Down Expand Up @@ -66,13 +66,13 @@ void finalise_inputs(pisp_be_config &config)
}
else if (config.global.rgb_enables & PISP_BE_RGB_ENABLE_INPUT)
{
if (PISP_IMAGE_FORMAT_sampling_420(config.input_format.format) && (config.input_format.width & 1))
if (PISP_IMAGE_FORMAT_SAMPLING_420(config.input_format.format) && (config.input_format.width & 1))
throw std::runtime_error("finalise_inputs: 420 input height must be even");
else if ((PISP_IMAGE_FORMAT_sampling_420(config.input_format.format) ||
PISP_IMAGE_FORMAT_sampling_422(config.input_format.format)) &&
else if ((PISP_IMAGE_FORMAT_SAMPLING_420(config.input_format.format) ||
PISP_IMAGE_FORMAT_SAMPLING_422(config.input_format.format)) &&
(config.input_format.width & 1))
throw std::runtime_error("finalise_inputs: 420/422 input width must be even");
if (PISP_IMAGE_FORMAT_wallpaper(config.input_format.format))
if (PISP_IMAGE_FORMAT_WALLPAPER(config.input_format.format))
{
if ((config.input_format.stride & 127) || (config.input_format.stride2 & 127))
throw std::runtime_error("finalise_inputs: wallpaper format strides must be at least 128-byte aligned");
Expand Down Expand Up @@ -150,13 +150,13 @@ void finalise_decompression(pisp_be_config const &be_config)
{
uint32_t fmt = be_config.input_format.format, bayer_enables = be_config.global.bayer_enables;

if (PISP_IMAGE_FORMAT_compressed(fmt) && !(bayer_enables & PISP_BE_BAYER_ENABLE_DECOMPRESS))
if (PISP_IMAGE_FORMAT_COMPRESSED(fmt) && !(bayer_enables & PISP_BE_BAYER_ENABLE_DECOMPRESS))
throw std::runtime_error("BackEnd::finalise: input compressed but decompression not enabled");

if (!PISP_IMAGE_FORMAT_compressed(fmt) && (bayer_enables & PISP_BE_BAYER_ENABLE_DECOMPRESS))
if (!PISP_IMAGE_FORMAT_COMPRESSED(fmt) && (bayer_enables & PISP_BE_BAYER_ENABLE_DECOMPRESS))
throw std::runtime_error("BackEnd::finalise: input uncompressed but decompression enabled");

if ((bayer_enables & PISP_BE_BAYER_ENABLE_DECOMPRESS) && !PISP_IMAGE_FORMAT_bps_8(fmt))
if ((bayer_enables & PISP_BE_BAYER_ENABLE_DECOMPRESS) && !PISP_IMAGE_FORMAT_BPS_8(fmt))
throw std::runtime_error("BackEnd::finalise: compressed input is not 8bpp");
}

Expand Down Expand Up @@ -189,13 +189,13 @@ void finalise_tdn(pisp_be_config &config)
if (tdn_enabled && !tdn_output_enabled)
throw std::runtime_error("BackEnd::finalise: TDN output not enabled when TDN enabled");

if (PISP_IMAGE_FORMAT_compressed(fmt) && !tdn_compress_enabled)
if (PISP_IMAGE_FORMAT_COMPRESSED(fmt) && !tdn_compress_enabled)
throw std::runtime_error("BackEnd::finalise: TDN output compressed but compression not enabled");

if (!PISP_IMAGE_FORMAT_compressed(fmt) && tdn_compress_enabled)
if (!PISP_IMAGE_FORMAT_COMPRESSED(fmt) && tdn_compress_enabled)
throw std::runtime_error("BackEnd::finalise: TDN output uncompressed but compression enabled");

if (tdn_compress_enabled && !PISP_IMAGE_FORMAT_bps_8(fmt))
if (tdn_compress_enabled && !PISP_IMAGE_FORMAT_BPS_8(fmt))
throw std::runtime_error("BackEnd::finalise: TDN output does not match compression mode");

if (tdn_output_enabled)
Expand All @@ -222,11 +222,11 @@ void finalise_tdn(pisp_be_config &config)
// Make the TDN input match the output if it's unset. Usually this will be the sensible thing to do.
if (config.tdn_input_format.width == 0 && config.tdn_input_format.height == 0)
config.tdn_input_format = config.tdn_output_format;
if (PISP_IMAGE_FORMAT_compressed(fmt) && !tdn_decompress_enabled)
if (PISP_IMAGE_FORMAT_COMPRESSED(fmt) && !tdn_decompress_enabled)
throw std::runtime_error("BackEnd::finalise: TDN input compressed but decompression not enabled");
if (!PISP_IMAGE_FORMAT_compressed(fmt) && tdn_decompress_enabled)
if (!PISP_IMAGE_FORMAT_COMPRESSED(fmt) && tdn_decompress_enabled)
throw std::runtime_error("BackEnd::finalise: TDN input uncompressed but decompression enabled");
if (tdn_compress_enabled && !PISP_IMAGE_FORMAT_bps_8(fmt))
if (tdn_compress_enabled && !PISP_IMAGE_FORMAT_BPS_8(fmt))
throw std::runtime_error("BackEnd::finalise: TDN output does not match compression mode");
}
}
Expand All @@ -243,17 +243,17 @@ void finalise_stitch(pisp_be_config &config)

if (stitch_enabled != stitch_input_enabled)
throw std::runtime_error("BackEnd::finalise: stitch and stitch_input should be enabled/disabled together");
if (stitch_input_enabled && PISP_IMAGE_FORMAT_compressed(input_fmt) && !stitch_decompress_enabled)
if (stitch_input_enabled && PISP_IMAGE_FORMAT_COMPRESSED(input_fmt) && !stitch_decompress_enabled)
throw std::runtime_error("BackEnd::finalise: stitch output compressed but decompression not enabled");
if (stitch_input_enabled && !PISP_IMAGE_FORMAT_compressed(input_fmt) && stitch_decompress_enabled)
if (stitch_input_enabled && !PISP_IMAGE_FORMAT_COMPRESSED(input_fmt) && stitch_decompress_enabled)
throw std::runtime_error("BackEnd::finalise: stitch output uncompressed but decompression enabled");
if (stitch_output_enabled && PISP_IMAGE_FORMAT_compressed(output_fmt) && !stitch_compress_enabled)
if (stitch_output_enabled && PISP_IMAGE_FORMAT_COMPRESSED(output_fmt) && !stitch_compress_enabled)
throw std::runtime_error("BackEnd::finalise: stitch output compressed but compression not enabled");
if (stitch_output_enabled && !PISP_IMAGE_FORMAT_compressed(output_fmt) && stitch_compress_enabled)
if (stitch_output_enabled && !PISP_IMAGE_FORMAT_COMPRESSED(output_fmt) && stitch_compress_enabled)
throw std::runtime_error("BackEnd::finalise: stitch output uncompressed but compression enabled");
if (stitch_decompress_enabled && !PISP_IMAGE_FORMAT_bps_8(input_fmt))
if (stitch_decompress_enabled && !PISP_IMAGE_FORMAT_BPS_8(input_fmt))
throw std::runtime_error("BackEnd::finalise: stitch input does not match compression mode");
if (stitch_compress_enabled && !PISP_IMAGE_FORMAT_bps_8(output_fmt))
if (stitch_compress_enabled && !PISP_IMAGE_FORMAT_BPS_8(output_fmt))
throw std::runtime_error("BackEnd::finalise: stitch output does not match compression mode");

if (stitch_output_enabled)
Expand Down Expand Up @@ -286,14 +286,14 @@ void finalise_output(pisp_be_output_format_config &config)
if (config.image.width < PISP_BACK_END_MIN_TILE_WIDTH || config.image.height < PISP_BACK_END_MIN_TILE_HEIGHT)
throw std::runtime_error("finalise_output: output image too small");

if (PISP_IMAGE_FORMAT_sampling_420(config.image.format) && (config.image.height & 1))
if (PISP_IMAGE_FORMAT_SAMPLING_420(config.image.format) && (config.image.height & 1))
throw std::runtime_error("finalise_output: 420 image height should be even");

if ((PISP_IMAGE_FORMAT_sampling_420(config.image.format) || PISP_IMAGE_FORMAT_sampling_422(config.image.format)) &&
if ((PISP_IMAGE_FORMAT_SAMPLING_420(config.image.format) || PISP_IMAGE_FORMAT_SAMPLING_422(config.image.format)) &&
(config.image.width & 1))
throw std::runtime_error("finalise_output: 420/422 image width should be even");

if (PISP_IMAGE_FORMAT_wallpaper(config.image.format))
if (PISP_IMAGE_FORMAT_WALLPAPER(config.image.format))
{
if ((config.image.stride & 127) || (config.image.stride2 & 127))
throw std::runtime_error("finalise_output: wallpaper image stride should be at least 128-byte aligned");
Expand Down Expand Up @@ -367,17 +367,17 @@ unsigned int get_pixel_alignment(uint32_t format, int byte_alignment)
{
int alignment_pixels = byte_alignment; // for 8bpp formats

if (PISP_IMAGE_FORMAT_bps_16(format))
if (PISP_IMAGE_FORMAT_BPS_16(format))
alignment_pixels = byte_alignment / 2;
else if (PISP_IMAGE_FORMAT_bps_10(format))
else if (PISP_IMAGE_FORMAT_BPS_10(format))
alignment_pixels = byte_alignment * 3 / 4;
else if (PISP_IMAGE_FORMAT_bpp_32(format))
else if (PISP_IMAGE_FORMAT_BPP_32(format))
alignment_pixels = byte_alignment / 4;

if (PISP_IMAGE_FORMAT_planar(format) && !PISP_IMAGE_FORMAT_sampling_444(format))
if (PISP_IMAGE_FORMAT_PLANAR(format) && !PISP_IMAGE_FORMAT_SAMPLING_444(format))
alignment_pixels *= 2; // the UV planes in fully planar 420/422 output will have half the width
else if (PISP_IMAGE_FORMAT_interleaved(format) &&
(PISP_IMAGE_FORMAT_sampling_422(format) || PISP_IMAGE_FORMAT_sampling_420(format)))
else if (PISP_IMAGE_FORMAT_INTERLEAVED(format) &&
(PISP_IMAGE_FORMAT_SAMPLING_422(format) || PISP_IMAGE_FORMAT_SAMPLING_420(format)))
alignment_pixels /= 2; // YUYV type outputs need only 8 pixels to make 16 bytes

return alignment_pixels;
Expand All @@ -398,19 +398,19 @@ static tiling::Length2 calculate_input_alignment(pisp_be_config const &config)
PISP_LOG(debug, "RGB input enabled");
// Need 4 byte alignment AND even number of pixels. Height must be 2 row aligned only for 420 input.
return tiling::Length2(lcm(get_pixel_alignment(config.input_format.format, PISP_BACK_END_INPUT_ALIGN), 2),
PISP_IMAGE_FORMAT_sampling_420(config.input_format.format) ? 2 : 1);
PISP_IMAGE_FORMAT_SAMPLING_420(config.input_format.format) ? 2 : 1);
}

uint32_t bayer_enables = config.global.bayer_enables;
// For starters, we need 4 *byte* alignment (this automatically cover 2 *pixel* alignment for all the raw formats).
int pixel_alignment = get_pixel_alignment(config.input_format.format, PISP_BACK_END_INPUT_ALIGN);

// If any input is compressed, we need 8 *pixel* alignment.
if (PISP_IMAGE_FORMAT_compressed(config.input_format.format) ||
if (PISP_IMAGE_FORMAT_COMPRESSED(config.input_format.format) ||
((bayer_enables & PISP_BE_BAYER_ENABLE_TDN_INPUT) &&
PISP_IMAGE_FORMAT_compressed(config.tdn_input_format.format)) ||
PISP_IMAGE_FORMAT_COMPRESSED(config.tdn_input_format.format)) ||
((bayer_enables & PISP_BE_BAYER_ENABLE_STITCH_INPUT) &&
PISP_IMAGE_FORMAT_compressed(config.stitch_input_format.format)))
PISP_IMAGE_FORMAT_COMPRESSED(config.stitch_input_format.format)))
pixel_alignment = lcm(pixel_alignment, PISP_BACK_END_COMPRESSED_ALIGN);

// If any of the Bayer outputs are enabled, those need 16 *byte* alignment. (This already covers the outputs being compressed.)
Expand All @@ -426,7 +426,7 @@ static tiling::Length2 calculate_input_alignment(pisp_be_config const &config)

static tiling::Length2 calculate_output_alignment(uint32_t format, int align = PISP_BACK_END_OUTPUT_MAX_ALIGN)
{
int y_alignment = PISP_IMAGE_FORMAT_sampling_420(format) ? 2 : 1;
int y_alignment = PISP_IMAGE_FORMAT_SAMPLING_420(format) ? 2 : 1;

return tiling::Length2(get_pixel_alignment(format, align), y_alignment);
}
Expand Down Expand Up @@ -897,16 +897,33 @@ void BackEnd::finaliseTiling()
// Update tile parameters (offsets/strides) from on the BE pipeline configuration.
for (pisp_tile &t : tiles_)
{
calculate_input_addr_offset(t.input_offset_x, t.input_offset_y, be_config_.input_format, &t.input_addr_offset,
&t.input_addr_offset2);
calculate_input_addr_offset(t.input_offset_x, t.input_offset_y, be_config_.tdn_input_format,
&t.tdn_input_addr_offset);
calculate_input_addr_offset(t.input_offset_x, t.input_offset_y, be_config_.tdn_output_format,
&t.tdn_output_addr_offset);
calculate_input_addr_offset(t.input_offset_x, t.input_offset_y, be_config_.stitch_input_format,
&t.stitch_input_addr_offset);
calculate_input_addr_offset(t.input_offset_x, t.input_offset_y, be_config_.stitch_output_format,
&t.stitch_output_addr_offset);
int offset_x = t.input_offset_x;
int offset_y = t.input_offset_y;
uint32_t addr_offset = t.input_addr_offset;
uint32_t addr_offset2 = t.input_addr_offset2;
uint32_t tdn_input_addr_offset = t.tdn_input_addr_offset;
uint32_t tdn_output_addr_offset = t.tdn_output_addr_offset;
uint32_t stitch_input_addr_offset = t.stitch_input_addr_offset;
uint32_t stitch_output_addr_offset = t.stitch_output_addr_offset;

calculate_input_addr_offset(offset_x, offset_y, be_config_.input_format, &addr_offset,
&addr_offset2);
calculate_input_addr_offset(offset_x, offset_y, be_config_.tdn_input_format,
&tdn_input_addr_offset);
calculate_input_addr_offset(offset_x, offset_y, be_config_.tdn_output_format,
&tdn_output_addr_offset);
calculate_input_addr_offset(offset_x, offset_y, be_config_.stitch_input_format,
&stitch_input_addr_offset);
calculate_input_addr_offset(offset_x, offset_y, be_config_.stitch_output_format,
&stitch_output_addr_offset);

t.input_addr_offset = addr_offset;
t.input_addr_offset2 = addr_offset2;
t.tdn_input_addr_offset = tdn_input_addr_offset;
t.tdn_output_addr_offset = tdn_output_addr_offset;
t.stitch_input_addr_offset = stitch_input_addr_offset;
t.stitch_output_addr_offset = stitch_output_addr_offset;

PISP_LOG(debug, "Input offsets " << t.input_offset_x << "," << t.input_offset_y << " address offsets "
<< t.input_addr_offset << " and " << t.input_addr_offset2);

Expand All @@ -925,6 +942,8 @@ void BackEnd::finaliseTiling()
for (unsigned int j = 0; j < variant_.BackEndNumBranches(0); j++)
{
int output_offset_x_unflipped = t.output_offset_x[j], output_offset_y_unflipped = t.output_offset_y[j];
uint32_t output_addr_offset = t.output_addr_offset[j];
uint32_t output_addr_offset2 = t.output_addr_offset2[j];

if (be_config_.output_format[j].transform & PISP_BE_TRANSFORM_HFLIP)
t.output_offset_x[j] =
Expand All @@ -934,7 +953,10 @@ void BackEnd::finaliseTiling()
t.output_offset_y[j] = be_config_.output_format[j].image.height - output_offset_y_unflipped - 1;

compute_addr_offset(be_config_.output_format[j].image, t.output_offset_x[j], t.output_offset_y[j],
&t.output_addr_offset[j], &t.output_addr_offset2[j]);
&output_addr_offset, &output_addr_offset2);

t.output_addr_offset[j] = output_addr_offset;
t.output_addr_offset2[j] = output_addr_offset2;

PISP_LOG(debug, "Branch " << j << " output offsets " << t.output_offset_x[j] << "," << t.output_offset_y[j]
<< " address offsets " << t.output_addr_offset[j] << " and "
Expand Down Expand Up @@ -968,7 +990,13 @@ bool BackEnd::ComputeOutputImageFormat(unsigned int i, pisp_image_format_config

if (be_config_.global.rgb_enables & PISP_BE_RGB_ENABLE_OUTPUT(i))
{
getOutputSize(i, &fmt.width, &fmt.height, ifmt);
uint16_t width = fmt.width;
uint16_t height = fmt.height;

getOutputSize(i, &width, &height, ifmt);
fmt.width = width;
fmt.height = height;

if (!fmt.stride)
compute_stride(fmt);
else
Expand Down
Loading
Loading