Skip to content

Commit

Permalink
Add wgsl missing float image format inference (#5716)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
4 people authored Dec 5, 2024
1 parent 27ee133 commit ce23f07
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions source/slang/slang-emit-wgsl.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ce23f07

Please sign in to comment.