Skip to content

Commit c6a5b27

Browse files
author
devsh
committed
clean up a bit
1 parent 105bcdb commit c6a5b27

File tree

5 files changed

+26
-42
lines changed

5 files changed

+26
-42
lines changed

05_StreamingAndBufferDeviceAddressApp/app_resources/common.hlsl

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#include "nbl/builtin/hlsl/cpp_compat.hlsl"
22

3-
// Unfortunately not every piece of C++14 metaprogramming syntax is available in HLSL 202x
4-
// https://github.com/microsoft/DirectXShaderCompiler/issues/5751#issuecomment-1800847954
5-
typedef nbl::hlsl::float32_t3 input_t;
6-
typedef nbl::hlsl::float32_t output_t;
3+
//
4+
using input_t = nbl::hlsl::float32_t3;
5+
using output_t = nbl::hlsl::float32_t;
76

87
NBL_CONSTEXPR_STATIC_INLINE uint32_t MaxPossibleElementCount = 1 << 20;
98

22_CppCompat/app_resources/common.hlsl

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define _NBL_EXAMPLES_TESTS_22_CPP_COMPAT_COMMON_INCLUDED_
77

88
// because DXC doesn't properly support `_Static_assert`
9+
// TODO: add a message, and move to macros.h or cpp_compat
910
#define STATIC_ASSERT(...) { nbl::hlsl::conditional<__VA_ARGS__, int, void>::type a = 0; }
1011

1112
#include <boost/preprocessor.hpp>

22_CppCompat/app_resources/test.comp.hlsl

+10-19
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@
33
//// For conditions of distribution and use, see copyright notice in nabla.h
44
#include "app_resources/common.hlsl"
55

6-
#define SHADER_CRASHING_ASSERT(expr) \
7-
{ \
8-
bool con = (expr); \
9-
do { \
10-
[branch] if (!con) \
11-
vk::RawBufferStore<uint32_t>(0xdeadbeefBADC0FFbull,0x45u,4u); \
12-
} while(!con); \
13-
}
14-
156
template<typename L, typename R>
167
const static bool is_same_v = nbl::hlsl::is_same_v<L,R>;
178

@@ -155,10 +146,10 @@ void main(uint3 invocationID : SV_DispatchThreadID)
155146
// uint32_t rotrResult0 = nbl::hlsl::mpl::rotr<uint32_t, 2u, 1>::value;
156147
// uint32_t rotrResult1 = nbl::hlsl::mpl::rotr<uint32_t, 2u, -1>::value;
157148

158-
// SHADER_CRASHING_ASSERT(rotlResult0 == mplRotlResult0);
159-
// SHADER_CRASHING_ASSERT(rotlResult1 == mplRotlResult1);
160-
// SHADER_CRASHING_ASSERT(rotrResult0 == mplRotrResult0);
161-
// SHADER_CRASHING_ASSERT(rotrResult1 == mplRotrResult1);
149+
// assert(rotlResult0 == mplRotlResult0);
150+
// assert(rotlResult1 == mplRotlResult1);
151+
// assert(rotrResult0 == mplRotrResult0);
152+
// assert(rotrResult1 == mplRotrResult1);
162153

163154
// TODO: more tests and compare with cpp version as well
164155
fill(invocationID, 5);
@@ -175,27 +166,27 @@ void main(uint3 invocationID : SV_DispatchThreadID)
175166
uint16_t compileTimeCountLZero = nbl::hlsl::mpl::countl_zero<uint16_t, TEST_VALUE_0>::value;
176167
uint16_t runTimeCountLZero = nbl::hlsl::countl_zero(TEST_VALUE_0);
177168
fill(invocationID, float4(5.1, compileTimeCountLZero, runTimeCountLZero, 0));
178-
SHADER_CRASHING_ASSERT(compileTimeCountLZero == runTimeCountLZero);
169+
assert(compileTimeCountLZero == runTimeCountLZero);
179170

180171
compileTimeCountLZero = nbl::hlsl::mpl::countl_zero<uint32_t, TEST_VALUE_1>::value;
181172
runTimeCountLZero = nbl::hlsl::countl_zero(TEST_VALUE_1);
182173
fill(invocationID, float4(5.2, compileTimeCountLZero, runTimeCountLZero, 0));
183-
SHADER_CRASHING_ASSERT(compileTimeCountLZero == runTimeCountLZero);
174+
assert(compileTimeCountLZero == runTimeCountLZero);
184175

185176
compileTimeCountLZero = nbl::hlsl::mpl::countl_zero<uint32_t, TEST_VALUE_2>::value;
186177
runTimeCountLZero = nbl::hlsl::countl_zero(TEST_VALUE_2);
187178
fill(invocationID, float4(5.3, compileTimeCountLZero, runTimeCountLZero, 0));
188-
SHADER_CRASHING_ASSERT(compileTimeCountLZero == runTimeCountLZero);
179+
assert(compileTimeCountLZero == runTimeCountLZero);
189180

190181
compileTimeCountLZero = nbl::hlsl::mpl::countl_zero<uint32_t, TEST_VALUE_3>::value;
191182
runTimeCountLZero = nbl::hlsl::countl_zero(TEST_VALUE_3);
192183
fill(invocationID, float4(5.4, compileTimeCountLZero, runTimeCountLZero, 0));
193-
SHADER_CRASHING_ASSERT(compileTimeCountLZero == runTimeCountLZero);
184+
assert(compileTimeCountLZero == runTimeCountLZero);
194185

195186
compileTimeCountLZero = nbl::hlsl::mpl::countl_zero<uint32_t, TEST_VALUE_4>::value;
196187
runTimeCountLZero = nbl::hlsl::countl_zero(TEST_VALUE_4);
197188
fill(invocationID, float4(5.5, compileTimeCountLZero, runTimeCountLZero, 0));
198-
SHADER_CRASHING_ASSERT(compileTimeCountLZero == runTimeCountLZero);
189+
assert(compileTimeCountLZero == runTimeCountLZero);
199190
}
200191

201192
{
@@ -211,7 +202,7 @@ void main(uint3 invocationID : SV_DispatchThreadID)
211202
{
212203
float4 v;
213204
fill(invocationID, float4(alignof(v.x), alignof(v), 0, 0));
214-
SHADER_CRASHING_ASSERT(alignof(v.x) == alignof(v));
205+
assert(alignof(v.x) == alignof(v));
215206
}
216207

217208
{

22_CppCompat/main.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ void cpu_tests()
686686

687687
// countl_zero test
688688
mpl::countl_zero<uint32_t, 5>::value;
689+
// TODO: fix warning about nodiscard
689690
std::countl_zero(5u);
690691
nbl::hlsl::countl_zero(5u);
691692

22_CppCompat/test.hlsl.orig

+11-19
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@
77
#define STATIC_ASSERT(C) { nbl::hlsl::conditional<C, int, void>::type a = 0; }
88

99
#define IS_SAME(L,R) nbl::hlsl::is_same<L,R>::value
10-
#define SHADER_CRASHING_ASSERT(expr) \
11-
{ \
12-
bool con = (expr); \
13-
do { \
14-
[branch] if (!con) \
15-
vk::RawBufferStore<uint32_t>(0xdeadbeefBADC0FFbull,0x45u,4u); \
16-
} while(!con); \
17-
}
1810

1911
#include <nbl/builtin/hlsl/cmath.hlsl>
2012

@@ -145,10 +137,10 @@ void main(uint3 invocationID : SV_DispatchThreadID)
145137
// uint32_t rotrResult0 = nbl::hlsl::mpl::rotr<uint32_t, 2u, 1>::value;
146138
// uint32_t rotrResult1 = nbl::hlsl::mpl::rotr<uint32_t, 2u, -1>::value;
147139

148-
// SHADER_CRASHING_ASSERT(rotlResult0 == mplRotlResult0);
149-
// SHADER_CRASHING_ASSERT(rotlResult1 == mplRotlResult1);
150-
// SHADER_CRASHING_ASSERT(rotrResult0 == mplRotrResult0);
151-
// SHADER_CRASHING_ASSERT(rotrResult1 == mplRotrResult1);
140+
// assert(rotlResult0 == mplRotlResult0);
141+
// assert(rotlResult1 == mplRotlResult1);
142+
// assert(rotrResult0 == mplRotrResult0);
143+
// assert(rotrResult1 == mplRotrResult1);
152144

153145
// TODO: more tests and compare with cpp version as well
154146
fill(invocationID, 5);
@@ -165,27 +157,27 @@ void main(uint3 invocationID : SV_DispatchThreadID)
165157
uint16_t compileTimeCountLZero = nbl::hlsl::mpl::countl_zero<uint16_t, TEST_VALUE_0>::value;
166158
uint16_t runTimeCountLZero = nbl::hlsl::countl_zero(TEST_VALUE_0);
167159
fill(invocationID, float4(5.1, compileTimeCountLZero, runTimeCountLZero, 0));
168-
SHADER_CRASHING_ASSERT(compileTimeCountLZero == runTimeCountLZero);
160+
assert(compileTimeCountLZero == runTimeCountLZero);
169161

170162
compileTimeCountLZero = nbl::hlsl::mpl::countl_zero<uint32_t, TEST_VALUE_1>::value;
171163
runTimeCountLZero = nbl::hlsl::countl_zero(TEST_VALUE_1);
172164
fill(invocationID, float4(5.2, compileTimeCountLZero, runTimeCountLZero, 0));
173-
SHADER_CRASHING_ASSERT(compileTimeCountLZero == runTimeCountLZero);
165+
assert(compileTimeCountLZero == runTimeCountLZero);
174166

175167
compileTimeCountLZero = nbl::hlsl::mpl::countl_zero<uint32_t, TEST_VALUE_2>::value;
176168
runTimeCountLZero = nbl::hlsl::countl_zero(TEST_VALUE_2);
177169
fill(invocationID, float4(5.3, compileTimeCountLZero, runTimeCountLZero, 0));
178-
SHADER_CRASHING_ASSERT(compileTimeCountLZero == runTimeCountLZero);
170+
assert(compileTimeCountLZero == runTimeCountLZero);
179171

180172
compileTimeCountLZero = nbl::hlsl::mpl::countl_zero<uint32_t, TEST_VALUE_3>::value;
181173
runTimeCountLZero = nbl::hlsl::countl_zero(TEST_VALUE_3);
182174
fill(invocationID, float4(5.4, compileTimeCountLZero, runTimeCountLZero, 0));
183-
SHADER_CRASHING_ASSERT(compileTimeCountLZero == runTimeCountLZero);
175+
assert(compileTimeCountLZero == runTimeCountLZero);
184176

185177
compileTimeCountLZero = nbl::hlsl::mpl::countl_zero<uint32_t, TEST_VALUE_4>::value;
186178
runTimeCountLZero = nbl::hlsl::countl_zero(TEST_VALUE_4);
187179
fill(invocationID, float4(5.5, compileTimeCountLZero, runTimeCountLZero, 0));
188-
SHADER_CRASHING_ASSERT(compileTimeCountLZero == runTimeCountLZero);
180+
assert(compileTimeCountLZero == runTimeCountLZero);
189181
}
190182

191183
{
@@ -201,7 +193,7 @@ void main(uint3 invocationID : SV_DispatchThreadID)
201193
{
202194
float4 v;
203195
fill(invocationID, float4(alignof(v.x), alignof(v), 0, 0));
204-
SHADER_CRASHING_ASSERT(alignof(v.x) == alignof(v));
196+
assert(alignof(v.x) == alignof(v));
205197
}
206198

207199
{
@@ -266,7 +258,7 @@ void main(uint3 invocationID : SV_DispatchThreadID)
266258
decltype(fn(__VA_ARGS__)) lhs = nbl::hlsl::fn(__VA_ARGS__); \
267259
decltype(lhs) rhs = fn(__VA_ARGS__); \
268260
fill(invocationID, float4(idx, lhs, rhs)); \
269-
SHADER_CRASHING_ASSERT(abs(lhs - rhs) < nbl::hlsl::numeric_limits<decltype(lhs)>::epsilon) \
261+
assert(abs(lhs - rhs) < nbl::hlsl::numeric_limits<decltype(lhs)>::epsilon) \
270262
}
271263
TEST_FN(float2(10, 1), cos, 1.44f)
272264
TEST_FN(float2(10, 2), sin, 1.44f)

0 commit comments

Comments
 (0)