Factor computation of inherited bindgroups in PipelineLayoutBase

This commit is contained in:
Corentin Wallez 2017-07-15 01:37:06 -04:00 committed by Corentin Wallez
parent 136cae5ee2
commit 0bcf0e8e74
5 changed files with 33 additions and 33 deletions

View File

@ -17,6 +17,8 @@
#include "backend/Device.h"
#include "common/Assert.h"
#include <iostream>
namespace backend {
bool BuilderBase::CanBeUsed() const {
@ -76,6 +78,8 @@ namespace backend {
result->Release();
result = nullptr;
}
if (!callback) std::cout << storedMessage << std::endl;
} else {
ASSERT(storedStatus == nxt::BuilderErrorStatus::Success);
ASSERT(storedMessage.empty());

View File

@ -520,23 +520,16 @@ namespace backend {
return true;
}
bool CommandBufferStateTracker::SetPipelineCommon(PipelineBase* pipeline) {
PipelineLayoutBase* layout = pipeline->GetLayout();
aspects.reset(VALIDATION_ASPECT_BIND_GROUPS);
// Reset bindgroups but mark unused bindgroups as valid
bindgroupsSet = ~layout->GetBindGroupsLayoutMask();
// Only bindgroups that were not the same layout in the last pipeline need to be set again.
if (lastPipeline) {
PipelineLayoutBase* lastLayout = lastPipeline->GetLayout();
for (uint32_t i = 0; i < kMaxBindGroups; ++i) {
if (lastLayout->GetBindGroupLayout(i) == layout->GetBindGroupLayout(i)) {
bindgroupsSet |= uint64_t(1) << i;
} else {
break;
}
}
bindgroupsSet |= layout->InheritedGroupsMask(lastPipeline->GetLayout());
}
lastPipeline = pipeline;

View File

@ -35,6 +35,19 @@ namespace backend {
return mask;
}
std::bitset<kMaxBindGroups> PipelineLayoutBase::InheritedGroupsMask(const PipelineLayoutBase* other) const {
return { GroupsInheritUpTo(other) - 1 };
}
uint32_t PipelineLayoutBase::GroupsInheritUpTo(const PipelineLayoutBase* other) const {
for (uint32_t i = 0; i < kMaxBindGroups; ++i) {
if (!mask[i] || bindGroupLayouts[i].Get() != other->bindGroupLayouts[i].Get()) {
return i;
}
}
return kMaxBindGroups + 1;
}
// PipelineLayoutBuilder
PipelineLayoutBuilder::PipelineLayoutBuilder(DeviceBase* device) : Builder(device) {

View File

@ -36,6 +36,13 @@ namespace backend {
const BindGroupLayoutBase* GetBindGroupLayout(size_t group) const;
const std::bitset<kMaxBindGroups> GetBindGroupsLayoutMask() const;
// Utility functions to compute inherited bind groups.
// Returns the inherited bind groups as a mask
std::bitset<kMaxBindGroups> InheritedGroupsMask(const PipelineLayoutBase* other) const;
// Returns the index of the first incompatible bind group (in the range [1, kMaxBindGroups + 1])
uint32_t GroupsInheritUpTo(const PipelineLayoutBase* other) const;
protected:
BindGroupLayoutArray bindGroupLayouts;
std::bitset<kMaxBindGroups> mask;

View File

@ -81,18 +81,9 @@ namespace d3d12 {
return;
}
auto mask = newLayout->GetBindGroupsLayoutMask();
for (uint32_t i = 0; i < kMaxBindGroups; ++i) {
// matching bind groups are inherited until they differ
if (mask[i] && oldLayout->GetBindGroupLayout(i) == newLayout->GetBindGroupLayout(i)) {
BindGroup* group = bindGroups[i];
if (group != nullptr) {
TrackSetBindGroup(group, i);
}
}
else {
break;
}
uint32_t inheritUntil = oldLayout->GroupsInheritUpTo(newLayout);
for (uint32_t i = 0; i < inheritUntil; ++i) {
TrackSetBindGroup(bindGroups[i], i);
}
}
@ -130,18 +121,10 @@ namespace d3d12 {
if (oldLayout == nullptr) {
return;
}
auto mask = newLayout->GetBindGroupsLayoutMask();
for (uint32_t i = 0; i < kMaxBindGroups; ++i) {
// matching bind groups are inherited until they differ
if (mask[i] && oldLayout->GetBindGroupLayout(i) == oldLayout->GetBindGroupLayout(i)) {
BindGroup* group = bindGroups[i];
if (group != nullptr) {
SetBindGroup(commandList, newLayout, group, i, true);
}
}
else {
break;
}
uint32_t inheritUntil = oldLayout->GroupsInheritUpTo(newLayout);
for (uint32_t i = 0; i < inheritUntil; ++i) {
SetBindGroup(commandList, newLayout, bindGroups[i], i, true);
}
}