Skip to content

Instantly share code, notes, and snippets.

@Reedbeta
Created July 8, 2014 21:24
Show Gist options
  • Save Reedbeta/16f257077f21590fb482 to your computer and use it in GitHub Desktop.
Save Reedbeta/16f257077f21590fb482 to your computer and use it in GitHub Desktop.
Indexable temporaries tests in HLSL
// This works (compiled with: fxc /T ps_5_0 /E main foo.hlsl)
float main (in uint x:X) : SV_Target0
{
float a[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
// Put some things in the array
a[x] = 47.0;
a[x&7] = 42.0;
a[(x+1)%12] = 3.14159;
// Return something from the array
return a[(x*x+3)%12];
}
// This doesn't work: gives error X3500: array reference cannot be used as an l-value; not natively addressable
struct S { float a[12]; };
float main (in uint x:X) : SV_Target0
{
S s = (S)0;
// Put some things in the array
s.a[x] = 47.0;
s.a[x&7] = 42.0;
s.a[(x+1)%12] = 3.14159;
// Return something from the array
return s.a[(x*x+3)%12];
}
@Iskanderlm
Copy link

YOU ARE THE LIGHT IN MY DARKNESS! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment