NVIDIA DriveOS Linux SDK API Reference

7.2.5.0 Early Access Release

Detailed Description

libnvrm_surface distinguishes between a "memory allocation" and a "surface". A memory allocation, which comes from an API like NvOsAlloc or NvRmMemHandleAllocAttr, is an unstructured array of bytes that have no particular semantic meaning – they are just bytes in which data can be stored. A surface, on the other hand, is a higher-level construct where the bytes comprise an array of pixels with some particular color format and layout in memory. Surfaces are always two-dimensional.

For the purpose of specifying x/y pixel coordinates, all coordinates are non-negative, and the first byte of surface memory corresponds to coordinates (0, 0). By convention, 'width' refers to a count of pixels along the x axis, and 'height' refers to a count of pixels along the y axis.

The mapping between surfaces and memory allocations is many-to-one. A given memory allocation can hold many surfaces. Usually they will be nonoverlapping, but not always. For example, one might choose to interpret the same bytes as either an RGB surface or a YUV surface for different purposes. Or, one might have a mipmap chain where each mipmap level is a separate surface with a different width and height, pointing to a different part of a larger memory allocation.

For this reason, it is useful to think of a surface as a view of memory, rather than as a piece of memory itself. The underlying memory's lifetime must exceed the surface's lifetime.

The surface API provides a uniform way of describing a surface for other APIs, regardless of its properties such as width, height, color format, layout, and so on.

The way the pixels are laid out in memory is defined by the "Layout", "Kind", and "Block Height" parameters of a surface.

The simplest layout is called "Pitch" (or "Pitchlinear"). In pitch format, a pixel at location (x,y) lives at address y*pitch + x*bpp from the base of the surface. Pitch layout is optimal for hardware engines that are optimized for linear access patterns (typically at least CPU).

The most efficient layout for many hardware engines (such as GPU and VIC) is "blocklinear". The blocklinear layout is parameterizable with the block height in GOBs (Groups Of Bytes), and "kind". The kind specifies how to interpret the bytes within a GOB (for pitch surfaces, kind is always NvRmMemKind_Pitch). For more information about GOBs, kinds and the blocklinear format, refer to T40 Pixel Memory Format GFD [16]

Because the pixel layout of a surface depends on many factors, it is a good idea to avoid manipulating the raw pixel data using the CPU (except for pitch surfaces). The surface API provides NvRmSurfaceRead, NvRmSurfaceWrite and NvRmSurfaceComputeOffset functions for doing CPU operations. These functions work for all layout configurations, but they are not intended for use by performance critical code.

libnvrm_surface can create surfaces that are consumed by a variety of HW engines. Upon setting up a surface, libnvrm_surface computes a minimum size for the surface, which depends on engine support, width, height, layout, and pixel format. The definitive source of information on surface sizing and addressing is: T19x Pixel Memory Format GFD [9]

But briefly, here is how surface size is computed:

surface_size = aligned_pitch * aligned_height

aligned_pitch is the width in bytes of one row of the surface.

unaligned_pitch = (bits_per_pixel * surface_width + 7) / 8

aligned_pitch = AlignUp(unaligned_pitch, pitch_alignment)

pitch_alignment depends on surface layout. For a pitch linear surface, pitch_alignment accommodates the coarsest granularity among HW engines. For a block linear surface, the pitch is aligned to the nearest GOB width.

aligned_height = AlignUp(surface_height, height_alignment)

aligned_height is in units of rows, not bytes. height_alignment depends on the surface layout. For a pitch linear surface, height_alignment is 4. For a block linear surface, the height of a surface is aligned up to the nearest block height in rows.

block_height = GOBs_per_block * GOB_height_in_bytes

GOB_height_in_bytes is 8, and GOBs_per_block is parameterizable, however the default value is 16.

In addition to computing a minimum surface size, libnvrm_surface exposes minimal functionality for accessing surface memory from the CPU. Computing the byte offset of a pitch surface given (x, y) coordinates is as follows:

byte_offset = y * surface_pitch + x * bits_per_pixel / 8

surface_pitch is in bytes. Computing the byte offset for a blocklinear surface is slightly more involved. Surface memory on Xavier and later chips is laid out in XBAR_RAW layout. Computing a byte offset for a blocklinear surface given (x, y) coordinates is as follows:

byte_offset = gob_offset + byte_offset_within_gob

gob_offset is the 64x8B gob that contains the (x, y) coordinate:

gob_offset = ((y / (gob_height * block_height)) * surface_pitch * gob_height * block_height) + ((x_bytes / gob_height) * bytes_per_gob * block_height) + (((y % (gob_height * block_height)) / gob_height) * bytes_per_gob);

where block_height is in units of gobs, surface_pitch is in units of bytes, x_bytes is in units of bytes and y is in units of pixels. As of Xavier, gob_height is 64 and gob_width is 8. bytes_per_gob is (64 * 8) = 512

byte_offset_within_gob = (((x_bytes % gob_width) / half_gob_width) * half_bytes_per_gob) + (((y % gob_height) / half_gob_height) * quarter_bytes_per_gob) + (((x_bytes % half_gob_width) / quarter_gob_width) * eighth_bytes_per_gob) + (((y % half_gob_height) * sixteenth_bytes_per_gob) + (x_bytes % quarter_gob_width));

where x_bytes is in units of bytes, and y is in units of pixels. This is a large calculation. Intuitively, this computes byte offset by partitioning the space. For a surface where X increases to the right, and Y increases up: The first term adds 256 to the offset if x is in the right half of the gob. The second term adds 128 to the offset if y is in the top half of the gob. The third term adds 64 to the offset if x if in the right half of the gob half that it occupies, etc.

For more information and a more complete discussion on XBAR_RAW and memory addressing, refer to these:

The surface API does not natively understand planar YUV surfaces. A planar YUV surface is really three separate surfaces that you can operate on independently, and that (usually) just happen to be adjacent in memory. However the API does provide helpers for setting up arrays of surfaces, typically used when setting up YUV surfaces.

libnvrm_surface uses opaque handles to represent memory allocations. However opaque handles are not used to represent surfaces. The surface structure is fully exposed to its clients. One important benefit is that surfaces can live on the stack, rather than on the heap – creating a "temporary" surface that refers to an existing chunk of memory is extremely cheap and cannot fail. Another benefit is that surfaces can be embedded directly in other heap data structures, rather than having to store a pointer to the surface. Finally, it allows code that operates on a surface to extract its properties (its underlying storage, its width, its height, its color format, etc.) without the overhead of a function call.

In general, this design decision increases performance and simplifies the code, at the cost of (1) having to recompile any time that the surface structure definition changes and (2) not being able to protect users as much from misusing the API. (1) is not a major concern, but (2) is slightly more worrisome, so take caution to use the API as documented.

Two types of backing storage are allowed: either a plain pointer (which would typically come from something like NvOsAlloc), or an NvRmMemHandle. No attempt is made here to manage the lifetime of the storage. That is entirely the responsibility of the client.

The two most important functions of this API are NvRmSurfaceSetup and NvRmMultiplanarSurfaceSetup. They should be used for initializing NvRmSurfaces for single-plane and YUV surfaces, respectively. A typical allocation code looks like:

e = NvRmSurfaceSetup(&s, 400, 400, NvColorFormat_A8R8G8B8, NULL);

This will choose the default layout (depends on the chip), and initialize the fields of NvRmSurface. The setup code (and the fields of NvRmSurface) tends to change slightly for every new chip, so using NvRmSurfaceSetup is highly encouraged.

If you want finer grained control over how exactly the surface should be set up, you can use the Attributes array for passing additional requirements (or hints) to NvRmSurfaceSetup. For example, to set up a pitchlinear surface, do:

e = NvRmSurfaceSetup(&s, 400, 400, NvColorFormat_A8R8G8B8, attrs);

Or to request a compressible surface, do:

NvU32 attrs[] = { NvRmSurfaceAttribute_Compression, true,
e = NvRmSurfaceSetup(&s, 400, 400, NvColorFormat_A8R8G8B8, attrs);

As stated above, the surface API is not responsible for memory allocation. However, typically the next step after setting up a surface is to allocate backing memory for it. Typical set up and allocation code looks like this:

// Set up.
e = NvRmSurfaceSetup(&s, 400, 400, NvColorFormat_A8R8G8B8, NULL);
// Compute size and alignment.
NvU32 size = s.Size;
NvU32 alignment = 0;
e = NvRmSurfaceGetAlignment(NULL, &s, &alignment);
// offet is the initial desired placement of the surface into the
// allocation that further needs to be aligned to the surface's requirements.
offset = ALIGN(offset, alignment);
// Allocate memory.
alignment,
size + offset,
e = NvRmMemHandleAllocAttr(Rm, &HandleAttr, &hMem);
void* basePtr = NULL;
// Optionally map surface into CPU visible address space
e = NvRmMemMap(hMem, offset, s.Size, mapFlags, &basePtr);
// Place surface into memory
e = NvRmSurfaceSetDeviceMemory(&s, hMem, offset, basePtr);

NvRmSurfaces cannot hold mutable state, since multiple copies of NvRmSurface that refer to the same surface may co-exist

Planar and semiplanar surfaces are represented by arrays of NvRmSurface structs, where each NvRmSurface struct represents a single plane. To setup a planar or semiplanar surface, use NvRmMultiplanarSurfaceSetup. NvRmMultiplanarSurfaceSetup initializes multiple surfaces based on the standard attributes that are passed into NvRmSurfaceSetup, and an additional NvYuvColorFormat parameter to control the size of the chroma plane(s) in relation to the luminance plane.

NvRmMultiplanarSurfaceSetup can also be used to initialize RGBA and other single-plane surfaces by passing SurfaceCount = 1. This can potentially simplify client code. A single codepath can be used that calls NvRmMultiplanarSurfaceSetup, rather than conditionally calling NvRmSurfaceSetup or NvRmMultiplanarSurfaceSetup when SurfaceCount > 1.

This code snippet initializes a planar YUV surface:

// format of each invidual plane
NvColorFormat colorFormats[] = {NvColorFormat_Y8,
NvColorFormat_U8,
NvColorFormat_V8};
// YUV format of the surface in aggregate
NvU32 surfaceCount = 3;
NvRmSurface surfaces[surfaceCount];
NvRmMultiplanarSurfaceSetup(surfaces, surfaceCount, 400, 400,
yuvColorFormat, colorFormats, NULL);

This code snippet initializes a semiplanar surface:

// format of each invidual plane
NvColorFormat colorFormats[] = {NvColorFormat_Y8,
NvColorFormat_U8_V8};
// YUV format of the surface in aggregate
NvU32 surfaceCount = 2;
NvRmSurface surfaces[surfaceCount];
NvRmMultiplanarSurfaceSetup(surfaces, surfaceCount, 400, 400,
yuvColorFormat, colorFormats, NULL);

Compression state is probably the most important piece of global mutable surface state that needs to be tracked in order to access the surface optimally (only decompress or transform the compression bits when necessary).

The NvRmSurface API provides two functions for tracking compression state and performing decompression and compression bit transformations: NvRmSurfacePrepareCompressibleRead and NvRmSurfaceMarkCompressibleWrite. Calling these functions correctly from both the producing and consuming drivers enables sharing of compressed surfaces across engines that natively support a different compression bit layout.

Example: A surface gets written to by the GPU, and will then be consumed by VIC. In this case the following code is needed:

// In the GPU driver, tell kernel that the GPU compbits are valid.
NvRmSurfaceMarkCompressibleWriteParams write =
NVRM_SURFACE_MARK_COMPRESSIBLE_WRITE_PARAMS_INIT();
write.Compbits = NvRmSurfaceCompbits_Gpu;
write.ZbcColor = 0; // If ZBC clear was issued, need to put the color here.
err = NvRmSurfaceMarkCompressibleWrite(
hDevice,
Surfaces, 1, // Single-plane surface in this example
&write,
Fence, // This fence will be closed...
&Fence); // ...and a new fence is stored to the same pointer.
if (err) {
// Handle error.
}
// ...
// In the VIC driver, request compbits for VIC's vertical CDE.
NvRmSurfacePrepareCompressibleReadParams read =
NVRM_SURFACE_PREPARE_COMPRESSIBLE_READ_PARAMS_INIT();
read.Compbits = NvRmSurfaceCompbits_CdeVertical;
err = NvRmSurfacePrepareCompressibleRead(
hDevice,
&Surface, 1, // Single-plane surface in this example.
&read,
Fence, // This fence will be closed...
&Fence); // ...and a new fence is stored to the same pointer.
if (err) {
// Handle error.
}
if (read.Compbits & NvRmSurfaceCompbits_CdeVertical) {
// Program VIC CDE:
// Compbits = IOVA(Surface.hMem) + Surface.CdeVerticalCompbitsOffset
// ZbcColor = read.ZbcColor
} else {
// Bypass VIC CDE.
}
Note
Pointers passed as parameters are not validated. nvrm_surface is a userspace component and it has no efficient way of validating pointers. All non-NULL pointers are expected to be valid.
A Note on error reporting/handling: Almost all NvRmSurface API functions will return NvError_* error codes. In debug builds, though, usage errors (i.e. passing bad parameters or surface objects that are not properly setup) will result in assertion failures. If needed, these usage asserts can be disabled via NvRmSurfaceDebugControl in libnvrm_surface_debug.so. When usage asserts are disabled, usage errors will still be printed out and the failing function will return with an appropriate error return value.

Satisfies requirements:
\jama{22189482, NVGPU60-REQ-579}

Data Structures

struct  NvRmSurfaceRec
 An exposed (not opaque) structure representing a surface. More...
 
struct  NvRmSurfaceContainerRec
 Common container struct to represent all surface types. More...
 

Modules

 NvRmSurfaceFlags
 

Macros

#define NvYuvChromaLocation_BT601   NvYuvChromaLocation_0_0
 Aliases for typical usage. More...
 
#define NvYuvChromaLocation_MPEG2   NvYuvChromaLocation_0_1
 
#define NvYuvChromaLocation_MPEG1   NvYuvChromaLocation_1_1
 
#define NvYuvChromaLocation_JPEG   NvYuvChromaLocation_1_1
 
#define NVRM_MAX_SURFACES   3
 Maximum number of NvRmSurfaces that GLES textureinfo/NvWsiPixmap contain. More...
 
#define NvRmSurfaceUnitSupport
 
#define NVRM_SURFACE_FORCE_BLOCK_HEIGHT_LOG2_DONT_FORCE   0xFFFFFFFFU
 Use for NvRmSurfaceAttribute_ForceBlockHeightLog2 to indicate no enforced block height. More...
 
#define NVRM_SURFACECONTAINER_MAX_SURFACES   3U
 Maximum number of surfaces which can be stored in the NvRmSurfaceContainer. More...
 

Typedefs

typedef struct NvRmSurfaceRec NvRmSurface
 An exposed (not opaque) structure representing a surface. More...
 
typedef struct NvRmSurfaceContainerRec NvRmSurfaceContainer
 Common container struct to represent all surface types. More...
 

Enumerations

enum  NvYuvColorFormat {
  NvYuvColorFormat_Unspecified = 0,
  NvYuvColorFormat_YUV420,
  NvYuvColorFormat_YUV422,
  NvYuvColorFormat_YUV422R,
  NvYuvColorFormat_YUV444,
  NvYuvColorFormat_Force32 = 0x7FFFFFFFU
}
 Defines the different color formats in the YUV color space. More...
 
enum  NvYuvChromaLocation {
  NvYuvChromaLocation_Unspecified,
  NvYuvChromaLocation_0_0,
  NvYuvChromaLocation_0_1,
  NvYuvChromaLocation_1_1,
  NvYuvChromaLocation_0_2,
  NvYuvChromaLocation_1_0,
  NvYuvChromaLocation_1_2,
  NvYuvChromaLocation_2_0,
  NvYuvChromaLocation_2_1,
  NvYuvChromaLocation_2_2
}
 Defines the chroma subsampling location. More...
 
enum  NvDisplayScanFormat {
  NvDisplayScanFormat_Progressive = 0,
  NvDisplayScanFormat_Interlaced,
  NvDisplayScanFormat_Force32 = 0x7FFFFFFFU
}
 Defines the different display scan formats in the video planes. More...
 
enum  NvRmSurfaceLayout {
  NvRmSurfaceLayout_Pitch = 1,
  NvRmSurfaceLayout_Tiled,
  NvRmSurfaceLayout_Blocklinear,
  NvRmSurfaceLayout_Num,
  NvRmSurfaceLayout_Force32 = 0x7FFFFFFFU
}
 The possible layouts that a surface can presently have. More...
 
enum  NvRmSurfaceUnitSupport {
  NvRmSurfaceUnitSupport_3D = 1 << 0,
  NvRmSurfaceUnitSupport_2D = 1 << 1,
  NvRmSurfaceUnitSupport_Display = 1 << 2,
  NvRmSurfaceUnitSupport_PVA = 1 << 3,
  NvRmSurfaceUnitSupport_NVENC = 1 << 4,
  NvRmSurfaceUnitSupport_VI = 1 << 5,
  NvRmSurfaceUnitSupport_CSI = 1 << 6,
  NvRmSurfaceUnitSupport_ISP = 1 << 7,
  NvRmSurfaceUnitSupport_Camera,
  NvRmSurfaceUnitSupport_All
}
 Defines engine/unit support. More...
 
enum  NvRmSurfaceCompression {
  NvRmSurfaceCompression_Disabled = 0,
  NvRmSurfaceCompression_Enabled = 1,
  NvRmSurfaceCompression_GpuOnly = 2,
  NvRmSurfaceCompression_Default = 3
}
 Defines general surface compression support. More...
 
enum  NvRmSurfaceContainerAllocType {
  NvRmSurfaceContainerAllocType_Contiguous,
  NvRmSurfaceContainerAllocType_NonContiguous
}
 Defines an allocation type for semiplanar and planar formats inside the container. More...
 
enum  NvRmSurfaceAttribute {
  NvRmSurfaceAttribute_None = 0,
  NvRmSurfaceAttribute_Layout,
  NvRmSurfaceAttribute_UnitSupport,
  NvRmSurfaceAttribute_DisplayScanFormat,
  NvRmSurfaceAttribute_OptimizeForDisplay,
  NvRmSurfaceAttribute_ForceBlockHeightLog2,
  NvRmSurfaceAttribute_Pitch,
  NvRmSurfaceAttribute_Size,
  NvRmSurfaceAttribute_Compression,
  NvRmSurfaceAttribute_Vpr,
  NvRmSurfaceAttribute_ForceTegraRawSwizzling,
  NvRmSurfaceAttribute_AllocType,
  NvRmSurfaceAttribute_ChromaLocType,
  NvRmSurfaceAttribute_NoForcePageAlignment,
  NvRmSurfaceAttribute_Last
}
 Define attribute types that can be passed into the attribute list accepted by NvRmSurfaceSetup. More...
 
enum  NvRmSurfaceContainerType {
  NvRmSurfaceContainerType_Single,
  NvRmSurfaceContainerType_SemiPlanar,
  NvRmSurfaceContainerType_Planar,
  NvRmSurfaceContainerType_Stereo
}
 Defines a container type for NvRmSurfaceContainer Depending of the format or how different color components are stored in the surfaces array, the container type can be single plane, semiplanar, planar or stereo. More...
 

Functions

NvError NvRmSurfaceSetup (NvRmSurface *const pSurf, NvU32 const width, NvU32 const height, NvColorFormat const colorFormat, NvU32 const *const attributes)
 Sets up an NvRmSurface. More...
 
NvError NvRmMultiplanarSurfaceSetup (NvRmSurface *Surfaces, NvU32 NumSurfaces, NvU32 Width, NvU32 Height, NvYuvColorFormat YuvFormat, const NvColorFormat *ColorFormats, const NvU32 *Attributes)
 Sets up a set of NvRmSurfaces describing a multiplanar surface. More...
 
NvYuvColorFormat NvRmSurfaceGetYuvColorFormat (NvRmSurface const *const *pSurf, NvU32 numSurfaces)
 Returns the YUV color format from an array of the N surfaces used to represent the YUV planes. More...
 
NvError NvRmSurfaceSetDeviceMemory (NvRmSurface *const pSurf, NvRmMemHandle const hMem, NvU32 const offset, void *const mappedPtr)
 Binds a surface to a region of device memory. More...
 
NvRmSurfaceLayout NvRmSurfaceGetDefaultLayout (void)
 Returns the system-wide default surface layout on the current platform. More...
 
NvError NvRmSurfaceGetPitchAlignment (NvRmSurfaceLayout const layout, NvU32 const unitSupport, NvU32 *const pitchAlign)
 Returns the pitch alignment requirement in bytes. More...
 
NvError NvRmSurfaceGetAlignment (NvRmSurface const *const pSurf, NvU32 *const pAlignment)
 Returns the alignment in bytes that the surface's memory will need to be allocated with. More...
 
NvError NvRmSurfaceGetCoordOffset (NvRmSurface const *const pSurf, NvU32 const x, NvU32 const y, NvU32 *const pOffset)
 Returns the byte offset of a given pixel coordinate relative to the start of the surface. More...
 
NvError NvRmSurfaceWrite (NvRmSurface const *const pSurf, NvU32 const x, NvU32 const y, NvU32 const width, NvU32 const height, void const *const pSrcPixels)
 Writes a subregion of a surface. More...
 
NvError NvRmSurfaceRead (NvRmSurface const *const pSurf, NvU32 const x, NvU32 const y, NvU32 const width, NvU32 const height, void *const pDstPixels)
 Reads a subregion of a surface. More...
 
static NvU32 NvRmSurfaceLayoutToRelocType (NvRmSurfaceLayout const layout)
 Convert surface layout into NvHost reloc type. More...
 

Macro Definition Documentation

◆ NVRM_MAX_SURFACES

#define NVRM_MAX_SURFACES   3

Maximum number of NvRmSurfaces that GLES textureinfo/NvWsiPixmap contain.

Definition at line 465 of file nvrm_surface_fusa.h.

◆ NVRM_SURFACE_FORCE_BLOCK_HEIGHT_LOG2_DONT_FORCE

#define NVRM_SURFACE_FORCE_BLOCK_HEIGHT_LOG2_DONT_FORCE   0xFFFFFFFFU

Use for NvRmSurfaceAttribute_ForceBlockHeightLog2 to indicate no enforced block height.

Definition at line 718 of file nvrm_surface_fusa.h.

◆ NVRM_SURFACECONTAINER_MAX_SURFACES

#define NVRM_SURFACECONTAINER_MAX_SURFACES   3U

Maximum number of surfaces which can be stored in the NvRmSurfaceContainer.

Currently it is not more than 3 as maximum three surfaces might be needed to store three color components (for planar data formats).

Definition at line 843 of file nvrm_surface_fusa.h.

◆ NvRmSurfaceUnitSupport

Definition at line 658 of file nvrm_surface_fusa.h.

◆ NvYuvChromaLocation_BT601

#define NvYuvChromaLocation_BT601   NvYuvChromaLocation_0_0

Aliases for typical usage.

Definition at line 443 of file nvrm_surface_fusa.h.

◆ NvYuvChromaLocation_JPEG

#define NvYuvChromaLocation_JPEG   NvYuvChromaLocation_1_1

Definition at line 446 of file nvrm_surface_fusa.h.

◆ NvYuvChromaLocation_MPEG1

#define NvYuvChromaLocation_MPEG1   NvYuvChromaLocation_1_1

Definition at line 445 of file nvrm_surface_fusa.h.

◆ NvYuvChromaLocation_MPEG2

#define NvYuvChromaLocation_MPEG2   NvYuvChromaLocation_0_1

Definition at line 444 of file nvrm_surface_fusa.h.

Typedef Documentation

◆ NvRmSurface

typedef struct NvRmSurfaceRec NvRmSurface

An exposed (not opaque) structure representing a surface.

Use constraints for the structure:

  1. Clients should always initialize NvRmSurface structs using either NvRmSurfaceSetup() or NvRmMultiplanarSurfaceSetup().
  2. Clients should treat all members of NvRmSurface struct as read-only and not modify them directly.
  3. Clients are responsible for managing the backing memory for read/write operations:
    1. allocating and releasing the backing memory.
    2. mapping and unmapping the backing memory to CPU address space.
    3. providing the backing memory and mapped pointer to the NvRmSurface via NvRmSurfaceSetDeviceMemory()
  4. Functions operating with NvRmSurface struct are not thread-safe. Clients are responsible for synchronizing the access if multiple threads are accessing the struct.
  5. NvRmSurface structs should not be shared with other processes. NvRmSurface can hold a reference to NvRmMemoryHandle and respective mapping to the CPU virtual address space which are invalid if shared with multiple processes.
Note
On Android/HOS, this struct must be tightly packed and the pointer 64-bit aligned for sharing across 32-bit/64-bit process boundaries, even though the pointer is never actually shared. This is enforced by compile-time asserts.

◆ NvRmSurfaceContainer

Common container struct to represent all surface types.

It is not a replacement for NvRmSurface, but contains an embedded array of NvRmSurface structs inside.

Enumeration Type Documentation

◆ NvDisplayScanFormat

Defines the different display scan formats in the video planes.

This enumeration is built to support display formats progressive, interlaced

Enumerator
NvDisplayScanFormat_Progressive 
NvDisplayScanFormat_Interlaced 
NvDisplayScanFormat_Force32 

Definition at line 452 of file nvrm_surface_fusa.h.

◆ NvRmSurfaceAttribute

Define attribute types that can be passed into the attribute list accepted by NvRmSurfaceSetup.

Enumerator
NvRmSurfaceAttribute_None 

Must terminate the attribute list.

NvRmSurfaceAttribute_Layout 

Memory Layout to use for the surface.

Type: NvRmSurfaceLayout
Default: return value of \ref NvRmSurfaceGetDefaultLayout 
NvRmSurfaceAttribute_UnitSupport 

A bitmask of HW units that will access the surface.

Type: NvRmSurfaceUnitSupport,
Default: NvRmSurfaceUnitSupport_All 
NvRmSurfaceAttribute_DisplayScanFormat 

The scanout format of displayable surfaces.

Type: NvDisplayScanFormat
Default: NvDisplayScanFormat_Progressive 
NvRmSurfaceAttribute_OptimizeForDisplay 

Optimize surface for display consumption.

If this is true, the layout of the surface is optimized for
consumption by the display. This might mean choosing a non-standard
block height if the layout is blocklinear, for example.
Type: bool
Default: false 
NvRmSurfaceAttribute_ForceBlockHeightLog2 

Force the surface's BlockHeightLog2 to the provided value.

Note that using this attribute can cause incompatibility with units specified in NvRmSurfaceAttribute_UnitSupport, and overrides the BlockHeightLog2 chosen by NvRmSurfaceAttribute_OptimizeForDisplay. Type: NvU32 Default: NVRM_SURFACE_FORCE_BLOCK_HEIGHT_LOG2_DONT_FORCE

NvRmSurfaceAttribute_Pitch 

Force the surface's Pitch to the provided value.

The provided pitch must be aligned to the alignment requirement. returned by NvRmSurfaceGetPitchAlignment for the surface's layout. Type: NvU32 Default: 0, indicating the pitch should be derived via the width of the surface and the pitch alignment requirement for the surface's layout.

NvRmSurfaceAttribute_Size 

Force the surface's size to the given size.

The provided size needs to be at least as large as indicated by the
surface's width, height, pitch, color format, layout and block height
(for blocklinear surfaces).

Type: NvU32
Default: 0, indicating regular surface size computation 
NvRmSurfaceAttribute_Compression 

Selects the level of compression support desired for the surface.

This flag is silently ignored if the surface does not support a
compressible kind (e.g. layout not blocklinear, unsupported BPP).
Type: NvRmSurfaceCompression
Default: \ref NvRmSurfaceCompression_Disabled 
NvRmSurfaceAttribute_Vpr 

If this is true, sets the NVRM_SURFACE_FLAG_VPR flag.

Type: bool
Default: false 
NvRmSurfaceAttribute_ForceTegraRawSwizzling 

If this is true, sets the NVRM_SURFACE_FLAG_FORCE_TEGRA_RAW_SWIZZLING flag.

When this flag is set, the surface's memory is forcefully interpreted with the
TEGRA_RAW swizzling format even if the format is not the default one on the
current chip for the block linear layout. At the very least, this means that
NvRmSurfaceRead and NvRmSurfaceWrite will use TEGRA_RAW memory swizzling when
the block-linear format is used.

Type: bool
Default: false 
NvRmSurfaceAttribute_AllocType 

Defines the allocation type inside NvRmSurfaceContainer.

Type: NvRmSurfaceContainerAllocType
Default: \ref NvRmSurfaceContainerAllocType_Contiguous 
NvRmSurfaceAttribute_ChromaLocType 

Defines the chroma subsampling location.

Type: NvYuvChromaLocation
Default: \ref NvYuvChromaLocation_Unspecified 
NvRmSurfaceAttribute_NoForcePageAlignment 

If this is true, sets the NVRM_SURFACE_FLAG_NO_FORCE_PAGE_ALIGNMENT flag.

When this flag is set, the surface size will be a value that is aligned
to the NVRM_SURFACE_PREFERRED_PAGE_SIZE (128K).

Type: bool
Default: \ref false 
NvRmSurfaceAttribute_Last 

Provides the number of attributes.

Must always be the last entry.

Definition at line 724 of file nvrm_surface_fusa.h.

◆ NvRmSurfaceCompression

Defines general surface compression support.

Enumerator
NvRmSurfaceCompression_Disabled 

Compression disabled (alias false).

NvRmSurfaceCompression_Enabled 

GPU compression enabled, CDEs can be used (alias true).

On platforms that don't support CDE, 'Enabled' is equivalent to 'GpuOnly'.

NvRmSurfaceCompression_GpuOnly 

GPU compression enabled, CDEs cannot be used.

NvRmSurfaceCompression_Default 

Use per-platform default, modifiable with config properties.

Definition at line 685 of file nvrm_surface_fusa.h.

◆ NvRmSurfaceContainerAllocType

Defines an allocation type for semiplanar and planar formats inside the container.

Allocation can be either contiguous or non-contiguous. For contiguous allocation the planes can be accessed by an offset inside the first surface in the container. For non-contiguous allocation the planes are allocated within the separate surfaces.

Enumerator
NvRmSurfaceContainerAllocType_Contiguous 

Contiguous allocation.

NvRmSurfaceContainerAllocType_NonContiguous 

Non-contiguous allocation.

Definition at line 707 of file nvrm_surface_fusa.h.

◆ NvRmSurfaceContainerType

Defines a container type for NvRmSurfaceContainer Depending of the format or how different color components are stored in the surfaces array, the container type can be single plane, semiplanar, planar or stereo.

Enumerator
NvRmSurfaceContainerType_Single 

Single plane container.

NvRmSurfaceContainerType_SemiPlanar 

SemiPlanar format container.

NvRmSurfaceContainerType_Planar 

Planar format, separate surfaces contain different planes.

NvRmSurfaceContainerType_Stereo 

Stereo format container.

Definition at line 851 of file nvrm_surface_fusa.h.

◆ NvRmSurfaceLayout

The possible layouts that a surface can presently have.

More layouts can be added when invented by HW. Swizzled surfaces are not allowed here; the 3D driver will take care of swizzling on its own, without RM's help.

Enumerator
NvRmSurfaceLayout_Pitch 

Pitch: Address formula is:

        y * Pitch + x * BytesPerPixel
    

Also referred to as 'Pitchlinear'.

NvRmSurfaceLayout_Tiled 

Tiled: Surface is stored in 1024-byte blocks that are 64 bytes wide and 16 rows tall, further divided into 256 B blocks that are 16 B x16.

Deprecated:
Tiled format is only supported on pre-Kepler chips and nvrm_surface does not support it anymore. This enumeration is only for build compatibility with non-Automotive platforms that haven't removed the dependency.
NvRmSurfaceLayout_Blocklinear 

BlockLinear: Surface is stored in a hardware defined, opaque "blocklinear" organization.

The exact byte layout of blocklinear format is determined by surface Kind and BlockHeightLog2.

NvRmSurfaceLayout_Num 
NvRmSurfaceLayout_Force32 

Definition at line 475 of file nvrm_surface_fusa.h.

◆ NvRmSurfaceUnitSupport

Defines engine/unit support.

The individual values are expected to be bitwise OR'ed into masks indicating multi-engine support.

Enumerator
NvRmSurfaceUnitSupport_3D 
NvRmSurfaceUnitSupport_2D 
NvRmSurfaceUnitSupport_Display 
NvRmSurfaceUnitSupport_PVA 
NvRmSurfaceUnitSupport_NVENC 
NvRmSurfaceUnitSupport_VI 
NvRmSurfaceUnitSupport_CSI 
NvRmSurfaceUnitSupport_ISP 
NvRmSurfaceUnitSupport_Camera 
NvRmSurfaceUnitSupport_All 

Definition at line 662 of file nvrm_surface_fusa.h.

◆ NvYuvChromaLocation

Defines the chroma subsampling location.

Enumerator
NvYuvChromaLocation_Unspecified 

Chroma subsampling location is unknown or not specifed.

NvYuvChromaLocation_0_0 

Cosited chroma location.

NvYuvChromaLocation_0_1 

Cosited horizontally and centered vertically, typical for MPEG2.

NvYuvChromaLocation_1_1 

Centered horizontally and vertically, typical for MPEG1 and JPEG.

NvYuvChromaLocation_0_2 

Less common locations.

NvYuvChromaLocation_1_0 
NvYuvChromaLocation_1_2 
NvYuvChromaLocation_2_0 
NvYuvChromaLocation_2_1 
NvYuvChromaLocation_2_2 

Definition at line 423 of file nvrm_surface_fusa.h.

◆ NvYuvColorFormat

Defines the different color formats in the YUV color space.

This enumeration describes the chroma sub-sampling ratios.

Enumerator
NvYuvColorFormat_Unspecified 

Placeholder error value.

Used to allow NvRmMultiplanarSurfaceSetup to create single-plane surfaces.

NvYuvColorFormat_YUV420 

Horizontal and vertical sub-sampling.

NvYuvColorFormat_YUV422 

Horizontal sub-sampling.

NvYuvColorFormat_YUV422R 

Vertical sub-sampling.

NvYuvColorFormat_YUV444 

No sub-sampling.

NvYuvColorFormat_Force32 

Ensures this enum occupies at least 32 bits.

Definition at line 403 of file nvrm_surface_fusa.h.

Function Documentation

◆ NvRmMultiplanarSurfaceSetup()

NvError NvRmMultiplanarSurfaceSetup ( NvRmSurface *  Surfaces,
NvU32  NumSurfaces,
NvU32  Width,
NvU32  Height,
NvYuvColorFormat  YuvFormat,
const NvColorFormat *  ColorFormats,
const NvU32 *  Attributes 
)

Sets up a set of NvRmSurfaces describing a multiplanar surface.

All fields are initialized to sensible defaults. hMem, Offset and and pBase are set to zero. Attributes array can be used for communicating extra requirements. This function should always be used instead of NvRmSurfaceSetup for multiplanar surfaces, to ensure that parameters of the different planes are compatible with each other. This function calls NvRmSurfaceSetup on each NvRmSurface in the Surfaces array using the NvColorFormat in the ColorFormats array, and the attributes specified in the Attributes array.

Parameters
[out]SurfacesThe array of surfaces to set up.

Parameter constraints: must point to an array of NvRmSurface* pointers, of size NumSurfaces.
[in]NumSurfacesHow many surfaces are in the array.

Parameter constraints: must be in the range [1, 3] inclusive.
[in]WidthWidth of the luma plane in pixels.

Parameter constraints: the resulting size of the surface must fit in a 32 bit word, as computed by NvRmSurfaceIntComputeSize.
[in]HeightHeight of the luma plane in pixels.

Parameter constraints: the resulting size of the surface must fit in a 32 bit word, as computed by NvRmSurfaceIntComputeSize.
[in]YuvFormatFormat of the YUV surface, used to compute sub-sampling for the chroma planes. Use NvYuvColorFormat_Unspecified when the surface to set up only contains a single plane.

Parameter constraints: must be a valid NvYuvColorFormat value, other than NvYuvColorFormat_Force32.
[in]ColorFormatsNumSurfaces-length array specifying which color format to be used for each surface in the Surfaces array.

Parameter constraints: must point to an array of NvColorFormats, where each entry in the array is a valid NvColorFormat enum.
[in]AttributesA NvRmSurfaceAttribute_None terminated list of attribute value pairs that override defaults. Pass NULL to use defaults for all attributes.

Parameter constraints: must point to an array of NvRmSurfaceAttribute pairs. Every even entry in the array must point to a valid NvRmSurfaceAttribute other than NvRmSurfaceAttribute_Last. The array must be terminated by NvRmSurfaceAttribute_None.
Returns
An NvError value describing the status of the operation.
Return values
NvError_BadParameterif a call to NvRmSurfaceSetup(&Surfaces[i], PlaneWidth, PlaneHeight, ColorFormats[i], Attributes) would return NvError_BadParameter. Where (0 <= i < numSurfaces) and PlaneWidth/PlaneHeight are a function of NvYuvColorFormat and Width/Height.
NvError_BadParameterif NumSurfaces, YuvFormat, Width and Height do not specify a valid Multiplanar YUV or non YUV single planar surface.
NvError_InvalidSizeif a call to NvRmSurfaceSetup(&Surfaces[i], PlaneWidth, PlaneHeight, ColorFormats[i], Attributes) would return NvError_InvalidSize. Where (0 <= i < numSurfaces) and PlaneWidth/PlaneHeight are a function of NvYuvColorFormat and Width/Height.
NvSuccessupon success.
Note
This function or NvRmSurfaceSetup() need to be called at least once during the Init state if they are going to be called during Runtime state.


Usage considerations

  • Allowed context for the API call
    • Thread-safe: No
    • Interrupt handler: No
    • Signal handler: No
    • Re-entrant: No
    • Async/Sync: Sync
  • API group
    • Init: Yes
    • Runtime: Yes
    • De-Init: Yes

◆ NvRmSurfaceGetAlignment()

NvError NvRmSurfaceGetAlignment ( NvRmSurface const *const  pSurf,
NvU32 *const  pAlignment 
)

Returns the alignment in bytes that the surface's memory will need to be allocated with.

For blocklinear surfaces, this is NVRM_BLOCK_LINEAR_BASE_ALIGN, and for pitch linear surfaces this is NVRM_SURFACE_LINEAR_BASE_ALIGN.

Alignment refers to minimum physical address alignment when using carveout, and minimum IOVA (SMMU) address alignment when SMMU translation is enabled.

Parameters
[in]pSurfA pointer to structure describing a fully initialized surface.

Parameter constraints: must point to an NvRmSurface that was setup using NvRmSurfaceSetup.
[out]pAlignmentOutput parameter: Receives the alignment if function succeeds.

Parameter constraints: Must point to at least 32 bits of writable memory.
Returns
An NvError value describing the status of the operation.
Return values
NvError_BadParameterif either pSurf or pAlignment is NULL.
NvError_InvalidSurfaceif the surface's layout is not supported
NvSuccessupon success.


Usage considerations

  • Allowed context for the API call
    • Thread-safe: No
    • Interrupt handler: No
    • Signal handler: No
    • Re-entrant: No
    • Async/Sync: Sync
  • API group
    • Init: Yes
    • Runtime: Yes
    • De-Init: Yes

◆ NvRmSurfaceGetCoordOffset()

NvError NvRmSurfaceGetCoordOffset ( NvRmSurface const *const  pSurf,
NvU32 const  x,
NvU32 const  y,
NvU32 *const  pOffset 
)

Returns the byte offset of a given pixel coordinate relative to the start of the surface.

This offset is relative to the base of the surface, not to the base of the hMem of the surface. That is, you still have to add in pSurf->Offset (if necessary) to the value returned by this function. Byte offset computation is performed according to the section on byte addressing depending on the if the surface is pitchlinear or blocklinear. See the discussion on accessing surface memory from the CPU in Software Unit Design.

Parameters
[in]pSurfNon-NULL pointer to surface.

Parameter constraints: must point to an NvRmSurface that was setup using NvRmSurfaceSetup.
[in]xX coordinate in pixels.

Parameter constraints: (x <= pSurf->Width) must be true.
[in]yY coordinate in pixels.

Parameter constraints: (y <= pSurf->Height) must be true.
[out]pOffsetOutput parameter: Receives the byte offset for x,y coordinate.

Parameter constraints: must point to 4 bytes of writable memory.
Returns
An NvError value describing the status of the operation.
Return values
NvError_BadParameterif any of the following is true
  • pSurf is NULL
  • pOffset is NULL
  • x or y are outside the surface's dimensions
  • x is not on a byte-boundary for the surface's colorformat
NvError_InvalidSurfaceif any of the following is true:
  • pSurf->ColorFormat is invalid
  • pSurf->Layout is invalid
NvSuccessupon success.
Note
The x coordinate MUST be byte-aligned (i.e. ((x * bits_per_pixel) % 8 == 0)). In particular, this affects color formats that are not byte-aligned.
Interleaved color formats are a special case, as two logical pixels are packed into a single container. This means pairs of pixels will share the same address offset, for example pixels at (0, 0) and (1, 0) both have an offset of 0.


Usage considerations

  • Allowed context for the API call
    • Thread-safe: No
    • Interrupt handler: No
    • Signal handler: No
    • Re-entrant: No
    • Async/Sync: Sync
  • API group
    • Init: Yes
    • Runtime: Yes
    • De-Init: Yes

◆ NvRmSurfaceGetDefaultLayout()

NvRmSurfaceLayout NvRmSurfaceGetDefaultLayout ( void  )

Returns the system-wide default surface layout on the current platform.

Returns
Default surface layout on the current platform.


Usage considerations

  • Allowed context for the API call
    • Thread-safe: No
    • Interrupt handler: No
    • Signal handler: No
    • Re-entrant: No
    • Async/Sync: Sync
  • API group
    • Init: Yes
    • Runtime: Yes
    • De-Init: Yes

◆ NvRmSurfaceGetPitchAlignment()

NvError NvRmSurfaceGetPitchAlignment ( NvRmSurfaceLayout const  layout,
NvU32 const  unitSupport,
NvU32 *const  pitchAlign 
)

Returns the pitch alignment requirement in bytes.

This is the minimum number of bytes for a single row of a surface. For a blocklinear surface, this is the width of a GOB, NVRM_SURFACE_BLOCKLINEAR_PITCH_ALIGN_EXACT. For a pitch linear surface, this is NVRM_SURFACE_LINEAR_PITCH_ALIGN.

Parameters
[in]layoutThe layout to query the pitch alignment for.
[in]unitSupportBitwise OR combination of NvRmSurfaceUnitSupport enums or NvRmSurfaceUnitSupport_All.

Parameter constraints: (~NvRmSurfaceUnitSupport_All & unitSupport) must equal zero.
[out]pitchAlignOutput parameter: Receives the required pitch alignment in bytes.

Parameter constraints: must point to a 32 bit value that can be written to.
Returns
An NvError value describing the status of the operation.
Return values
NvError_BadParameterif unitSupport is not a bitwise OR combination of NvRmSurfaceUnitSupport values.
NvError_BadParameteris not any of the supported NvRmSurfaceLayout_X layouts
NvSuccessupon success.


Usage considerations

  • Allowed context for the API call
    • Thread-safe: No
    • Interrupt handler: No
    • Signal handler: No
    • Re-entrant: No
    • Async/Sync: Sync
  • API group
    • Init: Yes
    • Runtime: Yes
    • De-Init: Yes

◆ NvRmSurfaceGetYuvColorFormat()

NvYuvColorFormat NvRmSurfaceGetYuvColorFormat ( NvRmSurface const *const *  pSurf,
NvU32  numSurfaces 
)

Returns the YUV color format from an array of the N surfaces used to represent the YUV planes.

Parameters
[in]pSurfThe array of surfaces that are interpreted as a single YUV surface.

Parameter constraints: pSurf must point to an array that was setup by calling NvRmMultiplanarSurfaceSetup().
[in]numSurfacesThe number of surfaces in the pSurf array.

Parameter constraints: must fall in the range [1, 3] inclusive.
Returns
The NvYuvColorFormat of the multiplanar surface
Return values
NvYuvColorFormat_Unspecifiedif the YUV format cannot be determined from the surface.


Usage considerations

  • Allowed context for the API call
    • Thread-safe: No
    • Interrupt handler: No
    • Signal handler: No
    • Re-entrant: No
    • Async/Sync: Sync
  • API group
    • Init: Yes
    • Runtime: Yes
    • De-Init: Yes

◆ NvRmSurfaceLayoutToRelocType()

static NvU32 NvRmSurfaceLayoutToRelocType ( NvRmSurfaceLayout const  layout)
inlinestatic

Convert surface layout into NvHost reloc type.

Satisfies requirements:
\jama{25124609, GID-REQ-6209783}

Parameters
[in]layoutis the surface layout to translate.
Returns
The stream layout corresponding to layout, or NvRmStreamRelocType_Default in case of an error.

Definition at line 1444 of file nvrm_surface_fusa.h.

References NvRmStreamRelocType_Blocklinear, NvRmStreamRelocType_Pitch, NvRmSurfaceLayout_Blocklinear, and NvRmSurfaceLayout_Pitch.

◆ NvRmSurfaceRead()

NvError NvRmSurfaceRead ( NvRmSurface const *const  pSurf,
NvU32 const  x,
NvU32 const  y,
NvU32 const  width,
NvU32 const  height,
void *const  pDstPixels 
)

Reads a subregion of a surface.

This call is not hardware accelerated but is expected to be faster than calling NvRmSurfaceGetCoordOffset once per pixel. Does not perform any color space conversion or decompression.

For any surface with less than 8 bpp, x*bpp and width*bpp must both be multiples of 8. Further, the given region to read must be within the bounds of the surface – clipping is not supported.

Parameters
[in]pSurfNon-NULL pointer to surface.

Parameter constraints: must point to an NvRmSurface that was setup using NvRmSurfaceSetup.
[in]xSmallest X pixel coordinate of the rectangle to read.

Parameter constraints: (x <= pSurf->Width) must be true.
[in]ySmallest Y pixel coordinate of the rectangle to read.

Parameter constraints: (y <= pSurf->Height) must be true.
[in]widthWidth of rectangle to read.

Parameter constraints: ((x + width) <= pSurf->Width) must be true.
[in]heightHeight of rectangle to read.

Parameter constraints: ((y + height) <= pSurf->Height) must be true.
[out]pDstPixelsOutput parameter: A pointer to an array of Width*Height pixels to fill in. The pixels are stored in pitch format with a pitch of (width*BytesPerPixel).

Parameter constraints: Must be aligned to at least the word size of pSurf->ColorFormat. pDstPixels must point to a region of CPU writable memory of at least (width*height*BytesPerPixel) bytes.
Returns
An NvError value describing the status of the operation.
Return values
NvError_BadParameterif any of the following is true:
  • pSurf is NULL
  • pDstPixels is NULL
  • the region described by x, y, width and height is not fully inside the surface.
NvError_InvalidSurfaceif any of the following is true:
  • pSurf->ColorFormat is invalid
  • pSurf->Layout is invalid
  • both pSurf->hMem and pSurf->pBase are NULL
  • pSurf->SecondFieldOffset is smaller or equal to pSurf->Offset for interlaced surfaces
  • the read window size has valid dimensions but would exceed 32bit, indicating a corrupted surface.
NvSuccessupon success.
NvError_AccessDeniedis returned if attempting to read from a VPR surface.
See also
NvRmSurfaceSetDeviceMemory()


Usage considerations

  • Allowed context for the API call
    • Thread-safe: No
    • Interrupt handler: No
    • Signal handler: No
    • Re-entrant: No
    • Async/Sync: Sync
  • API group
    • Init: Yes
    • Runtime: Yes
    • De-Init: Yes

◆ NvRmSurfaceSetDeviceMemory()

NvError NvRmSurfaceSetDeviceMemory ( NvRmSurface *const  pSurf,
NvRmMemHandle const  hMem,
NvU32 const  offset,
void *const  mappedPtr 
)

Binds a surface to a region of device memory.

mappedPtr will be stored in pSurf->pBase, offset in pSurf->Offset and hMem in pSurf->hMem. pSurf->SecondFieldOffset will be updated as well. Surfaces can be 'unbound' by calling this function with hMem as NVRM_MEMHANDLE_NULL, pBase as NULL and offset as 0.

pSurf->CdeHorizontalCompbitsOffset, pSurf->CdeVerticalCompbitsOffset and pSurf->CdeScatterBufferOffset will be updated in non-safety builds.

Note
The surface will not take ownership of hMem or mappedPtr. Thus, 'unbinding' via NVRM_MEMHANDLE_NULL does not truly have a meaning except offering a legal way to reset pSurf->pBase,pSurf->Offset and pSurf->hMem to their initial state for cleanup purposes. It is perfectly ok for a NvRmSurface object to go out of scope without first 'unbinding' it via NvRmSurfaceSetDeviceMemory(pSurf, NVRM_MEMHANDLE_NULL, 0U, NULL);
Client is responsible that the allocated memory and mapped pointer meet the requirements of the initialized surface.
Safety builds require a mapped pointer to be provided for NvRmSurfaceRead and NvRmSurfaceWrite to function.
The required surface size is invariant with the surface's offset in memory.
Parameters
[in,out]pSurfNon-NULL pointer to a surface object.

Parameter constraints: must be a pointer to an NvRmSurface struct that was setup using NvRmSurfaceSetup.
[in]hMemhandle to device memory, may be NVRM_MEMHANDLE_NULL to unbind surface.

Parameter constraints: must be an NvRmMemHandle that was created by Memory Services.
[in]offsetDenotes the base offset of the surface inside of hMem.

Parameter constraints: must be aligned to the surface base alignment returned by NvRmSurfaceGetAlignment.
[in]mappedPtrIf non-NULL, points to a CPU mapping of hMem at offset of at least size pSurf->Size. May be NULL. Passing NULL means, no mapping is provided. It could be provided with a later call to NvRmSurfaceSetDeviceMemory or never.

Parameter constraints: must point to a region of CPU-writable memory of at least pSurf->Size bytes.
Returns
An NvError value describing the status of the operation.
Return values
NvError_BadParameterIf any of the following conditions is true:
  • pSurf is NULL
  • hMem is NVRM_MEMHANDLE_NULL and either pBase != NULL or offset != 0
  • pSurf->Size plus offset exceed 32bit
  • offset is not aligned to the surface base alignment indicated by NvRmSurfaceGetAlignment
NvSuccessupon success.
See also
NvRmSurfaceRead()
NvRmSurfaceWrite()


Usage considerations

  • Allowed context for the API call
    • Thread-safe: No
    • Interrupt handler: No
    • Signal handler: No
    • Re-entrant: No
    • Async/Sync: Sync
  • API group
    • Init: Yes
    • Runtime: Yes
    • De-Init: Yes

◆ NvRmSurfaceSetup()

NvError NvRmSurfaceSetup ( NvRmSurface *const  pSurf,
NvU32 const  width,
NvU32 const  height,
NvColorFormat const  colorFormat,
NvU32 const *const  attributes 
)

Sets up an NvRmSurface.

All fields are initialized to defaults as detailed in NvRmSurfaceAttribute. hMem, Offset and and pBase are set to zero. Attributes array can be used for communicating extra requirements. After a successful call to NvRmSurfaceSetup, the size, in bytes, will be set to a value that is large enough given the attributes of the surface and the engines present.

Parameters
[out]pSurfPointer to the surface to set up.

Parameter constraints: must be a pointer to a writable NvRmSurface struct.
[in]widthWidth of the surface in pixels.

Parameter constraints: the resulting size of the surface must fit in a 32 bit word, as computed by NvRmSurfaceIntComputeSize.
[in]heightHeight of the surface in pixels.

Parameter constraints: the resulting size of the surface must fit in a 32 bit word, as computed by NvRmSurfaceIntComputeSize.
[in]colorFormatColor format of the surface.

Parameter constraints: must be a valid NvColorFormat enum.
[in]attributesA NvRmSurfaceAttribute_None terminated list of attribute value pairs that override defaults. Pass NULL to use defaults for all attributes.

Parameter constraints: must point to an array of NvRmSurfaceAttribute pairs. Every even entry in the array must point to a valid NvRmSurfaceAttribute other than NvRmSurfaceAttribute_Last. The array must be terminated by NvRmSurfaceAttribute_None.
See also
NvRmSurfaceAttribute.
Returns
An NvError value describing the status of the operation.
Return values
NvError_BadParameterif any of the following is true:
  • pSurf is NULL
  • colorFormat is not a valid format
  • width or height are 0
  • width is odd when colorFormat is an interleaved format
  • any of the attributes is not supported
  • the attributes list has more than NvRmSurfaceAttribute_Last items
  • any of the attributes has an invalid value
NvError_InvalidSizeis returned for any of the following conditions:
  • the provided NvRmSurfaceAttribute_Size is smaller than needed for the surface or if NvRmSurfaceSetup failed to compute the surface size.
  • the required surface size would exceed 4GB for the given surface dimensions
NvSuccessupon success.
Note
This function or NvRmMultiplanarSurfaceSetup() need to be called at least once during the Init state if they are going to be called during Runtime state.
It is an error to provide the same attribute multiple times in the attributes list.


Usage considerations

  • Allowed context for the API call
    • Thread-safe: No
    • Interrupt handler: No
    • Signal handler: No
    • Re-entrant: No
    • Async/Sync: Sync
  • API group
    • Init: Yes
    • Runtime: Yes
    • De-Init: Yes

◆ NvRmSurfaceWrite()

NvError NvRmSurfaceWrite ( NvRmSurface const *const  pSurf,
NvU32 const  x,
NvU32 const  y,
NvU32 const  width,
NvU32 const  height,
void const *const  pSrcPixels 
)

Writes a subregion of a surface.

This call is not hardware accelerated but is expected to be faster than calling NvRmSurfaceGetCoordOffset once per pixel. Does not perform any color space conversion. Assumes that the surface is not compressed.

For any surface with less than 8 bpp, x*bpp and width*bpp must both be multiples of 8. Further, the given region to write must be within the bounds of the surface – clipping is not supported.

Parameters
[in,out]pSurfPointer to surface.

Parameter constraints: must point to a writable NvRmSurface that was setup using NvRmSurfaceSetup.
[in]xSmallest X pixel coordinate of the rectangle to write.

Parameter constraints: (x <= pSurf->Width) must be true.
[in]ySmallest Y pixel coordinate of the rectangle to write.

Parameter constraints: (y <= pSurf->Height) must be true.
[in]widthWidth of rectangle to write.

Parameter constraints: ((x + width) <= pSurf->Width) must be true.
[in]heightHeight of rectangle to write.

Parameter constraints: ((y + height) <= pSurf->Height) must be true.
[in]pSrcPixelsA pointer to an array of width*height pixels to write. The pixels are stored in pitch format with a pitch of (width*BytesPerPixel). Must be aligned to no less than the word size of pSurf->ColorFormat.

Parameter constraints: must point to a region of readable memory of at least (width*height*pSurf->BytesPerPixel) bytes.
Returns
An NvError value describing the status of the operation.
Return values
NvError_BadParameterif any of the following is true:
  • pSurf is NULL
  • pSrcPixels is NULL
  • the region described by x, y, width and height is not fully inside the surface.
NvError_InvalidSurfaceif any of the following is true:
  • pSurf->ColorFormat is invalid
  • pSurf->Layout is invalid
  • both pSurf->hMem and pSurf->pBase are NULL
  • pSurf->SecondFieldOffset is smaller or equal to pSurf->Offset for interlaced surfaces
  • the write window size has valid dimensions but would exceed 32bit, indicating a corrupted surface.
NvSuccessupon success.
See also
NvRmSurfaceSetDeviceMemory()


Usage considerations

  • Allowed context for the API call
    • Thread-safe: No
    • Interrupt handler: No
    • Signal handler: No
    • Re-entrant: No
    • Async/Sync: Sync
  • API group
    • Init: Yes
    • Runtime: Yes
    • De-Init: Yes
NvRmSurfaceLayout_Pitch
@ NvRmSurfaceLayout_Pitch
Pitch: Address formula is:
Definition: nvrm_surface_fusa.h:482
NvError
NvError
The NvError enumeration contains ALL return / error codes.
Definition: nverror.h:43
NVRM_MEM_HANDLE_SET_ATTR
#define NVRM_MEM_HANDLE_SET_ATTR(attr, al, ch, sz, tg)
Description: Helper macro function for setting handle attributes.
Definition: nvrm_memmgr_safe.h:1027
NVRM_DEFINE_MEM_HANDLE_ATTR
#define NVRM_DEFINE_MEM_HANDLE_ATTR(x)
Description: Helper macro function for defining handle attribute.
Definition: nvrm_memmgr_safe.h:996
NvRmSurfaceSetup
NvError NvRmSurfaceSetup(NvRmSurface *const pSurf, NvU32 const width, NvU32 const height, NvColorFormat const colorFormat, NvU32 const *const attributes)
Sets up an NvRmSurface.
NvRmMemHandleAllocAttr
NvError NvRmMemHandleAllocAttr(NvRmDeviceHandle hDevice, NvRmMemHandleAttr *attr, NvRmMemHandle *phMem)
@IfaceTagForDoc
NvRmSurfaceSetDeviceMemory
NvError NvRmSurfaceSetDeviceMemory(NvRmSurface *const pSurf, NvRmMemHandle const hMem, NvU32 const offset, void *const mappedPtr)
Binds a surface to a region of device memory.
NvRmMultiplanarSurfaceSetup
NvError NvRmMultiplanarSurfaceSetup(NvRmSurface *Surfaces, NvU32 NumSurfaces, NvU32 Width, NvU32 Height, NvYuvColorFormat YuvFormat, const NvColorFormat *ColorFormats, const NvU32 *Attributes)
Sets up a set of NvRmSurfaces describing a multiplanar surface.
NvRmSurfaceAttribute_None
@ NvRmSurfaceAttribute_None
Must terminate the attribute list.
Definition: nvrm_surface_fusa.h:727
NvRmSurfaceAttribute_Layout
@ NvRmSurfaceAttribute_Layout
Memory Layout to use for the surface.
Definition: nvrm_surface_fusa.h:733
NvRmSurfaceAttribute_Compression
@ NvRmSurfaceAttribute_Compression
Selects the level of compression support desired for the surface.
Definition: nvrm_surface_fusa.h:789
NvRmMemHandle
struct NvRmMemRec * NvRmMemHandle
Definition: nvrm_memmgr_safe.h:160
NvYuvColorFormat_YUV420
@ NvYuvColorFormat_YUV420
Horizontal and vertical sub-sampling.
Definition: nvrm_surface_fusa.h:409
NvRmSurfaceGetAlignment
NvError NvRmSurfaceGetAlignment(NvRmSurface const *const pSurf, NvU32 *const pAlignment)
Returns the alignment in bytes that the surface's memory will need to be allocated with.
NvSuccess
@ NvSuccess
An alias for success.
Definition: nverror.h:49
NvRmSurfaceRec::Size
NvU64 Size
Size of the surface, in bytes, including all necessary padding and metadata.
Definition: nvrm_surface_fusa.h:613
NvRmMemMap
NvError NvRmMemMap(NvRmMemHandle hMem, NvU64 Offset, NvU64 Size, NvU32 Flags, void **pVirtAddr)
@IfaceTagForDoc qnx_sr_only_doxygen_start: Covers: [Libnvrm_mem_SWUD_15] qnx_sr_only_doxygen_end:
NvYuvColorFormat
NvYuvColorFormat
Defines the different color formats in the YUV color space.
Definition: nvrm_surface_fusa.h:403
NVRM_MEMHANDLE_NULL
#define NVRM_MEMHANDLE_NULL
Definition: nvrm_memmgr_safe.h:161
NvRmSurfaceRec
An exposed (not opaque) structure representing a surface.
Definition: nvrm_surface_fusa.h:553
NvOsMemAttribute_WriteBack
@ NvOsMemAttribute_WriteBack
Definition: nvos_common_tegra_safety.h:287
NVRM_MEM_TAG_GRALLOC_MISC
#define NVRM_MEM_TAG_GRALLOC_MISC
Deprecated macro.
Definition: nvrm_memmgr_deprecated.h:111