// Copyright 2019 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_NATIVE_FORMAT_H_ #define SRC_DAWN_NATIVE_FORMAT_H_ #include <array> #include <variant> #include "dawn/native/dawn_platform.h" #include "dawn/common/TypedInteger.h" #include "dawn/common/ityp_array.h" #include "dawn/common/ityp_bitset.h" #include "dawn/native/EnumClassBitmasks.h" #include "dawn/native/Error.h" #include "dawn/native/Subresource.h" #include "absl/strings/str_format.h" // About multi-planar formats. // // Dawn supports additional multi-planar formats when the multiplanar-formats extension is enabled. // When enabled, Dawn treats planar data as sub-resources (ie. 1 sub-resource == 1 view == 1 plane). // A multi-planar format name encodes the channel mapping and order of planes. For example, // R8BG8Biplanar420Unorm is YUV 4:2:0 where Plane 0 = R8, and Plane 1 = BG8. // // Requirements: // * Plane aspects cannot be combined with color, depth, or stencil aspects. // * Only compatible multi-planar formats of planes can be used with multi-planar texture // formats. // * Can't access multiple planes without creating per plane views (no color conversion). // * Multi-planar format cannot be written or read without a per plane view. // // TODO(dawn:551): Consider moving this comment. namespace dawn::native { enum class Aspect : uint8_t; class DeviceBase; // This mirrors wgpu::TextureSampleType as a bitmask instead. // NOTE: SampleTypeBit::External does not have an equivalent TextureSampleType. All future // additions to SampleTypeBit that have an equivalent TextureSampleType should use // SampleTypeBit::External's value and update SampleTypeBit::External to a higher value. // TODO(crbug.com/dawn/2476): Validate SampleTypeBit::External is compatible with Sampler. enum class SampleTypeBit : uint8_t { … }; // Converts a wgpu::TextureSampleType to its bitmask representation. SampleTypeBit SampleTypeToSampleTypeBit(wgpu::TextureSampleType sampleType); struct TexelBlockInfo { … }; enum class TextureComponentType { … }; enum class TextureSubsampling { … }; struct RequiresFeature { … }; struct CompatibilityMode { … }; UnsupportedReason; struct AspectInfo { … }; // The number of formats Dawn knows about. Asserts in BuildFormatTable ensure that this is the // exact number of known format. static constexpr uint32_t kWebGPUFormatCount = …; static constexpr uint32_t kDawnFormatCount = …; static constexpr uint32_t kKnownFormatCount = …; FormatIndex; struct Format; FormatTable; // A wgpu::TextureFormat along with all the information about it necessary for validation. struct Format { … }; class FormatSet : public ityp::bitset<FormatIndex, kKnownFormatCount> { … }; // Implementation details of the format table in the device. // Returns the index of a format in the FormatTable. FormatIndex ComputeFormatIndex(wgpu::TextureFormat format); // Builds the format table with the extensions enabled on the device. FormatTable BuildFormatTable(const DeviceBase* device); absl::FormatConvertResult<absl::FormatConversionCharSet::kString> AbslFormatConvert( const UnsupportedReason& value, const absl::FormatConversionSpec& spec, absl::FormatSink* s); } // namespace dawn::native template <> struct wgpu::IsWGPUBitmask<dawn::native::SampleTypeBit> { … }; #endif // SRC_DAWN_NATIVE_FORMAT_H_