[spv-out] implement derivatives

This commit is contained in:
Lain-dono
2021-03-15 02:39:36 +03:00
committed by Dzmitry Malyshau
parent 32a11752af
commit 4fb82bd955
2 changed files with 36 additions and 0 deletions

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
//

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"));