| 1 |
use crate::{ScalarKind, TypeInner, VectorSize}; |
| 2 |
|
| 3 |
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] |
| 4 |
pub struct InversePolyfill { |
| 5 |
pub fun_name: &'static str, |
| 6 |
pub source: &'static str, |
| 7 |
} |
| 8 |
|
| 9 |
impl InversePolyfill { |
| 10 |
pub fn find_overload(ty: &TypeInner) -> Option<InversePolyfill> { |
| 11 |
let &TypeInner::Matrix { |
| 12 |
columns, |
| 13 |
rows, |
| 14 |
scalar, |
| 15 |
} = ty |
| 16 |
else { |
| 17 |
return None; |
| 18 |
}; |
| 19 |
|
| 20 |
if columns != rows || scalar.kind != ScalarKind::Float { |
| 21 |
return None; |
| 22 |
}; |
| 23 |
|
| 24 |
Self::polyfill_overload(columns, scalar.width) |
| 25 |
} |
| 26 |
|
| 27 |
const fn polyfill_overload( |
| 28 |
dimension: VectorSize, |
| 29 |
width: crate::Bytes, |
| 30 |
) -> Option<InversePolyfill> { |
| 31 |
const INVERSE_2X2_F32: &str = include_str!("inverse/inverse_2x2_f32.wgsl"); |
| 32 |
const INVERSE_3X3_F32: &str = include_str!("inverse/inverse_3x3_f32.wgsl"); |
| 33 |
const INVERSE_4X4_F32: &str = include_str!("inverse/inverse_4x4_f32.wgsl"); |
| 34 |
const INVERSE_2X2_F16: &str = include_str!("inverse/inverse_2x2_f16.wgsl"); |
| 35 |
const INVERSE_3X3_F16: &str = include_str!("inverse/inverse_3x3_f16.wgsl"); |
| 36 |
const INVERSE_4X4_F16: &str = include_str!("inverse/inverse_4x4_f16.wgsl"); |
| 37 |
|
| 38 |
match (dimension, width) { |
| 39 |
(VectorSize::Bi, 4) => Some(InversePolyfill { |
| 40 |
fun_name: "_naga_inverse_2x2_f32", |
| 41 |
source: INVERSE_2X2_F32, |
| 42 |
}), |
| 43 |
(VectorSize::Tri, 4) => Some(InversePolyfill { |
| 44 |
fun_name: "_naga_inverse_3x3_f32", |
| 45 |
source: INVERSE_3X3_F32, |
| 46 |
}), |
| 47 |
(VectorSize::Quad, 4) => Some(InversePolyfill { |
| 48 |
fun_name: "_naga_inverse_4x4_f32", |
| 49 |
source: INVERSE_4X4_F32, |
| 50 |
}), |
| 51 |
(VectorSize::Bi, 2) => Some(InversePolyfill { |
| 52 |
fun_name: "_naga_inverse_2x2_f16", |
| 53 |
source: INVERSE_2X2_F16, |
| 54 |
}), |
| 55 |
(VectorSize::Tri, 2) => Some(InversePolyfill { |
| 56 |
fun_name: "_naga_inverse_3x3_f16", |
| 57 |
source: INVERSE_3X3_F16, |
| 58 |
}), |
| 59 |
(VectorSize::Quad, 2) => Some(InversePolyfill { |
| 60 |
fun_name: "_naga_inverse_4x4_f16", |
| 61 |
source: INVERSE_4X4_F16, |
| 62 |
}), |
| 63 |
_ => None, |
| 64 |
} |
| 65 |
} |
| 66 |
} |