Made GPU bone updates more conservative for moar fps

This commit is contained in:
Joshua Barretto 2020-04-25 15:38:17 +01:00
parent 7208b37dc5
commit 8e95444d85
16 changed files with 49 additions and 19 deletions

View File

@ -22,6 +22,7 @@ struct BoneData {
layout (std140)
uniform u_bones {
// Warning: might not actually be 16 elements long. Don't index out of bounds!
BoneData bones[16];
};

View File

@ -47,6 +47,8 @@ impl BipedLargeSkeleton {
impl Skeleton for BipedLargeSkeleton {
type Attr = SkeletonAttr;
fn bone_count(&self) -> usize { 11 }
fn compute_matrices(&self) -> [FigureBoneData; 16] {
let upper_torso_mat = self.upper_torso.compute_base_matrix();
let shoulder_l_mat = self.shoulder_l.compute_base_matrix();

View File

@ -27,6 +27,8 @@ impl BirdMediumSkeleton {
impl Skeleton for BirdMediumSkeleton {
type Attr = SkeletonAttr;
fn bone_count(&self) -> usize { 7 }
fn compute_matrices(&self) -> [FigureBoneData; 16] {
let torso_mat = self.torso.compute_base_matrix();

View File

@ -31,6 +31,8 @@ impl BirdSmallSkeleton {
impl Skeleton for BirdSmallSkeleton {
type Attr = SkeletonAttr;
fn bone_count(&self) -> usize { 4 }
fn compute_matrices(&self) -> [FigureBoneData; 16] {
let torso_mat = self.torso.compute_base_matrix();

View File

@ -62,6 +62,8 @@ impl CharacterSkeleton {
impl Skeleton for CharacterSkeleton {
type Attr = SkeletonAttr;
fn bone_count(&self) -> usize { 15 }
fn compute_matrices(&self) -> [FigureBoneData; 16] {
let chest_mat = self.chest.compute_base_matrix();
let torso_mat = self.torso.compute_base_matrix();

View File

@ -32,6 +32,8 @@ impl CritterSkeleton {
impl Skeleton for CritterSkeleton {
type Attr = CritterAttr;
fn bone_count(&self) -> usize { 5 }
fn compute_matrices(&self) -> [FigureBoneData; 16] {
[
FigureBoneData::new(self.head.compute_base_matrix()),

View File

@ -49,6 +49,8 @@ impl DragonSkeleton {
impl Skeleton for DragonSkeleton {
type Attr = SkeletonAttr;
fn bone_count(&self) -> usize { 13 }
fn compute_matrices(&self) -> [FigureBoneData; 16] {
let chest_front_mat = self.chest_front.compute_base_matrix();
let wing_in_l_mat = self.wing_in_l.compute_base_matrix();

View File

@ -35,6 +35,8 @@ impl FishMediumSkeleton {
impl Skeleton for FishMediumSkeleton {
type Attr = SkeletonAttr;
fn bone_count(&self) -> usize { 6 }
fn compute_matrices(&self) -> [FigureBoneData; 16] {
let torso_mat = self.torso.compute_base_matrix();
let rear_mat = self.rear.compute_base_matrix();

View File

@ -27,6 +27,8 @@ impl FishSmallSkeleton {
impl Skeleton for FishSmallSkeleton {
type Attr = SkeletonAttr;
fn bone_count(&self) -> usize { 2 }
fn compute_matrices(&self) -> [FigureBoneData; 16] {
let torso_mat = self.torso.compute_base_matrix();

View File

@ -13,9 +13,11 @@ impl FixtureSkeleton {
impl Skeleton for FixtureSkeleton {
type Attr = SkeletonAttr;
fn bone_count(&self) -> usize { 1 }
fn compute_matrices(&self) -> [FigureBoneData; 16] {
[
FigureBoneData::new(vek::Mat4::identity()),
FigureBoneData::new(vek::Mat4::identity()), // <-- This is actually a bone!
FigureBoneData::new(vek::Mat4::identity()),
FigureBoneData::new(vek::Mat4::identity()),
FigureBoneData::new(vek::Mat4::identity()),

View File

@ -52,6 +52,8 @@ impl Bone {
pub trait Skeleton: Send + Sync + 'static {
type Attr;
fn bone_count(&self) -> usize { 16 }
fn compute_matrices(&self) -> [FigureBoneData; 16];
/// Change the current skeleton to be more like `target`.

View File

@ -15,24 +15,26 @@ const SCALE: f32 = 1.0 / 11.0;
impl Skeleton for ObjectSkeleton {
type Attr = SkeletonAttr;
fn bone_count(&self) -> usize { 1 }
fn compute_matrices(&self) -> [FigureBoneData; 16] {
[
FigureBoneData::new(Mat4::scaling_3d(Vec3::broadcast(SCALE))),
FigureBoneData::new(Mat4::scaling_3d(Vec3::broadcast(SCALE))),
FigureBoneData::new(Mat4::scaling_3d(Vec3::broadcast(SCALE))),
FigureBoneData::new(Mat4::scaling_3d(Vec3::broadcast(SCALE))),
FigureBoneData::new(Mat4::scaling_3d(Vec3::broadcast(SCALE))),
FigureBoneData::new(Mat4::scaling_3d(Vec3::broadcast(SCALE))),
FigureBoneData::new(Mat4::scaling_3d(Vec3::broadcast(SCALE))),
FigureBoneData::new(Mat4::scaling_3d(Vec3::broadcast(SCALE))),
FigureBoneData::new(Mat4::scaling_3d(Vec3::broadcast(SCALE))),
FigureBoneData::new(Mat4::scaling_3d(Vec3::broadcast(SCALE))),
FigureBoneData::new(Mat4::scaling_3d(Vec3::broadcast(SCALE))),
FigureBoneData::new(Mat4::scaling_3d(Vec3::broadcast(SCALE))),
FigureBoneData::new(Mat4::scaling_3d(Vec3::broadcast(SCALE))),
FigureBoneData::new(Mat4::scaling_3d(Vec3::broadcast(SCALE))),
FigureBoneData::new(Mat4::scaling_3d(Vec3::broadcast(SCALE))),
FigureBoneData::new(Mat4::scaling_3d(Vec3::broadcast(SCALE))),
FigureBoneData::new(vek::Mat4::identity()),
FigureBoneData::new(vek::Mat4::identity()),
FigureBoneData::new(vek::Mat4::identity()),
FigureBoneData::new(vek::Mat4::identity()),
FigureBoneData::new(vek::Mat4::identity()),
FigureBoneData::new(vek::Mat4::identity()),
FigureBoneData::new(vek::Mat4::identity()),
FigureBoneData::new(vek::Mat4::identity()),
FigureBoneData::new(vek::Mat4::identity()),
FigureBoneData::new(vek::Mat4::identity()),
FigureBoneData::new(vek::Mat4::identity()),
FigureBoneData::new(vek::Mat4::identity()),
FigureBoneData::new(vek::Mat4::identity()),
FigureBoneData::new(vek::Mat4::identity()),
FigureBoneData::new(vek::Mat4::identity()),
]
}

View File

@ -31,6 +31,8 @@ impl QuadrupedMediumSkeleton {
impl Skeleton for QuadrupedMediumSkeleton {
type Attr = SkeletonAttr;
fn bone_count(&self) -> usize { 11 }
fn compute_matrices(&self) -> [FigureBoneData; 16] {
let ears_mat = self.ears.compute_base_matrix();
let head_upper_mat = self.head_upper.compute_base_matrix();

View File

@ -26,6 +26,8 @@ impl QuadrupedSmallSkeleton {
impl Skeleton for QuadrupedSmallSkeleton {
type Attr = SkeletonAttr;
fn bone_count(&self) -> usize { 6 }
fn compute_matrices(&self) -> [FigureBoneData; 16] {
[
FigureBoneData::new(self.head.compute_base_matrix()),

View File

@ -56,8 +56,11 @@ impl Vertex {
};
Self {
pos_norm: pos
.map2(Vec3::new(0, 8, 16), |e, shift| ((e + 128.0) as u32) << shift)
.reduce_bitor() | (norm_bits << 24),
.map2(Vec3::new(0, 8, 16), |e, shift| {
((e + 128.0) as u32) << shift
})
.reduce_bitor()
| (norm_bits << 24),
col: col
.map2(Rgb::new(0, 8, 16), |e, shift| ((e * 255.0) as u32) << shift)
.reduce_bitor(),

View File

@ -1859,7 +1859,7 @@ impl<S: Skeleton> FigureState<S> {
renderer.update_consts(&mut self.locals, &[locals]).unwrap();
renderer
.update_consts(&mut self.bone_consts, &self.skeleton.compute_matrices())
.update_consts(&mut self.bone_consts, &self.skeleton.compute_matrices()[0..self.skeleton.bone_count()])
.unwrap();
}