summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/slang/hlsl.meta.slang4
-rw-r--r--tests/cross-compile/sign-wgsl.slang31
2 files changed, 33 insertions, 2 deletions
diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang
index 1dcb0b7d4..1443843a9 100644
--- a/source/slang/hlsl.meta.slang
+++ b/source/slang/hlsl.meta.slang
@@ -13107,7 +13107,7 @@ int sign(T x)
};
else
return __int_cast<int>(spirv_asm {OpExtInst $$T result glsl450 SSign $x});
- case wgsl: __intrinsic_asm "sign";
+ case wgsl: __intrinsic_asm "i32(sign($0))";
}
}
@@ -13131,7 +13131,7 @@ vector<int, N> sign(vector<T, N> x)
};
else
return __int_cast<int>(spirv_asm {OpExtInst $$vector<T,N> result glsl450 SSign $x});
- case wgsl: __intrinsic_asm "sign";
+ case wgsl: __intrinsic_asm "vec$N0<i32>(sign($0))";
default:
VECTOR_MAP_UNARY(int, N, sign, x);
}
diff --git a/tests/cross-compile/sign-wgsl.slang b/tests/cross-compile/sign-wgsl.slang
new file mode 100644
index 000000000..60e0fceee
--- /dev/null
+++ b/tests/cross-compile/sign-wgsl.slang
@@ -0,0 +1,31 @@
+// sign-wgsl.slang
+
+//TEST:SIMPLE(filecheck=WGSL): -target wgsl -entry main -stage compute
+
+// Test that sign function returns correct type for WGSL
+// WGSL's sign returns float but Slang's sign should return int
+
+struct OutputBuffer
+{
+ int scalar_result;
+ int2 vector_result;
+};
+
+[[vk::binding(0, 0)]]
+RWStructuredBuffer<OutputBuffer> outputBuffer;
+
+[numthreads(1, 1, 1)]
+void main()
+{
+ // Test scalar sign function
+ int scalar_result = sign(0.5);
+
+ // Test vector sign function
+ int2 vector_result = sign(float2(1.5, -0.5));
+
+ outputBuffer[0].scalar_result = scalar_result;
+ outputBuffer[0].vector_result = vector_result;
+
+ // WGSL-DAG: i32(sign(
+ // WGSL-DAG: vec2<i32>(sign((vec2<f32>
+} \ No newline at end of file