summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-wgsl.cpp
diff options
context:
space:
mode:
authorvenkataram-nv <vedavamadath@nvidia.com>2025-07-30 09:27:38 -0700
committerGitHub <noreply@github.com>2025-07-30 16:27:38 +0000
commit92ee2927d0012dd454dff7bb53b900f5240073d5 (patch)
treed0a648fbb1e6b08c6eec90fadb23435731c1eefe /source/slang/slang-emit-wgsl.cpp
parent42dc521f7817328a20e40b3352ae667dfd124edb (diff)
Lowering unsupported matrix types for GLSL/WGSL/Metal targets (#7936)
* Add emit cases for WGSL and GLSL * Fix compilation warnings Modify short cutting test to reflect change in emit logic Lower matrix for metal as well Add emit matrix logic for metal Fix compiler warning Brace initializer for lowered matrices Fix compiler warnings * Tests for metal * Fix mult, any, and determinant * Fix matrix-matrix multiplication * Fix mat mul to be element-wise * Fix compiler warning * Move makeMatrix to legalization * Move unary and binary arithmetic operator lowering to legalization * Remove emit logic and move final comparison operators to legalization * Handle vector/matrix negation for WGSL * Restore older SPIR-V emit logic * Address PR comments * Revert to zero minus for negation * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-emit-wgsl.cpp')
-rw-r--r--source/slang/slang-emit-wgsl.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/source/slang/slang-emit-wgsl.cpp b/source/slang/slang-emit-wgsl.cpp
index fbcb54d10..53c3aa487 100644
--- a/source/slang/slang-emit-wgsl.cpp
+++ b/source/slang/slang-emit-wgsl.cpp
@@ -1624,6 +1624,22 @@ bool WGSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu
m_writer->emit(")");
return true;
}
+ case kIROp_Neg:
+ {
+ auto opType = inst->getOperand(0)->getDataType();
+ if (as<IRMatrixType>(opType) || as<IRVectorType>(opType))
+ {
+ // WGSL does not support negate operator on matrices and vectors,
+ // we should emit "(type(0) - op0)" instead.
+ m_writer->emit("(");
+ emitType(inst->getDataType());
+ m_writer->emit("(0) - ");
+ emitOperand(inst->getOperand(0), getInfo(EmitOp::General));
+ m_writer->emit(")");
+ return true;
+ }
+ break;
+ }
}
return false;