Parser: Implement extension GL_AMD_gpu_shader_half_float.
- Add built-in types: float16_t, f16vec, f16mat. - Add support of half float constant: hf, HF. - Extend built-in floating-point operators: +, -, *, /, ++, --, +=, -=, *=, /=, ==, !=, >=, <=, >, <. - Add support of type conversions: float16_t -> XXX, XXX -> float16_t. - Add new built-in functions.
This commit is contained in:
parent
b1672fa0de
commit
c9e3c3c941
35 changed files with 9765 additions and 4370 deletions
|
|
@ -46,6 +46,10 @@
|
|||
|
||||
#include "SpvBuilder.h"
|
||||
|
||||
#ifdef AMD_EXTENSIONS
|
||||
#include "hex_float.h"
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <cstdio>
|
||||
#endif
|
||||
|
|
@ -785,6 +789,36 @@ Id Builder::makeDoubleConstant(double d, bool specConstant)
|
|||
return c->getResultId();
|
||||
}
|
||||
|
||||
#ifdef AMD_EXTENSIONS
|
||||
Id Builder::makeFloat16Constant(float f16, bool specConstant)
|
||||
{
|
||||
Op opcode = specConstant ? OpSpecConstant : OpConstant;
|
||||
Id typeId = makeFloatType(16);
|
||||
|
||||
spvutils::HexFloat<spvutils::FloatProxy<float>> fVal(f16);
|
||||
spvutils::HexFloat<spvutils::FloatProxy<spvutils::Float16>> f16Val(0);
|
||||
fVal.castTo(f16Val, spvutils::round_direction::kToZero);
|
||||
|
||||
unsigned value = f16Val.value().getAsFloat().get_value();
|
||||
|
||||
// See if we already made it. Applies only to regular constants, because specialization constants
|
||||
// must remain distinct for the purpose of applying a SpecId decoration.
|
||||
if (!specConstant) {
|
||||
Id existing = findScalarConstant(OpTypeFloat, opcode, typeId, value);
|
||||
if (existing)
|
||||
return existing;
|
||||
}
|
||||
|
||||
Instruction* c = new Instruction(getUniqueId(), typeId, opcode);
|
||||
c->addImmediateOperand(value);
|
||||
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(c));
|
||||
groupedConstants[OpTypeFloat].push_back(c);
|
||||
module.mapInstruction(c);
|
||||
|
||||
return c->getResultId();
|
||||
}
|
||||
#endif
|
||||
|
||||
Id Builder::findCompositeConstant(Op typeClass, std::vector<Id>& comps) const
|
||||
{
|
||||
Instruction* constant = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue