Add/update comments to the code (#25)
* Add/update comments to the code * update comments * Update comments
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e73ec1412c
Коммит
73c0b10f6a
@@ -48,31 +48,62 @@ THE SOFTWARE.
|
||||
/*Note: va.h doesn't have VA_FOURCC_YUYV defined but vaExportSurfaceHandle returns 0x56595559 for packed YUYV for YUV 4:2:2*/
|
||||
#define ROCJPEG_FOURCC_YUYV 0x56595559
|
||||
|
||||
/**
|
||||
* @brief Enumeration representing the compute partition for the MI300+ family of GPUs.
|
||||
*/
|
||||
typedef enum {
|
||||
kSpx = 0, // Single Partition Accelerator
|
||||
kDpx = 1, // Dual Partition Accelerator
|
||||
kTpx = 2, // Triple Partition Accelerator
|
||||
kQpx = 3, // Quad Partition Accelerator
|
||||
kCpx = 4, // Core Partition Accelerator
|
||||
kSpx = 0, /**< Single Partition Accelerator */
|
||||
kDpx = 1, /**< Dual Partition Accelerator */
|
||||
kTpx = 2, /**< Triple Partition Accelerator */
|
||||
kQpx = 3, /**< Quad Partition Accelerator */
|
||||
kCpx = 4, /**< Core Partition Accelerator */
|
||||
} ComputePartition;
|
||||
|
||||
/**
|
||||
* @brief Structure representing the specifications of a VCN JPEG decoder.
|
||||
*
|
||||
* This structure contains information about the VCN JPEG decoder, including the number of JPEG cores,
|
||||
* whether it can convert to RGB, and whether it supports ROI (Region of Interest) decoding.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t num_jpeg_cores;
|
||||
bool can_convert_to_rgb;
|
||||
bool can_roi_decode;
|
||||
uint32_t num_jpeg_cores; /**< Number of JPEG cores in the VCN JPEG decoder. */
|
||||
bool can_convert_to_rgb; /**< Flag indicating whether the VCN JPEG decoder can convert to RGB. */
|
||||
bool can_roi_decode; /**< Flag indicating whether the VCN JPEG decoder supports ROI decoding. */
|
||||
} VcnJpegSpec;
|
||||
|
||||
/**
|
||||
* @brief Structure representing the HIP interop device memory.
|
||||
*
|
||||
* This structure holds information related to the HIP-VAAPI interop device memory.
|
||||
* It includes the HIP external memory interface, mapped device memory for the YUV plane,
|
||||
* pixel format fourcc of the whole surface, width and height of the surface in pixels,
|
||||
* offset and pitch of each plane, and the number of layers making up the surface.
|
||||
*/
|
||||
struct HipInteropDeviceMem {
|
||||
hipExternalMemory_t hip_ext_mem; // Interface to the vaapi-hip interop
|
||||
uint8_t* hip_mapped_device_mem; // Mapped device memory for the YUV plane
|
||||
uint32_t surface_format; // Pixel format fourcc of the whole surface
|
||||
uint32_t width; // Width of the surface in pixels.
|
||||
uint32_t height; // Height of the surface in pixels.
|
||||
uint32_t offset[3]; // Offset of each plane
|
||||
uint32_t pitch[3]; // Pitch of each plane
|
||||
uint32_t num_layers; // Number of layers making up the surface
|
||||
hipExternalMemory_t hip_ext_mem; /**< Interface to the vaapi-hip interop */
|
||||
uint8_t* hip_mapped_device_mem; /**< Mapped device memory for the YUV plane */
|
||||
uint32_t surface_format; /**< Pixel format fourcc of the whole surface */
|
||||
uint32_t width; /**< Width of the surface in pixels. */
|
||||
uint32_t height; /**< Height of the surface in pixels. */
|
||||
uint32_t offset[3]; /**< Offset of each plane */
|
||||
uint32_t pitch[3]; /**< Pitch of each plane */
|
||||
uint32_t num_layers; /**< Number of layers making up the surface */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Structure representing an entry in the RocJpegVappiMemPool.
|
||||
*
|
||||
* This structure holds information about an image in the memory pool used by the RocJpegVappiDecoder.
|
||||
* It includes the image width and height, the VASurfaceID and VAContextID associated with the image,
|
||||
* and the HipInteropDeviceMem for interoperation with HIP.
|
||||
*/
|
||||
/**
|
||||
* @brief Structure representing an entry in the RocJpegVappiMemPool.
|
||||
*
|
||||
* This structure holds information about an image in the memory pool used by the RocJpegVappiDecoder.
|
||||
* It includes the image width and height, the VASurfaceID and VAContextID associated with the image,
|
||||
* and the HipInteropDeviceMem for interoperation with HIP.
|
||||
*/
|
||||
struct RocJpegVappiMemPoolEntry {
|
||||
uint32_t image_width;
|
||||
uint32_t image_height;
|
||||
@@ -81,54 +112,190 @@ struct RocJpegVappiMemPoolEntry {
|
||||
HipInteropDeviceMem hip_interop;
|
||||
};
|
||||
|
||||
/**
|
||||
* @class RocJpegVappiMemoryPool
|
||||
* @brief A class that represents a memory pool for VAAPI surfaces used by the RocJpegVappiDecoder.
|
||||
*
|
||||
* The RocJpegVappiMemoryPool class provides methods to manage and allocate memory resources for VAAPI surfaces.
|
||||
* It allows setting the pool size, associating a VADisplay, finding surface IDs, getting pool entries, adding pool entries,
|
||||
* deleting surface IDs, and retrieving HipInterop memory for a specific surface ID.
|
||||
*/
|
||||
class RocJpegVappiMemoryPool {
|
||||
public:
|
||||
/**
|
||||
* @brief Default constructor for RocJpegVappiMemoryPool.
|
||||
*/
|
||||
RocJpegVappiMemoryPool();
|
||||
|
||||
/**
|
||||
* @brief Releases all the resources associated with the memory pool.
|
||||
*/
|
||||
void ReleaseResources();
|
||||
|
||||
/**
|
||||
* @brief Sets the maximum size of the memory pool.
|
||||
* @param max_pool_size The maximum size of the memory pool.
|
||||
*/
|
||||
void SetPoolSize(int32_t max_pool_size);
|
||||
|
||||
/**
|
||||
* @brief Sets the VADisplay for the memory pool.
|
||||
* @param va_display The VADisplay to be set.
|
||||
*/
|
||||
void SetVaapiDisplay(const VADisplay& va_display);
|
||||
|
||||
/**
|
||||
* @brief Finds a surface ID in the memory pool.
|
||||
* @param surface_id The surface ID to find.
|
||||
* @return True if the surface ID is found, false otherwise.
|
||||
*/
|
||||
bool FindSurfaceId(VASurfaceID surface_id);
|
||||
|
||||
/**
|
||||
* @brief Gets a pool entry based on the surface format, image width, and image height.
|
||||
* @param surface_format The surface format of the pool entry.
|
||||
* @param image_width The image width of the pool entry.
|
||||
* @param image_height The image height of the pool entry.
|
||||
* @return The RocJpegVappiMemPoolEntry object if found, otherwise a default-constructed object.
|
||||
*/
|
||||
RocJpegVappiMemPoolEntry GetEntry(uint32_t surface_format, uint32_t image_width, uint32_t image_height);
|
||||
|
||||
/**
|
||||
* @brief Adds a pool entry to the memory pool.
|
||||
* @param surface_format The surface format of the pool entry.
|
||||
* @param pool_entry The RocJpegVappiMemPoolEntry to be added.
|
||||
* @return The status of the operation.
|
||||
*/
|
||||
RocJpegStatus AddPoolEntry(uint32_t surface_format, const RocJpegVappiMemPoolEntry& pool_entry);
|
||||
|
||||
/**
|
||||
* @brief Deletes a surface ID from the memory pool.
|
||||
* @param surface_id The surface ID to be deleted.
|
||||
* @return The status of the operation.
|
||||
*/
|
||||
RocJpegStatus DeleteSurfaceId(VASurfaceID surface_id);
|
||||
|
||||
/**
|
||||
* @brief Retrieves HipInterop memory for a specific surface ID.
|
||||
* @param surface_id The surface ID to retrieve HipInterop memory for.
|
||||
* @param hip_interop The HipInteropDeviceMem object to store the retrieved memory.
|
||||
* @return The status of the operation.
|
||||
*/
|
||||
RocJpegStatus GetHipInteropMem(VASurfaceID surface_id, HipInteropDeviceMem& hip_interop);
|
||||
|
||||
private:
|
||||
VADisplay va_display_;
|
||||
std::unordered_map<uint32_t, std::vector<RocJpegVappiMemPoolEntry>> mem_pool_;
|
||||
VADisplay va_display_; // The VADisplay associated with the memory pool.
|
||||
std::unordered_map<uint32_t, std::vector<RocJpegVappiMemPoolEntry>> mem_pool_; // The memory pool.
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The RocJpegVappiDecoder class represents a VAAPI-based JPEG decoder.
|
||||
*/
|
||||
class RocJpegVappiDecoder {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs a RocJpegVappiDecoder object.
|
||||
* @param device_id The ID of the device to use for decoding (default is 0).
|
||||
*/
|
||||
RocJpegVappiDecoder(int device_id = 0);
|
||||
|
||||
/**
|
||||
* @brief Destroys the RocJpegVappiDecoder object.
|
||||
*/
|
||||
~RocJpegVappiDecoder();
|
||||
|
||||
/**
|
||||
* @brief Initializes the decoder with the specified device, GCN architecture, and device ID.
|
||||
* @param device_name The name of the device.
|
||||
* @param gcn_arch_name The name of the GCN architecture.
|
||||
* @param device_id The ID of the device.
|
||||
* @return The status of the initialization.
|
||||
*/
|
||||
RocJpegStatus InitializeDecoder(std::string device_name, std::string gcn_arch_name, int device_id);
|
||||
|
||||
/**
|
||||
* @brief Submits a JPEG stream for decoding.
|
||||
* @param jpeg_stream_params The parameters of the JPEG stream.
|
||||
* @param surface_id The ID of the output surface.
|
||||
* @param output_format The output format of the decoded image.
|
||||
* @return The status of the decoding operation.
|
||||
*/
|
||||
RocJpegStatus SubmitDecode(const JpegStreamParameters *jpeg_stream_params, uint32_t &surface_id, RocJpegOutputFormat output_format);
|
||||
|
||||
/**
|
||||
* @brief Waits for the decoding operation to complete.
|
||||
* @param surface_id The ID of the output surface.
|
||||
* @return The status of the synchronization operation.
|
||||
*/
|
||||
RocJpegStatus SyncSurface(VASurfaceID surface_id);
|
||||
|
||||
/**
|
||||
* @brief Retrieves the HIP interop memory associated with the specified surface.
|
||||
* @param surface_id The ID of the surface.
|
||||
* @param hip_interop The HIP interop memory object to be filled.
|
||||
* @return The status of the retrieval operation.
|
||||
*/
|
||||
RocJpegStatus GetHipInteropMem(VASurfaceID surface_id, HipInteropDeviceMem& hip_interop);
|
||||
|
||||
private:
|
||||
int device_id_;
|
||||
int drm_fd_;
|
||||
uint32_t min_picture_width_;
|
||||
uint32_t min_picture_height_;
|
||||
uint32_t max_picture_width_;
|
||||
uint32_t max_picture_height_;
|
||||
VADisplay va_display_;
|
||||
std::vector<VAConfigAttrib> va_config_attrib_;
|
||||
VAConfigID va_config_id_;
|
||||
VAProfile va_profile_;
|
||||
std::unordered_map<std::string, VcnJpegSpec> vcn_jpeg_spec_;
|
||||
std::unique_ptr<RocJpegVappiMemoryPool> vaapi_mem_pool_;
|
||||
VcnJpegSpec current_vcn_jpeg_spec_;
|
||||
VABufferID va_picture_parameter_buf_id_;
|
||||
VABufferID va_quantization_matrix_buf_id_;
|
||||
VABufferID va_huffmantable_buf_id_;
|
||||
VABufferID va_slice_param_buf_id_;
|
||||
VABufferID va_slice_data_buf_id_;
|
||||
int device_id_; // The ID of the device
|
||||
int drm_fd_; // The file descriptor for the DRM device
|
||||
uint32_t min_picture_width_; // The minimum width of the picture
|
||||
uint32_t min_picture_height_; // The minimum height of the picture
|
||||
uint32_t max_picture_width_; // The maximum width of the picture
|
||||
uint32_t max_picture_height_; // The maximum height of the picture
|
||||
VADisplay va_display_; // The VAAPI display
|
||||
std::vector<VAConfigAttrib> va_config_attrib_; // The VAAPI configuration attributes
|
||||
VAConfigID va_config_id_; // The VAAPI configuration ID
|
||||
VAProfile va_profile_; // The VAAPI profile
|
||||
std::unordered_map<std::string, VcnJpegSpec> vcn_jpeg_spec_; // The map of VCN JPEG specifications
|
||||
std::unique_ptr<RocJpegVappiMemoryPool> vaapi_mem_pool_; // The VAAPI memory pool
|
||||
VcnJpegSpec current_vcn_jpeg_spec_; // The current VCN JPEG specification
|
||||
VABufferID va_picture_parameter_buf_id_; // The VAAPI picture parameter buffer ID
|
||||
VABufferID va_quantization_matrix_buf_id_; // The VAAPI quantization matrix buffer ID
|
||||
VABufferID va_huffmantable_buf_id_; // The VAAPI Huffman table buffer ID
|
||||
VABufferID va_slice_param_buf_id_; // The VAAPI slice parameter buffer ID
|
||||
VABufferID va_slice_data_buf_id_; // The VAAPI slice data buffer ID
|
||||
|
||||
/**
|
||||
* @brief Initializes the VAAPI with the specified DRM node.
|
||||
* @param drm_node The DRM node to use for VAAPI initialization.
|
||||
* @return The status of the VAAPI initialization.
|
||||
*/
|
||||
RocJpegStatus InitVAAPI(std::string drm_node);
|
||||
|
||||
/**
|
||||
* @brief Creates the decoder configuration.
|
||||
* @return The status of the configuration creation.
|
||||
*/
|
||||
RocJpegStatus CreateDecoderConfig();
|
||||
|
||||
/**
|
||||
* @brief Destroys the data buffers.
|
||||
* @return The status of the buffer destruction.
|
||||
*/
|
||||
RocJpegStatus DestroyDataBuffers();
|
||||
|
||||
/**
|
||||
* @brief Retrieves the visible devices.
|
||||
* @param visible_devices The vector to store the visible devices.
|
||||
*/
|
||||
void GetVisibleDevices(std::vector<int>& visible_devices);
|
||||
|
||||
/**
|
||||
* @brief Retrieves the current compute partitions.
|
||||
* @param current_compute_partitions The vector to store the current compute partitions.
|
||||
*/
|
||||
void GetCurrentComputePartition(std::vector<ComputePartition> &currnet_compute_partitions);
|
||||
|
||||
/**
|
||||
* @brief Retrieves the DRM node offset.
|
||||
* @param device_name The name of the device.
|
||||
* @param device_id The ID of the device.
|
||||
* @param visible_devices The vector of visible devices.
|
||||
* @param current_compute_partitions The vector of current compute partitions.
|
||||
* @param offset The offset of the DRM node.
|
||||
*/
|
||||
void GetDrmNodeOffset(std::string device_name, uint8_t device_id, std::vector<int>& visible_devices,
|
||||
std::vector<ComputePartition> ¤t_compute_partitions,
|
||||
int &offset);
|
||||
|
||||
Ссылка в новой задаче
Block a user