shader-slang / slang

Making it easier to work with shaders
http://shader-slang.com
Other
3.22k stars 216 forks source link

Bug on supporting bit_cast<uint64_t>(double) #5470

Open kaizhangNV opened 1 month ago

kaizhangNV commented 1 month ago

Following code will cause internal error:

RWStructuredBuffer<uint64_t> out;

uint64_t cast(double x)
{
    return bit_cast<uint64_t>(x);
}

[shader("compute")]
[numthreads(1,1,1)]
void computeMain()
{
    double x = 1.0;

    out[0] = cast(x);
}

note, there is no problem just doing

  out[0] = bit_cast<uint64_t>(1.0lf);
kaizhangNV commented 1 month ago

The error message is:

test1.slang(6): internal error 99999: unimplemented feature in Slang compiler: unexpected IR opcode during code emit
    return bit_cast<uint64_t>(x);
kaizhangNV commented 1 month ago

I tried other targets It has no problem on cpp, cuda, spirv.

kaizhangNV commented 1 month ago

on all the shader language targets, we don't handle double base type during processing kIROp_BitCast.

kaizhangNV commented 1 month ago

There is a TODO in hlsl target // TODO: There is an asdouble function // for converting two 32-bit integer values into // one double. We could use that for // bit casts of 64-bit values with a bit of // extra work, but doing so might be best // handled in an IR pass that legalizes // bit-casts. //

csyonghe commented 4 weeks ago

We should work on top of https://github.com/shader-slang/slang/pull/5020 for this issue.