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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HGI_TYPES_H
8 #define PXR_IMAGING_HGI_TYPES_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/base/gf/vec3i.h"
12 #include "pxr/imaging/hgi/api.h"
13 #include <vector>
14 #include <limits>
15 #include <stdlib.h>
16 
17 
19 
20 /// \enum HgiFormat
21 ///
22 /// HgiFormat describes the memory format of image buffers used in Hgi.
23 /// These formats are closely aligned with HdFormat and allow us to keep Hgi
24 /// independent of Hd.
25 ///
26 /// For reference, see:
27 /// https://www.khronos.org/registry/vulkan/specs/1.1/html/vkspec.html#VkFormat
28 enum HgiFormat : int
29 {
31 
32  // UNorm8 - a 1-byte value representing a float between 0 and 1.
33  // float value = (unorm / 255.0f);
36  /* HgiFormatUNorm8Vec3 */ // Unsupported Metal (MTLPixelFormat)
38 
39  // SNorm8 - a 1-byte value representing a float between -1 and 1.
40  // float value = max(snorm / 127.0f, -1.0f);
43  /* HgiFormatSNorm8Vec3 */ // Unsupported Metal (MTLPixelFormat)
45 
46  // Float16 - a 2-byte IEEE half-precision float.
51 
52  // Float32 - a 4-byte IEEE float.
57 
58  // Int16 - a 2-byte signed integer
63 
64  // UInt16 - a 2-byte unsigned integer
69 
70  // Int32 - a 4-byte signed integer
75 
76  // UNorm8 SRGB - a 1-byte value representing a float between 0 and 1.
77  // Gamma compression/decompression happens during read/write.
78  // Alpha component is linear.
79  /* HgiFormatUNorm8srgb */ // Unsupported by OpenGL
80  /* HgiFormatUNorm8Vec2srgb */ // Unsupported by OpenGL
81  /* HgiFormatUNorm8Vec3srgb */ // Unsupported Metal (MTLPixelFormat)
83 
84  // BPTC compressed. 3-component, 4x4 blocks, signed floating-point
86 
87  // BPTC compressed. 3-component, 4x4 blocks, unsigned floating-point
89 
90  // BPTC compressed. 4-component, 4x4 blocks, unsigned byte.
91  // Representing a float between 0 and 1.
93 
94  // BPTC compressed. 4-component, 4x4 blocks, unsigned byte, sRGB.
95  // Representing a float between 0 and 1.
97 
98  // S3TC/DXT compressed. 4-component, 4x4 blocks, unsigned byte
99  // Representing a float between 0 and 1.
101 
102  // S3TC/DXT compressed. 4-component, 4x4 blocks, unsigned byte
103  // Representing a float between 0 and 1.
105 
106  // Depth stencil format (Float32 can be used for just depth)
108 
109  // Packed 32-bit value with four normalized signed two's complement
110  // integer values arranged as 10 bits, 10 bits, 10 bits, and 2 bits.
112 
114 };
115 
116 /// \class HgiMipInfo
117 ///
118 /// HgiMipInfo describes size and other info for a mip level.
120 {
121  /// Offset in bytes from start of texture data to start of mip map.
122  size_t byteOffset;
123  /// Dimension of mip GfVec3i.
125  /// size of (one layer if array of) mip map in bytes.
127 };
128 
129 /// Return the count of components in the given format.
130 HGI_API
132 
133 /// Return the size of a single element of the given format.
134 ///
135 /// For an uncompressed format, returns the number of bytes per pixel
136 /// and sets blockWidth and blockHeight to 1.
137 /// For a compressed format (e.g., BC6), returns the number of bytes per
138 /// block and sets blockWidth and blockHeight to the width and height of
139 /// a block.
140 ///
141 HGI_API
143  HgiFormat f,
144  size_t *blockWidth = nullptr,
145  size_t *blockHeight = nullptr);
146 
147 /// Return whether the given format uses compression.
148 HGI_API
150 
151 /// Returns the size necessary to allocate a buffer of given dimensions
152 /// and format, rounding dimensions up to suitable multiple when
153 /// using a compressed format.
154 HGI_API
155 size_t HgiGetDataSize(
156  HgiFormat f,
157  const GfVec3i &dimensions);
158 
159 /// Returns the scalar type of the format, in the form of an HgiFormat, if
160 /// possible.
161 HGI_API
163  HgiFormat f);
164 
165 /// Returns true if the scalar type of the format is a floating point type.
166 HGI_API
167 bool HgiIsFloatFormat(
168  HgiFormat f);
169 
170 /// Returns mip infos.
171 ///
172 /// If dataByteSize is specified, the levels stops when the total memory
173 /// required by all levels up to that point reach the specified value.
174 /// Otherwise, the levels stop when all dimensions are 1.
175 /// Mip map sizes are calculated by dividing the previous mip level by two and
176 /// rounding down to the nearest integer (minimum integer is 1).
177 /// level 0: 37x53
178 /// level 1: 18x26
179 /// level 2: 9x13
180 /// level 3: 4x6
181 /// level 4: 2x3
182 /// level 5: 1x1
183 HGI_API
184 std::vector<HgiMipInfo>
187  const GfVec3i& dimensions,
188  size_t layerCount,
189  size_t dataByteSize = std::numeric_limits<size_t>::max());
190 
192 
193 #endif
HGI_API bool HgiIsFloatFormat(HgiFormat f)
Returns true if the scalar type of the format is a floating point type.
size_t byteOffset
Offset in bytes from start of texture data to start of mip map.
Definition: types.h:122
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:28
GLfloat f
Definition: glcorearb.h:1926
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
Definition: vec3i.h:43
HGI_API size_t HgiGetDataSize(HgiFormat f, const GfVec3i &dimensions)
GfVec3i dimensions
Dimension of mip GfVec3i.
Definition: types.h:124
#define HGI_API
Definition: api.h:23
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:1425
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
size_t byteSizePerLayer
size of (one layer if array of) mip map in bytes.
Definition: types.h:126
HGI_API HgiFormat HgiGetComponentBaseFormat(HgiFormat f)