【问题标题】:What's the equivalent of GLSL's uintBitsToFloat and floatBitsToUint in Metal shading language?GLSL 的 uintBitsToFloat 和 floatBitsToUint 在 Metal 着色语言中的等价物是什么?
【发布时间】:2016-09-23 16:48:19
【问题描述】:

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

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

【问题讨论】:

    标签: opengl glsl shader metal


    【解决方案1】:

    看起来您可以为此使用 as_type<type-id>() 演员表。

    来自此链接的最底部:https://developer.apple.com/library/content/documentation/Metal/Reference/MetalShadingLanguageGuide/data-types/data-types.html#//apple_ref/doc/uid/TP40014364-CH2-SW1

    Metal 着色语言添加了一个 as_type 运算符,以允许将任何标量或矢量数据类型(不是指针)重新解释为另一个相同大小的标量或矢量数据类型。 操作数中的位不经修改直接返回为新类型。不执行通常的函数参数类型提升。

    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);
    

    【讨论】:

      猜你喜欢
      • 2017-09-14
      • 1970-01-01
      • 2016-12-13
      • 1970-01-01
      • 1970-01-01
      • 2020-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多