Reputation: 366
I am writing a Spir-v processor, which is intended to create a new OpTypeFloat
with a width of 16 bits and then change the result type ids of the existing OpConstants
to the result id of the created, new OpTypeFloat
. Practically, I want to change fp32 variables to fp16.
Here is the code snippet, which deals with this.
ir.for_each_typed_id<spirv_cross::SPIRConstant>([&](uint32_t id, spirv_cross::SPIRConstant& constant) {
auto type = compiler.get_type(constant.constant_type);
if (type.op != spv::OpTypeFloat || type.width != 32) {
return;
}
auto instruction = constant_id_to_instruction_mapping[id];
data[instruction.offset] = newtypeid;
});
To print out the spir-v, I am using this code:
spv_text text = nullptr;
spv_diagnostic diagnostic = nullptr;
spvBinaryToText(spvContextCreate(SPV_ENV_UNIVERSAL_1_0), data, bytecode.size(), SPV_BINARY_TO_TEXT_OPTION_INDENT, &text, &diagnostic);
printf("%s", text->str);
spvTextDestroy(text);
This is from the original Spir-V:
%10 = OpTypeFloat 16
%9 = OpConstant %6 0.5
This is after the processing:
%10 = OpTypeFloat 16
%9 = OpConstant %10 0x0p+0
As you can see after the code, I got 0x0p+0
for the literal value, not 0.5 like previously. Btw, if I print out the value from console, I got the right number.
So, What causes the problem? I bet that, spvBinaryToText
method interprets things differently, in case of changing the result type id of the OpConstant
.
Upvotes: 0
Views: 11