1 // Copyright 2019 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef DAWNNATIVE_FORMAT_H_ 16 #define DAWNNATIVE_FORMAT_H_ 17 18 #include "dawn_native/dawn_platform.h" 19 20 #include "dawn_native/Error.h" 21 22 #include <array> 23 24 namespace dawn_native { 25 26 class DeviceBase; 27 28 // The number of formats Dawn knows about. Asserts in BuildFormatTable ensure that this is the 29 // exact number of known format. 30 static constexpr size_t kKnownFormatCount = 52; 31 32 // A wgpu::TextureFormat along with all the information about it necessary for validation. 33 struct Format { 34 enum Aspect { 35 Color, 36 Depth, 37 Stencil, 38 DepthStencil, 39 }; 40 41 enum Type { 42 Float, 43 Sint, 44 Uint, 45 Other, 46 }; 47 48 wgpu::TextureFormat format; 49 bool isRenderable; 50 bool isCompressed; 51 // A format can be known but not supported because it is part of a disabled extension. 52 bool isSupported; 53 bool supportsStorageUsage; 54 Aspect aspect; 55 Type type; 56 57 uint32_t blockByteSize; 58 uint32_t blockWidth; 59 uint32_t blockHeight; 60 61 static Type TextureComponentTypeToFormatType(wgpu::TextureComponentType componentType); 62 static wgpu::TextureComponentType FormatTypeToTextureComponentType(Type type); 63 64 bool IsColor() const; 65 bool HasDepth() const; 66 bool HasStencil() const; 67 bool HasDepthOrStencil() const; 68 bool HasComponentType(Type componentType) const; 69 70 // The index of the format in the list of all known formats: a unique number for each format 71 // in [0, kKnownFormatCount) 72 size_t GetIndex() const; 73 }; 74 75 // Implementation details of the format table in the device. 76 77 using FormatTable = std::array<Format, kKnownFormatCount>; 78 79 // Returns the index of a format in the FormatTable. 80 size_t ComputeFormatIndex(wgpu::TextureFormat format); 81 // Builds the format table with the extensions enabled on the device. 82 FormatTable BuildFormatTable(const DeviceBase* device); 83 84 } // namespace dawn_native 85 86 #endif // DAWNNATIVE_FORMAT_H_ 87