Corentin Wallez | 4a9ef4e | 2018-07-18 11:40:26 +0200 | [diff] [blame] | 1 | // Copyright 2017 The Dawn Authors |
Corentin Wallez | 29ced28 | 2017-07-14 10:58:07 -0400 | [diff] [blame] | 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 | |
Corentin Wallez | d37523f | 2018-07-24 13:53:51 +0200 | [diff] [blame] | 15 | #include "dawn_native/ComputePipeline.h" |
Corentin Wallez | 29ced28 | 2017-07-14 10:58:07 -0400 | [diff] [blame] | 16 | |
Corentin Wallez | d37523f | 2018-07-24 13:53:51 +0200 | [diff] [blame] | 17 | #include "dawn_native/Device.h" |
Bryan Bernhart | 24bf7a4 | 2020-12-03 18:42:13 +0000 | [diff] [blame] | 18 | #include "dawn_native/ObjectContentHasher.h" |
Loko Kung | 8d195d5 | 2021-09-28 15:40:01 +0000 | [diff] [blame] | 19 | #include "dawn_native/ObjectType_autogen.h" |
Corentin Wallez | 29ced28 | 2017-07-14 10:58:07 -0400 | [diff] [blame] | 20 | |
Corentin Wallez | 49a65d0 | 2018-07-24 16:45:45 +0200 | [diff] [blame] | 21 | namespace dawn_native { |
Corentin Wallez | 29ced28 | 2017-07-14 10:58:07 -0400 | [diff] [blame] | 22 | |
Corentin Wallez | a594f8f | 2019-02-13 13:09:18 +0000 | [diff] [blame] | 23 | MaybeError ValidateComputePipelineDescriptor(DeviceBase* device, |
Corentin Wallez | 8e335a5 | 2018-08-27 23:12:56 +0200 | [diff] [blame] | 24 | const ComputePipelineDescriptor* descriptor) { |
Corentin Wallez | 6fee61c | 2018-09-10 16:17:24 +0200 | [diff] [blame] | 25 | if (descriptor->nextInChain != nullptr) { |
Brandon Jones | 520539f | 2021-10-20 17:42:38 +0000 | [diff] [blame] | 26 | return DAWN_FORMAT_VALIDATION_ERROR("nextInChain must be nullptr."); |
Corentin Wallez | 6fee61c | 2018-09-10 16:17:24 +0200 | [diff] [blame] | 27 | } |
Corentin Wallez | 8e335a5 | 2018-08-27 23:12:56 +0200 | [diff] [blame] | 28 | |
Austin Eng | f6eb890 | 2019-11-22 17:02:22 +0000 | [diff] [blame] | 29 | if (descriptor->layout != nullptr) { |
| 30 | DAWN_TRY(device->ValidateObject(descriptor->layout)); |
| 31 | } |
| 32 | |
shrekshao | e99ad76 | 2021-09-28 20:15:52 +0000 | [diff] [blame] | 33 | return ValidateProgrammableStage( |
| 34 | device, descriptor->compute.module, descriptor->compute.entryPoint, |
| 35 | descriptor->compute.constantCount, descriptor->compute.constants, descriptor->layout, |
| 36 | SingleShaderStage::Compute); |
Corentin Wallez | 8e335a5 | 2018-08-27 23:12:56 +0200 | [diff] [blame] | 37 | } |
| 38 | |
Corentin Wallez | 29ced28 | 2017-07-14 10:58:07 -0400 | [diff] [blame] | 39 | // ComputePipelineBase |
| 40 | |
Corentin Wallez | 8e335a5 | 2018-08-27 23:12:56 +0200 | [diff] [blame] | 41 | ComputePipelineBase::ComputePipelineBase(DeviceBase* device, |
Austin Eng | 84bcf44 | 2019-10-30 00:20:03 +0000 | [diff] [blame] | 42 | const ComputePipelineDescriptor* descriptor) |
Idan Raiter | f434fdc | 2020-06-19 21:39:23 +0000 | [diff] [blame] | 43 | : PipelineBase(device, |
| 44 | descriptor->layout, |
Brandon Jones | c1bcbbf | 2021-09-02 18:39:53 +0000 | [diff] [blame] | 45 | descriptor->label, |
Brandon Jones | 0d50a2c | 2021-06-09 18:07:32 +0000 | [diff] [blame] | 46 | {{SingleShaderStage::Compute, descriptor->compute.module, |
shrekshao | e99ad76 | 2021-09-28 20:15:52 +0000 | [diff] [blame] | 47 | descriptor->compute.entryPoint, descriptor->compute.constantCount, |
| 48 | descriptor->compute.constants}}) { |
Jiawei Shao | 8fd1eb5 | 2021-10-13 00:43:05 +0000 | [diff] [blame] | 49 | SetContentHash(ComputeContentHash()); |
Corentin Wallez | 29ced28 | 2017-07-14 10:58:07 -0400 | [diff] [blame] | 50 | } |
| 51 | |
Corentin Wallez | a594f8f | 2019-02-13 13:09:18 +0000 | [diff] [blame] | 52 | ComputePipelineBase::ComputePipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag) |
| 53 | : PipelineBase(device, tag) { |
| 54 | } |
| 55 | |
Corentin Wallez | 1152bba | 2019-05-01 13:48:47 +0000 | [diff] [blame] | 56 | ComputePipelineBase::~ComputePipelineBase() { |
| 57 | // Do not uncache the actual cached object if we are a blueprint |
Austin Eng | 84bcf44 | 2019-10-30 00:20:03 +0000 | [diff] [blame] | 58 | if (IsCachedReference()) { |
Corentin Wallez | 1152bba | 2019-05-01 13:48:47 +0000 | [diff] [blame] | 59 | GetDevice()->UncacheComputePipeline(this); |
| 60 | } |
| 61 | } |
| 62 | |
Corentin Wallez | a594f8f | 2019-02-13 13:09:18 +0000 | [diff] [blame] | 63 | // static |
| 64 | ComputePipelineBase* ComputePipelineBase::MakeError(DeviceBase* device) { |
Jiawei Shao | 8fd1eb5 | 2021-10-13 00:43:05 +0000 | [diff] [blame] | 65 | class ErrorComputePipeline final : public ComputePipelineBase { |
| 66 | public: |
| 67 | ErrorComputePipeline(DeviceBase* device) |
| 68 | : ComputePipelineBase(device, ObjectBase::kError) { |
| 69 | } |
| 70 | |
| 71 | MaybeError Initialize() override { |
| 72 | UNREACHABLE(); |
| 73 | return {}; |
| 74 | } |
| 75 | }; |
| 76 | |
| 77 | return new ErrorComputePipeline(device); |
Corentin Wallez | a594f8f | 2019-02-13 13:09:18 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Loko Kung | 8d195d5 | 2021-09-28 15:40:01 +0000 | [diff] [blame] | 80 | ObjectType ComputePipelineBase::GetType() const { |
| 81 | return ObjectType::ComputePipeline; |
| 82 | } |
| 83 | |
Corentin Wallez | 1152bba | 2019-05-01 13:48:47 +0000 | [diff] [blame] | 84 | bool ComputePipelineBase::EqualityFunc::operator()(const ComputePipelineBase* a, |
| 85 | const ComputePipelineBase* b) const { |
Corentin Wallez | 9ed8d51 | 2020-08-28 14:26:00 +0000 | [diff] [blame] | 86 | return PipelineBase::EqualForCache(a, b); |
Corentin Wallez | 1152bba | 2019-05-01 13:48:47 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Corentin Wallez | 49a65d0 | 2018-07-24 16:45:45 +0200 | [diff] [blame] | 89 | } // namespace dawn_native |