Skip to content

Commit ce23f07

Browse files
Devon7925csyongheslangbotexpipiplus1
authored
Add wgsl missing float image format inference (shader-slang#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 <[email protected]> Co-authored-by: slangbot <[email protected]> Co-authored-by: Ellie Hermaszewska <[email protected]>
1 parent 27ee133 commit ce23f07

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

source/slang/slang-emit-wgsl.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "slang-emit-wgsl.h"
22

3+
#include "slang-ir-util.h"
4+
35
// A note on row/column "terminology reversal".
46
//
57
// This is an "terminology reversing" implementation in the sense that
@@ -343,6 +345,38 @@ static const char* getWgslImageFormat(IRTextureTypeBase* type)
343345
//
344346
ImageFormat imageFormat =
345347
type->hasFormat() ? (ImageFormat)type->getFormat() : ImageFormat::unknown;
348+
349+
if (imageFormat == ImageFormat::unknown)
350+
{
351+
// WGSL doesn't have a texel format for "unknown" so we try to infer float types that
352+
// normally just resolve to unknown.
353+
auto elementType = type->getElementType();
354+
Int vectorWidth = 1;
355+
if (auto vectorType = as<IRVectorType>(elementType);
356+
auto intLitVal = as<IRIntLit>(vectorType->getElementCount()))
357+
{
358+
vectorWidth = intLitVal->getValue();
359+
}
360+
elementType = getVectorElementType((IRType*)elementType);
361+
if (auto basicType = as<IRBasicType>(elementType))
362+
{
363+
switch (basicType->getBaseType())
364+
{
365+
case BaseType::Float:
366+
switch (vectorWidth)
367+
{
368+
case 1:
369+
return "r32float";
370+
case 2:
371+
return "rg32float";
372+
case 4:
373+
return "rgba32float";
374+
}
375+
break;
376+
}
377+
}
378+
}
379+
346380
switch (imageFormat)
347381
{
348382
case ImageFormat::rgba8:

0 commit comments

Comments
 (0)