From 393d555a0ea9a809c6bd486e19e177118102c61a Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Mon, 11 Feb 2019 23:35:33 +0000 Subject: [PATCH] PipelineLayout: Only allow accessing defined BGLs. Undefined BGLs are stored as nullptr in the pipeline layout, so to be defensive we assert clients of PipelineLayout can't request undefined BGLs (which forces iteration on the BGLMask). Also fix two cases where the BGLs were iterated on incorrectly. BUG=dawn:8 Change-Id: I3c084125b93d6684b4c79a56745632874079ebec Reviewed-on: https://dawn-review.googlesource.com/c/4480 Reviewed-by: Stephen White Reviewed-by: Kai Ninomiya Commit-Queue: Kai Ninomiya --- src/dawn_native/PipelineLayout.cpp | 1 + src/dawn_native/ShaderModule.cpp | 11 ++++++++++- src/dawn_native/d3d12/ShaderModuleD3D12.cpp | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/dawn_native/PipelineLayout.cpp b/src/dawn_native/PipelineLayout.cpp index f067ec54da..96772bd0e8 100644 --- a/src/dawn_native/PipelineLayout.cpp +++ b/src/dawn_native/PipelineLayout.cpp @@ -52,6 +52,7 @@ namespace dawn_native { const BindGroupLayoutBase* PipelineLayoutBase::GetBindGroupLayout(size_t group) const { ASSERT(group < kMaxBindGroups); + ASSERT(mMask[group]); return mBindGroupLayouts[group].Get(); } diff --git a/src/dawn_native/ShaderModule.cpp b/src/dawn_native/ShaderModule.cpp index d7867a3ec3..7a0e49e655 100644 --- a/src/dawn_native/ShaderModule.cpp +++ b/src/dawn_native/ShaderModule.cpp @@ -227,11 +227,20 @@ namespace dawn_native { } bool ShaderModuleBase::IsCompatibleWithPipelineLayout(const PipelineLayoutBase* layout) { - for (size_t group = 0; group < kMaxBindGroups; ++group) { + for (uint32_t group : IterateBitSet(layout->GetBindGroupLayoutsMask())) { if (!IsCompatibleWithBindGroupLayout(group, layout->GetBindGroupLayout(group))) { return false; } } + + for (uint32_t group : IterateBitSet(~layout->GetBindGroupLayoutsMask())) { + for (size_t i = 0; i < kMaxBindingsPerGroup; ++i) { + if (mBindingInfo[group][i].used) { + return false; + } + } + } + return true; } diff --git a/src/dawn_native/d3d12/ShaderModuleD3D12.cpp b/src/dawn_native/d3d12/ShaderModuleD3D12.cpp index 9911d51a0c..b9ec960d2c 100644 --- a/src/dawn_native/d3d12/ShaderModuleD3D12.cpp +++ b/src/dawn_native/d3d12/ShaderModuleD3D12.cpp @@ -15,6 +15,7 @@ #include "dawn_native/d3d12/ShaderModuleD3D12.h" #include "common/Assert.h" +#include "common/BitSetIterator.h" #include "dawn_native/d3d12/BindGroupLayoutD3D12.h" #include "dawn_native/d3d12/DeviceD3D12.h" #include "dawn_native/d3d12/PipelineLayoutD3D12.h" @@ -45,7 +46,7 @@ namespace dawn_native { namespace d3d12 { compiler.set_hlsl_options(options_hlsl); const ModuleBindingInfo& moduleBindingInfo = GetBindingInfo(); - for (uint32_t group = 0; group < moduleBindingInfo.size(); ++group) { + for (uint32_t group : IterateBitSet(layout->GetBindGroupLayoutsMask())) { const auto& bindingOffsets = ToBackend(layout->GetBindGroupLayout(group))->GetBindingOffsets(); const auto& groupBindingInfo = moduleBindingInfo[group];