yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
54e1d0271
master
1//TEST:SIMPLE(filecheck=CHECK):-target cuda -entry computeMain -stage compute 2 3// Test on a regression that caused a field to be initialized twice in the ctor. 4 5// CHECK-COUNT-1: callOnce{{.*}}(int(1000)) 6// CHECK-COUNT-1: {{.*}}->origin_0 = 7int callOnce(int x) 8{ 9 *result += 1.0f; // cause some side effect so the call is not eliminated 10 return 999; 11} 12 13public struct Ray 14{ 15 public int calledOnce = callOnce(1000); 16 public float3 origin = {}; 17 public float t_min = 0; 18 public float3 dir = {}; 19 public float t_max = 0; 20 21 public __init(float3 origin, float3 dir, float t_min = 0.f, float t_max = 1000.0) 22 { 23 this.origin = origin; 24 this.dir = dir; 25 this.t_min = t_min; 26 this.t_max = t_max; 27 } 28 29 public RayDesc to_ray_desc() { return { origin, t_min, dir, t_max }; } 30}; 31 32uniform float* result; 33 34[numthreads(1,1,1)] 35void computeMain() 36{ 37 Ray r = Ray(float3(1,2,3), float3(4,5,6)); 38 RayDesc rd = r.to_ray_desc(); 39 *result = rd.Direction.x; 40}