Skip to content

Commit 70281ff

Browse files
committed
Added tests for ParameterBlock writes
1 parent 41ea51e commit 70281ff

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

slangpy/tests/device/test_shader_cursor.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ class Var:
124124
"u_float3x4": Var(kind="matrix", type="float", value=[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]]),
125125
"u_float4x4": Var(kind="matrix", type="float", value=[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]]),
126126
"pb_float4x4": Var(kind="matrix", type="float", value=[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]]),
127+
"pb_float4x3": Var(kind="matrix", type="float", value=[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]]),
128+
"pb_float3x4": Var(kind="matrix", type="float", value=[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]]),
127129
# float16_t
128130
"u_float16_t": Var(kind="scalar", type="float16_t", value=1.2345),
129131
"u_float16_t_min": Var(kind="scalar", type="float16_t", value=FLOAT16_MIN),
@@ -163,6 +165,31 @@ class Var:
163165
"f_float2": Var(kind="vector", type="float", value=[1.23, 1.234]),
164166
"f_float3": Var(kind="vector", type="float", value=[1.23, 1.234, 1.2345]),
165167
"f_float4": Var(kind="vector", type="float", value=[1.23, 1.235, 1.23456, 1.234567]),
168+
"f_float4x3": Var(kind="matrix", type="float", value=[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]]),
169+
"f_bool_array": Var(kind="array", type="bool", value=[False]),
170+
"f_int_array": Var(kind="array", type="int", value=[-10, 10]),
171+
"f_uint_array": Var(kind="array", type="uint", value=[0, 10, 20]),
172+
"f_float_array": Var(kind="array", type="float", value=[0.1, 0.2, 0.3, 0.4]),
173+
},
174+
# pb_struct
175+
"pb_struct": {
176+
"f_bool": Var(kind="scalar", type="bool", value=True),
177+
"f_bool2": Var(kind="vector", type="bool", value=[False, True]),
178+
"f_bool3": Var(kind="vector", type="bool", value=[False, True, False]),
179+
"f_bool4": Var(kind="vector", type="bool", value=[False, True, False, True]),
180+
"f_int": Var(kind="scalar", type="int", value=-123),
181+
"f_int2": Var(kind="vector", type="int", value=[-123, 123]),
182+
"f_int3": Var(kind="vector", type="int", value=[-123, 123, -1234]),
183+
"f_int4": Var(kind="vector", type="int", value=[-123, 123, -1234, 1234]),
184+
"f_uint": Var(kind="scalar", type="uint", value=12),
185+
"f_uint2": Var(kind="vector", type="uint", value=[123, 1234]),
186+
"f_uint3": Var(kind="vector", type="uint", value=[123, 1234, 12345]),
187+
"f_uint4": Var(kind="vector", type="uint", value=[123, 1235, 123456, 1234567]),
188+
"f_float": Var(kind="scalar", type="float", value=1.2),
189+
"f_float2": Var(kind="vector", type="float", value=[1.23, 1.234]),
190+
"f_float3": Var(kind="vector", type="float", value=[1.23, 1.234, 1.2345]),
191+
"f_float4": Var(kind="vector", type="float", value=[1.23, 1.235, 1.23456, 1.234567]),
192+
"f_float4x3": Var(kind="matrix", type="float", value=[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]]),
166193
"f_bool_array": Var(kind="array", type="bool", value=[False]),
167194
"f_int_array": Var(kind="array", type="int", value=[-10, 10]),
168195
"f_uint_array": Var(kind="array", type="uint", value=[0, 10, 20]),
@@ -226,6 +253,7 @@ def convert_matrix(type: str, rows: int, cols: int, values: Any):
226253
TABLE = {
227254
("float", 2, 2): spy.float2x2,
228255
("float", 3, 3): spy.float3x3,
256+
("float", 4, 3): spy.float4x3,
229257
("float", 2, 4): spy.float2x4,
230258
("float", 3, 4): spy.float3x4,
231259
("float", 4, 4): spy.float4x4,
@@ -321,6 +349,10 @@ def write_vars(
321349
):
322350
if isinstance(vars, dict):
323351
for key, var in vars.items():
352+
# Disabling ParameterBlock tests on Vulkan, due to issue:
353+
# https://github.com/shader-slang/slang/issues/7431
354+
if device_type == spy.DeviceType.vulkan and key.startswith("pb_"):
355+
continue
324356
if isinstance(var, dict):
325357
write_vars(device_type, cursor[key], var, key + ".")
326358
elif isinstance(var, list):

slangpy/tests/device/test_shader_cursor.slang

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22

3+
// Enable (and remove the define) after this issue has been addressed:
4+
// https://github.com/shader-slang/slang/issues/7431
5+
// Slang currently generates somewhat invalid code, and at the same time,
6+
// the tests fail in a weird fashion (u_struct_array[1:] are not set).
7+
#define ENABLE_PARAMBLOCK_TESTS !defined(__TARGET_VULKAN__)
8+
39
struct Test {
410
bool f_bool;
511
bool2 f_bool2;
@@ -17,6 +23,7 @@ struct Test {
1723
float2 f_float2;
1824
float3 f_float3;
1925
float4 f_float4;
26+
float4x3 f_float4x3;
2027

2128
bool f_bool_array[1];
2229
int f_int_array[2];
@@ -85,7 +92,11 @@ uniform float3x3 u_float3x3;
8592
uniform float2x4 u_float2x4;
8693
uniform float3x4 u_float3x4;
8794
uniform float4x4 u_float4x4;
95+
#if ENABLE_PARAMBLOCK_TESTS
8896
ParameterBlock<float4x4> pb_float4x4;
97+
ParameterBlock<float4x3> pb_float4x3;
98+
ParameterBlock<float3x4> pb_float3x4;
99+
#endif
89100

90101
uniform float16_t u_float16_t;
91102
uniform float16_t u_float16_t_min;
@@ -109,12 +120,14 @@ uniform uint u_uint_array[4];
109120
uniform float u_float_array[4];
110121

111122
uniform Test u_struct;
123+
#if ENABLE_PARAMBLOCK_TESTS
124+
ParameterBlock<Test> pb_struct;
125+
#endif
112126
uniform int u_int_array_2[4];
113127
uniform Test u_struct_array[4];
114128

115129
Buffer<uint> u_buffer;
116130

117-
118131
RWStructuredBuffer<uint> results;
119132

120133
struct Writer {
@@ -261,7 +274,11 @@ void compute_main(uint3 tid: SV_DispatchThreadID)
261274
writer.write(u_float2x4);
262275
writer.write(u_float3x4);
263276
writer.write(u_float4x4);
277+
#if ENABLE_PARAMBLOCK_TESTS
264278
writer.write(pb_float4x4);
279+
writer.write(pb_float4x3);
280+
writer.write(pb_float3x4);
281+
#endif
265282

266283
writer.write(u_float16_t);
267284
writer.write(u_float16_t_min);
@@ -304,6 +321,7 @@ void compute_main(uint3 tid: SV_DispatchThreadID)
304321
writer.write(u_struct.f_float2);
305322
writer.write(u_struct.f_float3);
306323
writer.write(u_struct.f_float4);
324+
writer.write(u_struct.f_float4x3);
307325

308326
for (uint i = 0; i < 1; ++i)
309327
writer.write(u_struct.f_bool_array[i]);
@@ -314,6 +332,35 @@ void compute_main(uint3 tid: SV_DispatchThreadID)
314332
for (uint i = 0; i < 4; ++i)
315333
writer.write(u_struct.f_float_array[i]);
316334

335+
#if ENABLE_PARAMBLOCK_TESTS
336+
writer.write(pb_struct.f_bool);
337+
writer.write(pb_struct.f_bool2);
338+
writer.write(pb_struct.f_bool3);
339+
writer.write(pb_struct.f_bool4);
340+
writer.write(pb_struct.f_int);
341+
writer.write(pb_struct.f_int2);
342+
writer.write(pb_struct.f_int3);
343+
writer.write(pb_struct.f_int4);
344+
writer.write(pb_struct.f_uint);
345+
writer.write(pb_struct.f_uint2);
346+
writer.write(pb_struct.f_uint3);
347+
writer.write(pb_struct.f_uint4);
348+
writer.write(pb_struct.f_float);
349+
writer.write(pb_struct.f_float2);
350+
writer.write(pb_struct.f_float3);
351+
writer.write(pb_struct.f_float4);
352+
writer.write(pb_struct.f_float4x3);
353+
354+
for (uint i = 0; i < 1; ++i)
355+
writer.write(pb_struct.f_bool_array[i]);
356+
for (uint i = 0; i < 2; ++i)
357+
writer.write(pb_struct.f_int_array[i]);
358+
for (uint i = 0; i < 3; ++i)
359+
writer.write(pb_struct.f_uint_array[i]);
360+
for (uint i = 0; i < 4; ++i)
361+
writer.write(pb_struct.f_float_array[i]);
362+
#endif
363+
317364
for (uint i = 0; i < 4; ++i)
318365
writer.write(u_int_array_2[i]);
319366

0 commit comments

Comments
 (0)