1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
|
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
//!
//! \file cm_buffer.h
//! \brief Contains Class CmBuffer/CmBufferUp definitions
//!
#ifndef MEDIADRIVER_AGNOSTIC_COMMON_CM_CMBUFFER_H_
#define MEDIADRIVER_AGNOSTIC_COMMON_CM_CMBUFFER_H_
#include "cm_def.h"
// Parameters used to set the surface state of the buffer
struct CM_BUFFER_STATE_PARAM
{
uint32_t uiSize;
uint32_t uiBaseAddressOffset;
CM_SURFACE_MEM_OBJ_CTRL mocs;
};
namespace CMRT_UMD
{
class CmEvent;
//! \brief CmBufferSVM Class to manage SVM (Shared Virtual Memory) resource.
//! \details CmBufferSVM represents a 1D surface in SVM (Shared Virtual Memory)
//! memory space that is shared between CPU and GPU. The SVM memory must
//! be page(4K Bytes) aligned and runtime allocates SVM memory when
//! CmDevice::CreateBufferSVM is called. CPU can access the memory by using
//! the address returned by GetAddress. GPU can access the memory in two ways
//! One way is to use the surfaceIndex returned by GetIndex, similiar to all
//! other surfaces and buffers. The other way is to pass the address to CM
//! kernel function(genx_main) as an argument for kernel to use.
//! \note Right now BufferSVM feature is not working on Linux yet.
class CmBufferSVM
{
public:
//!
//! \brief This function returns the SurfaceIndex object associated
//! with the SVM resource.
//! \param [out] index
//! Reference to the pointer to SurfaceIndex.
//! \returns CM_SUCCESS.
//!
CM_RT_API virtual int32_t GetIndex(SurfaceIndex* &index) = 0;
//!
//! \brief Get the pointer of allocated SVM memory starting address.
//! \param [out] addr
//! return the allocated SVM memory starting address.
//! \returns CM_SUCCESS.
//!
CM_RT_API virtual int32_t GetAddress(void* &addr) = 0;
};
//!
//! \brief CmBufferUP class to manage 1D surface in user provided system memory.
//! \details CmBufferUP represents a 1D surface in system memory. It is
//! created upon the UP(User Provided) memory. The UP memory
//! must be page(4K Bytes) aligned. CPU can access the memory
//! as usual.Each CmBufferUP object is associated with a SurfaceIndex
//! object containing a unique index value the surface is mapped to
//! when created by the CmDevice.The CmDevice keeps the mapping b/w
//! index and CmBufferUP. The SurfaceIndex is passed to CM kernel
//! function(genx_main) as argument to indicate the surface. It is
//! application's responsibility to make sure the accesses from CPU
//! and GPU are not overlapped.
//!
class CmBufferUP
{
public:
//!
//! \brief This function returns the SurfaceIndex object associated
//! with this CmBufferUp object.
//! \param [out] index
//! Reference to the pointer to SurfaceIndex.
//! \returns CM_SUCCESS.
//!
CM_RT_API virtual int32_t GetIndex(SurfaceIndex* &index) = 0;
//!
//! \brief Selects one of the pre-defined memory object control
//! settings for this buffer.
//! \param [in] memCtrl
//! The selected pre-defined memory object control setting.
//! \retval CM_SUCCESS if the memory object control is set successfully.
//! \retval CM_FAILURE otherwise.
//! \note This API is only supported for Gen9 and plus platform.
//!
CM_RT_API virtual int32_t
SelectMemoryObjectControlSetting(MEMORY_OBJECT_CONTROL memCtrl) = 0;
};
//!
//! \brief CmBuffer Class to manage 1D surface in video memory.
//! \details CmBuffer represents a 1D surface in video memory. Each CmBuffer
//! object is associated with a SurfaceIndex object containing a
//! unique index value the surface is mapped to when created by the
//! CmDevice. The CmDevice keeps the mapping b/w index and CmBuffer.
//! The SurfaceIndex is passed to CM kernel function (genx_main) as
//! argument to indicate the surface.
//!
class CmBuffer
{
public:
//!
//! \brief This function returns the SurfaceIndex object associated
//! with this CmBuffer object.
//! \param [out] index
//! Reference to the pointer to SurfaceIndex.
//! \returns CM_SUCCESS.
//!
CM_RT_API virtual int32_t GetIndex(SurfaceIndex* &index) = 0;
//!
//! \brief Copies data in this buffer to system memory using CPU.
//! \details The size of data copied is the size of data in buffer.This
//! API is a blocking function, i.e. the function will not
//! return until the copy operation is completed. Buffer
//! reading will not happen until the status of the dependent
//! event becomes CM_STATUS_FINISHED. It is application's
//! responsibility to make sure no other task enqueued after
//! the task corresponding to the dependent task but before
//! ReadSurface. If sysMemSize is given, it will be checked
//! against the size needed for the buffer. If the sysMemSize
//! is less than the CmBuffer size, copy only happens for sysMemSize
//! bytes, not all data in CmBuffer.
//! \param [out] sysMem
//! Pointer to the system memory receiving buffer data.
//! \param [in] event
//! Pointer to the dependent event used for sychronization.
//! \param [in] sysMemSize
//! Size of the system memory in byte.
//! \retval CM_SUCCESS if copy is successful.
//! \retval CM_INVALID_ARG_VALUE if sysMem is nullptr.
//! \retval CM_LOCK_SURFACE_FAIL if surface locking is failed.
//! \retval CM_FAILURE otherwise.
//!
CM_RT_API virtual int32_t
ReadSurface(unsigned char* sysMem,
CmEvent* event,
uint64_t sysMemSize = 0xFFFFFFFFFFFFFFFFULL) = 0;
//!
//! \brief Copies system memory content to this buffer usingg CPU.
//! \details The size of data copied is the size of data in the
//! buffer. This is a blocking function, i.e. the function will
//! not return until the copy operation is completed. Buffer
//! writing will not happen until the status of the dependent
//! event becomes CM_STATUS_FINISHED. The dependent event for
//! WriteSurface is usually NULL. If sysMemSize is given, it
//! will be checked against the size needed for the buffer.
//! If the sysMemSize is less than the CmBuffer size, copy only
//! happens for sysMemSize bytes, not all data in CmBuffer.
//! \param [in] sysMem
//! Pointer to the system memory storing the buffer data.
//! \param [in] event
//! Pointer to the dependent event used for sychronization.
//! \param [in] sysMemSize
//! Size of the system memory in byte.
//! \retval CM_SUCCESS if copy is successful.
//! \retval CM_INVALID_ARG_VALUE if sysMem pointer is nullptr.
//! \retval CM_LOCK_SURFACE_FAIL if surface locking is failed.
//! \retval CM_FAILURE otherwise.
//!
CM_RT_API virtual int32_t
WriteSurface(const unsigned char* sysMem,
CmEvent* event,
uint64_t sysMemSize = 0xFFFFFFFFFFFFFFFFULL) = 0;
//!
//! \brief Sets memory in this buffer to uint32_t value using CPU.
//! \details The size of data initialized is the size of data in the
//! buffer. This is a blocking function, i.e. the function will
//! not return until the set operation is completed. Buffer
//! initialization will not happen until the status of the
//! dependent event becomes CM_STATUS_FINISHED. The dependent
//! event for InitSurface is usually NULL.
//! \param [in] initValue
//! uint32_t value used to initialize to.
//! \param [in] event
//! Pointer to the dependent event used for sychronization.
//! \retval CM_SUCCESS if copy is successful.
//! \retval CM_LOCK_SURFACE_FAIL if surface locking is failed.
//! \retval CM_FAILURE otherwise.
//!
CM_RT_API virtual int32_t InitSurface(const uint32_t initValue,
CmEvent* event) = 0;
//!
//! \brief Selects one of the pre-defined memory object control
//! settings for this buffer.
//! \param [in] memCtrl
//! The selected pre-defined memory object control setting.
//! \retval CM_SUCCESS if the memory object control is set successfully.
//! \retval CM_FAILURE otherwise.
//! \note This API is only supported for Gen9 and plus platform.
//!
CM_RT_API virtual int32_t
SelectMemoryObjectControlSetting(MEMORY_OBJECT_CONTROL memCtrl) = 0;
//!
//! \brief Sets the surface state of this buffer.
//! \details Set the new size, offset, and mocs to the surface index,
//! so they will take effect during surface state setting.
//! Usually, the surface index is an alias surface index created
//! by calling CmDevice::CreateBufferAlias. This function can be used to
//! reinterpret the size, offset, and mocs of an existing CmBuffer.
//! \param [in] surfIndex
//! Pointer to surface index of this buffer.
//! \param [in] bufferStateParam
//! The surface state parameter of this buffer. It contains
//! size, base address offset and memory object control setting. The
//! offset must be 16-aligned due to hardware requirement.
//! \retval CM_SUCCESS if the surface state is set successfully.
//! \retval CM_INVALID_ARG_VALUE if the surface state parameter is
//! invalid.
//! \retval CM_NULL_POINTER if any internal used pointer is nullptr.
//! \retval CM_FAILURE otherwise.
//!
CM_RT_API virtual int32_t
SetSurfaceStateParam(SurfaceIndex *surfIndex,
const CM_BUFFER_STATE_PARAM *bufferStateParam) = 0;
};
};//namespace
#endif // #ifndef MEDIADRIVER_AGNOSTIC_COMMON_CM_CMBUFFER_H_
|