diff options
| author | Devon <devonrutledge03@gmail.com> | 2024-12-05 11:03:03 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-05 10:03:03 -0800 |
| commit | ce23f078781ae977d827a559e775250dc429709c (patch) | |
| tree | eea70bf0b400b194164ad8533834f25a5a6b8b91 /source | |
| parent | 27ee1337a0090cf28a0600758884fad405866afe (diff) | |
Add wgsl missing float image format inference (#5716)
* Add missing float image format inference
* Drop float4 inference and adjust test
* Do wgsl float format fix at emit time
* improve formatting
* format code
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-emit-wgsl.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/source/slang/slang-emit-wgsl.cpp b/source/slang/slang-emit-wgsl.cpp index d49986263..13c14cf34 100644 --- a/source/slang/slang-emit-wgsl.cpp +++ b/source/slang/slang-emit-wgsl.cpp @@ -1,5 +1,7 @@ #include "slang-emit-wgsl.h" +#include "slang-ir-util.h" + // A note on row/column "terminology reversal". // // This is an "terminology reversing" implementation in the sense that @@ -343,6 +345,38 @@ static const char* getWgslImageFormat(IRTextureTypeBase* type) // ImageFormat imageFormat = type->hasFormat() ? (ImageFormat)type->getFormat() : ImageFormat::unknown; + + if (imageFormat == ImageFormat::unknown) + { + // WGSL doesn't have a texel format for "unknown" so we try to infer float types that + // normally just resolve to unknown. + auto elementType = type->getElementType(); + Int vectorWidth = 1; + if (auto vectorType = as<IRVectorType>(elementType); + auto intLitVal = as<IRIntLit>(vectorType->getElementCount())) + { + vectorWidth = intLitVal->getValue(); + } + elementType = getVectorElementType((IRType*)elementType); + if (auto basicType = as<IRBasicType>(elementType)) + { + switch (basicType->getBaseType()) + { + case BaseType::Float: + switch (vectorWidth) + { + case 1: + return "r32float"; + case 2: + return "rg32float"; + case 4: + return "rgba32float"; + } + break; + } + } + } + switch (imageFormat) { case ImageFormat::rgba8: |
