dawn-cmake/src/tests/end2end/PipelineLayoutTests.cpp
Bryan Bernhart 18992f7be9 D3D12: Fix pipeline layout overflow when using dynamic offsets.
Pipeline layout incorrectly indexes into a root table array
when there are more root descriptors than root tables.
To fix, the array is dynamically sized where parameters
are appended instead of indexed into the root signature.

Bug: dawn:449
Change-Id: I6d7f65fb791d323704b1c3a3af9c871a79e32a30
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/22960
Commit-Queue: Bryan Bernhart <bryan.bernhart@intel.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
2020-06-10 16:09:45 +00:00

65 lines
2.7 KiB
C++

// Copyright 2020 The Dawn Authors
//
// 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.
#include "common/Constants.h"
#include "tests/DawnTest.h"
#include <vector>
class PipelineLayoutTests : public DawnTest {};
// Test creating a PipelineLayout with multiple BGLs where the first BGL uses the max number of
// dynamic buffers. This is a regression test for crbug.com/dawn/449 which would overflow when
// dynamic offset bindings were at max. Test is successful if the pipeline layout is created
// without error.
TEST_P(PipelineLayoutTests, DynamicBuffersOverflow) {
// Create the first bind group layout which uses max number of dynamic buffers bindings.
wgpu::BindGroupLayout bglA;
{
std::vector<wgpu::BindGroupLayoutEntry> entries;
for (uint32_t i = 0; i < kMaxDynamicStorageBufferCount; i++) {
entries.push_back(
{i, wgpu::ShaderStage::Compute, wgpu::BindingType::StorageBuffer, true});
}
wgpu::BindGroupLayoutDescriptor descriptor;
descriptor.entryCount = static_cast<uint32_t>(entries.size());
descriptor.entries = entries.data();
bglA = device.CreateBindGroupLayout(&descriptor);
}
// Create the second bind group layout that has one non-dynamic buffer binding.
wgpu::BindGroupLayout bglB;
{
wgpu::BindGroupLayoutDescriptor descriptor;
wgpu::BindGroupLayoutEntry entry = {0, wgpu::ShaderStage::Compute,
wgpu::BindingType::StorageBuffer, false};
descriptor.entryCount = 1;
descriptor.entries = &entry;
bglB = device.CreateBindGroupLayout(&descriptor);
}
// Create a pipeline layout using both bind group layouts.
wgpu::PipelineLayoutDescriptor descriptor;
std::vector<wgpu::BindGroupLayout> bindgroupLayouts = {bglA, bglB};
descriptor.bindGroupLayoutCount = bindgroupLayouts.size();
descriptor.bindGroupLayouts = bindgroupLayouts.data();
device.CreatePipelineLayout(&descriptor);
}
DAWN_INSTANTIATE_TEST(PipelineLayoutTests,
D3D12Backend(),
MetalBackend(),
OpenGLBackend(),
VulkanBackend());