Autoformat all tests and examples

Bug: none
Change-Id: I69904944db1d4c2fbcca74bb8b66b5a7524e76bb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/24642
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Kai Ninomiya
2020-07-10 20:33:08 +00:00
committed by Commit Bot service account
parent 3d80b5c378
commit 2afea0c671
83 changed files with 3604 additions and 3481 deletions

View File

@@ -121,16 +121,10 @@ TEST_F(BindGroupValidationTest, BindingSetTwice) {
{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::Sampler}});
// Control case: check that different bindings work
utils::MakeBindGroup(device, layout, {
{0, mSampler},
{1, mSampler}
});
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}
}));
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, mSampler}, {0, mSampler}}));
}
// Check that a sampler binding must contain exactly one sampler
@@ -406,7 +400,7 @@ TEST_F(BindGroupValidationTest, BufferBindingOOB) {
utils::MakeBindGroup(device, layout, {{0, buffer, 0, 256}});
// Success case, touching the end of the buffer works
utils::MakeBindGroup(device, layout, {{0, buffer, 3*256, 256}});
utils::MakeBindGroup(device, layout, {{0, buffer, 3 * 256, 256}});
// Error case, zero size is invalid.
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 1024, 0}}));
@@ -419,16 +413,17 @@ TEST_F(BindGroupValidationTest, BufferBindingOOB) {
utils::MakeBindGroup(device, layout, {{0, buffer, 256, wgpu::kWholeSize}});
// Error case, offset is OOB
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 256*5, 0}}));
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 256 * 5, 0}}));
// Error case, size is OOB
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 0, 256*5}}));
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 0, 256 * 5}}));
// Error case, offset+size is OOB
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 1024, 256}}));
// Error case, offset+size overflows to be 0
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 256, uint32_t(0) - uint32_t(256)}}));
ASSERT_DEVICE_ERROR(
utils::MakeBindGroup(device, layout, {{0, buffer, 256, uint32_t(0) - uint32_t(256)}}));
}
// Tests constraints to be sure the uniform buffer binding isn't too large
@@ -1191,8 +1186,8 @@ TEST_F(SetBindGroupValidationTest, DynamicOffsetOrder) {
// Create buffers which are 3x, 2x, and 1x the size of the minimum buffer offset, plus 4 bytes
// to spare (to avoid zero-sized bindings). We will offset the bindings so they reach the very
// 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.
// 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);
wgpu::Buffer buffer2x =
@@ -1487,7 +1482,6 @@ class BindGroupLayoutCompatibilityTest : public ValidationTest {
wgpu::RenderPipeline CreateFSRenderPipeline(
const char* fsShader,
std::vector<wgpu::BindGroupLayout> bindGroupLayout) {
wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
@@ -1520,7 +1514,7 @@ class BindGroupLayoutCompatibilityTest : public ValidationTest {
layout(location = 0) out vec4 fragColor;
void main() {
})",
std::move(bindGroupLayout));
std::move(bindGroupLayout));
}
wgpu::ComputePipeline CreateComputePipeline(
@@ -1558,7 +1552,7 @@ class BindGroupLayoutCompatibilityTest : public ValidationTest {
} rdst;
void main() {
})",
std::move(bindGroupLayout));
std::move(bindGroupLayout));
}
};

View File

@@ -21,13 +21,13 @@
using namespace testing;
class MockBufferMapReadCallback {
public:
MOCK_METHOD(void,
Call,
(WGPUBufferMapAsyncStatus status,
const uint32_t* ptr,
uint64_t dataLength,
void* userdata));
public:
MOCK_METHOD(void,
Call,
(WGPUBufferMapAsyncStatus status,
const uint32_t* ptr,
uint64_t dataLength,
void* userdata));
};
static std::unique_ptr<MockBufferMapReadCallback> mockBufferMapReadCallback;
@@ -41,11 +41,11 @@ static void ToMockBufferMapReadCallback(WGPUBufferMapAsyncStatus status,
}
class MockBufferMapWriteCallback {
public:
MOCK_METHOD(
void,
Call,
(WGPUBufferMapAsyncStatus status, uint32_t* ptr, uint64_t dataLength, void* userdata));
public:
MOCK_METHOD(
void,
Call,
(WGPUBufferMapAsyncStatus status, uint32_t* ptr, uint64_t dataLength, void* userdata));
};
static std::unique_ptr<MockBufferMapWriteCallback> mockBufferMapWriteCallback;
@@ -59,57 +59,57 @@ static void ToMockBufferMapWriteCallback(WGPUBufferMapAsyncStatus status,
}
class BufferValidationTest : public ValidationTest {
protected:
wgpu::Buffer CreateMapReadBuffer(uint64_t size) {
wgpu::BufferDescriptor descriptor;
descriptor.size = size;
descriptor.usage = wgpu::BufferUsage::MapRead;
protected:
wgpu::Buffer CreateMapReadBuffer(uint64_t size) {
wgpu::BufferDescriptor descriptor;
descriptor.size = size;
descriptor.usage = wgpu::BufferUsage::MapRead;
return device.CreateBuffer(&descriptor);
}
wgpu::Buffer CreateMapWriteBuffer(uint64_t size) {
wgpu::BufferDescriptor descriptor;
descriptor.size = size;
descriptor.usage = wgpu::BufferUsage::MapWrite;
return device.CreateBuffer(&descriptor);
}
wgpu::Buffer CreateMapWriteBuffer(uint64_t size) {
wgpu::BufferDescriptor descriptor;
descriptor.size = size;
descriptor.usage = wgpu::BufferUsage::MapWrite;
return device.CreateBuffer(&descriptor);
}
return device.CreateBuffer(&descriptor);
}
wgpu::CreateBufferMappedResult CreateBufferMapped(uint64_t size, wgpu::BufferUsage usage) {
wgpu::BufferDescriptor descriptor;
descriptor.size = size;
descriptor.usage = usage;
wgpu::CreateBufferMappedResult CreateBufferMapped(uint64_t size, wgpu::BufferUsage usage) {
wgpu::BufferDescriptor descriptor;
descriptor.size = size;
descriptor.usage = usage;
return device.CreateBufferMapped(&descriptor);
}
return device.CreateBufferMapped(&descriptor);
}
wgpu::Buffer BufferMappedAtCreation(uint64_t size, wgpu::BufferUsage usage) {
wgpu::BufferDescriptor descriptor;
descriptor.size = size;
descriptor.usage = usage;
descriptor.mappedAtCreation = true;
wgpu::Buffer BufferMappedAtCreation(uint64_t size, wgpu::BufferUsage usage) {
wgpu::BufferDescriptor descriptor;
descriptor.size = size;
descriptor.usage = usage;
descriptor.mappedAtCreation = true;
return device.CreateBuffer(&descriptor);
}
return device.CreateBuffer(&descriptor);
}
wgpu::Queue queue;
wgpu::Queue queue;
private:
void SetUp() override {
ValidationTest::SetUp();
private:
void SetUp() override {
ValidationTest::SetUp();
mockBufferMapReadCallback = std::make_unique<MockBufferMapReadCallback>();
mockBufferMapWriteCallback = std::make_unique<MockBufferMapWriteCallback>();
queue = device.GetDefaultQueue();
}
mockBufferMapReadCallback = std::make_unique<MockBufferMapReadCallback>();
mockBufferMapWriteCallback = std::make_unique<MockBufferMapWriteCallback>();
queue = device.GetDefaultQueue();
}
void TearDown() override {
// Delete mocks so that expectations are checked
mockBufferMapReadCallback = nullptr;
mockBufferMapWriteCallback = nullptr;
void TearDown() override {
// Delete mocks so that expectations are checked
mockBufferMapReadCallback = nullptr;
mockBufferMapWriteCallback = nullptr;
ValidationTest::TearDown();
}
ValidationTest::TearDown();
}
};
// Test case where creation should succeed
@@ -416,7 +416,8 @@ TEST_F(BufferValidationTest, UnmapInsideMapWriteCallback) {
WaitForAllOperations(device);
}
// Test that the MapReadCallback isn't fired twice the buffer external refcount reaches 0 in the callback
// Test that the MapReadCallback isn't fired twice the buffer external refcount reaches 0 in the
// callback
TEST_F(BufferValidationTest, DestroyInsideMapReadCallback) {
wgpu::Buffer buf = CreateMapReadBuffer(4);
@@ -429,7 +430,8 @@ TEST_F(BufferValidationTest, DestroyInsideMapReadCallback) {
WaitForAllOperations(device);
}
// Test that the MapWriteCallback isn't fired twice the buffer external refcount reaches 0 in the callback
// Test that the MapWriteCallback isn't fired twice the buffer external refcount reaches 0 in the
// callback
TEST_F(BufferValidationTest, DestroyInsideMapWriteCallback) {
wgpu::Buffer buf = CreateMapWriteBuffer(4);

View File

@@ -16,8 +16,7 @@
#include "utils/WGPUHelpers.h"
class CommandBufferValidationTest : public ValidationTest {
};
class CommandBufferValidationTest : public ValidationTest {};
// Test for an empty command buffer
TEST_F(CommandBufferValidationTest, Empty) {

View File

@@ -14,7 +14,7 @@
#include "tests/unittests/validation/ValidationTest.h"
class ComputeValidationTest : public ValidationTest {
};
class ComputeValidationTest : public ValidationTest {};
//TODO(cwallez@chromium.org): Add a regression test for Disptach validation trying to acces the input state.
// TODO(cwallez@chromium.org): Add a regression test for Disptach validation trying to acces the
// input state.

View File

@@ -1168,8 +1168,8 @@ TEST_F(CopyCommandTest_T2T, 2DTextureDepthStencil) {
TEST_F(CopyCommandTest_T2T, 2DTextureArrayDepthStencil) {
{
wgpu::Texture source = Create2DTexture(16, 16, 1, 3, wgpu::TextureFormat::Depth24PlusStencil8,
wgpu::TextureUsage::CopySrc);
wgpu::Texture source = Create2DTexture(
16, 16, 1, 3, wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureUsage::CopySrc);
wgpu::Texture destination = Create2DTexture(
16, 16, 1, 1, wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureUsage::CopyDst);
@@ -1179,8 +1179,8 @@ TEST_F(CopyCommandTest_T2T, 2DTextureArrayDepthStencil) {
}
{
wgpu::Texture source = Create2DTexture(16, 16, 1, 1, wgpu::TextureFormat::Depth24PlusStencil8,
wgpu::TextureUsage::CopySrc);
wgpu::Texture source = Create2DTexture(
16, 16, 1, 1, wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureUsage::CopySrc);
wgpu::Texture destination = Create2DTexture(
16, 16, 1, 3, wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureUsage::CopyDst);
@@ -1190,8 +1190,8 @@ TEST_F(CopyCommandTest_T2T, 2DTextureArrayDepthStencil) {
}
{
wgpu::Texture source = Create2DTexture(16, 16, 1, 3, wgpu::TextureFormat::Depth24PlusStencil8,
wgpu::TextureUsage::CopySrc);
wgpu::Texture source = Create2DTexture(
16, 16, 1, 3, wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureUsage::CopySrc);
wgpu::Texture destination = Create2DTexture(
16, 16, 1, 3, wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureUsage::CopyDst);
@@ -1659,4 +1659,4 @@ TEST_F(CopyCommandTest_CompressedTextureFormats, CopyToMultipleArrayLayers) {
{0, 0, 0});
}
}
}
}

View File

@@ -223,8 +223,7 @@ TEST_F(SetViewportTest, MinDepthEqualOrGreaterThanMaxDepth) {
}
}
class SetScissorRectTest : public ValidationTest {
};
class SetScissorRectTest : public ValidationTest {};
// Test to check basic use of SetScissor
TEST_F(SetScissorRectTest, Success) {
@@ -284,8 +283,7 @@ TEST_F(SetScissorRectTest, ScissorLargerThanFramebuffer) {
encoder.Finish();
}
class SetBlendColorTest : public ValidationTest {
};
class SetBlendColorTest : public ValidationTest {};
// Test to check basic use of SetBlendColor
TEST_F(SetBlendColorTest, Success) {
@@ -315,8 +313,7 @@ TEST_F(SetBlendColorTest, AnyValueAllowed) {
encoder.Finish();
}
class SetStencilReferenceTest : public ValidationTest {
};
class SetStencilReferenceTest : public ValidationTest {};
// Test to check basic use of SetStencilReferenceTest
TEST_F(SetStencilReferenceTest, Success) {

View File

@@ -18,181 +18,180 @@
namespace {
class QueueSubmitValidationTest : public ValidationTest {
};
class QueueSubmitValidationTest : public ValidationTest {};
// Test submitting with a mapped buffer is disallowed
TEST_F(QueueSubmitValidationTest, SubmitWithMappedBuffer) {
// Create a map-write buffer.
wgpu::BufferDescriptor descriptor;
descriptor.usage = wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc;
descriptor.size = 4;
wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
// Create a fake copy destination buffer
descriptor.usage = wgpu::BufferUsage::CopyDst;
wgpu::Buffer targetBuffer = device.CreateBuffer(&descriptor);
// Create a command buffer that reads from the mappable buffer.
wgpu::CommandBuffer commands;
{
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyBufferToBuffer(buffer, 0, targetBuffer, 0, 4);
commands = encoder.Finish();
}
wgpu::Queue queue = device.GetDefaultQueue();
// Submitting when the buffer has never been mapped should succeed
queue.Submit(1, &commands);
// Map the buffer, submitting when the buffer is mapped should fail
buffer.MapWriteAsync(nullptr, nullptr);
// Try submitting before the callback is fired.
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
WaitForAllOperations(device);
// Try submitting after the callback is fired.
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
// Unmap the buffer, queue submit should succeed
buffer.Unmap();
queue.Submit(1, &commands);
}
class QueueWriteBufferValidationTest : public ValidationTest {
private:
void SetUp() override {
ValidationTest::SetUp();
queue = device.GetDefaultQueue();
}
protected:
wgpu::Buffer CreateBuffer(uint64_t size) {
wgpu::BufferDescriptor descriptor;
descriptor.size = size;
descriptor.usage = wgpu::BufferUsage::CopyDst;
return device.CreateBuffer(&descriptor);
}
wgpu::Queue queue;
};
// Test the success case for WriteBuffer
TEST_F(QueueWriteBufferValidationTest, Success) {
wgpu::Buffer buf = CreateBuffer(4);
uint32_t foo = 0x01020304;
queue.WriteBuffer(buf, 0, &foo, sizeof(foo));
}
// Test error case for WriteBuffer out of bounds
TEST_F(QueueWriteBufferValidationTest, OutOfBounds) {
wgpu::Buffer buf = CreateBuffer(4);
uint32_t foo[2] = {0, 0};
ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, foo, 8));
}
// Test error case for WriteBuffer out of bounds with an overflow
TEST_F(QueueWriteBufferValidationTest, OutOfBoundsOverflow) {
wgpu::Buffer buf = CreateBuffer(1024);
uint32_t foo[2] = {0, 0};
// An offset that when added to "4" would overflow to be zero and pass validation without
// overflow checks.
uint64_t offset = uint64_t(int64_t(0) - int64_t(4));
ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, offset, foo, 4));
}
// Test error case for WriteBuffer with the wrong usage
TEST_F(QueueWriteBufferValidationTest, WrongUsage) {
wgpu::BufferDescriptor descriptor;
descriptor.size = 4;
descriptor.usage = wgpu::BufferUsage::Vertex;
wgpu::Buffer buf = device.CreateBuffer(&descriptor);
uint32_t foo = 0;
ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &foo, sizeof(foo)));
}
// Test WriteBuffer with unaligned size
TEST_F(QueueWriteBufferValidationTest, UnalignedSize) {
wgpu::Buffer buf = CreateBuffer(4);
uint16_t value = 123;
ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &value, sizeof(value)));
}
// Test WriteBuffer with unaligned offset
TEST_F(QueueWriteBufferValidationTest, UnalignedOffset) {
wgpu::Buffer buf = CreateBuffer(8);
uint32_t value = 0x01020304;
ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 2, &value, sizeof(value)));
}
// Test WriteBuffer with destroyed buffer
TEST_F(QueueWriteBufferValidationTest, DestroyedBuffer) {
wgpu::Buffer buf = CreateBuffer(4);
buf.Destroy();
uint32_t value = 0;
ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &value, sizeof(value)));
}
// Test WriteBuffer with mapped buffer
TEST_F(QueueWriteBufferValidationTest, MappedBuffer) {
// CreateBufferMapped
{
// Test submitting with a mapped buffer is disallowed
TEST_F(QueueSubmitValidationTest, SubmitWithMappedBuffer) {
// Create a map-write buffer.
wgpu::BufferDescriptor descriptor;
descriptor.usage = wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc;
descriptor.size = 4;
descriptor.usage = wgpu::BufferUsage::CopyDst;
wgpu::CreateBufferMappedResult result = device.CreateBufferMapped(&descriptor);
uint32_t value = 0;
ASSERT_DEVICE_ERROR(queue.WriteBuffer(result.buffer, 0, &value, sizeof(value)));
}
// mappedAtCreation
{
wgpu::BufferDescriptor descriptor;
descriptor.size = 4;
descriptor.usage = wgpu::BufferUsage::CopyDst;
descriptor.mappedAtCreation = true;
wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
uint32_t value = 0;
ASSERT_DEVICE_ERROR(queue.WriteBuffer(buffer, 0, &value, sizeof(value)));
// Create a fake copy destination buffer
descriptor.usage = wgpu::BufferUsage::CopyDst;
wgpu::Buffer targetBuffer = device.CreateBuffer(&descriptor);
// Create a command buffer that reads from the mappable buffer.
wgpu::CommandBuffer commands;
{
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyBufferToBuffer(buffer, 0, targetBuffer, 0, 4);
commands = encoder.Finish();
}
wgpu::Queue queue = device.GetDefaultQueue();
// Submitting when the buffer has never been mapped should succeed
queue.Submit(1, &commands);
// Map the buffer, submitting when the buffer is mapped should fail
buffer.MapWriteAsync(nullptr, nullptr);
// Try submitting before the callback is fired.
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
WaitForAllOperations(device);
// Try submitting after the callback is fired.
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
// Unmap the buffer, queue submit should succeed
buffer.Unmap();
queue.Submit(1, &commands);
}
// MapReadAsync
{
class QueueWriteBufferValidationTest : public ValidationTest {
private:
void SetUp() override {
ValidationTest::SetUp();
queue = device.GetDefaultQueue();
}
protected:
wgpu::Buffer CreateBuffer(uint64_t size) {
wgpu::BufferDescriptor descriptor;
descriptor.size = size;
descriptor.usage = wgpu::BufferUsage::CopyDst;
return device.CreateBuffer(&descriptor);
}
wgpu::Queue queue;
};
// Test the success case for WriteBuffer
TEST_F(QueueWriteBufferValidationTest, Success) {
wgpu::Buffer buf = CreateBuffer(4);
uint32_t foo = 0x01020304;
queue.WriteBuffer(buf, 0, &foo, sizeof(foo));
}
// Test error case for WriteBuffer out of bounds
TEST_F(QueueWriteBufferValidationTest, OutOfBounds) {
wgpu::Buffer buf = CreateBuffer(4);
uint32_t foo[2] = {0, 0};
ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, foo, 8));
}
// Test error case for WriteBuffer out of bounds with an overflow
TEST_F(QueueWriteBufferValidationTest, OutOfBoundsOverflow) {
wgpu::Buffer buf = CreateBuffer(1024);
uint32_t foo[2] = {0, 0};
// An offset that when added to "4" would overflow to be zero and pass validation without
// overflow checks.
uint64_t offset = uint64_t(int64_t(0) - int64_t(4));
ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, offset, foo, 4));
}
// Test error case for WriteBuffer with the wrong usage
TEST_F(QueueWriteBufferValidationTest, WrongUsage) {
wgpu::BufferDescriptor descriptor;
descriptor.size = 4;
descriptor.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::MapRead;
descriptor.usage = wgpu::BufferUsage::Vertex;
wgpu::Buffer buf = device.CreateBuffer(&descriptor);
buf.MapReadAsync(nullptr, nullptr);
uint32_t foo = 0;
ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &foo, sizeof(foo)));
}
// Test WriteBuffer with unaligned size
TEST_F(QueueWriteBufferValidationTest, UnalignedSize) {
wgpu::Buffer buf = CreateBuffer(4);
uint16_t value = 123;
ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &value, sizeof(value)));
}
// Test WriteBuffer with unaligned offset
TEST_F(QueueWriteBufferValidationTest, UnalignedOffset) {
wgpu::Buffer buf = CreateBuffer(8);
uint32_t value = 0x01020304;
ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 2, &value, sizeof(value)));
}
// Test WriteBuffer with destroyed buffer
TEST_F(QueueWriteBufferValidationTest, DestroyedBuffer) {
wgpu::Buffer buf = CreateBuffer(4);
buf.Destroy();
uint32_t value = 0;
ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &value, sizeof(value)));
}
// MapWriteAsync
{
wgpu::BufferDescriptor descriptor;
descriptor.size = 4;
descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::MapWrite;
wgpu::Buffer buf = device.CreateBuffer(&descriptor);
// Test WriteBuffer with mapped buffer
TEST_F(QueueWriteBufferValidationTest, MappedBuffer) {
// CreateBufferMapped
{
wgpu::BufferDescriptor descriptor;
descriptor.size = 4;
descriptor.usage = wgpu::BufferUsage::CopyDst;
wgpu::CreateBufferMappedResult result = device.CreateBufferMapped(&descriptor);
buf.MapWriteAsync(nullptr, nullptr);
uint32_t value = 0;
ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &value, sizeof(value)));
uint32_t value = 0;
ASSERT_DEVICE_ERROR(queue.WriteBuffer(result.buffer, 0, &value, sizeof(value)));
}
// mappedAtCreation
{
wgpu::BufferDescriptor descriptor;
descriptor.size = 4;
descriptor.usage = wgpu::BufferUsage::CopyDst;
descriptor.mappedAtCreation = true;
wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
uint32_t value = 0;
ASSERT_DEVICE_ERROR(queue.WriteBuffer(buffer, 0, &value, sizeof(value)));
}
// MapReadAsync
{
wgpu::BufferDescriptor descriptor;
descriptor.size = 4;
descriptor.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::MapRead;
wgpu::Buffer buf = device.CreateBuffer(&descriptor);
buf.MapReadAsync(nullptr, nullptr);
uint32_t value = 0;
ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &value, sizeof(value)));
}
// MapWriteAsync
{
wgpu::BufferDescriptor descriptor;
descriptor.size = 4;
descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::MapWrite;
wgpu::Buffer buf = device.CreateBuffer(&descriptor);
buf.MapWriteAsync(nullptr, nullptr);
uint32_t value = 0;
ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &value, sizeof(value)));
}
}
}
} // anonymous namespace

View File

@@ -636,4 +636,4 @@ namespace {
}
}
} // anonymous namespace
} // anonymous namespace

View File

@@ -22,26 +22,26 @@
#include <sstream>
class RenderPipelineValidationTest : public ValidationTest {
protected:
void SetUp() override {
ValidationTest::SetUp();
protected:
void SetUp() override {
ValidationTest::SetUp();
vsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
vsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
void main() {
gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
})");
fsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
fsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = vec4(0.0, 1.0, 0.0, 1.0);
})");
}
}
wgpu::ShaderModule vsModule;
wgpu::ShaderModule fsModule;
wgpu::ShaderModule vsModule;
wgpu::ShaderModule fsModule;
};
// Test cases where creation should succeed

View File

@@ -20,8 +20,7 @@
#include <sstream>
class ShaderModuleValidationTest : public ValidationTest {
};
class ShaderModuleValidationTest : public ValidationTest {};
// Test case with a simpler shader that should successfully be created
TEST_F(ShaderModuleValidationTest, CreationSuccess) {
@@ -112,8 +111,8 @@ TEST_F(ShaderModuleValidationTest, FragmentOutputLocationExceedsMaxColorAttachme
// Test that it is invalid to create a shader module with no chained descriptor. (It must be
// WGSL or SPIRV, not empty)
TEST_F(ShaderModuleValidationTest, NoChainedDescriptor) {
wgpu::ShaderModuleDescriptor desc = {};
ASSERT_DEVICE_ERROR(device.CreateShaderModule(&desc));
wgpu::ShaderModuleDescriptor desc = {};
ASSERT_DEVICE_ERROR(device.CreateShaderModule(&desc));
}
// Test that it is not allowed to use combined texture and sampler.

View File

@@ -21,474 +21,476 @@
namespace {
class TextureValidationTest : public ValidationTest {
protected:
void SetUp() override {
queue = device.GetDefaultQueue();
}
class TextureValidationTest : public ValidationTest {
protected:
void SetUp() override {
queue = device.GetDefaultQueue();
}
wgpu::TextureDescriptor CreateDefaultTextureDescriptor() {
wgpu::TextureDescriptor descriptor;
descriptor.size.width = kWidth;
descriptor.size.height = kHeight;
descriptor.size.depth = kDefaultDepth;
descriptor.mipLevelCount = kDefaultMipLevels;
descriptor.sampleCount = kDefaultSampleCount;
descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.format = kDefaultTextureFormat;
descriptor.usage = wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::Sampled;
return descriptor;
}
wgpu::TextureDescriptor CreateDefaultTextureDescriptor() {
wgpu::TextureDescriptor descriptor;
descriptor.size.width = kWidth;
descriptor.size.height = kHeight;
descriptor.size.depth = kDefaultDepth;
descriptor.mipLevelCount = kDefaultMipLevels;
descriptor.sampleCount = kDefaultSampleCount;
descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.format = kDefaultTextureFormat;
descriptor.usage = wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::Sampled;
return descriptor;
}
wgpu::Queue queue;
wgpu::Queue queue;
private:
static constexpr uint32_t kWidth = 32;
static constexpr uint32_t kHeight = 32;
static constexpr uint32_t kDefaultDepth = 1;
static constexpr uint32_t kDefaultMipLevels = 1;
static constexpr uint32_t kDefaultSampleCount = 1;
private:
static constexpr uint32_t kWidth = 32;
static constexpr uint32_t kHeight = 32;
static constexpr uint32_t kDefaultDepth = 1;
static constexpr uint32_t kDefaultMipLevels = 1;
static constexpr uint32_t kDefaultSampleCount = 1;
static constexpr wgpu::TextureFormat kDefaultTextureFormat = wgpu::TextureFormat::RGBA8Unorm;
};
// Test the validation of sample count
TEST_F(TextureValidationTest, SampleCount) {
wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
// sampleCount == 1 is allowed.
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.sampleCount = 1;
device.CreateTexture(&descriptor);
}
// sampleCount == 4 is allowed.
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.sampleCount = 4;
device.CreateTexture(&descriptor);
}
// It is an error to create a texture with an invalid sampleCount.
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.sampleCount = 3;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// It is an error to create a multisampled texture with mipLevelCount > 1.
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.sampleCount = 4;
descriptor.mipLevelCount = 2;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// Currently we do not support multisampled 2D array textures.
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.sampleCount = 4;
descriptor.size.depth = 2;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// It is an error to set TextureUsage::Storage when sampleCount > 1.
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.sampleCount = 4;
descriptor.usage |= wgpu::TextureUsage::Storage;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
}
// Test the validation of the mip level count
TEST_F(TextureValidationTest, MipLevelCount) {
wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
// mipLevelCount == 1 is allowed
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = 32;
descriptor.size.height = 32;
descriptor.mipLevelCount = 1;
device.CreateTexture(&descriptor);
}
// mipLevelCount == 0 is an error
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = 32;
descriptor.size.height = 32;
descriptor.mipLevelCount = 0;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// Full mip chains are allowed
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = 32;
descriptor.size.height = 32;
// Mip level sizes: 32, 16, 8, 4, 2, 1
descriptor.mipLevelCount = 6;
device.CreateTexture(&descriptor);
}
// Too big mip chains on width are disallowed
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = 31;
descriptor.size.height = 32;
// Mip level width: 31, 15, 7, 3, 1, 1
descriptor.mipLevelCount = 7;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// Too big mip chains on height are disallowed
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = 32;
descriptor.size.height = 31;
// Mip level height: 31, 15, 7, 3, 1, 1
descriptor.mipLevelCount = 7;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// Undefined shift check if miplevel is bigger than the integer bit width.
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = 32;
descriptor.size.height = 32;
descriptor.mipLevelCount = 100;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// Non square mip map halves the resolution until a 1x1 dimension.
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = 32;
descriptor.size.height = 8;
// Mip maps: 32 * 8, 16 * 4, 8 * 2, 4 * 1, 2 * 1, 1 * 1
descriptor.mipLevelCount = 6;
device.CreateTexture(&descriptor);
}
// Mip level exceeding kMaxTexture2DMipLevels not allowed
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = 1 >> kMaxTexture2DMipLevels;
descriptor.size.height = 1 >> kMaxTexture2DMipLevels;
descriptor.mipLevelCount = kMaxTexture2DMipLevels + 1u;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
}
// Test the validation of array layer count
TEST_F(TextureValidationTest, ArrayLayerCount) {
wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
// Array layer count exceeding kMaxTexture2DArrayLayers is not allowed
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.depth = kMaxTexture2DArrayLayers + 1u;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// Array layer count less than kMaxTexture2DArrayLayers is allowed;
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.depth = kMaxTexture2DArrayLayers >> 1;
device.CreateTexture(&descriptor);
}
// Array layer count equal to kMaxTexture2DArrayLayers is allowed;
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.depth = kMaxTexture2DArrayLayers;
device.CreateTexture(&descriptor);
}
}
// Test the validation of texture size
TEST_F(TextureValidationTest, TextureSize) {
wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
// Texture size exceeding kMaxTextureSize is not allowed
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = kMaxTextureSize + 1u;
descriptor.size.height = kMaxTextureSize + 1u;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// Texture size less than kMaxTextureSize is allowed
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = kMaxTextureSize >> 1;
descriptor.size.height = kMaxTextureSize >> 1;
device.CreateTexture(&descriptor);
}
// Texture equal to kMaxTextureSize is allowed
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = kMaxTextureSize;
descriptor.size.height = kMaxTextureSize;
device.CreateTexture(&descriptor);
}
}
// Test that it is valid to destroy a texture
TEST_F(TextureValidationTest, DestroyTexture) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
wgpu::Texture texture = device.CreateTexture(&descriptor);
texture.Destroy();
}
// Test that it's valid to destroy a destroyed texture
TEST_F(TextureValidationTest, DestroyDestroyedTexture) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
wgpu::Texture texture = device.CreateTexture(&descriptor);
texture.Destroy();
texture.Destroy();
}
// Test that it's invalid to submit a destroyed texture in a queue
// in the case of destroy, encode, submit
TEST_F(TextureValidationTest, DestroyEncodeSubmit) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
wgpu::Texture texture = device.CreateTexture(&descriptor);
wgpu::TextureView textureView = texture.CreateView();
utils::ComboRenderPassDescriptor renderPass({textureView});
// Destroy the texture
texture.Destroy();
wgpu::CommandEncoder encoder_post_destroy = device.CreateCommandEncoder();
{
wgpu::RenderPassEncoder pass = encoder_post_destroy.BeginRenderPass(&renderPass);
pass.EndPass();
}
wgpu::CommandBuffer commands = encoder_post_destroy.Finish();
// Submit should fail due to destroyed texture
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
}
// Test that it's invalid to submit a destroyed texture in a queue
// in the case of encode, destroy, submit
TEST_F(TextureValidationTest, EncodeDestroySubmit) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
wgpu::Texture texture = device.CreateTexture(&descriptor);
wgpu::TextureView textureView = texture.CreateView();
utils::ComboRenderPassDescriptor renderPass({textureView});
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
pass.EndPass();
}
wgpu::CommandBuffer commands = encoder.Finish();
// Destroy the texture
texture.Destroy();
// Submit should fail due to destroyed texture
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
}
// Test it is an error to create an OutputAttachment texture with a non-renderable format.
TEST_F(TextureValidationTest, NonRenderableAndOutputAttachment) {
wgpu::TextureDescriptor descriptor;
descriptor.size = {1, 1, 1};
descriptor.usage = wgpu::TextureUsage::OutputAttachment;
// Succeeds because RGBA8Unorm is renderable
descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
device.CreateTexture(&descriptor);
wgpu::TextureFormat nonRenderableFormats[] = {
wgpu::TextureFormat::RG11B10Float,
wgpu::TextureFormat::R8Snorm,
wgpu::TextureFormat::RG8Snorm,
wgpu::TextureFormat::RGBA8Snorm,
static constexpr wgpu::TextureFormat kDefaultTextureFormat =
wgpu::TextureFormat::RGBA8Unorm;
};
for (wgpu::TextureFormat format : nonRenderableFormats) {
// Fails because `format` is non-renderable
descriptor.format = format;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
}
// Test the validation of sample count
TEST_F(TextureValidationTest, SampleCount) {
wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
// Test it is an error to create a Storage texture with any format that doesn't support
// TextureUsage::Storage texture usages.
TEST_F(TextureValidationTest, TextureFormatNotSupportTextureUsageStorage) {
wgpu::TextureDescriptor descriptor;
descriptor.size = {1, 1, 1};
descriptor.usage = wgpu::TextureUsage::Storage;
for (wgpu::TextureFormat format : utils::kAllTextureFormats) {
descriptor.format = format;
if (utils::TextureFormatSupportsStorageTexture(format)) {
device.CreateTexture(&descriptor);
} else {
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
}
}
// Test it is an error to create a texture with format "Undefined".
TEST_F(TextureValidationTest, TextureFormatUndefined) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = wgpu::TextureFormat::Undefined;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// TODO(jiawei.shao@intel.com): add tests to verify we cannot create 1D or 3D textures with
// compressed texture formats.
class CompressedTextureFormatsValidationTests : public TextureValidationTest {
public:
CompressedTextureFormatsValidationTests() : TextureValidationTest() {
device = CreateDeviceFromAdapter(adapter, {"texture_compression_bc"});
}
protected:
wgpu::TextureDescriptor CreateDefaultTextureDescriptor() {
wgpu::TextureDescriptor descriptor =
TextureValidationTest::CreateDefaultTextureDescriptor();
descriptor.usage =
wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::Sampled;
return descriptor;
}
const std::array<wgpu::TextureFormat, 14> kBCFormats = {
wgpu::TextureFormat::BC1RGBAUnorm, wgpu::TextureFormat::BC1RGBAUnormSrgb,
wgpu::TextureFormat::BC2RGBAUnorm, wgpu::TextureFormat::BC2RGBAUnormSrgb,
wgpu::TextureFormat::BC3RGBAUnorm, wgpu::TextureFormat::BC3RGBAUnormSrgb,
wgpu::TextureFormat::BC4RUnorm, wgpu::TextureFormat::BC4RSnorm,
wgpu::TextureFormat::BC5RGUnorm, wgpu::TextureFormat::BC5RGSnorm,
wgpu::TextureFormat::BC6HRGBUfloat, wgpu::TextureFormat::BC6HRGBSfloat,
wgpu::TextureFormat::BC7RGBAUnorm, wgpu::TextureFormat::BC7RGBAUnormSrgb};
};
// Test the validation of texture size when creating textures in compressed texture formats.
TEST_F(CompressedTextureFormatsValidationTests, TextureSize) {
// Test that it is invalid to use a number that is not a multiple of 4 (the compressed block
// width and height of all BC formats) as the width or height of textures in BC formats.
for (wgpu::TextureFormat format : kBCFormats) {
// sampleCount == 1 is allowed.
{
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = format;
ASSERT_TRUE(descriptor.size.width % 4 == 0 && descriptor.size.height % 4 == 0);
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.sampleCount = 1;
device.CreateTexture(&descriptor);
}
// sampleCount == 4 is allowed.
{
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = format;
descriptor.size.width = 31;
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.sampleCount = 4;
device.CreateTexture(&descriptor);
}
// It is an error to create a texture with an invalid sampleCount.
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.sampleCount = 3;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// It is an error to create a multisampled texture with mipLevelCount > 1.
{
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = format;
descriptor.size.height = 31;
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.sampleCount = 4;
descriptor.mipLevelCount = 2;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// Currently we do not support multisampled 2D array textures.
{
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = format;
descriptor.size.width = 12;
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.sampleCount = 4;
descriptor.size.depth = 2;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// It is an error to set TextureUsage::Storage when sampleCount > 1.
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.sampleCount = 4;
descriptor.usage |= wgpu::TextureUsage::Storage;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
}
// Test the validation of the mip level count
TEST_F(TextureValidationTest, MipLevelCount) {
wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
// mipLevelCount == 1 is allowed
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = 32;
descriptor.size.height = 32;
descriptor.mipLevelCount = 1;
device.CreateTexture(&descriptor);
}
// mipLevelCount == 0 is an error
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = 32;
descriptor.size.height = 32;
descriptor.mipLevelCount = 0;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// Full mip chains are allowed
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = 32;
descriptor.size.height = 32;
// Mip level sizes: 32, 16, 8, 4, 2, 1
descriptor.mipLevelCount = 6;
device.CreateTexture(&descriptor);
}
// Too big mip chains on width are disallowed
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = 31;
descriptor.size.height = 32;
// Mip level width: 31, 15, 7, 3, 1, 1
descriptor.mipLevelCount = 7;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// Too big mip chains on height are disallowed
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = 32;
descriptor.size.height = 31;
// Mip level height: 31, 15, 7, 3, 1, 1
descriptor.mipLevelCount = 7;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// Undefined shift check if miplevel is bigger than the integer bit width.
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = 32;
descriptor.size.height = 32;
descriptor.mipLevelCount = 100;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// Non square mip map halves the resolution until a 1x1 dimension.
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = 32;
descriptor.size.height = 8;
// Mip maps: 32 * 8, 16 * 4, 8 * 2, 4 * 1, 2 * 1, 1 * 1
descriptor.mipLevelCount = 6;
device.CreateTexture(&descriptor);
}
// Mip level exceeding kMaxTexture2DMipLevels not allowed
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = 1 >> kMaxTexture2DMipLevels;
descriptor.size.height = 1 >> kMaxTexture2DMipLevels;
descriptor.mipLevelCount = kMaxTexture2DMipLevels + 1u;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
}
// Test the validation of array layer count
TEST_F(TextureValidationTest, ArrayLayerCount) {
wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
// Array layer count exceeding kMaxTexture2DArrayLayers is not allowed
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.depth = kMaxTexture2DArrayLayers + 1u;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// Array layer count less than kMaxTexture2DArrayLayers is allowed;
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.depth = kMaxTexture2DArrayLayers >> 1;
device.CreateTexture(&descriptor);
}
// Array layer count equal to kMaxTexture2DArrayLayers is allowed;
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.depth = kMaxTexture2DArrayLayers;
device.CreateTexture(&descriptor);
}
}
}
// Test the creation of a texture with BC format will fail when the extension textureCompressionBC
// is not enabled.
TEST_F(CompressedTextureFormatsValidationTests, UseBCFormatWithoutEnablingExtension) {
const std::vector<const char*> kEmptyVector;
wgpu::Device deviceWithoutExtension = CreateDeviceFromAdapter(adapter, kEmptyVector);
for (wgpu::TextureFormat format : kBCFormats) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = format;
ASSERT_DEVICE_ERROR(deviceWithoutExtension.CreateTexture(&descriptor));
// Test the validation of texture size
TEST_F(TextureValidationTest, TextureSize) {
wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
// Texture size exceeding kMaxTextureSize is not allowed
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = kMaxTextureSize + 1u;
descriptor.size.height = kMaxTextureSize + 1u;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// Texture size less than kMaxTextureSize is allowed
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = kMaxTextureSize >> 1;
descriptor.size.height = kMaxTextureSize >> 1;
device.CreateTexture(&descriptor);
}
// Texture equal to kMaxTextureSize is allowed
{
wgpu::TextureDescriptor descriptor = defaultDescriptor;
descriptor.size.width = kMaxTextureSize;
descriptor.size.height = kMaxTextureSize;
device.CreateTexture(&descriptor);
}
}
}
// Test the validation of texture usages when creating textures in compressed texture formats.
TEST_F(CompressedTextureFormatsValidationTests, TextureUsage) {
// Test that only CopySrc, CopyDst and Sampled are accepted as the texture usage of the
// textures in BC formats.
for (wgpu::TextureFormat format : kBCFormats) {
// Test that it is valid to destroy a texture
TEST_F(TextureValidationTest, DestroyTexture) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
wgpu::Texture texture = device.CreateTexture(&descriptor);
texture.Destroy();
}
// Test that it's valid to destroy a destroyed texture
TEST_F(TextureValidationTest, DestroyDestroyedTexture) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
wgpu::Texture texture = device.CreateTexture(&descriptor);
texture.Destroy();
texture.Destroy();
}
// Test that it's invalid to submit a destroyed texture in a queue
// in the case of destroy, encode, submit
TEST_F(TextureValidationTest, DestroyEncodeSubmit) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
wgpu::Texture texture = device.CreateTexture(&descriptor);
wgpu::TextureView textureView = texture.CreateView();
utils::ComboRenderPassDescriptor renderPass({textureView});
// Destroy the texture
texture.Destroy();
wgpu::CommandEncoder encoder_post_destroy = device.CreateCommandEncoder();
{
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = format;
descriptor.usage = wgpu::TextureUsage::OutputAttachment;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
wgpu::RenderPassEncoder pass = encoder_post_destroy.BeginRenderPass(&renderPass);
pass.EndPass();
}
wgpu::CommandBuffer commands = encoder_post_destroy.Finish();
// Submit should fail due to destroyed texture
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
}
// Test that it's invalid to submit a destroyed texture in a queue
// in the case of encode, destroy, submit
TEST_F(TextureValidationTest, EncodeDestroySubmit) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
wgpu::Texture texture = device.CreateTexture(&descriptor);
wgpu::TextureView textureView = texture.CreateView();
utils::ComboRenderPassDescriptor renderPass({textureView});
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = format;
descriptor.usage = wgpu::TextureUsage::Storage;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
pass.EndPass();
}
wgpu::CommandBuffer commands = encoder.Finish();
{
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
// Destroy the texture
texture.Destroy();
// Submit should fail due to destroyed texture
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
}
// Test it is an error to create an OutputAttachment texture with a non-renderable format.
TEST_F(TextureValidationTest, NonRenderableAndOutputAttachment) {
wgpu::TextureDescriptor descriptor;
descriptor.size = {1, 1, 1};
descriptor.usage = wgpu::TextureUsage::OutputAttachment;
// Succeeds because RGBA8Unorm is renderable
descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
device.CreateTexture(&descriptor);
wgpu::TextureFormat nonRenderableFormats[] = {
wgpu::TextureFormat::RG11B10Float,
wgpu::TextureFormat::R8Snorm,
wgpu::TextureFormat::RG8Snorm,
wgpu::TextureFormat::RGBA8Snorm,
};
for (wgpu::TextureFormat format : nonRenderableFormats) {
// Fails because `format` is non-renderable
descriptor.format = format;
descriptor.usage = wgpu::TextureUsage::Present;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
}
}
// Test the validation of sample count when creating textures in compressed texture formats.
TEST_F(CompressedTextureFormatsValidationTests, SampleCount) {
// Test that it is invalid to specify SampleCount > 1 when we create a texture in BC formats.
for (wgpu::TextureFormat format : kBCFormats) {
// Test it is an error to create a Storage texture with any format that doesn't support
// TextureUsage::Storage texture usages.
TEST_F(TextureValidationTest, TextureFormatNotSupportTextureUsageStorage) {
wgpu::TextureDescriptor descriptor;
descriptor.size = {1, 1, 1};
descriptor.usage = wgpu::TextureUsage::Storage;
for (wgpu::TextureFormat format : utils::kAllTextureFormats) {
descriptor.format = format;
if (utils::TextureFormatSupportsStorageTexture(format)) {
device.CreateTexture(&descriptor);
} else {
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
}
}
// Test it is an error to create a texture with format "Undefined".
TEST_F(TextureValidationTest, TextureFormatUndefined) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = format;
descriptor.sampleCount = 4;
descriptor.format = wgpu::TextureFormat::Undefined;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
}
// Test the validation of creating 2D array textures in compressed texture formats.
TEST_F(CompressedTextureFormatsValidationTests, 2DArrayTexture) {
// Test that it is allowed to create a 2D array texture in BC formats.
for (wgpu::TextureFormat format : kBCFormats) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = format;
descriptor.size.depth = 6;
device.CreateTexture(&descriptor);
// TODO(jiawei.shao@intel.com): add tests to verify we cannot create 1D or 3D textures with
// compressed texture formats.
class CompressedTextureFormatsValidationTests : public TextureValidationTest {
public:
CompressedTextureFormatsValidationTests() : TextureValidationTest() {
device = CreateDeviceFromAdapter(adapter, {"texture_compression_bc"});
}
protected:
wgpu::TextureDescriptor CreateDefaultTextureDescriptor() {
wgpu::TextureDescriptor descriptor =
TextureValidationTest::CreateDefaultTextureDescriptor();
descriptor.usage = wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst |
wgpu::TextureUsage::Sampled;
return descriptor;
}
const std::array<wgpu::TextureFormat, 14> kBCFormats = {
wgpu::TextureFormat::BC1RGBAUnorm, wgpu::TextureFormat::BC1RGBAUnormSrgb,
wgpu::TextureFormat::BC2RGBAUnorm, wgpu::TextureFormat::BC2RGBAUnormSrgb,
wgpu::TextureFormat::BC3RGBAUnorm, wgpu::TextureFormat::BC3RGBAUnormSrgb,
wgpu::TextureFormat::BC4RUnorm, wgpu::TextureFormat::BC4RSnorm,
wgpu::TextureFormat::BC5RGUnorm, wgpu::TextureFormat::BC5RGSnorm,
wgpu::TextureFormat::BC6HRGBUfloat, wgpu::TextureFormat::BC6HRGBSfloat,
wgpu::TextureFormat::BC7RGBAUnorm, wgpu::TextureFormat::BC7RGBAUnormSrgb};
};
// Test the validation of texture size when creating textures in compressed texture formats.
TEST_F(CompressedTextureFormatsValidationTests, TextureSize) {
// Test that it is invalid to use a number that is not a multiple of 4 (the compressed block
// width and height of all BC formats) as the width or height of textures in BC formats.
for (wgpu::TextureFormat format : kBCFormats) {
{
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = format;
ASSERT_TRUE(descriptor.size.width % 4 == 0 && descriptor.size.height % 4 == 0);
device.CreateTexture(&descriptor);
}
{
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = format;
descriptor.size.width = 31;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
{
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = format;
descriptor.size.height = 31;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
{
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = format;
descriptor.size.width = 12;
descriptor.size.height = 32;
device.CreateTexture(&descriptor);
}
}
}
// Test the creation of a texture with BC format will fail when the extension
// textureCompressionBC is not enabled.
TEST_F(CompressedTextureFormatsValidationTests, UseBCFormatWithoutEnablingExtension) {
const std::vector<const char*> kEmptyVector;
wgpu::Device deviceWithoutExtension = CreateDeviceFromAdapter(adapter, kEmptyVector);
for (wgpu::TextureFormat format : kBCFormats) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = format;
ASSERT_DEVICE_ERROR(deviceWithoutExtension.CreateTexture(&descriptor));
}
}
// Test the validation of texture usages when creating textures in compressed texture formats.
TEST_F(CompressedTextureFormatsValidationTests, TextureUsage) {
// Test that only CopySrc, CopyDst and Sampled are accepted as the texture usage of the
// textures in BC formats.
for (wgpu::TextureFormat format : kBCFormats) {
{
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = format;
descriptor.usage = wgpu::TextureUsage::OutputAttachment;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
{
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = format;
descriptor.usage = wgpu::TextureUsage::Storage;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
{
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = format;
descriptor.usage = wgpu::TextureUsage::Present;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
}
}
// Test the validation of sample count when creating textures in compressed texture formats.
TEST_F(CompressedTextureFormatsValidationTests, SampleCount) {
// Test that it is invalid to specify SampleCount > 1 when we create a texture in BC
// formats.
for (wgpu::TextureFormat format : kBCFormats) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = format;
descriptor.sampleCount = 4;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
}
// Test the validation of creating 2D array textures in compressed texture formats.
TEST_F(CompressedTextureFormatsValidationTests, 2DArrayTexture) {
// Test that it is allowed to create a 2D array texture in BC formats.
for (wgpu::TextureFormat format : kBCFormats) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = format;
descriptor.size.depth = 6;
device.CreateTexture(&descriptor);
}
}
}
} // namespace

View File

@@ -16,349 +16,348 @@
namespace {
class TextureViewValidationTest : public ValidationTest {
};
class TextureViewValidationTest : public ValidationTest {};
constexpr uint32_t kWidth = 32u;
constexpr uint32_t kHeight = 32u;
constexpr uint32_t kDefaultMipLevels = 6u;
constexpr uint32_t kWidth = 32u;
constexpr uint32_t kHeight = 32u;
constexpr uint32_t kDefaultMipLevels = 6u;
constexpr wgpu::TextureFormat kDefaultTextureFormat = wgpu::TextureFormat::RGBA8Unorm;
constexpr wgpu::TextureFormat kDefaultTextureFormat = wgpu::TextureFormat::RGBA8Unorm;
wgpu::Texture Create2DArrayTexture(wgpu::Device& device,
uint32_t arrayLayerCount,
uint32_t width = kWidth,
uint32_t height = kHeight,
uint32_t mipLevelCount = kDefaultMipLevels,
uint32_t sampleCount = 1) {
wgpu::TextureDescriptor descriptor;
descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = width;
descriptor.size.height = height;
descriptor.size.depth = arrayLayerCount;
descriptor.sampleCount = sampleCount;
descriptor.format = kDefaultTextureFormat;
descriptor.mipLevelCount = mipLevelCount;
descriptor.usage = wgpu::TextureUsage::Sampled;
return device.CreateTexture(&descriptor);
}
wgpu::TextureViewDescriptor CreateDefaultViewDescriptor(wgpu::TextureViewDimension dimension) {
wgpu::TextureViewDescriptor descriptor;
descriptor.format = kDefaultTextureFormat;
descriptor.dimension = dimension;
descriptor.baseMipLevel = 0;
descriptor.mipLevelCount = kDefaultMipLevels;
descriptor.baseArrayLayer = 0;
descriptor.arrayLayerCount = 1;
return descriptor;
}
// Test creating texture view on a 2D non-array texture
TEST_F(TextureViewValidationTest, CreateTextureViewOnTexture2D) {
wgpu::Texture texture = Create2DArrayTexture(device, 1);
wgpu::TextureViewDescriptor base2DTextureViewDescriptor =
CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2D);
// It is OK to create a 2D texture view on a 2D texture.
{
wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
descriptor.arrayLayerCount = 1;
texture.CreateView(&descriptor);
wgpu::Texture Create2DArrayTexture(wgpu::Device& device,
uint32_t arrayLayerCount,
uint32_t width = kWidth,
uint32_t height = kHeight,
uint32_t mipLevelCount = kDefaultMipLevels,
uint32_t sampleCount = 1) {
wgpu::TextureDescriptor descriptor;
descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = width;
descriptor.size.height = height;
descriptor.size.depth = arrayLayerCount;
descriptor.sampleCount = sampleCount;
descriptor.format = kDefaultTextureFormat;
descriptor.mipLevelCount = mipLevelCount;
descriptor.usage = wgpu::TextureUsage::Sampled;
return device.CreateTexture(&descriptor);
}
// It is an error to view a layer past the end of the texture.
{
wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
descriptor.arrayLayerCount = 2;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
// It is OK to create a 1-layer 2D array texture view on a 2D texture.
{
wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
descriptor.dimension = wgpu::TextureViewDimension::e2DArray;
descriptor.arrayLayerCount = 1;
texture.CreateView(&descriptor);
}
// baseMipLevel == k && mipLevelCount == 0 means to use levels k..end.
{
wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
descriptor.mipLevelCount = 0;
wgpu::TextureViewDescriptor CreateDefaultViewDescriptor(wgpu::TextureViewDimension dimension) {
wgpu::TextureViewDescriptor descriptor;
descriptor.format = kDefaultTextureFormat;
descriptor.dimension = dimension;
descriptor.baseMipLevel = 0;
texture.CreateView(&descriptor);
descriptor.baseMipLevel = 1;
texture.CreateView(&descriptor);
descriptor.baseMipLevel = kDefaultMipLevels - 1;
texture.CreateView(&descriptor);
descriptor.baseMipLevel = kDefaultMipLevels;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
// It is an error to make the mip level out of range.
{
wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
descriptor.baseMipLevel = 0;
descriptor.mipLevelCount = kDefaultMipLevels + 1;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
descriptor.baseMipLevel = 1;
descriptor.mipLevelCount = kDefaultMipLevels;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
descriptor.baseMipLevel = kDefaultMipLevels - 1;
descriptor.mipLevelCount = 2;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
descriptor.baseMipLevel = kDefaultMipLevels;
descriptor.mipLevelCount = 1;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
}
// Test creating texture view on a 2D array texture
TEST_F(TextureViewValidationTest, CreateTextureViewOnTexture2DArray) {
constexpr uint32_t kDefaultArrayLayers = 6;
wgpu::Texture texture = Create2DArrayTexture(device, kDefaultArrayLayers);
wgpu::TextureViewDescriptor base2DArrayTextureViewDescriptor =
CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2DArray);
// It is OK to create a 2D texture view on a 2D array texture.
{
wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
descriptor.dimension = wgpu::TextureViewDimension::e2D;
descriptor.arrayLayerCount = 1;
texture.CreateView(&descriptor);
}
// It is OK to create a 2D array texture view on a 2D array texture.
{
wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
descriptor.arrayLayerCount = kDefaultArrayLayers;
texture.CreateView(&descriptor);
}
// baseArrayLayer == k && arrayLayerCount == 0 means to use layers k..end.
{
wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
descriptor.arrayLayerCount = 0;
descriptor.baseArrayLayer = 0;
texture.CreateView(&descriptor);
descriptor.baseArrayLayer = 1;
texture.CreateView(&descriptor);
descriptor.baseArrayLayer = kDefaultArrayLayers - 1;
texture.CreateView(&descriptor);
descriptor.baseArrayLayer = kDefaultArrayLayers;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
// It is an error for the array layer range of the view to exceed that of the texture.
{
wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
descriptor.baseArrayLayer = 0;
descriptor.arrayLayerCount = kDefaultArrayLayers + 1;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
descriptor.baseArrayLayer = 1;
descriptor.arrayLayerCount = kDefaultArrayLayers;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
descriptor.baseArrayLayer = kDefaultArrayLayers - 1;
descriptor.arrayLayerCount = 2;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
descriptor.baseArrayLayer = kDefaultArrayLayers;
descriptor.arrayLayerCount = 1;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
}
// Using the "none" ("default") values validates the same as explicitly
// specifying the values they're supposed to default to.
// Variant for a texture with more than 1 array layer.
TEST_F(TextureViewValidationTest, TextureViewDescriptorDefaultsArray) {
constexpr uint32_t kDefaultArrayLayers = 6;
wgpu::Texture texture = Create2DArrayTexture(device, kDefaultArrayLayers);
{ texture.CreateView(); }
{
wgpu::TextureViewDescriptor descriptor;
descriptor.format = wgpu::TextureFormat::Undefined;
texture.CreateView(&descriptor);
descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
texture.CreateView(&descriptor);
descriptor.format = wgpu::TextureFormat::R8Unorm;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
{
wgpu::TextureViewDescriptor descriptor;
descriptor.dimension = wgpu::TextureViewDimension::Undefined;
texture.CreateView(&descriptor);
descriptor.dimension = wgpu::TextureViewDimension::e2DArray;
texture.CreateView(&descriptor);
descriptor.dimension = wgpu::TextureViewDimension::e2D;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
{
wgpu::TextureViewDescriptor descriptor;
// Setting array layers to non-0 means the dimensionality will
// default to 2D so by itself it causes an error.
descriptor.arrayLayerCount = kDefaultArrayLayers;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
descriptor.dimension = wgpu::TextureViewDimension::e2DArray;
texture.CreateView(&descriptor);
descriptor.mipLevelCount = kDefaultMipLevels;
texture.CreateView(&descriptor);
}
}
// Using the "none" ("default") values validates the same as explicitly
// specifying the values they're supposed to default to.
// Variant for a texture with only 1 array layer.
TEST_F(TextureViewValidationTest, TextureViewDescriptorDefaultsNonArray) {
constexpr uint32_t kDefaultArrayLayers = 1;
wgpu::Texture texture = Create2DArrayTexture(device, kDefaultArrayLayers);
{ texture.CreateView(); }
{
wgpu::TextureViewDescriptor descriptor;
descriptor.format = wgpu::TextureFormat::Undefined;
texture.CreateView(&descriptor);
descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
texture.CreateView(&descriptor);
descriptor.format = wgpu::TextureFormat::R8Unorm;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
{
wgpu::TextureViewDescriptor descriptor;
descriptor.dimension = wgpu::TextureViewDimension::Undefined;
texture.CreateView(&descriptor);
descriptor.dimension = wgpu::TextureViewDimension::e2D;
texture.CreateView(&descriptor);
descriptor.dimension = wgpu::TextureViewDimension::e2DArray;
texture.CreateView(&descriptor);
}
{
wgpu::TextureViewDescriptor descriptor;
descriptor.arrayLayerCount = 0;
texture.CreateView(&descriptor);
descriptor.arrayLayerCount = 1;
texture.CreateView(&descriptor);
descriptor.arrayLayerCount = 2;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
{
wgpu::TextureViewDescriptor descriptor;
descriptor.mipLevelCount = kDefaultMipLevels;
texture.CreateView(&descriptor);
descriptor.arrayLayerCount = kDefaultArrayLayers;
texture.CreateView(&descriptor);
}
}
// Test creating cube map texture view
TEST_F(TextureViewValidationTest, CreateCubeMapTextureView) {
constexpr uint32_t kDefaultArrayLayers = 16;
wgpu::Texture texture = Create2DArrayTexture(device, kDefaultArrayLayers);
wgpu::TextureViewDescriptor base2DArrayTextureViewDescriptor =
CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2DArray);
// It is OK to create a cube map texture view with arrayLayerCount == 6.
{
wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
descriptor.dimension = wgpu::TextureViewDimension::Cube;
descriptor.arrayLayerCount = 6;
texture.CreateView(&descriptor);
return descriptor;
}
// It is an error to create a cube map texture view with arrayLayerCount != 6.
{
wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
descriptor.dimension = wgpu::TextureViewDimension::Cube;
descriptor.arrayLayerCount = 3;
// Test creating texture view on a 2D non-array texture
TEST_F(TextureViewValidationTest, CreateTextureViewOnTexture2D) {
wgpu::Texture texture = Create2DArrayTexture(device, 1);
wgpu::TextureViewDescriptor base2DTextureViewDescriptor =
CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2D);
// It is OK to create a 2D texture view on a 2D texture.
{
wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
descriptor.arrayLayerCount = 1;
texture.CreateView(&descriptor);
}
// It is an error to view a layer past the end of the texture.
{
wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
descriptor.arrayLayerCount = 2;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
// It is OK to create a 1-layer 2D array texture view on a 2D texture.
{
wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
descriptor.dimension = wgpu::TextureViewDimension::e2DArray;
descriptor.arrayLayerCount = 1;
texture.CreateView(&descriptor);
}
// baseMipLevel == k && mipLevelCount == 0 means to use levels k..end.
{
wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
descriptor.mipLevelCount = 0;
descriptor.baseMipLevel = 0;
texture.CreateView(&descriptor);
descriptor.baseMipLevel = 1;
texture.CreateView(&descriptor);
descriptor.baseMipLevel = kDefaultMipLevels - 1;
texture.CreateView(&descriptor);
descriptor.baseMipLevel = kDefaultMipLevels;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
// It is an error to make the mip level out of range.
{
wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
descriptor.baseMipLevel = 0;
descriptor.mipLevelCount = kDefaultMipLevels + 1;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
descriptor.baseMipLevel = 1;
descriptor.mipLevelCount = kDefaultMipLevels;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
descriptor.baseMipLevel = kDefaultMipLevels - 1;
descriptor.mipLevelCount = 2;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
descriptor.baseMipLevel = kDefaultMipLevels;
descriptor.mipLevelCount = 1;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
}
// Test creating texture view on a 2D array texture
TEST_F(TextureViewValidationTest, CreateTextureViewOnTexture2DArray) {
constexpr uint32_t kDefaultArrayLayers = 6;
wgpu::Texture texture = Create2DArrayTexture(device, kDefaultArrayLayers);
wgpu::TextureViewDescriptor base2DArrayTextureViewDescriptor =
CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2DArray);
// It is OK to create a 2D texture view on a 2D array texture.
{
wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
descriptor.dimension = wgpu::TextureViewDimension::e2D;
descriptor.arrayLayerCount = 1;
texture.CreateView(&descriptor);
}
// It is OK to create a 2D array texture view on a 2D array texture.
{
wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
descriptor.arrayLayerCount = kDefaultArrayLayers;
texture.CreateView(&descriptor);
}
// baseArrayLayer == k && arrayLayerCount == 0 means to use layers k..end.
{
wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
descriptor.arrayLayerCount = 0;
descriptor.baseArrayLayer = 0;
texture.CreateView(&descriptor);
descriptor.baseArrayLayer = 1;
texture.CreateView(&descriptor);
descriptor.baseArrayLayer = kDefaultArrayLayers - 1;
texture.CreateView(&descriptor);
descriptor.baseArrayLayer = kDefaultArrayLayers;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
// It is an error for the array layer range of the view to exceed that of the texture.
{
wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
descriptor.baseArrayLayer = 0;
descriptor.arrayLayerCount = kDefaultArrayLayers + 1;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
descriptor.baseArrayLayer = 1;
descriptor.arrayLayerCount = kDefaultArrayLayers;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
descriptor.baseArrayLayer = kDefaultArrayLayers - 1;
descriptor.arrayLayerCount = 2;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
descriptor.baseArrayLayer = kDefaultArrayLayers;
descriptor.arrayLayerCount = 1;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
}
// Using the "none" ("default") values validates the same as explicitly
// specifying the values they're supposed to default to.
// Variant for a texture with more than 1 array layer.
TEST_F(TextureViewValidationTest, TextureViewDescriptorDefaultsArray) {
constexpr uint32_t kDefaultArrayLayers = 6;
wgpu::Texture texture = Create2DArrayTexture(device, kDefaultArrayLayers);
{ texture.CreateView(); }
{
wgpu::TextureViewDescriptor descriptor;
descriptor.format = wgpu::TextureFormat::Undefined;
texture.CreateView(&descriptor);
descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
texture.CreateView(&descriptor);
descriptor.format = wgpu::TextureFormat::R8Unorm;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
{
wgpu::TextureViewDescriptor descriptor;
descriptor.dimension = wgpu::TextureViewDimension::Undefined;
texture.CreateView(&descriptor);
descriptor.dimension = wgpu::TextureViewDimension::e2DArray;
texture.CreateView(&descriptor);
descriptor.dimension = wgpu::TextureViewDimension::e2D;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
{
wgpu::TextureViewDescriptor descriptor;
// Setting array layers to non-0 means the dimensionality will
// default to 2D so by itself it causes an error.
descriptor.arrayLayerCount = kDefaultArrayLayers;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
descriptor.dimension = wgpu::TextureViewDimension::e2DArray;
texture.CreateView(&descriptor);
descriptor.mipLevelCount = kDefaultMipLevels;
texture.CreateView(&descriptor);
}
}
// Using the "none" ("default") values validates the same as explicitly
// specifying the values they're supposed to default to.
// Variant for a texture with only 1 array layer.
TEST_F(TextureViewValidationTest, TextureViewDescriptorDefaultsNonArray) {
constexpr uint32_t kDefaultArrayLayers = 1;
wgpu::Texture texture = Create2DArrayTexture(device, kDefaultArrayLayers);
{ texture.CreateView(); }
{
wgpu::TextureViewDescriptor descriptor;
descriptor.format = wgpu::TextureFormat::Undefined;
texture.CreateView(&descriptor);
descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
texture.CreateView(&descriptor);
descriptor.format = wgpu::TextureFormat::R8Unorm;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
{
wgpu::TextureViewDescriptor descriptor;
descriptor.dimension = wgpu::TextureViewDimension::Undefined;
texture.CreateView(&descriptor);
descriptor.dimension = wgpu::TextureViewDimension::e2D;
texture.CreateView(&descriptor);
descriptor.dimension = wgpu::TextureViewDimension::e2DArray;
texture.CreateView(&descriptor);
}
{
wgpu::TextureViewDescriptor descriptor;
descriptor.arrayLayerCount = 0;
texture.CreateView(&descriptor);
descriptor.arrayLayerCount = 1;
texture.CreateView(&descriptor);
descriptor.arrayLayerCount = 2;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
{
wgpu::TextureViewDescriptor descriptor;
descriptor.mipLevelCount = kDefaultMipLevels;
texture.CreateView(&descriptor);
descriptor.arrayLayerCount = kDefaultArrayLayers;
texture.CreateView(&descriptor);
}
}
// Test creating cube map texture view
TEST_F(TextureViewValidationTest, CreateCubeMapTextureView) {
constexpr uint32_t kDefaultArrayLayers = 16;
wgpu::Texture texture = Create2DArrayTexture(device, kDefaultArrayLayers);
wgpu::TextureViewDescriptor base2DArrayTextureViewDescriptor =
CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2DArray);
// It is OK to create a cube map texture view with arrayLayerCount == 6.
{
wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
descriptor.dimension = wgpu::TextureViewDimension::Cube;
descriptor.arrayLayerCount = 6;
texture.CreateView(&descriptor);
}
// It is an error to create a cube map texture view with arrayLayerCount != 6.
{
wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
descriptor.dimension = wgpu::TextureViewDimension::Cube;
descriptor.arrayLayerCount = 3;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
// It is OK to create a cube map array texture view with arrayLayerCount % 6 == 0.
{
wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
descriptor.dimension = wgpu::TextureViewDimension::CubeArray;
descriptor.arrayLayerCount = 12;
texture.CreateView(&descriptor);
}
// It is an error to create a cube map array texture view with arrayLayerCount % 6 != 0.
{
wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
descriptor.dimension = wgpu::TextureViewDimension::CubeArray;
descriptor.arrayLayerCount = 11;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
// It is an error to create a cube map texture view with width != height.
{
wgpu::Texture nonSquareTexture = Create2DArrayTexture(device, 18, 32, 16, 5);
wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
descriptor.dimension = wgpu::TextureViewDimension::Cube;
descriptor.arrayLayerCount = 6;
ASSERT_DEVICE_ERROR(nonSquareTexture.CreateView(&descriptor));
}
// It is an error to create a cube map array texture view with width != height.
{
wgpu::Texture nonSquareTexture = Create2DArrayTexture(device, 18, 32, 16, 5);
wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
descriptor.dimension = wgpu::TextureViewDimension::CubeArray;
descriptor.arrayLayerCount = 12;
ASSERT_DEVICE_ERROR(nonSquareTexture.CreateView(&descriptor));
}
}
// Test the format compatibility rules when creating a texture view.
// TODO(jiawei.shao@intel.com): add more tests when the rules are fully implemented.
TEST_F(TextureViewValidationTest, TextureViewFormatCompatibility) {
wgpu::Texture texture = Create2DArrayTexture(device, 1);
wgpu::TextureViewDescriptor base2DTextureViewDescriptor =
CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2D);
// It is an error to create a texture view in depth-stencil format on a RGBA texture.
{
wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
descriptor.format = wgpu::TextureFormat::Depth24PlusStencil8;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
}
// Test that it's invalid to create a texture view from a destroyed texture
TEST_F(TextureViewValidationTest, DestroyCreateTextureView) {
wgpu::Texture texture = Create2DArrayTexture(device, 1);
wgpu::TextureViewDescriptor descriptor =
CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2D);
texture.Destroy();
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
// It is OK to create a cube map array texture view with arrayLayerCount % 6 == 0.
{
wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
descriptor.dimension = wgpu::TextureViewDimension::CubeArray;
descriptor.arrayLayerCount = 12;
texture.CreateView(&descriptor);
// Test that only TextureAspect::All is supported
TEST_F(TextureViewValidationTest, AspectMustBeAll) {
wgpu::TextureDescriptor descriptor = {};
descriptor.size = {1, 1, 1};
descriptor.format = wgpu::TextureFormat::Depth32Float;
descriptor.usage = wgpu::TextureUsage::Sampled | wgpu::TextureUsage::OutputAttachment;
wgpu::Texture texture = device.CreateTexture(&descriptor);
wgpu::TextureViewDescriptor viewDescriptor = {};
viewDescriptor.aspect = wgpu::TextureAspect::All;
texture.CreateView(&viewDescriptor);
viewDescriptor.aspect = wgpu::TextureAspect::DepthOnly;
ASSERT_DEVICE_ERROR(texture.CreateView(&viewDescriptor));
}
// It is an error to create a cube map array texture view with arrayLayerCount % 6 != 0.
{
wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
descriptor.dimension = wgpu::TextureViewDimension::CubeArray;
descriptor.arrayLayerCount = 11;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
// It is an error to create a cube map texture view with width != height.
{
wgpu::Texture nonSquareTexture = Create2DArrayTexture(device, 18, 32, 16, 5);
wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
descriptor.dimension = wgpu::TextureViewDimension::Cube;
descriptor.arrayLayerCount = 6;
ASSERT_DEVICE_ERROR(nonSquareTexture.CreateView(&descriptor));
}
// It is an error to create a cube map array texture view with width != height.
{
wgpu::Texture nonSquareTexture = Create2DArrayTexture(device, 18, 32, 16, 5);
wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
descriptor.dimension = wgpu::TextureViewDimension::CubeArray;
descriptor.arrayLayerCount = 12;
ASSERT_DEVICE_ERROR(nonSquareTexture.CreateView(&descriptor));
}
}
// Test the format compatibility rules when creating a texture view.
// TODO(jiawei.shao@intel.com): add more tests when the rules are fully implemented.
TEST_F(TextureViewValidationTest, TextureViewFormatCompatibility) {
wgpu::Texture texture = Create2DArrayTexture(device, 1);
wgpu::TextureViewDescriptor base2DTextureViewDescriptor =
CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2D);
// It is an error to create a texture view in depth-stencil format on a RGBA texture.
{
wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
descriptor.format = wgpu::TextureFormat::Depth24PlusStencil8;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
}
// Test that it's invalid to create a texture view from a destroyed texture
TEST_F(TextureViewValidationTest, DestroyCreateTextureView) {
wgpu::Texture texture = Create2DArrayTexture(device, 1);
wgpu::TextureViewDescriptor descriptor =
CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2D);
texture.Destroy();
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
// Test that only TextureAspect::All is supported
TEST_F(TextureViewValidationTest, AspectMustBeAll) {
wgpu::TextureDescriptor descriptor = {};
descriptor.size = {1, 1, 1};
descriptor.format = wgpu::TextureFormat::Depth32Float;
descriptor.usage = wgpu::TextureUsage::Sampled | wgpu::TextureUsage::OutputAttachment;
wgpu::Texture texture = device.CreateTexture(&descriptor);
wgpu::TextureViewDescriptor viewDescriptor = {};
viewDescriptor.aspect = wgpu::TextureAspect::All;
texture.CreateView(&viewDescriptor);
viewDescriptor.aspect = wgpu::TextureAspect::DepthOnly;
ASSERT_DEVICE_ERROR(texture.CreateView(&viewDescriptor));
}
} // anonymous namespace

View File

@@ -16,34 +16,67 @@
namespace {
class ToggleValidationTest : public ValidationTest {
};
class ToggleValidationTest : public ValidationTest {};
// Tests querying the detail of a toggle from dawn_native::InstanceBase works correctly.
TEST_F(ToggleValidationTest, QueryToggleInfo) {
// Query with a valid toggle name
{
const char* kValidToggleName = "emulate_store_and_msaa_resolve";
const dawn_native::ToggleInfo* toggleInfo = instance->GetToggleInfo(kValidToggleName);
ASSERT_NE(nullptr, toggleInfo);
ASSERT_NE(nullptr, toggleInfo->name);
ASSERT_NE(nullptr, toggleInfo->description);
ASSERT_NE(nullptr, toggleInfo->url);
// Tests querying the detail of a toggle from dawn_native::InstanceBase works correctly.
TEST_F(ToggleValidationTest, QueryToggleInfo) {
// Query with a valid toggle name
{
const char* kValidToggleName = "emulate_store_and_msaa_resolve";
const dawn_native::ToggleInfo* toggleInfo = instance->GetToggleInfo(kValidToggleName);
ASSERT_NE(nullptr, toggleInfo);
ASSERT_NE(nullptr, toggleInfo->name);
ASSERT_NE(nullptr, toggleInfo->description);
ASSERT_NE(nullptr, toggleInfo->url);
}
// Query with an invalid toggle name
{
const char* kInvalidToggleName = "!@#$%^&*";
const dawn_native::ToggleInfo* toggleInfo = instance->GetToggleInfo(kInvalidToggleName);
ASSERT_EQ(nullptr, toggleInfo);
}
}
// Query with an invalid toggle name
{
const char* kInvalidToggleName = "!@#$%^&*";
const dawn_native::ToggleInfo* toggleInfo = instance->GetToggleInfo(kInvalidToggleName);
ASSERT_EQ(nullptr, toggleInfo);
}
}
// Tests overriding toggles when creating a device works correctly.
TEST_F(ToggleValidationTest, OverrideToggleUsage) {
// Create device with a valid name of a toggle
{
const char* kValidToggleName = "emulate_store_and_msaa_resolve";
dawn_native::DeviceDescriptor descriptor;
descriptor.forceEnabledToggles.push_back(kValidToggleName);
// Tests overriding toggles when creating a device works correctly.
TEST_F(ToggleValidationTest, OverrideToggleUsage) {
// Create device with a valid name of a toggle
{
const char* kValidToggleName = "emulate_store_and_msaa_resolve";
WGPUDevice deviceWithToggle = adapter.CreateDevice(&descriptor);
std::vector<const char*> toggleNames = dawn_native::GetTogglesUsed(deviceWithToggle);
bool validToggleExists = false;
for (const char* toggle : toggleNames) {
if (strcmp(toggle, kValidToggleName) == 0) {
validToggleExists = true;
}
}
ASSERT_EQ(validToggleExists, true);
}
// Create device with an invalid toggle name
{
const char* kInvalidToggleName = "!@#$%^&*";
dawn_native::DeviceDescriptor descriptor;
descriptor.forceEnabledToggles.push_back(kInvalidToggleName);
WGPUDevice deviceWithToggle = adapter.CreateDevice(&descriptor);
std::vector<const char*> toggleNames = dawn_native::GetTogglesUsed(deviceWithToggle);
bool InvalidToggleExists = false;
for (const char* toggle : toggleNames) {
if (strcmp(toggle, kInvalidToggleName) == 0) {
InvalidToggleExists = true;
}
}
ASSERT_EQ(InvalidToggleExists, false);
}
}
TEST_F(ToggleValidationTest, TurnOffVsyncWithToggle) {
const char* kValidToggleName = "turn_off_vsync";
dawn_native::DeviceDescriptor descriptor;
descriptor.forceEnabledToggles.push_back(kValidToggleName);
@@ -57,38 +90,4 @@ TEST_F(ToggleValidationTest, OverrideToggleUsage) {
}
ASSERT_EQ(validToggleExists, true);
}
// Create device with an invalid toggle name
{
const char* kInvalidToggleName = "!@#$%^&*";
dawn_native::DeviceDescriptor descriptor;
descriptor.forceEnabledToggles.push_back(kInvalidToggleName);
WGPUDevice deviceWithToggle = adapter.CreateDevice(&descriptor);
std::vector<const char*> toggleNames = dawn_native::GetTogglesUsed(deviceWithToggle);
bool InvalidToggleExists = false;
for (const char* toggle : toggleNames) {
if (strcmp(toggle, kInvalidToggleName) == 0) {
InvalidToggleExists = true;
}
}
ASSERT_EQ(InvalidToggleExists, false);
}
}
TEST_F(ToggleValidationTest, TurnOffVsyncWithToggle) {
const char* kValidToggleName = "turn_off_vsync";
dawn_native::DeviceDescriptor descriptor;
descriptor.forceEnabledToggles.push_back(kValidToggleName);
WGPUDevice deviceWithToggle = adapter.CreateDevice(&descriptor);
std::vector<const char*> toggleNames = dawn_native::GetTogglesUsed(deviceWithToggle);
bool validToggleExists = false;
for (const char* toggle : toggleNames) {
if (strcmp(toggle, kValidToggleName) == 0) {
validToggleExists = true;
}
}
ASSERT_EQ(validToggleExists, true);
}
} // anonymous namespace

View File

@@ -27,7 +27,7 @@ ValidationTest::ValidationTest() {
// Validation tests run against the null backend, find the corresponding adapter
bool foundNullAdapter = false;
for (auto &currentAdapter : adapters) {
for (auto& currentAdapter : adapters) {
wgpu::AdapterProperties adapterProperties;
currentAdapter.GetProperties(&adapterProperties);
@@ -129,7 +129,7 @@ ValidationTest::DummyRenderPass::DummyRenderPass(const wgpu::Device& device)
wgpu::TextureView view = attachment.CreateView();
mColorAttachment.attachment = view;
mColorAttachment.resolveTarget = nullptr;
mColorAttachment.clearColor = { 0.0f, 0.0f, 0.0f, 0.0f };
mColorAttachment.clearColor = {0.0f, 0.0f, 0.0f, 0.0f};
mColorAttachment.loadOp = wgpu::LoadOp::Clear;
mColorAttachment.storeOp = wgpu::StoreOp::Store;

View File

@@ -70,4 +70,4 @@ class ValidationTest : public testing::Test {
bool mError = false;
};
#endif // TESTS_UNITTESTS_VALIDATIONTEST_H_
#endif // TESTS_UNITTESTS_VALIDATIONTEST_H_

View File

@@ -21,68 +21,68 @@
#include "utils/WGPUHelpers.h"
class VertexBufferValidationTest : public ValidationTest {
protected:
void SetUp() override {
ValidationTest::SetUp();
protected:
void SetUp() override {
ValidationTest::SetUp();
fsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
fsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = vec4(0.0, 1.0, 0.0, 1.0);
})");
}
wgpu::Buffer MakeVertexBuffer() {
wgpu::BufferDescriptor descriptor;
descriptor.size = 256;
descriptor.usage = wgpu::BufferUsage::Vertex;
return device.CreateBuffer(&descriptor);
}
wgpu::ShaderModule MakeVertexShader(unsigned int bufferCount) {
std::ostringstream vs;
vs << "#version 450\n";
for (unsigned int i = 0; i < bufferCount; ++i) {
vs << "layout(location = " << i << ") in vec3 a_position" << i << ";\n";
}
vs << "void main() {\n";
wgpu::Buffer MakeVertexBuffer() {
wgpu::BufferDescriptor descriptor;
descriptor.size = 256;
descriptor.usage = wgpu::BufferUsage::Vertex;
return device.CreateBuffer(&descriptor);
}
wgpu::ShaderModule MakeVertexShader(unsigned int bufferCount) {
std::ostringstream vs;
vs << "#version 450\n";
for (unsigned int i = 0; i < bufferCount; ++i) {
vs << "layout(location = " << i << ") in vec3 a_position" << i << ";\n";
vs << "gl_Position = vec4(";
for (unsigned int i = 0; i < bufferCount; ++i) {
vs << "a_position" << i;
if (i != bufferCount - 1) {
vs << " + ";
}
vs << "void main() {\n";
vs << "gl_Position = vec4(";
for (unsigned int i = 0; i < bufferCount; ++i) {
vs << "a_position" << i;
if (i != bufferCount - 1) {
vs << " + ";
}
}
vs << ", 1.0);";
vs << "}\n";
return utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex,
vs.str().c_str());
}
vs << ", 1.0);";
wgpu::RenderPipeline MakeRenderPipeline(const wgpu::ShaderModule& vsModule,
unsigned int bufferCount) {
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
vs << "}\n";
for (unsigned int i = 0; i < bufferCount; ++i) {
descriptor.cVertexState.cVertexBuffers[i].attributeCount = 1;
descriptor.cVertexState.cVertexBuffers[i].attributes =
&descriptor.cVertexState.cAttributes[i];
descriptor.cVertexState.cAttributes[i].shaderLocation = i;
descriptor.cVertexState.cAttributes[i].format = wgpu::VertexFormat::Float3;
}
descriptor.cVertexState.vertexBufferCount = bufferCount;
return utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex,
vs.str().c_str());
}
return device.CreateRenderPipeline(&descriptor);
wgpu::RenderPipeline MakeRenderPipeline(const wgpu::ShaderModule& vsModule,
unsigned int bufferCount) {
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
for (unsigned int i = 0; i < bufferCount; ++i) {
descriptor.cVertexState.cVertexBuffers[i].attributeCount = 1;
descriptor.cVertexState.cVertexBuffers[i].attributes =
&descriptor.cVertexState.cAttributes[i];
descriptor.cVertexState.cAttributes[i].shaderLocation = i;
descriptor.cVertexState.cAttributes[i].format = wgpu::VertexFormat::Float3;
}
descriptor.cVertexState.vertexBufferCount = bufferCount;
wgpu::ShaderModule fsModule;
return device.CreateRenderPipeline(&descriptor);
}
wgpu::ShaderModule fsModule;
};
TEST_F(VertexBufferValidationTest, VertexBuffersInheritedBetweenPipelines) {