Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable FP16 support for bitmap textures #1478

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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