dfd.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* -*- tab-width: 4; -*- */
  2. /* vi: set sw=2 ts=4 expandtab: */
  3. /* Copyright 2019-2020 The Khronos Group Inc.
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @~English
  9. * @brief Header file defining the data format descriptor utilities API.
  10. */
  11. /*
  12. * Author: Andrew Garrard
  13. */
  14. #ifndef _DFD_H_
  15. #define _DFD_H_
  16. #include <KHR/khr_df.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /** Qualifier suffix to the format, in Vulkan terms. */
  21. enum VkSuffix {
  22. s_UNORM, /*!< Unsigned normalized format. */
  23. s_SNORM, /*!< Signed normalized format. */
  24. s_USCALED, /*!< Unsigned scaled format. */
  25. s_SSCALED, /*!< Signed scaled format. */
  26. s_UINT, /*!< Unsigned integer format. */
  27. s_SINT, /*!< Signed integer format. */
  28. s_SFLOAT, /*!< Signed float format. */
  29. s_UFLOAT, /*!< Unsigned float format. */
  30. s_SRGB /*!< sRGB normalized format. */
  31. };
  32. /** Compression scheme, in Vulkan terms. */
  33. enum VkCompScheme {
  34. c_BC1_RGB, /*!< BC1, aka DXT1, no alpha. */
  35. c_BC1_RGBA, /*!< BC1, aka DXT1, punch-through alpha. */
  36. c_BC2, /*!< BC2, aka DXT2 and DXT3. */
  37. c_BC3, /*!< BC3, aka DXT4 and DXT5. */
  38. c_BC4, /*!< BC4. */
  39. c_BC5, /*!< BC5. */
  40. c_BC6H, /*!< BC6h HDR format. */
  41. c_BC7, /*!< BC7. */
  42. c_ETC2_R8G8B8, /*!< ETC2 no alpha. */
  43. c_ETC2_R8G8B8A1, /*!< ETC2 punch-through alpha. */
  44. c_ETC2_R8G8B8A8, /*!< ETC2 independent alpha. */
  45. c_EAC_R11, /*!< R11 ETC2 single-channel. */
  46. c_EAC_R11G11, /*!< R11G11 ETC2 dual-channel. */
  47. c_ASTC, /*!< ASTC. */
  48. c_ETC1S, /*!< ETC1S. */
  49. c_PVRTC, /*!< PVRTC(1). */
  50. c_PVRTC2 /*!< PVRTC2. */
  51. };
  52. typedef unsigned int uint32_t;
  53. #if !defined(LIBKTX)
  54. #include <vulkan/vulkan_core.h>
  55. #else
  56. #include "../vkformat_enum.h"
  57. #endif
  58. uint32_t* vk2dfd(enum VkFormat format);
  59. /* Create a Data Format Descriptor for an unpacked format. */
  60. uint32_t *createDFDUnpacked(int bigEndian, int numChannels, int bytes,
  61. int redBlueSwap, enum VkSuffix suffix);
  62. /* Create a Data Format Descriptor for a packed format. */
  63. uint32_t *createDFDPacked(int bigEndian, int numChannels,
  64. int bits[], int channels[],
  65. enum VkSuffix suffix);
  66. /* Create a Data Format Descriptor for a compressed format. */
  67. uint32_t *createDFDCompressed(enum VkCompScheme compScheme,
  68. int bwidth, int bheight, int bdepth,
  69. enum VkSuffix suffix);
  70. /* Create a Data Format Descriptor for a depth/stencil format. */
  71. uint32_t *createDFDDepthStencil(int depthBits,
  72. int stencilBits,
  73. int sizeBytes);
  74. /** @brief Result of interpreting the data format descriptor. */
  75. enum InterpretDFDResult {
  76. i_LITTLE_ENDIAN_FORMAT_BIT = 0, /*!< Confirmed little-endian (default for 8bpc). */
  77. i_BIG_ENDIAN_FORMAT_BIT = 1, /*!< Confirmed big-endian. */
  78. i_PACKED_FORMAT_BIT = 2, /*!< Packed format. */
  79. i_SRGB_FORMAT_BIT = 4, /*!< sRGB transfer function. */
  80. i_NORMALIZED_FORMAT_BIT = 8, /*!< Normalized (UNORM or SNORM). */
  81. i_SIGNED_FORMAT_BIT = 16, /*!< Format is signed. */
  82. i_FLOAT_FORMAT_BIT = 32, /*!< Format is floating point. */
  83. i_UNSUPPORTED_ERROR_BIT = 64, /*!< Format not successfully interpreted. */
  84. /** "NONTRIVIAL_ENDIANNESS" means not big-endian, not little-endian
  85. * (a channel has bits that are not consecutive in either order). **/
  86. i_UNSUPPORTED_NONTRIVIAL_ENDIANNESS = i_UNSUPPORTED_ERROR_BIT,
  87. /** "MULTIPLE_SAMPLE_LOCATIONS" is an error because only single-sample
  88. * texel blocks (with coordinates 0,0,0,0 for all samples) are supported. **/
  89. i_UNSUPPORTED_MULTIPLE_SAMPLE_LOCATIONS = i_UNSUPPORTED_ERROR_BIT + 1,
  90. /** "MULTIPLE_PLANES" is an error because only contiguous data is supported. */
  91. i_UNSUPPORTED_MULTIPLE_PLANES = i_UNSUPPORTED_ERROR_BIT + 2,
  92. /** Only channels R, G, B and A are supported. */
  93. i_UNSUPPORTED_CHANNEL_TYPES = i_UNSUPPORTED_ERROR_BIT + 3,
  94. /** Only channels with the same flags are supported
  95. * (e.g. we don't support float red with integer green). */
  96. i_UNSUPPORTED_MIXED_CHANNELS = i_UNSUPPORTED_ERROR_BIT + 4
  97. };
  98. /** @brief Interpretation of a channel from the data format descriptor. */
  99. typedef struct _InterpretedDFDChannel {
  100. uint32_t offset; /*!< Offset in bits for packed, bytes for unpacked. */
  101. uint32_t size; /*!< Size in bits for packed, bytes for unpacked. */
  102. } InterpretedDFDChannel;
  103. /* Interpret a Data Format Descriptor. */
  104. enum InterpretDFDResult interpretDFD(const uint32_t *DFD,
  105. InterpretedDFDChannel *R,
  106. InterpretedDFDChannel *G,
  107. InterpretedDFDChannel *B,
  108. InterpretedDFDChannel *A,
  109. uint32_t *wordBytes);
  110. /* Print a human-readable interpretation of a data format descriptor. */
  111. void printDFD(uint32_t *DFD);
  112. /* Get the number of components & component size from a DFD for an
  113. * unpacked format.
  114. */
  115. void
  116. getDFDComponentInfoUnpacked(const uint32_t* DFD, uint32_t* numComponents,
  117. uint32_t* componentByteLength);
  118. /* Return the number of components described by a DFD. */
  119. uint32_t getDFDNumComponents(const uint32_t* DFD);
  120. /* Recreate and return the value of bytesPlane0 as it should be for the data
  121. * post-inflation from variable-rate compression.
  122. */
  123. void
  124. recreateBytesPlane0FromSampleInfo(const uint32_t* DFD, uint32_t* bytesPlane0);
  125. /** @brief Colourspace primaries information.
  126. *
  127. * Structure to store the 1931 CIE x,y chromaticities of the red, green, and blue
  128. * display primaries and the reference white point of a colourspace.
  129. */
  130. typedef struct _Primaries {
  131. float Rx; /*!< Red x. */
  132. float Ry; /*!< Red y. */
  133. float Gx; /*!< Green x. */
  134. float Gy; /*!< Green y. */
  135. float Bx; /*!< Blue x. */
  136. float By; /*!< Blue y. */
  137. float Wx; /*!< White x. */
  138. float Wy; /*!< White y. */
  139. } Primaries;
  140. khr_df_primaries_e findMapping(Primaries *p, float latitude);
  141. #ifdef __cplusplus
  142. }
  143. #endif
  144. #endif /* _DFD_H_ */