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:
Jiawei Shao 2018-12-12 09:27:16 +00:00 committed by Commit Bot service account
parent d86edb310a
commit 8bff3b22be
22 changed files with 146 additions and 39 deletions

View File

@ -841,6 +841,7 @@ test("dawn_unittests") {
"src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp", "src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp",
"src/tests/unittests/validation/RenderPipelineValidationTests.cpp", "src/tests/unittests/validation/RenderPipelineValidationTests.cpp",
"src/tests/unittests/validation/ShaderModuleValidationTests.cpp", "src/tests/unittests/validation/ShaderModuleValidationTests.cpp",
"src/tests/unittests/validation/TextureValidationTests.cpp",
"src/tests/unittests/validation/TextureViewValidationTests.cpp", "src/tests/unittests/validation/TextureViewValidationTests.cpp",
"src/tests/unittests/validation/ValidationTest.cpp", "src/tests/unittests/validation/ValidationTest.cpp",
"src/tests/unittests/validation/ValidationTest.h", "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 # Temporary groups to make a 5-way patch to fix crbug.com/913171
group("dawn_unittests_temp_group") { group("dawn_unittests_temp_group") {
testonly = true testonly = true
deps = [ ":dawn_unittests" ] deps = [
":dawn_unittests",
]
} }
group("dawn_end2end_tests_temp_group") { group("dawn_end2end_tests_temp_group") {
testonly = true testonly = true
deps = [ ":dawn_end2end_tests" ] deps = [
":dawn_end2end_tests",
]
} }
############################################################################### ###############################################################################

View File

@ -1045,9 +1045,10 @@
{"name": "usage", "type": "texture usage bit"}, {"name": "usage", "type": "texture usage bit"},
{"name": "dimension", "type": "texture dimension"}, {"name": "dimension", "type": "texture dimension"},
{"name": "size", "type": "extent 3D"}, {"name": "size", "type": "extent 3D"},
{"name": "array layer", "type": "uint32_t"}, {"name": "array size", "type": "uint32_t"},
{"name": "format", "type": "texture format"}, {"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": { "texture dimension": {

View File

@ -54,7 +54,8 @@ void initTextures() {
descriptor.size.width = 1024; descriptor.size.width = 1024;
descriptor.size.height = 1024; descriptor.size.height = 1024;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayer = 1; descriptor.arraySize = 1;
descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
descriptor.levelCount = 1; descriptor.levelCount = 1;
descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled; descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled;

View File

@ -141,7 +141,8 @@ dawn::TextureView CreateDefaultDepthStencilView(const dawn::Device& device) {
descriptor.size.width = 640; descriptor.size.width = 640;
descriptor.size.height = 480; descriptor.size.height = 480;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayer = 1; descriptor.arraySize = 1;
descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::D32FloatS8Uint; descriptor.format = dawn::TextureFormat::D32FloatS8Uint;
descriptor.levelCount = 1; descriptor.levelCount = 1;
descriptor.usage = dawn::TextureUsageBit::OutputAttachment; descriptor.usage = dawn::TextureUsageBit::OutputAttachment;

View File

@ -395,7 +395,8 @@ namespace {
descriptor.size.width = iImage.width; descriptor.size.width = iImage.width;
descriptor.size.height = iImage.height; descriptor.size.height = iImage.height;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayer = 1; descriptor.arraySize = 1;
descriptor.sampleCount = 1;
descriptor.format = format; descriptor.format = format;
descriptor.levelCount = 1; descriptor.levelCount = 1;
descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled; descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled;

View File

@ -60,7 +60,8 @@ namespace dawn_native {
descriptor.size.width = mWidth; descriptor.size.width = mWidth;
descriptor.size.height = mHeight; descriptor.size.height = mHeight;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayer = 1; descriptor.arraySize = 1;
descriptor.sampleCount = 1;
descriptor.format = mFormat; descriptor.format = mFormat;
descriptor.levelCount = 1; descriptor.levelCount = 1;
descriptor.usage = mAllowedUsage; descriptor.usage = mAllowedUsage;

View File

@ -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( MaybeError ValidateTextureViewDimensionCompatibility(
const TextureBase* texture, const TextureBase* texture,
const TextureViewDescriptor* descriptor) { const TextureViewDescriptor* descriptor) {
@ -142,10 +151,11 @@ namespace dawn_native {
DAWN_TRY(ValidateTextureUsageBit(descriptor->usage)); DAWN_TRY(ValidateTextureUsageBit(descriptor->usage));
DAWN_TRY(ValidateTextureDimension(descriptor->dimension)); DAWN_TRY(ValidateTextureDimension(descriptor->dimension));
DAWN_TRY(ValidateTextureFormat(descriptor->format)); DAWN_TRY(ValidateTextureFormat(descriptor->format));
DAWN_TRY(ValidateSampleCount(descriptor->sampleCount));
// TODO(jiawei.shao@intel.com): check stuff based on the dimension // TODO(jiawei.shao@intel.com): check stuff based on the dimension
if (descriptor->size.width == 0 || descriptor->size.height == 0 || 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) { descriptor->levelCount == 0) {
return DAWN_VALIDATION_ERROR("Cannot create an empty texture"); return DAWN_VALIDATION_ERROR("Cannot create an empty texture");
} }
@ -277,7 +287,7 @@ namespace dawn_native {
mDimension(descriptor->dimension), mDimension(descriptor->dimension),
mFormat(descriptor->format), mFormat(descriptor->format),
mSize(descriptor->size), mSize(descriptor->size),
mArrayLayers(descriptor->arrayLayer), mArrayLayers(descriptor->arraySize),
mNumMipLevels(descriptor->levelCount), mNumMipLevels(descriptor->levelCount),
mUsage(descriptor->usage) { mUsage(descriptor->usage) {
} }

View File

@ -228,7 +228,8 @@ TEST_P(BindGroupTests, UBOSamplerAndTexture) {
descriptor.size.width = kRTSize; descriptor.size.width = kRTSize;
descriptor.size.height = kRTSize; descriptor.size.height = kRTSize;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayer = 1; descriptor.arraySize = 1;
descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
descriptor.levelCount = 1; descriptor.levelCount = 1;
descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled; descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled;

View File

@ -717,7 +717,8 @@ TEST_P(BlendStateTest, IndependentBlendState) {
descriptor.size.width = kRTSize; descriptor.size.width = kRTSize;
descriptor.size.height = kRTSize; descriptor.size.height = kRTSize;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayer = 1; descriptor.arraySize = 1;
descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
descriptor.levelCount = 1; descriptor.levelCount = 1;
descriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc; descriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc;

View File

@ -31,7 +31,7 @@ class CopyTests : public DawnTest {
uint32_t copyWidth; uint32_t copyWidth;
uint32_t copyHeight; uint32_t copyHeight;
uint32_t level; uint32_t level;
uint32_t arrayLayer = 1u; uint32_t arraySize = 1u;
}; };
struct BufferSpec { struct BufferSpec {
@ -78,7 +78,8 @@ class CopyTests_T2B : public CopyTests {
descriptor.size.width = textureSpec.width; descriptor.size.width = textureSpec.width;
descriptor.size.height = textureSpec.height; descriptor.size.height = textureSpec.height;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayer = textureSpec.arrayLayer; descriptor.arraySize = textureSpec.arraySize;
descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
descriptor.levelCount = textureSpec.level + 1; descriptor.levelCount = textureSpec.level + 1;
descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::TransferSrc; descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::TransferSrc;
@ -92,8 +93,8 @@ class CopyTests_T2B : public CopyTests {
dawn::CommandBufferBuilder cmdBuilder = device.CreateCommandBufferBuilder(); dawn::CommandBufferBuilder cmdBuilder = device.CreateCommandBufferBuilder();
std::vector<std::vector<RGBA8>> textureArrayData(textureSpec.arrayLayer); std::vector<std::vector<RGBA8>> textureArrayData(textureSpec.arraySize);
for (uint32_t slice = 0; slice < textureSpec.arrayLayer; ++slice) { for (uint32_t slice = 0; slice < textureSpec.arraySize; ++slice) {
textureArrayData[slice].resize(texelCountPerLayer); textureArrayData[slice].resize(texelCountPerLayer);
FillTextureData(width, height, rowPitch / kBytesPerTexel, textureArrayData[slice].data(), slice); 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 // 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 // and helps ensure that the padding due to the row pitch is not modified by the copy
dawn::BufferDescriptor bufDescriptor; dawn::BufferDescriptor bufDescriptor;
bufDescriptor.size = bufferSpec.size * textureSpec.arrayLayer; bufDescriptor.size = bufferSpec.size * textureSpec.arraySize;
bufDescriptor.usage = dawn::BufferUsageBit::TransferSrc | dawn::BufferUsageBit::TransferDst; bufDescriptor.usage = dawn::BufferUsageBit::TransferSrc | dawn::BufferUsageBit::TransferDst;
dawn::Buffer buffer = device.CreateBuffer(&bufDescriptor); 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())); buffer.SetSubData(0, static_cast<uint32_t>(emptyData.size() * sizeof(RGBA8)), reinterpret_cast<const uint8_t*>(emptyData.data()));
uint32_t bufferOffset = bufferSpec.offset; 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` // 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( dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(
texture, textureSpec.level, slice, {textureSpec.x, textureSpec.y, 0}, texture, textureSpec.level, slice, {textureSpec.x, textureSpec.y, 0},
@ -136,7 +137,7 @@ class CopyTests_T2B : public CopyTests {
bufferOffset = bufferSpec.offset; bufferOffset = bufferSpec.offset;
std::vector<RGBA8> expected(bufferSpec.rowPitch / kBytesPerTexel * (textureSpec.copyHeight - 1) + textureSpec.copyWidth); 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. // 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()); std::fill(expected.begin(), expected.end(), RGBA8());
PackTextureData( PackTextureData(
@ -188,7 +189,8 @@ protected:
descriptor.size.width = textureSpec.width; descriptor.size.width = textureSpec.width;
descriptor.size.height = textureSpec.height; descriptor.size.height = textureSpec.height;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayer = 1; descriptor.arraySize = 1;
descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
descriptor.levelCount = textureSpec.level + 1; descriptor.levelCount = textureSpec.level + 1;
descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::TransferSrc; descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::TransferSrc;

View File

@ -30,7 +30,8 @@ class DepthStencilStateTest : public DawnTest {
renderTargetDescriptor.size.width = kRTSize; renderTargetDescriptor.size.width = kRTSize;
renderTargetDescriptor.size.height = kRTSize; renderTargetDescriptor.size.height = kRTSize;
renderTargetDescriptor.size.depth = 1; renderTargetDescriptor.size.depth = 1;
renderTargetDescriptor.arrayLayer = 1; renderTargetDescriptor.arraySize = 1;
renderTargetDescriptor.sampleCount = 1;
renderTargetDescriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; renderTargetDescriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
renderTargetDescriptor.levelCount = 1; renderTargetDescriptor.levelCount = 1;
renderTargetDescriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc; renderTargetDescriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc;
@ -43,7 +44,8 @@ class DepthStencilStateTest : public DawnTest {
depthDescriptor.size.width = kRTSize; depthDescriptor.size.width = kRTSize;
depthDescriptor.size.height = kRTSize; depthDescriptor.size.height = kRTSize;
depthDescriptor.size.depth = 1; depthDescriptor.size.depth = 1;
depthDescriptor.arrayLayer = 1; depthDescriptor.arraySize = 1;
depthDescriptor.sampleCount = 1;
depthDescriptor.format = dawn::TextureFormat::D32FloatS8Uint; depthDescriptor.format = dawn::TextureFormat::D32FloatS8Uint;
depthDescriptor.levelCount = 1; depthDescriptor.levelCount = 1;
depthDescriptor.usage = dawn::TextureUsageBit::OutputAttachment; depthDescriptor.usage = dawn::TextureUsageBit::OutputAttachment;

View File

@ -62,7 +62,8 @@ class RenderPassLoadOpTests : public DawnTest {
descriptor.size.width = kRTSize; descriptor.size.width = kRTSize;
descriptor.size.height = kRTSize; descriptor.size.height = kRTSize;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayer = 1; descriptor.arraySize = 1;
descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
descriptor.levelCount = 1; descriptor.levelCount = 1;
descriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc; descriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc;

View File

@ -87,7 +87,8 @@ protected:
descriptor.size.width = 2; descriptor.size.width = 2;
descriptor.size.height = 2; descriptor.size.height = 2;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayer = 1; descriptor.arraySize = 1;
descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
descriptor.levelCount = 1; descriptor.levelCount = 1;
descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled; descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled;

View File

@ -38,7 +38,8 @@ namespace {
descriptor.size.width = width; descriptor.size.width = width;
descriptor.size.height = height; descriptor.size.height = height;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayer = layerCount; descriptor.arraySize = layerCount;
descriptor.sampleCount = 1;
descriptor.format = kDefaultFormat; descriptor.format = kDefaultFormat;
descriptor.levelCount = levelCount; descriptor.levelCount = levelCount;
descriptor.usage = usage; descriptor.usage = usage;

View File

@ -41,7 +41,8 @@ class BindGroupValidationTest : public ValidationTest {
dawn::TextureDescriptor descriptor; dawn::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = dawn::TextureDimension::e2D;
descriptor.size = {16, 16, 1}; descriptor.size = {16, 16, 1};
descriptor.arrayLayer = 1; descriptor.arraySize = 1;
descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
descriptor.levelCount = 1; descriptor.levelCount = 1;
descriptor.usage = dawn::TextureUsageBit::Sampled; descriptor.usage = dawn::TextureUsageBit::Sampled;
@ -252,7 +253,8 @@ TEST_F(BindGroupValidationTest, TextureUsage) {
dawn::TextureDescriptor descriptor; dawn::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = dawn::TextureDimension::e2D;
descriptor.size = {16, 16, 1}; descriptor.size = {16, 16, 1};
descriptor.arrayLayer = 1; descriptor.arraySize = 1;
descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
descriptor.levelCount = 1; descriptor.levelCount = 1;
descriptor.usage = dawn::TextureUsageBit::OutputAttachment; descriptor.usage = dawn::TextureUsageBit::OutputAttachment;

View File

@ -94,7 +94,8 @@ TEST_F(CommandBufferValidationTest, TextureWithReadAndWriteUsage) {
textureDescriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; textureDescriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
textureDescriptor.dimension = dawn::TextureDimension::e2D; textureDescriptor.dimension = dawn::TextureDimension::e2D;
textureDescriptor.size = {1, 1, 1}; textureDescriptor.size = {1, 1, 1};
textureDescriptor.arrayLayer = 1; textureDescriptor.arraySize = 1;
textureDescriptor.sampleCount = 1;
textureDescriptor.levelCount = 1; textureDescriptor.levelCount = 1;
dawn::Texture texture = device.CreateTexture(&textureDescriptor); dawn::Texture texture = device.CreateTexture(&textureDescriptor);
dawn::TextureView view = texture.CreateDefaultTextureView(); dawn::TextureView view = texture.CreateDefaultTextureView();

View File

@ -27,14 +27,16 @@ class CopyCommandTest : public ValidationTest {
return device.CreateBuffer(&descriptor); return device.CreateBuffer(&descriptor);
} }
dawn::Texture Create2DTexture(uint32_t width, uint32_t height, uint32_t levels, uint32_t arrayLayer, dawn::Texture Create2DTexture(uint32_t width, uint32_t height, uint32_t levels,
dawn::TextureFormat format, dawn::TextureUsageBit usage) { uint32_t arraySize, dawn::TextureFormat format,
dawn::TextureUsageBit usage) {
dawn::TextureDescriptor descriptor; dawn::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = dawn::TextureDimension::e2D;
descriptor.size.width = width; descriptor.size.width = width;
descriptor.size.height = height; descriptor.size.height = height;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayer = arrayLayer; descriptor.arraySize = arraySize;
descriptor.sampleCount = 1;
descriptor.format = format; descriptor.format = format;
descriptor.levelCount = levels; descriptor.levelCount = levels;
descriptor.usage = usage; descriptor.usage = usage;

View File

@ -26,14 +26,15 @@ dawn::Texture CreateTexture(dawn::Device& device,
dawn::TextureFormat format, dawn::TextureFormat format,
uint32_t width, uint32_t width,
uint32_t height, uint32_t height,
uint32_t arrayLayer, uint32_t arraySize,
uint32_t levelCount) { uint32_t levelCount) {
dawn::TextureDescriptor descriptor; dawn::TextureDescriptor descriptor;
descriptor.dimension = dimension; descriptor.dimension = dimension;
descriptor.size.width = width; descriptor.size.width = width;
descriptor.size.height = height; descriptor.size.height = height;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayer = arrayLayer; descriptor.arraySize = arraySize;
descriptor.sampleCount = 1;
descriptor.format = format; descriptor.format = format;
descriptor.levelCount = levelCount; descriptor.levelCount = levelCount;
descriptor.usage = dawn::TextureUsageBit::OutputAttachment; descriptor.usage = dawn::TextureUsageBit::OutputAttachment;

View 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));
}
}
}

View File

@ -26,7 +26,7 @@ constexpr uint32_t kDefaultMipLevels = 6u;
constexpr dawn::TextureFormat kDefaultTextureFormat = dawn::TextureFormat::R8G8B8A8Unorm; constexpr dawn::TextureFormat kDefaultTextureFormat = dawn::TextureFormat::R8G8B8A8Unorm;
dawn::Texture Create2DArrayTexture(dawn::Device& device, dawn::Texture Create2DArrayTexture(dawn::Device& device,
uint32_t arrayLayers, uint32_t arraySize,
uint32_t width = kWidth, uint32_t width = kWidth,
uint32_t height = kHeight) { uint32_t height = kHeight) {
dawn::TextureDescriptor descriptor; dawn::TextureDescriptor descriptor;
@ -34,7 +34,8 @@ dawn::Texture Create2DArrayTexture(dawn::Device& device,
descriptor.size.width = width; descriptor.size.width = width;
descriptor.size.height = height; descriptor.size.height = height;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayer = arrayLayers; descriptor.arraySize = arraySize;
descriptor.sampleCount = 1;
descriptor.format = kDefaultTextureFormat; descriptor.format = kDefaultTextureFormat;
descriptor.levelCount = kDefaultMipLevels; descriptor.levelCount = kDefaultMipLevels;
descriptor.usage = dawn::TextureUsageBit::Sampled; descriptor.usage = dawn::TextureUsageBit::Sampled;

View File

@ -79,7 +79,8 @@ dawn::RenderPassDescriptor ValidationTest::CreateSimpleRenderPass() {
descriptor.size.width = 640; descriptor.size.width = 640;
descriptor.size.height = 480; descriptor.size.height = 480;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayer = 1; descriptor.arraySize = 1;
descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm; descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
descriptor.levelCount = 1; descriptor.levelCount = 1;
descriptor.usage = dawn::TextureUsageBit::OutputAttachment; descriptor.usage = dawn::TextureUsageBit::OutputAttachment;
@ -132,7 +133,8 @@ ValidationTest::DummyRenderPass ValidationTest::CreateDummyRenderPass() {
descriptor.size.width = dummy.width; descriptor.size.width = dummy.width;
descriptor.size.height = dummy.height; descriptor.size.height = dummy.height;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayer = 1; descriptor.arraySize = 1;
descriptor.sampleCount = 1;
descriptor.format = dummy.attachmentFormat; descriptor.format = dummy.attachmentFormat;
descriptor.levelCount = 1; descriptor.levelCount = 1;
descriptor.usage = dawn::TextureUsageBit::OutputAttachment; descriptor.usage = dawn::TextureUsageBit::OutputAttachment;

View File

@ -138,7 +138,8 @@ namespace utils {
descriptor.size.width = width; descriptor.size.width = width;
descriptor.size.height = height; descriptor.size.height = height;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayer = 1; descriptor.arraySize = 1;
descriptor.sampleCount = 1;
descriptor.format = result.colorFormat; descriptor.format = result.colorFormat;
descriptor.levelCount = 1; descriptor.levelCount = 1;
descriptor.usage = descriptor.usage =