// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 #include "inc/gpu_ops/rectify.hpp" #include namespace camera_bridge { namespace { constexpr unsigned kBlockX = 32; constexpr unsigned kBlockY = 8; // The kernels only find their sample and bounds-check it. The per-pixel work is in remap_pixel.hpp, which the CPU // reference runs too, so keep it there. __global__ void rectify_luma(RemapPlaneJob job) { const int x = blockIdx.x * blockDim.x + threadIdx.x; const int y = blockIdx.y * blockDim.y + threadIdx.y; if (x >= job.dst_width || y >= job.dst_height) return; remap_luma_pixel(job, x, y); } __global__ void rectify_chroma(RemapPlaneJob job) { const int cx = blockIdx.x * blockDim.x + threadIdx.x; const int cy = blockIdx.y * blockDim.y + threadIdx.y; if (cx >= job.dst_width || cy >= job.dst_height) return; remap_chroma_pixel(job, cx, cy); } dim3 grid_for(const RemapPlaneJob& job) { return dim3((job.dst_width + kBlockX - 1) / kBlockX, (job.dst_height + kBlockY - 1) / kBlockY); } } // namespace cudaError_t rectify_nv12(const Nv12Planes& source, const Nv12PlanesOut& destination, const RemapTableView& tables, bool full_range, cudaStream_t stream) { if (tables.luma == nullptr || tables.chroma == nullptr) return cudaErrorInvalidValue; const RemapJobs jobs = remap_nv12_jobs(tables, { source.y, source.uv, source.y_pitch, source.uv_pitch }, { destination.y, destination.uv, destination.y_pitch, destination.uv_pitch }, full_range); const dim3 block(kBlockX, kBlockY); rectify_luma<<>>(jobs.luma); if (const cudaError_t status = cudaGetLastError(); status != cudaSuccess) return status; rectify_chroma<<>>(jobs.chroma); return cudaGetLastError(); } } // namespace camera_bridge