mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[spv-out] implement derivatives
This commit is contained in:
committed by
Dzmitry Malyshau
parent
32a11752af
commit
4fb82bd955
@@ -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
|
||||
//
|
||||
|
||||
@@ -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"));
|
||||
|
||||
Reference in New Issue
Block a user