[naga] Support casting to f64 in the constant evaluator.

This commit is contained in:
Jim Blandy 2023-11-22 10:13:48 -08:00 committed by Teodor Tanasoaia
parent eb92ab2878
commit 86562e69a6
6 changed files with 38 additions and 35 deletions

View File

@ -998,6 +998,14 @@ impl<'a> ConstantEvaluator<'a> {
return Err(ConstantEvaluatorError::InvalidCastArg)
}
}),
Sc::F64 => Literal::F64(match literal {
Literal::I32(v) => v as f64,
Literal::U32(v) => v as f64,
Literal::F32(v) => v as f64,
Literal::Bool(v) => v as u32 as f64,
Literal::F64(v) => v,
Literal::I64(_) => return Err(ConstantEvaluatorError::InvalidCastArg),
}),
Sc::BOOL => Literal::Bool(match literal {
Literal::I32(v) => v != 0,
Literal::U32(v) => v != 0,

View File

@ -8,7 +8,7 @@ const double k = 2.0LF;
double f(double x) {
double z = 0.0;
double y = (30.0LF + 400.0LF);
z = (y + double(5));
z = (y + 5.0LF);
return (((x + y) + k) + 5.0LF);
}

View File

@ -7,7 +7,7 @@ double f(double x)
double z = (double)0;
double y = (30.0L + 400.0L);
z = (y + double(5));
z = (y + 5.0L);
return (((x + y) + k) + 5.0L);
}

View File

@ -1,13 +1,13 @@
; SPIR-V
; Version: 1.0
; Generator: rspirv
; Bound: 33
; Bound: 30
OpCapability Shader
OpCapability Float64
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %28 "main"
OpExecutionMode %28 LocalSize 1 1 1
OpEntryPoint GLCompute %25 "main"
OpExecutionMode %25 LocalSize 1 1 1
%2 = OpTypeVoid
%3 = OpTypeFloat 64
%4 = OpConstant %3 1.0
@ -17,32 +17,29 @@ OpExecutionMode %28 LocalSize 1 1 1
%11 = OpTypeFunction %3 %3
%12 = OpConstant %3 30.0
%13 = OpConstant %3 400.0
%14 = OpTypeInt 32 1
%15 = OpConstant %14 5
%16 = OpConstant %3 5.0
%18 = OpTypePointer Function %3
%19 = OpConstantNull %3
%29 = OpTypeFunction %2
%30 = OpConstant %3 6.0
%14 = OpConstant %3 5.0
%16 = OpTypePointer Function %3
%17 = OpConstantNull %3
%26 = OpTypeFunction %2
%27 = OpConstant %3 6.0
%10 = OpFunction %3 None %11
%9 = OpFunctionParameter %3
%8 = OpLabel
%17 = OpVariable %18 Function %19
OpBranch %20
%20 = OpLabel
%21 = OpFAdd %3 %12 %13
%22 = OpConvertSToF %3 %15
%23 = OpFAdd %3 %21 %22
OpStore %17 %23
%24 = OpFAdd %3 %9 %21
%25 = OpFAdd %3 %24 %5
%26 = OpFAdd %3 %25 %16
OpReturnValue %26
%15 = OpVariable %16 Function %17
OpBranch %18
%18 = OpLabel
%19 = OpFAdd %3 %12 %13
%20 = OpFAdd %3 %19 %14
OpStore %15 %20
%21 = OpFAdd %3 %9 %19
%22 = OpFAdd %3 %21 %5
%23 = OpFAdd %3 %22 %14
OpReturnValue %23
OpFunctionEnd
%28 = OpFunction %2 None %29
%27 = OpLabel
OpBranch %31
%31 = OpLabel
%32 = OpFunctionCall %3 %10 %30
%25 = OpFunction %2 None %26
%24 = OpLabel
OpBranch %28
%28 = OpLabel
%29 = OpFunctionCall %3 %10 %27
OpReturn
OpFunctionEnd

View File

@ -1,6 +1,6 @@
fn main_1() {
var a: vec4<f64>;
var b: vec4<f64>;
var a: vec4<f64> = vec4(1.0lf);
var b: vec4<f64> = vec4(2.0lf);
var m: mat4x4<f64>;
var i: i32 = 5;
var ceilOut: vec4<f64>;
@ -29,8 +29,6 @@ fn main_1() {
var smoothStepVector: vec4<f64>;
var smoothStepMixed: vec4<f64>;
a = vec4(f64(1.0));
b = vec4(f64(2.0));
let _e8 = a;
let _e9 = b;
let _e10 = a;
@ -95,8 +93,8 @@ fn main_1() {
let _e152 = i;
ldexpOut = ldexp(_e150.x, _e152);
smoothStepScalar = f64(smoothstep(0.0, 1.0, 0.5));
smoothStepVector = smoothstep(vec4(f64(0.0)), vec4(f64(1.0)), vec4(f64(0.5)));
smoothStepMixed = smoothstep(vec4(f64(0.0)), vec4(f64(1.0)), vec4(f64(0.5)));
smoothStepVector = smoothstep(vec4(0.0lf), vec4(1.0lf), vec4(0.5lf));
smoothStepMixed = smoothstep(vec4(0.0lf), vec4(1.0lf), vec4(0.5lf));
return;
}

View File

@ -6,7 +6,7 @@ fn f(x: f64) -> f64 {
var z: f64;
let y = (30.0lf + 400.0lf);
z = (y + f64(5));
z = (y + 5.0lf);
return (((x + y) + k) + 5.0lf);
}