Skip to content

Commit e8e57d4

Browse files
committed
[naga] Support casting to f64 in the constant evaluator.
1 parent ea23916 commit e8e57d4

File tree

6 files changed

+38
-35
lines changed

6 files changed

+38
-35
lines changed

naga/src/proc/constant_evaluator.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,14 @@ impl<'a> ConstantEvaluator<'a> {
998998
return Err(ConstantEvaluatorError::InvalidCastArg)
999999
}
10001000
}),
1001+
Sc::F64 => Literal::F64(match literal {
1002+
Literal::I32(v) => v as f64,
1003+
Literal::U32(v) => v as f64,
1004+
Literal::F32(v) => v as f64,
1005+
Literal::Bool(v) => v as u32 as f64,
1006+
Literal::F64(v) => v,
1007+
Literal::I64(_) => return Err(ConstantEvaluatorError::InvalidCastArg),
1008+
}),
10011009
Sc::BOOL => Literal::Bool(match literal {
10021010
Literal::I32(v) => v != 0,
10031011
Literal::U32(v) => v != 0,

naga/tests/out/glsl/f64.main.Compute.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const double k = 2.0LF;
88
double f(double x) {
99
double z = 0.0;
1010
double y = (30.0LF + 400.0LF);
11-
z = (y + double(5));
11+
z = (y + 5.0LF);
1212
return (((x + y) + k) + 5.0LF);
1313
}
1414

naga/tests/out/hlsl/f64.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ double f(double x)
77
double z = (double)0;
88

99
double y = (30.0L + 400.0L);
10-
z = (y + double(5));
10+
z = (y + 5.0L);
1111
return (((x + y) + k) + 5.0L);
1212
}
1313

naga/tests/out/spv/f64.spvasm

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
; SPIR-V
22
; Version: 1.0
33
; Generator: rspirv
4-
; Bound: 33
4+
; Bound: 30
55
OpCapability Shader
66
OpCapability Float64
77
%1 = OpExtInstImport "GLSL.std.450"
88
OpMemoryModel Logical GLSL450
9-
OpEntryPoint GLCompute %28 "main"
10-
OpExecutionMode %28 LocalSize 1 1 1
9+
OpEntryPoint GLCompute %25 "main"
10+
OpExecutionMode %25 LocalSize 1 1 1
1111
%2 = OpTypeVoid
1212
%3 = OpTypeFloat 64
1313
%4 = OpConstant %3 1.0
@@ -17,32 +17,29 @@ OpExecutionMode %28 LocalSize 1 1 1
1717
%11 = OpTypeFunction %3 %3
1818
%12 = OpConstant %3 30.0
1919
%13 = OpConstant %3 400.0
20-
%14 = OpTypeInt 32 1
21-
%15 = OpConstant %14 5
22-
%16 = OpConstant %3 5.0
23-
%18 = OpTypePointer Function %3
24-
%19 = OpConstantNull %3
25-
%29 = OpTypeFunction %2
26-
%30 = OpConstant %3 6.0
20+
%14 = OpConstant %3 5.0
21+
%16 = OpTypePointer Function %3
22+
%17 = OpConstantNull %3
23+
%26 = OpTypeFunction %2
24+
%27 = OpConstant %3 6.0
2725
%10 = OpFunction %3 None %11
2826
%9 = OpFunctionParameter %3
2927
%8 = OpLabel
30-
%17 = OpVariable %18 Function %19
31-
OpBranch %20
32-
%20 = OpLabel
33-
%21 = OpFAdd %3 %12 %13
34-
%22 = OpConvertSToF %3 %15
35-
%23 = OpFAdd %3 %21 %22
36-
OpStore %17 %23
37-
%24 = OpFAdd %3 %9 %21
38-
%25 = OpFAdd %3 %24 %5
39-
%26 = OpFAdd %3 %25 %16
40-
OpReturnValue %26
28+
%15 = OpVariable %16 Function %17
29+
OpBranch %18
30+
%18 = OpLabel
31+
%19 = OpFAdd %3 %12 %13
32+
%20 = OpFAdd %3 %19 %14
33+
OpStore %15 %20
34+
%21 = OpFAdd %3 %9 %19
35+
%22 = OpFAdd %3 %21 %5
36+
%23 = OpFAdd %3 %22 %14
37+
OpReturnValue %23
4138
OpFunctionEnd
42-
%28 = OpFunction %2 None %29
43-
%27 = OpLabel
44-
OpBranch %31
45-
%31 = OpLabel
46-
%32 = OpFunctionCall %3 %10 %30
39+
%25 = OpFunction %2 None %26
40+
%24 = OpLabel
41+
OpBranch %28
42+
%28 = OpLabel
43+
%29 = OpFunctionCall %3 %10 %27
4744
OpReturn
4845
OpFunctionEnd

naga/tests/out/wgsl/double-math-functions.frag.wgsl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn main_1() {
2-
var a: vec4<f64>;
3-
var b: vec4<f64>;
2+
var a: vec4<f64> = vec4(1.0lf);
3+
var b: vec4<f64> = vec4(2.0lf);
44
var m: mat4x4<f64>;
55
var i: i32 = 5;
66
var ceilOut: vec4<f64>;
@@ -29,8 +29,6 @@ fn main_1() {
2929
var smoothStepVector: vec4<f64>;
3030
var smoothStepMixed: vec4<f64>;
3131

32-
a = vec4(f64(1.0));
33-
b = vec4(f64(2.0));
3432
let _e8 = a;
3533
let _e9 = b;
3634
let _e10 = a;
@@ -95,8 +93,8 @@ fn main_1() {
9593
let _e152 = i;
9694
ldexpOut = ldexp(_e150.x, _e152);
9795
smoothStepScalar = f64(smoothstep(0.0, 1.0, 0.5));
98-
smoothStepVector = smoothstep(vec4(f64(0.0)), vec4(f64(1.0)), vec4(f64(0.5)));
99-
smoothStepMixed = smoothstep(vec4(f64(0.0)), vec4(f64(1.0)), vec4(f64(0.5)));
96+
smoothStepVector = smoothstep(vec4(0.0lf), vec4(1.0lf), vec4(0.5lf));
97+
smoothStepMixed = smoothstep(vec4(0.0lf), vec4(1.0lf), vec4(0.5lf));
10098
return;
10199
}
102100

naga/tests/out/wgsl/f64.wgsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn f(x: f64) -> f64 {
66
var z: f64;
77

88
let y = (30.0lf + 400.0lf);
9-
z = (y + f64(5));
9+
z = (y + 5.0lf);
1010
return (((x + y) + k) + 5.0lf);
1111
}
1212

0 commit comments

Comments
 (0)