Debian Codegraph @

media_driver/agnostic/common/cm/cm_surface_state_manager.h

raw
1 /*
2 * Copyright (c) 2018-2019, 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_state_manager.h
24 //! \brief Contains Class CmSurfaceStateMgr definitions
25 //!
26 #pragma once
27
28 #include "cm_def.h"
29 #include "cm_hal.h"
30 #include "cm_device_rt.h"
31 #include <unordered_map>
32
33 class CmSurfaceState2Dor3D;
34 class CmSurfaceStateBuffer;
35 class CmSurfaceState;
36
37 #define UPDATE_IF_DIFFERENT(src, value) \
38 if(src != value) \
39 { \
40 src = value; \
41 m_dirty = true; \
42 }
43
44 class CmSurfaceState2Dor3DMgr
45 {
46 public:
47 CmSurfaceState2Dor3DMgr(CM_HAL_STATE *cmhal, MOS_RESOURCE *resource);
48 virtual ~CmSurfaceState2Dor3DMgr();
49
50 CmSurfaceState* GetSurfaceState(int isAvs = 0, int isSampler = 0, CM_HAL_SURFACE2D_SURFACE_STATE_PARAM *param = nullptr);
51 void SetRotationFlag(uint32_t rotation);
52 void SetChromaSitting(uint8_t chromaSitting);
53 inline void SetMemoryObjectControl(uint16_t moc) { UPDATE_IF_DIFFERENT(m_defaultMoc, moc); }
54 inline void SetRenderTarget(bool flag) { UPDATE_IF_DIFFERENT(m_defaultRenderTarget, flag); }
55 inline void SetFrameType(CM_FRAME_TYPE frameType) { UPDATE_IF_DIFFERENT(m_defaultFrameType, frameType); }
56 inline void SetOrigFormat(MOS_FORMAT format) { UPDATE_IF_DIFFERENT(m_defaultFormat, format);}
57 inline void SetOrigDimension(uint32_t width, uint32_t height, uint32_t depth)
58 {
59 UPDATE_IF_DIFFERENT(m_defaultWidth, width);
60 UPDATE_IF_DIFFERENT(m_defaultHeight, height);
61 UPDATE_IF_DIFFERENT(m_defaultDepth, depth);
62 }
63 inline MOS_RESOURCE* GetResource()
64 {
65 if (m_resource == nullptr)
66 return nullptr;
67 m_resourceData = *m_resource;
68 return &m_resourceData;
69 }
70 protected:
71 enum _SurfaceStateType
72 {
73 _RENDER_SURFACE = 0,
74 _3D_SAMPLER_SURFACE = 1,
75 _VME_SURFACE = 2,
76 _AVS_SAMPLER_SURFACE = 3
77 };
78 uint32_t Hash(CM_HAL_SURFACE2D_SURFACE_STATE_PARAM *param);
79 void clean();
80 CmSurfaceState2Dor3D *m_defaultSurfState[4];
81 std::map<uint32_t, CmSurfaceState2Dor3D *> m_surfStateMap[4];
82
83 CM_HAL_STATE *m_cmhal;
84 MOS_RESOURCE *m_resource;
85 MOS_RESOURCE m_resourceData;
86
87 // default configs
88 uint16_t m_defaultMoc;
89 bool m_defaultRenderTarget;
90 CM_FRAME_TYPE m_defaultFrameType;
91 MOS_FORMAT m_defaultFormat;
92 uint32_t m_defaultWidth;
93 uint32_t m_defaultHeight;
94 uint32_t m_defaultDepth;
95
96 // sampler settings
97 uint32_t m_rotationFlag;
98 uint8_t m_chromaSitting;
99
100 // indicate whether default configs change
101 bool m_dirty;
102 };
103
104 class CmSurfaceStateBufferMgr
105 {
106 public:
107 CmSurfaceStateBufferMgr(CM_HAL_STATE *cmhal, MOS_RESOURCE *resource);
108 ~CmSurfaceStateBufferMgr();
109 virtual CmSurfaceState* GetSurfaceState(CM_HAL_BUFFER_SURFACE_STATE_ENTRY *param = nullptr);
110 inline void SetOrigSize(uint32_t size) {m_origSize = size; }
111 inline void SetMemoryObjectControl(uint16_t moc) {UPDATE_IF_DIFFERENT(m_defaultMoc, moc); }
112 protected:
113 uint32_t Hash(CM_HAL_BUFFER_SURFACE_STATE_ENTRY *param);
114 void clean();
115 CmSurfaceStateBuffer *m_defaultSurfState;
116 std::map<uint32_t, CmSurfaceStateBuffer *> m_surfStateMap;
117
118 CM_HAL_STATE *m_cmhal;
119 MOS_RESOURCE *m_resource;
120
121 // default configs
122 uint32_t m_origSize;
123 uint16_t m_defaultMoc;
124
125 // indicate whether default configs change
126 bool m_dirty;
127 };
128
129 class CmSurfaceState3DMgr: public CmSurfaceState2Dor3DMgr
130 {
131 public:
132 CmSurfaceState3DMgr(CM_HAL_STATE *cmhal, MOS_RESOURCE *resource);
133 ~CmSurfaceState3DMgr() {}
134 protected:
135 MOS_RESOURCE m_resourceFor3d;
136 };
137