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

benefit from 32-bit opacity #73

Open
github-actions bot opened this issue Jan 9, 2024 · 0 comments
Open

benefit from 32-bit opacity #73

github-actions bot opened this issue Jan 9, 2024 · 0 comments
Assignees
Labels

Comments

@github-actions
Copy link

github-actions bot commented Jan 9, 2024

opacity: pack_f32s_to_u32(opacity, opacity), // TODO: benefit from 32-bit opacity

}


#[derive(
    Clone,
    Debug,
    Default,
    Copy,
    PartialEq,
    Reflect,
    ShaderType,
    Pod,
    Zeroable,
    Serialize,
    Deserialize,
)]
#[repr(C)]
pub struct Covariance3dOpacityPacked128 {
    #[reflect(ignore)]
    pub cov3d: [u32; 3],
    pub opacity: u32,
}

impl Covariance3dOpacityPacked128 {
    pub fn from_gaussian(gaussian: &Gaussian) -> Self {
        let cov3d: Covariance3dOpacity = gaussian.into();
        let cov3d = cov3d.cov3d;

        let opacity = gaussian.scale_opacity.opacity;

        Self {
            cov3d: [
                pack_f32s_to_u32(cov3d[0], cov3d[1]),
                pack_f32s_to_u32(cov3d[2], cov3d[3]),
                pack_f32s_to_u32(cov3d[4], cov3d[5]),
            ],
            opacity: pack_f32s_to_u32(opacity, opacity),  // TODO: benefit from 32-bit opacity
        }
    }

    pub fn covariance_3d_opacity(&self) -> Covariance3dOpacity {
        let (c0, c1) = unpack_u32_to_f32s(self.cov3d[0]);
        let (c2, c3) = unpack_u32_to_f32s(self.cov3d[1]);
        let (c4, c5) = unpack_u32_to_f32s(self.cov3d[2]);

        let (opacity, _) = unpack_u32_to_f32s(self.opacity);

        let cov3d: [f32; 6] = [c0, c1, c2, c3, c4, c5];

        Covariance3dOpacity {
            cov3d,
            opacity,
            pad: 0.0,
        }
    }
}

impl From<[u32; 4]> for Covariance3dOpacityPacked128 {
    fn from(cov3d_opacity: [u32; 4]) -> Self {
        Self {
            cov3d: [
                cov3d_opacity[0],
                cov3d_opacity[1],
                cov3d_opacity[2],
            ],
            opacity: cov3d_opacity[3],
        }
    }
}


pub fn pack_f32s_to_u32(upper: f32, lower: f32) -> u32 {
    pack_f16s_to_u32(
        f16::from_f32(upper),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant