test(naga): add float-sign snapshot

This commit is contained in:
Erich Gubler authored and mergify[bot] committed 2026-10-05 12:08:36 +00:00
1 parent 957a90dd12
commit 3a227342f2
9 files changed
+244

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
targets = "SPIRV | METAL | HLSL | GLSL | WGSL"
[msl]
fake_missing_bindings = true
lang_version = [2, 0]
spirv_cross_compatibility = false
zero_initialize_workgroup_memory = false
[hlsl]
shader_model = "V5_1"
fake_missing_bindings = true
immediates_target = { register = 0, space = 0 }
restrict_indexing = true
zero_initialize_workgroup_memory = false
[spv]
version = [1, 0]
+22
View File
@@ -0,0 +1,22 @@
// Regression test for `sign` lowering in the HLSL backend
// (https://bugzilla.mozilla.org/show_bug.cgi?id=2011051). HLSL's `sign`
// intrinsic returns a signed integer even for floating-point arguments, so the
// result must be converted back to the argument's type. Storing an unconverted
// result reinterprets the integer's bits, turning `sign(-1.0)` into a NaN.
@group(0) @binding(0) var<storage, read_write> floats: array<f32, 4>;
@group(0) @binding(1) var<storage, read_write> ints: array<i32, 4>;
@compute @workgroup_size(1)
fn main() {
floats[0] = sign(floats[1]);
let v = vec2(floats[2], floats[3]);
let signs = sign(v);
floats[2] = signs.x;
floats[3] = signs.y;
// Unlike the floating-point overloads, HLSL's `sign` already returns the
// right type here, so no conversion is emitted.
ints[0] = sign(ints[1]);
}
@@ -0,0 +1,26 @@
#version 310 es
precision highp float;
precision highp int;
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(std430) buffer type_1_block_0Compute { float _group_0_binding_0_cs[4]; };
layout(std430) buffer type_3_block_1Compute { int _group_0_binding_1_cs[4]; };
void main() {
float _e4 = _group_0_binding_0_cs[1];
_group_0_binding_0_cs[0] = sign(_e4);
float _e8 = _group_0_binding_0_cs[2];
float _e11 = _group_0_binding_0_cs[3];
vec2 v = vec2(_e8, _e11);
vec2 signs = sign(v);
_group_0_binding_0_cs[2] = signs.x;
_group_0_binding_0_cs[3] = signs.y;
int _e24 = _group_0_binding_1_cs[1];
_group_0_binding_1_cs[0] = sign(_e24);
return;
}
+18
View File
@@ -0,0 +1,18 @@
RWByteAddressBuffer floats : register(u0);
RWByteAddressBuffer ints : register(u1);
[numthreads(1, 1, 1)]
void main()
{
float _e4 = asfloat(floats.Load(4));
floats.Store(0, asuint(sign(_e4)));
float _e8 = asfloat(floats.Load(8));
float _e11 = asfloat(floats.Load(12));
float2 v = float2(_e8, _e11);
float2 signs = sign(v);
floats.Store(8, asuint(signs.x));
floats.Store(12, asuint(signs.y));
int _e24 = asint(ints.Load(4));
ints.Store(0, asuint(sign(_e24)));
return;
}
+16
View File
@@ -0,0 +1,16 @@
(
vertex:[
],
fragment:[
],
compute:[
(
entry_point:"main",
target_profile:"cs_5_1",
),
],
task:[
],
mesh:[
],
)
+29
View File
@@ -0,0 +1,29 @@
// language: metal2.0
#include <metal_stdlib>
#include <simd/simd.h>
using metal::uint;
struct type_1 {
float inner[4];
};
struct type_3 {
int inner[4];
};
kernel void main_(
device type_1& floats [[user(fake0)]]
, device type_3& ints [[user(fake0)]]
) {
float _e4 = floats.inner[1];
floats.inner[0] = metal::sign(_e4);
float _e8 = floats.inner[2];
float _e11 = floats.inner[3];
metal::float2 v = metal::float2(_e8, _e11);
metal::float2 signs = metal::sign(v);
floats.inner[2] = signs.x;
floats.inner[3] = signs.y;
int _e24 = ints.inner[1];
ints.inner[0] = metal::select(metal::select(int(-1), int(1), (_e24 > 0)), int(0), (_e24 == 0));
return;
}
+73
View File
@@ -0,0 +1,73 @@
; SPIR-V
; Version: 1.0
; Generator: rspirv
; Bound: 48
OpCapability Shader
OpExtension "SPV_KHR_storage_buffer_storage_class"
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %17 "main"
OpExecutionMode %17 LocalSize 1 1 1
OpDecorate %4 ArrayStride 4
OpDecorate %8 ArrayStride 4
OpDecorate %10 DescriptorSet 0
OpDecorate %10 Binding 0
OpDecorate %11 Block
OpMemberDecorate %11 0 Offset 0
OpDecorate %13 DescriptorSet 0
OpDecorate %13 Binding 1
OpDecorate %14 Block
OpMemberDecorate %14 0 Offset 0
%2 = OpTypeVoid
%3 = OpTypeFloat 32
%6 = OpTypeInt 32 0
%5 = OpConstant %6 4
%4 = OpTypeArray %3 %5
%7 = OpTypeInt 32 1
%8 = OpTypeArray %7 %5
%9 = OpTypeVector %3 2
%11 = OpTypeStruct %4
%12 = OpTypePointer StorageBuffer %11
%10 = OpVariable %12 StorageBuffer
%14 = OpTypeStruct %8
%15 = OpTypePointer StorageBuffer %14
%13 = OpVariable %15 StorageBuffer
%18 = OpTypeFunction %2
%19 = OpTypePointer StorageBuffer %4
%20 = OpConstant %6 0
%22 = OpTypePointer StorageBuffer %8
%25 = OpTypePointer StorageBuffer %3
%26 = OpConstant %6 1
%31 = OpConstant %6 2
%34 = OpConstant %6 3
%43 = OpTypePointer StorageBuffer %7
%17 = OpFunction %2 None %18
%16 = OpLabel
%21 = OpAccessChain %19 %10 %20
%23 = OpAccessChain %22 %13 %20
OpBranch %24
%24 = OpLabel
%27 = OpAccessChain %25 %21 %26
%28 = OpLoad %3 %27
%29 = OpExtInst %3 %1 FSign %28
%30 = OpAccessChain %25 %21 %20
OpStore %30 %29
%32 = OpAccessChain %25 %21 %31
%33 = OpLoad %3 %32
%35 = OpAccessChain %25 %21 %34
%36 = OpLoad %3 %35
%37 = OpCompositeConstruct %9 %33 %36
%38 = OpExtInst %9 %1 FSign %37
%39 = OpCompositeExtract %3 %38 0
%40 = OpAccessChain %25 %21 %31
OpStore %40 %39
%41 = OpCompositeExtract %3 %38 1
%42 = OpAccessChain %25 %21 %34
OpStore %42 %41
%44 = OpAccessChain %43 %23 %26
%45 = OpLoad %7 %44
%46 = OpExtInst %7 %1 SSign %45
%47 = OpAccessChain %43 %23 %20
OpStore %47 %46
OpReturn
OpFunctionEnd
@@ -0,0 +1,24 @@
#version 460
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(set = 0, binding = 0, std430) buffer _11_10
{
float _m0[4];
} _10;
layout(set = 0, binding = 1, std430) buffer _14_13
{
int _m0[4];
} _13;
void main()
{
_10._m0[0u] = sign(_10._m0[1u]);
float _33 = _10._m0[2u];
float _36 = _10._m0[3u];
vec2 _38 = sign(vec2(_33, _36));
_10._m0[2u] = _38.x;
_10._m0[3u] = _38.y;
_13._m0[0u] = sign(_13._m0[1u]);
}
+19
View File
@@ -0,0 +1,19 @@
@group(0) @binding(0)
var<storage, read_write> floats: array<f32, 4>;
@group(0) @binding(1)
var<storage, read_write> ints: array<i32, 4>;
@compute @workgroup_size(1, 1, 1)
fn main() {
let _e4 = floats[1];
floats[0] = sign(_e4);
let _e8 = floats[2];
let _e11 = floats[3];
let v = vec2<f32>(_e8, _e11);
let signs = sign(v);
floats[2] = signs.x;
floats[3] = signs.y;
let _e24 = ints[1];
ints[0] = sign(_e24);
return;
}