• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_command_buffer.h
24 //! \brief     Contains Class CmCommandBuffer  definitions
25 //!
26 #pragma once
27 
28 #include "cm_hal.h"
29 #include "mos_os_specific.h"
30 
31 class CmISH;
32 class CmMediaState;
33 class CmSSH;
34 class CmKernelEx;
35 namespace CMRT_UMD
36 {
37 class CmThreadSpaceRT;
38 class CmThreadGroupSpace;
39 };
40 
41 template <typename T1, typename T2>
NonZeroMin(T1 a,T2 b)42 static inline T1 NonZeroMin(T1 a, T2 b)
43 {
44  return (a == 0) ? b : MOS_MIN(a, b);
45 }
46 
47 class CmCommandBuffer
48 {
49 public:
50     CmCommandBuffer(CM_HAL_STATE *cmhal);
51     virtual ~CmCommandBuffer();
52 
53     MOS_STATUS AddFrameTracker(MOS_RESOURCE *resource, uint32_t offset, uint32_t tag);
54 
55     //--------------------------------------------------------------------------------
56     // Adds a PIPE_CONTROL command to flush cache. It's also used to synchronize tasks in a CmQueue (GPU context).
57     // Task synchronization is only needed on certain platforms. In most cases, this PIPE_CONTROL command is used for flushing cache exclusively.
58     //--------------------------------------------------------------------------------
59     MOS_STATUS AddFlushCacheAndSyncTask(bool isRead,
60                                         bool rtCache,
61                                         MOS_RESOURCE *syncBuffer);
62 
63     MOS_STATUS AddReadTimeStamp(MOS_RESOURCE *resource, uint32_t offset, bool isRead = false);
64     MOS_STATUS AddL3CacheConfig(L3ConfigRegisterValues *l3values);
65     MOS_STATUS AddPipelineSelect(bool gpgpu = false);
66     MOS_STATUS AddStateBaseAddress(CmISH *ish, CmMediaState *mediaState);
67     MOS_STATUS AddMediaVFE(CmMediaState *mediaState, bool fusedEuDispatch = false, CMRT_UMD::CmThreadSpaceRT **threadSpaces = nullptr, uint32_t count = 0);
68     MOS_STATUS AddCurbeLoad(CmMediaState *mediaState);
69     MOS_STATUS AddMediaIDLoad(CmMediaState *mediaState);
70 
71     //--------------------------------------------------------------------------------
72     // Adds a PIPE_CONTROL command for synchronization between kernels in a batch.
73     //--------------------------------------------------------------------------------
74     MOS_STATUS AddSyncBetweenKernels();
75 
76     MOS_STATUS AddMediaObjectWalker(CMRT_UMD::CmThreadSpaceRT *threadSpace, uint32_t mediaID);
77     MOS_STATUS AddDummyVFE();
78     MOS_STATUS AddBatchBufferEnd();
79     MOS_STATUS AddMMCProlog();
80     MOS_STATUS AddProtectedProlog();
81     MOS_STATUS AddConditionalBatchBufferEnd(CM_HAL_CONDITIONAL_BB_END_INFO *cbbInfo);
82     MOS_STATUS AddConditionalFrameTracker(MOS_RESOURCE *resource, uint32_t offset, uint32_t tag, CM_HAL_CONDITIONAL_BB_END_INFO *cbbInfo);
83     virtual MOS_STATUS AddPowerOption(CM_POWER_OPTION *option);
84 
85     //UMD profiler related
86     MOS_STATUS AddUmdProfilerStart();
87     MOS_STATUS AddUmdProfilerEnd();
88 
89     //GPGPU walker specific
90     MOS_STATUS AddPreemptionConfig(bool isGpgpu);
91     MOS_STATUS AddSipState(uint32_t sipKernelOffset);
92     MOS_STATUS AddCsrBaseAddress(MOS_RESOURCE *resource);
93     MOS_STATUS AddGpgpuWalker(CMRT_UMD::CmThreadGroupSpace *threadGroupSpace,
94                                     CmKernelEx *kernel,
95                                     uint32_t mediaID);
96 
97     void ReturnUnusedBuffer();
98     void ReturnWholeBuffer();
99 
100     MOS_STATUS Submit();
101 
102     MOS_STATUS Initialize();
103 
104     CmSSH* GetSSH();
105 
106     void Dump();
107 
GetResource()108     inline MOS_RESOURCE *GetResource() {return &m_cmdBuf.OsResource; }
109 
110 protected:
111 
112     CM_HAL_STATE *m_cmhal;
113     MOS_INTERFACE *m_osInterface;
114     PMHW_MI_INTERFACE m_miInterface;
115     MhwRenderInterface *m_hwRender;
116     MOS_COMMAND_BUFFER m_cmdBuf;
117     CmSSH *m_ssh;
118 
119     uint8_t m_masks[16];
120 
121     int m_origRemain;
122 };
123