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:
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:
Or to request a compressible surface, do:
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:
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:
This code snippet initializes a semiplanar surface:
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:
NULL pointers are expected to be valid.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... | |
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... | |
| #define NVRM_MAX_SURFACES 3 |
Maximum number of NvRmSurfaces that GLES textureinfo/NvWsiPixmap contain.
Definition at line 465 of file nvrm_surface_fusa.h.
| #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.
| #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.
| #define NvRmSurfaceUnitSupport |
Definition at line 658 of file nvrm_surface_fusa.h.
| #define NvYuvChromaLocation_BT601 NvYuvChromaLocation_0_0 |
Aliases for typical usage.
Definition at line 443 of file nvrm_surface_fusa.h.
| #define NvYuvChromaLocation_JPEG NvYuvChromaLocation_1_1 |
Definition at line 446 of file nvrm_surface_fusa.h.
| #define NvYuvChromaLocation_MPEG1 NvYuvChromaLocation_1_1 |
Definition at line 445 of file nvrm_surface_fusa.h.
| #define NvYuvChromaLocation_MPEG2 NvYuvChromaLocation_0_1 |
Definition at line 444 of file nvrm_surface_fusa.h.
| typedef struct NvRmSurfaceRec NvRmSurface |
An exposed (not opaque) structure representing a surface.
Use constraints for the structure:
| typedef struct NvRmSurfaceContainerRec 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.
| enum 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.
| enum 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.
Defines general surface compression support.
Definition at line 685 of file nvrm_surface_fusa.h.
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.
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.
Definition at line 851 of file nvrm_surface_fusa.h.
| enum 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.
|
| NvRmSurfaceLayout_Blocklinear | BlockLinear: Surface is stored in a hardware defined, opaque "blocklinear" organization. The exact byte layout of blocklinear format is determined by surface |
| NvRmSurfaceLayout_Num | |
| NvRmSurfaceLayout_Force32 | |
Definition at line 475 of file nvrm_surface_fusa.h.
Defines engine/unit support.
The individual values are expected to be bitwise OR'ed into masks indicating multi-engine support.
Definition at line 662 of file nvrm_surface_fusa.h.
| enum NvYuvChromaLocation |
Defines the chroma subsampling location.
Definition at line 423 of file nvrm_surface_fusa.h.
| enum NvYuvColorFormat |
Defines the different color formats in the YUV color space.
This enumeration describes the chroma sub-sampling ratios.
Definition at line 403 of file nvrm_surface_fusa.h.
| 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.
| [out] | Surfaces | The array of surfaces to set up. Parameter constraints: must point to an array of NvRmSurface* pointers, of size NumSurfaces. |
| [in] | NumSurfaces | How many surfaces are in the array. Parameter constraints: must be in the range [1, 3] inclusive. |
| [in] | Width | Width 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] | Height | Height 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] | YuvFormat | Format 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] | ColorFormats | NumSurfaces-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] | Attributes | A 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. |
| NvError_BadParameter | if 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_BadParameter | if NumSurfaces, YuvFormat, Width and Height do not specify a valid Multiplanar YUV or non YUV single planar surface. |
| NvError_InvalidSize | if 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. |
| NvSuccess | upon success. |
Usage considerations
| 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.
| [in] | pSurf | A pointer to structure describing a fully initialized surface. Parameter constraints: must point to an NvRmSurface that was setup using NvRmSurfaceSetup. |
| [out] | pAlignment | Output parameter: Receives the alignment if function succeeds. Parameter constraints: Must point to at least 32 bits of writable memory. |
| NvError_BadParameter | if either pSurf or pAlignment is NULL. |
| NvError_InvalidSurface | if the surface's layout is not supported |
| NvSuccess | upon success. |
Usage considerations
| 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.
| [in] | pSurf | Non-NULL pointer to surface. Parameter constraints: must point to an NvRmSurface that was setup using NvRmSurfaceSetup. |
| [in] | x | X coordinate in pixels. Parameter constraints: (x <= pSurf->Width) must be true. |
| [in] | y | Y coordinate in pixels. Parameter constraints: (y <= pSurf->Height) must be true. |
| [out] | pOffset | Output parameter: Receives the byte offset for x,y coordinate. Parameter constraints: must point to 4 bytes of writable memory. |
| NvError_BadParameter | if any of the following is true
|
| NvError_InvalidSurface | if any of the following is true:
|
| NvSuccess | upon success. |
Usage considerations
| NvRmSurfaceLayout NvRmSurfaceGetDefaultLayout | ( | void | ) |
Returns the system-wide default surface layout on the current platform.
Usage considerations
| 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.
| [in] | layout | The layout to query the pitch alignment for. |
| [in] | unitSupport | Bitwise OR combination of NvRmSurfaceUnitSupport enums or NvRmSurfaceUnitSupport_All. Parameter constraints: (~NvRmSurfaceUnitSupport_All & unitSupport) must equal zero. |
| [out] | pitchAlign | Output parameter: Receives the required pitch alignment in bytes. Parameter constraints: must point to a 32 bit value that can be written to. |
| NvError_BadParameter | if unitSupport is not a bitwise OR combination of NvRmSurfaceUnitSupport values. |
| NvError_BadParameter | is not any of the supported NvRmSurfaceLayout_X layouts |
| NvSuccess | upon success. |
Usage considerations
| 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.
| [in] | pSurf | The 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] | numSurfaces | The number of surfaces in the pSurf array. Parameter constraints: must fall in the range [1, 3] inclusive. |
| NvYuvColorFormat_Unspecified | if the YUV format cannot be determined from the surface. |
Usage considerations
|
inlinestatic |
Convert surface layout into NvHost reloc type.
Satisfies requirements:
\jama{25124609, GID-REQ-6209783}
| [in] | layout | is the surface layout to translate. |
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.
| 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.
| [in] | pSurf | Non-NULL pointer to surface. Parameter constraints: must point to an NvRmSurface that was setup using NvRmSurfaceSetup. |
| [in] | x | Smallest X pixel coordinate of the rectangle to read. Parameter constraints: (x <= pSurf->Width) must be true. |
| [in] | y | Smallest Y pixel coordinate of the rectangle to read. Parameter constraints: (y <= pSurf->Height) must be true. |
| [in] | width | Width of rectangle to read. Parameter constraints: ((x + width) <= pSurf->Width) must be true. |
| [in] | height | Height of rectangle to read. Parameter constraints: ((y + height) <= pSurf->Height) must be true. |
| [out] | pDstPixels | Output 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. |
| NvError_BadParameter | if any of the following is true:
|
| NvError_InvalidSurface | if any of the following is true:
|
| NvSuccess | upon success. |
| NvError_AccessDenied | is returned if attempting to read from a VPR surface. |
Usage considerations
| 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.
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);| [in,out] | pSurf | Non-NULL pointer to a surface object. Parameter constraints: must be a pointer to an NvRmSurface struct that was setup using NvRmSurfaceSetup. |
| [in] | hMem | handle to device memory, may be NVRM_MEMHANDLE_NULL to unbind surface. Parameter constraints: must be an NvRmMemHandle that was created by Memory Services. |
| [in] | offset | Denotes the base offset of the surface inside of hMem. Parameter constraints: must be aligned to the surface base alignment returned by NvRmSurfaceGetAlignment. |
| [in] | mappedPtr | If 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. |
| NvError_BadParameter | If any of the following conditions is true:
|
| NvSuccess | upon success. |
Usage considerations
| 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.
| [out] | pSurf | Pointer to the surface to set up. Parameter constraints: must be a pointer to a writable NvRmSurface struct. |
| [in] | width | Width 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] | height | Height 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] | colorFormat | Color format of the surface. Parameter constraints: must be a valid NvColorFormat enum. |
| [in] | attributes | A 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. |
| NvError_BadParameter | if any of the following is true:
|
| NvError_InvalidSize | is returned for any of the following conditions:
|
| NvSuccess | upon success. |
Usage considerations
| 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.
| [in,out] | pSurf | Pointer to surface. Parameter constraints: must point to a writable NvRmSurface that was setup using NvRmSurfaceSetup. |
| [in] | x | Smallest X pixel coordinate of the rectangle to write. Parameter constraints: (x <= pSurf->Width) must be true. |
| [in] | y | Smallest Y pixel coordinate of the rectangle to write. Parameter constraints: (y <= pSurf->Height) must be true. |
| [in] | width | Width of rectangle to write. Parameter constraints: ((x + width) <= pSurf->Width) must be true. |
| [in] | height | Height of rectangle to write. Parameter constraints: ((y + height) <= pSurf->Height) must be true. |
| [in] | pSrcPixels | A 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. |
| NvError_BadParameter | if any of the following is true:
|
| NvError_InvalidSurface | if any of the following is true:
|
| NvSuccess | upon success. |
Usage considerations