From ce23f078781ae977d827a559e775250dc429709c Mon Sep 17 00:00:00 2001 From: Devon Date: Thu, 5 Dec 2024 11:03:03 -0700 Subject: 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 Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Ellie Hermaszewska --- source/slang/slang-emit-wgsl.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'source') 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(elementType); + auto intLitVal = as(vectorType->getElementCount())) + { + vectorWidth = intLitVal->getValue(); + } + elementType = getVectorElementType((IRType*)elementType); + if (auto basicType = as(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: -- cgit v1.2.3