mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-14 11:21:40 +00:00
Factor computation of inherited bindgroups in PipelineLayoutBase
This commit is contained in:
parent
136cae5ee2
commit
0bcf0e8e74
@ -17,6 +17,8 @@
|
|||||||
#include "backend/Device.h"
|
#include "backend/Device.h"
|
||||||
#include "common/Assert.h"
|
#include "common/Assert.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace backend {
|
namespace backend {
|
||||||
|
|
||||||
bool BuilderBase::CanBeUsed() const {
|
bool BuilderBase::CanBeUsed() const {
|
||||||
@ -76,6 +78,8 @@ namespace backend {
|
|||||||
result->Release();
|
result->Release();
|
||||||
result = nullptr;
|
result = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!callback) std::cout << storedMessage << std::endl;
|
||||||
} else {
|
} else {
|
||||||
ASSERT(storedStatus == nxt::BuilderErrorStatus::Success);
|
ASSERT(storedStatus == nxt::BuilderErrorStatus::Success);
|
||||||
ASSERT(storedMessage.empty());
|
ASSERT(storedMessage.empty());
|
||||||
|
@ -520,23 +520,16 @@ namespace backend {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CommandBufferStateTracker::SetPipelineCommon(PipelineBase* pipeline) {
|
bool CommandBufferStateTracker::SetPipelineCommon(PipelineBase* pipeline) {
|
||||||
PipelineLayoutBase* layout = pipeline->GetLayout();
|
PipelineLayoutBase* layout = pipeline->GetLayout();
|
||||||
|
|
||||||
aspects.reset(VALIDATION_ASPECT_BIND_GROUPS);
|
aspects.reset(VALIDATION_ASPECT_BIND_GROUPS);
|
||||||
|
// Reset bindgroups but mark unused bindgroups as valid
|
||||||
bindgroupsSet = ~layout->GetBindGroupsLayoutMask();
|
bindgroupsSet = ~layout->GetBindGroupsLayoutMask();
|
||||||
|
|
||||||
// Only bindgroups that were not the same layout in the last pipeline need to be set again.
|
// Only bindgroups that were not the same layout in the last pipeline need to be set again.
|
||||||
if (lastPipeline) {
|
if (lastPipeline) {
|
||||||
PipelineLayoutBase* lastLayout = lastPipeline->GetLayout();
|
bindgroupsSet |= layout->InheritedGroupsMask(lastPipeline->GetLayout());
|
||||||
for (uint32_t i = 0; i < kMaxBindGroups; ++i) {
|
|
||||||
if (lastLayout->GetBindGroupLayout(i) == layout->GetBindGroupLayout(i)) {
|
|
||||||
bindgroupsSet |= uint64_t(1) << i;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lastPipeline = pipeline;
|
lastPipeline = pipeline;
|
||||||
|
@ -35,6 +35,19 @@ namespace backend {
|
|||||||
return mask;
|
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::PipelineLayoutBuilder(DeviceBase* device) : Builder(device) {
|
PipelineLayoutBuilder::PipelineLayoutBuilder(DeviceBase* device) : Builder(device) {
|
||||||
|
@ -36,6 +36,13 @@ namespace backend {
|
|||||||
const BindGroupLayoutBase* GetBindGroupLayout(size_t group) const;
|
const BindGroupLayoutBase* GetBindGroupLayout(size_t group) const;
|
||||||
const std::bitset<kMaxBindGroups> GetBindGroupsLayoutMask() 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:
|
protected:
|
||||||
BindGroupLayoutArray bindGroupLayouts;
|
BindGroupLayoutArray bindGroupLayouts;
|
||||||
std::bitset<kMaxBindGroups> mask;
|
std::bitset<kMaxBindGroups> mask;
|
||||||
|
@ -81,18 +81,9 @@ namespace d3d12 {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto mask = newLayout->GetBindGroupsLayoutMask();
|
uint32_t inheritUntil = oldLayout->GroupsInheritUpTo(newLayout);
|
||||||
for (uint32_t i = 0; i < kMaxBindGroups; ++i) {
|
for (uint32_t i = 0; i < inheritUntil; ++i) {
|
||||||
// matching bind groups are inherited until they differ
|
TrackSetBindGroup(bindGroups[i], i);
|
||||||
if (mask[i] && oldLayout->GetBindGroupLayout(i) == newLayout->GetBindGroupLayout(i)) {
|
|
||||||
BindGroup* group = bindGroups[i];
|
|
||||||
if (group != nullptr) {
|
|
||||||
TrackSetBindGroup(group, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,18 +121,10 @@ namespace d3d12 {
|
|||||||
if (oldLayout == nullptr) {
|
if (oldLayout == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto mask = newLayout->GetBindGroupsLayoutMask();
|
|
||||||
for (uint32_t i = 0; i < kMaxBindGroups; ++i) {
|
uint32_t inheritUntil = oldLayout->GroupsInheritUpTo(newLayout);
|
||||||
// matching bind groups are inherited until they differ
|
for (uint32_t i = 0; i < inheritUntil; ++i) {
|
||||||
if (mask[i] && oldLayout->GetBindGroupLayout(i) == oldLayout->GetBindGroupLayout(i)) {
|
SetBindGroup(commandList, newLayout, bindGroups[i], i, true);
|
||||||
BindGroup* group = bindGroups[i];
|
|
||||||
if (group != nullptr) {
|
|
||||||
SetBindGroup(commandList, newLayout, group, i, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user