Refactor compressed formats
This CL has no functional changes.
Bug: 342840940
Change-Id: Ice647d453b8618ce59ad8046712f5330a0a43ca4
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/238714
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Fr <beaufort.francois@gmail.com>
diff --git a/src/dawn/native/Format.cpp b/src/dawn/native/Format.cpp
index fee3c66..a130d6d 100644
--- a/src/dawn/native/Format.cpp
+++ b/src/dawn/native/Format.cpp
@@ -386,104 +386,67 @@
AddFormat(internalFormat);
};
- auto AddCompressedFormat =
- [&AddFormat](wgpu::TextureFormat format, ByteSize byteSize, Width width, Height height,
- UnsupportedReason unsupportedReason, ComponentCount componentCount,
- wgpu::TextureFormat baseFormat = wgpu::TextureFormat::Undefined) {
- Format internalFormat;
- internalFormat.format = format;
- internalFormat.isRenderable = false;
- internalFormat.isBlendable = false;
- internalFormat.isCompressed = true;
- internalFormat.unsupportedReason = unsupportedReason;
- internalFormat.supportsStorageUsage = false;
- internalFormat.supportsMultisample = false;
- internalFormat.supportsResolveTarget = false;
- internalFormat.aspects = Aspect::Color;
- internalFormat.componentCount = static_cast<uint32_t>(componentCount);
+ auto BaseCompressedFormat = [](wgpu::TextureFormat format, ByteSize byteSize, Width width,
+ Height height, UnsupportedReason unsupportedReason,
+ ComponentCount componentCount, wgpu::TextureFormat baseFormat) {
+ Format internalFormat;
+ internalFormat.format = format;
+ internalFormat.isRenderable = false;
+ internalFormat.isBlendable = false;
+ internalFormat.isCompressed = true;
+ internalFormat.unsupportedReason = unsupportedReason;
+ internalFormat.supportsStorageUsage = false;
+ internalFormat.supportsMultisample = false;
+ internalFormat.supportsResolveTarget = false;
+ internalFormat.aspects = Aspect::Color;
+ internalFormat.componentCount = static_cast<uint32_t>(componentCount);
- // Default baseFormat of each compressed formats should be themselves.
- if (baseFormat == wgpu::TextureFormat::Undefined) {
- internalFormat.baseFormat = format;
- } else {
- internalFormat.baseFormat = baseFormat;
- }
+ // Default baseFormat of each compressed formats should be themselves.
+ if (baseFormat == wgpu::TextureFormat::Undefined) {
+ internalFormat.baseFormat = format;
+ } else {
+ internalFormat.baseFormat = baseFormat;
+ }
- AspectInfo* firstAspect = internalFormat.aspectInfo.data();
- firstAspect->block.byteSize = static_cast<uint32_t>(byteSize);
- firstAspect->block.width = static_cast<uint32_t>(width);
- firstAspect->block.height = static_cast<uint32_t>(height);
- firstAspect->baseType = TextureComponentType::Float;
- firstAspect->supportedSampleTypes = kAnyFloat;
- firstAspect->format = format;
+ AspectInfo* firstAspect = internalFormat.aspectInfo.data();
+ firstAspect->block.byteSize = static_cast<uint32_t>(byteSize);
+ firstAspect->block.width = static_cast<uint32_t>(width);
+ firstAspect->block.height = static_cast<uint32_t>(height);
+ firstAspect->baseType = TextureComponentType::Float;
+ firstAspect->supportedSampleTypes = kAnyFloat;
+ firstAspect->format = format;
+ return internalFormat;
+ };
+
+ auto AddETCCompressedFormat =
+ [&BaseCompressedFormat, &AddFormat](
+ wgpu::TextureFormat format, ByteSize byteSize, Width width, Height height,
+ UnsupportedReason unsupportedReason, ComponentCount componentCount,
+ wgpu::TextureFormat baseFormat = wgpu::TextureFormat::Undefined) {
+ Format internalFormat = BaseCompressedFormat(
+ format, byteSize, width, height, unsupportedReason, componentCount, baseFormat);
AddFormat(internalFormat);
};
auto AddBCCompressedFormat =
- [&AddFormat](wgpu::TextureFormat format, ByteSize byteSize, Width width, Height height,
- UnsupportedReason unsupportedReason, ComponentCount componentCount,
- wgpu::TextureFormat baseFormat = wgpu::TextureFormat::Undefined) {
- Format internalFormat;
- internalFormat.format = format;
- internalFormat.isRenderable = false;
- internalFormat.isBlendable = false;
+ [&BaseCompressedFormat, &AddFormat](
+ wgpu::TextureFormat format, ByteSize byteSize, Width width, Height height,
+ UnsupportedReason unsupportedReason, ComponentCount componentCount,
+ wgpu::TextureFormat baseFormat = wgpu::TextureFormat::Undefined) {
+ Format internalFormat = BaseCompressedFormat(
+ format, byteSize, width, height, unsupportedReason, componentCount, baseFormat);
internalFormat.isBC = true;
- internalFormat.isCompressed = true;
- internalFormat.unsupportedReason = unsupportedReason;
- internalFormat.supportsStorageUsage = false;
- internalFormat.supportsMultisample = false;
- internalFormat.supportsResolveTarget = false;
- internalFormat.aspects = Aspect::Color;
- internalFormat.componentCount = static_cast<uint32_t>(componentCount);
-
- // Default baseFormat of each compressed formats should be themselves.
- if (baseFormat == wgpu::TextureFormat::Undefined) {
- internalFormat.baseFormat = format;
- } else {
- internalFormat.baseFormat = baseFormat;
- }
-
- AspectInfo* firstAspect = internalFormat.aspectInfo.data();
- firstAspect->block.byteSize = static_cast<uint32_t>(byteSize);
- firstAspect->block.width = static_cast<uint32_t>(width);
- firstAspect->block.height = static_cast<uint32_t>(height);
- firstAspect->baseType = TextureComponentType::Float;
- firstAspect->supportedSampleTypes = kAnyFloat;
- firstAspect->format = format;
AddFormat(internalFormat);
};
auto AddASTCCompressedFormat =
- [&AddFormat](wgpu::TextureFormat format, ByteSize byteSize, Width width, Height height,
- UnsupportedReason unsupportedReason, ComponentCount componentCount,
- wgpu::TextureFormat baseFormat = wgpu::TextureFormat::Undefined) {
- Format internalFormat;
- internalFormat.format = format;
- internalFormat.isRenderable = false;
- internalFormat.isBlendable = false;
+ [&BaseCompressedFormat, &AddFormat](
+ wgpu::TextureFormat format, ByteSize byteSize, Width width, Height height,
+ UnsupportedReason unsupportedReason, ComponentCount componentCount,
+ wgpu::TextureFormat baseFormat = wgpu::TextureFormat::Undefined) {
+ Format internalFormat = BaseCompressedFormat(
+ format, byteSize, width, height, unsupportedReason, componentCount, baseFormat);
internalFormat.isASTC = true;
- internalFormat.isCompressed = true;
- internalFormat.unsupportedReason = unsupportedReason;
- internalFormat.supportsStorageUsage = false;
- internalFormat.supportsMultisample = false;
- internalFormat.supportsResolveTarget = false;
- internalFormat.aspects = Aspect::Color;
- internalFormat.componentCount = static_cast<uint32_t>(componentCount);
-
- // Default baseFormat of each compressed formats should be themselves.
- if (baseFormat == wgpu::TextureFormat::Undefined) {
- internalFormat.baseFormat = format;
- } else {
- internalFormat.baseFormat = baseFormat;
- }
-
- AspectInfo* firstAspect = internalFormat.aspectInfo.data();
- firstAspect->block.byteSize = static_cast<uint32_t>(byteSize);
- firstAspect->block.width = static_cast<uint32_t>(width);
- firstAspect->block.height = static_cast<uint32_t>(height);
- firstAspect->baseType = TextureComponentType::Float;
- firstAspect->supportedSampleTypes = kAnyFloat;
- firstAspect->format = format;
AddFormat(internalFormat);
};
@@ -643,16 +606,16 @@
// ETC2/EAC compressed formats
UnsupportedReason etc2FormatUnsupportedReason = device->HasFeature(Feature::TextureCompressionETC2) ? Format::supported : RequiresFeature{wgpu::FeatureName::TextureCompressionETC2};
- AddCompressedFormat(wgpu::TextureFormat::ETC2RGB8Unorm, ByteSize(8), Width(4), Height(4), etc2FormatUnsupportedReason, ComponentCount(3));
- AddCompressedFormat(wgpu::TextureFormat::ETC2RGB8UnormSrgb, ByteSize(8), Width(4), Height(4), etc2FormatUnsupportedReason, ComponentCount(3), wgpu::TextureFormat::ETC2RGB8Unorm);
- AddCompressedFormat(wgpu::TextureFormat::ETC2RGB8A1Unorm, ByteSize(8), Width(4), Height(4), etc2FormatUnsupportedReason, ComponentCount(4));
- AddCompressedFormat(wgpu::TextureFormat::ETC2RGB8A1UnormSrgb, ByteSize(8), Width(4), Height(4), etc2FormatUnsupportedReason, ComponentCount(4), wgpu::TextureFormat::ETC2RGB8A1Unorm);
- AddCompressedFormat(wgpu::TextureFormat::ETC2RGBA8Unorm, ByteSize(16), Width(4), Height(4), etc2FormatUnsupportedReason, ComponentCount(4));
- AddCompressedFormat(wgpu::TextureFormat::ETC2RGBA8UnormSrgb, ByteSize(16), Width(4), Height(4), etc2FormatUnsupportedReason, ComponentCount(4), wgpu::TextureFormat::ETC2RGBA8Unorm);
- AddCompressedFormat(wgpu::TextureFormat::EACR11Unorm, ByteSize(8), Width(4), Height(4), etc2FormatUnsupportedReason, ComponentCount(1));
- AddCompressedFormat(wgpu::TextureFormat::EACR11Snorm, ByteSize(8), Width(4), Height(4), etc2FormatUnsupportedReason, ComponentCount(1));
- AddCompressedFormat(wgpu::TextureFormat::EACRG11Unorm, ByteSize(16), Width(4), Height(4), etc2FormatUnsupportedReason, ComponentCount(2));
- AddCompressedFormat(wgpu::TextureFormat::EACRG11Snorm, ByteSize(16), Width(4), Height(4), etc2FormatUnsupportedReason, ComponentCount(2));
+ AddETCCompressedFormat(wgpu::TextureFormat::ETC2RGB8Unorm, ByteSize(8), Width(4), Height(4), etc2FormatUnsupportedReason, ComponentCount(3));
+ AddETCCompressedFormat(wgpu::TextureFormat::ETC2RGB8UnormSrgb, ByteSize(8), Width(4), Height(4), etc2FormatUnsupportedReason, ComponentCount(3), wgpu::TextureFormat::ETC2RGB8Unorm);
+ AddETCCompressedFormat(wgpu::TextureFormat::ETC2RGB8A1Unorm, ByteSize(8), Width(4), Height(4), etc2FormatUnsupportedReason, ComponentCount(4));
+ AddETCCompressedFormat(wgpu::TextureFormat::ETC2RGB8A1UnormSrgb, ByteSize(8), Width(4), Height(4), etc2FormatUnsupportedReason, ComponentCount(4), wgpu::TextureFormat::ETC2RGB8A1Unorm);
+ AddETCCompressedFormat(wgpu::TextureFormat::ETC2RGBA8Unorm, ByteSize(16), Width(4), Height(4), etc2FormatUnsupportedReason, ComponentCount(4));
+ AddETCCompressedFormat(wgpu::TextureFormat::ETC2RGBA8UnormSrgb, ByteSize(16), Width(4), Height(4), etc2FormatUnsupportedReason, ComponentCount(4), wgpu::TextureFormat::ETC2RGBA8Unorm);
+ AddETCCompressedFormat(wgpu::TextureFormat::EACR11Unorm, ByteSize(8), Width(4), Height(4), etc2FormatUnsupportedReason, ComponentCount(1));
+ AddETCCompressedFormat(wgpu::TextureFormat::EACR11Snorm, ByteSize(8), Width(4), Height(4), etc2FormatUnsupportedReason, ComponentCount(1));
+ AddETCCompressedFormat(wgpu::TextureFormat::EACRG11Unorm, ByteSize(16), Width(4), Height(4), etc2FormatUnsupportedReason, ComponentCount(2));
+ AddETCCompressedFormat(wgpu::TextureFormat::EACRG11Snorm, ByteSize(16), Width(4), Height(4), etc2FormatUnsupportedReason, ComponentCount(2));
// ASTC compressed formats
UnsupportedReason astcFormatUnsupportedReason = device->HasFeature(Feature::TextureCompressionASTC) ? Format::supported : RequiresFeature{wgpu::FeatureName::TextureCompressionASTC};