blob: 2f47ad276df71624efab8e6859065736c142f8d1 [file] [log] [blame] [edit]
// 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 < kMaxDynamicStorageBuffersPerPipelineLayout; i++) {
wgpu::BindGroupLayoutEntry entry;
entry.binding = i;
entry.visibility = wgpu::ShaderStage::Compute;
entry.buffer.type = wgpu::BufferBindingType::Storage;
entry.buffer.hasDynamicOffset = true;
entries.push_back(entry);
}
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.
// It is in the fragment stage to avoid the max per-stage storage buffer limit.
wgpu::BindGroupLayout bglB;
{
wgpu::BindGroupLayoutDescriptor descriptor;
wgpu::BindGroupLayoutEntry entry;
entry.binding = 0;
entry.visibility = wgpu::ShaderStage::Fragment;
entry.buffer.type = wgpu::BufferBindingType::Storage;
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(),
OpenGLESBackend(),
VulkanBackend());