xref: /aosp_15_r20/external/intel-media-driver/media_driver/agnostic/common/cm/cm_media_state.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_hal.h"
29 #include "heap_manager.h"
30 #include <list>
31 
32 class CmKernelEx;
33 namespace CMRT_UMD
34 {
35 class CmThreadGroupSpace;
36 };
37 
38 class CmMediaState
39 {
40 public:
41     CmMediaState(CM_HAL_STATE *cmhal);
42     ~CmMediaState();
43 
44     MOS_STATUS Initialize(HeapManager *heapMgr);
45 
46     MOS_STATUS Allocate(CmKernelEx **kernels, int count, uint32_t trackerIndex, uint32_t trackerID);
47 
GetHeapResource()48     inline MOS_RESOURCE* GetHeapResource() {return m_memoryBlock.GetResource(); }
49 
GetCurbeOffset()50     inline uint32_t GetCurbeOffset() {return m_curbeOffsetInternal + m_memoryBlock.GetOffset();}
51 
GetCurbeOffset(uint32_t kernelIndex)52     inline uint32_t GetCurbeOffset(uint32_t kernelIndex) {return m_curbeOffsets[kernelIndex] + m_curbeOffsetInternal + m_memoryBlock.GetOffset();}
53 
GetMediaIDOffset()54     inline uint32_t GetMediaIDOffset() {return m_mediaIDOffsetInternal + m_memoryBlock.GetOffset();}
55 
GetHeapSize()56     inline uint32_t GetHeapSize() {return m_memoryBlock.GetHeapSize(); }
57 
GetCurbeSize()58     inline uint32_t GetCurbeSize() {return m_totalCurbeSize; }
59 
GetMediaIDSize()60     inline uint32_t GetMediaIDSize() {return m_totalMediaIDSize;}
61 
GetSamplerHeapOffset(uint32_t kernelIndex)62     inline uint32_t GetSamplerHeapOffset(uint32_t kernelIndex) {return m_samplerOffsets[kernelIndex] + m_samplerHeapOffsetInternal + m_memoryBlock.GetOffset();}
63 
GetSamplerCount(uint32_t kernelIndex)64     inline uint32_t GetSamplerCount(uint32_t kernelIndex) {return m_samplerCount[kernelIndex]; }
65 
GetScratchSizePerThread()66     inline uint32_t GetScratchSizePerThread() {return m_scratchSizePerThread; }
67 
GetScratchSpaceOffset()68     inline uint32_t GetScratchSpaceOffset() {return m_scratchSpaceOffsetExternal; }
69 
70     MOS_STATUS LoadCurbe(CmKernelEx *kernel, int index);
71 
72     MOS_STATUS LoadCurbe(uint8_t *curbe, uint32_t size, int index);
73 
74     MOS_STATUS LoadMediaID(CmKernelEx *kernel, int index, uint32_t btOffset, CMRT_UMD::CmThreadGroupSpace *threadGroupSpace = nullptr);
75 
76     int AddSampler(void *samplerParam, int index, int bteIndex = -1);
77 
78     MOS_STATUS Submit();
79 
80     void Dump();
81 
82 protected:
83 
84     MOS_STATUS PrepareMemoryBlock(uint32_t size, uint32_t trackerIndex, uint32_t trackerID);
85 
86     uint32_t UpdateHeapSizeAndOffsets(CmKernelEx *kernel, uint32_t kernelIdx);
87 
88     enum _BlockState
89     {
90         _Empty,
91         _Allocated,
92         _Submitted
93     };
94 
95     CM_HAL_STATE *m_cmhal;
96     HeapManager *m_heapMgr;
97 
98     MemoryBlock m_memoryBlock;
99 
100     uint32_t m_curbeOffsetInternal;
101     uint32_t m_mediaIDOffsetInternal;
102     uint32_t m_samplerHeapOffsetInternal;
103     uint32_t m_scratchSpaceOffsetExternal;
104 
105     uint32_t m_totalCurbeSize;
106     uint32_t m_totalMediaIDSize;
107     uint32_t m_totalSamplerHeapSize;
108     uint32_t m_totalScratchSpaceSize;
109 
110     uint32_t m_curbeOffsets[CM_MAX_KERNELS_PER_TASK];
111     uint32_t m_samplerOffsets[CM_MAX_KERNELS_PER_TASK];
112     uint32_t m_next3dSamplerOffsets[CM_MAX_KERNELS_PER_TASK];
113     uint32_t m_nextAvsSamplerOffsets[CM_MAX_KERNELS_PER_TASK];
114     uint32_t m_nextIndStateOffsets[CM_MAX_KERNELS_PER_TASK];
115     uint32_t m_samplerCount[CM_MAX_KERNELS_PER_TASK];
116     uint32_t m_mediaIDSize;
117     uint32_t m_scratchSizePerThread;
118 
119     _BlockState m_state;
120 
121     const uint32_t m_3dSamplerElementSize = 16;
122     const uint32_t m_avsSamplerElementSize = 2048;
123 
124 };
125