Converting from pitched layout to block linear layout with NvBufSurfTransform fails

Hello,

I am trying to convert a buffer that is allocated as NVBUF_LAYOUT_PITCH to a NVBUF_LAYOUT_BLOCK_LINEAR buffer with the following code:

NvBufSurfTransformParams params;
NvBufSurfTransform(pitched_input, block_linear_output, &params);

pitched_input and block_linear_output are both allocated with NvBufSurfaceCreate and with the following parameters:

 params.memType = NVBUF_MEM_SURFACE_ARRAY;
  params.isContiguous = false;
  params.width = width;
  params.height = height;
  params.size = 0;
  params.layout = layout;
  params.colorFormat = NVBUF_COLOR_FORMAT_NV12;

Where layout is NVBUF_LAYOUT_PITCH for one and NVBUF_LAYOUT_BLOCK_LINEAR for the other.

When I call NvBufSurfTransform I get the error flag NvBufSurfTransformError_Invalid_Params.
Unfrtunately there is no further explaination what could cause this error.

Does anybody know what can be the cause of a invalid parameters error in this case?

Hi,
Please refer to get_converted_mat() in

/opt/nvidia/deepstream/deepstream-5.1/sources/gst-plugins/gst-dsexample/gstdsexample.cpp

Need to configure the paraters:

  /* Configure transform session parameters for the transformation */
  transform_config_params.compute_mode = NvBufSurfTransformCompute_Default;
  transform_config_params.gpu_id = dsexample->gpu_id;
  transform_config_params.cuda_stream = dsexample->cuda_stream;

  /* Set the transform parameters */
  transform_params.src_rect = &src_rect;
  transform_params.dst_rect = &dst_rect;
  transform_params.transform_flag =
    NVBUFSURF_TRANSFORM_FILTER | NVBUFSURF_TRANSFORM_CROP_SRC |
      NVBUFSURF_TRANSFORM_CROP_DST;
  transform_params.transform_filter = NvBufSurfTransformInter_Default;

Hi @DaneLLL ,
In get_converted_mat cropping is applied. That is why they set the parameters.
For example, none of the transform_params.transform_flags can be applied to a situation, where all I want to do is transform from pitch layout to block linear. What parameters can be set by me?

I have tried setting the NvBufSurfTransformConfigParams to:

  NvBufSurfTransformConfigParams config_params;
  config_params.compute_mode = NvBufSurfTransformCompute_Default;
  config_params.gpu_id = gpu_id;
  config_params.cuda_stream = cuda_stream;

like in get_converted_mat()

The conversion from block linear to pitched works flawlessly in the same way, but not the other way around.

Are there unpublished limitations to this?

Do you have a idea what else can be tested?

Hi,
Please configure all parameters. If you don’t need scaling/cropping, please set identical src_rect and dst_rect.

Hi @DaneLLL ,

I now changed my function to set all parameters, see below:

  void ConvertPitchToBlockLinearLayout(NvBufSurface *pitched_input, NvBufSurface *block_linear_output, std::int32_t gpu_id, cudaStream_t cuda_stream) {
  NvBufSurfTransformParams params;
  NvBufSurfTransformConfigParams config_params;
  NvBufSurfTransformRect source;
  NvBufSurfTransformRect destination;
  source.top = 0;
  source.left = 0;
  source.width = pitched_input->surfaceList[0].width;
  source.height = pitched_input->surfaceList[0].height;
  destination.top = 0;
  destination.left = 0;
  destination.width = block_linear_output->surfaceList[0].width;
  destination.height = block_linear_output->surfaceList[0].height;
  config_params.compute_mode = NvBufSurfTransformCompute_Default;
  config_params.gpu_id = gpu_id;
  config_params.cuda_stream = cuda_stream;
  params.src_rect = &source;
  params.dst_rect = &destination;
  params.transform_filter = NvBufSurfTransformInter_Default;
  params.transform_flip = NvBufSurfTransform_None;
  params.transform_flag = NVBUFSURF_TRANSFORM_CROP_DST | NVBUFSURF_TRANSFORM_CROP_SRC | NVBUFSURF_TRANSFORM_FILTER | NVBUFSURF_TRANSFORM_FLIP;
  NvBufSurfTransformSetSessionParams(&config_params);
  NvBufSurfTransform(pitched_input, block_linear_output, &params);
}

The error of NvBufSurfTransform stays the same.

The following is the configuration of both surfaces that are handled in this function

pitched_input:
                                                                                                                                                                      
GPU ID: 0
MEM Layout(0 is pitch): 0
Batch Size: 1
Is contiguous: 0
Width: 816, Height: 616
Data size: 1048576
Number of planes: 2
Width plane 0: 816, Height plane 0: 616
Width plane 1: 408, Height plane 1: 308
Byte per pixel plane 0: 1, Byte per pixel plane 1: 2
pitch plane 0: 1024 bytes, pitch plane 1: 1024 bytes
offset plane 0: 0 bytes, offset plane 1: 655360 bytes
size plane 0: 655360, size plane 1: 393216





block_linear_output

GPU ID: 0
MEM Layout(0 is pitch): 1
Batch Size: 1
Num Filled: 0
Is contiguous: 0
Width: 816, Height: 616
Data size: 1048576
Number of planes: 2
Width plane 0: 816, Height plane 0: 616
Width plane 1: 408, Height plane 1: 308
Byte per pixel plane 0: 1, Byte per pixel plane 1: 2
pitch plane 0: 832 bytes, pitch plane 1: 832 bytes
offset plane 0: 0 bytes, offset plane 1: 655360 bytes
size plane 0: 655360, size plane 1: 393216


Do you have any idea, why this doesn’t work?

Any Idea @DaneLLL

Hi,
Pleas try with this flag:

params.transform_flag = NVBUFSURF_TRANSFORM_FILTER;

If the issue is still present, please share a patch to

/opt/nvidia/deepstream/deepstream-5.1/sources/gst-plugins/gst-dsexample/gstdsexample.cpp

So that we can reproduce it and check with teams.