Skip to content

Commit 41ea51e

Browse files
committed
Added handling of non-struct ParamBlock writes
1 parent 54876aa commit 41ea51e

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

slangpy/tests/device/test_shader_cursor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class Var:
123123
"u_float2x4": Var(kind="matrix", type="float", value=[[0, 1, 2, 3], [4, 5, 6, 7]]),
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]]),
126+
"pb_float4x4": Var(kind="matrix", type="float", value=[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]]),
126127
# float16_t
127128
"u_float16_t": Var(kind="scalar", type="float16_t", value=1.2345),
128129
"u_float16_t_min": Var(kind="scalar", type="float16_t", value=FLOAT16_MIN),

slangpy/tests/device/test_shader_cursor.slang

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ uniform float3x3 u_float3x3;
8585
uniform float2x4 u_float2x4;
8686
uniform float3x4 u_float3x4;
8787
uniform float4x4 u_float4x4;
88+
ParameterBlock<float4x4> pb_float4x4;
8889

8990
uniform float16_t u_float16_t;
9091
uniform float16_t u_float16_t_min;
@@ -260,6 +261,7 @@ void compute_main(uint3 tid: SV_DispatchThreadID)
260261
writer.write(u_float2x4);
261262
writer.write(u_float3x4);
262263
writer.write(u_float4x4);
264+
writer.write(pb_float4x4);
263265

264266
writer.write(u_float16_t);
265267
writer.write(u_float16_t_min);

src/slangpy_ext/device/cursor_utils.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,14 @@ class WriteConverterTable {
687687
}
688688
case TypeReflection::Kind::constant_buffer:
689689
case TypeReflection::Kind::parameter_block:
690+
if constexpr (requires { self.dereference(); }) {
691+
// Unwrap constant buffers or parameter blocks for shader cursors
692+
auto child = self.dereference();
693+
write_internal(child, nbval);
694+
return;
695+
} else
696+
SGL_THROW("constant_buffer and param_block not expected in BufferElementCursor");
690697
case TypeReflection::Kind::struct_: {
691-
// Unwrap constant buffers or parameter blocks
692698
if (kind != TypeReflection::Kind::struct_)
693699
type_layout = type_layout->getElementTypeLayout();
694700

0 commit comments

Comments
 (0)