summaryrefslogtreecommitdiffstats
path: root/tests/hlsl-intrinsic/active-mask/for-continue.slang
blob: 31fe66eb7c4171a281bad2811bbd532ed408bd25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// for-continue.slang

// Test case of a `for` loop that
// has multiple paths to continue
// the loop (both the ordinary one
// and an explicit `continue`)

//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute 
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile cs_6_0 -xslang -DHACK
//DISABLE_TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -xslang -DHACK
//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -capability cuda_sm_7_0

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

#define THREAD_COUNT 4
#define LOC_COUNT 4
#define ITER_COUNT THREAD_COUNT
#define WRITE_VAL(LOC, ITER, VAL) buffer[tid + (LOC)*THREAD_COUNT + (ITER)*THREAD_COUNT*LOC_COUNT] = 0xA0000000 | (tid << 24) | (ITER << 16) | (LOC << 8) | VAL
#define WRITE(LOC, ITER) WRITE_VAL(LOC, ITER, WaveGetActiveMask())

//TEST_INPUT:cbuffer(data=[0 1]):name C
cbuffer C
{
	int alwaysFalse;
	int alwaysTrue;
}

// In order to make a test of `continue` behavior
// adversarial, we need to observe the value of
// the active mask during the code that executes
// on a `continue`.
//
// We therefore define a subroutine that
// will perform the increment action for an
// ordinary counted loop, allowing us to
// observe the value of the active mask inside
// the function.
//
void inc(uint tid, in out int ii)
{
	// NOTE: For our current HLSL and GLSL output
	// strategies, we end up duplicating the
	// "continue clause" of a `for` loop into
	// each of the sites in the code where control
	// flow continues the loop. Unsurprisingly,
	// those copies mean that the active mask
	// seen on those platforms is not the expected
	// one.
	//
	// We will therefore write out the expected
	// value directly instead of using `WaveGetActiveMask()`
	// on those targets.
	//
#ifdef HACK
	WRITE_VAL(3, ii, (0xE << ii) & 0xF);
#else
	WRITE(3, ii);
#endif
	ii++;
}

void test(uint tid)
{
	for(int ii = 0; ii < tid; inc(tid, ii))
	{
		WRITE(0, ii);
		if((tid & 1) != 0)
		{
			WRITE(1, ii);
			continue;
		}
		WRITE(2, ii);
	}
	WRITE(4, 0);
}

[numthreads(THREAD_COUNT, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
	test(dispatchThreadID.x);
}