Skip to content

Commit

Permalink
Fix incorrect use of pointer in WGSL (#5144)
Browse files Browse the repository at this point in the history
Closes #5143

Recently there was a commit that changed the behavior of the memory
pointer for WGSL.

This commit fixes some issues came up after the change.
  • Loading branch information
jkwak-work authored Sep 23, 2024
1 parent 53684ed commit 6912c58
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions source/slang/hlsl.meta.slang
Original file line number Diff line number Diff line change
Expand Up @@ -9039,7 +9039,7 @@ __generic<T : __BuiltinFloatingPointType>
[require(wgsl)]
void __wgsl_frexp(T x, out T fract, out int exp)
{
__intrinsic_asm "{ var s = frexp($0); (*($1)) = s.fract; (*($2)) = s.exp; }";
__intrinsic_asm "{ var s = frexp($0); ($1) = s.fract; ($2) = s.exp; }";
}

__generic<T : __BuiltinFloatingPointType, let N : int>
Expand Down Expand Up @@ -9071,7 +9071,7 @@ __generic<T : __BuiltinFloatingPointType, let N : int>
[require(wgsl)]
void __wgsl_frexp(vector<T, N> x, out vector<T, N> fract, out vector<int, N> exp)
{
__intrinsic_asm "{ var s = frexp($0); (*($1)) = s.fract; (*($2)) = s.exp; }";
__intrinsic_asm "{ var s = frexp($0); ($1) = s.fract; ($2) = s.exp; }";
}

__generic<T : __BuiltinFloatingPointType, let N : int, let M : int, let L : int>
Expand Down Expand Up @@ -11469,7 +11469,7 @@ __generic<T : __BuiltinFloatingPointType>
[require(wgsl)]
void __wgsl_modf(T x, out T fract, out T whole)
{
__intrinsic_asm "{ var s = modf($0); (*($1)) = s.fract; (*($2)) = s.whole; }";
__intrinsic_asm "{ var s = modf($0); ($1) = s.fract; ($2) = s.whole; }";
}

__generic<T : __BuiltinFloatingPointType, let N : int>
Expand Down Expand Up @@ -11501,7 +11501,7 @@ __generic<T : __BuiltinFloatingPointType, let N : int>
[require(wgsl)]
void __wgsl_modf(vector<T,N> x, out vector<T,N> fract, out vector<T,N> whole)
{
__intrinsic_asm "{ var s = modf($0); (*($1)) = s.fract; (*($2)) = s.whole; }";
__intrinsic_asm "{ var s = modf($0); ($1) = s.fract; ($2) = s.whole; }";
}

__generic<T : __BuiltinFloatingPointType, let N : int, let M : int, let L : int>
Expand Down
18 changes: 9 additions & 9 deletions source/slang/slang-stdlib-textures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ void TextureTypeInfo::writeGetDimensionFunctions()
++paramCount;
params << t << "width";
metal << "(*($" << String(paramCount) << ") = $0.get_width(" << String(metalMipLevel) << ")),";
wgsl << "*($" << String(paramCount) << ") = textureDimensions($0" << (includeMipInfo ? ", $1" : "") << ");";
wgsl << "($" << String(paramCount) << ") = textureDimensions($0" << (includeMipInfo ? ", $1" : "") << ");";

sizeDimCount = 1;
break;
Expand All @@ -235,12 +235,12 @@ void TextureTypeInfo::writeGetDimensionFunctions()
params << t << "width,";
metal << "(*($" << String(paramCount) << ") = $0.get_width(" << String(metalMipLevel) << ")),";
wgsl << "var dim = textureDimensions($0" << (includeMipInfo ? ", $1" : "") << ");";
wgsl << "(*$" << String(paramCount) << ") = dim.x;";
wgsl << "($" << String(paramCount) << ") = dim.x;";

++paramCount;
params << t << "height";
metal << "(*($" << String(paramCount) << ") = $0.get_height(" << String(metalMipLevel) << ")),";
wgsl << "(*$" << String(paramCount) << ") = dim.y;";
wgsl << "($" << String(paramCount) << ") = dim.y;";

sizeDimCount = 2;
break;
Expand All @@ -250,17 +250,17 @@ void TextureTypeInfo::writeGetDimensionFunctions()
params << t << "width,";
metal << "(*($" << String(paramCount) << ") = $0.get_width(" << String(metalMipLevel) << ")),";
wgsl << "var dim = textureDimensions($0" << (includeMipInfo ? ", $1" : "") << ");";
wgsl << "(*$" << String(paramCount) << ") = dim.x;";
wgsl << "($" << String(paramCount) << ") = dim.x;";

++paramCount;
params << t << "height,";
metal << "(*($" << String(paramCount) << ") = $0.get_height(" << String(metalMipLevel) << ")),";
wgsl << "(*$" << String(paramCount) << ") = dim.y;";
wgsl << "($" << String(paramCount) << ") = dim.y;";

++paramCount;
params << t << "depth";
metal << "(*($" << String(paramCount) << ") = $0.get_depth(" << String(metalMipLevel) << ")),";
wgsl << "(*$" << String(paramCount) << ") = dim.z;";
wgsl << "($" << String(paramCount) << ") = dim.z;";

sizeDimCount = 3;
break;
Expand All @@ -276,23 +276,23 @@ void TextureTypeInfo::writeGetDimensionFunctions()
++paramCount;
params << ", " << t << "elements";
metal << "(*($" << String(paramCount) << ") = $0.get_array_size()),";
wgsl << "(*$" << String(paramCount) << ") = textureNumLayers($0);";
wgsl << "($" << String(paramCount) << ") = textureNumLayers($0);";
}

if (isMultisample)
{
++paramCount;
params << ", " << t << "sampleCount";
metal << "(*($" << String(paramCount) << ") = $0.get_num_samples()),";
wgsl << "(*$" << String(paramCount) << ") = textureNumSamples($0);";
wgsl << "($" << String(paramCount) << ") = textureNumSamples($0);";
}

if (includeMipInfo)
{
++paramCount;
params << ", " << t << "numberOfLevels";
metal << "(*($" << String(paramCount) << ") = $0.get_num_mip_levels()),";
wgsl << "(*$" << String(paramCount) << ") = textureNumLevels($0);";
wgsl << "($" << String(paramCount) << ") = textureNumLevels($0);";
}

metal.reduceLength(metal.getLength() - 1); // drop the last comma
Expand Down

0 comments on commit 6912c58

Please sign in to comment.