Make TextureFormat/ViewDimension::None Undefined and value 0.

This matches the conclusion the changes in the webgpu-header pull
request where we discussed these values:
https://github.com/webgpu-native/webgpu-headers/pull/5

BUG=dawn:22
Bug=dawn:214

Change-Id: I7e9168c2b5e09dcb4c1882725a5cc0580a73d853
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/10860
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2019-09-05 09:12:32 +00:00 committed by Commit Bot service account
parent 3bcb567d8f
commit d55bd7ad94
9 changed files with 89 additions and 83 deletions

126
dawn.json
View File

@ -879,7 +879,7 @@
"members": [ "members": [
{"name": "color formats count", "type": "uint32_t"}, {"name": "color formats count", "type": "uint32_t"},
{"name": "color formats", "type": "texture format", "annotation": "const*", "length": "color formats count"}, {"name": "color formats", "type": "texture format", "annotation": "const*", "length": "color formats count"},
{"name": "depth stencil format", "type": "texture format", "default": "none"}, {"name": "depth stencil format", "type": "texture format", "default": "undefined"},
{"name": "sample count", "type": "uint32_t", "default": "1"} {"name": "sample count", "type": "uint32_t", "default": "1"}
] ]
}, },
@ -1221,65 +1221,65 @@
"texture format": { "texture format": {
"category": "enum", "category": "enum",
"values": [ "values": [
{"value": 0, "name": "R8 unorm"}, {"value": 0, "name": "undefined", "valid": false},
{"value": 1, "name": "R8 snorm"}, {"value": 1, "name": "R8 unorm"},
{"value": 2, "name": "R8 uint"}, {"value": 2, "name": "R8 snorm"},
{"value": 3, "name": "R8 sint"}, {"value": 3, "name": "R8 uint"},
{"value": 4, "name": "R8 sint"},
{"value": 4, "name": "R16 uint"}, {"value": 5, "name": "R16 uint"},
{"value": 5, "name": "R16 sint"}, {"value": 6, "name": "R16 sint"},
{"value": 6, "name": "R16 float"}, {"value": 7, "name": "R16 float"},
{"value": 7, "name": "RG8 unorm"}, {"value": 8, "name": "RG8 unorm"},
{"value": 8, "name": "RG8 snorm"}, {"value": 9, "name": "RG8 snorm"},
{"value": 9, "name": "RG8 uint"}, {"value": 10, "name": "RG8 uint"},
{"value": 10, "name": "RG8 sint"}, {"value": 11, "name": "RG8 sint"},
{"value": 11, "name": "R32 float"}, {"value": 12, "name": "R32 float"},
{"value": 12, "name": "R32 uint"}, {"value": 13, "name": "R32 uint"},
{"value": 13, "name": "R32 sint"}, {"value": 14, "name": "R32 sint"},
{"value": 14, "name": "RG16 uint"}, {"value": 15, "name": "RG16 uint"},
{"value": 15, "name": "RG16 sint"}, {"value": 16, "name": "RG16 sint"},
{"value": 16, "name": "RG16 float"}, {"value": 17, "name": "RG16 float"},
{"value": 17, "name": "RGBA8 unorm"}, {"value": 18, "name": "RGBA8 unorm"},
{"value": 18, "name": "RGBA8 unorm srgb"}, {"value": 19, "name": "RGBA8 unorm srgb"},
{"value": 19, "name": "RGBA8 snorm"}, {"value": 20, "name": "RGBA8 snorm"},
{"value": 20, "name": "RGBA8 uint"}, {"value": 21, "name": "RGBA8 uint"},
{"value": 21, "name": "RGBA8 sint"}, {"value": 22, "name": "RGBA8 sint"},
{"value": 22, "name": "BGRA8 unorm"}, {"value": 23, "name": "BGRA8 unorm"},
{"value": 23, "name": "BGRA8 unorm srgb"}, {"value": 24, "name": "BGRA8 unorm srgb"},
{"value": 24, "name": "RGB10 A2 unorm"}, {"value": 25, "name": "RGB10 A2 unorm"},
{"value": 25, "name": "RG11 B10 float"}, {"value": 26, "name": "RG11 B10 float"},
{"value": 26, "name": "RG32 float"}, {"value": 27, "name": "RG32 float"},
{"value": 27, "name": "RG32 uint"}, {"value": 28, "name": "RG32 uint"},
{"value": 28, "name": "RG32 sint"}, {"value": 29, "name": "RG32 sint"},
{"value": 29, "name": "RGBA16 uint"}, {"value": 30, "name": "RGBA16 uint"},
{"value": 30, "name": "RGBA16 sint"}, {"value": 31, "name": "RGBA16 sint"},
{"value": 31, "name": "RGBA16 float"}, {"value": 32, "name": "RGBA16 float"},
{"value": 32, "name": "RGBA32 float"}, {"value": 33, "name": "RGBA32 float"},
{"value": 33, "name": "RGBA32 uint"}, {"value": 34, "name": "RGBA32 uint"},
{"value": 34, "name": "RGBA32 sint"}, {"value": 35, "name": "RGBA32 sint"},
{"value": 35, "name": "depth32 float"}, {"value": 36, "name": "depth32 float"},
{"value": 36, "name": "depth24 plus"}, {"value": 37, "name": "depth24 plus"},
{"value": 37, "name": "depth24 plus stencil8"}, {"value": 38, "name": "depth24 plus stencil8"},
{"value": 38, "name": "BC1 RGBA unorm"}, {"value": 39, "name": "BC1 RGBA unorm"},
{"value": 39, "name": "BC1 RGBA unorm srgb"}, {"value": 40, "name": "BC1 RGBA unorm srgb"},
{"value": 40, "name": "BC2 RGBA unorm"}, {"value": 41, "name": "BC2 RGBA unorm"},
{"value": 41, "name": "BC2 RGBA unorm srgb"}, {"value": 42, "name": "BC2 RGBA unorm srgb"},
{"value": 42, "name": "BC3 RGBA unorm"}, {"value": 43, "name": "BC3 RGBA unorm"},
{"value": 43, "name": "BC3 RGBA unorm srgb"}, {"value": 44, "name": "BC3 RGBA unorm srgb"},
{"value": 44, "name": "BC4 R unorm"}, {"value": 45, "name": "BC4 R unorm"},
{"value": 45, "name": "BC4 R snorm"}, {"value": 46, "name": "BC4 R snorm"},
{"value": 46, "name": "BC5 RG unorm"}, {"value": 47, "name": "BC5 RG unorm"},
{"value": 47, "name": "BC5 RG snorm"}, {"value": 48, "name": "BC5 RG snorm"},
{"value": 48, "name": "BC6H RGB ufloat"}, {"value": 49, "name": "BC6H RGB ufloat"},
{"value": 49, "name": "BC6H RGB sfloat"}, {"value": 50, "name": "BC6H RGB sfloat"},
{"value": 50, "name": "BC7 RGBA unorm"}, {"value": 51, "name": "BC7 RGBA unorm"},
{"value": 51, "name": "BC7 RGBA unorm srgb"}, {"value": 52, "name": "BC7 RGBA unorm srgb"}
{"value": 4294967295, "name": "none", "valid": false}
] ]
}, },
"texture usage": { "texture usage": {
@ -1298,8 +1298,8 @@
"category": "structure", "category": "structure",
"extensible": true, "extensible": true,
"members": [ "members": [
{"name": "format", "type": "texture format", "default": "none"}, {"name": "format", "type": "texture format", "default": "undefined"},
{"name": "dimension", "type": "texture view dimension", "default": "none"}, {"name": "dimension", "type": "texture view dimension", "default": "undefined"},
{"name": "base mip level", "type": "uint32_t", "default": "0"}, {"name": "base mip level", "type": "uint32_t", "default": "0"},
{"name": "mip level count", "type": "uint32_t", "default": "0"}, {"name": "mip level count", "type": "uint32_t", "default": "0"},
{"name": "base array layer", "type": "uint32_t", "default": "0"}, {"name": "base array layer", "type": "uint32_t", "default": "0"},
@ -1315,13 +1315,13 @@
"texture view dimension": { "texture view dimension": {
"category": "enum", "category": "enum",
"values": [ "values": [
{"value": 0, "name": "1D"}, {"value": 0, "name": "undefined", "valid": false},
{"value": 1, "name": "2D"}, {"value": 1, "name": "1D"},
{"value": 2, "name": "2D array"}, {"value": 2, "name": "2D"},
{"value": 3, "name": "cube"}, {"value": 3, "name": "2D array"},
{"value": 4, "name": "cube array"}, {"value": 4, "name": "cube"},
{"value": 5, "name": "3D"}, {"value": 5, "name": "cube array"},
{"value": 4294967295, "name": "none", "valid": false} {"value": 6, "name": "3D"}
], ],
"TODO": [ "TODO": [
"jiawei.shao@intel.com: support 1D and 3D texture views" "jiawei.shao@intel.com: support 1D and 3D texture views"

View File

@ -134,7 +134,7 @@ namespace dawn_native {
} }
bool AttachmentState::HasDepthStencilAttachment() const { bool AttachmentState::HasDepthStencilAttachment() const {
return mDepthStencilFormat != dawn::TextureFormat::None; return mDepthStencilFormat != dawn::TextureFormat::Undefined;
} }
dawn::TextureFormat AttachmentState::GetDepthStencilFormat() const { dawn::TextureFormat AttachmentState::GetDepthStencilFormat() const {

View File

@ -51,8 +51,8 @@ namespace dawn_native {
protected: protected:
std::bitset<kMaxColorAttachments> mColorAttachmentsSet; std::bitset<kMaxColorAttachments> mColorAttachmentsSet;
std::array<dawn::TextureFormat, kMaxColorAttachments> mColorFormats; std::array<dawn::TextureFormat, kMaxColorAttachments> mColorFormats;
// Default (texture format None) indicates there is no depth stencil attachment. // Default (texture format Undefined) indicates there is no depth stencil attachment.
dawn::TextureFormat mDepthStencilFormat = dawn::TextureFormat::None; dawn::TextureFormat mDepthStencilFormat = dawn::TextureFormat::Undefined;
uint32_t mSampleCount = 0; uint32_t mSampleCount = 0;
}; };

View File

@ -64,9 +64,13 @@ namespace dawn_native {
// Implementation details of the format table of the DeviceBase // Implementation details of the format table of the DeviceBase
// For the enum for formats are packed but this might change when we have a broader extension // For the enum for formats are packed but this might change when we have a broader extension
// mechanism for webgpu.h // mechanism for webgpu.h. Formats start at 1 because 0 is the undefined format.
size_t ComputeFormatIndex(dawn::TextureFormat format) { size_t ComputeFormatIndex(dawn::TextureFormat format) {
return static_cast<size_t>(static_cast<uint32_t>(format)); // This takes advantage of overflows to make the index of TextureFormat::Undefined outside
// of the range of the FormatTable.
static_assert(static_cast<uint32_t>(dawn::TextureFormat::Undefined) - 1 > kKnownFormatCount,
"");
return static_cast<size_t>(static_cast<uint32_t>(format) - 1);
} }
FormatTable BuildFormatTable(const DeviceBase* device) { FormatTable BuildFormatTable(const DeviceBase* device) {

View File

@ -60,7 +60,7 @@ namespace dawn_native {
} }
if (descriptor->colorFormatsCount == 0 && if (descriptor->colorFormatsCount == 0 &&
descriptor->depthStencilFormat == dawn::TextureFormat::None) { descriptor->depthStencilFormat == dawn::TextureFormat::Undefined) {
return DAWN_VALIDATION_ERROR("Should have at least one attachment format"); return DAWN_VALIDATION_ERROR("Should have at least one attachment format");
} }
@ -68,7 +68,7 @@ namespace dawn_native {
DAWN_TRY(ValidateColorAttachmentFormat(device, descriptor->colorFormats[i])); DAWN_TRY(ValidateColorAttachmentFormat(device, descriptor->colorFormats[i]));
} }
if (descriptor->depthStencilFormat != dawn::TextureFormat::None) { if (descriptor->depthStencilFormat != dawn::TextureFormat::Undefined) {
DAWN_TRY(ValidateDepthStencilAttachmentFormat(device, descriptor->depthStencilFormat)); DAWN_TRY(ValidateDepthStencilAttachmentFormat(device, descriptor->depthStencilFormat));
} }

View File

@ -282,10 +282,10 @@ namespace dawn_native {
desc = *descriptor; desc = *descriptor;
} }
if (desc.format == dawn::TextureFormat::None) { if (desc.format == dawn::TextureFormat::Undefined) {
desc.format = texture->GetFormat().format; desc.format = texture->GetFormat().format;
} }
if (desc.dimension == dawn::TextureViewDimension::None) { if (desc.dimension == dawn::TextureViewDimension::Undefined) {
desc.dimension = GetDefaultViewDimension(texture); desc.dimension = GetDefaultViewDimension(texture);
} }
if (desc.arrayLayerCount == 0) { if (desc.arrayLayerCount == 0) {

View File

@ -585,16 +585,18 @@ TEST_F(RenderBundleValidationTest, RequiresAtLeastOneTextureFormat) {
} }
} }
TEST_F(RenderBundleValidationTest, ColorFormatNone) { // Test that render bundle color formats cannot be set to undefined.
TEST_F(RenderBundleValidationTest, ColorFormatUndefined) {
utils::ComboRenderBundleEncoderDescriptor desc = {}; utils::ComboRenderBundleEncoderDescriptor desc = {};
desc.colorFormatsCount = 1; desc.colorFormatsCount = 1;
desc.cColorFormats[0] = dawn::TextureFormat::None; desc.cColorFormats[0] = dawn::TextureFormat::Undefined;
ASSERT_DEVICE_ERROR(device.CreateRenderBundleEncoder(&desc)); ASSERT_DEVICE_ERROR(device.CreateRenderBundleEncoder(&desc));
} }
TEST_F(RenderBundleValidationTest, DepthStencilFormatNone) { // Test that the render bundle depth stencil format cannot be set to undefined.
TEST_F(RenderBundleValidationTest, DepthStencilFormatUndefined) {
utils::ComboRenderBundleEncoderDescriptor desc = {}; utils::ComboRenderBundleEncoderDescriptor desc = {};
desc.depthStencilFormat = dawn::TextureFormat::None; desc.depthStencilFormat = dawn::TextureFormat::Undefined;
ASSERT_DEVICE_ERROR(device.CreateRenderBundleEncoder(&desc)); ASSERT_DEVICE_ERROR(device.CreateRenderBundleEncoder(&desc));
} }

View File

@ -257,10 +257,10 @@ TEST_F(TextureValidationTest, NonRenderableAndOutputAttachment) {
} }
} }
// Test it is an error to create a texture with format "None". // Test it is an error to create a texture with format "Undefined".
TEST_F(TextureValidationTest, TextureFormatNone) { TEST_F(TextureValidationTest, TextureFormatUndefined) {
dawn::TextureDescriptor descriptor = CreateDefaultTextureDescriptor(); dawn::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = dawn::TextureFormat::None; descriptor.format = dawn::TextureFormat::Undefined;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor)); ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
} }

View File

@ -187,7 +187,7 @@ TEST_F(TextureViewValidationTest, TextureViewDescriptorDefaultsArray) {
} }
{ {
dawn::TextureViewDescriptor descriptor; dawn::TextureViewDescriptor descriptor;
descriptor.format = dawn::TextureFormat::None; descriptor.format = dawn::TextureFormat::Undefined;
texture.CreateView(&descriptor); texture.CreateView(&descriptor);
descriptor.format = dawn::TextureFormat::RGBA8Unorm; descriptor.format = dawn::TextureFormat::RGBA8Unorm;
texture.CreateView(&descriptor); texture.CreateView(&descriptor);
@ -196,7 +196,7 @@ TEST_F(TextureViewValidationTest, TextureViewDescriptorDefaultsArray) {
} }
{ {
dawn::TextureViewDescriptor descriptor; dawn::TextureViewDescriptor descriptor;
descriptor.dimension = dawn::TextureViewDimension::None; descriptor.dimension = dawn::TextureViewDimension::Undefined;
texture.CreateView(&descriptor); texture.CreateView(&descriptor);
descriptor.dimension = dawn::TextureViewDimension::e2DArray; descriptor.dimension = dawn::TextureViewDimension::e2DArray;
texture.CreateView(&descriptor); texture.CreateView(&descriptor);
@ -225,7 +225,7 @@ TEST_F(TextureViewValidationTest, TextureViewDescriptorDefaultsNonArray) {
} }
{ {
dawn::TextureViewDescriptor descriptor; dawn::TextureViewDescriptor descriptor;
descriptor.format = dawn::TextureFormat::None; descriptor.format = dawn::TextureFormat::Undefined;
texture.CreateView(&descriptor); texture.CreateView(&descriptor);
descriptor.format = dawn::TextureFormat::RGBA8Unorm; descriptor.format = dawn::TextureFormat::RGBA8Unorm;
texture.CreateView(&descriptor); texture.CreateView(&descriptor);
@ -234,7 +234,7 @@ TEST_F(TextureViewValidationTest, TextureViewDescriptorDefaultsNonArray) {
} }
{ {
dawn::TextureViewDescriptor descriptor; dawn::TextureViewDescriptor descriptor;
descriptor.dimension = dawn::TextureViewDimension::None; descriptor.dimension = dawn::TextureViewDimension::Undefined;
texture.CreateView(&descriptor); texture.CreateView(&descriptor);
descriptor.dimension = dawn::TextureViewDimension::e2D; descriptor.dimension = dawn::TextureViewDimension::e2D;
texture.CreateView(&descriptor); texture.CreateView(&descriptor);