Skip to content

Commit

Permalink
WGSL: Fix issue where swizzle L-values are generated (shader-slang#5682)
Browse files Browse the repository at this point in the history
* wgsl: Do not generate L-value swizzle expressions

* Enable tests/language-feature/swizzles/matrix-swizzle-write-*.slang

The following tests are enabled

- tests/language-feature/swizzles/matrix-swizzle-write-swizzle.slang
- tests/language-feature/swizzles/matrix-swizzle-write-array.slang

This closes shader-slang#5603.
  • Loading branch information
aleino-nv authored Nov 26, 2024
1 parent 9e21cd4 commit 915e05d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
10 changes: 6 additions & 4 deletions source/slang/slang-emit-c-like.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1661,15 +1661,16 @@ bool CLikeSourceEmitter::shouldFoldInstIntoUseSites(IRInst* inst)
}
}

// For cuda and cpu targets don't support swizzle on the left-hand-side
// The cpp, cuda and wgsl targets don't support swizzle on the left-hand-side
// variable, e.g. vec4.xy = vec2 is not allowed.
// Therefore, we don't want to fold the right-hand-side expression.
// Instead, the right-hand-side expression should be generated as a separable
// statement and stored in a temporary varible, then assign to the left-hand-side
// variable per element. E.g. vec4.x = vec2.x; vec4.y = vec2.y.
if (as<IRSwizzledStore>(user))
{
if (isCPUTarget(getTargetReq()) || isCUDATarget(getTargetReq()))
if (isCPUTarget(getTargetReq()) || isCUDATarget(getTargetReq()) ||
isWGPUTarget(getTargetReq()))
return false;
}

Expand Down Expand Up @@ -3123,9 +3124,10 @@ void CLikeSourceEmitter::_emitInst(IRInst* inst)

case kIROp_SwizzledStore:
{
// cpp and cuda target don't support swizzle on the left handside, so we
// cpp, cuda and wgsl targets don't support swizzle on the left handside, so we
// have to assign the element one by one.
if (isCPUTarget(getTargetReq()) || isCUDATarget(getTargetReq()))
if (isCPUTarget(getTargetReq()) || isCUDATarget(getTargetReq()) ||
isWGPUTarget(getTargetReq()))
{
_emitSwizzleStorePerElement(inst);
}
Expand Down
2 changes: 0 additions & 2 deletions tests/expected-failure-github.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,3 @@ tests/language-feature/enums/strongly-typed-id.slang.1 syn (wgpu)
tests/language-feature/generics/tuple.slang.1 syn (wgpu)
tests/language-feature/generics/variadic-0.slang.4 syn (wgpu)
tests/language-feature/shader-params/interface-shader-param-ordinary.slang.4 syn (wgpu)
tests/language-feature/swizzles/matrix-swizzle-write-array.slang.3 syn (wgpu)
tests/language-feature/swizzles/matrix-swizzle-write-swizzle.slang.3 syn (wgpu)
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//TEST(compute):COMPARE_COMPUTE: -compute -shaderobj -output-using-type
//TEST(compute, vulkan):COMPARE_COMPUTE: -vk -compute -shaderobj -output-using-type
//TEST(compute):COMPARE_COMPUTE:-slang -shaderobj -mtl -output-using-type
// WGSL: Assign to swizzle expression not allowed #5603
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-wgpu

// Test that matrix swizzle writes work correctly
// Matrix swizzles can either be one or zero indexed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//TEST(compute):COMPARE_COMPUTE: -compute -shaderobj -output-using-type
//TEST(compute, vulkan):COMPARE_COMPUTE: -vk -compute -shaderobj -output-using-type
//TEST(compute):COMPARE_COMPUTE:-slang -shaderobj -mtl -output-using-type
// WGSL: Assign to swizzle expression not allowed #5603
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-wgpu

// Test that writing to swizzles of matrix swizzles works correctly

Expand Down

0 comments on commit 915e05d

Please sign in to comment.