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 "dawn_native/Device.h" 18 #include "dawn_native/ObjectContentHasher.h" 19 #include "dawn_native/ObjectType_autogen.h" 20 21 namespace dawn_native { 22 ValidateComputePipelineDescriptor(DeviceBase * device,const ComputePipelineDescriptor * descriptor)23 MaybeError ValidateComputePipelineDescriptor(DeviceBase* device, 24 const ComputePipelineDescriptor* descriptor) { 25 if (descriptor->nextInChain != nullptr) { 26 return DAWN_FORMAT_VALIDATION_ERROR("nextInChain must be nullptr."); 27 } 28 29 if (descriptor->layout != nullptr) { 30 DAWN_TRY(device->ValidateObject(descriptor->layout)); 31 } 32 33 return ValidateProgrammableStage( 34 device, descriptor->compute.module, descriptor->compute.entryPoint, 35 descriptor->compute.constantCount, descriptor->compute.constants, descriptor->layout, 36 SingleShaderStage::Compute); 37 } 38 39 // ComputePipelineBase 40 ComputePipelineBase(DeviceBase * device,const ComputePipelineDescriptor * descriptor)41 ComputePipelineBase::ComputePipelineBase(DeviceBase* device, 42 const ComputePipelineDescriptor* descriptor) 43 : PipelineBase(device, 44 descriptor->layout, 45 descriptor->label, 46 {{SingleShaderStage::Compute, descriptor->compute.module, 47 descriptor->compute.entryPoint, descriptor->compute.constantCount, 48 descriptor->compute.constants}}) { 49 SetContentHash(ComputeContentHash()); 50 TrackInDevice(); 51 } 52 ComputePipelineBase(DeviceBase * device)53 ComputePipelineBase::ComputePipelineBase(DeviceBase* device) : PipelineBase(device) { 54 TrackInDevice(); 55 } 56 ComputePipelineBase(DeviceBase * device,ObjectBase::ErrorTag tag)57 ComputePipelineBase::ComputePipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag) 58 : PipelineBase(device, tag) { 59 } 60 61 ComputePipelineBase::~ComputePipelineBase() = default; 62 DestroyImpl()63 void ComputePipelineBase::DestroyImpl() { 64 if (IsCachedReference()) { 65 // Do not uncache the actual cached object if we are a blueprint. 66 GetDevice()->UncacheComputePipeline(this); 67 } 68 } 69 70 // static MakeError(DeviceBase * device)71 ComputePipelineBase* ComputePipelineBase::MakeError(DeviceBase* device) { 72 class ErrorComputePipeline final : public ComputePipelineBase { 73 public: 74 ErrorComputePipeline(DeviceBase* device) 75 : ComputePipelineBase(device, ObjectBase::kError) { 76 } 77 78 MaybeError Initialize() override { 79 UNREACHABLE(); 80 return {}; 81 } 82 }; 83 84 return new ErrorComputePipeline(device); 85 } 86 GetType() const87 ObjectType ComputePipelineBase::GetType() const { 88 return ObjectType::ComputePipeline; 89 } 90 operator ()(const ComputePipelineBase * a,const ComputePipelineBase * b) const91 bool ComputePipelineBase::EqualityFunc::operator()(const ComputePipelineBase* a, 92 const ComputePipelineBase* b) const { 93 return PipelineBase::EqualForCache(a, b); 94 } 95 96 } // namespace dawn_native 97