Skip to content

Commit

Permalink
Re-enable FP16 support for bitmap textures
Browse files Browse the repository at this point in the history
* Prior to Mitsuba 3.6, FP16 storage for bitmaps was disabled due to observed degradation in performance (particularly on LLVM backends)
* Changes with Dr.Jit textures now using PacketOps (mitsuba-renderer/drjit#329) means we can re-enable support for FP16 bitmap textures
  • Loading branch information
rtabbara authored and njroussel committed Feb 6, 2025
1 parent ba8d9fb commit af5aaa6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ext/drjit
21 changes: 13 additions & 8 deletions src/textures/bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ Bitmap texture (:monosp:`bitmap`)
- Specifies the underlying texture storage format. The following options are
currently available:
- ``variant``(default): Use the corresponding native floating point representation
- ``auto`` (default): If loading a texture from a bitmap, use half
precision for bitmap data with 16 or lower bit depth, otherwise use
the native floating point representation of the Mitsuba variant. For
variants using a spectral color representation this option is the same
as `variant`.
- ``variant``: Use the corresponding native floating point representation
of the Mitsuba variant
- ``fp16``: Forcibly store the texture in half precision
Expand Down Expand Up @@ -167,13 +173,15 @@ class BitmapTexture final : public Texture<Float, Spectrum> {

// Format
{
std::string format_str = props.string("format", "variant");
if (format_str == "variant")
std::string format_str = props.string("format", "auto");
if (format_str == "auto")
m_format = Format::Auto;
else if (format_str == "variant")
m_format = Format::Variant;
else if (format_str == "fp16")
m_format = Format::Float16;
else
Throw("Invalid format \"%s\", must be one of: "
Throw("Invalid format \"%s\", must be one of: \"auto\", "
"\"variant\", or \"fp16\"!", format_str);
}

Expand Down Expand Up @@ -221,9 +229,6 @@ class BitmapTexture final : public Texture<Float, Spectrum> {
Object* expand_1() const {
if (m_bitmap) {
Format format = m_format;

// TODO: Temporarily disable this as LLVM FP16 gather/scatter operations are costly
#if 0
// Format auto means we store texture as FP16 when possible.
// Skip this conversion for spectral variants as we want to perform
// spectral upsampling in the variant's native FP representation
Expand All @@ -233,7 +238,6 @@ class BitmapTexture final : public Texture<Float, Spectrum> {
if (m_format == Format::Auto && bytes_p_ch <= 2)
format = Format::Float16;
}
#endif

if (format == Format::Float16)
return expand_bitmap<dr::replace_scalar_t<Float, dr::half>>();
Expand Down Expand Up @@ -338,6 +342,7 @@ class BitmapTexture final : public Texture<Float, Spectrum> {
}

enum class Format {
Auto,
Variant,
Float16
} m_format;
Expand Down
2 changes: 1 addition & 1 deletion tutorials

0 comments on commit af5aaa6

Please sign in to comment.