diff options
| author | Yong He <yonghe@outlook.com> | 2024-06-13 16:29:58 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-13 16:29:58 -0700 |
| commit | cfef0c6f66c9d36ae2899c8c2790c3fe422a7700 (patch) | |
| tree | 0e116769009ae7e4b3b16d2ef28f275bea5e1fd7 /source/slang/slang-emit-metal.cpp | |
| parent | 2407966e899f9e4f490b23a92fc06d5da20544cc (diff) | |
Metal: misc fixes and enable more tests. (#4374)
* Fix and enable tests for metal.
* Fix.
* Fix.
* Fix tests.
* Fix warnings.
* Fix.
---------
Co-authored-by: Yong He <yonghe@Yongs-Mac-mini.local>
Diffstat (limited to 'source/slang/slang-emit-metal.cpp')
| -rw-r--r-- | source/slang/slang-emit-metal.cpp | 66 |
1 files changed, 47 insertions, 19 deletions
diff --git a/source/slang/slang-emit-metal.cpp b/source/slang/slang-emit-metal.cpp index 794a31e41..07d5b9f6c 100644 --- a/source/slang/slang-emit-metal.cpp +++ b/source/slang/slang-emit-metal.cpp @@ -143,24 +143,36 @@ void MetalSourceEmitter::emitFuncParamLayoutImpl(IRInst* param) auto layout = as<IRVarLayout>(layoutDecoration->getLayout()); if (!layout) return; + for (auto rr : layout->getOffsetAttrs()) { switch (rr->getResourceKind()) { case LayoutResourceKind::MetalTexture: - m_writer->emit(" [[texture("); - m_writer->emit(rr->getOffset()); - m_writer->emit(")]]"); + if (as<IRTextureTypeBase>(param->getDataType()) || as<IRTextureBufferType>(param->getDataType())) + { + m_writer->emit(" [[texture("); + m_writer->emit(rr->getOffset()); + m_writer->emit(")]]"); + } break; case LayoutResourceKind::MetalBuffer: - m_writer->emit(" [[buffer("); - m_writer->emit(rr->getOffset()); - m_writer->emit(")]]"); + if (as<IRPtrTypeBase>(param->getDataType()) || as<IRHLSLStructuredBufferTypeBase>(param->getDataType()) || + as<IRByteAddressBufferTypeBase>(param->getDataType()) || + as<IRUniformParameterGroupType>(param->getDataType())) + { + m_writer->emit(" [[buffer("); + m_writer->emit(rr->getOffset()); + m_writer->emit(")]]"); + } break; case LayoutResourceKind::SamplerState: - m_writer->emit(" [[sampler("); - m_writer->emit(rr->getOffset()); - m_writer->emit(")]]"); + if (as<IRSamplerStateTypeBase>(param->getDataType())) + { + m_writer->emit(" [[sampler("); + m_writer->emit(rr->getOffset()); + m_writer->emit(")]]"); + } break; case LayoutResourceKind::VaryingInput: m_writer->emit(" [[stage_in]]"); @@ -314,6 +326,15 @@ bool MetalSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inO } break; } + case kIROp_FRem: + { + m_writer->emit("fmod("); + emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); + m_writer->emit(", "); + emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); + m_writer->emit(")"); + return true; + } case kIROp_Select: { m_writer->emit("select("); @@ -374,7 +395,7 @@ bool MetalSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inO m_writer->emit("[("); emitOperand(offset, getInfo(EmitOp::General)); m_writer->emit(")>>2] = as_type<uint32_t>("); - emitOperand(inst->getOperand(2), getInfo(EmitOp::General)); + emitOperand(inst->getOperand(inst->getOperandCount() - 1), getInfo(EmitOp::General)); m_writer->emit(")"); return true; } @@ -587,9 +608,9 @@ void MetalSourceEmitter::emitSimpleTypeImpl(IRType* type) m_writer->emit("matrix<"); emitType(matType->getElementType()); m_writer->emit(","); - emitVal(matType->getColumnCount(), getInfo(EmitOp::General)); - m_writer->emit(","); emitVal(matType->getRowCount(), getInfo(EmitOp::General)); + m_writer->emit(","); + emitVal(matType->getColumnCount(), getInfo(EmitOp::General)); m_writer->emit("> "); return; } @@ -760,7 +781,7 @@ bool MetalSourceEmitter::maybeEmitSystemSemantic(IRInst* inst) return false; } -void MetalSourceEmitter::_emitUserSemantic(UnownedStringSlice semanticName, IRIntegerValue semanticIndex) +bool MetalSourceEmitter::_emitUserSemantic(UnownedStringSlice semanticName, IRIntegerValue semanticIndex) { if (!semanticName.startsWithCaseInsensitive(toSlice("SV_"))) { @@ -772,7 +793,9 @@ void MetalSourceEmitter::_emitUserSemantic(UnownedStringSlice semanticName, IRIn m_writer->emit(semanticIndex); } m_writer->emit(")]]"); + return true; } + return false; } void MetalSourceEmitter::emitSemanticsImpl(IRInst* inst, bool allowOffsets) @@ -785,8 +808,10 @@ void MetalSourceEmitter::emitSemanticsImpl(IRInst* inst, bool allowOffsets) if (maybeEmitSystemSemantic(inst)) return; - bool hasSemanticFromLayout = false; - if (auto varLayout = findVarLayout(inst)) + auto varLayout = findVarLayout(inst); + bool hasSemantic = false; + + if (varLayout) { for (auto attr : varLayout->getAllAttrs()) { @@ -797,18 +822,21 @@ void MetalSourceEmitter::emitSemanticsImpl(IRInst* inst, bool allowOffsets) m_writer->emit(" [[attribute("); m_writer->emit(offsetAttr->getOffset()); m_writer->emit(")]]"); + return; } } - else if (auto semanticAttr = as<IRSemanticAttr>(attr)) + } + for (auto attr : varLayout->getAllAttrs()) + { + if (auto semanticAttr = as<IRSemanticAttr>(attr)) { auto semanticName = String(semanticAttr->getName()).toUpper(); - _emitUserSemantic(semanticAttr->getName(), semanticAttr->getIndex()); - hasSemanticFromLayout = true; + hasSemantic = _emitUserSemantic(semanticAttr->getName(), semanticAttr->getIndex()); } } } - if (!hasSemanticFromLayout) + if (!hasSemantic) { if (auto semanticDecor = inst->findDecoration<IRSemanticDecoration>()) { |
