mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-18 09:25:25 +00:00
Add missing WebGPU limits to Constants.h
This will help check that the Vulkan devices are enough for WebGPU in a following CL. In addition to additional limits this CL: - Change maxColorAttachments 4 -> 8 to match WebGPU - Renames kMinDynamicBufferOffsetAlignment to kMinUniformBufferOffsetAlignment. - Renames kMaxVertexBufferStride to kMaxVertexBufferArrayStride. - Changes validation of buffer offsets to use the separate uniform and storage limits (but no test is added because they are the same). - Adds validation and a test for kMaxStorageBufferBindingSize. - Augment the null::Device memory limit for that new test (it allocates a buffer of 512MB). - Fix the maxColorAttachment test to not use hardcoded values. Bug: dawn:796 Change-Id: Ibe4219130a44355ae91c02aaa0a41cf5d9f9e234 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/56081 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
895bc934bb
commit
73b7cd624f
@@ -731,6 +731,36 @@ TEST_F(BindGroupValidationTest, MaxUniformBufferBindingSize) {
|
||||
utils::MakeBindGroup(device, storageLayout, {{0, buffer, 0, 2 * kMaxUniformBufferBindingSize}});
|
||||
}
|
||||
|
||||
// Tests constraints to be sure the storage buffer binding isn't too large
|
||||
TEST_F(BindGroupValidationTest, MaxStorageBufferBindingSize) {
|
||||
wgpu::BufferDescriptor descriptor;
|
||||
descriptor.size = 2 * kMaxStorageBufferBindingSize;
|
||||
descriptor.usage = wgpu::BufferUsage::Storage;
|
||||
wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
|
||||
|
||||
wgpu::BindGroupLayout uniformLayout = utils::MakeBindGroupLayout(
|
||||
device, {{0, wgpu::ShaderStage::Fragment, wgpu::BufferBindingType::Storage}});
|
||||
|
||||
// Success case, this is exactly the limit
|
||||
utils::MakeBindGroup(device, uniformLayout, {{0, buffer, 0, kMaxStorageBufferBindingSize}});
|
||||
|
||||
// Success case, this is one less than the limit (check it is not an alignment constraint)
|
||||
utils::MakeBindGroup(device, uniformLayout, {{0, buffer, 0, kMaxStorageBufferBindingSize - 1}});
|
||||
|
||||
wgpu::BindGroupLayout doubleUniformLayout = utils::MakeBindGroupLayout(
|
||||
device, {{0, wgpu::ShaderStage::Fragment, wgpu::BufferBindingType::Storage},
|
||||
{1, wgpu::ShaderStage::Fragment, wgpu::BufferBindingType::Storage}});
|
||||
|
||||
// Success case, individual bindings don't exceed the limit
|
||||
utils::MakeBindGroup(device, doubleUniformLayout,
|
||||
{{0, buffer, 0, kMaxStorageBufferBindingSize},
|
||||
{1, buffer, kMaxStorageBufferBindingSize, kMaxStorageBufferBindingSize}});
|
||||
|
||||
// Error case, this is above the limit
|
||||
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, uniformLayout,
|
||||
{{0, buffer, 0, kMaxStorageBufferBindingSize + 1}}));
|
||||
}
|
||||
|
||||
// Test what happens when the layout is an error.
|
||||
TEST_F(BindGroupValidationTest, ErrorLayout) {
|
||||
wgpu::BindGroupLayout goodLayout = utils::MakeBindGroupLayout(
|
||||
@@ -1267,7 +1297,7 @@ TEST_F(BindGroupLayoutValidationTest, MultisampledTextureComponentType) {
|
||||
}));
|
||||
}
|
||||
|
||||
constexpr uint64_t kBufferSize = 3 * kMinDynamicBufferOffsetAlignment + 8;
|
||||
constexpr uint64_t kBufferSize = 3 * kMinUniformBufferOffsetAlignment + 8;
|
||||
constexpr uint32_t kBindingSize = 9;
|
||||
|
||||
class SetBindGroupValidationTest : public ValidationTest {
|
||||
@@ -1610,11 +1640,11 @@ TEST_F(SetBindGroupValidationTest, DynamicOffsetOrder) {
|
||||
// end of the buffer. Any mismatch applying too-large of an offset to a smaller buffer will hit
|
||||
// the out-of-bounds condition during validation.
|
||||
wgpu::Buffer buffer3x =
|
||||
CreateBuffer(3 * kMinDynamicBufferOffsetAlignment + 4, wgpu::BufferUsage::Storage);
|
||||
CreateBuffer(3 * kMinUniformBufferOffsetAlignment + 4, wgpu::BufferUsage::Storage);
|
||||
wgpu::Buffer buffer2x =
|
||||
CreateBuffer(2 * kMinDynamicBufferOffsetAlignment + 4, wgpu::BufferUsage::Storage);
|
||||
CreateBuffer(2 * kMinUniformBufferOffsetAlignment + 4, wgpu::BufferUsage::Storage);
|
||||
wgpu::Buffer buffer1x =
|
||||
CreateBuffer(1 * kMinDynamicBufferOffsetAlignment + 4, wgpu::BufferUsage::Uniform);
|
||||
CreateBuffer(1 * kMinUniformBufferOffsetAlignment + 4, wgpu::BufferUsage::Uniform);
|
||||
wgpu::BindGroup bindGroup = utils::MakeBindGroup(device, bgl,
|
||||
{
|
||||
{0, buffer3x, 0, 4},
|
||||
@@ -1638,7 +1668,7 @@ TEST_F(SetBindGroupValidationTest, DynamicOffsetOrder) {
|
||||
// Offset the first binding to touch the end of the buffer. Should succeed.
|
||||
// Will fail if the offset is applied to the first or second bindings since their buffers
|
||||
// are too small.
|
||||
offsets = {/* binding 0 */ 3 * kMinDynamicBufferOffsetAlignment,
|
||||
offsets = {/* binding 0 */ 3 * kMinUniformBufferOffsetAlignment,
|
||||
/* binding 2 */ 0,
|
||||
/* binding 3 */ 0};
|
||||
wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
|
||||
@@ -1650,7 +1680,7 @@ TEST_F(SetBindGroupValidationTest, DynamicOffsetOrder) {
|
||||
{
|
||||
// Offset the second binding to touch the end of the buffer. Should succeed.
|
||||
offsets = {/* binding 0 */ 0,
|
||||
/* binding 2 */ 1 * kMinDynamicBufferOffsetAlignment,
|
||||
/* binding 2 */ 1 * kMinUniformBufferOffsetAlignment,
|
||||
/* binding 3 */ 0};
|
||||
wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
|
||||
wgpu::ComputePassEncoder computePassEncoder = commandEncoder.BeginComputePass();
|
||||
@@ -1664,7 +1694,7 @@ TEST_F(SetBindGroupValidationTest, DynamicOffsetOrder) {
|
||||
// is too small.
|
||||
offsets = {/* binding 0 */ 0,
|
||||
/* binding 2 */ 0,
|
||||
/* binding 3 */ 2 * kMinDynamicBufferOffsetAlignment};
|
||||
/* binding 3 */ 2 * kMinUniformBufferOffsetAlignment};
|
||||
wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
|
||||
wgpu::ComputePassEncoder computePassEncoder = commandEncoder.BeginComputePass();
|
||||
computePassEncoder.SetBindGroup(0, bindGroup, offsets.size(), offsets.data());
|
||||
@@ -1673,9 +1703,9 @@ TEST_F(SetBindGroupValidationTest, DynamicOffsetOrder) {
|
||||
}
|
||||
{
|
||||
// Offset each binding to touch the end of their buffer. Should succeed.
|
||||
offsets = {/* binding 0 */ 3 * kMinDynamicBufferOffsetAlignment,
|
||||
/* binding 2 */ 1 * kMinDynamicBufferOffsetAlignment,
|
||||
/* binding 3 */ 2 * kMinDynamicBufferOffsetAlignment};
|
||||
offsets = {/* binding 0 */ 3 * kMinUniformBufferOffsetAlignment,
|
||||
/* binding 2 */ 1 * kMinUniformBufferOffsetAlignment,
|
||||
/* binding 3 */ 2 * kMinUniformBufferOffsetAlignment};
|
||||
wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
|
||||
wgpu::ComputePassEncoder computePassEncoder = commandEncoder.BeginComputePass();
|
||||
computePassEncoder.SetBindGroup(0, bindGroup, offsets.size(), offsets.data());
|
||||
|
||||
@@ -101,45 +101,30 @@ namespace {
|
||||
|
||||
// Test OOB color attachment indices are handled
|
||||
TEST_F(RenderPassDescriptorValidationTest, ColorAttachmentOutOfBounds) {
|
||||
wgpu::TextureView color0 =
|
||||
Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
|
||||
wgpu::TextureView color1 =
|
||||
Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
|
||||
wgpu::TextureView color2 =
|
||||
Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
|
||||
wgpu::TextureView color3 =
|
||||
Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
|
||||
// For setting the color attachment, control case
|
||||
std::array<wgpu::RenderPassColorAttachmentDescriptor, kMaxColorAttachments + 1>
|
||||
colorAttachments;
|
||||
for (uint32_t i = 0; i < colorAttachments.size(); i++) {
|
||||
colorAttachments[i].view =
|
||||
Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
|
||||
colorAttachments[i].resolveTarget = nullptr;
|
||||
colorAttachments[i].clearColor = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
colorAttachments[i].loadOp = wgpu::LoadOp::Clear;
|
||||
colorAttachments[i].storeOp = wgpu::StoreOp::Store;
|
||||
}
|
||||
|
||||
// Control case: kMaxColorAttachments is valid.
|
||||
{
|
||||
utils::ComboRenderPassDescriptor renderPass({color0, color1, color2, color3});
|
||||
wgpu::RenderPassDescriptor renderPass;
|
||||
renderPass.colorAttachmentCount = kMaxColorAttachments;
|
||||
renderPass.colorAttachments = colorAttachments.data();
|
||||
renderPass.depthStencilAttachment = nullptr;
|
||||
AssertBeginRenderPassSuccess(&renderPass);
|
||||
}
|
||||
// For setting the color attachment, OOB
|
||||
|
||||
// Error case: kMaxColorAttachments + 1 is an error.
|
||||
{
|
||||
// We cannot use utils::ComboRenderPassDescriptor here because it only supports at most
|
||||
// kMaxColorAttachments(4) color attachments.
|
||||
std::array<wgpu::RenderPassColorAttachmentDescriptor, 5> colorAttachments;
|
||||
colorAttachments[0].view = color0;
|
||||
colorAttachments[0].resolveTarget = nullptr;
|
||||
colorAttachments[0].clearColor = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
colorAttachments[0].loadOp = wgpu::LoadOp::Clear;
|
||||
colorAttachments[0].storeOp = wgpu::StoreOp::Store;
|
||||
|
||||
colorAttachments[1] = colorAttachments[0];
|
||||
colorAttachments[1].view = color1;
|
||||
|
||||
colorAttachments[2] = colorAttachments[0];
|
||||
colorAttachments[2].view = color2;
|
||||
|
||||
colorAttachments[3] = colorAttachments[0];
|
||||
colorAttachments[3].view = color3;
|
||||
|
||||
colorAttachments[4] = colorAttachments[0];
|
||||
colorAttachments[4].view =
|
||||
Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
|
||||
|
||||
wgpu::RenderPassDescriptor renderPass;
|
||||
renderPass.colorAttachmentCount = 5;
|
||||
renderPass.colorAttachmentCount = kMaxColorAttachments + 1;
|
||||
renderPass.colorAttachments = colorAttachments.data();
|
||||
renderPass.depthStencilAttachment = nullptr;
|
||||
AssertBeginRenderPassError(&renderPass);
|
||||
|
||||
@@ -199,12 +199,12 @@ TEST_F(VertexStateTest, SetInputStrideOutOfBounds) {
|
||||
// Control case, setting max input arrayStride
|
||||
utils::ComboVertexStateDescriptor state;
|
||||
state.vertexBufferCount = 1;
|
||||
state.cVertexBuffers[0].arrayStride = kMaxVertexBufferStride;
|
||||
state.cVertexBuffers[0].arrayStride = kMaxVertexBufferArrayStride;
|
||||
state.cVertexBuffers[0].attributeCount = 1;
|
||||
CreatePipeline(true, state, kDummyVertexShader);
|
||||
|
||||
// Test input arrayStride OOB
|
||||
state.cVertexBuffers[0].arrayStride = kMaxVertexBufferStride + 1;
|
||||
state.cVertexBuffers[0].arrayStride = kMaxVertexBufferArrayStride + 1;
|
||||
CreatePipeline(false, state, kDummyVertexShader);
|
||||
}
|
||||
|
||||
@@ -283,11 +283,11 @@ TEST_F(VertexStateTest, SetAttributeOffsetOutOfBounds) {
|
||||
utils::ComboVertexStateDescriptor state;
|
||||
state.vertexBufferCount = 1;
|
||||
state.cVertexBuffers[0].attributeCount = 1;
|
||||
state.cAttributes[0].offset = kMaxVertexBufferStride - sizeof(wgpu::VertexFormat::Float32);
|
||||
state.cAttributes[0].offset = kMaxVertexBufferArrayStride - sizeof(wgpu::VertexFormat::Float32);
|
||||
CreatePipeline(true, state, kDummyVertexShader);
|
||||
|
||||
// Test attribute offset out of bounds
|
||||
state.cAttributes[0].offset = kMaxVertexBufferStride - 1;
|
||||
state.cAttributes[0].offset = kMaxVertexBufferArrayStride - 1;
|
||||
CreatePipeline(false, state, kDummyVertexShader);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user