• 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 #include "dawn_native/Queue.h"
16 
17 #include "dawn_native/Buffer.h"
18 #include "dawn_native/CommandBuffer.h"
19 #include "dawn_native/Device.h"
20 #include "dawn_native/Fence.h"
21 #include "dawn_native/FenceSignalTracker.h"
22 #include "dawn_native/Texture.h"
23 
24 namespace dawn_native {
25 
26     // QueueBase
27 
QueueBase(DeviceBase * device)28     QueueBase::QueueBase(DeviceBase* device) : ObjectBase(device) {
29     }
30 
Submit(uint32_t commandCount,CommandBufferBase * const * commands)31     void QueueBase::Submit(uint32_t commandCount, CommandBufferBase* const* commands) {
32         if (GetDevice()->ConsumedError(ValidateSubmit(commandCount, commands))) {
33             return;
34         }
35         ASSERT(!IsError());
36 
37         SubmitImpl(commandCount, commands);
38     }
39 
Signal(FenceBase * fence,uint64_t signalValue)40     void QueueBase::Signal(FenceBase* fence, uint64_t signalValue) {
41         if (GetDevice()->ConsumedError(ValidateSignal(fence, signalValue))) {
42             return;
43         }
44         ASSERT(!IsError());
45 
46         fence->SetSignaledValue(signalValue);
47         GetDevice()->GetFenceSignalTracker()->UpdateFenceOnComplete(fence, signalValue);
48     }
49 
CreateFence(const FenceDescriptor * descriptor)50     FenceBase* QueueBase::CreateFence(const FenceDescriptor* descriptor) {
51         if (GetDevice()->ConsumedError(ValidateCreateFence(descriptor))) {
52             return FenceBase::MakeError(GetDevice());
53         }
54 
55         return new FenceBase(this, descriptor);
56     }
57 
ValidateSubmit(uint32_t commandCount,CommandBufferBase * const * commands)58     MaybeError QueueBase::ValidateSubmit(uint32_t commandCount,
59                                          CommandBufferBase* const* commands) {
60         DAWN_TRY(GetDevice()->ValidateObject(this));
61 
62         for (uint32_t i = 0; i < commandCount; ++i) {
63             DAWN_TRY(GetDevice()->ValidateObject(commands[i]));
64 
65             const CommandBufferResourceUsage& usages = commands[i]->GetResourceUsages();
66 
67             for (const PassResourceUsage& passUsages : usages.perPass) {
68                 for (const BufferBase* buffer : passUsages.buffers) {
69                     DAWN_TRY(buffer->ValidateCanUseInSubmitNow());
70                 }
71                 for (const TextureBase* texture : passUsages.textures) {
72                     DAWN_TRY(texture->ValidateCanUseInSubmitNow());
73                 }
74             }
75 
76             for (const BufferBase* buffer : usages.topLevelBuffers) {
77                 DAWN_TRY(buffer->ValidateCanUseInSubmitNow());
78             }
79             for (const TextureBase* texture : usages.topLevelTextures) {
80                 DAWN_TRY(texture->ValidateCanUseInSubmitNow());
81             }
82         }
83 
84         return {};
85     }
86 
ValidateSignal(const FenceBase * fence,uint64_t signalValue)87     MaybeError QueueBase::ValidateSignal(const FenceBase* fence, uint64_t signalValue) {
88         DAWN_TRY(GetDevice()->ValidateObject(this));
89         DAWN_TRY(GetDevice()->ValidateObject(fence));
90 
91         if (fence->GetQueue() != this) {
92             return DAWN_VALIDATION_ERROR(
93                 "Fence must be signaled on the queue on which it was created.");
94         }
95         if (signalValue <= fence->GetSignaledValue()) {
96             return DAWN_VALIDATION_ERROR("Signal value less than or equal to fence signaled value");
97         }
98         return {};
99     }
100 
ValidateCreateFence(const FenceDescriptor * descriptor)101     MaybeError QueueBase::ValidateCreateFence(const FenceDescriptor* descriptor) {
102         DAWN_TRY(GetDevice()->ValidateObject(this));
103         DAWN_TRY(ValidateFenceDescriptor(descriptor));
104 
105         return {};
106     }
107 
108 }  // namespace dawn_native
109