Skip to content

Commit 1cc6a20

Browse files
3D Blit test case was failing because of unimplemented functions for the R11G11B10_UFLOAT format, but there are still errors
1 parent 6dca57a commit 1cc6a20

File tree

3 files changed

+54
-40
lines changed

3 files changed

+54
-40
lines changed

include/nbl/asset/format/EFormat.h

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,18 +1762,28 @@ inline value_type getFormatMaxValue(E_FORMAT format, uint32_t channel)
17621762
{
17631763
switch (format)
17641764
{
1765-
case EF_BC6H_SFLOAT_BLOCK: return 32767;
1766-
case EF_BC6H_UFLOAT_BLOCK: return 65504;
1767-
default: break;
1765+
case EF_B10G11R11_UFLOAT_PACK32:
1766+
if (channel<=1)
1767+
return 65520;
1768+
else if (channel==2)
1769+
return 65504;
1770+
break;
1771+
case EF_E5B9G9R9_UFLOAT_PACK32:
1772+
if (channel<3)
1773+
return 32704;
1774+
break;
1775+
case EF_BC6H_SFLOAT_BLOCK: return 32767;
1776+
case EF_BC6H_UFLOAT_BLOCK: return 65504;
1777+
default: break;
17681778
}
17691779

17701780
auto bytesPerChannel = (getBytesPerPixel(format)*core::rational(1,getFormatChannelCount(format))).getIntegerApprox();
17711781
switch (bytesPerChannel)
17721782
{
1773-
case 2u: return 65504;
1774-
case 4u: return FLT_MAX;
1775-
case 8u: return DBL_MAX;
1776-
default: break;
1783+
case 2u: return 65504;
1784+
case 4u: return FLT_MAX;
1785+
case 8u: return DBL_MAX;
1786+
default: break;
17771787
}
17781788
}
17791789
return 0;
@@ -1882,44 +1892,47 @@ inline value_type getFormatPrecision(E_FORMAT format, uint32_t channel, value_ty
18821892
else if (isFloatingPointFormat(format))
18831893
{
18841894
switch (format)
1885-
{
1886-
case EF_B10G11R11_UFLOAT_PACK32:
18871895
{
18881896
// unsigned values are always ordered as + 1
1889-
float f = std::abs(static_cast<float>(value));
1890-
int bitshft = channel == 2u ? 6 : 5;
1891-
1892-
uint16_t f16 = core::Float16Compressor::compress(f);
1893-
uint16_t enc = f16 >> bitshft;
1894-
uint16_t next_f16 = (enc + 1) << bitshft;
1895-
1896-
return core::Float16Compressor::decompress(next_f16) - f;
1897-
}
1898-
case EF_E5B9G9R9_UFLOAT_PACK32:
1899-
return 0; //TODO
1900-
default: break;
1897+
case EF_B10G11R11_UFLOAT_PACK32: [[fallthrough]];
1898+
case EF_E5B9G9R9_UFLOAT_PACK32: // TODO: probably need to change signature and take all values?
1899+
{
1900+
float f = std::abs(static_cast<float>(value));
1901+
int bitshift;
1902+
if (format==EF_B10G11R11_UFLOAT_PACK32)
1903+
bitshift = channel==2u ? 6:5;
1904+
else
1905+
bitshift = 4;
1906+
1907+
uint16_t f16 = core::Float16Compressor::compress(f);
1908+
uint16_t enc = f16 >> bitshift;
1909+
uint16_t next_f16 = (enc + 1) << bitshift;
1910+
1911+
return core::Float16Compressor::decompress(next_f16) - f;
1912+
}
1913+
default: break;
19011914
}
19021915
auto bytesPerChannel = (getBytesPerPixel(format)*core::rational(1,getFormatChannelCount(format))).getIntegerApprox();
19031916
switch (bytesPerChannel)
19041917
{
1905-
case 2u:
1906-
{
1907-
float f = std::abs(static_cast<float>(value));
1908-
uint16_t f16 = core::Float16Compressor::compress(f);
1909-
uint16_t dir = core::Float16Compressor::compress(2.f*(f+1.f));
1910-
return core::Float16Compressor::decompress( core::nextafter16(f16, dir) ) - f;
1911-
}
1912-
case 4u:
1913-
{
1914-
float f32 = std::abs(static_cast<float>(value));
1915-
return core::nextafter32(f32,2.f*(f32+1.f))-f32;
1916-
}
1917-
case 8u:
1918-
{
1919-
double f64 = std::abs(static_cast<double>(value));
1920-
return core::nextafter64(f64,2.0*(f64+1.0))-f64;
1921-
}
1922-
default: break;
1918+
case 2u:
1919+
{
1920+
float f = std::abs(static_cast<float>(value));
1921+
uint16_t f16 = core::Float16Compressor::compress(f);
1922+
uint16_t dir = core::Float16Compressor::compress(2.f*(f+1.f));
1923+
return core::Float16Compressor::decompress( core::nextafter16(f16, dir) ) - f;
1924+
}
1925+
case 4u:
1926+
{
1927+
float f32 = std::abs(static_cast<float>(value));
1928+
return core::nextafter32(f32,2.f*(f32+1.f))-f32;
1929+
}
1930+
case 8u:
1931+
{
1932+
double f64 = std::abs(static_cast<double>(value));
1933+
return core::nextafter64(f64,2.0*(f64+1.0))-f64;
1934+
}
1935+
default: break;
19231936
}
19241937
}
19251938

include/nbl/asset/format/encodePixels.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,6 +2488,7 @@ namespace asset
24882488
inp >>= 52;
24892489
inp &= 0x7ffull;
24902490
inp -= (1023ull - 15ull);
2491+
// TODO: this is wrong, need to get maximum exponent across all 3 input values
24912492
exp = (static_cast<uint32_t>(inp) << 27);
24922493
}
24932494
for (uint32_t i = 0u; i < 3u; ++i)

0 commit comments

Comments
 (0)