Blender V5.3
eevee_test_occupancy.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
9
10[[compute, local_size(1)]]
11void eevee_test_occupancy_main([[resource_table]] [[maybe_unused]] const ShaderTestOutput &srt)
12{
21
22 using Bits = occupancy::Bits;
23
24 TEST(eevee_occupancy, Occupancy)
25 {
26 Bits occup;
27
28 /* bits_from_depth */
29 occup = bits_from_depth(0.1f, 1);
30 EXPECT_EQ(to_uint4(occup), uint4(0xFFFFFFFFu, ~0u, ~0u, ~0u));
31
32 occup = bits_from_depth(0.6f, 1);
33 EXPECT_EQ(to_uint4(occup), uint4(0xFFFFFFFEu, ~0u, ~0u, ~0u));
34
35 occup = bits_from_depth(0.5f, 32);
36 EXPECT_EQ(to_uint4(occup), uint4(0xFFFF0000u, ~0u, ~0u, ~0u));
37
38 occup = bits_from_depth(0.5f, 64);
39 EXPECT_EQ(to_uint4(occup), uint4(0u, ~0u, ~0u, ~0u));
40
41 occup = bits_from_depth(0.5f, 128);
42 EXPECT_EQ(to_uint4(occup), uint4(0u, 0u, ~0u, ~0u));
43
44 occup = bits_from_depth(33.0f / 64.0f, 64);
45 EXPECT_EQ(to_uint4(occup), uint4(0u, 0xFFFFFFFEu, ~0u, ~0u));
46
47 /* bit_from_depth */
48 occup = bit_from_depth(0.1f, 1);
49 EXPECT_EQ(to_uint4(occup), uint4(0x00000001u, 0u, 0u, 0u));
50
51 occup = bit_from_depth(0.6f, 1);
52 EXPECT_EQ(to_uint4(occup), uint4(0x00000002u, 0u, 0u, 0u));
53
54 occup = bit_from_depth(0.5f, 32);
55 EXPECT_EQ(to_uint4(occup), uint4(0x00010000u, 0u, 0u, 0u));
56
57 occup = bit_from_depth(0.5f, 64);
58 EXPECT_EQ(to_uint4(occup), uint4(0x00000000u, 0x00000001u, 0u, 0u));
59
60 occup = bit_from_depth(0.5f, 128);
61 EXPECT_EQ(to_uint4(occup), uint4(0x00000000u, 0x00000000u, 0x00000001u, 0u));
62
63 occup = bit_from_depth(33.0f / 64.0f, 64);
64 EXPECT_EQ(to_uint4(occup), uint4(0x00000000u, 0x00000002u, 0u, 0u));
65
66 /* Test composing occupancy an the expected result. */
67 /* Start empty. */
68 Bits entry = occupancy_new();
69 Bits exit = occupancy_new();
70 entry = bitwise_or(entry, bit_from_depth(1.0f / 32.0f, 32));
71 /* Second entry at the same depth. Should not change anything. */
72 entry = bitwise_or(entry, bit_from_depth(1.1f / 32.0f, 32));
73 /* Exit 2 bits later. */
74 exit = bitwise_or(exit, bit_from_depth(3.0f / 32.0f, 32));
75 /* Second exit. Should not change anything. */
76 exit = bitwise_or(exit, bit_from_depth(5.0f / 32.0f, 32));
77 /* Third entry is valid. */
78 entry = bitwise_or(entry, bit_from_depth(7.0f / 32.0f, 32));
79 /* Third exit is valid. */
80 exit = bitwise_or(exit, bit_from_depth(9.0f / 32.0f, 32));
81 /* Fourth entry is valid. */
82 entry = bitwise_or(entry, bit_from_depth(11.0f / 32.0f, 32));
83 /* Fourth exit on the same depth. Cancels the occupancy. */
84 exit = bitwise_or(exit, bit_from_depth(11.0f / 32.0f, 32));
85 EXPECT_EQ(entry.bits[0], 2178u); /* 1000 1000 0010 */
86 EXPECT_EQ(exit.bits[0], 2600u); /* 1010 0010 1000 */
87
88 occup = resolve(entry, exit, 32);
89 EXPECT_EQ(occup.bits[0], 390u); /* 0001 1000 0110 */
90
91 /* Start empty. */
92 entry = occupancy_new();
93 exit = occupancy_new();
94 /* First exit. Anything prior should be considered in volume. */
95 exit = bitwise_or(exit, bit_from_depth(33.0f / 44.0f, 44));
96 /* First entry. */
97 entry = bitwise_or(entry, bit_from_depth(36.0f / 44.0f, 44));
98 /* Second exit. Should not change anything. */
99 exit = bitwise_or(exit, bit_from_depth(40.0f / 44.0f, 44));
100 /* 0000 0001 0000 0000 0000 0000 0000 0000 0000 0000 0000 */
101 EXPECT_EQ(to_uint4(entry), uint4(0x00000000u, 0x010u, 0u, 0u));
102 /* 0001 0000 0010 0000 0000 0000 0000 0000 0000 0000 0000 */
103 EXPECT_EQ(to_uint4(exit), uint4(0x00000000u, 0x102u, 0u, 0u));
104
105 EXPECT_EQ(find_lsb(entry), 36);
106 EXPECT_EQ(find_lsb(exit), 33);
107
108 occup = resolve(entry, exit, 44);
109 /* 0000 1111 0001 1111 1111 1111 1111 1111 1111 1111 1111 */
110 EXPECT_EQ(to_uint4(occup), uint4(0xFFFFFFFFu, 0x0F1u, 0u, 0u));
111
112 occup = occupancy_new();
113 occup = set_bits_high(occup, 16, 32);
114 occup = set_bits_high(occup, 80, 16);
115 EXPECT_EQ(to_uint4(occup), uint4(0xFFFF0000u, 0x0000FFFFu, 0xFFFF0000u, 0u));
116 }
117}
118
void eevee_test_occupancy_main(const ShaderTestOutput &srt)
PipelineCompute eevee_test_occupancy(eevee_test_occupancy_main)
#define resource_table
#define compute
#define local_size(...)
#define TEST(a, b)
#define EXPECT_EQ(result, expect)
Bits bit_from_depth(float depth, int bit_count)
int find_lsb(Bits occupancy)
Bits set_bits_high(Bits occupancy, int bit_start, int bit_count)
uint4 to_uint4(Bits occupancy)
Bits bitwise_or(Bits a, Bits b)
Bits bits_from_depth(float depth, int bit_count)
Bits resolve(Bits entry, Bits exit, int bit_count)