blob: 72addc479731f181f634fd7b4008a602b42144ce [file] [log] [blame]
Corentin Wallez4a9ef4e2018-07-18 11:40:26 +02001// Copyright 2017 The Dawn Authors
Corentin Wallez29ced282017-07-14 10:58:07 -04002//
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 Wallezd37523f2018-07-24 13:53:51 +020015#include "dawn_native/ComputePipeline.h"
Corentin Wallez29ced282017-07-14 10:58:07 -040016
Corentin Wallezd37523f2018-07-24 13:53:51 +020017#include "dawn_native/Device.h"
Bryan Bernhart24bf7a42020-12-03 18:42:13 +000018#include "dawn_native/ObjectContentHasher.h"
Loko Kung8d195d52021-09-28 15:40:01 +000019#include "dawn_native/ObjectType_autogen.h"
Corentin Wallez29ced282017-07-14 10:58:07 -040020
Corentin Wallez49a65d02018-07-24 16:45:45 +020021namespace dawn_native {
Corentin Wallez29ced282017-07-14 10:58:07 -040022
Corentin Walleza594f8f2019-02-13 13:09:18 +000023 MaybeError ValidateComputePipelineDescriptor(DeviceBase* device,
Corentin Wallez8e335a52018-08-27 23:12:56 +020024 const ComputePipelineDescriptor* descriptor) {
Corentin Wallez6fee61c2018-09-10 16:17:24 +020025 if (descriptor->nextInChain != nullptr) {
Brandon Jones520539f2021-10-20 17:42:38 +000026 return DAWN_FORMAT_VALIDATION_ERROR("nextInChain must be nullptr.");
Corentin Wallez6fee61c2018-09-10 16:17:24 +020027 }
Corentin Wallez8e335a52018-08-27 23:12:56 +020028
Austin Engf6eb8902019-11-22 17:02:22 +000029 if (descriptor->layout != nullptr) {
30 DAWN_TRY(device->ValidateObject(descriptor->layout));
31 }
32
shrekshaoe99ad762021-09-28 20:15:52 +000033 return ValidateProgrammableStage(
34 device, descriptor->compute.module, descriptor->compute.entryPoint,
35 descriptor->compute.constantCount, descriptor->compute.constants, descriptor->layout,
36 SingleShaderStage::Compute);
Corentin Wallez8e335a52018-08-27 23:12:56 +020037 }
38
Corentin Wallez29ced282017-07-14 10:58:07 -040039 // ComputePipelineBase
40
Corentin Wallez8e335a52018-08-27 23:12:56 +020041 ComputePipelineBase::ComputePipelineBase(DeviceBase* device,
Austin Eng84bcf442019-10-30 00:20:03 +000042 const ComputePipelineDescriptor* descriptor)
Idan Raiterf434fdc2020-06-19 21:39:23 +000043 : PipelineBase(device,
44 descriptor->layout,
Brandon Jonesc1bcbbf2021-09-02 18:39:53 +000045 descriptor->label,
Brandon Jones0d50a2c2021-06-09 18:07:32 +000046 {{SingleShaderStage::Compute, descriptor->compute.module,
shrekshaoe99ad762021-09-28 20:15:52 +000047 descriptor->compute.entryPoint, descriptor->compute.constantCount,
48 descriptor->compute.constants}}) {
Jiawei Shao8fd1eb52021-10-13 00:43:05 +000049 SetContentHash(ComputeContentHash());
Corentin Wallez29ced282017-07-14 10:58:07 -040050 }
51
Corentin Walleza594f8f2019-02-13 13:09:18 +000052 ComputePipelineBase::ComputePipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag)
53 : PipelineBase(device, tag) {
54 }
55
Corentin Wallez1152bba2019-05-01 13:48:47 +000056 ComputePipelineBase::~ComputePipelineBase() {
57 // Do not uncache the actual cached object if we are a blueprint
Austin Eng84bcf442019-10-30 00:20:03 +000058 if (IsCachedReference()) {
Corentin Wallez1152bba2019-05-01 13:48:47 +000059 GetDevice()->UncacheComputePipeline(this);
60 }
61 }
62
Corentin Walleza594f8f2019-02-13 13:09:18 +000063 // static
64 ComputePipelineBase* ComputePipelineBase::MakeError(DeviceBase* device) {
Jiawei Shao8fd1eb52021-10-13 00:43:05 +000065 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 Walleza594f8f2019-02-13 13:09:18 +000078 }
79
Loko Kung8d195d52021-09-28 15:40:01 +000080 ObjectType ComputePipelineBase::GetType() const {
81 return ObjectType::ComputePipeline;
82 }
83
Corentin Wallez1152bba2019-05-01 13:48:47 +000084 bool ComputePipelineBase::EqualityFunc::operator()(const ComputePipelineBase* a,
85 const ComputePipelineBase* b) const {
Corentin Wallez9ed8d512020-08-28 14:26:00 +000086 return PipelineBase::EqualForCache(a, b);
Corentin Wallez1152bba2019-05-01 13:48:47 +000087 }
88
Corentin Wallez49a65d02018-07-24 16:45:45 +020089} // namespace dawn_native