chromium/third_party/dawn/src/dawn/utils/TextureUtils.h

// Copyright 2020 The Dawn & Tint Authors
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
//    list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
//    this list of conditions and the following disclaimer in the documentation
//    and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
//    contributors may be used to endorse or promote products derived from
//    this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef SRC_DAWN_UTILS_TEXTUREUTILS_H_
#define SRC_DAWN_UTILS_TEXTUREUTILS_H_

#include <webgpu/webgpu_cpp.h>

#include <array>

#include "dawn/common/Assert.h"

namespace dawn::utils {

#ifndef __EMSCRIPTEN__
static constexpr std::array<wgpu::TextureFormat, 101> kAllTextureFormats =;
#endif  // __EMSCRIPTEN__

static constexpr std::array<wgpu::TextureFormat, 41> kFormatsInCoreSpec =;

static constexpr std::array<wgpu::TextureFormat, 14> kBCFormats =;

static constexpr std::array<wgpu::TextureFormat, 10> kETC2Formats =;

static constexpr std::array<wgpu::TextureFormat, 28> kASTCFormats =;

static constexpr std::array<wgpu::TextureFormat, 52> kCompressedFormats =;
static_assert;

#ifndef __EMSCRIPTEN__
static constexpr std::array<wgpu::TextureFormat, 6> kNorm16Formats =;
#endif  // __EMSCRIPTEN__

static constexpr std::array<wgpu::TextureFormat, 5> kDepthFormats =;
static constexpr std::array<wgpu::TextureFormat, 3> kStencilFormats =;
static constexpr std::array<wgpu::TextureFormat, 2> kDepthAndStencilFormats =;

class SubsamplingFactor {};

bool TextureFormatSupportsStorageTexture(wgpu::TextureFormat format,
                                         const wgpu::Device& device,
                                         bool isCompatibilityMode);
bool TextureFormatSupportsReadWriteStorageTexture(wgpu::TextureFormat format);

bool IsBCTextureFormat(wgpu::TextureFormat textureFormat);
bool IsETC2TextureFormat(wgpu::TextureFormat textureFormat);
bool IsASTCTextureFormat(wgpu::TextureFormat textureFormat);
bool IsCompressedTextureFormat(wgpu::TextureFormat textureFormat);

bool IsDepthOnlyFormat(wgpu::TextureFormat textureFormat);
bool IsStencilOnlyFormat(wgpu::TextureFormat textureFormat);
bool IsDepthOrStencilFormat(wgpu::TextureFormat textureFormat);

bool IsRenderableFormat(const wgpu::Device& device, wgpu::TextureFormat textureFormat);

bool TextureFormatSupportsMultisampling(const wgpu::Device& device,
                                        wgpu::TextureFormat textureFormat);
bool TextureFormatSupportsResolveTarget(const wgpu::Device& device,
                                        wgpu::TextureFormat textureFormat);

#ifndef __EMSCRIPTEN__
bool IsUnorm16TextureFormat(wgpu::TextureFormat textureFormat);
bool IsSnorm16TextureFormat(wgpu::TextureFormat textureFormat);

bool IsMultiPlanarFormat(wgpu::TextureFormat textureFormat);
uint32_t GetMultiPlaneTextureBitDepth(wgpu::TextureFormat textureFormat);
uint32_t GetMultiPlaneTextureNumPlanes(wgpu::TextureFormat textureFormat);
uint32_t GetMultiPlaneTextureBytesPerElement(wgpu::TextureFormat textureFormat, size_t plane);
SubsamplingFactor GetMultiPlaneTextureSubsamplingFactor(wgpu::TextureFormat textureFormat,
                                                        size_t plane);
#endif  // __EMSCRIPTEN__

uint32_t GetTexelBlockSizeInBytes(wgpu::TextureFormat textureFormat);
uint32_t GetTextureFormatBlockWidth(wgpu::TextureFormat textureFormat);
uint32_t GetTextureFormatBlockHeight(wgpu::TextureFormat textureFormat);

const char* GetWGSLColorTextureComponentType(wgpu::TextureFormat textureFormat);
const char* GetWGSLImageFormatQualifier(wgpu::TextureFormat textureFormat);
uint32_t GetTextureComponentCount(wgpu::TextureFormat textureFormat);

wgpu::TextureDimension ViewDimensionToTextureDimension(const wgpu::TextureViewDimension dimension);
}  // namespace dawn::utils

#endif  // SRC_DAWN_UTILS_TEXTUREUTILS_H_