• 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/ComputePipeline.h"
16 
17 #include "common/HashUtils.h"
18 #include "dawn_native/Device.h"
19 
20 namespace dawn_native {
21 
ValidateComputePipelineDescriptor(DeviceBase * device,const ComputePipelineDescriptor * descriptor)22     MaybeError ValidateComputePipelineDescriptor(DeviceBase* device,
23                                                  const ComputePipelineDescriptor* descriptor) {
24         if (descriptor->nextInChain != nullptr) {
25             return DAWN_VALIDATION_ERROR("nextInChain must be nullptr");
26         }
27 
28         DAWN_TRY(device->ValidateObject(descriptor->layout));
29         DAWN_TRY(ValidatePipelineStageDescriptor(device, descriptor->computeStage,
30                                                  descriptor->layout, ShaderStage::Compute));
31         return {};
32     }
33 
34     // ComputePipelineBase
35 
ComputePipelineBase(DeviceBase * device,const ComputePipelineDescriptor * descriptor,bool blueprint)36     ComputePipelineBase::ComputePipelineBase(DeviceBase* device,
37                                              const ComputePipelineDescriptor* descriptor,
38                                              bool blueprint)
39         : PipelineBase(device, descriptor->layout, dawn::ShaderStageBit::Compute),
40           mModule(descriptor->computeStage->module),
41           mEntryPoint(descriptor->computeStage->entryPoint),
42           mIsBlueprint(blueprint) {
43     }
44 
ComputePipelineBase(DeviceBase * device,ObjectBase::ErrorTag tag)45     ComputePipelineBase::ComputePipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag)
46         : PipelineBase(device, tag) {
47     }
48 
~ComputePipelineBase()49     ComputePipelineBase::~ComputePipelineBase() {
50         // Do not uncache the actual cached object if we are a blueprint
51         if (!mIsBlueprint && !IsError()) {
52             GetDevice()->UncacheComputePipeline(this);
53         }
54     }
55 
56     // static
MakeError(DeviceBase * device)57     ComputePipelineBase* ComputePipelineBase::MakeError(DeviceBase* device) {
58         return new ComputePipelineBase(device, ObjectBase::kError);
59     }
60 
operator ()(const ComputePipelineBase * pipeline) const61     size_t ComputePipelineBase::HashFunc::operator()(const ComputePipelineBase* pipeline) const {
62         size_t hash = 0;
63         HashCombine(&hash, pipeline->mModule.Get(), pipeline->mEntryPoint, pipeline->GetLayout());
64         return hash;
65     }
66 
operator ()(const ComputePipelineBase * a,const ComputePipelineBase * b) const67     bool ComputePipelineBase::EqualityFunc::operator()(const ComputePipelineBase* a,
68                                                        const ComputePipelineBase* b) const {
69         return a->mModule.Get() == b->mModule.Get() && a->mEntryPoint == b->mEntryPoint &&
70                a->GetLayout() == b->GetLayout();
71     }
72 
73 }  // namespace dawn_native
74