Allow bind group layouts to be sparse in pipeline layout

Instead of initializing all of the bind group layouts in the pipeline
layout to default values, let them be nullptr and allow this elsewhere.

Follow-up on some changes in #206
This commit is contained in:
Kai Ninomiya 2018-06-29 18:22:02 -07:00 committed by Kai Ninomiya
parent 804fc749a0
commit 311e2a44b9
6 changed files with 10 additions and 14 deletions

View File

@ -34,7 +34,7 @@ namespace backend {
// PipelineLayoutBase // PipelineLayoutBase
PipelineLayoutBase::PipelineLayoutBase(DeviceBase* device, PipelineLayoutBase::PipelineLayoutBase(DeviceBase*,
const nxt::PipelineLayoutDescriptor* descriptor) { const nxt::PipelineLayoutDescriptor* descriptor) {
ASSERT(descriptor->numBindGroupLayouts <= kMaxBindGroups); ASSERT(descriptor->numBindGroupLayouts <= kMaxBindGroups);
for (uint32_t group = 0; group < descriptor->numBindGroupLayouts; ++group) { for (uint32_t group = 0; group < descriptor->numBindGroupLayouts; ++group) {
@ -42,15 +42,6 @@ namespace backend {
reinterpret_cast<BindGroupLayoutBase*>(descriptor->bindGroupLayouts[group].Get()); reinterpret_cast<BindGroupLayoutBase*>(descriptor->bindGroupLayouts[group].Get());
mMask.set(group); mMask.set(group);
} }
// TODO(kainino@chromium.org): It shouldn't be necessary to construct default bind
// group layouts here. Remove these and fix things so that they are not needed.
for (uint32_t group = descriptor->numBindGroupLayouts; group < kMaxBindGroups; ++group) {
auto builder = device->CreateBindGroupLayoutBuilder();
mBindGroupLayouts[group] = builder->GetResult();
// Remove the external ref objects are created with
mBindGroupLayouts[group]->Release();
builder->Release();
}
} }
const BindGroupLayoutBase* PipelineLayoutBase::GetBindGroupLayout(size_t group) const { const BindGroupLayoutBase* PipelineLayoutBase::GetBindGroupLayout(size_t group) const {

View File

@ -37,6 +37,7 @@ namespace backend {
PipelineLayoutBase(DeviceBase* device, const nxt::PipelineLayoutDescriptor* descriptor); PipelineLayoutBase(DeviceBase* device, const nxt::PipelineLayoutDescriptor* descriptor);
const BindGroupLayoutBase* GetBindGroupLayout(size_t group) const; const BindGroupLayoutBase* GetBindGroupLayout(size_t group) const;
// XXX: rename to GetBindGroupLayoutsMask?
const std::bitset<kMaxBindGroups> GetBindGroupsLayoutMask() const; const std::bitset<kMaxBindGroups> GetBindGroupsLayoutMask() const;
// Utility functions to compute inherited bind groups. // Utility functions to compute inherited bind groups.

View File

@ -17,6 +17,7 @@
#include "backend/d3d12/BindGroupLayoutD3D12.h" #include "backend/d3d12/BindGroupLayoutD3D12.h"
#include "backend/d3d12/DeviceD3D12.h" #include "backend/d3d12/DeviceD3D12.h"
#include "common/Assert.h" #include "common/Assert.h"
#include "common/BitSetIterator.h"
using Microsoft::WRL::ComPtr; using Microsoft::WRL::ComPtr;
@ -42,7 +43,7 @@ namespace backend { namespace d3d12 {
uint32_t parameterIndex = 0; uint32_t parameterIndex = 0;
uint32_t rangeIndex = 0; uint32_t rangeIndex = 0;
for (uint32_t group = 0; group < kMaxBindGroups; ++group) { for (uint32_t group : IterateBitSet(GetBindGroupsLayoutMask())) {
const BindGroupLayout* bindGroupLayout = ToBackend(GetBindGroupLayout(group)); const BindGroupLayout* bindGroupLayout = ToBackend(GetBindGroupLayout(group));
// Set the root descriptor table parameter and copy ranges. Ranges are offset by the // Set the root descriptor table parameter and copy ranges. Ranges are offset by the

View File

@ -16,6 +16,7 @@
#include "backend/BindGroupLayout.h" #include "backend/BindGroupLayout.h"
#include "backend/metal/DeviceMTL.h" #include "backend/metal/DeviceMTL.h"
#include "common/BitSetIterator.h"
namespace backend { namespace metal { namespace backend { namespace metal {
@ -28,7 +29,7 @@ namespace backend { namespace metal {
uint32_t samplerIndex = 0; uint32_t samplerIndex = 0;
uint32_t textureIndex = 0; uint32_t textureIndex = 0;
for (size_t group = 0; group < kMaxBindGroups; ++group) { for (uint32_t group : IterateBitSet(GetBindGroupsLayoutMask())) {
const auto& groupInfo = GetBindGroupLayout(group)->GetBindingInfo(); const auto& groupInfo = GetBindGroupLayout(group)->GetBindingInfo();
for (size_t binding = 0; binding < kMaxBindingsPerGroup; ++binding) { for (size_t binding = 0; binding < kMaxBindingsPerGroup; ++binding) {
if (!(groupInfo.visibilities[binding] & StageBit(stage))) { if (!(groupInfo.visibilities[binding] & StageBit(stage))) {

View File

@ -19,6 +19,7 @@
#include "backend/opengl/PersistentPipelineStateGL.h" #include "backend/opengl/PersistentPipelineStateGL.h"
#include "backend/opengl/PipelineLayoutGL.h" #include "backend/opengl/PipelineLayoutGL.h"
#include "backend/opengl/ShaderModuleGL.h" #include "backend/opengl/ShaderModuleGL.h"
#include "common/BitSetIterator.h"
#include <iostream> #include <iostream>
#include <set> #include <set>
@ -125,7 +126,7 @@ namespace backend { namespace opengl {
const auto& layout = ToBackend(parent->GetLayout()); const auto& layout = ToBackend(parent->GetLayout());
const auto& indices = layout->GetBindingIndexInfo(); const auto& indices = layout->GetBindingIndexInfo();
for (uint32_t group = 0; group < kMaxBindGroups; ++group) { for (uint32_t group : IterateBitSet(layout->GetBindGroupsLayoutMask())) {
const auto& groupInfo = layout->GetBindGroupLayout(group)->GetBindingInfo(); const auto& groupInfo = layout->GetBindGroupLayout(group)->GetBindingInfo();
for (uint32_t binding = 0; binding < kMaxBindingsPerGroup; ++binding) { for (uint32_t binding = 0; binding < kMaxBindingsPerGroup; ++binding) {

View File

@ -16,6 +16,7 @@
#include "backend/BindGroupLayout.h" #include "backend/BindGroupLayout.h"
#include "backend/opengl/DeviceGL.h" #include "backend/opengl/DeviceGL.h"
#include "common/BitSetIterator.h"
namespace backend { namespace opengl { namespace backend { namespace opengl {
@ -26,7 +27,7 @@ namespace backend { namespace opengl {
GLuint sampledTextureIndex = 0; GLuint sampledTextureIndex = 0;
GLuint ssboIndex = 0; GLuint ssboIndex = 0;
for (size_t group = 0; group < kMaxBindGroups; ++group) { for (uint32_t group : IterateBitSet(GetBindGroupsLayoutMask())) {
const auto& groupInfo = GetBindGroupLayout(group)->GetBindingInfo(); const auto& groupInfo = GetBindGroupLayout(group)->GetBindingInfo();
for (size_t binding = 0; binding < kMaxBindingsPerGroup; ++binding) { for (size_t binding = 0; binding < kMaxBindingsPerGroup; ++binding) {