yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Yong HeMake `-no-mangle` option work, add `-no-hlsl-binding`. (#3817)a23adc221

master
1.4 KiB67 linesraw
1//TEST_DISABLED:COMPARE_HLSL: -profile cs_5_0 -entry main
2
3// Test various cases of implicit type conversion and preference
4// for overload resolution.
5
6cbuffer U
7{
8	int 	ii;
9	uint 	uu;
10	float 	ff;	
11};
12
13Buffer<int> ib;
14RWBuffer<int> ob;
15
16
17int pick(int   x) 	{ return 1; }
18int pick(uint  x)	{ return 2; }
19int pick(float x) 	{ return 3; }
20
21
22int test0(int x) { return x; }
23uint test0(uint x) { return x; }
24
25// Test: is integer-to-float conversion preferred
26// over scalar-to-vector conversion?
27int test1(uint3 v) { return 0; }
28float test1(float v) { return 0; }
29
30// Is rank of signed-int-to-float the same
31// as unsigned-init-to-float?
32int test2(float f, uint u) { return 0; }
33float test2(int i, float f) { return 0; }
34
35// Is just having "more" implicit conversions
36// enough to rank overloads?
37int test3(float f, uint u, uint u2) { return 0; }
38float test3(int i, float f, float f2) { return 0; }
39
40[numthreads(1,1,1)]
41void main(uint3 tid : SV_DispatchThreadID)
42{
43	uint idx = tid.x;
44
45	bool bb = (ii + uu) != 0;
46
47#define CASE(exp) ob[ib[idx++]] = pick(exp)
48
49	CASE(ii + uu);
50	CASE(uu + ii);
51	CASE(ii + ff);
52	CASE(uu + ff);
53
54	// Should be ambiguous, but currently isn't:
55//	CASE(test0(bb));
56
57	CASE(test1(uu));
58
59	// Ambiguous, and it should be
60//	CASE(test2(ii, uu));
61
62	// Prefer overload with lower overall converion cost
63	// (not necessarily one that is unambiguously "better"
64	// at every argument position).
65	//
66	CASE(test3(ii, uu, uu));
67}