mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 08:27:05 +00:00
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 <kainino@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
d86edb310a
commit
8bff3b22be
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<std::vector<RGBA8>> textureArrayData(textureSpec.arrayLayer);
|
||||
for (uint32_t slice = 0; slice < textureSpec.arrayLayer; ++slice) {
|
||||
std::vector<std::vector<RGBA8>> 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<RGBA8> emptyData(bufferSpec.size / kBytesPerTexel * textureSpec.arrayLayer);
|
||||
std::vector<RGBA8> emptyData(bufferSpec.size / kBytesPerTexel * textureSpec.arraySize);
|
||||
buffer.SetSubData(0, static_cast<uint32_t>(emptyData.size() * sizeof(RGBA8)), reinterpret_cast<const uint8_t*>(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<RGBA8> 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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
68
src/tests/unittests/validation/TextureValidationTests.cpp
Normal file
68
src/tests/unittests/validation/TextureValidationTests.cpp
Normal file
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user