From 6d4fa92a86fe5d05dbfa248524cf976ab27f4444 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 20 Apr 2020 16:24:49 -0700 Subject: Fix stdlib definitions of half<->float conversion (#1326) These ended up being additional cases where we needed to use an explicit loop over components in the stdlib in order to produce valid GLSL output, but the existing declarations weren't doing it. I added a very minimal cross-compilation test just to confirm that we generate valid SPIR-V for code using `f16tof32()`. --- tests/cross-compile/half-conversion.slang | 13 ++++++++ tests/cross-compile/half-conversion.slang.glsl | 42 ++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 tests/cross-compile/half-conversion.slang create mode 100644 tests/cross-compile/half-conversion.slang.glsl (limited to 'tests') diff --git a/tests/cross-compile/half-conversion.slang b/tests/cross-compile/half-conversion.slang new file mode 100644 index 000000000..316629f81 --- /dev/null +++ b/tests/cross-compile/half-conversion.slang @@ -0,0 +1,13 @@ +// half-conversion.slang + +//TEST:CROSS_COMPILE:-target spirv-assembly -entry main -stage fragment + +cbuffer C +{ + uint4 u; +} + +float4 main() : SV_Target +{ + return f16tof32(u); +} diff --git a/tests/cross-compile/half-conversion.slang.glsl b/tests/cross-compile/half-conversion.slang.glsl new file mode 100644 index 000000000..3b7b740e4 --- /dev/null +++ b/tests/cross-compile/half-conversion.slang.glsl @@ -0,0 +1,42 @@ +//half-conversion.slang.glsl +//TEST_IGNORE_FILE: + +#version 450 + +struct SLANG_ParameterGroup_C_0 +{ + uvec4 u_0; +}; + +layout(binding = 0) +layout(std140) uniform _S1 +{ + SLANG_ParameterGroup_C_0 _data; +} C_0; + +vec4 f16tof32_0(uvec4 value_0) +{ + int i_0; + vec4 result_0; + i_0 = 0; + for(;;) + { + if(i_0 < 4) {} else break; + + float _S2 = (unpackHalf2x16((value_0[i_0])).x); + result_0[i_0] = _S2; + int _S3 = i_0 + int(1); + i_0 = _S3; + } + return result_0; +} + +layout(location = 0) +out vec4 _S4; + +void main() +{ + vec4 _S5 = f16tof32_0(C_0._data.u_0); + _S4 = _S5; + return; +} -- cgit v1.2.3