• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Dawn Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef DAWNNATIVE_D3D12_COMMANDALLOCATORMANAGER_H_
16 #define DAWNNATIVE_D3D12_COMMANDALLOCATORMANAGER_H_
17 
18 #include "dawn_native/d3d12/d3d12_platform.h"
19 
20 #include "common/SerialQueue.h"
21 #include "dawn_native/Error.h"
22 #include "dawn_native/IntegerTypes.h"
23 
24 #include <bitset>
25 
26 namespace dawn_native { namespace d3d12 {
27 
28     class Device;
29 
30     class CommandAllocatorManager {
31       public:
32         CommandAllocatorManager(Device* device);
33 
34         // A CommandAllocator that is reserved must be used on the next ExecuteCommandLists
35         // otherwise its commands may be reset before execution has completed on the GPU
36         ResultOrError<ID3D12CommandAllocator*> ReserveCommandAllocator();
37         MaybeError Tick(ExecutionSerial lastCompletedSerial);
38 
39       private:
40         Device* device;
41 
42         // This must be at least 2 because the Device and Queue use separate command allocators
43         static constexpr unsigned int kMaxCommandAllocators = 32;
44         unsigned int mAllocatorCount;
45 
46         struct IndexedCommandAllocator {
47             ComPtr<ID3D12CommandAllocator> commandAllocator;
48             unsigned int index;
49         };
50 
51         ComPtr<ID3D12CommandAllocator> mCommandAllocators[kMaxCommandAllocators];
52         std::bitset<kMaxCommandAllocators> mFreeAllocators;
53         SerialQueue<ExecutionSerial, IndexedCommandAllocator> mInFlightCommandAllocators;
54     };
55 
56 }}  // namespace dawn_native::d3d12
57 
58 #endif  // DAWNNATIVE_D3D12_COMMANDALLOCATORMANAGER_H_
59