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/Pipeline.h" 16 17 #include "dawn_native/Device.h" 18 #include "dawn_native/PipelineLayout.h" 19 #include "dawn_native/ShaderModule.h" 20 21 namespace dawn_native { 22 ValidatePipelineStageDescriptor(const DeviceBase * device,const PipelineStageDescriptor * descriptor,const PipelineLayoutBase * layout,ShaderStage stage)23 MaybeError ValidatePipelineStageDescriptor(const DeviceBase* device, 24 const PipelineStageDescriptor* descriptor, 25 const PipelineLayoutBase* layout, 26 ShaderStage stage) { 27 DAWN_TRY(device->ValidateObject(descriptor->module)); 28 29 if (descriptor->entryPoint != std::string("main")) { 30 return DAWN_VALIDATION_ERROR("Entry point must be \"main\""); 31 } 32 if (descriptor->module->GetExecutionModel() != stage) { 33 return DAWN_VALIDATION_ERROR("Setting module with wrong stages"); 34 } 35 if (!descriptor->module->IsCompatibleWithPipelineLayout(layout)) { 36 return DAWN_VALIDATION_ERROR("Stage not compatible with layout"); 37 } 38 return {}; 39 } 40 41 // PipelineBase 42 PipelineBase(DeviceBase * device,PipelineLayoutBase * layout,dawn::ShaderStageBit stages)43 PipelineBase::PipelineBase(DeviceBase* device, 44 PipelineLayoutBase* layout, 45 dawn::ShaderStageBit stages) 46 : ObjectBase(device), mStageMask(stages), mLayout(layout) { 47 } 48 PipelineBase(DeviceBase * device,ObjectBase::ErrorTag tag)49 PipelineBase::PipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag) 50 : ObjectBase(device, tag) { 51 } 52 GetStageMask() const53 dawn::ShaderStageBit PipelineBase::GetStageMask() const { 54 ASSERT(!IsError()); 55 return mStageMask; 56 } 57 GetLayout()58 PipelineLayoutBase* PipelineBase::GetLayout() { 59 ASSERT(!IsError()); 60 return mLayout.Get(); 61 } 62 GetLayout() const63 const PipelineLayoutBase* PipelineBase::GetLayout() const { 64 ASSERT(!IsError()); 65 return mLayout.Get(); 66 } 67 68 } // namespace dawn_native 69