diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2024-10-29 14:49:26 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-29 14:49:26 +0800 |
| commit | f65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch) | |
| tree | ea1d61342cd29368e19135000ec2948813096205 /source/slang/slang-ir-resolve-texture-format.cpp | |
| parent | a729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff) | |
format
* format
* Minor test fixes
* enable checking cpp format in ci
Diffstat (limited to 'source/slang/slang-ir-resolve-texture-format.cpp')
| -rw-r--r-- | source/slang/slang-ir-resolve-texture-format.cpp | 158 |
1 files changed, 83 insertions, 75 deletions
diff --git a/source/slang/slang-ir-resolve-texture-format.cpp b/source/slang/slang-ir-resolve-texture-format.cpp index 7cd81fc2d..09989e892 100644 --- a/source/slang/slang-ir-resolve-texture-format.cpp +++ b/source/slang/slang-ir-resolve-texture-format.cpp @@ -1,22 +1,24 @@ #include "slang-ir-resolve-texture-format.h" -#include "slang-ir-insts.h" + #include "slang-ir-clone.h" +#include "slang-ir-insts.h" namespace Slang { - static IRType* replaceImageElementType(IRInst* originalType, IRInst* newElementType) +static IRType* replaceImageElementType(IRInst* originalType, IRInst* newElementType) +{ + switch (originalType->getOp()) { - switch (originalType->getOp()) + case kIROp_ArrayType: + case kIROp_UnsizedArrayType: + case kIROp_PtrType: + case kIROp_OutType: + case kIROp_RefType: + case kIROp_ConstRefType: + case kIROp_InOutType: { - case kIROp_ArrayType: - case kIROp_UnsizedArrayType: - case kIROp_PtrType: - case kIROp_OutType: - case kIROp_RefType: - case kIROp_ConstRefType: - case kIROp_InOutType: - { - auto newInnerType = replaceImageElementType(originalType->getOperand(0), newElementType); + auto newInnerType = + replaceImageElementType(originalType->getOperand(0), newElementType); if (newInnerType != originalType->getOperand(0)) { IRBuilder builder(originalType); @@ -28,65 +30,66 @@ namespace Slang return (IRType*)originalType; } - default: - if (as<IRResourceTypeBase>(originalType)) - return (IRType*)newElementType; - return (IRType*)originalType; - } + default: + if (as<IRResourceTypeBase>(originalType)) + return (IRType*)newElementType; + return (IRType*)originalType; } +} + +static void resolveTextureFormatForParameter(IRInst* textureInst, IRTextureTypeBase* textureType) +{ + ImageFormat format = (ImageFormat)(textureType->getFormat()); + auto decor = textureInst->findDecoration<IRFormatDecoration>(); + if (!decor) + return; + if (decor->getFormat() == (ImageFormat)textureType->getFormat()) + return; - static void resolveTextureFormatForParameter(IRInst* textureInst, IRTextureTypeBase* textureType) + format = decor->getFormat(); + if (format != ImageFormat::unknown) { - ImageFormat format = (ImageFormat)(textureType->getFormat()); - auto decor = textureInst->findDecoration<IRFormatDecoration>(); - if (!decor) - return; - if (decor->getFormat() == (ImageFormat)textureType->getFormat()) - return; + IRBuilder builder(textureInst->getModule()); + builder.setInsertBefore(textureInst); + auto formatArg = builder.getIntValue(builder.getUIntType(), IRIntegerValue(format)); - format = decor->getFormat(); - if (format != ImageFormat::unknown) - { - IRBuilder builder(textureInst->getModule()); - builder.setInsertBefore(textureInst); - auto formatArg = builder.getIntValue(builder.getUIntType(), IRIntegerValue(format)); + auto newType = builder.getTextureType( + textureType->getElementType(), + textureType->getShapeInst(), + textureType->getIsArrayInst(), + textureType->getIsMultisampleInst(), + textureType->getSampleCountInst(), + textureType->getAccessInst(), + textureType->getIsShadowInst(), + textureType->getIsCombinedInst(), + formatArg); - auto newType = builder.getTextureType( - textureType->getElementType(), - textureType->getShapeInst(), - textureType->getIsArrayInst(), - textureType->getIsMultisampleInst(), - textureType->getSampleCountInst(), - textureType->getAccessInst(), - textureType->getIsShadowInst(), - textureType->getIsCombinedInst(), - formatArg); + List<IRUse*> typeReplacementWorkList; + HashSet<IRUse*> typeReplacementWorkListSet; - List<IRUse*> typeReplacementWorkList; - HashSet<IRUse*> typeReplacementWorkListSet; + auto newInstType = (IRType*)replaceImageElementType(textureInst->getFullType(), newType); + textureInst->setFullType(newInstType); - auto newInstType = (IRType*)replaceImageElementType(textureInst->getFullType(), newType); - textureInst->setFullType(newInstType); - - for (auto use = textureInst->firstUse; use; use = use->nextUse) - { - if (typeReplacementWorkListSet.add(use)) - typeReplacementWorkList.add(use); - } + for (auto use = textureInst->firstUse; use; use = use->nextUse) + { + if (typeReplacementWorkListSet.add(use)) + typeReplacementWorkList.add(use); + } - // Update the types on dependent insts. - for (Index i = 0; i < typeReplacementWorkList.getCount(); i++) + // Update the types on dependent insts. + for (Index i = 0; i < typeReplacementWorkList.getCount(); i++) + { + auto use = typeReplacementWorkList[i]; + auto user = use->getUser(); + switch (user->getOp()) { - auto use = typeReplacementWorkList[i]; - auto user = use->getUser(); - switch (user->getOp()) - { - case kIROp_GetElementPtr: - case kIROp_GetElement: - case kIROp_Load: - case kIROp_Var: + case kIROp_GetElementPtr: + case kIROp_GetElement: + case kIROp_Load: + case kIROp_Var: { - auto newUserType = (IRType*)replaceImageElementType(user->getFullType(), newType); + auto newUserType = + (IRType*)replaceImageElementType(user->getFullType(), newType); if (newUserType != user->getFullType()) { user->setFullType(newUserType); @@ -98,13 +101,14 @@ namespace Slang } break; } - case kIROp_Store: + case kIROp_Store: { auto store = as<IRStore>(user); if (use == store->getValUse()) { auto ptr = store->getPtr(); - auto newPtrType = (IRType*)replaceImageElementType(ptr->getFullType(), newType); + auto newPtrType = + (IRType*)replaceImageElementType(ptr->getFullType(), newType); if (newPtrType != ptr->getFullType()) { ptr->setFullType(newPtrType); @@ -117,26 +121,30 @@ namespace Slang } break; } - } } } } +} - void resolveTextureFormat(IRModule* module) +void resolveTextureFormat(IRModule* module) +{ + for (auto globalInst : module->getGlobalInsts()) { - for (auto globalInst : module->getGlobalInsts()) + if (as<IRTextureTypeBase>(globalInst->getDataType())) { - if (as<IRTextureTypeBase>(globalInst->getDataType())) - { - resolveTextureFormatForParameter(globalInst, (IRTextureTypeBase*)globalInst->getDataType()); - } - else if (auto arrayType = as<IRArrayTypeBase>(globalInst->getDataType())) + resolveTextureFormatForParameter( + globalInst, + (IRTextureTypeBase*)globalInst->getDataType()); + } + else if (auto arrayType = as<IRArrayTypeBase>(globalInst->getDataType())) + { + if (as<IRTextureTypeBase>(arrayType->getElementType())) { - if (as<IRTextureTypeBase>(arrayType->getElementType())) - { - resolveTextureFormatForParameter(globalInst, (IRTextureTypeBase*)arrayType->getElementType()); - } + resolveTextureFormatForParameter( + globalInst, + (IRTextureTypeBase*)arrayType->getElementType()); } } } } +} // namespace Slang |
