2019-07-18 09:25:04 +00:00
|
|
|
// Copyright 2019 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 "dawn_native/Format.h"
|
2020-07-30 15:25:37 +00:00
|
|
|
|
2019-08-02 00:06:38 +00:00
|
|
|
#include "dawn_native/Device.h"
|
2021-02-16 19:55:09 +00:00
|
|
|
#include "dawn_native/EnumMaskIterator.h"
|
2019-08-02 00:06:38 +00:00
|
|
|
#include "dawn_native/Extensions.h"
|
2020-07-30 15:25:37 +00:00
|
|
|
#include "dawn_native/Texture.h"
|
2019-07-18 09:25:04 +00:00
|
|
|
|
|
|
|
#include <bitset>
|
|
|
|
|
|
|
|
namespace dawn_native {
|
|
|
|
|
|
|
|
// Format
|
|
|
|
|
2020-12-21 20:14:26 +00:00
|
|
|
// TODO(dawn:527): Remove when unused.
|
2021-07-02 02:29:40 +00:00
|
|
|
SampleTypeBit ToSampleTypeBit(wgpu::TextureComponentType type) {
|
2020-10-16 14:07:06 +00:00
|
|
|
switch (type) {
|
2019-11-22 17:02:22 +00:00
|
|
|
case wgpu::TextureComponentType::Float:
|
2021-07-02 02:29:40 +00:00
|
|
|
return SampleTypeBit::Float;
|
2019-11-22 17:02:22 +00:00
|
|
|
case wgpu::TextureComponentType::Sint:
|
2021-07-02 02:29:40 +00:00
|
|
|
return SampleTypeBit::Sint;
|
2019-11-22 17:02:22 +00:00
|
|
|
case wgpu::TextureComponentType::Uint:
|
2021-07-02 02:29:40 +00:00
|
|
|
return SampleTypeBit::Uint;
|
2020-10-16 14:13:16 +00:00
|
|
|
case wgpu::TextureComponentType::DepthComparison:
|
2021-07-02 02:29:40 +00:00
|
|
|
return SampleTypeBit::Depth;
|
2019-11-22 17:02:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-02 02:29:40 +00:00
|
|
|
SampleTypeBit SampleTypeToSampleTypeBit(wgpu::TextureSampleType sampleType) {
|
2020-12-21 20:14:26 +00:00
|
|
|
switch (sampleType) {
|
|
|
|
case wgpu::TextureSampleType::Float:
|
|
|
|
case wgpu::TextureSampleType::UnfilterableFloat:
|
|
|
|
case wgpu::TextureSampleType::Sint:
|
|
|
|
case wgpu::TextureSampleType::Uint:
|
|
|
|
case wgpu::TextureSampleType::Depth:
|
|
|
|
case wgpu::TextureSampleType::Undefined:
|
2021-07-02 02:29:40 +00:00
|
|
|
// When the compiler complains that you need to add a case statement here, please
|
|
|
|
// also add a corresponding static assert below!
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
static_assert(static_cast<uint32_t>(wgpu::TextureSampleType::Undefined) == 0, "");
|
|
|
|
if (sampleType == wgpu::TextureSampleType::Undefined) {
|
|
|
|
return SampleTypeBit::None;
|
2020-12-21 20:14:26 +00:00
|
|
|
}
|
|
|
|
|
2021-07-02 02:29:40 +00:00
|
|
|
// Check that SampleTypeBit bits are in the same position / order as the respective
|
|
|
|
// wgpu::TextureSampleType value.
|
|
|
|
static_assert(SampleTypeBit::Float ==
|
|
|
|
static_cast<SampleTypeBit>(
|
|
|
|
1 << (static_cast<uint32_t>(wgpu::TextureSampleType::Float) - 1)),
|
|
|
|
"");
|
|
|
|
static_assert(
|
|
|
|
SampleTypeBit::UnfilterableFloat ==
|
|
|
|
static_cast<SampleTypeBit>(
|
|
|
|
1 << (static_cast<uint32_t>(wgpu::TextureSampleType::UnfilterableFloat) - 1)),
|
|
|
|
"");
|
|
|
|
static_assert(SampleTypeBit::Uint ==
|
|
|
|
static_cast<SampleTypeBit>(
|
|
|
|
1 << (static_cast<uint32_t>(wgpu::TextureSampleType::Uint) - 1)),
|
|
|
|
"");
|
|
|
|
static_assert(SampleTypeBit::Sint ==
|
|
|
|
static_cast<SampleTypeBit>(
|
|
|
|
1 << (static_cast<uint32_t>(wgpu::TextureSampleType::Sint) - 1)),
|
|
|
|
"");
|
|
|
|
static_assert(SampleTypeBit::Depth ==
|
|
|
|
static_cast<SampleTypeBit>(
|
|
|
|
1 << (static_cast<uint32_t>(wgpu::TextureSampleType::Depth) - 1)),
|
|
|
|
"");
|
|
|
|
return static_cast<SampleTypeBit>(1 << (static_cast<uint32_t>(sampleType) - 1));
|
2020-12-21 20:14:26 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 09:25:04 +00:00
|
|
|
bool Format::IsColor() const {
|
2020-07-30 15:25:37 +00:00
|
|
|
return aspects == Aspect::Color;
|
2019-07-18 09:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Format::HasDepth() const {
|
2020-07-30 15:25:37 +00:00
|
|
|
return (aspects & Aspect::Depth) != 0;
|
2019-07-18 09:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Format::HasStencil() const {
|
2020-07-30 15:25:37 +00:00
|
|
|
return (aspects & Aspect::Stencil) != 0;
|
2019-07-18 09:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Format::HasDepthOrStencil() const {
|
2020-07-30 15:25:37 +00:00
|
|
|
return (aspects & (Aspect::Depth | Aspect::Stencil)) != 0;
|
2019-07-18 09:25:04 +00:00
|
|
|
}
|
|
|
|
|
2021-02-05 20:11:24 +00:00
|
|
|
bool Format::IsMultiPlanar() const {
|
|
|
|
return (aspects & (Aspect::Plane0 | Aspect::Plane1)) != 0;
|
|
|
|
}
|
|
|
|
|
2020-10-15 09:05:03 +00:00
|
|
|
const AspectInfo& Format::GetAspectInfo(wgpu::TextureAspect aspect) const {
|
2021-02-16 19:55:09 +00:00
|
|
|
return GetAspectInfo(SelectFormatAspects(*this, aspect));
|
2020-07-30 15:29:57 +00:00
|
|
|
}
|
|
|
|
|
2020-10-15 09:05:03 +00:00
|
|
|
const AspectInfo& Format::GetAspectInfo(Aspect aspect) const {
|
2020-08-06 17:00:29 +00:00
|
|
|
ASSERT(HasOneBit(aspect));
|
|
|
|
ASSERT(aspects & aspect);
|
2021-02-16 19:55:09 +00:00
|
|
|
const size_t aspectIndex = GetAspectIndex(aspect);
|
|
|
|
ASSERT(aspectIndex < GetAspectCount(aspects));
|
|
|
|
return aspectInfo[aspectIndex];
|
2020-08-06 17:00:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 09:25:04 +00:00
|
|
|
size_t Format::GetIndex() const {
|
|
|
|
return ComputeFormatIndex(format);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2019-09-05 09:12:32 +00:00
|
|
|
// mechanism for webgpu.h. Formats start at 1 because 0 is the undefined format.
|
2019-10-23 11:57:41 +00:00
|
|
|
size_t ComputeFormatIndex(wgpu::TextureFormat format) {
|
2019-09-05 09:12:32 +00:00
|
|
|
// This takes advantage of overflows to make the index of TextureFormat::Undefined outside
|
|
|
|
// of the range of the FormatTable.
|
2019-10-23 11:57:41 +00:00
|
|
|
static_assert(static_cast<uint32_t>(wgpu::TextureFormat::Undefined) - 1 > kKnownFormatCount,
|
2019-09-05 09:12:32 +00:00
|
|
|
"");
|
|
|
|
return static_cast<size_t>(static_cast<uint32_t>(format) - 1);
|
2019-07-18 09:25:04 +00:00
|
|
|
}
|
|
|
|
|
2019-08-02 00:06:38 +00:00
|
|
|
FormatTable BuildFormatTable(const DeviceBase* device) {
|
2019-07-18 09:25:04 +00:00
|
|
|
FormatTable table;
|
|
|
|
std::bitset<kKnownFormatCount> formatsSet;
|
|
|
|
|
2021-07-02 02:29:40 +00:00
|
|
|
static constexpr SampleTypeBit kAnyFloat =
|
|
|
|
SampleTypeBit::Float | SampleTypeBit::UnfilterableFloat;
|
2019-08-21 12:16:33 +00:00
|
|
|
|
2019-07-18 09:25:04 +00:00
|
|
|
auto AddFormat = [&table, &formatsSet](Format format) {
|
|
|
|
size_t index = ComputeFormatIndex(format.format);
|
|
|
|
ASSERT(index < table.size());
|
|
|
|
|
|
|
|
// This checks that each format is set at most once, the first part of checking that all
|
|
|
|
// formats are set exactly once.
|
|
|
|
ASSERT(!formatsSet[index]);
|
|
|
|
|
2020-11-06 13:41:50 +00:00
|
|
|
// Vulkan describes bytesPerRow in units of texels. If there's any format for which this
|
|
|
|
// ASSERT isn't true, then additional validation on bytesPerRow must be added.
|
2021-02-16 19:55:09 +00:00
|
|
|
const bool hasMultipleAspects = !HasOneBit(format.aspects);
|
|
|
|
ASSERT(hasMultipleAspects ||
|
|
|
|
(kTextureBytesPerRowAlignment % format.aspectInfo[0].block.byteSize) == 0);
|
2020-11-06 13:41:50 +00:00
|
|
|
|
2019-07-18 09:25:04 +00:00
|
|
|
table[index] = format;
|
|
|
|
formatsSet.set(index);
|
|
|
|
};
|
|
|
|
|
2019-10-23 11:57:41 +00:00
|
|
|
auto AddColorFormat = [&AddFormat](wgpu::TextureFormat format, bool renderable,
|
2020-01-15 00:09:42 +00:00
|
|
|
bool supportsStorageUsage, uint32_t byteSize,
|
2021-07-02 02:29:40 +00:00
|
|
|
SampleTypeBit sampleTypes) {
|
2019-07-18 09:25:04 +00:00
|
|
|
Format internalFormat;
|
|
|
|
internalFormat.format = format;
|
|
|
|
internalFormat.isRenderable = renderable;
|
|
|
|
internalFormat.isCompressed = false;
|
|
|
|
internalFormat.isSupported = true;
|
2020-01-15 00:09:42 +00:00
|
|
|
internalFormat.supportsStorageUsage = supportsStorageUsage;
|
2020-07-30 15:25:37 +00:00
|
|
|
internalFormat.aspects = Aspect::Color;
|
2021-02-16 19:55:09 +00:00
|
|
|
AspectInfo* firstAspect = internalFormat.aspectInfo.data();
|
|
|
|
firstAspect->block.byteSize = byteSize;
|
|
|
|
firstAspect->block.width = 1;
|
|
|
|
firstAspect->block.height = 1;
|
2021-07-02 02:29:40 +00:00
|
|
|
if (HasOneBit(sampleTypes)) {
|
|
|
|
switch (sampleTypes) {
|
|
|
|
case SampleTypeBit::Float:
|
|
|
|
case SampleTypeBit::UnfilterableFloat:
|
|
|
|
firstAspect->baseType = wgpu::TextureComponentType::Float;
|
|
|
|
break;
|
|
|
|
case SampleTypeBit::Sint:
|
|
|
|
firstAspect->baseType = wgpu::TextureComponentType::Sint;
|
|
|
|
break;
|
|
|
|
case SampleTypeBit::Uint:
|
|
|
|
firstAspect->baseType = wgpu::TextureComponentType::Uint;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ASSERT((sampleTypes & SampleTypeBit::Float) != 0);
|
|
|
|
firstAspect->baseType = wgpu::TextureComponentType::Float;
|
|
|
|
}
|
|
|
|
firstAspect->supportedSampleTypes = sampleTypes;
|
2021-02-16 19:55:09 +00:00
|
|
|
firstAspect->format = format;
|
2019-07-18 09:25:04 +00:00
|
|
|
AddFormat(internalFormat);
|
|
|
|
};
|
|
|
|
|
2021-02-16 19:55:09 +00:00
|
|
|
auto AddDepthFormat = [&AddFormat](wgpu::TextureFormat format, uint32_t byteSize) {
|
2019-07-18 09:25:04 +00:00
|
|
|
Format internalFormat;
|
|
|
|
internalFormat.format = format;
|
|
|
|
internalFormat.isRenderable = true;
|
|
|
|
internalFormat.isCompressed = false;
|
|
|
|
internalFormat.isSupported = true;
|
2020-01-15 00:09:42 +00:00
|
|
|
internalFormat.supportsStorageUsage = false;
|
2021-02-16 19:55:09 +00:00
|
|
|
internalFormat.aspects = Aspect::Depth;
|
|
|
|
AspectInfo* firstAspect = internalFormat.aspectInfo.data();
|
|
|
|
firstAspect->block.byteSize = byteSize;
|
|
|
|
firstAspect->block.width = 1;
|
|
|
|
firstAspect->block.height = 1;
|
|
|
|
firstAspect->baseType = wgpu::TextureComponentType::Float;
|
2021-07-02 02:29:40 +00:00
|
|
|
firstAspect->supportedSampleTypes = kAnyFloat | SampleTypeBit::Depth;
|
2021-02-16 19:55:09 +00:00
|
|
|
firstAspect->format = format;
|
|
|
|
AddFormat(internalFormat);
|
|
|
|
};
|
|
|
|
|
|
|
|
auto AddStencilFormat = [&AddFormat](wgpu::TextureFormat format) {
|
|
|
|
Format internalFormat;
|
|
|
|
internalFormat.format = format;
|
|
|
|
internalFormat.isRenderable = true;
|
|
|
|
internalFormat.isCompressed = false;
|
|
|
|
internalFormat.isSupported = false;
|
|
|
|
internalFormat.supportsStorageUsage = false;
|
|
|
|
internalFormat.aspects = Aspect::Stencil;
|
|
|
|
AspectInfo* firstAspect = internalFormat.aspectInfo.data();
|
|
|
|
firstAspect->block.byteSize = 1;
|
|
|
|
firstAspect->block.width = 1;
|
|
|
|
firstAspect->block.height = 1;
|
|
|
|
firstAspect->baseType = wgpu::TextureComponentType::Uint;
|
2021-07-02 02:29:40 +00:00
|
|
|
firstAspect->supportedSampleTypes = SampleTypeBit::Uint;
|
2021-02-16 19:55:09 +00:00
|
|
|
firstAspect->format = format;
|
2020-04-22 19:54:00 +00:00
|
|
|
AddFormat(internalFormat);
|
|
|
|
};
|
|
|
|
|
2019-10-23 11:57:41 +00:00
|
|
|
auto AddCompressedFormat = [&AddFormat](wgpu::TextureFormat format, uint32_t byteSize,
|
2019-08-02 00:06:38 +00:00
|
|
|
uint32_t width, uint32_t height, bool isSupported) {
|
2019-07-18 09:25:04 +00:00
|
|
|
Format internalFormat;
|
|
|
|
internalFormat.format = format;
|
|
|
|
internalFormat.isRenderable = false;
|
|
|
|
internalFormat.isCompressed = true;
|
2019-08-02 00:06:38 +00:00
|
|
|
internalFormat.isSupported = isSupported;
|
2020-01-15 00:09:42 +00:00
|
|
|
internalFormat.supportsStorageUsage = false;
|
2020-07-30 15:25:37 +00:00
|
|
|
internalFormat.aspects = Aspect::Color;
|
2021-02-16 19:55:09 +00:00
|
|
|
AspectInfo* firstAspect = internalFormat.aspectInfo.data();
|
|
|
|
firstAspect->block.byteSize = byteSize;
|
|
|
|
firstAspect->block.width = width;
|
|
|
|
firstAspect->block.height = height;
|
|
|
|
firstAspect->baseType = wgpu::TextureComponentType::Float;
|
2021-07-02 02:29:40 +00:00
|
|
|
firstAspect->supportedSampleTypes = kAnyFloat;
|
2021-02-16 19:55:09 +00:00
|
|
|
firstAspect->format = format;
|
2019-07-18 09:25:04 +00:00
|
|
|
AddFormat(internalFormat);
|
|
|
|
};
|
|
|
|
|
2021-02-16 19:55:09 +00:00
|
|
|
auto AddMultiAspectFormat = [&AddFormat, &table](wgpu::TextureFormat format, Aspect aspects,
|
|
|
|
wgpu::TextureFormat firstFormat,
|
|
|
|
wgpu::TextureFormat secondFormat,
|
|
|
|
bool isRenderable, bool isSupported) {
|
2021-02-05 20:11:24 +00:00
|
|
|
Format internalFormat;
|
|
|
|
internalFormat.format = format;
|
2021-02-16 19:55:09 +00:00
|
|
|
internalFormat.isRenderable = isRenderable;
|
2021-02-05 20:11:24 +00:00
|
|
|
internalFormat.isCompressed = false;
|
|
|
|
internalFormat.isSupported = isSupported;
|
|
|
|
internalFormat.supportsStorageUsage = false;
|
|
|
|
internalFormat.aspects = aspects;
|
2021-02-16 19:55:09 +00:00
|
|
|
|
|
|
|
const size_t firstFormatIndex = ComputeFormatIndex(firstFormat);
|
|
|
|
const size_t secondFormatIndex = ComputeFormatIndex(secondFormat);
|
|
|
|
|
|
|
|
internalFormat.aspectInfo[0] = table[firstFormatIndex].aspectInfo[0];
|
|
|
|
internalFormat.aspectInfo[1] = table[secondFormatIndex].aspectInfo[0];
|
|
|
|
|
2021-02-05 20:11:24 +00:00
|
|
|
AddFormat(internalFormat);
|
|
|
|
};
|
|
|
|
|
2019-07-18 09:25:04 +00:00
|
|
|
// clang-format off
|
|
|
|
// 1 byte color formats
|
2021-07-02 02:29:40 +00:00
|
|
|
AddColorFormat(wgpu::TextureFormat::R8Unorm, true, false, 1, kAnyFloat);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::R8Snorm, false, false, 1, kAnyFloat);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::R8Uint, true, false, 1, SampleTypeBit::Uint);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::R8Sint, true, false, 1, SampleTypeBit::Sint);
|
2019-07-18 09:25:04 +00:00
|
|
|
|
|
|
|
// 2 bytes color formats
|
2021-07-02 02:29:40 +00:00
|
|
|
AddColorFormat(wgpu::TextureFormat::R16Uint, true, false, 2, SampleTypeBit::Uint);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::R16Sint, true, false, 2, SampleTypeBit::Sint);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::R16Float, true, false, 2, kAnyFloat);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RG8Unorm, true, false, 2, kAnyFloat);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RG8Snorm, false, false, 2, kAnyFloat);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RG8Uint, true, false, 2, SampleTypeBit::Uint);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RG8Sint, true, false, 2, SampleTypeBit::Sint);
|
2019-07-18 09:25:04 +00:00
|
|
|
|
|
|
|
// 4 bytes color formats
|
2021-07-02 02:29:40 +00:00
|
|
|
AddColorFormat(wgpu::TextureFormat::R32Uint, true, true, 4, SampleTypeBit::Uint);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::R32Sint, true, true, 4, SampleTypeBit::Sint);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::R32Float, true, true, 4, SampleTypeBit::UnfilterableFloat);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RG16Uint, true, false, 4, SampleTypeBit::Uint);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RG16Sint, true, false, 4, SampleTypeBit::Sint);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RG16Float, true, false, 4, kAnyFloat);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RGBA8Unorm, true, true, 4, kAnyFloat);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RGBA8UnormSrgb, true, false, 4, kAnyFloat);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RGBA8Snorm, false, true, 4, kAnyFloat);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RGBA8Uint, true, true, 4, SampleTypeBit::Uint);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RGBA8Sint, true, true, 4, SampleTypeBit::Sint);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::BGRA8Unorm, true, false, 4, kAnyFloat);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::BGRA8UnormSrgb, true, false, 4, kAnyFloat);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RGB10A2Unorm, true, false, 4, kAnyFloat);
|
|
|
|
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RG11B10Ufloat, false, false, 4, kAnyFloat);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RGB9E5Ufloat, false, false, 4, kAnyFloat);
|
2019-07-18 09:25:04 +00:00
|
|
|
|
|
|
|
// 8 bytes color formats
|
2021-07-02 02:29:40 +00:00
|
|
|
AddColorFormat(wgpu::TextureFormat::RG32Uint, true, true, 8, SampleTypeBit::Uint);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RG32Sint, true, true, 8, SampleTypeBit::Sint);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RG32Float, true, true, 8, SampleTypeBit::UnfilterableFloat);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RGBA16Uint, true, true, 8, SampleTypeBit::Uint);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RGBA16Sint, true, true, 8, SampleTypeBit::Sint);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RGBA16Float, true, true, 8, kAnyFloat);
|
2019-07-18 09:25:04 +00:00
|
|
|
|
|
|
|
// 16 bytes color formats
|
2021-07-02 02:29:40 +00:00
|
|
|
AddColorFormat(wgpu::TextureFormat::RGBA32Uint, true, true, 16, SampleTypeBit::Uint);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RGBA32Sint, true, true, 16, SampleTypeBit::Sint);
|
|
|
|
AddColorFormat(wgpu::TextureFormat::RGBA32Float, true, true, 16, SampleTypeBit::UnfilterableFloat);
|
2019-07-18 09:25:04 +00:00
|
|
|
|
2020-10-16 14:07:06 +00:00
|
|
|
// Depth-stencil formats
|
2021-02-16 19:55:09 +00:00
|
|
|
AddDepthFormat(wgpu::TextureFormat::Depth32Float, 4);
|
2021-06-04 22:23:56 +00:00
|
|
|
// TODO(crbug.com/dawn/843): This is 4 because we read this to perform zero initialization,
|
|
|
|
// and textures are always use depth32float. We should improve this to be more robust. Perhaps,
|
|
|
|
// using 0 here to mean "unsized" and adding a backend-specific query for the block size.
|
2021-02-16 19:55:09 +00:00
|
|
|
AddDepthFormat(wgpu::TextureFormat::Depth24Plus, 4);
|
|
|
|
// TODO(dawn:666): Implement the stencil8 format
|
|
|
|
AddStencilFormat(wgpu::TextureFormat::Stencil8);
|
|
|
|
AddMultiAspectFormat(wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
Aspect::Depth | Aspect::Stencil, wgpu::TextureFormat::Depth24Plus, wgpu::TextureFormat::Stencil8, true, true);
|
2021-06-04 22:23:56 +00:00
|
|
|
// TODO(dawn:690): Implement Depth16Unorm, Depth24UnormStencil8, Depth32FloatStencil8.
|
2019-07-18 09:25:04 +00:00
|
|
|
|
|
|
|
// BC compressed formats
|
2019-08-02 00:06:38 +00:00
|
|
|
bool isBCFormatSupported = device->IsExtensionEnabled(Extension::TextureCompressionBC);
|
2019-10-23 11:57:41 +00:00
|
|
|
AddCompressedFormat(wgpu::TextureFormat::BC1RGBAUnorm, 8, 4, 4, isBCFormatSupported);
|
|
|
|
AddCompressedFormat(wgpu::TextureFormat::BC1RGBAUnormSrgb, 8, 4, 4, isBCFormatSupported);
|
|
|
|
AddCompressedFormat(wgpu::TextureFormat::BC4RSnorm, 8, 4, 4, isBCFormatSupported);
|
|
|
|
AddCompressedFormat(wgpu::TextureFormat::BC4RUnorm, 8, 4, 4, isBCFormatSupported);
|
|
|
|
AddCompressedFormat(wgpu::TextureFormat::BC2RGBAUnorm, 16, 4, 4, isBCFormatSupported);
|
|
|
|
AddCompressedFormat(wgpu::TextureFormat::BC2RGBAUnormSrgb, 16, 4, 4, isBCFormatSupported);
|
|
|
|
AddCompressedFormat(wgpu::TextureFormat::BC3RGBAUnorm, 16, 4, 4, isBCFormatSupported);
|
|
|
|
AddCompressedFormat(wgpu::TextureFormat::BC3RGBAUnormSrgb, 16, 4, 4, isBCFormatSupported);
|
|
|
|
AddCompressedFormat(wgpu::TextureFormat::BC5RGSnorm, 16, 4, 4, isBCFormatSupported);
|
|
|
|
AddCompressedFormat(wgpu::TextureFormat::BC5RGUnorm, 16, 4, 4, isBCFormatSupported);
|
2020-09-10 08:48:57 +00:00
|
|
|
AddCompressedFormat(wgpu::TextureFormat::BC6HRGBFloat, 16, 4, 4, isBCFormatSupported);
|
2019-10-23 11:57:41 +00:00
|
|
|
AddCompressedFormat(wgpu::TextureFormat::BC6HRGBUfloat, 16, 4, 4, isBCFormatSupported);
|
|
|
|
AddCompressedFormat(wgpu::TextureFormat::BC7RGBAUnorm, 16, 4, 4, isBCFormatSupported);
|
|
|
|
AddCompressedFormat(wgpu::TextureFormat::BC7RGBAUnormSrgb, 16, 4, 4, isBCFormatSupported);
|
2019-07-18 09:25:04 +00:00
|
|
|
|
2021-02-05 20:11:24 +00:00
|
|
|
// multi-planar formats
|
|
|
|
const bool isMultiPlanarFormatSupported = device->IsExtensionEnabled(Extension::MultiPlanarFormats);
|
2021-02-16 19:55:09 +00:00
|
|
|
AddMultiAspectFormat(wgpu::TextureFormat::R8BG8Biplanar420Unorm, Aspect::Plane0 | Aspect::Plane1,
|
|
|
|
wgpu::TextureFormat::R8Unorm, wgpu::TextureFormat::RG8Unorm, false, isMultiPlanarFormatSupported);
|
2021-02-05 20:11:24 +00:00
|
|
|
|
2019-07-18 09:25:04 +00:00
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
// This checks that each format is set at least once, the second part of checking that all
|
|
|
|
// formats are checked exactly once.
|
|
|
|
ASSERT(formatsSet.all());
|
|
|
|
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dawn_native
|