2018-07-18 09:40:26 +00:00
|
|
|
// Copyright 2017 The Dawn Authors
|
2017-04-20 18:38:20 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/PipelineLayout.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-07-10 17:46:05 +00:00
|
|
|
#include "common/Assert.h"
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/BindGroupLayout.h"
|
|
|
|
#include "dawn_native/Device.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
namespace dawn_native {
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-06-27 23:21:39 +00:00
|
|
|
MaybeError ValidatePipelineLayoutDescriptor(DeviceBase*,
|
2018-07-25 15:03:23 +00:00
|
|
|
const PipelineLayoutDescriptor* descriptor) {
|
2018-09-10 14:17:24 +00:00
|
|
|
if (descriptor->nextInChain != nullptr) {
|
|
|
|
return DAWN_VALIDATION_ERROR("nextInChain must be nullptr");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (descriptor->numBindGroupLayouts > kMaxBindGroups) {
|
|
|
|
return DAWN_VALIDATION_ERROR("too many bind group layouts");
|
|
|
|
}
|
|
|
|
|
2018-06-27 23:21:39 +00:00
|
|
|
for (uint32_t i = 0; i < descriptor->numBindGroupLayouts; ++i) {
|
2018-09-10 14:17:24 +00:00
|
|
|
if (descriptor->bindGroupLayouts[i] == nullptr) {
|
|
|
|
return DAWN_VALIDATION_ERROR("bind group layouts may not be null");
|
|
|
|
}
|
2018-06-27 23:21:39 +00:00
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2017-04-20 18:38:20 +00:00
|
|
|
// PipelineLayoutBase
|
|
|
|
|
2018-07-03 20:28:27 +00:00
|
|
|
PipelineLayoutBase::PipelineLayoutBase(DeviceBase* device,
|
2018-07-25 15:03:23 +00:00
|
|
|
const PipelineLayoutDescriptor* descriptor)
|
2018-10-15 12:54:30 +00:00
|
|
|
: ObjectBase(device) {
|
2018-06-27 23:21:39 +00:00
|
|
|
ASSERT(descriptor->numBindGroupLayouts <= kMaxBindGroups);
|
|
|
|
for (uint32_t group = 0; group < descriptor->numBindGroupLayouts; ++group) {
|
2018-07-25 15:03:23 +00:00
|
|
|
mBindGroupLayouts[group] = descriptor->bindGroupLayouts[group];
|
2018-06-27 23:21:39 +00:00
|
|
|
mMask.set(group);
|
|
|
|
}
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const BindGroupLayoutBase* PipelineLayoutBase::GetBindGroupLayout(size_t group) const {
|
|
|
|
ASSERT(group < kMaxBindGroups);
|
2019-02-11 23:35:33 +00:00
|
|
|
ASSERT(mMask[group]);
|
2017-11-23 18:32:51 +00:00
|
|
|
return mBindGroupLayouts[group].Get();
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2018-07-02 23:55:51 +00:00
|
|
|
const std::bitset<kMaxBindGroups> PipelineLayoutBase::GetBindGroupLayoutsMask() const {
|
2017-11-23 18:32:51 +00:00
|
|
|
return mMask;
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
std::bitset<kMaxBindGroups> PipelineLayoutBase::InheritedGroupsMask(
|
|
|
|
const PipelineLayoutBase* other) const {
|
2018-04-18 19:16:57 +00:00
|
|
|
return {(1 << GroupsInheritUpTo(other)) - 1u};
|
2017-07-15 05:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t PipelineLayoutBase::GroupsInheritUpTo(const PipelineLayoutBase* other) const {
|
|
|
|
for (uint32_t i = 0; i < kMaxBindGroups; ++i) {
|
2017-11-23 18:32:51 +00:00
|
|
|
if (!mMask[i] || mBindGroupLayouts[i].Get() != other->mBindGroupLayouts[i].Get()) {
|
2017-07-15 05:37:06 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2019-01-18 04:41:20 +00:00
|
|
|
return kMaxBindGroups;
|
2017-07-15 05:37:06 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
} // namespace dawn_native
|