From f65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Tue, 29 Oct 2024 14:49:26 +0800 Subject: format * format * Minor test fixes * enable checking cpp format in ci --- source/slang/slang-emit-hlsl.cpp | 1036 +++++++++++++++++++------------------- 1 file changed, 513 insertions(+), 523 deletions(-) (limited to 'source/slang/slang-emit-hlsl.cpp') diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp index ae87fd6d5..0b4ceed92 100644 --- a/source/slang/slang-emit-hlsl.cpp +++ b/source/slang/slang-emit-hlsl.cpp @@ -2,16 +2,19 @@ #include "slang-emit-hlsl.h" #include "../core/slang-writer.h" - -#include "slang-ir-util.h" #include "slang-emit-source-writer.h" +#include "slang-ir-util.h" #include "slang-mangled-lexer.h" #include -namespace Slang { +namespace Slang +{ -void HLSLSourceEmitter::_emitHLSLDecorationSingleString(const char* name, IRFunc* entryPoint, IRStringLit* val) +void HLSLSourceEmitter::_emitHLSLDecorationSingleString( + const char* name, + IRFunc* entryPoint, + IRStringLit* val) { SLANG_UNUSED(entryPoint); assert(val); @@ -23,7 +26,10 @@ void HLSLSourceEmitter::_emitHLSLDecorationSingleString(const char* name, IRFunc m_writer->emit("\")]\n"); } -void HLSLSourceEmitter::_emitHLSLDecorationSingleInt(const char* name, IRFunc* entryPoint, IRIntLit* val) +void HLSLSourceEmitter::_emitHLSLDecorationSingleInt( + const char* name, + IRFunc* entryPoint, + IRIntLit* val) { SLANG_UNUSED(entryPoint); SLANG_ASSERT(val); @@ -37,7 +43,11 @@ void HLSLSourceEmitter::_emitHLSLDecorationSingleInt(const char* name, IRFunc* e m_writer->emit(")]\n"); } -void HLSLSourceEmitter::_emitHLSLRegisterSemantic(LayoutResourceKind kind, EmitVarChain* chain, IRInst* inst, char const* uniformSemanticSpelling) +void HLSLSourceEmitter::_emitHLSLRegisterSemantic( + LayoutResourceKind kind, + EmitVarChain* chain, + IRInst* inst, + char const* uniformSemanticSpelling) { if (!chain) return; @@ -49,7 +59,7 @@ void HLSLSourceEmitter::_emitHLSLRegisterSemantic(LayoutResourceKind kind, EmitV switch (kind) { - case LayoutResourceKind::Uniform: + case LayoutResourceKind::Uniform: { UInt offset = index; @@ -84,7 +94,7 @@ void HLSLSourceEmitter::_emitHLSLRegisterSemantic(LayoutResourceKind kind, EmitV size_t startComponent = byteOffsetInRegister / componentSize; - static const char* kComponentNames[] = { "x", "y", "z", "w" }; + static const char* kComponentNames[] = {"x", "y", "z", "w"}; m_writer->emit("."); m_writer->emit(kComponentNames[startComponent]); } @@ -92,26 +102,27 @@ void HLSLSourceEmitter::_emitHLSLRegisterSemantic(LayoutResourceKind kind, EmitV } break; - case LayoutResourceKind::InputAttachmentIndex: + case LayoutResourceKind::InputAttachmentIndex: { - m_writer->emit("[[vk::input_attachment_index("); + m_writer->emit("[[vk::input_attachment_index("); m_writer->emit(index); m_writer->emit(")]]"); } break; - case LayoutResourceKind::RegisterSpace: - case LayoutResourceKind::GenericResource: - case LayoutResourceKind::ExistentialTypeParam: - case LayoutResourceKind::ExistentialObjectParam: - // ignore - break; - default: + case LayoutResourceKind::RegisterSpace: + case LayoutResourceKind::GenericResource: + case LayoutResourceKind::ExistentialTypeParam: + case LayoutResourceKind::ExistentialObjectParam: + // ignore + break; + default: { - if (m_codeGenContext->getTargetProgram()->getOptionSet().getBoolOption(CompilerOptionName::NoHLSLBinding)) + if (m_codeGenContext->getTargetProgram()->getOptionSet().getBoolOption( + CompilerOptionName::NoHLSLBinding)) { - // If we are told not to emit hlsl binding, and the user has not provided explicit binding, - // then skip emitting the `: register` semantics here. + // If we are told not to emit hlsl binding, and the user has not provided explicit + // binding, then skip emitting the `: register` semantics here. // if (!inst || !inst->findDecoration()) { @@ -121,21 +132,13 @@ void HLSLSourceEmitter::_emitHLSLRegisterSemantic(LayoutResourceKind kind, EmitV m_writer->emit(" : register("); switch (kind) { - case LayoutResourceKind::ConstantBuffer: - m_writer->emit("b"); - break; - case LayoutResourceKind::ShaderResource: - m_writer->emit("t"); - break; - case LayoutResourceKind::UnorderedAccess: - m_writer->emit("u"); - break; - case LayoutResourceKind::SamplerState: - m_writer->emit("s"); - break; - default: - SLANG_DIAGNOSE_UNEXPECTED(getSink(), SourceLoc(), "unhandled HLSL register type"); - break; + case LayoutResourceKind::ConstantBuffer: m_writer->emit("b"); break; + case LayoutResourceKind::ShaderResource: m_writer->emit("t"); break; + case LayoutResourceKind::UnorderedAccess: m_writer->emit("u"); break; + case LayoutResourceKind::SamplerState: m_writer->emit("s"); break; + default: + SLANG_DIAGNOSE_UNEXPECTED(getSink(), SourceLoc(), "unhandled HLSL register type"); + break; } m_writer->emit(index); if (space) @@ -148,31 +151,38 @@ void HLSLSourceEmitter::_emitHLSLRegisterSemantic(LayoutResourceKind kind, EmitV } } -void HLSLSourceEmitter::_emitHLSLRegisterSemantics(EmitVarChain* chain, IRInst* inst, char const* uniformSemanticSpelling, EmitLayoutSemanticOption layoutSemanticOption) +void HLSLSourceEmitter::_emitHLSLRegisterSemantics( + EmitVarChain* chain, + IRInst* inst, + char const* uniformSemanticSpelling, + EmitLayoutSemanticOption layoutSemanticOption) { - if (!chain) return; + if (!chain) + return; auto layout = chain->varLayout; switch (getSourceLanguage()) { - default: - return; + default: return; - case SourceLanguage::HLSL: - break; + case SourceLanguage::HLSL: break; } for (auto rr : layout->getOffsetAttrs()) { - if (layoutSemanticOption == EmitLayoutSemanticOption::kPreType - && rr->getResourceKind() != LayoutResourceKind::InputAttachmentIndex) + if (layoutSemanticOption == EmitLayoutSemanticOption::kPreType && + rr->getResourceKind() != LayoutResourceKind::InputAttachmentIndex) continue; _emitHLSLRegisterSemantic(rr->getResourceKind(), chain, inst, uniformSemanticSpelling); } } -void HLSLSourceEmitter::_emitHLSLRegisterSemantics(IRVarLayout* varLayout, IRInst* inst, char const* uniformSemanticSpelling, EmitLayoutSemanticOption layoutSemanticOption) +void HLSLSourceEmitter::_emitHLSLRegisterSemantics( + IRVarLayout* varLayout, + IRInst* inst, + char const* uniformSemanticSpelling, + EmitLayoutSemanticOption layoutSemanticOption) { if (!varLayout) return; @@ -193,13 +203,17 @@ void HLSLSourceEmitter::_emitHLSLParameterGroupFieldLayoutSemantics(EmitVarChain } } -void HLSLSourceEmitter::_emitHLSLParameterGroupFieldLayoutSemantics(IRVarLayout* fieldLayout, EmitVarChain* inChain) +void HLSLSourceEmitter::_emitHLSLParameterGroupFieldLayoutSemantics( + IRVarLayout* fieldLayout, + EmitVarChain* inChain) { EmitVarChain chain(fieldLayout, inChain); _emitHLSLParameterGroupFieldLayoutSemantics(&chain); } -void HLSLSourceEmitter::_emitHLSLParameterGroup(IRGlobalParam* varDecl, IRUniformParameterGroupType* type) +void HLSLSourceEmitter::_emitHLSLParameterGroup( + IRGlobalParam* varDecl, + IRUniformParameterGroupType* type) { LayoutResourceKind layoutResourceKind = LayoutResourceKind::ConstantBuffer; if (as(type)) @@ -224,7 +238,8 @@ void HLSLSourceEmitter::_emitHLSLParameterGroup(IRGlobalParam* varDecl, IRUnifor auto typeLayout = varLayout->getTypeLayout(); if (auto parameterGroupTypeLayout = as(typeLayout)) { - containerChain = EmitVarChain(parameterGroupTypeLayout->getContainerVarLayout(), &blockChain); + containerChain = + EmitVarChain(parameterGroupTypeLayout->getContainerVarLayout(), &blockChain); elementChain = EmitVarChain(parameterGroupTypeLayout->getElementVarLayout(), &blockChain); typeLayout = parameterGroupTypeLayout->getElementVarLayout()->getTypeLayout(); @@ -242,8 +257,8 @@ void HLSLSourceEmitter::_emitHLSLParameterGroup(IRGlobalParam* varDecl, IRUnifor m_writer->emit("\n"); return; } - - + + m_writer->emit("\n{\n"); m_writer->indent(); @@ -259,44 +274,31 @@ void HLSLSourceEmitter::_emitHLSLTextureType(IRTextureTypeBase* texType) { switch (texType->getAccess()) { - case SLANG_RESOURCE_ACCESS_READ: - break; + case SLANG_RESOURCE_ACCESS_READ: break; - case SLANG_RESOURCE_ACCESS_READ_WRITE: - m_writer->emit("RW"); - break; + case SLANG_RESOURCE_ACCESS_READ_WRITE: m_writer->emit("RW"); break; - case SLANG_RESOURCE_ACCESS_RASTER_ORDERED: - m_writer->emit("RasterizerOrdered"); - break; + case SLANG_RESOURCE_ACCESS_RASTER_ORDERED: m_writer->emit("RasterizerOrdered"); break; - case SLANG_RESOURCE_ACCESS_APPEND: - m_writer->emit("Append"); - break; + case SLANG_RESOURCE_ACCESS_APPEND: m_writer->emit("Append"); break; - case SLANG_RESOURCE_ACCESS_CONSUME: - m_writer->emit("Consume"); - break; + case SLANG_RESOURCE_ACCESS_CONSUME: m_writer->emit("Consume"); break; - case SLANG_RESOURCE_ACCESS_FEEDBACK: - m_writer->emit("Feedback"); - break; + case SLANG_RESOURCE_ACCESS_FEEDBACK: m_writer->emit("Feedback"); break; - default: - SLANG_DIAGNOSE_UNEXPECTED(getSink(), SourceLoc(), "unhandled resource access mode"); - break; + default: + SLANG_DIAGNOSE_UNEXPECTED(getSink(), SourceLoc(), "unhandled resource access mode"); + break; } switch (texType->GetBaseShape()) { - case SLANG_TEXTURE_1D: m_writer->emit("Texture1D"); break; - case SLANG_TEXTURE_2D: m_writer->emit("Texture2D"); break; - case SLANG_TEXTURE_3D: m_writer->emit("Texture3D"); break; - case SLANG_TEXTURE_CUBE: m_writer->emit("TextureCube"); break; - case SLANG_TEXTURE_BUFFER: m_writer->emit("Buffer"); break; - default: - SLANG_DIAGNOSE_UNEXPECTED(getSink(), SourceLoc(), "unhandled resource shape"); - break; + case SLANG_TEXTURE_1D: m_writer->emit("Texture1D"); break; + case SLANG_TEXTURE_2D: m_writer->emit("Texture2D"); break; + case SLANG_TEXTURE_3D: m_writer->emit("Texture3D"); break; + case SLANG_TEXTURE_CUBE: m_writer->emit("TextureCube"); break; + case SLANG_TEXTURE_BUFFER: m_writer->emit("Buffer"); break; + default: SLANG_DIAGNOSE_UNEXPECTED(getSink(), SourceLoc(), "unhandled resource shape"); break; } if (texType->isMultisample()) @@ -330,21 +332,28 @@ void HLSLSourceEmitter::_emitHLSLSubpassInputType(IRSubpassInputType* subpassTyp m_writer->emit(">"); } -void HLSLSourceEmitter::emitLayoutSemanticsImpl(IRInst* inst, char const* uniformSemanticSpelling, EmitLayoutSemanticOption layoutSemanticOption) +void HLSLSourceEmitter::emitLayoutSemanticsImpl( + IRInst* inst, + char const* uniformSemanticSpelling, + EmitLayoutSemanticOption layoutSemanticOption) { - auto layout = getVarLayout(inst); + auto layout = getVarLayout(inst); if (layout) { _emitHLSLRegisterSemantics(layout, inst, uniformSemanticSpelling, layoutSemanticOption); } } -void HLSLSourceEmitter::emitParameterGroupImpl(IRGlobalParam* varDecl, IRUniformParameterGroupType* type) +void HLSLSourceEmitter::emitParameterGroupImpl( + IRGlobalParam* varDecl, + IRUniformParameterGroupType* type) { _emitHLSLParameterGroup(varDecl, type); } -void HLSLSourceEmitter::emitEntryPointAttributesImpl(IRFunc* irFunc, IREntryPointDecoration* entryPointDecor) +void HLSLSourceEmitter::emitEntryPointAttributesImpl( + IRFunc* irFunc, + IREntryPointDecoration* entryPointDecor) { auto profile = m_effectiveProfile; auto stage = entryPointDecor->getProfile().getStage(); @@ -364,39 +373,40 @@ void HLSLSourceEmitter::emitEntryPointAttributesImpl(IRFunc* irFunc, IREntryPoin } auto emitNumThreadsAttribute = [&]() - { - Int sizeAlongAxis[kThreadGroupAxisCount]; - getComputeThreadGroupSize(irFunc, sizeAlongAxis); + { + Int sizeAlongAxis[kThreadGroupAxisCount]; + getComputeThreadGroupSize(irFunc, sizeAlongAxis); - m_writer->emit("[numthreads("); - for (int ii = 0; ii < kThreadGroupAxisCount; ++ii) - { - if (ii != 0) m_writer->emit(", "); - m_writer->emit(sizeAlongAxis[ii]); - } - m_writer->emit(")]\n"); - }; + m_writer->emit("[numthreads("); + for (int ii = 0; ii < kThreadGroupAxisCount; ++ii) + { + if (ii != 0) + m_writer->emit(", "); + m_writer->emit(sizeAlongAxis[ii]); + } + m_writer->emit(")]\n"); + }; auto emitWaveSizeAttribute = [&]() + { + Int waveSize; + if (getComputeWaveSize(irFunc, &waveSize)) { - Int waveSize; - if (getComputeWaveSize(irFunc, &waveSize)) - { - m_writer->emit("[WaveSize("); - m_writer->emit(waveSize); - m_writer->emit(")]\n"); - } - }; + m_writer->emit("[WaveSize("); + m_writer->emit(waveSize); + m_writer->emit(")]\n"); + } + }; switch (stage) { - case Stage::Compute: + case Stage::Compute: { emitWaveSizeAttribute(); emitNumThreadsAttribute(); } break; - case Stage::Geometry: + case Stage::Geometry: { if (auto decor = irFunc->findDecoration()) { @@ -415,7 +425,7 @@ void HLSLSourceEmitter::emitEntryPointAttributesImpl(IRFunc* irFunc, IREntryPoin } break; } - case Stage::Domain: + case Stage::Domain: { /* [domain("isoline")] */ if (auto decor = irFunc->findDecoration()) @@ -424,7 +434,7 @@ void HLSLSourceEmitter::emitEntryPointAttributesImpl(IRFunc* irFunc, IREntryPoin } break; } - case Stage::Hull: + case Stage::Hull: { // Lists these are only attributes for hull shader // https://docs.microsoft.com/en-us/windows/desktop/direct3d11/direct3d-11-advanced-stages-hull-shader-design @@ -450,7 +460,10 @@ void HLSLSourceEmitter::emitEntryPointAttributesImpl(IRFunc* irFunc, IREntryPoin /* [outputcontrolpoints(4)] */ if (auto decor = irFunc->findDecoration()) { - _emitHLSLDecorationSingleInt("outputcontrolpoints", irFunc, decor->getControlPointCount()); + _emitHLSLDecorationSingleInt( + "outputcontrolpoints", + irFunc, + decor->getControlPointCount()); } /* [patchconstantfunc("HSConst")] */ @@ -465,7 +478,7 @@ void HLSLSourceEmitter::emitEntryPointAttributesImpl(IRFunc* irFunc, IREntryPoin break; } - case Stage::Pixel: + case Stage::Pixel: { if (irFunc->findDecoration()) { @@ -473,7 +486,7 @@ void HLSLSourceEmitter::emitEntryPointAttributesImpl(IRFunc* irFunc, IREntryPoin } break; } - case Stage::Mesh: + case Stage::Mesh: { emitNumThreadsAttribute(); if (auto decor = irFunc->findDecoration()) @@ -485,204 +498,205 @@ void HLSLSourceEmitter::emitEntryPointAttributesImpl(IRFunc* irFunc, IREntryPoin } break; } - case Stage::Amplification: + case Stage::Amplification: { emitNumThreadsAttribute(); break; } - // TODO: There are other stages that will need this kind of handling. - default: - break; + // TODO: There are other stages that will need this kind of handling. + default: break; } } bool HLSLSourceEmitter::tryEmitInstStmtImpl(IRInst* inst) { auto diagnoseFloatAtommic = [&]() - { - getSink()->diagnose(inst, Diagnostics::unsupportedTargetIntrinsic, "floating point atomic operation"); - }; + { + getSink()->diagnose( + inst, + Diagnostics::unsupportedTargetIntrinsic, + "floating point atomic operation"); + }; switch (inst->getOp()) { case kIROp_AtomicLoad: - { - emitInstResultDecl(inst); - emitDereferenceOperand(inst->getOperand(0), getInfo(EmitOp::General)); - m_writer->emit(";\n"); - return true; - } + { + emitInstResultDecl(inst); + emitDereferenceOperand(inst->getOperand(0), getInfo(EmitOp::General)); + m_writer->emit(";\n"); + return true; + } case kIROp_AtomicStore: - { - emitDereferenceOperand(inst->getOperand(0), getInfo(EmitOp::General)); - m_writer->emit(" = "); - emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); - m_writer->emit(";\n"); - return true; - } + { + emitDereferenceOperand(inst->getOperand(0), getInfo(EmitOp::General)); + m_writer->emit(" = "); + emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); + m_writer->emit(";\n"); + return true; + } case kIROp_AtomicExchange: - { - emitType(inst->getDataType(), getName(inst)); - m_writer->emit(";\n"); - m_writer->emit("InterlockedExchange"); - m_writer->emit("("); - emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); - m_writer->emit(", "); - emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); - m_writer->emit(", "); - m_writer->emit(getName(inst)); - m_writer->emit(");\n"); - return true; - } + { + emitType(inst->getDataType(), getName(inst)); + m_writer->emit(";\n"); + m_writer->emit("InterlockedExchange"); + m_writer->emit("("); + emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); + m_writer->emit(", "); + emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); + m_writer->emit(", "); + m_writer->emit(getName(inst)); + m_writer->emit(");\n"); + return true; + } case kIROp_AtomicCompareExchange: - { - emitType(inst->getDataType(), getName(inst)); - m_writer->emit(";\n"); - m_writer->emit("InterlockedCompareExchange"); - if (inst->getDataType()->getOp() == kIROp_FloatType) - m_writer->emit("FloatBitwise"); - m_writer->emit("("); - emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); - m_writer->emit(", "); - emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); - m_writer->emit(", "); - emitOperand(inst->getOperand(2), getInfo(EmitOp::General)); - m_writer->emit(", "); - m_writer->emit(getName(inst)); - m_writer->emit(");\n"); - return true; - } + { + emitType(inst->getDataType(), getName(inst)); + m_writer->emit(";\n"); + m_writer->emit("InterlockedCompareExchange"); + if (inst->getDataType()->getOp() == kIROp_FloatType) + m_writer->emit("FloatBitwise"); + m_writer->emit("("); + emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); + m_writer->emit(", "); + emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); + m_writer->emit(", "); + emitOperand(inst->getOperand(2), getInfo(EmitOp::General)); + m_writer->emit(", "); + m_writer->emit(getName(inst)); + m_writer->emit(");\n"); + return true; + } case kIROp_AtomicAdd: - { - emitType(inst->getDataType(), getName(inst)); - m_writer->emit(";\n"); - if (inst->getDataType()->getOp() == kIROp_FloatType) { - diagnoseFloatAtommic(); + emitType(inst->getDataType(), getName(inst)); + m_writer->emit(";\n"); + if (inst->getDataType()->getOp() == kIROp_FloatType) + { + diagnoseFloatAtommic(); + } + m_writer->emit("InterlockedAdd"); + m_writer->emit("("); + emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); + m_writer->emit(", "); + emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); + m_writer->emit(", "); + m_writer->emit(getName(inst)); + m_writer->emit(");\n"); + return true; } - m_writer->emit("InterlockedAdd"); - m_writer->emit("("); - emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); - m_writer->emit(", "); - emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); - m_writer->emit(", "); - m_writer->emit(getName(inst)); - m_writer->emit(");\n"); - return true; - } case kIROp_AtomicSub: - { - emitType(inst->getDataType(), getName(inst)); - m_writer->emit(";\n"); - if (inst->getDataType()->getOp() == kIROp_FloatType) { - diagnoseFloatAtommic(); + emitType(inst->getDataType(), getName(inst)); + m_writer->emit(";\n"); + if (inst->getDataType()->getOp() == kIROp_FloatType) + { + diagnoseFloatAtommic(); + } + m_writer->emit("InterlockedAdd"); + m_writer->emit("("); + emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); + m_writer->emit(", -("); + emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); + m_writer->emit("), "); + m_writer->emit(getName(inst)); + m_writer->emit(");\n"); + return true; } - m_writer->emit("InterlockedAdd"); - m_writer->emit("("); - emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); - m_writer->emit(", -("); - emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); - m_writer->emit("), "); - m_writer->emit(getName(inst)); - m_writer->emit(");\n"); - return true; - } case kIROp_AtomicAnd: - { - emitType(inst->getDataType(), getName(inst)); - m_writer->emit(";\n"); - m_writer->emit("InterlockedAnd"); - m_writer->emit("("); - emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); - m_writer->emit(", "); - emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); - m_writer->emit(", "); - m_writer->emit(getName(inst)); - m_writer->emit(");\n"); - return true; - } + { + emitType(inst->getDataType(), getName(inst)); + m_writer->emit(";\n"); + m_writer->emit("InterlockedAnd"); + m_writer->emit("("); + emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); + m_writer->emit(", "); + emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); + m_writer->emit(", "); + m_writer->emit(getName(inst)); + m_writer->emit(");\n"); + return true; + } case kIROp_AtomicOr: - { - emitType(inst->getDataType(), getName(inst)); - m_writer->emit(";\n"); - m_writer->emit("InterlockedOr"); - m_writer->emit("("); - emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); - m_writer->emit(", "); - emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); - m_writer->emit(", "); - m_writer->emit(getName(inst)); - m_writer->emit(");\n"); - return true; - } + { + emitType(inst->getDataType(), getName(inst)); + m_writer->emit(";\n"); + m_writer->emit("InterlockedOr"); + m_writer->emit("("); + emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); + m_writer->emit(", "); + emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); + m_writer->emit(", "); + m_writer->emit(getName(inst)); + m_writer->emit(");\n"); + return true; + } case kIROp_AtomicXor: - { - emitType(inst->getDataType(), getName(inst)); - m_writer->emit(";\n"); - m_writer->emit("InterlockedXor"); - m_writer->emit("("); - emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); - m_writer->emit(", "); - emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); - m_writer->emit(", "); - m_writer->emit(getName(inst)); - m_writer->emit(");\n"); - return true; - } + { + emitType(inst->getDataType(), getName(inst)); + m_writer->emit(";\n"); + m_writer->emit("InterlockedXor"); + m_writer->emit("("); + emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); + m_writer->emit(", "); + emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); + m_writer->emit(", "); + m_writer->emit(getName(inst)); + m_writer->emit(");\n"); + return true; + } case kIROp_AtomicMin: - { - emitType(inst->getDataType(), getName(inst)); - m_writer->emit(";\n"); - m_writer->emit("InterlockedMin"); - m_writer->emit("("); - emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); - m_writer->emit(", "); - emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); - m_writer->emit(", "); - m_writer->emit(getName(inst)); - m_writer->emit(");\n"); - return true; - } + { + emitType(inst->getDataType(), getName(inst)); + m_writer->emit(";\n"); + m_writer->emit("InterlockedMin"); + m_writer->emit("("); + emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); + m_writer->emit(", "); + emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); + m_writer->emit(", "); + m_writer->emit(getName(inst)); + m_writer->emit(");\n"); + return true; + } case kIROp_AtomicMax: - { - emitType(inst->getDataType(), getName(inst)); - m_writer->emit(";\n"); - m_writer->emit("InterlockedMax"); - m_writer->emit("("); - emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); - m_writer->emit(", "); - emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); - m_writer->emit(", "); - m_writer->emit(getName(inst)); - m_writer->emit(");\n"); - return true; - } + { + emitType(inst->getDataType(), getName(inst)); + m_writer->emit(";\n"); + m_writer->emit("InterlockedMax"); + m_writer->emit("("); + emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); + m_writer->emit(", "); + emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); + m_writer->emit(", "); + m_writer->emit(getName(inst)); + m_writer->emit(");\n"); + return true; + } case kIROp_AtomicInc: - { - emitType(inst->getDataType(), getName(inst)); - m_writer->emit(";\n"); - m_writer->emit("InterlockedAdd"); - m_writer->emit("("); - emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); - m_writer->emit(", 1, "); - m_writer->emit(getName(inst)); - m_writer->emit(");\n"); - return true; - } + { + emitType(inst->getDataType(), getName(inst)); + m_writer->emit(";\n"); + m_writer->emit("InterlockedAdd"); + m_writer->emit("("); + emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); + m_writer->emit(", 1, "); + m_writer->emit(getName(inst)); + m_writer->emit(");\n"); + return true; + } case kIROp_AtomicDec: - { - emitType(inst->getDataType(), getName(inst)); - m_writer->emit(";\n"); - m_writer->emit("InterlockedAdd"); - m_writer->emit("("); - emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); - m_writer->emit(", -1, "); - m_writer->emit(getName(inst)); - m_writer->emit(");"); - return true; - } - default: - return false; + { + emitType(inst->getDataType(), getName(inst)); + m_writer->emit(";\n"); + m_writer->emit("InterlockedAdd"); + m_writer->emit("("); + emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); + m_writer->emit(", -1, "); + m_writer->emit(getName(inst)); + m_writer->emit(");"); + return true; + } + default: return false; } } @@ -690,13 +704,13 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu { switch (inst->getOp()) { - case kIROp_ControlBarrier: + case kIROp_ControlBarrier: { m_writer->emit("GroupMemoryBatrierWithGroupSync();\n"); return true; } - case kIROp_MakeVector: - case kIROp_MakeMatrix: + case kIROp_MakeVector: + case kIROp_MakeMatrix: { if (inst->getOperandCount() == 1) { @@ -718,7 +732,7 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu } break; } - case kIROp_BitCast: + case kIROp_BitCast: { // For simplicity, we will handle all bit-cast operations // by first casting the "from" type to an intermediate @@ -737,85 +751,77 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu auto toType = extractBaseType(inst->getDataType()); switch (toType) { - default: - diagnoseUnhandledInst(inst); - break; - - case BaseType::Int8: - case BaseType::Int16: - case BaseType::Int: - case BaseType::Int64: - case BaseType::IntPtr: - case BaseType::UInt8: - case BaseType::UInt16: - case BaseType::UInt: - case BaseType::UInt64: - case BaseType::UIntPtr: - case BaseType::Bool: - // Because the intermediate type will always - // be an integer type, we can convert to - // another integer type of the same size - // via a cast. - m_writer->emit("("); - emitType(inst->getDataType()); - m_writer->emit(")"); - break; - case BaseType::Half: - m_writer->emit("asfloat16"); - break; - case BaseType::Float: - // Note: at present HLSL only supports - // reinterpreting integer bits as a `float`. - // - // There is no current function (it seems) - // for bit-casting an `int16_t` to a `half`. - // - // TODO: There is an `asdouble` function - // for converting two 32-bit integer values into - // one `double`. We could use that for - // bit casts of 64-bit values with a bit of - // extra work, but doing so might be best - // handled in an IR pass that legalizes - // bit-casts. - // - m_writer->emit("asfloat"); - break; + default: diagnoseUnhandledInst(inst); break; + + case BaseType::Int8: + case BaseType::Int16: + case BaseType::Int: + case BaseType::Int64: + case BaseType::IntPtr: + case BaseType::UInt8: + case BaseType::UInt16: + case BaseType::UInt: + case BaseType::UInt64: + case BaseType::UIntPtr: + case BaseType::Bool: + // Because the intermediate type will always + // be an integer type, we can convert to + // another integer type of the same size + // via a cast. + m_writer->emit("("); + emitType(inst->getDataType()); + m_writer->emit(")"); + break; + case BaseType::Half: m_writer->emit("asfloat16"); break; + case BaseType::Float: + // Note: at present HLSL only supports + // reinterpreting integer bits as a `float`. + // + // There is no current function (it seems) + // for bit-casting an `int16_t` to a `half`. + // + // TODO: There is an `asdouble` function + // for converting two 32-bit integer values into + // one `double`. We could use that for + // bit casts of 64-bit values with a bit of + // extra work, but doing so might be best + // handled in an IR pass that legalizes + // bit-casts. + // + m_writer->emit("asfloat"); + break; } m_writer->emit("("); int closeCount = 1; auto fromType = extractBaseType(inst->getOperand(0)->getDataType()); - switch( fromType ) + switch (fromType) { - default: - diagnoseUnhandledInst(inst); - break; - - case BaseType::UInt: - case BaseType::Int: - case BaseType::Bool: - break; - case BaseType::UInt16: - case BaseType::Int16: - break; - case BaseType::Float: - m_writer->emit("asuint("); - closeCount++; - break; + default: diagnoseUnhandledInst(inst); break; + + case BaseType::UInt: + case BaseType::Int: + case BaseType::Bool: break; + case BaseType::UInt16: + case BaseType::Int16: break; + case BaseType::Float: + m_writer->emit("asuint("); + closeCount++; + break; - case BaseType::Half: - m_writer->emit("asuint16("); - closeCount++; - break; + case BaseType::Half: + m_writer->emit("asuint16("); + closeCount++; + break; } emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); - while(closeCount--) + while (closeCount--) m_writer->emit(")"); return true; } - case kIROp_StringLit: + case kIROp_StringLit: { const auto handler = StringEscapeUtil::getHandler(StringEscapeUtil::Style::Slang); @@ -827,7 +833,7 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu return true; } - case kIROp_ByteAddressBufferLoad: + case kIROp_ByteAddressBufferLoad: { // HLSL byte-address buffers have two kinds of `Load` operations. // @@ -854,16 +860,16 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu // auto elementType = inst->getDataType(); IRIntegerValue elementCount = 1; - if( auto vecType = as(elementType) ) + if (auto vecType = as(elementType)) { - if( auto elementCountInst = as(vecType->getElementCount()) ) + if (auto elementCountInst = as(vecType->getElementCount())) { elementType = vecType->getElementType(); elementCount = elementCountInst->getValue(); } } - if( elementType->getOp() == kIROp_UIntType ) + if (elementType->getOp() == kIROp_UIntType) { // If we are in the case that can use `Load`/`Load2`/`Load3`/`Load4`, // then we will always prefer to use it. @@ -874,7 +880,7 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu emitOperand(inst->getOperand(0), leftSide(outerPrec, prec)); m_writer->emit(".Load"); - if( elementCount != 1 ) + if (elementCount != 1) { m_writer->emit(elementCount); } @@ -890,7 +896,7 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu // is already handled by the base `CLikeSourceEmitter` return false; } - case kIROp_ByteAddressBufferStore: + case kIROp_ByteAddressBufferStore: { // Similar to the case for a load, we want to specialize // the generated code for the case where we store a `uint` @@ -898,15 +904,15 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu // auto elementType = inst->getDataType(); IRIntegerValue elementCount = 1; - if( auto vecType = as(elementType) ) + if (auto vecType = as(elementType)) { - if( auto elementCountInst = as(vecType->getElementCount()) ) + if (auto elementCountInst = as(vecType->getElementCount())) { elementType = vecType->getElementType(); elementCount = elementCountInst->getValue(); } } - if( elementType->getOp() == kIROp_UIntType ) + if (elementType->getOp() == kIROp_UIntType) { auto outerPrec = inOuterPrec; auto prec = getInfo(EmitOp::Postfix); @@ -914,14 +920,16 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu emitOperand(inst->getOperand(0), leftSide(outerPrec, prec)); m_writer->emit(".Store"); - if( elementCount != 1 ) + if (elementCount != 1) { m_writer->emit(elementCount); } m_writer->emit("("); emitOperand(inst->getOperand(1), getInfo(EmitOp::General)); m_writer->emit(", "); - emitOperand(inst->getOperand(inst->getOperandCount() - 1), getInfo(EmitOp::General)); + emitOperand( + inst->getOperand(inst->getOperandCount() - 1), + getInfo(EmitOp::General)); m_writer->emit(")"); maybeCloseParens(needClose); @@ -933,7 +941,7 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu return false; } break; - case kIROp_NonUniformResourceIndex: + case kIROp_NonUniformResourceIndex: { // Need to emit as a Function call for HLSL m_writer->emit("NonUniformResourceIndex"); @@ -945,7 +953,7 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu return true; } break; - default: break; + default: break; } // Not handled return false; @@ -956,20 +964,19 @@ void HLSLSourceEmitter::emitVectorTypeNameImpl(IRType* elementType, IRIntegerVal // In some cases we *need* to use the built-in syntax sugar for vector types, // so we will try to emit those whenever possible. // - if( elementCount >= 1 && elementCount <= 4 ) + if (elementCount >= 1 && elementCount <= 4) { - switch( elementType->getOp() ) + switch (elementType->getOp()) { case kIROp_FloatType: case kIROp_IntType: case kIROp_UIntType: - // TODO: There are more types that need to be covered here + // TODO: There are more types that need to be covered here emitType(elementType); m_writer->emit(elementCount); return; - default: - break; + default: break; } } @@ -988,14 +995,9 @@ void HLSLSourceEmitter::emitLoopControlDecorationImpl(IRLoopControlDecoration* d { switch (decl->getMode()) { - case kIRLoopControl_Unroll: - m_writer->emit("[unroll]\n"); - break; - case kIRLoopControl_Loop: - m_writer->emit("[loop]\n"); - break; - default: - break; + case kIRLoopControl_Unroll: m_writer->emit("[unroll]\n"); break; + case kIRLoopControl_Loop: m_writer->emit("[loop]\n"); break; + default: break; } } @@ -1007,17 +1009,17 @@ static bool _canEmitExport(const Profile& profile) return (family == ProfileFamily::DX && version >= ProfileVersion::DX_6_1); } -/* virtual */void HLSLSourceEmitter::emitFuncDecorationsImpl(IRFunc* func) +/* virtual */ void HLSLSourceEmitter::emitFuncDecorationsImpl(IRFunc* func) { // Specially handle export, as we don't want to emit it multiple times - if (getTargetProgram()->getOptionSet().getBoolOption(CompilerOptionName::GenerateWholeProgram) && + if (getTargetProgram()->getOptionSet().getBoolOption( + CompilerOptionName::GenerateWholeProgram) && _canEmitExport(m_effectiveProfile)) { for (auto decoration : func->getDecorations()) { const auto op = decoration->getOp(); - if (op == kIROp_PublicDecoration || - op == kIROp_HLSLExportDecoration) + if (op == kIROp_PublicDecoration || op == kIROp_HLSLExportDecoration) { m_writer->emit("export\n"); break; @@ -1051,14 +1053,11 @@ void HLSLSourceEmitter::emitSwitchDecorationsImpl(IRSwitch* switchInst) void HLSLSourceEmitter::emitFuncDecorationImpl(IRDecoration* decoration) { - switch( decoration->getOp() ) + switch (decoration->getOp()) { - case kIROp_NoInlineDecoration: - m_writer->emit("[noinline]\n"); - break; + case kIROp_NoInlineDecoration: m_writer->emit("[noinline]\n"); break; - default: - break; + default: break; } } @@ -1067,33 +1066,33 @@ void HLSLSourceEmitter::emitSimpleValueImpl(IRInst* inst) { switch (inst->getOp()) { - case kIROp_FloatLit: + case kIROp_FloatLit: { IRConstant* constantInst = static_cast(inst); IRConstant::FloatKind kind = constantInst->getFloatKind(); switch (kind) { - case IRConstant::FloatKind::Nan: + case IRConstant::FloatKind::Nan: { m_writer->emit("(0.0 / 0.0)"); return; } - case IRConstant::FloatKind::PositiveInfinity: + case IRConstant::FloatKind::PositiveInfinity: { m_writer->emit("(1.0 / 0.0)"); return; } - case IRConstant::FloatKind::NegativeInfinity: + case IRConstant::FloatKind::NegativeInfinity: { m_writer->emit("(-1.0 / 0.0)"); return; } - default: break; + default: break; } break; } - default: break; + default: break; } Super::emitSimpleValueImpl(inst); @@ -1103,49 +1102,41 @@ void HLSLSourceEmitter::emitSimpleTypeImpl(IRType* type) { switch (type->getOp()) { - case kIROp_VoidType: - case kIROp_BoolType: - case kIROp_Int8Type: - case kIROp_IntType: - case kIROp_Int64Type: - case kIROp_UInt8Type: - case kIROp_UIntType: - case kIROp_UInt64Type: - case kIROp_FloatType: - case kIROp_DoubleType: - case kIROp_Int16Type: - case kIROp_UInt16Type: - case kIROp_HalfType: + case kIROp_VoidType: + case kIROp_BoolType: + case kIROp_Int8Type: + case kIROp_IntType: + case kIROp_Int64Type: + case kIROp_UInt8Type: + case kIROp_UIntType: + case kIROp_UInt64Type: + case kIROp_FloatType: + case kIROp_DoubleType: + case kIROp_Int16Type: + case kIROp_UInt16Type: + case kIROp_HalfType: { m_writer->emit(getDefaultBuiltinTypeName(type->getOp())); return; } #if SLANG_PTR_IS_64 - case kIROp_IntPtrType: - m_writer->emit("int64_t"); - return; - case kIROp_UIntPtrType: - m_writer->emit("uint64_t"); - return; + case kIROp_IntPtrType: m_writer->emit("int64_t"); return; + case kIROp_UIntPtrType: m_writer->emit("uint64_t"); return; #else - case kIROp_IntPtrType: - m_writer->emit("int"); - return; - case kIROp_UIntPtrType: - m_writer->emit("uint"); - return; + case kIROp_IntPtrType: m_writer->emit("int"); return; + case kIROp_UIntPtrType: m_writer->emit("uint"); return; #endif - case kIROp_StructType: - m_writer->emit(getName(type)); - return; + case kIROp_StructType: m_writer->emit(getName(type)); return; - case kIROp_VectorType: + case kIROp_VectorType: { auto vecType = (IRVectorType*)type; - emitVectorTypeNameImpl(vecType->getElementType(), getIntVal(vecType->getElementCount())); + emitVectorTypeNameImpl( + vecType->getElementType(), + getIntVal(vecType->getElementCount())); return; } - case kIROp_MatrixType: + case kIROp_MatrixType: { auto matType = (IRMatrixType*)type; bool canUseSugar = true; @@ -1153,12 +1144,8 @@ void HLSLSourceEmitter::emitSimpleTypeImpl(IRType* type) { case kIROp_IntType: case kIROp_UIntType: - case kIROp_FloatType: - canUseSugar = true; - break; - default: - canUseSugar = false; - break; + case kIROp_FloatType: canUseSugar = true; break; + default: canUseSugar = false; break; } if (!as(matType->getRowCount()) || !as(matType->getColumnCount())) canUseSugar = false; @@ -1181,50 +1168,50 @@ void HLSLSourceEmitter::emitSimpleTypeImpl(IRType* type) } return; } - case kIROp_SamplerStateType: - case kIROp_SamplerComparisonStateType: + case kIROp_SamplerStateType: + case kIROp_SamplerComparisonStateType: { auto samplerStateType = cast(type); switch (samplerStateType->getOp()) { - case kIROp_SamplerStateType: m_writer->emit("SamplerState"); break; - case kIROp_SamplerComparisonStateType: m_writer->emit("SamplerComparisonState"); break; - default: - SLANG_DIAGNOSE_UNEXPECTED(getSink(), SourceLoc(), "unhandled sampler state flavor"); - break; + case kIROp_SamplerStateType: m_writer->emit("SamplerState"); break; + case kIROp_SamplerComparisonStateType: m_writer->emit("SamplerComparisonState"); break; + default: + SLANG_DIAGNOSE_UNEXPECTED(getSink(), SourceLoc(), "unhandled sampler state flavor"); + break; } return; } - case kIROp_NativeStringType: - case kIROp_StringType: + case kIROp_NativeStringType: + case kIROp_StringType: { - m_writer->emit("int"); + m_writer->emit("int"); return; } - case kIROp_RayQueryType: + case kIROp_RayQueryType: { m_writer->emit("RayQuery<"); emitSimpleValue(type->getOperand(0)); m_writer->emit(" >"); return; } - case kIROp_HitObjectType: + case kIROp_HitObjectType: { m_writer->emit("NvHitObject"); return; } - case kIROp_TextureFootprintType: + case kIROp_TextureFootprintType: { m_writer->emit("uint4"); return; } - case kIROp_AtomicType: + case kIROp_AtomicType: { emitSimpleTypeImpl(cast(type)->getElementType()); return; } - default: break; + default: break; } // TODO: Ideally the following should be data-driven, @@ -1249,15 +1236,19 @@ void HLSLSourceEmitter::emitSimpleTypeImpl(IRType* type) { switch (structuredBufferType->getOp()) { - case kIROp_HLSLStructuredBufferType: m_writer->emit("StructuredBuffer"); break; - case kIROp_HLSLRWStructuredBufferType: m_writer->emit("RWStructuredBuffer"); break; - case kIROp_HLSLRasterizerOrderedStructuredBufferType: m_writer->emit("RasterizerOrderedStructuredBuffer"); break; - case kIROp_HLSLAppendStructuredBufferType: m_writer->emit("AppendStructuredBuffer"); break; - case kIROp_HLSLConsumeStructuredBufferType: m_writer->emit("ConsumeStructuredBuffer"); break; + case kIROp_HLSLStructuredBufferType: m_writer->emit("StructuredBuffer"); break; + case kIROp_HLSLRWStructuredBufferType: m_writer->emit("RWStructuredBuffer"); break; + case kIROp_HLSLRasterizerOrderedStructuredBufferType: + m_writer->emit("RasterizerOrderedStructuredBuffer"); + break; + case kIROp_HLSLAppendStructuredBufferType: m_writer->emit("AppendStructuredBuffer"); break; + case kIROp_HLSLConsumeStructuredBufferType: + m_writer->emit("ConsumeStructuredBuffer"); + break; - default: - SLANG_DIAGNOSE_UNEXPECTED(getSink(), SourceLoc(), "unhandled structured buffer type"); - break; + default: + SLANG_DIAGNOSE_UNEXPECTED(getSink(), SourceLoc(), "unhandled structured buffer type"); + break; } m_writer->emit("<"); @@ -1270,28 +1261,31 @@ void HLSLSourceEmitter::emitSimpleTypeImpl(IRType* type) { switch (type->getOp()) { - case kIROp_HLSLByteAddressBufferType: m_writer->emit("ByteAddressBuffer"); break; - case kIROp_HLSLRWByteAddressBufferType: m_writer->emit("RWByteAddressBuffer"); break; - case kIROp_HLSLRasterizerOrderedByteAddressBufferType: m_writer->emit("RasterizerOrderedByteAddressBuffer"); break; - case kIROp_RaytracingAccelerationStructureType: m_writer->emit("RaytracingAccelerationStructure"); break; - default: - SLANG_DIAGNOSE_UNEXPECTED(getSink(), SourceLoc(), "unhandled buffer type"); - break; + case kIROp_HLSLByteAddressBufferType: m_writer->emit("ByteAddressBuffer"); break; + case kIROp_HLSLRWByteAddressBufferType: m_writer->emit("RWByteAddressBuffer"); break; + case kIROp_HLSLRasterizerOrderedByteAddressBufferType: + m_writer->emit("RasterizerOrderedByteAddressBuffer"); + break; + case kIROp_RaytracingAccelerationStructureType: + m_writer->emit("RaytracingAccelerationStructure"); + break; + default: SLANG_DIAGNOSE_UNEXPECTED(getSink(), SourceLoc(), "unhandled buffer type"); break; } return; } - else if(auto specializedType = as(type)) + else if (auto specializedType = as(type)) { // If a `specialize` instruction made it this far, then // it represents an intrinsic generic type. // - emitSimpleType((IRType*) getSpecializedValue(specializedType)); + emitSimpleType((IRType*)getSpecializedValue(specializedType)); m_writer->emit("<"); UInt argCount = specializedType->getArgCount(); for (UInt ii = 0; ii < argCount; ++ii) { - if (ii != 0) m_writer->emit(", "); + if (ii != 0) + m_writer->emit(", "); emitVal(specializedType->getArg(ii), getInfo(EmitOp::General)); } m_writer->emit(" >"); @@ -1309,7 +1303,8 @@ void HLSLSourceEmitter::emitSimpleTypeImpl(IRType* type) m_writer->emit("<"); for (UInt ii = 0; ii < operandCount; ++ii) { - if (ii != 0) m_writer->emit(", "); + if (ii != 0) + m_writer->emit(", "); emitVal(type->getOperand(ii), getInfo(EmitOp::General)); } m_writer->emit(" >"); @@ -1317,7 +1312,9 @@ void HLSLSourceEmitter::emitSimpleTypeImpl(IRType* type) } } -void HLSLSourceEmitter::emitRateQualifiersAndAddressSpaceImpl(IRRate* rate, [[maybe_unused]] AddressSpace addressSpace) +void HLSLSourceEmitter::emitRateQualifiersAndAddressSpaceImpl( + IRRate* rate, + [[maybe_unused]] AddressSpace addressSpace) { if (as(rate)) { @@ -1343,17 +1340,10 @@ void HLSLSourceEmitter::emitSemanticsImpl(IRInst* inst, bool allowOffsets) { switch (packOffsetDecoration->getComponentOffset()->getValue()) { - case 0: - break; - case 1: - m_writer->emit(".y"); - break; - case 2: - m_writer->emit(".z"); - break; - case 3: - m_writer->emit(".w"); - break; + case 0: break; + case 1: m_writer->emit(".y"); break; + case 2: m_writer->emit(".z"); break; + case 3: m_writer->emit(".w"); break; } } m_writer->emit(")"); @@ -1361,9 +1351,9 @@ void HLSLSourceEmitter::emitSemanticsImpl(IRInst* inst, bool allowOffsets) } } - if( auto readAccessSemantic = inst->findDecoration()) + if (auto readAccessSemantic = inst->findDecoration()) _emitStageAccessSemantic(readAccessSemantic, "read"); - if( auto writeAccessSemantic = inst->findDecoration()) + if (auto writeAccessSemantic = inst->findDecoration()) _emitStageAccessSemantic(writeAccessSemantic, "write"); if (auto layoutDecoration = inst->findDecoration()) @@ -1383,18 +1373,21 @@ void HLSLSourceEmitter::emitSemanticsImpl(IRInst* inst, bool allowOffsets) } } -void HLSLSourceEmitter::_emitStageAccessSemantic(IRStageAccessDecoration* decoration, const char* name) +void HLSLSourceEmitter::_emitStageAccessSemantic( + IRStageAccessDecoration* decoration, + const char* name) { Int stageCount = decoration->getStageCount(); - if(stageCount == 0) + if (stageCount == 0) return; m_writer->emit(" : "); m_writer->emit(name); m_writer->emit("("); - for( Int i = 0; i < stageCount; ++i ) + for (Int i = 0; i < stageCount; ++i) { - if(i != 0) m_writer->emit(", "); + if (i != 0) + m_writer->emit(", "); m_writer->emit(decoration->getStageName(i)); } m_writer->emit(")"); @@ -1402,7 +1395,7 @@ void HLSLSourceEmitter::_emitStageAccessSemantic(IRStageAccessDecoration* decora void HLSLSourceEmitter::emitPostKeywordTypeAttributesImpl(IRInst* inst) { - if( const auto payloadDecoration = inst->findDecoration() ) + if (const auto payloadDecoration = inst->findDecoration()) { m_writer->emit("[payload] "); } @@ -1410,11 +1403,9 @@ void HLSLSourceEmitter::emitPostKeywordTypeAttributesImpl(IRInst* inst) void HLSLSourceEmitter::_emitPrefixTypeAttr(IRAttr* attr) { - switch( attr->getOp() ) + switch (attr->getOp()) { - default: - Super::_emitPrefixTypeAttr(attr); - break; + default: Super::_emitPrefixTypeAttr(attr); break; case kIROp_UNormAttr: m_writer->emit("unorm "); break; case kIROp_SNormAttr: m_writer->emit("snorm "); break; @@ -1433,12 +1424,12 @@ void HLSLSourceEmitter::emitSimpleFuncParamImpl(IRParam* param) { switch (decor->getOp()) { - case kIROp_TriangleInputPrimitiveTypeDecoration: m_writer->emit("triangle "); break; - case kIROp_PointInputPrimitiveTypeDecoration: m_writer->emit("point "); break; - case kIROp_LineInputPrimitiveTypeDecoration: m_writer->emit("line "); break; - case kIROp_LineAdjInputPrimitiveTypeDecoration: m_writer->emit("lineadj "); break; - case kIROp_TriangleAdjInputPrimitiveTypeDecoration: m_writer->emit("triangleadj "); break; - default: SLANG_ASSERT(!"Unknown primitive type"); break; + case kIROp_TriangleInputPrimitiveTypeDecoration: m_writer->emit("triangle "); break; + case kIROp_PointInputPrimitiveTypeDecoration: m_writer->emit("point "); break; + case kIROp_LineInputPrimitiveTypeDecoration: m_writer->emit("line "); break; + case kIROp_LineAdjInputPrimitiveTypeDecoration: m_writer->emit("lineadj "); break; + case kIROp_TriangleAdjInputPrimitiveTypeDecoration: m_writer->emit("triangleadj "); break; + default: SLANG_ASSERT(!"Unknown primitive type"); break; } } @@ -1449,17 +1440,22 @@ static UnownedStringSlice _getInterpolationModifierText(IRInterpolationMode mode { switch (mode) { - case IRInterpolationMode::PerVertex: - case IRInterpolationMode::NoInterpolation: return UnownedStringSlice::fromLiteral("nointerpolation"); - case IRInterpolationMode::NoPerspective: return UnownedStringSlice::fromLiteral("noperspective"); - case IRInterpolationMode::Linear: return UnownedStringSlice::fromLiteral("linear"); - case IRInterpolationMode::Sample: return UnownedStringSlice::fromLiteral("sample"); - case IRInterpolationMode::Centroid: return UnownedStringSlice::fromLiteral("centroid"); - default: return UnownedStringSlice(); + case IRInterpolationMode::PerVertex: + case IRInterpolationMode::NoInterpolation: + return UnownedStringSlice::fromLiteral("nointerpolation"); + case IRInterpolationMode::NoPerspective: + return UnownedStringSlice::fromLiteral("noperspective"); + case IRInterpolationMode::Linear: return UnownedStringSlice::fromLiteral("linear"); + case IRInterpolationMode::Sample: return UnownedStringSlice::fromLiteral("sample"); + case IRInterpolationMode::Centroid: return UnownedStringSlice::fromLiteral("centroid"); + default: return UnownedStringSlice(); } } -void HLSLSourceEmitter::emitInterpolationModifiersImpl(IRInst* varInst, IRType* valueType, IRVarLayout* layout) +void HLSLSourceEmitter::emitInterpolationModifiersImpl( + IRInst* varInst, + IRType* valueType, + IRVarLayout* layout) { SLANG_UNUSED(layout); SLANG_UNUSED(valueType); @@ -1470,7 +1466,7 @@ void HLSLSourceEmitter::emitInterpolationModifiersImpl(IRInst* varInst, IRType* continue; auto decoration = (IRInterpolationModeDecoration*)dd; - + UnownedStringSlice modeText = _getInterpolationModifierText(decoration->getMode()); if (modeText.getLength() > 0) { @@ -1480,7 +1476,10 @@ void HLSLSourceEmitter::emitInterpolationModifiersImpl(IRInst* varInst, IRType* } } -void HLSLSourceEmitter::emitPackOffsetModifier(IRInst* varInst, IRType* valueType, IRPackOffsetDecoration* layout) +void HLSLSourceEmitter::emitPackOffsetModifier( + IRInst* varInst, + IRType* valueType, + IRPackOffsetDecoration* layout) { SLANG_UNUSED(varInst); SLANG_UNUSED(valueType); @@ -1490,18 +1489,17 @@ void HLSLSourceEmitter::emitPackOffsetModifier(IRInst* varInst, IRType* valueTyp void HLSLSourceEmitter::emitMeshShaderModifiersImpl(IRInst* varInst) { - if(auto modifier = varInst->findDecoration()) + if (auto modifier = varInst->findDecoration()) { // DXC requires that mesh payload parameters have "out" specified - const char* s = - as(modifier) ? "out vertices " - : as(modifier) ? "out indices " - : as(modifier) ? "out primitives " - : nullptr; + const char* s = as(modifier) ? "out vertices " + : as(modifier) ? "out indices " + : as(modifier) ? "out primitives " + : nullptr; SLANG_ASSERT(s && "Unhandled type of mesh output decoration"); m_writer->emit(s); } - if(varInst->findDecoration()) + if (varInst->findDecoration()) { // DXC requires that mesh payload parameters have "in" specified m_writer->emit("in payload "); @@ -1510,12 +1508,12 @@ void HLSLSourceEmitter::emitMeshShaderModifiersImpl(IRInst* varInst) void HLSLSourceEmitter::emitVarDecorationsImpl(IRInst* varDecl) { - for(auto decoration : varDecl->getDecorations()) + for (auto decoration : varDecl->getDecorations()) { if (auto collection = as(decoration)) { auto flags = collection->getMemoryQualifierBit(); - if(flags & MemoryQualifierSetModifier::Flags::kCoherent) + if (flags & MemoryQualifierSetModifier::Flags::kCoherent) m_writer->emit("globallycoherent\n"); continue; } @@ -1532,27 +1530,22 @@ void HLSLSourceEmitter::emitMatrixLayoutModifiersImpl(IRType* type) { switch (matrixLayout) { - case SLANG_MATRIX_LAYOUT_COLUMN_MAJOR: - m_writer->emit("column_major "); - break; - case SLANG_MATRIX_LAYOUT_ROW_MAJOR: - m_writer->emit("row_major "); - break; - default: - break; + case SLANG_MATRIX_LAYOUT_COLUMN_MAJOR: m_writer->emit("column_major "); break; + case SLANG_MATRIX_LAYOUT_ROW_MAJOR: m_writer->emit("row_major "); break; + default: break; } } } void HLSLSourceEmitter::handleRequiredCapabilitiesImpl(IRInst* inst) { - if(inst->findDecoration()) + if (inst->findDecoration()) { m_extensionTracker->m_requiresNVAPI = true; } } -void HLSLSourceEmitter::emitFrontMatterImpl(TargetRequest*) +void HLSLSourceEmitter::emitFrontMatterImpl(TargetRequest*) { if (m_extensionTracker->m_requiresNVAPI) { @@ -1562,7 +1555,7 @@ void HLSLSourceEmitter::emitFrontMatterImpl(TargetRequest*) // m_writer->emit("#define SLANG_HLSL_ENABLE_NVAPI 1\n"); - // TODO(JS): For now when using NVAPI for generated code we do not want to + // TODO(JS): For now when using NVAPI for generated code we do not want to // use HLSL2021 features, that are typically used for Shader Execution Reordering // so we turn on the 'macro' based interface by default m_writer->emit(toSlice("#define NV_HITOBJECT_USE_MACRO_API 1\n")); @@ -1609,9 +1602,7 @@ void HLSLSourceEmitter::emitFrontMatterImpl(TargetRequest*) switch (getTargetProgram()->getOptionSet().getMatrixLayoutMode()) { case kMatrixLayoutMode_RowMajor: - default: - m_writer->emit("#pragma pack_matrix(row_major)\n"); - break; + default: m_writer->emit("#pragma pack_matrix(row_major)\n"); break; case kMatrixLayoutMode_ColumnMajor: m_writer->emit("#pragma pack_matrix(column_major)\n"); break; @@ -1620,7 +1611,7 @@ void HLSLSourceEmitter::emitFrontMatterImpl(TargetRequest*) void HLSLSourceEmitter::emitGlobalInstImpl(IRInst* inst) { - if( const auto nvapiDecor = inst->findDecoration() ) + if (const auto nvapiDecor = inst->findDecoration()) { // When emitting one of the "magic" NVAPI declarations, // we will wrap it in a preprocessor conditional that @@ -1642,7 +1633,7 @@ void HLSLSourceEmitter::emitGlobalInstImpl(IRInst* inst) // but field keys don't produce anything in the output, so // we'd have conditionals that are wrapping empty lines. // - if( !as(inst) ) + if (!as(inst)) { m_writer->emit("#ifndef SLANG_HLSL_ENABLE_NVAPI\n"); Super::emitGlobalInstImpl(inst); @@ -1655,5 +1646,4 @@ void HLSLSourceEmitter::emitGlobalInstImpl(IRInst* inst) } - } // namespace Slang -- cgit v1.2.3