[spv-out] implement derivatives

This commit is contained in:
Lain-dono authored and Dzmitry Malyshau committed 2021-03-14 20:34:59 -04:00
1 parent 32a11752af
commit 4fb82bd955
2 files changed
+36

No files matched your search

+24
View File
@@ -683,6 +683,30 @@ impl super::Instruction {
// Derivative Instructions
//
pub(super) fn derive_x(result_type_id: Word, id: Word, expr_id: Word) -> Self {
let mut instruction = Self::new(Op::DPdx);
instruction.set_type(result_type_id);
instruction.set_result(id);
instruction.add_operand(expr_id);
instruction
}
pub(super) fn derive_y(result_type_id: Word, id: Word, expr_id: Word) -> Self {
let mut instruction = Self::new(Op::DPdy);
instruction.set_type(result_type_id);
instruction.set_result(id);
instruction.add_operand(expr_id);
instruction
}
pub(super) fn derive_width(result_type_id: Word, id: Word, expr_id: Word) -> Self {
let mut instruction = Self::new(Op::Fwidth);
instruction.set_type(result_type_id);
instruction.set_result(id);
instruction.add_operand(expr_id);
instruction
}
//
// Control-Flow Instructions
//
+12
View File
@@ -1901,6 +1901,18 @@ impl Writer {
block.body.push(instruction);
id
}
crate::Expression::Derivative { axis, expr } => {
use crate::DerivativeAxis;
let id = self.generate_id();
let expr_id = self.cached[expr];
block.body.push(match axis {
DerivativeAxis::X => Instruction::derive_x(result_type_id, id, expr_id),
DerivativeAxis::Y => Instruction::derive_y(result_type_id, id, expr_id),
DerivativeAxis::Width => Instruction::derive_width(result_type_id, id, expr_id),
});
id
}
ref other => {
log::error!("unimplemented {:?}", other);
return Err(Error::FeatureNotImplemented("expression"));