From 8bff3b22be1ac768e505ec0d0e4c3bfc9eb41906 Mon Sep 17 00:00:00 2001 From: Jiawei Shao Date: Wed, 12 Dec 2018 09:27:16 +0000 Subject: [PATCH] Make TextureDescriptor match WebGPU IDL This patch updates the definition of TextureDescriptor to make it match WebGPU IDL: 1. Rename 'arrayLayer' to 'arraySize' 2. Add the missing member "sampleCount" and check that currently sampleCount can only be 1. BUG=dawn:56 TEST=dawn_unittests Change-Id: I642186529f045865ae344cb5545ac80e14445c59 Reviewed-on: https://dawn-review.googlesource.com/c/3180 Reviewed-by: Kai Ninomiya Commit-Queue: Corentin Wallez --- BUILD.gn | 9 ++- dawn.json | 5 +- examples/CppHelloTriangle.cpp | 3 +- examples/SampleUtils.cpp | 3 +- examples/glTFViewer/glTFViewer.cpp | 3 +- src/dawn_native/SwapChain.cpp | 3 +- src/dawn_native/Texture.cpp | 14 +++- src/tests/end2end/BindGroupTests.cpp | 3 +- src/tests/end2end/BlendStateTests.cpp | 3 +- src/tests/end2end/CopyTests.cpp | 20 +++--- src/tests/end2end/DepthStencilStateTests.cpp | 6 +- src/tests/end2end/RenderPassLoadOpTests.cpp | 3 +- src/tests/end2end/SamplerTests.cpp | 3 +- src/tests/end2end/TextureViewTests.cpp | 3 +- .../validation/BindGroupValidationTests.cpp | 6 +- .../CommandBufferValidationTests.cpp | 3 +- .../CopyCommandsValidationTests.cpp | 8 ++- .../RenderPassDescriptorValidationTests.cpp | 5 +- .../validation/TextureValidationTests.cpp | 68 +++++++++++++++++++ .../validation/TextureViewValidationTests.cpp | 5 +- .../unittests/validation/ValidationTest.cpp | 6 +- src/utils/DawnHelpers.cpp | 3 +- 22 files changed, 146 insertions(+), 39 deletions(-) create mode 100644 src/tests/unittests/validation/TextureValidationTests.cpp diff --git a/BUILD.gn b/BUILD.gn index 7963877b49..195204cab6 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -841,6 +841,7 @@ test("dawn_unittests") { "src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp", "src/tests/unittests/validation/RenderPipelineValidationTests.cpp", "src/tests/unittests/validation/ShaderModuleValidationTests.cpp", + "src/tests/unittests/validation/TextureValidationTests.cpp", "src/tests/unittests/validation/TextureViewValidationTests.cpp", "src/tests/unittests/validation/ValidationTest.cpp", "src/tests/unittests/validation/ValidationTest.h", @@ -908,12 +909,16 @@ test("dawn_end2end_tests") { # Temporary groups to make a 5-way patch to fix crbug.com/913171 group("dawn_unittests_temp_group") { testonly = true - deps = [ ":dawn_unittests" ] + deps = [ + ":dawn_unittests", + ] } group("dawn_end2end_tests_temp_group") { testonly = true - deps = [ ":dawn_end2end_tests" ] + deps = [ + ":dawn_end2end_tests", + ] } ############################################################################### diff --git a/dawn.json b/dawn.json index cf58c9b38c..4066d28290 100644 --- a/dawn.json +++ b/dawn.json @@ -1045,9 +1045,10 @@ {"name": "usage", "type": "texture usage bit"}, {"name": "dimension", "type": "texture dimension"}, {"name": "size", "type": "extent 3D"}, - {"name": "array layer", "type": "uint32_t"}, + {"name": "array size", "type": "uint32_t"}, {"name": "format", "type": "texture format"}, - {"name": "level count", "type": "uint32_t"} + {"name": "level count", "type": "uint32_t"}, + {"name": "sample count", "type": "uint32_t"} ] }, "texture dimension": { diff --git a/examples/CppHelloTriangle.cpp b/examples/CppHelloTriangle.cpp index f0f67940dc..44b262135b 100644 --- a/examples/CppHelloTriangle.cpp +++ b/examples/CppHelloTriangle.cpp @@ -54,7 +54,8 @@ void initTextures() { descriptor.size.width = 1024; descriptor.size.height = 1024; descriptor.size.depth = 1; - descriptor.arrayLayer = 1; + descriptor.arraySize = 1; + descriptor.sampleCount = 1; descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; descriptor.levelCount = 1; descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled; diff --git a/examples/SampleUtils.cpp b/examples/SampleUtils.cpp index 0c01964a1a..92b8a81766 100644 --- a/examples/SampleUtils.cpp +++ b/examples/SampleUtils.cpp @@ -141,7 +141,8 @@ dawn::TextureView CreateDefaultDepthStencilView(const dawn::Device& device) { descriptor.size.width = 640; descriptor.size.height = 480; descriptor.size.depth = 1; - descriptor.arrayLayer = 1; + descriptor.arraySize = 1; + descriptor.sampleCount = 1; descriptor.format = dawn::TextureFormat::D32FloatS8Uint; descriptor.levelCount = 1; descriptor.usage = dawn::TextureUsageBit::OutputAttachment; diff --git a/examples/glTFViewer/glTFViewer.cpp b/examples/glTFViewer/glTFViewer.cpp index b90b7715d6..ef9b07de9a 100644 --- a/examples/glTFViewer/glTFViewer.cpp +++ b/examples/glTFViewer/glTFViewer.cpp @@ -395,7 +395,8 @@ namespace { descriptor.size.width = iImage.width; descriptor.size.height = iImage.height; descriptor.size.depth = 1; - descriptor.arrayLayer = 1; + descriptor.arraySize = 1; + descriptor.sampleCount = 1; descriptor.format = format; descriptor.levelCount = 1; descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled; diff --git a/src/dawn_native/SwapChain.cpp b/src/dawn_native/SwapChain.cpp index 6314a0da0f..c2ea095c20 100644 --- a/src/dawn_native/SwapChain.cpp +++ b/src/dawn_native/SwapChain.cpp @@ -60,7 +60,8 @@ namespace dawn_native { descriptor.size.width = mWidth; descriptor.size.height = mHeight; descriptor.size.depth = 1; - descriptor.arrayLayer = 1; + descriptor.arraySize = 1; + descriptor.sampleCount = 1; descriptor.format = mFormat; descriptor.levelCount = 1; descriptor.usage = mAllowedUsage; diff --git a/src/dawn_native/Texture.cpp b/src/dawn_native/Texture.cpp index 4b13579305..44b416093e 100644 --- a/src/dawn_native/Texture.cpp +++ b/src/dawn_native/Texture.cpp @@ -82,6 +82,15 @@ namespace dawn_native { } } + // TODO(jiawei.shao@intel.com): support multisampled textures + MaybeError ValidateSampleCount(uint32_t sampleCount) { + if (sampleCount != 1) { + return DAWN_VALIDATION_ERROR("The sample count of the texture is not supported."); + } + + return {}; + } + MaybeError ValidateTextureViewDimensionCompatibility( const TextureBase* texture, const TextureViewDescriptor* descriptor) { @@ -142,10 +151,11 @@ namespace dawn_native { DAWN_TRY(ValidateTextureUsageBit(descriptor->usage)); DAWN_TRY(ValidateTextureDimension(descriptor->dimension)); DAWN_TRY(ValidateTextureFormat(descriptor->format)); + DAWN_TRY(ValidateSampleCount(descriptor->sampleCount)); // TODO(jiawei.shao@intel.com): check stuff based on the dimension if (descriptor->size.width == 0 || descriptor->size.height == 0 || - descriptor->size.depth == 0 || descriptor->arrayLayer == 0 || + descriptor->size.depth == 0 || descriptor->arraySize == 0 || descriptor->levelCount == 0) { return DAWN_VALIDATION_ERROR("Cannot create an empty texture"); } @@ -277,7 +287,7 @@ namespace dawn_native { mDimension(descriptor->dimension), mFormat(descriptor->format), mSize(descriptor->size), - mArrayLayers(descriptor->arrayLayer), + mArrayLayers(descriptor->arraySize), mNumMipLevels(descriptor->levelCount), mUsage(descriptor->usage) { } diff --git a/src/tests/end2end/BindGroupTests.cpp b/src/tests/end2end/BindGroupTests.cpp index fb9c97da82..4c415e01e1 100644 --- a/src/tests/end2end/BindGroupTests.cpp +++ b/src/tests/end2end/BindGroupTests.cpp @@ -228,7 +228,8 @@ TEST_P(BindGroupTests, UBOSamplerAndTexture) { descriptor.size.width = kRTSize; descriptor.size.height = kRTSize; descriptor.size.depth = 1; - descriptor.arrayLayer = 1; + descriptor.arraySize = 1; + descriptor.sampleCount = 1; descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; descriptor.levelCount = 1; descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled; diff --git a/src/tests/end2end/BlendStateTests.cpp b/src/tests/end2end/BlendStateTests.cpp index 35bb4d3b3f..af4522e5f9 100644 --- a/src/tests/end2end/BlendStateTests.cpp +++ b/src/tests/end2end/BlendStateTests.cpp @@ -717,7 +717,8 @@ TEST_P(BlendStateTest, IndependentBlendState) { descriptor.size.width = kRTSize; descriptor.size.height = kRTSize; descriptor.size.depth = 1; - descriptor.arrayLayer = 1; + descriptor.arraySize = 1; + descriptor.sampleCount = 1; descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; descriptor.levelCount = 1; descriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc; diff --git a/src/tests/end2end/CopyTests.cpp b/src/tests/end2end/CopyTests.cpp index 02c2e51e96..f6f45fa6d1 100644 --- a/src/tests/end2end/CopyTests.cpp +++ b/src/tests/end2end/CopyTests.cpp @@ -31,7 +31,7 @@ class CopyTests : public DawnTest { uint32_t copyWidth; uint32_t copyHeight; uint32_t level; - uint32_t arrayLayer = 1u; + uint32_t arraySize = 1u; }; struct BufferSpec { @@ -78,7 +78,8 @@ class CopyTests_T2B : public CopyTests { descriptor.size.width = textureSpec.width; descriptor.size.height = textureSpec.height; descriptor.size.depth = 1; - descriptor.arrayLayer = textureSpec.arrayLayer; + descriptor.arraySize = textureSpec.arraySize; + descriptor.sampleCount = 1; descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; descriptor.levelCount = textureSpec.level + 1; descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::TransferSrc; @@ -92,8 +93,8 @@ class CopyTests_T2B : public CopyTests { dawn::CommandBufferBuilder cmdBuilder = device.CreateCommandBufferBuilder(); - std::vector> textureArrayData(textureSpec.arrayLayer); - for (uint32_t slice = 0; slice < textureSpec.arrayLayer; ++slice) { + std::vector> textureArrayData(textureSpec.arraySize); + for (uint32_t slice = 0; slice < textureSpec.arraySize; ++slice) { textureArrayData[slice].resize(texelCountPerLayer); FillTextureData(width, height, rowPitch / kBytesPerTexel, textureArrayData[slice].data(), slice); @@ -112,14 +113,14 @@ class CopyTests_T2B : public CopyTests { // Note: Prepopulating the buffer with empty data ensures that there is not random data in the expectation // and helps ensure that the padding due to the row pitch is not modified by the copy dawn::BufferDescriptor bufDescriptor; - bufDescriptor.size = bufferSpec.size * textureSpec.arrayLayer; + bufDescriptor.size = bufferSpec.size * textureSpec.arraySize; bufDescriptor.usage = dawn::BufferUsageBit::TransferSrc | dawn::BufferUsageBit::TransferDst; dawn::Buffer buffer = device.CreateBuffer(&bufDescriptor); - std::vector emptyData(bufferSpec.size / kBytesPerTexel * textureSpec.arrayLayer); + std::vector emptyData(bufferSpec.size / kBytesPerTexel * textureSpec.arraySize); buffer.SetSubData(0, static_cast(emptyData.size() * sizeof(RGBA8)), reinterpret_cast(emptyData.data())); uint32_t bufferOffset = bufferSpec.offset; - for (uint32_t slice = 0; slice < textureSpec.arrayLayer; ++slice) { + for (uint32_t slice = 0; slice < textureSpec.arraySize; ++slice) { // Copy the region [(`x`, `y`), (`x + copyWidth, `y + copyWidth`)] from the `level` mip into the buffer at `offset + bufferSpec.size * slice` and `rowPitch` dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView( texture, textureSpec.level, slice, {textureSpec.x, textureSpec.y, 0}, @@ -136,7 +137,7 @@ class CopyTests_T2B : public CopyTests { bufferOffset = bufferSpec.offset; std::vector expected(bufferSpec.rowPitch / kBytesPerTexel * (textureSpec.copyHeight - 1) + textureSpec.copyWidth); - for (uint32_t slice = 0; slice < textureSpec.arrayLayer; ++slice) { + for (uint32_t slice = 0; slice < textureSpec.arraySize; ++slice) { // Pack the data used to create the upload buffer in the specified copy region to have the same format as the expected buffer data. std::fill(expected.begin(), expected.end(), RGBA8()); PackTextureData( @@ -188,7 +189,8 @@ protected: descriptor.size.width = textureSpec.width; descriptor.size.height = textureSpec.height; descriptor.size.depth = 1; - descriptor.arrayLayer = 1; + descriptor.arraySize = 1; + descriptor.sampleCount = 1; descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; descriptor.levelCount = textureSpec.level + 1; descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::TransferSrc; diff --git a/src/tests/end2end/DepthStencilStateTests.cpp b/src/tests/end2end/DepthStencilStateTests.cpp index fb6c162973..7eb080a541 100644 --- a/src/tests/end2end/DepthStencilStateTests.cpp +++ b/src/tests/end2end/DepthStencilStateTests.cpp @@ -30,7 +30,8 @@ class DepthStencilStateTest : public DawnTest { renderTargetDescriptor.size.width = kRTSize; renderTargetDescriptor.size.height = kRTSize; renderTargetDescriptor.size.depth = 1; - renderTargetDescriptor.arrayLayer = 1; + renderTargetDescriptor.arraySize = 1; + renderTargetDescriptor.sampleCount = 1; renderTargetDescriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; renderTargetDescriptor.levelCount = 1; renderTargetDescriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc; @@ -43,7 +44,8 @@ class DepthStencilStateTest : public DawnTest { depthDescriptor.size.width = kRTSize; depthDescriptor.size.height = kRTSize; depthDescriptor.size.depth = 1; - depthDescriptor.arrayLayer = 1; + depthDescriptor.arraySize = 1; + depthDescriptor.sampleCount = 1; depthDescriptor.format = dawn::TextureFormat::D32FloatS8Uint; depthDescriptor.levelCount = 1; depthDescriptor.usage = dawn::TextureUsageBit::OutputAttachment; diff --git a/src/tests/end2end/RenderPassLoadOpTests.cpp b/src/tests/end2end/RenderPassLoadOpTests.cpp index ae3c8e674c..bbf3136460 100644 --- a/src/tests/end2end/RenderPassLoadOpTests.cpp +++ b/src/tests/end2end/RenderPassLoadOpTests.cpp @@ -62,7 +62,8 @@ class RenderPassLoadOpTests : public DawnTest { descriptor.size.width = kRTSize; descriptor.size.height = kRTSize; descriptor.size.depth = 1; - descriptor.arrayLayer = 1; + descriptor.arraySize = 1; + descriptor.sampleCount = 1; descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; descriptor.levelCount = 1; descriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc; diff --git a/src/tests/end2end/SamplerTests.cpp b/src/tests/end2end/SamplerTests.cpp index 18c50b505d..8b10d8ab94 100644 --- a/src/tests/end2end/SamplerTests.cpp +++ b/src/tests/end2end/SamplerTests.cpp @@ -87,7 +87,8 @@ protected: descriptor.size.width = 2; descriptor.size.height = 2; descriptor.size.depth = 1; - descriptor.arrayLayer = 1; + descriptor.arraySize = 1; + descriptor.sampleCount = 1; descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; descriptor.levelCount = 1; descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled; diff --git a/src/tests/end2end/TextureViewTests.cpp b/src/tests/end2end/TextureViewTests.cpp index bae07d4316..cd15beec68 100644 --- a/src/tests/end2end/TextureViewTests.cpp +++ b/src/tests/end2end/TextureViewTests.cpp @@ -38,7 +38,8 @@ namespace { descriptor.size.width = width; descriptor.size.height = height; descriptor.size.depth = 1; - descriptor.arrayLayer = layerCount; + descriptor.arraySize = layerCount; + descriptor.sampleCount = 1; descriptor.format = kDefaultFormat; descriptor.levelCount = levelCount; descriptor.usage = usage; diff --git a/src/tests/unittests/validation/BindGroupValidationTests.cpp b/src/tests/unittests/validation/BindGroupValidationTests.cpp index 91f8eb7328..5718d994b2 100644 --- a/src/tests/unittests/validation/BindGroupValidationTests.cpp +++ b/src/tests/unittests/validation/BindGroupValidationTests.cpp @@ -41,7 +41,8 @@ class BindGroupValidationTest : public ValidationTest { dawn::TextureDescriptor descriptor; descriptor.dimension = dawn::TextureDimension::e2D; descriptor.size = {16, 16, 1}; - descriptor.arrayLayer = 1; + descriptor.arraySize = 1; + descriptor.sampleCount = 1; descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; descriptor.levelCount = 1; descriptor.usage = dawn::TextureUsageBit::Sampled; @@ -252,7 +253,8 @@ TEST_F(BindGroupValidationTest, TextureUsage) { dawn::TextureDescriptor descriptor; descriptor.dimension = dawn::TextureDimension::e2D; descriptor.size = {16, 16, 1}; - descriptor.arrayLayer = 1; + descriptor.arraySize = 1; + descriptor.sampleCount = 1; descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; descriptor.levelCount = 1; descriptor.usage = dawn::TextureUsageBit::OutputAttachment; diff --git a/src/tests/unittests/validation/CommandBufferValidationTests.cpp b/src/tests/unittests/validation/CommandBufferValidationTests.cpp index 7a4cecaf13..8655449c88 100644 --- a/src/tests/unittests/validation/CommandBufferValidationTests.cpp +++ b/src/tests/unittests/validation/CommandBufferValidationTests.cpp @@ -94,7 +94,8 @@ TEST_F(CommandBufferValidationTest, TextureWithReadAndWriteUsage) { textureDescriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; textureDescriptor.dimension = dawn::TextureDimension::e2D; textureDescriptor.size = {1, 1, 1}; - textureDescriptor.arrayLayer = 1; + textureDescriptor.arraySize = 1; + textureDescriptor.sampleCount = 1; textureDescriptor.levelCount = 1; dawn::Texture texture = device.CreateTexture(&textureDescriptor); dawn::TextureView view = texture.CreateDefaultTextureView(); diff --git a/src/tests/unittests/validation/CopyCommandsValidationTests.cpp b/src/tests/unittests/validation/CopyCommandsValidationTests.cpp index 6f4145090f..01bae1dcda 100644 --- a/src/tests/unittests/validation/CopyCommandsValidationTests.cpp +++ b/src/tests/unittests/validation/CopyCommandsValidationTests.cpp @@ -27,14 +27,16 @@ class CopyCommandTest : public ValidationTest { return device.CreateBuffer(&descriptor); } - dawn::Texture Create2DTexture(uint32_t width, uint32_t height, uint32_t levels, uint32_t arrayLayer, - dawn::TextureFormat format, dawn::TextureUsageBit usage) { + dawn::Texture Create2DTexture(uint32_t width, uint32_t height, uint32_t levels, + uint32_t arraySize, dawn::TextureFormat format, + dawn::TextureUsageBit usage) { dawn::TextureDescriptor descriptor; descriptor.dimension = dawn::TextureDimension::e2D; descriptor.size.width = width; descriptor.size.height = height; descriptor.size.depth = 1; - descriptor.arrayLayer = arrayLayer; + descriptor.arraySize = arraySize; + descriptor.sampleCount = 1; descriptor.format = format; descriptor.levelCount = levels; descriptor.usage = usage; diff --git a/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp b/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp index e98d1c025b..b7e0970745 100644 --- a/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp +++ b/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp @@ -26,14 +26,15 @@ dawn::Texture CreateTexture(dawn::Device& device, dawn::TextureFormat format, uint32_t width, uint32_t height, - uint32_t arrayLayer, + uint32_t arraySize, uint32_t levelCount) { dawn::TextureDescriptor descriptor; descriptor.dimension = dimension; descriptor.size.width = width; descriptor.size.height = height; descriptor.size.depth = 1; - descriptor.arrayLayer = arrayLayer; + descriptor.arraySize = arraySize; + descriptor.sampleCount = 1; descriptor.format = format; descriptor.levelCount = levelCount; descriptor.usage = dawn::TextureUsageBit::OutputAttachment; diff --git a/src/tests/unittests/validation/TextureValidationTests.cpp b/src/tests/unittests/validation/TextureValidationTests.cpp new file mode 100644 index 0000000000..ae5994b0b9 --- /dev/null +++ b/src/tests/unittests/validation/TextureValidationTests.cpp @@ -0,0 +1,68 @@ +// Copyright 2018 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "tests/unittests/validation/ValidationTest.h" + +#include "common/Constants.h" +#include "utils/DawnHelpers.h" + +namespace { + +class TextureValidationTest : public ValidationTest { +}; + +constexpr uint32_t kWidth = 32; +constexpr uint32_t kHeight = 32; +constexpr uint32_t kDefaultArraySize = 1; +constexpr uint32_t kDefaultMipLevels = 1; +constexpr uint32_t kDefaultSampleCount = 1; + +constexpr dawn::TextureFormat kDefaultTextureFormat = dawn::TextureFormat::R8G8B8A8Unorm; + +dawn::TextureDescriptor CreateDefaultTextureDescriptor() { + dawn::TextureDescriptor descriptor; + descriptor.nextInChain = nullptr; + descriptor.size.width = kWidth; + descriptor.size.height = kHeight; + descriptor.size.depth = 1; + descriptor.arraySize = kDefaultArraySize; + descriptor.levelCount = kDefaultMipLevels; + descriptor.sampleCount = kDefaultSampleCount; + descriptor.dimension = dawn::TextureDimension::e2D; + descriptor.format = kDefaultTextureFormat; + descriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::Sampled; + return descriptor; +} + +// Test the validation of sample count +TEST_F(TextureValidationTest, SampleCount) { + dawn::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor(); + + // sampleCount == 1 is allowed. + { + dawn::TextureDescriptor descriptor = defaultDescriptor; + descriptor.sampleCount = 1; + + device.CreateTexture(&descriptor); + } + + // It is an error to create a texture with an invalid sampleCount. + { + dawn::TextureDescriptor descriptor = defaultDescriptor; + descriptor.sampleCount = 3; + + ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor)); + } +} +} \ No newline at end of file diff --git a/src/tests/unittests/validation/TextureViewValidationTests.cpp b/src/tests/unittests/validation/TextureViewValidationTests.cpp index 0d4ec769e2..93c41e7b19 100644 --- a/src/tests/unittests/validation/TextureViewValidationTests.cpp +++ b/src/tests/unittests/validation/TextureViewValidationTests.cpp @@ -26,7 +26,7 @@ constexpr uint32_t kDefaultMipLevels = 6u; constexpr dawn::TextureFormat kDefaultTextureFormat = dawn::TextureFormat::R8G8B8A8Unorm; dawn::Texture Create2DArrayTexture(dawn::Device& device, - uint32_t arrayLayers, + uint32_t arraySize, uint32_t width = kWidth, uint32_t height = kHeight) { dawn::TextureDescriptor descriptor; @@ -34,7 +34,8 @@ dawn::Texture Create2DArrayTexture(dawn::Device& device, descriptor.size.width = width; descriptor.size.height = height; descriptor.size.depth = 1; - descriptor.arrayLayer = arrayLayers; + descriptor.arraySize = arraySize; + descriptor.sampleCount = 1; descriptor.format = kDefaultTextureFormat; descriptor.levelCount = kDefaultMipLevels; descriptor.usage = dawn::TextureUsageBit::Sampled; diff --git a/src/tests/unittests/validation/ValidationTest.cpp b/src/tests/unittests/validation/ValidationTest.cpp index a5af880787..2a6aaebb5e 100644 --- a/src/tests/unittests/validation/ValidationTest.cpp +++ b/src/tests/unittests/validation/ValidationTest.cpp @@ -79,7 +79,8 @@ dawn::RenderPassDescriptor ValidationTest::CreateSimpleRenderPass() { descriptor.size.width = 640; descriptor.size.height = 480; descriptor.size.depth = 1; - descriptor.arrayLayer = 1; + descriptor.arraySize = 1; + descriptor.sampleCount = 1; descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; descriptor.levelCount = 1; descriptor.usage = dawn::TextureUsageBit::OutputAttachment; @@ -132,7 +133,8 @@ ValidationTest::DummyRenderPass ValidationTest::CreateDummyRenderPass() { descriptor.size.width = dummy.width; descriptor.size.height = dummy.height; descriptor.size.depth = 1; - descriptor.arrayLayer = 1; + descriptor.arraySize = 1; + descriptor.sampleCount = 1; descriptor.format = dummy.attachmentFormat; descriptor.levelCount = 1; descriptor.usage = dawn::TextureUsageBit::OutputAttachment; diff --git a/src/utils/DawnHelpers.cpp b/src/utils/DawnHelpers.cpp index 624c114050..115b023c23 100644 --- a/src/utils/DawnHelpers.cpp +++ b/src/utils/DawnHelpers.cpp @@ -138,7 +138,8 @@ namespace utils { descriptor.size.width = width; descriptor.size.height = height; descriptor.size.depth = 1; - descriptor.arrayLayer = 1; + descriptor.arraySize = 1; + descriptor.sampleCount = 1; descriptor.format = result.colorFormat; descriptor.levelCount = 1; descriptor.usage =