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 KiB56 linesraw
1//TEST:COMPARE_HLSL: -profile ps_4_0 -entry main
2
3// We want to make sure that the registers Slang generates
4// are used, even if there are "dead" parameter earlier in the program.
5//
6// In this case, we declare two each of textures, samplers, and constant
7// buffers, and then only use the second one.
8// Left to its own devices, the HLSL compiler would usually shift the
9// object that was used up to binding slot zero, and eliminate the one
10// that wasn't used.
11// We expect Slang to generate explicit annotations that stop this from
12// happening.
13
14#ifdef __SLANG__
15#define R(X) /**/
16#define BEGIN_CBUFFER(NAME) cbuffer NAME
17#define END_CBUFFER(NAME, REG) /**/
18#define CBUFFER_REF(NAME, FIELD) FIELD
19#else
20#define R(X) X
21#define BEGIN_CBUFFER(NAME) struct SLANG_ParameterGroup_##NAME
22#define END_CBUFFER(NAME, REG) ; cbuffer NAME : REG { SLANG_ParameterGroup_##NAME NAME; }
23#define CBUFFER_REF(NAME, FIELD) NAME.FIELD
24
25#define tB tB_0
26#define sB sB_0
27
28#define C1 C1_0
29#define c1 c1_0
30
31#endif
32
33float4 use(float4 val) { return val; };
34float4 use(Texture2D t, SamplerState s) { return t.Sample(s, 0.0); }
35
36Texture2D 		tA R(: register(t0));
37Texture2D 		tB R(: register(t1));
38SamplerState 	sA R(: register(s0));
39SamplerState 	sB R(: register(s1));
40
41BEGIN_CBUFFER(C0)
42{
43	float c0;
44}
45END_CBUFFER(C0, register(b0))
46
47BEGIN_CBUFFER(C1)
48{
49	float c1;
50}
51END_CBUFFER(C1, register(b1))
52
53float4 main() : SV_TARGET
54{
55	return use(tB,sB) + use(CBUFFER_REF(C1,c1));
56}