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_surface_sampler8x8.cpp
24 //! \brief Contains Class CmSurfaceSampler8x8 definitions
25 //!
26
27 #include "cm_surface_sampler8x8.h"
28
29 #include "cm_debug.h"
30 #include "cm_surface_manager.h"
31 #include "cm_device_rt.h"
32 #include "cm_hal.h"
33
34 namespace CMRT_UMD
35 {
36 //*-----------------------------------------------------------------------------
37 //| Purpose: Create CmSurfaceSampler8x8
38 //| Returns: Result of the operation.
39 //*-----------------------------------------------------------------------------
Create(uint32_t index,uint32_t indexFor2D,uint32_t cmIndex,CmSurfaceManager * surfaceManager,CmSurfaceSampler8x8 * & surface,CM_SAMPLER8x8_SURFACE sampler8x8Type,CM_SURFACE_ADDRESS_CONTROL_MODE mode,CM_FLAG * flag)40 int32_t CmSurfaceSampler8x8::Create(
41 uint32_t index,
42 uint32_t indexFor2D, //indexing resource array of HalCm
43 uint32_t cmIndex, //SurfaceIndex's ID for 2D, also indexing surface array in cmrt@umd
44 CmSurfaceManager* surfaceManager,
45 CmSurfaceSampler8x8* &surface,
46 CM_SAMPLER8x8_SURFACE sampler8x8Type,
47 CM_SURFACE_ADDRESS_CONTROL_MODE mode,
48 CM_FLAG* flag)
49 {
50 int32_t result = CM_SUCCESS;
51
52 surface = new ( std::nothrow ) CmSurfaceSampler8x8( cmIndex, indexFor2D, surfaceManager, sampler8x8Type, mode, flag);
53 if ( surface )
54 {
55 result = surface->Initialize( index );
56 if( result != CM_SUCCESS )
57 {
58 CmSurface* baseSurface = surface;
59 CmSurface::Destroy( baseSurface );
60 }
61 }
62 else
63 {
64 CM_ASSERTMESSAGE("Error: Failed to create CmSurfaceSampler8x8 due to out of system memory.");
65 result = CM_OUT_OF_HOST_MEMORY;
66 }
67
68 return result;
69
70 }
71
72 // Constructor of CmSurfaceSampler8x8
CmSurfaceSampler8x8(uint32_t cmIndex,uint32_t indexFor2D,CmSurfaceManager * surfaceManager,CM_SAMPLER8x8_SURFACE sampler8x8Type,CM_SURFACE_ADDRESS_CONTROL_MODE mode,CM_FLAG * flag)73 CmSurfaceSampler8x8::CmSurfaceSampler8x8(
74 uint32_t cmIndex, //SurfaceIndex's ID for 2D, also indexing surface array in cmrt@umd
75 uint32_t indexFor2D,
76 CmSurfaceManager* surfaceManager,
77 CM_SAMPLER8x8_SURFACE sampler8x8Type,
78 CM_SURFACE_ADDRESS_CONTROL_MODE mode,
79 CM_FLAG* flag) :
80 CmSurface(surfaceManager, false ),
81 m_indexFor2D( indexFor2D ),
82 m_surfaceIndex(cmIndex),
83 m_sampler8x8Type( sampler8x8Type ),
84 m_nAddressMode( mode )
85 {
86 if (flag != nullptr)
87 {
88 m_flag.rotationFlag = flag->rotationFlag;
89 m_flag.chromaSiting = flag->chromaSiting;
90 }
91 }
92
93 // Destructor of CmSurfaceSampler8x8
~CmSurfaceSampler8x8(void)94 CmSurfaceSampler8x8::~CmSurfaceSampler8x8( void )
95 {
96 }
97
98 //*-----------------------------------------------------------------------------
99 //| Purpose: Initialize CmSurfaceSampler8x8
100 //| Returns: Result of the operation.
101 //*-----------------------------------------------------------------------------
Initialize(uint32_t index)102 int32_t CmSurfaceSampler8x8::Initialize( uint32_t index )
103 {
104 CmSurfaceManager* surfMgr = m_surfaceMgr;
105
106 surfMgr->UpdateSurface2DTableRotation(m_indexFor2D, m_flag.rotationFlag);
107 surfMgr->UpdateSurface2DTableChromaSiting(m_indexFor2D, m_flag.chromaSiting);
108
109 return CmSurface::Initialize( index );
110 }
111
112 //*-----------------------------------------------------------------------------
113 //| Purpose: Get the index of CmSurfaceSampler8x8
114 //| Returns: Result of the operation.
115 //*-----------------------------------------------------------------------------
GetIndex(SurfaceIndex * & index)116 int32_t CmSurfaceSampler8x8::GetIndex( SurfaceIndex*& index )
117 {
118 index = m_index;
119 return CM_SUCCESS;
120 }
121
122 //*-----------------------------------------------------------------------------
123 //| Purpose: Get the current index of CmSurfaceSampler8x8
124 //| Returns: Result of the operation.
125 //*-----------------------------------------------------------------------------
GetIndexCurrent(uint32_t & index)126 int32_t CmSurfaceSampler8x8::GetIndexCurrent( uint32_t& index )
127 {
128 index = m_indexFor2D;
129 return CM_SUCCESS;
130 }
131
GetCmIndex(uint16_t & index)132 int32_t CmSurfaceSampler8x8::GetCmIndex( uint16_t& index )
133 {
134 index = (uint16_t)m_surfaceIndex;
135 return CM_SUCCESS;
136 }
137
GetSampler8x8SurfaceType()138 CM_SAMPLER8x8_SURFACE CmSurfaceSampler8x8::GetSampler8x8SurfaceType()
139 {
140 return m_sampler8x8Type;
141 }
142
GetAddressControlMode()143 CM_SURFACE_ADDRESS_CONTROL_MODE CmSurfaceSampler8x8::GetAddressControlMode()
144 {
145 return m_nAddressMode;
146 }
147
SetMemoryObjectControl(MEMORY_OBJECT_CONTROL memCtrl,MEMORY_TYPE memType,uint32_t age)148 int32_t CmSurfaceSampler8x8::SetMemoryObjectControl(MEMORY_OBJECT_CONTROL memCtrl, MEMORY_TYPE memType, uint32_t age)
149 {
150 CM_RETURN_CODE hr = CM_SUCCESS;
151 uint16_t mocs = 0;
152
153 CmSurface::SetMemoryObjectControl( memCtrl, memType, age );
154
155 CmDeviceRT *cmDevice = nullptr;
156 m_surfaceMgr->GetCmDevice(cmDevice);
157 CM_CHK_NULL_RETURN_CMERROR(cmDevice);
158 PCM_CONTEXT_DATA cmData = (PCM_CONTEXT_DATA)cmDevice->GetAccelData();
159 CM_CHK_NULL_RETURN_CMERROR(cmData);
160 CM_CHK_NULL_RETURN_CMERROR(cmData->cmHalState);
161
162 mocs = (m_memObjCtrl.mem_ctrl << 8) | (m_memObjCtrl.mem_type<<4) | m_memObjCtrl.age;
163
164 CM_ARG_KIND argType;
165
166 if (m_sampler8x8Type == CM_VA_SURFACE)
167 {
168 argType = ARG_KIND_SURFACE_SAMPLER8X8_VA;
169 }
170 else
171 {
172 argType = ARG_KIND_SURFACE_SAMPLER8X8_AVS;
173 }
174
175 CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmData->cmHalState->pfnSetSurfaceMOCS(cmData->cmHalState, m_indexFor2D, mocs, argType));
176
177 finish:
178 return hr;
179 }
180 }
181