| 1 |
/* |
| 2 |
* Copyright (c) 2017, Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included |
| 12 |
* in all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
//! |
| 23 |
//! \file cm_buffer_rt.h |
| 24 |
//! \brief Declaration of CmBuffer_RT. |
| 25 |
//! |
| 26 |
|
| 27 |
#ifndef MEDIADRIVER_AGNOSTIC_COMMON_CM_CMBUFFERRT_H_ |
| 28 |
#define MEDIADRIVER_AGNOSTIC_COMMON_CM_CMBUFFERRT_H_ |
| 29 |
|
| 30 |
#include "cm_buffer.h" |
| 31 |
#include "cm_surface.h" |
| 32 |
|
| 33 |
namespace CMRT_UMD |
| 34 |
{ |
| 35 |
class CmBuffer_RT: public CmBuffer, |
| 36 |
public CmBufferUP, |
| 37 |
public CmBufferSVM, |
| 38 |
public CmSurface, |
| 39 |
public CmBufferStateless |
| 40 |
{ |
| 41 |
public: |
| 42 |
static int32_t Create(uint32_t index, |
| 43 |
uint32_t handle, |
| 44 |
size_t size, |
| 45 |
bool isCmCreated, |
| 46 |
CmSurfaceManager *surfaceManager, |
| 47 |
uint32_t bufferType, |
| 48 |
bool isCMRTAllocatedSVM, |
| 49 |
void *sysMem, |
| 50 |
CmBuffer_RT* &surface, |
| 51 |
bool isConditionalBuffer, |
| 52 |
uint32_t comparisonValue, |
| 53 |
uint64_t gfxMem, |
| 54 |
bool enableCompareMask = false); |
| 55 |
|
| 56 |
CM_RT_API int32_t ReadSurface(unsigned char* sysMem, |
| 57 |
CmEvent* event, |
| 58 |
uint64_t sysMemSize = 0xFFFFFFFFFFFFFFFFULL); |
| 59 |
|
| 60 |
CM_RT_API int32_t WriteSurface(const unsigned char* sysMem, |
| 61 |
CmEvent* event, |
| 62 |
uint64_t sysMemSize = 0xFFFFFFFFFFFFFFFFULL); |
| 63 |
|
| 64 |
|
| 65 |
int32_t ReadBuffer(unsigned char* sysMem, |
| 66 |
CmEvent* event, |
| 67 |
uint64_t sysMemSize = 0xFFFFFFFFFFFFFFFFULL, |
| 68 |
size_t offset = 0); |
| 69 |
|
| 70 |
int32_t WriteBuffer(const unsigned char* sysMem, |
| 71 |
CmEvent* event, |
| 72 |
uint64_t sysMemSize = 0xFFFFFFFFFFFFFFFFULL, |
| 73 |
size_t offset = 0); |
| 74 |
|
| 75 |
CM_RT_API int32_t InitSurface(const uint32_t initValue, CmEvent *event); |
| 76 |
|
| 77 |
CM_RT_API int32_t GetIndex(SurfaceIndex *&index); |
| 78 |
|
| 79 |
virtual int32_t GetHandle(uint32_t &handle); |
| 80 |
|
| 81 |
//NOT depend on RTTI::dynamic_cast |
| 82 |
CM_RT_API CM_ENUM_CLASS_TYPE Type() const |
| 83 |
{ return CM_ENUM_CLASS_TYPE_CMBUFFER_RT; }; |
| 84 |
|
| 85 |
int32_t SetMemoryObjectControl(MEMORY_OBJECT_CONTROL memCtrl, |
| 86 |
MEMORY_TYPE memType, |
| 87 |
uint32_t age); |
| 88 |
|
| 89 |
CM_RT_API int32_t |
| 90 |
SelectMemoryObjectControlSetting(MEMORY_OBJECT_CONTROL memCtrl); |
| 91 |
|
| 92 |
CMRT_UMD_API int32_t |
| 93 |
SetResourceUsage(const MOS_HW_RESOURCE_DEF mosUsage); |
| 94 |
|
| 95 |
CM_RT_API int32_t GetAddress(void* &addr); |
| 96 |
|
| 97 |
CM_RT_API int32_t |
| 98 |
SetSurfaceStateParam(SurfaceIndex *surfIndex, |
| 99 |
const CM_BUFFER_STATE_PARAM *bufferStateParam); |
| 100 |
|
| 101 |
CM_RT_API int32_t GetGfxAddress(uint64_t &gfxAddr); |
| 102 |
|
| 103 |
CM_RT_API int32_t GetSysAddress(void* &sysAddr); |
| 104 |
|
| 105 |
virtual int32_t UpdateResource(MOS_RESOURCE *resource); |
| 106 |
|
| 107 |
size_t GetSize() { return m_size; } |
| 108 |
|
| 109 |
void SetSize(size_t size); |
| 110 |
|
| 111 |
bool IsUpSurface(); |
| 112 |
|
| 113 |
bool IsSVMSurface(); |
| 114 |
|
| 115 |
virtual bool IsCMRTAllocatedSVMBuffer(); |
| 116 |
|
| 117 |
bool IsConditionalSurface(); |
| 118 |
|
| 119 |
uint32_t GetConditionalCompareValue(); |
| 120 |
|
| 121 |
bool IsCompareMaskEnabled(); |
| 122 |
|
| 123 |
uint32_t GetBufferType() { return m_bufferType; } |
| 124 |
|
| 125 |
virtual int32_t CreateBufferAlias(SurfaceIndex *&aliasSurfIndex); |
| 126 |
|
| 127 |
virtual int32_t GetNumAliases(uint32_t &numAliases); |
| 128 |
|
| 129 |
void Log(std::ostringstream &oss); |
| 130 |
|
| 131 |
void DumpContent(uint32_t kernelNumber, |
| 132 |
char *kernelName, |
| 133 |
int32_t taskId, |
| 134 |
uint32_t argIndex, |
| 135 |
uint32_t vectorIndex); |
| 136 |
|
| 137 |
virtual int32_t UpdateProperty(uint32_t size); |
| 138 |
|
| 139 |
protected: |
| 140 |
CmBuffer_RT(uint32_t handle, |
| 141 |
size_t size, |
| 142 |
bool isCmCreated, |
| 143 |
CmSurfaceManager *surfaceManager, |
| 144 |
uint32_t bufferType, |
| 145 |
bool isCMRTAllocatedSVM, |
| 146 |
void *sysMem, |
| 147 |
bool isConditionalBuffer, |
| 148 |
uint32_t comparisonValue, |
| 149 |
uint64_t gfxAddr, |
| 150 |
bool enableCompareMask = false); |
| 151 |
|
| 152 |
~CmBuffer_RT(); |
| 153 |
|
| 154 |
int32_t Initialize(uint32_t index); |
| 155 |
|
| 156 |
uint32_t m_handle; |
| 157 |
|
| 158 |
size_t m_size; |
| 159 |
|
| 160 |
uint32_t m_bufferType; // SURFACE_TYPE_BUFFER, SURFACE_TYPE_BUFFER_UP, |
| 161 |
// SURFACE_TYPE_BUFFER_SVM |
| 162 |
|
| 163 |
void *m_sysMem; // start address of BufferUP/BufferSVM/BufferStatelss in CPU memory space |
| 164 |
uint64_t m_gfxMem; // start address of buffer in graphics memory space |
| 165 |
|
| 166 |
bool m_isCMRTAllocatedSVMBuffer; //0--User provided SVM buffer, 1--CMRT allocated SVM buffer |
| 167 |
|
| 168 |
bool m_isConditionalBuffer; |
| 169 |
|
| 170 |
uint32_t m_comparisonValue; // value used for conditional batch buffer end |
| 171 |
|
| 172 |
bool m_enableCompareMask; |
| 173 |
|
| 174 |
uint32_t m_numAliases; // number of alias indexes |
| 175 |
|
| 176 |
SurfaceIndex *m_aliasIndexes[CM_HAL_MAX_NUM_BUFFER_ALIASES]; |
| 177 |
|
| 178 |
private: |
| 179 |
CmBuffer_RT(const CmBuffer_RT& other); |
| 180 |
CmBuffer_RT& operator=(const CmBuffer_RT& other); |
| 181 |
}; |
| 182 |
}; |
| 183 |
|
| 184 |
#endif // #ifndef MEDIADRIVER_AGNOSTIC_COMMON_CM_CMBUFFERRT_H_ |