Falcor
Falcor copied to clipboard
InterlockedAdd failed to compile on vulkan
Hi, InterlockedAdd can't be compiled on linux with vulkan. Please see below.
RWTexture2D<uint> gGridSegmentationCountTex0; uint prevValue = 0; InterlockedAdd(gGridSegmentationCountTex0[mapIntCoord], 1u, prevValue);
Would appreciate for a quick fix. thanks!
the error message:
Program Linkage failed.
Program with Shaders:
(119): error 40008: the form of this l-value argument is not valid for a ref
parameter
This probably needs to be filed as an issue against Slang instead.
I wouldn't be able to look at this until Monday at the earliest, but even then I'm concerned that it won't be a quick fix to get this working correctly with the HLSL syntax in your example. I can try to add the missing support but I'd estimate at least 2-3 days to do it right.
As a temporary workaround (please understand that I'm not promising Slang will support this in the long run), could you try defining a function like the following:
__target_intrinsic(glsl, "imageAtomicAdd($0, $1, $2)$z")
uint imageAtomicAdd(RWTexture2D<uint> t, int2 coord, uint val)
{
uint prevVal = 0;
InterlockedAdd(t[coord], val, prevVal);
return prevVal;
}
I haven't tested the above, so I may have made some mistakes, but something like this should work to define a custom GLSL lowering for a function. I'll repeat that this is not intended to be something that Slang supports in the long term.
Worst case I could add a function along the lines of the above to the Slang standard library so that you can access image atomics on both D3D and Vulkan, even if the syntax isn't the standard HLSL syntax.
Okay, I gave the above a quick test and it doesn't quite work as written, but the following should work for both D3D and Vulkan targets:
__target_intrinsic(glsl, "($3 = imageAtomicAdd($0, $1, $2)$z)")
__target_intrinsic(hlsl, "InterlockedAdd($0[$1], $2, $3)")
void imageAtomicAdd(RWTexture2D<uint> t, int2 coord, uint val, out uint prevVal);
// test shader to make sure it works...
float4 main(float2 uv : UV) : SV_Target
{
int2 mapIntCoord = int2(uv);
uint prevValue = 0;
imageAtomicAdd(gGridSegmentationCountTex0, mapIntCoord, 1u, prevValue);
return prevValue;
}
I can try to add a set of operations along these lines to the Slang standard library early next week to cover the main image atomic cases. Adding support for the proper HLSL syntax will take a bit longer.
I will repeat (for anybody else who might be reading this issue report) that __target_intrinsic
is not a publicly-supported Slang feature, and we reserve the right to completely remove it at any point. This is just a way to get users unblocked since this appears to be time-sensitive.
thank you very much for quick answer. i will try that.
Slang v0.10.35
is in the release pipeline and should add support for the original HLSL InterlockedAdd
syntax. If you get a chance to try that please let me know if it resolves the issue.
Falcor 3.1 has updated Slang 0.11.4
. The error I'm seeing now in Vulkan is:
imageAtomicAdd: no matching overloaded function found
assign: cannot convert from 'const float' to 'temp highp uint'