Commit e148f3d3 by Geoff Lang

Fix lots of compilation errors in generated GLSL functions.

Reformatted to improve readability. BUG=angleproject:angleproject:947 Change-Id: I467f0396a0318b7a51d5cafce3f11e55d929c369 Reviewed-on: https://chromium-review.googlesource.com/278250Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 7b9b284b
......@@ -47,17 +47,21 @@ void InitBuiltInFunctionEmulatorForGLSLMissingFunctions(BuiltInFunctionEmulator
TType *uint1 = new TType(EbtUInt);
emu->addEmulatedFunction(EOpPackSnorm2x16, float2,
"uint webgl_packSnorm2x16_emu(vec2 v){\n"
"uint webgl_packSnorm2x16_emu(vec2 v)\n"
"{\n"
" int x = int(round(clamp(v.x, -1.0, 1.0) * 32767.0));\n"
" int y = int(round(clamp(v.y, -1.0, 1.0) * 32767.0));\n"
" return uint((y << 16) | (x & 0xffff));\n"
" return uint((y << 16) | (x & 0xFFFF));\n"
"}\n");
emu->addEmulatedFunction(EOpUnpackSnorm2x16, uint1,
"float webgl_fromSnorm(uint x){\n"
" int xi = (int(x) & 0x7fff) - (int(x) & 0x8000);\n"
"float webgl_fromSnorm(uint x)\n"
"{\n"
" int xi = (int(x) & 0x7FFF) - (int(x) & 0x8000);\n"
" return clamp(float(xi) / 32767.0, -1.0, 1.0);\n"
"}\n"
"vec2 webgl_unpackSnorm2x16_emu(uint u){\n"
"\n"
"vec2 webgl_unpackSnorm2x16_emu(uint u)\n"
"{\n"
" uint y = (u >> 16);\n"
" uint x = u;\n"
" return vec2(webgl_fromSnorm(x), webgl_fromSnorm(y));\n"
......@@ -65,47 +69,93 @@ void InitBuiltInFunctionEmulatorForGLSLMissingFunctions(BuiltInFunctionEmulator
// Functions uint webgl_f32tof16(float val) and float webgl_f16tof32(uint val) are
// based on the OpenGL redbook Appendix Session "Floating-Point Formats Used in OpenGL".
emu->addEmulatedFunction(EOpPackHalf2x16, float2,
"uint webgl_f32tof16(float val){\n"
" uint f32 = floatBitsToInt(val);\n"
" uint f16 = 0;\n"
"uint webgl_f32tof16(float val)\n"
"{\n"
" uint f32 = floatBitsToUint(val);\n"
" uint f16 = 0u;\n"
" uint sign = (f32 >> 16) & 0x8000u;\n"
" int exponent = int((f32 >> 23) & 0xff) - 127;\n"
" uint mantissa = f32 & 0x007fffffu;\n"
" if (exponent == 128) { /* Infinity or NaN */\n"
" // NaN bits that are masked out by 0x3ff get discarded. This can turn some NaNs to infinity, but this is allowed by the spec.\n"
" f16 = sign | (0x1F << 10); f16 |= (mantissa & 0x3ff);\n"
" int exponent = int((f32 >> 23) & 0xFFu) - 127;\n"
" uint mantissa = f32 & 0x007FFFFFu;\n"
" if (exponent == 128)\n"
" {\n"
" // Infinity or NaN\n"
" // NaN bits that are masked out by 0x3FF get discarded.\n"
" // This can turn some NaNs to infinity, but this is allowed by the spec.\n"
" f16 = sign | (0x1Fu << 10);\n"
" f16 |= (mantissa & 0x3FFu);\n"
" }\n"
" else if (exponent > 15)\n"
" {\n"
" // Overflow - flush to Infinity\n"
" f16 = sign | (0x1Fu << 10);\n"
" }\n"
" else if (exponent > -15)\n"
" {\n"
" // Representable value\n"
" exponent += 15;\n"
" mantissa >>= 13;\n"
" f16 = sign | uint(exponent << 10) | mantissa;\n"
" }\n"
" else\n"
" {\n"
" f16 = sign;\n"
" }\n"
" else if (exponent > 15) { /* Overflow - flush to Infinity */ f16 = sign | (0x1F << 10); }\n"
" else if (exponent > -15) { /* Representable value */ exponent += 15; mantissa >>= 13; f16 = sign | exponent << 10 | mantissa; }\n"
" else { f16 = sign; }\n"
" return f16;\n"
"}\n"
"uint webgl_packHalf2x16_emu(vec2 v){\n"
"\n"
"uint webgl_packHalf2x16_emu(vec2 v)\n"
"{\n"
" uint x = webgl_f32tof16(v.x);\n"
" uint y = webgl_f32tof16(v.y);\n"
" return (y << 16) | x;\n"
"}\n");
emu->addEmulatedFunction(EOpUnpackHalf2x16, uint1,
"float webgl_f16tof32(uint val){\n"
"float webgl_f16tof32(uint val)\n"
"{\n"
" uint sign = (val & 0x8000u) << 16;\n"
" int exponent = int((val & 0x7c00) >> 10);\n"
" uint mantissa = val & 0x03ffu;\n"
" int exponent = int((val & 0x7C00u) >> 10);\n"
" uint mantissa = val & 0x03FFu;\n"
" float f32 = 0.0;\n"
" if(exponent == 0) { if (mantissa != 0) { const float scale = 1.0 / (1 << 24); f32 = scale * mantissa; } }\n"
" else if (exponent == 31) { return uintBitsToFloat(sign | 0x7f800000 | mantissa); }\n"
" else{\n"
" float scale, decimal; exponent -= 15;\n"
" if(exponent < 0) { scale = 1.0 / (1 << -exponent); }\n"
" else { scale = 1 << exponent; }\n"
" decimal = 1.0 + float(mantissa) / float(1 << 10);\n"
" f32 = scale * decimal;\n"
" if(exponent == 0)\n"
" {\n"
" if (mantissa != 0u)\n"
" {\n"
" const float scale = 1.0 / (1 << 24);\n"
" f32 = scale * mantissa;\n"
" }\n"
" if (sign != 0) f32 = -f32;\n"
" }\n"
" else if (exponent == 31)\n"
" {\n"
" return uintBitsToFloat(sign | 0x7F800000u | mantissa);\n"
" }\n"
" else\n"
" {\n"
" exponent -= 15;\n"
" float scale;\n"
" if(exponent < 0)\n"
" {\n"
" scale = 1.0 / (1 << -exponent);\n"
" }\n"
" else\n"
" {\n"
" scale = 1 << exponent;\n"
" }\n"
" float decimal = 1.0 + float(mantissa) / float(1 << 10);\n"
" f32 = scale * decimal;\n"
" }\n"
"\n"
" if (sign != 0u)\n"
" {\n"
" f32 = -f32;\n"
" }\n"
"\n"
" return f32;\n"
"}\n"
"vec2 webgl_unpackHalf2x16_emu(uint u){\n"
"\n"
"vec2 webgl_unpackHalf2x16_emu(uint u)\n"
"{\n"
" uint y = (u >> 16);\n"
" uint x = u & 0xffffu;\n"
" uint x = u & 0xFFFFu;\n"
" return vec2(webgl_f16tof32(x), webgl_f16tof32(y));\n"
"}\n");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment