xref: /aosp_15_r20/external/intel-media-driver/media_driver/agnostic/common/cm/cm_ssh.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2018, 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_ssh.h
24 //! \brief     Contains Class CmSSH  definitions
25 //!
26 #pragma once
27 
28 #include "cm_surface_state.h"
29 #include <bitset>
30 
31 class CmKernelEx;
32 class CmScratchSpace;
33 class CmSSH
34 {
35 public:
36     CmSSH(CM_HAL_STATE *cmhal, PMOS_COMMAND_BUFFER cmdBuf);
37     ~CmSSH();
38     MOS_STATUS Initialize(CmKernelEx **kernels = nullptr, uint32_t count = 0);
39 
40     int AssignBindingTable();
41 
42     int GetBindingTableOffset(int btIndex = -1);
43 
44     virtual int AddSurfaceState(CmSurfaceState *surfState, int bteIndex = -1, int btIndex = -1);
45 
46     int AddScratchSpace(CmScratchSpace *scratch);
47 
48     MOS_STATUS PrepareResourcesForCp();
49 
50     static void DumpSSH(CM_HAL_STATE *cmhal, PMOS_COMMAND_BUFFER cmdBuf); // to dump legacy path
51 
52     void DumpSSH();
53 
54 protected:
55     int GetFreeBindingTableEntries(int surfNum, int btIndex = -1);
56     int GetFreeSurfStateIndex(int surfNum);
57     int EstimateBTSize(int maxBteNum, std::map<int, CmSurfaceState *> &reservedBteIndex);
58 
59 private:
60     struct _BteFlag
61     {
62         std::bitset<256> _map;
63 
Set_BteFlag64         inline void Set(int start, int count)
65         {
66             uint64_t mask = 0xffffffff >> (32-count);
67             std::bitset<256> temp(mask);
68             temp <<= start;
69             _map |= temp;
70         }
71 
IsSet_BteFlag72         inline bool IsSet(int start, int count)
73         {
74             uint64_t mask = 0xffffffff >> (32-count);
75             std::bitset<256> temp(mask);
76             temp <<= start;
77             temp &= _map;
78             return temp.any();
79         }
80 
81     };
82 
83     // SSH buffer
84     uint8_t *m_stateBase;
85     uint32_t m_stateOffset;
86     uint32_t m_length;
87     uint32_t m_btStart; // start of binding tables
88     uint32_t m_ssStart; // start of surface states
89     uint32_t m_bteNum;
90     uint32_t m_btStartPerKernel[CM_MAX_KERNELS_PER_TASK + 1]; // start of each bt, the last one means the end of last BT
91     uint32_t m_maxSsNum;
92     uint32_t m_btEntrySize; // size of each binding table entry
93     uint32_t m_ssCmdSize; // size of each Surface state cmd
94 
95     // current ssh is in the end of a command buffer
96     PMOS_COMMAND_BUFFER m_cmdBuf;
97 
98     // Current BT
99     uint32_t m_curBTIndex;
100     uint32_t m_curBteIndexes[CM_MAX_KERNELS_PER_TASK];
101     uint32_t m_normalBteStart;
102 
103     // Surface States added in the ssh
104     CmSurfaceState *m_surfStatesInSsh[CM_MAX_SURFACE_STATES];
105 
106     // Current Surface State
107     uint32_t m_curSsIndex;
108 
109     CM_HAL_STATE *m_cmhal;
110     RENDERHAL_INTERFACE *m_renderhal;
111 
112     // All MOS_RESOURCE added in the ssh
113     MOS_RESOURCE *m_resourcesAdded[CM_MAX_SURFACE_STATES];
114     uint32_t m_resCount;
115 
116     // Occupied BteIndexes
117     _BteFlag *m_occupiedBteIndexes; // maximun 64x4 = 256 entries for each BT
118 };
119