GLSL 的 uintBitsToFloat 和 floatBitsToUint 在 Metal 着色语言中的等价物是什么?

What's the equivalent of GLSL's uintBitsToFloat and floatBitsToUint in Metal shading language?

我正在将计算着色器从 GLSL 转换为金属着色语言。我正在使用函数 uintBitsToFloatfloatBitsToUint 来存储原子变量。它们在 Metal 中的等价物是什么? GLSL 中的示例用法:

shared uint ldsZMin;
...
float depth = -imageLoad( depthTexture, ivec2( globalThreadIdx.x, globalThreadIdx.y ) ).x;
uint z = floatBitsToUint( depth );
atomicMin( ldsZMin, z );

看来您可以为此使用 as_type<type-id>() 转换。

从这个 link 的最底部开始:https://developer.apple.com/library/content/documentation/Metal/Reference/MetalShadingLanguageGuide/data-types/data-types.html#//apple_ref/doc/uid/TP40014364-CH2-SW1

The Metal shading language adds an as_type operator to allow any scalar or vector data type (that is not a pointer) to be reinterpreted as another scalar or vector data type of the same size. The bits in the operand are returned directly without modification as the new type. The usual type promotion for function arguments is not performed.

float f = 1.0f;
// Legal. Contains: 0x3f800000
uint u = as_type<uint>(f);

// Legal. Contains:
// (int4)(0x3f800000, 0x40000000,
//        0x40400000, 0x40800000)
float4 f = float4(1.0f, 2.0f, 3.0f, 4.0f);
int4 i = as_type<int4>(f);