|
9 | 9 | #include "openvdb_ax/codegen/FunctionTypes.h" |
10 | 10 | #include "openvdb_ax/codegen/Types.h" |
11 | 11 | #include "openvdb_ax/codegen/Utils.h" |
| 12 | +#include "openvdb_ax/util/x86.h" |
12 | 13 |
|
13 | 14 | namespace openvdb { |
14 | 15 | OPENVDB_USE_VERSION_NAMESPACE |
@@ -324,24 +325,55 @@ const CodecTypeMap& getCodecTypeMap() |
324 | 325 | std::make_unique<Codec>(axprfxpt16encode(), axprfxpt16decode(), 1<<4), |
325 | 326 | }; |
326 | 327 |
|
327 | | - static CodecTypeMap map { |
328 | | - { |
329 | | - ast::tokens::FLOAT, |
330 | | - { |
| 328 | + // If on X86, see if the hardware supports f16c. For other platforms we |
| 329 | + // currently assume hardware support for half/float conversion. This only |
| 330 | + // applies to the truncate codec. |
| 331 | + // @todo Add software support. Will be simpler with AX function support. |
| 332 | + static bool HasF16C = |
| 333 | + ax::x86::CheckX86Feature("f16c") != ax::x86::CpuFlagStatus::Unsupported; |
| 334 | + |
| 335 | + static auto GetFloatCodecs = []() -> CodecNameMap { |
| 336 | + if (HasF16C) { |
| 337 | + return { |
331 | 338 | { points::TruncateCodec::name(), codecs[0].get() }, |
332 | 339 | { points::FixedPointCodec<true, points::UnitRange>::name(), codecs[1].get() }, |
333 | 340 | { points::FixedPointCodec<false, points::UnitRange>::name(), codecs[2].get() } |
334 | | - } |
335 | | - }, |
336 | | - { |
337 | | - ast::tokens::VEC3F, |
338 | | - { |
| 341 | + }; |
| 342 | + } |
| 343 | + else { |
| 344 | + return { |
| 345 | + { points::FixedPointCodec<true, points::UnitRange>::name(), codecs[1].get() }, |
| 346 | + { points::FixedPointCodec<false, points::UnitRange>::name(), codecs[2].get() } |
| 347 | + }; |
| 348 | + } |
| 349 | + }; |
| 350 | + |
| 351 | + static auto GetVectorCodecs = []() -> CodecNameMap { |
| 352 | + if (HasF16C) { |
| 353 | + return { |
339 | 354 | { points::TruncateCodec::name(), codecs[0].get() }, |
340 | 355 | { points::FixedPointCodec<true, points::UnitRange>::name(), codecs[1].get() }, |
341 | 356 | { points::FixedPointCodec<false, points::UnitRange>::name(), codecs[2].get() }, |
342 | 357 | { points::FixedPointCodec<true, points::PositionRange>::name(), codecs[3].get() }, |
343 | 358 | { points::FixedPointCodec<false, points::PositionRange>::name(), codecs[4].get() } |
344 | | - } |
| 359 | + }; |
| 360 | + } |
| 361 | + else { |
| 362 | + return { |
| 363 | + { points::FixedPointCodec<true, points::UnitRange>::name(), codecs[1].get() }, |
| 364 | + { points::FixedPointCodec<false, points::UnitRange>::name(), codecs[2].get() }, |
| 365 | + { points::FixedPointCodec<true, points::PositionRange>::name(), codecs[3].get() }, |
| 366 | + { points::FixedPointCodec<false, points::PositionRange>::name(), codecs[4].get() } |
| 367 | + }; |
| 368 | + } |
| 369 | + }; |
| 370 | + |
| 371 | + static CodecTypeMap map { |
| 372 | + { |
| 373 | + ast::tokens::FLOAT, GetFloatCodecs() |
| 374 | + }, |
| 375 | + { |
| 376 | + ast::tokens::VEC3F, GetVectorCodecs() |
345 | 377 | }, |
346 | 378 | }; |
347 | 379 |
|
|
0 commit comments