HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
types.h
Go to the documentation of this file.
1 //
2 // Copyright 2020 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_HGI_TYPES_H
25 #define PXR_IMAGING_HGI_TYPES_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/base/gf/vec3i.h"
29 #include "pxr/imaging/hgi/api.h"
30 #include <vector>
31 #include <limits>
32 #include <stdlib.h>
33 
34 
36 
37 /// \enum HgiFormat
38 ///
39 /// HgiFormat describes the memory format of image buffers used in Hgi.
40 /// These formats are closely aligned with HdFormat and allow us to keep Hgi
41 /// independent of Hd.
42 ///
43 /// For reference, see:
44 /// https://www.khronos.org/registry/vulkan/specs/1.1/html/vkspec.html#VkFormat
45 enum HgiFormat : int
46 {
48 
49  // UNorm8 - a 1-byte value representing a float between 0 and 1.
50  // float value = (unorm / 255.0f);
53  /* HgiFormatUNorm8Vec3 */ // Unsupported Metal (MTLPixelFormat)
55 
56  // SNorm8 - a 1-byte value representing a float between -1 and 1.
57  // float value = max(snorm / 127.0f, -1.0f);
60  /* HgiFormatSNorm8Vec3 */ // Unsupported Metal (MTLPixelFormat)
62 
63  // Float16 - a 2-byte IEEE half-precision float.
68 
69  // Float32 - a 4-byte IEEE float.
74 
75  // Int16 - a 2-byte signed integer
80 
81  // UInt16 - a 2-byte unsigned integer
86 
87  // Int32 - a 4-byte signed integer
92 
93  // UNorm8 SRGB - a 1-byte value representing a float between 0 and 1.
94  // Gamma compression/decompression happens during read/write.
95  // Alpha component is linear.
96  /* HgiFormatUNorm8srgb */ // Unsupported by OpenGL
97  /* HgiFormatUNorm8Vec2srgb */ // Unsupported by OpenGL
98  /* HgiFormatUNorm8Vec3srgb */ // Unsupported Metal (MTLPixelFormat)
100 
101  // BPTC compressed. 3-component, 4x4 blocks, signed floating-point
103 
104  // BPTC compressed. 3-component, 4x4 blocks, unsigned floating-point
106 
107  // BPTC compressed. 4-component, 4x4 blocks, unsigned byte.
108  // Representing a float between 0 and 1.
110 
111  // BPTC compressed. 4-component, 4x4 blocks, unsigned byte, sRGB.
112  // Representing a float between 0 and 1.
114 
115  // S3TC/DXT compressed. 4-component, 4x4 blocks, unsigned byte
116  // Representing a float between 0 and 1.
118 
119  // S3TC/DXT compressed. 4-component, 4x4 blocks, unsigned byte
120  // Representing a float between 0 and 1.
122 
123  // Depth stencil format (Float32 can be used for just depth)
125 
127 };
128 
129 /// \class HgiMipInfo
130 ///
131 /// HgiMipInfo describes size and other info for a mip level.
133 {
134  /// Offset in bytes from start of texture data to start of mip map.
135  size_t byteOffset;
136  /// Dimension of mip GfVec3i.
138  /// size of (one layer if array of) mip map in bytes.
140 };
141 
142 /// Return the count of components in the given format.
143 HGI_API
145 
146 /// Return the size of a single element of the given format.
147 ///
148 /// For an uncompressed format, returns the number of bytes per pixel
149 /// and sets blockWidth and blockHeight to 1.
150 /// For a compressed format (e.g., BC6), returns the number of bytes per
151 /// block and sets blockWidth and blockHeight to the width and height of
152 /// a block.
153 ///
154 HGI_API
156  HgiFormat f,
157  size_t *blockWidth = nullptr,
158  size_t *blockHeight = nullptr);
159 
160 /// Return whether the given format uses compression.
161 HGI_API
163 
164 /// Returns the size necessary to allocate a buffer of given dimensions
165 /// and format, rounding dimensions up to suitable multiple when
166 /// using a compressed format.
167 HGI_API
168 size_t HgiGetDataSize(
169  HgiFormat f,
170  const GfVec3i &dimensions);
171 
172 /// Returns mip infos.
173 ///
174 /// If dataByteSize is specified, the levels stops when the total memory
175 /// required by all levels up to that point reach the specified value.
176 /// Otherwise, the levels stop when all dimensions are 1.
177 /// Mip map sizes are calculated by dividing the previous mip level by two and
178 /// rounding down to the nearest integer (minimum integer is 1).
179 /// level 0: 37x53
180 /// level 1: 18x26
181 /// level 2: 9x13
182 /// level 3: 4x6
183 /// level 4: 2x3
184 /// level 5: 1x1
185 HGI_API
186 std::vector<HgiMipInfo>
189  const GfVec3i& dimensions,
190  size_t layerCount,
191  size_t dataByteSize = std::numeric_limits<size_t>::max());
192 
194 
195 #endif
size_t byteOffset
Offset in bytes from start of texture data to start of mip map.
Definition: types.h:135
HGI_API bool HgiIsCompressed(HgiFormat f)
Return whether the given format uses compression.
HGI_API size_t HgiGetDataSizeOfFormat(HgiFormat f, size_t *blockWidth=nullptr, size_t *blockHeight=nullptr)
HGI_API std::vector< HgiMipInfo > HgiGetMipInfos(HgiFormat format, const GfVec3i &dimensions, size_t layerCount, size_t dataByteSize=std::numeric_limits< size_t >::max())
HgiFormat
Definition: types.h:45
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
Definition: vec3i.h:61
HGI_API size_t HgiGetDataSize(HgiFormat f, const GfVec3i &dimensions)
GfVec3i dimensions
Dimension of mip GfVec3i.
Definition: types.h:137
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:107
#define HGI_API
Definition: api.h:40
HGI_API size_t HgiGetComponentCount(HgiFormat f)
Return the count of components in the given format.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
size_t byteSizePerLayer
size of (one layer if array of) mip map in bytes.
Definition: types.h:139
GLfloat f
Definition: glcorearb.h:1925