1 /*
2  * Copyright (C) 2020-2021 Intel Corporation
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  */
7 
8 #pragma once
9 #include "shared/source/command_stream/command_stream_receiver.h"
10 #include "shared/source/command_stream/scratch_space_controller.h"
11 #include "shared/source/command_stream/submissions_aggregator.h"
12 #include "shared/source/helpers/constants.h"
13 #include "shared/source/memory_manager/graphics_allocation.h"
14 #include "shared/source/memory_manager/residency_container.h"
15 
16 #include "level_zero/core/source/cmdqueue/cmdqueue_imp.h"
17 
18 #include "igfxfmid.h"
19 
20 namespace L0 {
21 
22 template <GFXCORE_FAMILY gfxCoreFamily>
23 struct CommandQueueHw : public CommandQueueImp {
24     using CommandQueueImp::CommandQueueImp;
25     using GfxFamily = typename NEO::GfxFamilyMapper<gfxCoreFamily>::GfxFamily;
26 
27     ze_result_t createFence(const ze_fence_desc_t *desc, ze_fence_handle_t *phFence) override;
28     ze_result_t destroy() override;
29     ze_result_t executeCommandLists(uint32_t numCommandLists,
30                                     ze_command_list_handle_t *phCommandLists,
31                                     ze_fence_handle_t hFence, bool performMigration) override;
32     ze_result_t executeCommands(uint32_t numCommands,
33                                 void *phCommands,
34                                 ze_fence_handle_t hFence) override;
35 
36     void dispatchTaskCountWrite(NEO::LinearStream &commandStream, bool flushDataCache) override;
37 
38     void programStateBaseAddress(uint64_t gsba, bool useLocalMemoryForIndirectHeap, NEO::LinearStream &commandStream, bool cachedMOCSAllowed);
39     size_t estimateStateBaseAddressCmdSize();
40     MOCKABLE_VIRTUAL void programFrontEnd(uint64_t scratchAddress, uint32_t perThreadScratchSpaceSize, NEO::LinearStream &commandStream);
41 
42     MOCKABLE_VIRTUAL size_t estimateFrontEndCmdSizeForMultipleCommandLists(bool isFrontEndStateDirty, uint32_t numCommandLists,
43                                                                            ze_command_list_handle_t *phCommandLists);
44     size_t estimateFrontEndCmdSize();
45     size_t estimatePipelineSelect();
46     void programPipelineSelect(NEO::LinearStream &commandStream);
47 
48     MOCKABLE_VIRTUAL void handleScratchSpace(NEO::HeapContainer &heapContainer,
49                                              NEO::ScratchSpaceController *scratchController,
50                                              bool &gsbaState, bool &frontEndState,
51                                              uint32_t perThreadScratchSpaceSize,
52                                              uint32_t perThreadPrivateScratchSize);
53 
54     bool getPreemptionCmdProgramming() override;
55     void patchCommands(CommandList &commandList, uint64_t scratchAddress);
56 };
57 
58 } // namespace L0
59