2018-07-18 09:40:26 +00:00
|
|
|
// Copyright 2017 The Dawn Authors
|
2017-05-31 00:03:44 +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/Pipeline.h"
|
2017-05-31 00:03:44 +00:00
|
|
|
|
2020-08-28 14:26:00 +00:00
|
|
|
#include "common/HashUtils.h"
|
2019-11-22 17:02:22 +00:00
|
|
|
#include "dawn_native/BindGroupLayout.h"
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/Device.h"
|
|
|
|
#include "dawn_native/PipelineLayout.h"
|
|
|
|
#include "dawn_native/ShaderModule.h"
|
2017-05-31 00:03:44 +00:00
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
namespace dawn_native {
|
2017-05-31 00:03:44 +00:00
|
|
|
|
2019-10-07 12:23:09 +00:00
|
|
|
MaybeError ValidateProgrammableStageDescriptor(const DeviceBase* device,
|
|
|
|
const ProgrammableStageDescriptor* descriptor,
|
|
|
|
const PipelineLayoutBase* layout,
|
|
|
|
SingleShaderStage stage) {
|
2019-04-09 15:17:30 +00:00
|
|
|
DAWN_TRY(device->ValidateObject(descriptor->module));
|
|
|
|
|
|
|
|
if (descriptor->entryPoint != std::string("main")) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Entry point must be \"main\"");
|
|
|
|
}
|
|
|
|
if (descriptor->module->GetExecutionModel() != stage) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Setting module with wrong stages");
|
|
|
|
}
|
2020-06-09 17:06:04 +00:00
|
|
|
if (layout != nullptr) {
|
|
|
|
DAWN_TRY(descriptor->module->ValidateCompatibilityWithPipelineLayout(layout));
|
2019-04-09 15:17:30 +00:00
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2017-05-31 00:03:44 +00:00
|
|
|
// PipelineBase
|
|
|
|
|
2018-08-27 21:12:56 +00:00
|
|
|
PipelineBase::PipelineBase(DeviceBase* device,
|
|
|
|
PipelineLayoutBase* layout,
|
2020-08-28 14:26:00 +00:00
|
|
|
std::vector<StageAndDescriptor> stages)
|
|
|
|
: CachedObject(device), mLayout(layout) {
|
|
|
|
ASSERT(!stages.empty());
|
|
|
|
|
|
|
|
for (const StageAndDescriptor& stage : stages) {
|
|
|
|
bool isFirstStage = mStageMask == wgpu::ShaderStage::None;
|
|
|
|
mStageMask |= StageBit(stage.first);
|
|
|
|
mStages[stage.first] = {stage.second->module, stage.second->entryPoint};
|
|
|
|
|
|
|
|
// Compute the max() of all minBufferSizes across all stages.
|
|
|
|
RequiredBufferSizes stageMinBufferSizes =
|
|
|
|
stage.second->module->ComputeRequiredBufferSizesForLayout(layout);
|
|
|
|
|
|
|
|
if (isFirstStage) {
|
|
|
|
mMinBufferSizes = std::move(stageMinBufferSizes);
|
|
|
|
} else {
|
|
|
|
for (BindGroupIndex group(0); group < mMinBufferSizes.size(); ++group) {
|
|
|
|
ASSERT(stageMinBufferSizes[group].size() == mMinBufferSizes[group].size());
|
|
|
|
|
|
|
|
for (size_t i = 0; i < stageMinBufferSizes[group].size(); ++i) {
|
|
|
|
mMinBufferSizes[group][i] =
|
|
|
|
std::max(mMinBufferSizes[group][i], stageMinBufferSizes[group][i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-13 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PipelineBase::PipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag)
|
2019-10-30 00:20:03 +00:00
|
|
|
: CachedObject(device, tag) {
|
2018-08-27 21:12:56 +00:00
|
|
|
}
|
|
|
|
|
2017-05-31 00:03:44 +00:00
|
|
|
PipelineLayoutBase* PipelineBase::GetLayout() {
|
2019-02-13 13:09:18 +00:00
|
|
|
ASSERT(!IsError());
|
2017-11-23 18:32:51 +00:00
|
|
|
return mLayout.Get();
|
2017-05-31 00:03:44 +00:00
|
|
|
}
|
|
|
|
|
2019-05-01 13:48:47 +00:00
|
|
|
const PipelineLayoutBase* PipelineBase::GetLayout() const {
|
|
|
|
ASSERT(!IsError());
|
|
|
|
return mLayout.Get();
|
|
|
|
}
|
|
|
|
|
2020-08-28 14:26:00 +00:00
|
|
|
const RequiredBufferSizes& PipelineBase::GetMinBufferSizes() const {
|
|
|
|
ASSERT(!IsError());
|
|
|
|
return mMinBufferSizes;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ProgrammableStage& PipelineBase::GetStage(SingleShaderStage stage) const {
|
2020-06-19 21:39:23 +00:00
|
|
|
ASSERT(!IsError());
|
2020-08-28 14:26:00 +00:00
|
|
|
return mStages[stage];
|
2020-06-19 21:39:23 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 18:22:36 +00:00
|
|
|
MaybeError PipelineBase::ValidateGetBindGroupLayout(uint32_t groupIndex) {
|
2020-01-21 18:48:45 +00:00
|
|
|
DAWN_TRY(GetDevice()->ValidateIsAlive());
|
2019-11-22 17:02:22 +00:00
|
|
|
DAWN_TRY(GetDevice()->ValidateObject(this));
|
|
|
|
DAWN_TRY(GetDevice()->ValidateObject(mLayout.Get()));
|
2020-04-01 18:22:36 +00:00
|
|
|
if (groupIndex >= kMaxBindGroups) {
|
2019-11-22 17:02:22 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Bind group layout index out of bounds");
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2020-06-20 01:30:32 +00:00
|
|
|
BindGroupLayoutBase* PipelineBase::GetBindGroupLayout(uint32_t groupIndexIn) {
|
|
|
|
if (GetDevice()->ConsumedError(ValidateGetBindGroupLayout(groupIndexIn))) {
|
2019-11-22 17:02:22 +00:00
|
|
|
return BindGroupLayoutBase::MakeError(GetDevice());
|
|
|
|
}
|
|
|
|
|
2020-06-20 01:30:32 +00:00
|
|
|
BindGroupIndex groupIndex(groupIndexIn);
|
2019-11-22 17:02:22 +00:00
|
|
|
|
2020-07-01 13:09:46 +00:00
|
|
|
BindGroupLayoutBase* bgl = nullptr;
|
2020-06-29 11:13:43 +00:00
|
|
|
if (!mLayout->GetBindGroupLayoutsMask()[groupIndex]) {
|
2020-07-01 13:09:46 +00:00
|
|
|
bgl = GetDevice()->GetEmptyBindGroupLayout();
|
|
|
|
} else {
|
|
|
|
bgl = mLayout->GetBindGroupLayout(groupIndex);
|
2019-11-22 17:02:22 +00:00
|
|
|
}
|
|
|
|
bgl->Reference();
|
|
|
|
return bgl;
|
|
|
|
}
|
|
|
|
|
2020-08-28 14:26:00 +00:00
|
|
|
// static
|
|
|
|
size_t PipelineBase::HashForCache(const PipelineBase* pipeline) {
|
|
|
|
size_t hash = 0;
|
|
|
|
|
|
|
|
// The layout is deduplicated so it can be hashed by pointer.
|
|
|
|
HashCombine(&hash, pipeline->mLayout.Get());
|
|
|
|
|
|
|
|
HashCombine(&hash, pipeline->mStageMask);
|
|
|
|
for (SingleShaderStage stage : IterateStages(pipeline->mStageMask)) {
|
|
|
|
// The module is deduplicated so it can be hashed by pointer.
|
|
|
|
HashCombine(&hash, pipeline->mStages[stage].module.Get());
|
|
|
|
HashCombine(&hash, pipeline->mStages[stage].entryPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool PipelineBase::EqualForCache(const PipelineBase* a, const PipelineBase* b) {
|
|
|
|
// The layout is deduplicated so it can be compared by pointer.
|
|
|
|
if (a->mLayout.Get() != b->mLayout.Get() || a->mStageMask != b->mStageMask) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (SingleShaderStage stage : IterateStages(a->mStageMask)) {
|
|
|
|
// The module is deduplicated so it can be compared by pointer.
|
|
|
|
if (a->mStages[stage].module.Get() != b->mStages[stage].module.Get() ||
|
|
|
|
a->mStages[stage].entryPoint != b->mStages[stage].entryPoint) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-10 18:19:38 +00:00
|
|
|
} // namespace dawn_native
|