mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 08:27:05 +00:00
Descriptorize BindGroups.
This commit adds utils::MakeBindGroup to make code craeting bind groups nicer to read. Additional tests are added that give 100% coverage of ValidateBindGroupDescriptor. BUG=dawn:3 Change-Id: I56e1da8c2952306ad233845b0ec3ec32aef793d9 Reviewed-on: https://dawn-review.googlesource.com/c/2802 Reviewed-by: Jiawei Shao <jiawei.shao@intel.com> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
006f218392
commit
6f9d21e805
@@ -68,10 +68,7 @@ TEST_P(BindGroupTests, ReusedBindGroupSingleSubmit) {
|
||||
dawn::Buffer buffer = device.CreateBuffer(&bufferDesc);
|
||||
dawn::BufferView bufferView =
|
||||
buffer.CreateBufferViewBuilder().SetExtent(0, sizeof(float)).GetResult();
|
||||
dawn::BindGroup bindGroup = device.CreateBindGroupBuilder()
|
||||
.SetLayout(bgl)
|
||||
.SetBufferViews(0, 1, &bufferView)
|
||||
.GetResult();
|
||||
dawn::BindGroup bindGroup = utils::MakeBindGroup(device, bgl, {{0, bufferView}});
|
||||
|
||||
dawn::CommandBuffer cb[2];
|
||||
cb[0] = CreateSimpleComputeCommandBuffer(cp, bindGroup);
|
||||
@@ -143,11 +140,10 @@ TEST_P(BindGroupTests, ReusedUBO) {
|
||||
buffer.CreateBufferViewBuilder().SetExtent(0, sizeof(Data::transform)).GetResult();
|
||||
dawn::BufferView fragUBOBufferView =
|
||||
buffer.CreateBufferViewBuilder().SetExtent(256, sizeof(Data::color)).GetResult();
|
||||
dawn::BindGroup bindGroup = device.CreateBindGroupBuilder()
|
||||
.SetLayout(bgl)
|
||||
.SetBufferViews(0, 1, &vertUBOBufferView)
|
||||
.SetBufferViews(1, 1, &fragUBOBufferView)
|
||||
.GetResult();
|
||||
dawn::BindGroup bindGroup = utils::MakeBindGroup(device, bgl, {
|
||||
{0, vertUBOBufferView},
|
||||
{1, fragUBOBufferView}
|
||||
});
|
||||
|
||||
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||
@@ -250,12 +246,11 @@ TEST_P(BindGroupTests, UBOSamplerAndTexture) {
|
||||
data[i] = RGBA8(0, 255, 0, 255);
|
||||
}
|
||||
dawn::Buffer stagingBuffer = utils::CreateBufferFromData(device, data.data(), sizeInBytes, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::BindGroup bindGroup = device.CreateBindGroupBuilder()
|
||||
.SetLayout(bgl)
|
||||
.SetBufferViews(0, 1, &vertUBOBufferView)
|
||||
.SetSamplers(1, 1, &sampler)
|
||||
.SetTextureViews(2, 1, &textureView)
|
||||
.GetResult();
|
||||
dawn::BindGroup bindGroup = utils::MakeBindGroup(device, bgl, {
|
||||
{0, vertUBOBufferView},
|
||||
{1, sampler},
|
||||
{2, textureView}
|
||||
});
|
||||
|
||||
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||
dawn::BufferCopyView bufferCopyView =
|
||||
|
||||
@@ -101,10 +101,7 @@ class BlendStateTest : public DawnTest {
|
||||
.SetExtent(0, bufferSize)
|
||||
.GetResult();
|
||||
|
||||
return device.CreateBindGroupBuilder()
|
||||
.SetLayout(bindGroupLayout)
|
||||
.SetBufferViews(0, 1, &view)
|
||||
.GetResult();
|
||||
return utils::MakeBindGroup(device, bindGroupLayout, {{0, view}});
|
||||
}
|
||||
|
||||
// Test that after drawing a triangle with the base color, and then the given triangle spec, the color is as expected
|
||||
|
||||
@@ -73,11 +73,10 @@ void ComputeCopyStorageBufferTests::BasicTest(const char* shader) {
|
||||
dst.CreateBufferViewBuilder().SetExtent(0, kNumUints * sizeof(uint32_t)).GetResult();
|
||||
|
||||
// Set up bind group and issue dispatch
|
||||
auto bindGroup = device.CreateBindGroupBuilder()
|
||||
.SetLayout(bgl)
|
||||
.SetBufferViews(0, 1, &srcView)
|
||||
.SetBufferViews(1, 1, &dstView)
|
||||
.GetResult();
|
||||
dawn::BindGroup bindGroup = utils::MakeBindGroup(device, bgl, {
|
||||
{0, srcView},
|
||||
{1, dstView},
|
||||
});
|
||||
|
||||
dawn::CommandBuffer commands;
|
||||
{
|
||||
|
||||
@@ -214,10 +214,7 @@ class DepthStencilStateTest : public DawnTest {
|
||||
.GetResult();
|
||||
|
||||
// Create a bind group for the data
|
||||
dawn::BindGroup bindGroup = device.CreateBindGroupBuilder()
|
||||
.SetLayout(bindGroupLayout)
|
||||
.SetBufferViews(0, 1, &view)
|
||||
.GetResult();
|
||||
dawn::BindGroup bindGroup = utils::MakeBindGroup(device, bindGroupLayout, {{0, view}});
|
||||
|
||||
// Create a pipeline for the triangles with the test spec's depth stencil state
|
||||
dawn::RenderPipeline pipeline = device.CreateRenderPipelineBuilder()
|
||||
|
||||
@@ -56,10 +56,17 @@ class PushConstantTest: public DawnTest {
|
||||
buf2.CreateBufferViewBuilder().SetExtent(0, 4).GetResult(),
|
||||
};
|
||||
|
||||
dawn::BindGroup bg = device.CreateBindGroupBuilder()
|
||||
.SetLayout(bgl)
|
||||
.SetBufferViews(0, extraBuffer ? 2 : 1, views)
|
||||
.GetResult();
|
||||
dawn::BindGroup bg;
|
||||
if (extraBuffer) {
|
||||
bg = utils::MakeBindGroup(device, bgl, {
|
||||
{0, views[0]},
|
||||
{1, views[1]},
|
||||
});
|
||||
} else {
|
||||
bg = utils::MakeBindGroup(device, bgl, {
|
||||
{0, views[0]},
|
||||
});
|
||||
}
|
||||
|
||||
return {std::move(pl), std::move(bg), std::move(buf1)};
|
||||
}
|
||||
|
||||
@@ -126,11 +126,10 @@ protected:
|
||||
sampler = device.CreateSampler(&descriptor);
|
||||
}
|
||||
|
||||
auto bindGroup = device.CreateBindGroupBuilder()
|
||||
.SetLayout(mBindGroupLayout)
|
||||
.SetSamplers(0, 1, &sampler)
|
||||
.SetTextureViews(1, 1, &mTextureView)
|
||||
.GetResult();
|
||||
dawn::BindGroup bindGroup = utils::MakeBindGroup(device, mBindGroupLayout, {
|
||||
{0, sampler},
|
||||
{1, mTextureView}
|
||||
});
|
||||
|
||||
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||
{
|
||||
|
||||
@@ -155,11 +155,10 @@ protected:
|
||||
}
|
||||
|
||||
void Verify(const dawn::TextureView &textureView, const char* fragmentShader, int expected) {
|
||||
dawn::BindGroup bindGroup = device.CreateBindGroupBuilder()
|
||||
.SetLayout(mBindGroupLayout)
|
||||
.SetSamplers(0, 1, &mSampler)
|
||||
.SetTextureViews(1, 1, &textureView)
|
||||
.GetResult();
|
||||
dawn::BindGroup bindGroup = utils::MakeBindGroup(device, mBindGroupLayout, {
|
||||
{0, mSampler},
|
||||
{1, textureView}
|
||||
});
|
||||
|
||||
dawn::ShaderModule fsModule =
|
||||
utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, fragmentShader);
|
||||
|
||||
@@ -494,21 +494,39 @@ TEST_F(WireTests, StructureOfStructureArrayArgument) {
|
||||
}
|
||||
|
||||
// Test passing nullptr instead of objects - object as value version
|
||||
TEST_F(WireTests, DISABLED_NullptrAsValue) {
|
||||
dawnCommandBufferBuilder builder = dawnDeviceCreateCommandBufferBuilder(device);
|
||||
dawnComputePassEncoder pass = dawnCommandBufferBuilderBeginComputePass(builder);
|
||||
dawnComputePassEncoderSetComputePipeline(pass, nullptr);
|
||||
TEST_F(WireTests, OptionalObjectValue) {
|
||||
dawnBindGroupLayoutDescriptor bglDesc;
|
||||
bglDesc.nextInChain = nullptr;
|
||||
bglDesc.numBindings = 0;
|
||||
dawnBindGroupLayout bgl = dawnDeviceCreateBindGroupLayout(device, &bglDesc);
|
||||
|
||||
dawnCommandBufferBuilder apiBuilder = api.GetNewCommandBufferBuilder();
|
||||
EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
|
||||
.WillOnce(Return(apiBuilder));
|
||||
dawnBindGroupLayout apiBindGroupLayout = api.GetNewBindGroupLayout();
|
||||
EXPECT_CALL(api, DeviceCreateBindGroupLayout(apiDevice, _))
|
||||
.WillOnce(Return(apiBindGroupLayout));
|
||||
|
||||
dawnComputePassEncoder apiPass = api.GetNewComputePassEncoder();
|
||||
EXPECT_CALL(api, CommandBufferBuilderBeginComputePass(apiBuilder))
|
||||
.WillOnce(Return(apiPass));
|
||||
// The `sampler`, `textureView` and `bufferView` members of a binding are optional.
|
||||
dawnBindGroupBinding binding;
|
||||
binding.binding = 0;
|
||||
binding.sampler = nullptr;
|
||||
binding.textureView = nullptr;
|
||||
binding.bufferView = nullptr;
|
||||
|
||||
EXPECT_CALL(api, ComputePassEncoderSetComputePipeline(apiPass, nullptr))
|
||||
.Times(1);
|
||||
dawnBindGroupDescriptor bgDesc;
|
||||
bgDesc.nextInChain = nullptr;
|
||||
bgDesc.layout = bgl;
|
||||
bgDesc.numBindings = 1;
|
||||
bgDesc.bindings = &binding;
|
||||
|
||||
dawnDeviceCreateBindGroup(device, &bgDesc);
|
||||
EXPECT_CALL(api, DeviceCreateBindGroup(apiDevice, MatchesLambda([](const dawnBindGroupDescriptor* desc) -> bool {
|
||||
return desc->nextInChain == nullptr &&
|
||||
desc->numBindings == 1 &&
|
||||
desc->bindings[0].binding == 0 &&
|
||||
desc->bindings[0].sampler == nullptr &&
|
||||
desc->bindings[0].bufferView == nullptr &&
|
||||
desc->bindings[0].textureView == nullptr;
|
||||
})))
|
||||
.WillOnce(Return(nullptr));
|
||||
|
||||
FlushClient();
|
||||
}
|
||||
|
||||
@@ -18,98 +18,350 @@
|
||||
#include "utils/DawnHelpers.h"
|
||||
|
||||
class BindGroupValidationTest : public ValidationTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
// Create objects to use as resources inside test bind groups.
|
||||
{
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 1024;
|
||||
descriptor.usage = dawn::BufferUsageBit::Uniform;
|
||||
mUBO = device.CreateBuffer(&descriptor);
|
||||
}
|
||||
{
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 1024;
|
||||
descriptor.usage = dawn::BufferUsageBit::Storage;
|
||||
mSSBO = device.CreateBuffer(&descriptor);
|
||||
}
|
||||
{
|
||||
dawn::SamplerDescriptor descriptor = utils::GetDefaultSamplerDescriptor();
|
||||
mSampler = device.CreateSampler(&descriptor);
|
||||
}
|
||||
{
|
||||
dawn::TextureDescriptor descriptor;
|
||||
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||
descriptor.size = {16, 16, 1};
|
||||
descriptor.arrayLayer = 1;
|
||||
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||
descriptor.levelCount = 1;
|
||||
descriptor.usage = dawn::TextureUsageBit::Sampled;
|
||||
mSampledTexture = device.CreateTexture(&descriptor);
|
||||
mSampledTextureView = mSampledTexture.CreateDefaultTextureView();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
dawn::Buffer mUBO;
|
||||
dawn::Buffer mSSBO;
|
||||
dawn::Sampler mSampler;
|
||||
dawn::Texture mSampledTexture;
|
||||
dawn::TextureView mSampledTextureView;
|
||||
};
|
||||
|
||||
// Test the validation of BindGroupDescriptor::nextInChain
|
||||
TEST_F(BindGroupValidationTest, NextInChainNullptr) {
|
||||
dawn::BindGroupLayout layout = utils::MakeBindGroupLayout(device, {});
|
||||
|
||||
dawn::BindGroupDescriptor descriptor;
|
||||
descriptor.layout = layout;
|
||||
descriptor.numBindings = 0;
|
||||
descriptor.bindings = nullptr;
|
||||
|
||||
// Control case: check that nextInChain = nullptr is valid
|
||||
descriptor.nextInChain = nullptr;
|
||||
device.CreateBindGroup(&descriptor);
|
||||
|
||||
// Check that nextInChain != nullptr is an error.
|
||||
descriptor.nextInChain = static_cast<void*>(&descriptor);
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
|
||||
}
|
||||
|
||||
// Check constraints on numBindings
|
||||
TEST_F(BindGroupValidationTest, NumBindingsMismatch) {
|
||||
dawn::BindGroupLayout layout = utils::MakeBindGroupLayout(device, {
|
||||
{0, dawn::ShaderStageBit::Fragment, dawn::BindingType::Sampler}
|
||||
});
|
||||
|
||||
// Control case: check that a descriptor with one binding is ok
|
||||
utils::MakeBindGroup(device, layout, {{0, mSampler}});
|
||||
|
||||
// Check that numBindings != layout.numBindings fails.
|
||||
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {}));
|
||||
}
|
||||
|
||||
// Check constraints on BindGroupBinding::binding
|
||||
TEST_F(BindGroupValidationTest, WrongBindings) {
|
||||
dawn::BindGroupLayout layout = utils::MakeBindGroupLayout(device, {
|
||||
{0, dawn::ShaderStageBit::Fragment, dawn::BindingType::Sampler}
|
||||
});
|
||||
|
||||
// Control case: check that a descriptor with a binding matching the layout's is ok
|
||||
utils::MakeBindGroup(device, layout, {{0, mSampler}});
|
||||
|
||||
// Check that binding must be present in the layout
|
||||
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{1, mSampler}}));
|
||||
|
||||
// Check that binding >= kMaxBindingsPerGroup fails.
|
||||
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{kMaxBindingsPerGroup, mSampler}}));
|
||||
}
|
||||
|
||||
// Check that the same binding cannot be set twice
|
||||
TEST_F(BindGroupValidationTest, BindingSetTwice) {
|
||||
dawn::BindGroupLayout layout = utils::MakeBindGroupLayout(device, {
|
||||
{0, dawn::ShaderStageBit::Fragment, dawn::BindingType::Sampler},
|
||||
{1, dawn::ShaderStageBit::Fragment, dawn::BindingType::Sampler}
|
||||
});
|
||||
|
||||
// Control case: check that different bindings work
|
||||
utils::MakeBindGroup(device, layout, {
|
||||
{0, mSampler},
|
||||
{1, mSampler}
|
||||
});
|
||||
|
||||
// Check that setting the same binding twice is invalid
|
||||
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {
|
||||
{0, mSampler},
|
||||
{0, mSampler}
|
||||
}));
|
||||
}
|
||||
|
||||
// Check that a sampler binding must contain exactly one sampler
|
||||
TEST_F(BindGroupValidationTest, SamplerBindingType) {
|
||||
dawn::BindGroupLayout layout = utils::MakeBindGroupLayout(device, {
|
||||
{0, dawn::ShaderStageBit::Fragment, dawn::BindingType::Sampler}
|
||||
});
|
||||
|
||||
dawn::BindGroupBinding binding;
|
||||
binding.binding = 0;
|
||||
binding.sampler = nullptr;
|
||||
binding.textureView = nullptr;
|
||||
binding.bufferView = nullptr;
|
||||
|
||||
dawn::BindGroupDescriptor descriptor;
|
||||
descriptor.nextInChain = nullptr;
|
||||
descriptor.layout = layout;
|
||||
descriptor.numBindings = 1;
|
||||
descriptor.bindings = &binding;
|
||||
|
||||
// Not setting anything fails
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
|
||||
|
||||
// Control case: setting just the sampler works
|
||||
binding.sampler = mSampler;
|
||||
device.CreateBindGroup(&descriptor);
|
||||
|
||||
// Setting the texture view as well is an error
|
||||
binding.textureView = mSampledTextureView;
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
|
||||
binding.textureView = nullptr;
|
||||
|
||||
// Setting the buffer view as well is an error
|
||||
binding.bufferView = mUBO.CreateBufferViewBuilder().SetExtent(0, 256).GetResult();
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
|
||||
binding.bufferView = nullptr;
|
||||
}
|
||||
|
||||
// Check that a texture binding must contain exactly a texture view
|
||||
TEST_F(BindGroupValidationTest, TextureBindingType) {
|
||||
dawn::BindGroupLayout layout = utils::MakeBindGroupLayout(device, {
|
||||
{0, dawn::ShaderStageBit::Fragment, dawn::BindingType::SampledTexture}
|
||||
});
|
||||
|
||||
dawn::BindGroupBinding binding;
|
||||
binding.binding = 0;
|
||||
binding.sampler = nullptr;
|
||||
binding.textureView = nullptr;
|
||||
binding.bufferView = nullptr;
|
||||
|
||||
dawn::BindGroupDescriptor descriptor;
|
||||
descriptor.nextInChain = nullptr;
|
||||
descriptor.layout = layout;
|
||||
descriptor.numBindings = 1;
|
||||
descriptor.bindings = &binding;
|
||||
|
||||
// Not setting anything fails
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
|
||||
|
||||
// Control case: setting just the texture view works
|
||||
binding.textureView = mSampledTextureView;
|
||||
device.CreateBindGroup(&descriptor);
|
||||
|
||||
// Setting the sampler as well is an error
|
||||
binding.sampler = mSampler;
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
|
||||
binding.textureView = nullptr;
|
||||
|
||||
// Setting the buffer view as well is an error
|
||||
binding.bufferView = mUBO.CreateBufferViewBuilder().SetExtent(0, 256).GetResult();
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
|
||||
binding.bufferView = nullptr;
|
||||
}
|
||||
|
||||
// Check that a buffer binding must contain exactly a buffer view
|
||||
TEST_F(BindGroupValidationTest, BufferBindingType) {
|
||||
dawn::BindGroupLayout layout = utils::MakeBindGroupLayout(device, {
|
||||
{0, dawn::ShaderStageBit::Fragment, dawn::BindingType::UniformBuffer}
|
||||
});
|
||||
|
||||
dawn::BindGroupBinding binding;
|
||||
binding.binding = 0;
|
||||
binding.sampler = nullptr;
|
||||
binding.textureView = nullptr;
|
||||
binding.bufferView = nullptr;
|
||||
|
||||
dawn::BindGroupDescriptor descriptor;
|
||||
descriptor.nextInChain = nullptr;
|
||||
descriptor.layout = layout;
|
||||
descriptor.numBindings = 1;
|
||||
descriptor.bindings = &binding;
|
||||
|
||||
// Not setting anything fails
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
|
||||
|
||||
// Control case: setting just the buffer view works
|
||||
binding.bufferView = mUBO.CreateBufferViewBuilder().SetExtent(0, 256).GetResult();
|
||||
device.CreateBindGroup(&descriptor);
|
||||
|
||||
// Setting the texture view as well is an error
|
||||
binding.textureView = mSampledTextureView;
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
|
||||
binding.textureView = nullptr;
|
||||
|
||||
// Setting the sampler as well is an error
|
||||
binding.sampler = mSampler;
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
|
||||
binding.sampler = nullptr;
|
||||
}
|
||||
|
||||
// Check that a texture must have the correct usage
|
||||
TEST_F(BindGroupValidationTest, TextureUsage) {
|
||||
dawn::BindGroupLayout layout = utils::MakeBindGroupLayout(device, {
|
||||
{0, dawn::ShaderStageBit::Fragment, dawn::BindingType::SampledTexture}
|
||||
});
|
||||
|
||||
// Control case: setting a sampleable texture view works.
|
||||
utils::MakeBindGroup(device, layout, {{0, mSampledTextureView}});
|
||||
|
||||
// Make an output attachment texture and try to set it for a SampledTexture binding
|
||||
dawn::TextureDescriptor descriptor;
|
||||
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||
descriptor.size = {16, 16, 1};
|
||||
descriptor.arrayLayer = 1;
|
||||
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||
descriptor.levelCount = 1;
|
||||
descriptor.usage = dawn::TextureUsageBit::OutputAttachment;
|
||||
dawn::Texture outputTexture = device.CreateTexture(&descriptor);
|
||||
dawn::TextureView outputTextureView = outputTexture.CreateDefaultTextureView();
|
||||
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, outputTextureView}}));
|
||||
}
|
||||
|
||||
// Check that a UBO must have the correct usage
|
||||
TEST_F(BindGroupValidationTest, BufferUsageUBO) {
|
||||
dawn::BindGroupLayout layout = utils::MakeBindGroupLayout(device, {
|
||||
{0, dawn::ShaderStageBit::Fragment, dawn::BindingType::UniformBuffer}
|
||||
});
|
||||
|
||||
dawn::BufferView uboView = mUBO.CreateBufferViewBuilder().SetExtent(0, 256).GetResult();
|
||||
dawn::BufferView ssboView = mSSBO.CreateBufferViewBuilder().SetExtent(0, 256).GetResult();
|
||||
|
||||
// Control case: using a buffer with the uniform usage works
|
||||
utils::MakeBindGroup(device, layout, {{0, uboView}});
|
||||
|
||||
// Using a buffer without the uniform usage fails
|
||||
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, ssboView}}));
|
||||
}
|
||||
|
||||
// Check that a SSBO must have the correct usage
|
||||
TEST_F(BindGroupValidationTest, BufferUsageSSBO) {
|
||||
dawn::BindGroupLayout layout = utils::MakeBindGroupLayout(device, {
|
||||
{0, dawn::ShaderStageBit::Fragment, dawn::BindingType::StorageBuffer}
|
||||
});
|
||||
|
||||
dawn::BufferView uboView = mUBO.CreateBufferViewBuilder().SetExtent(0, 256).GetResult();
|
||||
dawn::BufferView ssboView = mSSBO.CreateBufferViewBuilder().SetExtent(0, 256).GetResult();
|
||||
|
||||
// Control case: using a buffer with the storage usage works
|
||||
utils::MakeBindGroup(device, layout, {{0, ssboView}});
|
||||
|
||||
// Using a buffer without the storage usage fails
|
||||
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, uboView}}));
|
||||
}
|
||||
|
||||
// Tests constraints on the buffer view offset for bind groups.
|
||||
TEST_F(BindGroupValidationTest, BufferViewOffset) {
|
||||
auto layout = utils::MakeBindGroupLayout(
|
||||
device, {
|
||||
{0, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer},
|
||||
});
|
||||
|
||||
dawn::Buffer buffer;
|
||||
{
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 512;
|
||||
descriptor.usage = dawn::BufferUsageBit::Uniform;
|
||||
buffer = device.CreateBuffer(&descriptor);
|
||||
}
|
||||
dawn::BindGroupLayout layout = utils::MakeBindGroupLayout(device, {
|
||||
{0, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer},
|
||||
});
|
||||
|
||||
// Check that offset 0 is valid
|
||||
{
|
||||
auto bufferView = buffer.CreateBufferViewBuilder()
|
||||
dawn::BufferView bufferView = mUBO.CreateBufferViewBuilder()
|
||||
.SetExtent(0, 512)
|
||||
.GetResult();
|
||||
|
||||
auto bindGroup = AssertWillBeSuccess(device.CreateBindGroupBuilder())
|
||||
.SetLayout(layout)
|
||||
.SetBufferViews(0, 1, &bufferView)
|
||||
.GetResult();
|
||||
utils::MakeBindGroup(device, layout, {{0, bufferView}});
|
||||
}
|
||||
|
||||
// Check that offset 256 (aligned) is valid
|
||||
{
|
||||
auto bufferView = buffer.CreateBufferViewBuilder()
|
||||
dawn::BufferView bufferView = mUBO.CreateBufferViewBuilder()
|
||||
.SetExtent(256, 256)
|
||||
.GetResult();
|
||||
|
||||
auto bindGroup = AssertWillBeSuccess(device.CreateBindGroupBuilder())
|
||||
.SetLayout(layout)
|
||||
.SetBufferViews(0, 1, &bufferView)
|
||||
.GetResult();
|
||||
utils::MakeBindGroup(device, layout, {{0, bufferView}});
|
||||
}
|
||||
|
||||
// Check cases where unaligned buffer view offset is invalid
|
||||
{
|
||||
auto bufferView = buffer.CreateBufferViewBuilder()
|
||||
dawn::BufferView bufferView = mUBO.CreateBufferViewBuilder()
|
||||
.SetExtent(1, 256)
|
||||
.GetResult();
|
||||
|
||||
auto bindGroup = AssertWillBeError(device.CreateBindGroupBuilder())
|
||||
.SetLayout(layout)
|
||||
.SetBufferViews(0, 1, &bufferView)
|
||||
.GetResult();
|
||||
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, bufferView}}));
|
||||
}
|
||||
|
||||
{
|
||||
auto bufferView = buffer.CreateBufferViewBuilder()
|
||||
.SetExtent(64, 256)
|
||||
.GetResult();
|
||||
|
||||
auto bindGroup = AssertWillBeError(device.CreateBindGroupBuilder())
|
||||
.SetLayout(layout)
|
||||
.SetBufferViews(0, 1, &bufferView)
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
{
|
||||
auto bufferView = buffer.CreateBufferViewBuilder()
|
||||
dawn::BufferView bufferView = mUBO.CreateBufferViewBuilder()
|
||||
.SetExtent(128, 256)
|
||||
.GetResult();
|
||||
|
||||
auto bindGroup = AssertWillBeError(device.CreateBindGroupBuilder())
|
||||
.SetLayout(layout)
|
||||
.SetBufferViews(0, 1, &bufferView)
|
||||
.GetResult();
|
||||
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, bufferView}}));
|
||||
}
|
||||
|
||||
{
|
||||
auto bufferView = buffer.CreateBufferViewBuilder()
|
||||
dawn::BufferView bufferView = mUBO.CreateBufferViewBuilder()
|
||||
.SetExtent(255, 256)
|
||||
.GetResult();
|
||||
|
||||
auto bindGroup = AssertWillBeError(device.CreateBindGroupBuilder())
|
||||
.SetLayout(layout)
|
||||
.SetBufferViews(0, 1, &bufferView)
|
||||
.GetResult();
|
||||
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, bufferView}}));
|
||||
}
|
||||
}
|
||||
|
||||
class BindGroupLayoutValidationTest : public ValidationTest {
|
||||
};
|
||||
|
||||
// Tests setting OOB checks for kMaxBindingsPerGroup in bind group layouts.
|
||||
TEST_F(BindGroupLayoutValidationTest, BindGroupLayoutBindingOOB) {
|
||||
// Checks that kMaxBindingsPerGroup - 1 is valid.
|
||||
utils::MakeBindGroupLayout(device, {
|
||||
{kMaxBindingsPerGroup - 1, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer}
|
||||
});
|
||||
|
||||
// Checks that kMaxBindingsPerGroup is OOB
|
||||
ASSERT_DEVICE_ERROR(utils::MakeBindGroupLayout(device, {
|
||||
{kMaxBindingsPerGroup, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer}
|
||||
}));
|
||||
}
|
||||
|
||||
// This test verifies that the BindGroupLayout bindings are correctly validated, even if the
|
||||
// binding ids are out-of-order.
|
||||
TEST_F(BindGroupLayoutValidationTest, BindGroupBinding) {
|
||||
auto layout = utils::MakeBindGroupLayout(
|
||||
device, {
|
||||
{1, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer},
|
||||
{0, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// This test verifies that the BindGroupLayout cache is successfully caching/deduplicating objects.
|
||||
//
|
||||
// NOTE: This test only works currently because unittests are run without the wire - so the returned
|
||||
// BindGroupLayout pointers are actually visibly equivalent. With the wire, this would not be true.
|
||||
TEST_F(BindGroupValidationTest, BindGroupLayoutCache) {
|
||||
TEST_F(BindGroupLayoutValidationTest, BindGroupLayoutCache) {
|
||||
auto layout1 = utils::MakeBindGroupLayout(
|
||||
device, {
|
||||
{0, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer},
|
||||
@@ -122,26 +374,3 @@ TEST_F(BindGroupValidationTest, BindGroupLayoutCache) {
|
||||
// Caching should cause these to be the same.
|
||||
ASSERT_EQ(layout1.Get(), layout2.Get());
|
||||
}
|
||||
|
||||
// This test verifies that the BindGroupLayout bindings are correctly validated, even if the
|
||||
// binding ids are out-of-order.
|
||||
TEST_F(BindGroupValidationTest, BindGroupBinding) {
|
||||
auto layout = utils::MakeBindGroupLayout(
|
||||
device, {
|
||||
{1, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer},
|
||||
{0, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer},
|
||||
});
|
||||
}
|
||||
|
||||
// Tests setting OOB checks for kMaxBindingsPerGroup in bind group layouts.
|
||||
TEST_F(BindGroupValidationTest, BindGroupLayoutBindingOOB) {
|
||||
// Checks that kMaxBindingsPerGroup - 1 is valid.
|
||||
utils::MakeBindGroupLayout(device, {
|
||||
{kMaxBindingsPerGroup - 1, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer}
|
||||
});
|
||||
|
||||
// Checks that kMaxBindingsPerGroup is OOB
|
||||
ASSERT_DEVICE_ERROR(utils::MakeBindGroupLayout(device, {
|
||||
{kMaxBindingsPerGroup, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer}
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -75,10 +75,7 @@ TEST_F(CommandBufferValidationTest, BufferWithReadAndWriteUsage) {
|
||||
0, dawn::ShaderStageBit::Vertex, dawn::BindingType::StorageBuffer
|
||||
}});
|
||||
dawn::BufferView view = buffer.CreateBufferViewBuilder().SetExtent(0, 4).GetResult();
|
||||
dawn::BindGroup bg = device.CreateBindGroupBuilder()
|
||||
.SetLayout(bgl)
|
||||
.SetBufferViews(0, 1, &view)
|
||||
.GetResult();
|
||||
dawn::BindGroup bg = utils::MakeBindGroup(device, bgl, {{0, view}});
|
||||
|
||||
// Use the buffer as both index and storage in the same pass
|
||||
dawn::CommandBufferBuilder builder = AssertWillBeError(device.CreateCommandBufferBuilder());
|
||||
@@ -107,10 +104,7 @@ TEST_F(CommandBufferValidationTest, TextureWithReadAndWriteUsage) {
|
||||
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout(device, {{
|
||||
0, dawn::ShaderStageBit::Vertex, dawn::BindingType::SampledTexture
|
||||
}});
|
||||
dawn::BindGroup bg = device.CreateBindGroupBuilder()
|
||||
.SetLayout(bgl)
|
||||
.SetTextureViews(0, 1, &view)
|
||||
.GetResult();
|
||||
dawn::BindGroup bg = utils::MakeBindGroup(device, bgl, {{0, view}});
|
||||
|
||||
// Create the render pass that will use the texture as an output attachment
|
||||
dawn::RenderPassDescriptor renderPass = device.CreateRenderPassDescriptorBuilder()
|
||||
|
||||
Reference in New Issue
Block a user