mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-17 20:13:31 +00:00
tint: HLSL and GLSL backends now emit 0 for inf and nan
Bug: tint:1581 Change-Id: I62dcde177c3b82408cd8d737526d10d481b48a17 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/101240 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
parent
1741f4443e
commit
679cf4f351
@ -150,25 +150,22 @@ const char* convert_texel_format_to_glsl(const ast::TexelFormat format) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PrintF32(std::ostream& out, float value) {
|
void PrintF32(std::ostream& out, float value) {
|
||||||
// Note: Currently inf and nan should not be constructable, but this is implemented for the day
|
|
||||||
// we support them.
|
|
||||||
if (std::isinf(value)) {
|
if (std::isinf(value)) {
|
||||||
out << (value >= 0 ? "uintBitsToFloat(0x7f800000u)" : "uintBitsToFloat(0xff800000u)");
|
out << "0.0f " << (value >= 0 ? "/* inf */" : "/* -inf */");
|
||||||
} else if (std::isnan(value)) {
|
} else if (std::isnan(value)) {
|
||||||
out << "uintBitsToFloat(0x7fc00000u)";
|
out << "0.0f /* nan */";
|
||||||
} else {
|
} else {
|
||||||
out << FloatToString(value) << "f";
|
out << FloatToString(value) << "f";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PrintF16(std::ostream& out, float value) {
|
void PrintF16(std::ostream& out, float value) {
|
||||||
// Note: Currently inf and nan should not be constructable, and there is no solid way to
|
if (std::isinf(value)) {
|
||||||
// generate constant/literal f16 Inf or NaN.
|
out << "0.0hf " << (value >= 0 ? "/* inf */" : "/* -inf */");
|
||||||
if (std::isinf(value) || std::isnan(value)) {
|
} else if (std::isnan(value)) {
|
||||||
return false;
|
out << "0.0hf /* nan */";
|
||||||
} else {
|
} else {
|
||||||
out << FloatToString(value) << "hf";
|
out << FloatToString(value) << "hf";
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2185,7 +2182,10 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, const sem::Constant* constan
|
|||||||
PrintF32(out, constant->As<float>());
|
PrintF32(out, constant->As<float>());
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
[&](const sem::F16*) { return PrintF16(out, constant->As<float>()); },
|
[&](const sem::F16*) {
|
||||||
|
PrintF16(out, constant->As<float>());
|
||||||
|
return true;
|
||||||
|
},
|
||||||
[&](const sem::I32*) {
|
[&](const sem::I32*) {
|
||||||
out << constant->As<AInt>();
|
out << constant->As<AInt>();
|
||||||
return true;
|
return true;
|
||||||
@ -2285,9 +2285,10 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::LiteralExpression*
|
|||||||
},
|
},
|
||||||
[&](const ast::FloatLiteralExpression* l) {
|
[&](const ast::FloatLiteralExpression* l) {
|
||||||
if (l->suffix == ast::FloatLiteralExpression::Suffix::kH) {
|
if (l->suffix == ast::FloatLiteralExpression::Suffix::kH) {
|
||||||
return PrintF16(out, static_cast<float>(l->value));
|
PrintF16(out, static_cast<float>(l->value));
|
||||||
|
} else {
|
||||||
|
PrintF32(out, static_cast<float>(l->value));
|
||||||
}
|
}
|
||||||
PrintF32(out, static_cast<float>(l->value));
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
[&](const ast::IntLiteralExpression* l) {
|
[&](const ast::IntLiteralExpression* l) {
|
||||||
|
@ -112,24 +112,22 @@ const char* image_format_to_rwtexture_type(ast::TexelFormat image_format) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PrintF32(std::ostream& out, float value) {
|
void PrintF32(std::ostream& out, float value) {
|
||||||
// Note: Currently inf and nan should not be constructable, but this is implemented for the day
|
|
||||||
// we support them.
|
|
||||||
if (std::isinf(value)) {
|
if (std::isinf(value)) {
|
||||||
out << (value >= 0 ? "asfloat(0x7f800000u)" : "asfloat(0xff800000u)");
|
out << "0.0f " << (value >= 0 ? "/* inf */" : "/* -inf */");
|
||||||
} else if (std::isnan(value)) {
|
} else if (std::isnan(value)) {
|
||||||
out << "asfloat(0x7fc00000u)";
|
out << "0.0f /* nan */";
|
||||||
} else {
|
} else {
|
||||||
out << FloatToString(value) << "f";
|
out << FloatToString(value) << "f";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PrintF16(std::ostream& out, float value) {
|
void PrintF16(std::ostream& out, float value) {
|
||||||
// Note: Currently inf and nan should not be constructable, don't emit them.
|
if (std::isinf(value)) {
|
||||||
if (std::isinf(value) || std::isnan(value)) {
|
out << "0.0h " << (value >= 0 ? "/* inf */" : "/* -inf */");
|
||||||
return false;
|
} else if (std::isnan(value)) {
|
||||||
|
out << "0.0h /* nan */";
|
||||||
} else {
|
} else {
|
||||||
out << FloatToString(value) << "h";
|
out << FloatToString(value) << "h";
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3127,9 +3125,9 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, const sem::Constant* constan
|
|||||||
[&](const sem::F16*) {
|
[&](const sem::F16*) {
|
||||||
// emit a f16 scalar with explicit float16_t type declaration.
|
// emit a f16 scalar with explicit float16_t type declaration.
|
||||||
out << "float16_t(";
|
out << "float16_t(";
|
||||||
bool valid = PrintF16(out, constant->As<float>());
|
PrintF16(out, constant->As<float>());
|
||||||
out << ")";
|
out << ")";
|
||||||
return valid;
|
return true;
|
||||||
},
|
},
|
||||||
[&](const sem::I32*) {
|
[&](const sem::I32*) {
|
||||||
out << constant->As<AInt>();
|
out << constant->As<AInt>();
|
||||||
@ -3254,9 +3252,8 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::LiteralExpression*
|
|||||||
if (l->suffix == ast::FloatLiteralExpression::Suffix::kH) {
|
if (l->suffix == ast::FloatLiteralExpression::Suffix::kH) {
|
||||||
// Emit f16 literal with explicit float16_t type declaration.
|
// Emit f16 literal with explicit float16_t type declaration.
|
||||||
out << "float16_t(";
|
out << "float16_t(";
|
||||||
bool valid = PrintF16(out, static_cast<float>(l->value));
|
PrintF16(out, static_cast<float>(l->value));
|
||||||
out << ")";
|
out << ")";
|
||||||
return valid;
|
|
||||||
}
|
}
|
||||||
PrintF32(out, static_cast<float>(l->value));
|
PrintF32(out, static_cast<float>(l->value));
|
||||||
return true;
|
return true;
|
||||||
|
@ -14,7 +14,7 @@ float getAAtOutCoords_() {
|
|||||||
float unaryOperation_f1_(inout float a) {
|
float unaryOperation_f1_(inout float a) {
|
||||||
const float x_47 = a;
|
const float x_47 = a;
|
||||||
if ((x_47 < 0.0f)) {
|
if ((x_47 < 0.0f)) {
|
||||||
return asfloat(0x7f800000u);
|
return 0.0f /* inf */;
|
||||||
}
|
}
|
||||||
const float x_55 = a;
|
const float x_55 = a;
|
||||||
return log(x_55);
|
return log(x_55);
|
||||||
|
@ -14,7 +14,7 @@ float getAAtOutCoords_() {
|
|||||||
float unaryOperation_f1_(inout float a) {
|
float unaryOperation_f1_(inout float a) {
|
||||||
const float x_47 = a;
|
const float x_47 = a;
|
||||||
if ((x_47 < 0.0f)) {
|
if ((x_47 < 0.0f)) {
|
||||||
return asfloat(0x7f800000u);
|
return 0.0f /* inf */;
|
||||||
}
|
}
|
||||||
const float x_55 = a;
|
const float x_55 = a;
|
||||||
return log(x_55);
|
return log(x_55);
|
||||||
|
@ -26,7 +26,7 @@ float getAAtOutCoords_() {
|
|||||||
float unaryOperation_f1_(inout float a) {
|
float unaryOperation_f1_(inout float a) {
|
||||||
float x_47 = a;
|
float x_47 = a;
|
||||||
if ((x_47 < 0.0f)) {
|
if ((x_47 < 0.0f)) {
|
||||||
return uintBitsToFloat(0x7f800000u);
|
return 0.0f /* inf */;
|
||||||
}
|
}
|
||||||
float x_55 = a;
|
float x_55 = a;
|
||||||
return log(x_55);
|
return log(x_55);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
static float4 out_var_SV_TARGET = float4(0.0f, 0.0f, 0.0f, 0.0f);
|
static float4 out_var_SV_TARGET = float4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
void main_1() {
|
void main_1() {
|
||||||
out_var_SV_TARGET = (asfloat(0xff800000u)).xxxx;
|
out_var_SV_TARGET = (0.0f /* -inf */).xxxx;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
static float4 out_var_SV_TARGET = float4(0.0f, 0.0f, 0.0f, 0.0f);
|
static float4 out_var_SV_TARGET = float4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
void main_1() {
|
void main_1() {
|
||||||
out_var_SV_TARGET = (asfloat(0xff800000u)).xxxx;
|
out_var_SV_TARGET = (0.0f /* -inf */).xxxx;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ precision mediump float;
|
|||||||
layout(location = 0) out vec4 out_var_SV_TARGET_1_1;
|
layout(location = 0) out vec4 out_var_SV_TARGET_1_1;
|
||||||
vec4 out_var_SV_TARGET = vec4(0.0f, 0.0f, 0.0f, 0.0f);
|
vec4 out_var_SV_TARGET = vec4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
void main_1() {
|
void main_1() {
|
||||||
out_var_SV_TARGET = vec4(uintBitsToFloat(0xff800000u));
|
out_var_SV_TARGET = vec4(0.0f /* -inf */);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
static float4 out_var_SV_TARGET = float4(0.0f, 0.0f, 0.0f, 0.0f);
|
static float4 out_var_SV_TARGET = float4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
void main_1() {
|
void main_1() {
|
||||||
out_var_SV_TARGET = (asfloat(0x7f800000u)).xxxx;
|
out_var_SV_TARGET = (0.0f /* inf */).xxxx;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
static float4 out_var_SV_TARGET = float4(0.0f, 0.0f, 0.0f, 0.0f);
|
static float4 out_var_SV_TARGET = float4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
void main_1() {
|
void main_1() {
|
||||||
out_var_SV_TARGET = (asfloat(0x7f800000u)).xxxx;
|
out_var_SV_TARGET = (0.0f /* inf */).xxxx;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ precision mediump float;
|
|||||||
layout(location = 0) out vec4 out_var_SV_TARGET_1_1;
|
layout(location = 0) out vec4 out_var_SV_TARGET_1_1;
|
||||||
vec4 out_var_SV_TARGET = vec4(0.0f, 0.0f, 0.0f, 0.0f);
|
vec4 out_var_SV_TARGET = vec4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
void main_1() {
|
void main_1() {
|
||||||
out_var_SV_TARGET = vec4(uintBitsToFloat(0x7f800000u));
|
out_var_SV_TARGET = vec4(0.0f /* inf */);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
static float4 out_var_SV_TARGET = float4(0.0f, 0.0f, 0.0f, 0.0f);
|
static float4 out_var_SV_TARGET = float4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
void main_1() {
|
void main_1() {
|
||||||
out_var_SV_TARGET = float4(asfloat(0x7fc00000u), asfloat(0x7fc00000u), asfloat(0x7fc00000u), asfloat(0x7fc00000u));
|
out_var_SV_TARGET = float4(0.0f /* nan */, 0.0f /* nan */, 0.0f /* nan */, 0.0f /* nan */);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
static float4 out_var_SV_TARGET = float4(0.0f, 0.0f, 0.0f, 0.0f);
|
static float4 out_var_SV_TARGET = float4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
void main_1() {
|
void main_1() {
|
||||||
out_var_SV_TARGET = float4(asfloat(0x7fc00000u), asfloat(0x7fc00000u), asfloat(0x7fc00000u), asfloat(0x7fc00000u));
|
out_var_SV_TARGET = float4(0.0f /* nan */, 0.0f /* nan */, 0.0f /* nan */, 0.0f /* nan */);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ precision mediump float;
|
|||||||
layout(location = 0) out vec4 out_var_SV_TARGET_1_1;
|
layout(location = 0) out vec4 out_var_SV_TARGET_1_1;
|
||||||
vec4 out_var_SV_TARGET = vec4(0.0f, 0.0f, 0.0f, 0.0f);
|
vec4 out_var_SV_TARGET = vec4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
void main_1() {
|
void main_1() {
|
||||||
out_var_SV_TARGET = vec4(uintBitsToFloat(0x7fc00000u), uintBitsToFloat(0x7fc00000u), uintBitsToFloat(0x7fc00000u), uintBitsToFloat(0x7fc00000u));
|
out_var_SV_TARGET = vec4(0.0f /* nan */, 0.0f /* nan */, 0.0f /* nan */, 0.0f /* nan */);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user