From 99a38c7b7cb09235dde702aaba44dabec20dbd1c Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Thu, 14 Dec 2023 10:41:35 -0500 Subject: [PATCH] feat(const_eval): impl. `sin` --- CHANGELOG.md | 1 + naga/src/proc/constant_evaluator.rs | 3 + .../tests/out/spv/debug-symbol-terrain.spvasm | 64 +++++++++---------- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c033e572f..587c7c9e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ Bottom level categories: - `abs` - `round` - `saturate` + - `sin` ## v0.19.0 (2024-01-17) diff --git a/naga/src/proc/constant_evaluator.rs b/naga/src/proc/constant_evaluator.rs index e89c1dd2c..33002d5c4 100644 --- a/naga/src/proc/constant_evaluator.rs +++ b/naga/src/proc/constant_evaluator.rs @@ -850,6 +850,9 @@ impl<'a> ConstantEvaluator<'a> { crate::MathFunction::Saturate => { component_wise_float!(self, span, [arg], |e| { Ok([e.clamp(0., 1.)]) }) } + crate::MathFunction::Sin => { + component_wise_float!(self, span, [arg], |e| { Ok([e.sin()]) }) + } fun => Err(ConstantEvaluatorError::NotImplemented(format!( "{fun:?} built-in function" ))), diff --git a/naga/tests/out/spv/debug-symbol-terrain.spvasm b/naga/tests/out/spv/debug-symbol-terrain.spvasm index 623b8dc2c..a818ee6fe 100644 --- a/naga/tests/out/spv/debug-symbol-terrain.spvasm +++ b/naga/tests/out/spv/debug-symbol-terrain.spvasm @@ -366,10 +366,10 @@ OpName %91 "x12" OpName %94 "m" OpName %203 "p" OpName %204 "fbm" -OpName %209 "x" -OpName %211 "v" -OpName %213 "a" -OpName %214 "i" +OpName %210 "x" +OpName %212 "v" +OpName %214 "a" +OpName %215 "i" OpName %255 "p" OpName %256 "min_max_height" OpName %257 "terrain_point" @@ -575,9 +575,10 @@ OpDecorate %582 Location 0 %206 = OpConstant %5 0.01 %207 = OpConstant %5 100.0 %208 = OpConstantComposite %6 %207 %207 -%210 = OpConstantNull %6 -%212 = OpTypePointer Function %5 -%215 = OpTypePointer Function %8 +%209 = OpConstant %5 0.47942555 +%211 = OpConstantNull %6 +%213 = OpTypePointer Function %5 +%216 = OpTypePointer Function %8 %258 = OpTypeFunction %4 %6 %6 %271 = OpTypeFunction %14 %6 %6 %272 = OpConstant %5 0.1 @@ -835,22 +836,21 @@ OpFunctionEnd %204 = OpFunction %5 None %68 %203 = OpFunctionParameter %6 %202 = OpLabel -%211 = OpVariable %212 Function %74 -%214 = OpVariable %215 Function %135 -%209 = OpVariable %87 Function %210 -%213 = OpVariable %212 Function %78 -OpBranch %216 -%216 = OpLabel +%212 = OpVariable %213 Function %74 +%215 = OpVariable %216 Function %135 +%210 = OpVariable %87 Function %211 +%214 = OpVariable %213 Function %78 +OpBranch %217 +%217 = OpLabel OpLine %3 36 13 -%217 = OpVectorTimesScalar %6 %203 %206 +%218 = OpVectorTimesScalar %6 %203 %206 OpLine %3 36 5 -OpStore %209 %217 +OpStore %210 %218 OpLine %3 39 17 OpLine %3 40 24 -%218 = OpExtInst %5 %1 Cos %78 +%219 = OpExtInst %5 %1 Cos %78 OpLine %3 40 14 -%219 = OpExtInst %5 %1 Sin %78 -%220 = OpCompositeConstruct %6 %218 %219 +%220 = OpCompositeConstruct %6 %219 %209 OpLine %3 41 15 %221 = OpCompositeExtract %5 %220 0 %222 = OpCompositeExtract %5 %220 1 @@ -867,7 +867,7 @@ OpLoopMerge %230 %232 None OpBranch %231 %231 = OpLabel OpLine %3 43 22 -%233 = OpLoad %8 %214 +%233 = OpLoad %8 %215 %234 = OpULessThan %112 %233 %205 OpLine %3 43 21 OpSelectionMerge %235 None @@ -878,44 +878,44 @@ OpBranch %230 OpBranch %237 %237 = OpLabel OpLine %3 1 1 -%239 = OpLoad %5 %211 -%240 = OpLoad %5 %213 -%241 = OpLoad %6 %209 +%239 = OpLoad %5 %212 +%240 = OpLoad %5 %214 +%241 = OpLoad %6 %210 OpLine %3 44 21 %242 = OpFunctionCall %5 %67 %241 OpLine %3 44 13 %243 = OpFMul %5 %240 %242 %244 = OpFAdd %5 %239 %243 OpLine %3 44 9 -OpStore %211 %244 +OpStore %212 %244 OpLine %3 45 13 -%245 = OpLoad %6 %209 +%245 = OpLoad %6 %210 %246 = OpMatrixTimesVector %6 %228 %245 OpLine %3 45 13 %247 = OpVectorTimesScalar %6 %246 %81 %248 = OpFAdd %6 %247 %208 OpLine %3 45 9 -OpStore %209 %248 +OpStore %210 %248 OpLine %3 1 1 -%249 = OpLoad %5 %213 +%249 = OpLoad %5 %214 OpLine %3 46 13 %250 = OpFMul %5 %249 %78 OpLine %3 46 9 -OpStore %213 %250 +OpStore %214 %250 OpBranch %238 %238 = OpLabel OpBranch %232 %232 = OpLabel OpLine %3 1 1 -%251 = OpLoad %8 %214 +%251 = OpLoad %8 %215 OpLine %3 43 43 %252 = OpIAdd %8 %251 %126 OpLine %3 43 39 -OpStore %214 %252 +OpStore %215 %252 OpBranch %229 %230 = OpLabel OpLine %3 1 1 -%253 = OpLoad %5 %211 +%253 = OpLoad %5 %212 OpReturnValue %253 OpFunctionEnd %257 = OpFunction %4 None %258 @@ -1193,8 +1193,8 @@ OpReturn OpFunctionEnd %465 = OpFunction %2 None %346 %453 = OpLabel -%468 = OpVariable %212 Function %74 -%469 = OpVariable %215 Function %135 +%468 = OpVariable %213 Function %74 +%469 = OpVariable %216 Function %135 %456 = OpLoad %8 %455 %459 = OpLoad %7 %457 %462 = OpLoad %6 %460