Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between normalized, scaled and integer VkFormats?

Tags:

vulkan

Let's take the following 6 VkFormats for example:

VK_FORMAT_R8_UNORM
VK_FORMAT_R8_SNORM
VK_FORMAT_R8_USCALED
VK_FORMAT_R8_SSCALED
VK_FORMAT_R8_UINT
VK_FORMAT_R8_SINT

All of these specify a one-component 8-bit format that has a single 8-bit R component.

The formats differ in whether they are (a) normalized, (b) scaled; or (c) integer. What does that mean? What are the differences between those three things? Where is that specified?

Are all 256 possible values of 8-bits meaningful and valid in all six formats?

(They also differ in whether they are signed or unsigned. I assume this means whether their underlying types are like the C types int8_t or uint8_t ?)

like image 367
Andrew Tomazos Avatar asked Jan 07 '20 13:01

Andrew Tomazos


People also ask

What is a normalized integer?

A Normalized Integer is an integer which is used to store a decimal floating point number. When formats use such an integer, OpenGL will automatically convert them to/from floating point values as needed.

What does Unorm mean?

UNORM. Unsigned normalized integer, meaning that for an n-bit number, all 0's means 0.0f, and all 1's means 1.0f. A sequence of evenly spaced floating point values from 0.0f to 1.0f are represented. e.g. a 2-bit UNORM represents 0.0f, 1/3, 2/3, and 1.0f.


1 Answers

Refer to Identification of Formats and Conversion from Normalized Fixed-Point to Floating-Point in the specification.

  • UNORM is a float in the range of [0, 1].
  • SNORM is the same but in the range of [-1, 1]
  • USCALED is the unsigned integer value converted to float
  • SSCALED is the integer value converted to float
  • UINT is an unsigned integer
  • SINT is a signed integer

I.e. for the VK_FORMAT_R8_*:

  • for UNORM raw 0 would give 0.0f, raw 255 would give 1.0f
  • for SNORM raw -127 (resp. 129) would give -1.0f, raw 127 would give 1.0f
  • USCALED raw 0 would give 0.0f, raw 255 would give 255.0f
  • SSCALEDraw -128 (resp. 128) would give -128.0f, raw 127 would give 127.0f

-128 (-2n-1) is not meaningful in SNORM, and simply clamps to -1.0f.

like image 168
krOoze Avatar answered Oct 14 '22 07:10

krOoze