2017-04-20 18:38:20 +00:00
|
|
|
// Copyright 2017 The NXT Authors
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2017-07-06 18:41:13 +00:00
|
|
|
#include "backend/PipelineLayout.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-07-06 18:41:13 +00:00
|
|
|
#include "backend/BindGroupLayout.h"
|
|
|
|
#include "backend/Device.h"
|
2017-07-10 17:46:05 +00:00
|
|
|
#include "common/Assert.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
|
|
|
namespace backend {
|
|
|
|
|
|
|
|
// PipelineLayoutBase
|
|
|
|
|
|
|
|
PipelineLayoutBase::PipelineLayoutBase(PipelineLayoutBuilder* builder)
|
2017-11-23 18:32:51 +00:00
|
|
|
: mBindGroupLayouts(std::move(builder->mBindGroupLayouts)), mMask(builder->mMask) {
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const BindGroupLayoutBase* PipelineLayoutBase::GetBindGroupLayout(size_t group) const {
|
|
|
|
ASSERT(group < kMaxBindGroups);
|
2017-11-23 18:32:51 +00:00
|
|
|
return mBindGroupLayouts[group].Get();
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::bitset<kMaxBindGroups> PipelineLayoutBase::GetBindGroupsLayoutMask() 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return kMaxBindGroups + 1;
|
|
|
|
}
|
|
|
|
|
2017-04-20 18:38:20 +00:00
|
|
|
// PipelineLayoutBuilder
|
|
|
|
|
2017-05-08 08:52:11 +00:00
|
|
|
PipelineLayoutBuilder::PipelineLayoutBuilder(DeviceBase* device) : Builder(device) {
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2017-05-08 13:17:44 +00:00
|
|
|
PipelineLayoutBase* PipelineLayoutBuilder::GetResultImpl() {
|
2017-11-24 18:59:42 +00:00
|
|
|
// TODO(cwallez@chromium.org): this is a hack, have the null bind group layout somewhere in
|
|
|
|
// the device once we have a cache of BGL
|
2017-04-20 18:38:20 +00:00
|
|
|
for (size_t group = 0; group < kMaxBindGroups; ++group) {
|
2017-11-23 18:32:51 +00:00
|
|
|
if (!mBindGroupLayouts[group]) {
|
2018-04-26 15:03:53 +00:00
|
|
|
auto builder = mDevice->CreateBindGroupLayoutBuilder();
|
|
|
|
mBindGroupLayouts[group] = builder->GetResult();
|
2018-04-17 20:37:07 +00:00
|
|
|
// Remove the external ref objects are created with
|
|
|
|
mBindGroupLayouts[group]->Release();
|
2018-04-26 15:03:53 +00:00
|
|
|
builder->Release();
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-23 18:32:51 +00:00
|
|
|
return mDevice->CreatePipelineLayout(this);
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
void PipelineLayoutBuilder::SetBindGroupLayout(uint32_t groupIndex,
|
|
|
|
BindGroupLayoutBase* layout) {
|
2017-04-20 18:38:20 +00:00
|
|
|
if (groupIndex >= kMaxBindGroups) {
|
2017-05-08 08:52:11 +00:00
|
|
|
HandleError("groupIndex is over the maximum allowed");
|
2017-04-20 18:38:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-11-23 18:32:51 +00:00
|
|
|
if (mMask[groupIndex]) {
|
2017-05-08 08:52:11 +00:00
|
|
|
HandleError("Bind group layout already specified");
|
2017-04-20 18:38:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-23 18:32:51 +00:00
|
|
|
mBindGroupLayouts[groupIndex] = layout;
|
|
|
|
mMask.set(groupIndex);
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
} // namespace backend
|