user187676
user187676

Reputation:

Metal Texture Formats

I declare a metal texture in Swift with format .bgra8Unorm. Now in the metal compute kernel I access it using the half data type (I believe an Apple example did it this way).

texture2d<half, access::sample> inTexture [[ texture(0) ]]

Will accessing a bgra8Unorm texture this way (via a sampler) and/or writing it back automatically pack and unpack half values to and from 8 bit integers? What happens when I write a negative half value to the texture?

Upvotes: 2

Views: 631

Answers (1)

warrenm
warrenm

Reputation: 31782

Yes. When writing to a texture with normalized unsigned integer components, the values are effectively clamped to [0, 1], then scaled by the maximum value of the format (255, in this case).

Upvotes: 3

Related Questions