1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#include "RenderAPI/BsCommandBuffer.h"
4#include "Managers/BsCommandBufferManager.h"
5
6namespace bs { namespace ct
7{
8 void CommandSyncMask::addDependency(const SPtr<CommandBuffer>& buffer)
9 {
10 if (buffer == nullptr)
11 return;
12
13 mMask |= getGlobalQueueMask(buffer->getType(), buffer->getQueueIdx());
14 }
15
16 UINT32 CommandSyncMask::getGlobalQueueMask(GpuQueueType type, UINT32 queueIdx)
17 {
18 UINT32 bitShift = 0;
19 switch (type)
20 {
21 case GQT_GRAPHICS:
22 break;
23 case GQT_COMPUTE:
24 bitShift = 8;
25 break;
26 case GQT_UPLOAD:
27 bitShift = 16;
28 break;
29 default:
30 break;
31 }
32
33 return (1 << queueIdx) << bitShift;
34 }
35
36 UINT32 CommandSyncMask::getGlobalQueueIdx(GpuQueueType type, UINT32 queueIdx)
37 {
38 switch (type)
39 {
40 case GQT_COMPUTE:
41 return 8 + queueIdx;
42 case GQT_UPLOAD:
43 return 16 + queueIdx;
44 default:
45 return queueIdx;
46 }
47 }
48
49 UINT32 CommandSyncMask::getQueueIdxAndType(UINT32 globalQueueIdx, GpuQueueType& type)
50 {
51 if(globalQueueIdx >= 16)
52 {
53 type = GQT_UPLOAD;
54 return globalQueueIdx - 16;
55 }
56
57 if(globalQueueIdx >= 8)
58 {
59 type = GQT_COMPUTE;
60 return globalQueueIdx - 8;
61 }
62
63 type = GQT_GRAPHICS;
64 return globalQueueIdx;
65 }
66
67 CommandBuffer::CommandBuffer(GpuQueueType type, UINT32 deviceIdx, UINT32 queueIdx, bool secondary)
68 :mType(type), mDeviceIdx(deviceIdx), mQueueIdx(queueIdx), mIsSecondary(secondary)
69 {
70
71 }
72
73 SPtr<CommandBuffer> CommandBuffer::create(GpuQueueType type, UINT32 deviceIdx, UINT32 queueIdx,
74 bool secondary)
75 {
76 return CommandBufferManager::instance().create(type, deviceIdx, queueIdx, secondary);
77 }
78}}