Skip to content

Commit

Permalink
Add specializations for 1 vectors in functions using the $N glsl intr…
Browse files Browse the repository at this point in the history
…insic placement (#4534)

Closes #4533
Fixes part of #4531
  • Loading branch information
expipiplus1 authored Jul 5, 2024
1 parent 42a9fce commit 40a4022
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions source/slang/hlsl.meta.slang
Original file line number Diff line number Diff line change
Expand Up @@ -5575,6 +5575,8 @@ __generic<T : __BuiltinType, let N : int>
[require(cpp_cuda_glsl_hlsl_metal_spirv)]
bool all(vector<T,N> x)
{
if(N == 1)
return all(x[0]);
__target_switch
{
case hlsl:
Expand Down Expand Up @@ -5710,6 +5712,8 @@ __generic<T : __BuiltinType, let N : int>
[require(cpp_cuda_glsl_hlsl_metal_spirv)]
bool any(vector<T, N> x)
{
if(N == 1)
return any(x[0]);
__target_switch
{
case hlsl:
Expand Down Expand Up @@ -6066,6 +6070,8 @@ __generic<let N : int>
[require(cpp_cuda_glsl_hlsl_metal_spirv, shader5_sm_4_0)]
vector<int, N> asint(vector<uint, N> x)
{
if(N == 1)
return vector<int, N>(asint(x[0]));
__target_switch
{
case glsl: __intrinsic_asm "ivec$N0($0)";
Expand Down Expand Up @@ -6207,6 +6213,8 @@ __generic<let N : int>
[require(cpp_cuda_glsl_hlsl_metal_spirv, shader5_sm_4_0)]
vector<uint, N> asuint(vector<int, N> x)
{
if(N == 1)
return vector<uint, N>(asuint(x[0]));
__target_switch
{
case glsl: __intrinsic_asm "uvec$N0($0)";
Expand Down Expand Up @@ -12054,6 +12062,8 @@ __generic<T : __BuiltinSignedArithmeticType, let N : int>
[__readNone]
vector<int, N> sign(vector<T, N> x)
{
if(N == 1)
return vector<int, N>(sign(x[0]));
__target_switch
{
case hlsl: __intrinsic_asm "sign";
Expand Down
20 changes: 20 additions & 0 deletions tests/bugs/gh-4533.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-dx12 -use-dxil
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-mtl
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cuda

// CHECK: 0
// CHECK-NEXT: 1
// CHECK-NEXT: 1
// CHECK-NEXT: 1

//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<uint> outputBuffer;

[numthreads(4, 1, 1)]
void computeMain(uint tid : SV_GroupIndex)
{
vector<float,1> k = float1(tid);
outputBuffer[tid] = all(k) && any(k) && bool(asint(k)) && bool(asuint(k));
}

0 comments on commit 40a4022

Please sign in to comment.