Skip to content

Commit 8bd4f2b

Browse files
committed
Bump version to 2.0.1; add matrix uniform overrides
Bump project version to 2.0.1 (VERSION and APP_VERSION). Add uniform_component_count helper in src/gl/program.cpp and use it to correctly compare and copy uniform value arrays for all scalar, vector and matrix GL types. Extend input override handling in src/runtime/sequence.cpp to accept float/double matrix types. Update compute shader and tests: add matrix and vector input uniforms to tests/shaders/input_override.comp and extend C++ and Python smoke tests to verify numeric overrides (vector and matrix cases) for prepared workflows. Overall this enables numeric overrides for matrix uniforms and adds tests to validate the behavior.
1 parent c691f84 commit 8bd4f2b

8 files changed

Lines changed: 251 additions & 16 deletions

File tree

‎VERSION‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.0
1+
2.0.1

‎src/core/context.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
const char* APP_NAME = "RawGL";
2424
const char* APP_AUTHOR = "Erium Vladlen";
25-
const int APP_VERSION[] = { 2, 0, 0 };
25+
const int APP_VERSION[] = { 2, 0, 1 };
2626

2727
namespace rawgl {
2828

‎src/gl/program.cpp‎

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,52 @@ trim_glsl_array_suffix(char* name, GLsizei length)
2626
*split = '\0';
2727
}
2828
}
29+
30+
GLsizei
31+
uniform_component_count(const GLenum type)
32+
{
33+
switch (type) {
34+
case GL_BOOL:
35+
case GL_INT:
36+
case GL_UNSIGNED_INT:
37+
case GL_FLOAT:
38+
case GL_DOUBLE: return 1;
39+
case GL_BOOL_VEC2:
40+
case GL_INT_VEC2:
41+
case GL_UNSIGNED_INT_VEC2:
42+
case GL_FLOAT_VEC2:
43+
case GL_DOUBLE_VEC2: return 2;
44+
case GL_BOOL_VEC3:
45+
case GL_INT_VEC3:
46+
case GL_UNSIGNED_INT_VEC3:
47+
case GL_FLOAT_VEC3:
48+
case GL_DOUBLE_VEC3: return 3;
49+
case GL_BOOL_VEC4:
50+
case GL_INT_VEC4:
51+
case GL_UNSIGNED_INT_VEC4:
52+
case GL_FLOAT_VEC4:
53+
case GL_DOUBLE_VEC4:
54+
case GL_FLOAT_MAT2:
55+
case GL_DOUBLE_MAT2: return 4;
56+
case GL_FLOAT_MAT2x3:
57+
case GL_FLOAT_MAT3x2:
58+
case GL_DOUBLE_MAT2x3:
59+
case GL_DOUBLE_MAT3x2: return 6;
60+
case GL_FLOAT_MAT2x4:
61+
case GL_FLOAT_MAT4x2:
62+
case GL_DOUBLE_MAT2x4:
63+
case GL_DOUBLE_MAT4x2: return 8;
64+
case GL_FLOAT_MAT3:
65+
case GL_DOUBLE_MAT3: return 9;
66+
case GL_FLOAT_MAT3x4:
67+
case GL_FLOAT_MAT4x3:
68+
case GL_DOUBLE_MAT3x4:
69+
case GL_DOUBLE_MAT4x3: return 12;
70+
case GL_FLOAT_MAT4:
71+
case GL_DOUBLE_MAT4: return 16;
72+
default: return 1;
73+
}
74+
}
2975
} // namespace
3076

3177
//
@@ -60,19 +106,20 @@ void
60106
GLProgramUniform::set(const GLint* values)
61107
{
62108
int i;
109+
const GLsizei valueCount = uniform_component_count(type);
63110

64111
if (isSet) {
65-
for (i = 0; i < size; i++) {
112+
for (i = 0; i < valueCount; i++) {
66113
if (ints[i] != values[i])
67114
break;
68115
}
69116

70-
if (i == size)
117+
if (i == valueCount)
71118
return;
72119
} else
73120
isSet = true;
74121

75-
for (i = 0; i < size; i++)
122+
for (i = 0; i < valueCount; i++)
76123
ints[i] = values[i];
77124

78125
switch (type) {
@@ -115,19 +162,20 @@ void
115162
GLProgramUniform::set(const GLuint* values)
116163
{
117164
int i;
165+
const GLsizei valueCount = uniform_component_count(type);
118166

119167
if (isSet) {
120-
for (i = 0; i < size; i++) {
168+
for (i = 0; i < valueCount; i++) {
121169
if (uints[i] != values[i])
122170
break;
123171
}
124172

125-
if (i == size)
173+
if (i == valueCount)
126174
return;
127175
} else
128176
isSet = true;
129177

130-
for (i = 0; i < size; i++)
178+
for (i = 0; i < valueCount; i++)
131179
uints[i] = values[i];
132180

133181
switch (type) {
@@ -157,19 +205,20 @@ void
157205
GLProgramUniform::set(const GLfloat* values)
158206
{
159207
int i;
208+
const GLsizei valueCount = uniform_component_count(type);
160209

161210
if (isSet) {
162-
for (i = 0; i < size; i++) {
211+
for (i = 0; i < valueCount; i++) {
163212
if (floats[i] != values[i])
164213
break;
165214
}
166215

167-
if (i == size)
216+
if (i == valueCount)
168217
return;
169218
} else
170219
isSet = true;
171220

172-
for (i = 0; i < size; i++)
221+
for (i = 0; i < valueCount; i++)
173222
floats[i] = values[i];
174223

175224
// setting uniform variables in current program
@@ -209,19 +258,20 @@ void
209258
GLProgramUniform::set(const GLdouble* values)
210259
{
211260
int i;
261+
const GLsizei valueCount = uniform_component_count(type);
212262

213263
if (isSet) {
214-
for (i = 0; i < size; i++) {
264+
for (i = 0; i < valueCount; i++) {
215265
if (doubles[i] != values[i])
216266
break;
217267
}
218268

219-
if (i == size)
269+
if (i == valueCount)
220270
return;
221271
} else
222272
isSet = true;
223273

224-
for (i = 0; i < size; i++)
274+
for (i = 0; i < valueCount; i++)
225275
doubles[i] = values[i];
226276

227277
// setting uniform variables in current program

‎src/runtime/sequence.cpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,15 @@ Sequence::bindPassInputs(const PassExecutionPlan& plan,
10451045
case GL_FLOAT_VEC2:
10461046
case GL_FLOAT_VEC3:
10471047
case GL_FLOAT_VEC4:
1048+
case GL_FLOAT_MAT2:
1049+
case GL_FLOAT_MAT2x3:
1050+
case GL_FLOAT_MAT2x4:
1051+
case GL_FLOAT_MAT3:
1052+
case GL_FLOAT_MAT3x2:
1053+
case GL_FLOAT_MAT3x4:
1054+
case GL_FLOAT_MAT4:
1055+
case GL_FLOAT_MAT4x2:
1056+
case GL_FLOAT_MAT4x3:
10481057
if (inputOverride && inputOverride->kind == SequenceExecutionInputOverrideKind::floatValues) {
10491058
if (input.usesArrayElement) {
10501059
set_addressed_float_uniform(input, inputOverride->floatValues.data());
@@ -1063,6 +1072,15 @@ Sequence::bindPassInputs(const PassExecutionPlan& plan,
10631072
case GL_DOUBLE_VEC2:
10641073
case GL_DOUBLE_VEC3:
10651074
case GL_DOUBLE_VEC4:
1075+
case GL_DOUBLE_MAT2:
1076+
case GL_DOUBLE_MAT2x3:
1077+
case GL_DOUBLE_MAT2x4:
1078+
case GL_DOUBLE_MAT3:
1079+
case GL_DOUBLE_MAT3x2:
1080+
case GL_DOUBLE_MAT3x4:
1081+
case GL_DOUBLE_MAT4:
1082+
case GL_DOUBLE_MAT4x2:
1083+
case GL_DOUBLE_MAT4x3:
10661084
if (inputOverride && inputOverride->kind == SequenceExecutionInputOverrideKind::doubleValues) {
10671085
if (input.usesArrayElement) {
10681086
set_addressed_double_uniform(input, inputOverride->doubleValues.data());

‎tests/python/rawgl_python_import_smoke.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def fail(message: str) -> int:
1313

1414

1515
def main() -> int:
16-
if rawgl.__version__ != "2.0.0":
16+
if rawgl.__version__ != "2.0.1":
1717
return fail(f"unexpected rawgl.__version__: {rawgl.__version__}")
1818

1919
status = rawgl.status()

‎tests/python/rawgl_python_workflow_smoke.py‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,23 @@ def verify_inline_lut(session: rawgl.Session) -> int:
106106
}
107107
"""
108108

109+
110+
INLINE_PREPARED_OVERRIDE_COMPUTE = """#version 450 core
111+
layout(local_size_x = 1, local_size_y = 1) in;
112+
layout(binding = 0, rgba32f) uniform writeonly image2D o_out0;
113+
114+
uniform float gain;
115+
uniform vec3 bias;
116+
uniform mat3 transform;
117+
118+
void main()
119+
{
120+
vec3 value = transform * vec3(gain, gain, gain) + bias;
121+
imageStore(o_out0, ivec2(0, 0), vec4(value, 1.0));
122+
}
123+
"""
124+
125+
109126
def verify_inline_host_counter(session: rawgl.Session) -> int:
110127
source_input = rawgl.make_rgba32f_host_image(1, 1, [0.25, 0.5, 0.75, 1.0])
111128
if np is not None:
@@ -149,6 +166,78 @@ def verify_inline_host_counter(session: rawgl.Session) -> int:
149166
return 0
150167

151168

169+
def verify_prepared_numeric_overrides(session: rawgl.Session) -> int:
170+
prepared = rawgl.prepare_compute(
171+
INLINE_PREPARED_OVERRIDE_COMPUTE,
172+
session=session,
173+
size=(1, 1),
174+
workgroup_size=(1, 1),
175+
verbosity=0,
176+
inputs={
177+
"gain": 0.25,
178+
"bias": [0.0, 0.0, 0.0],
179+
"transform": [
180+
1.0, 0.0, 0.0,
181+
0.0, 1.0, 0.0,
182+
0.0, 0.0, 1.0,
183+
],
184+
},
185+
outputs={
186+
"o_out0": {
187+
"format": "rgba32f",
188+
"channels": 4,
189+
"alpha_channel": 3,
190+
"bits": 16,
191+
"capture_to_host": True,
192+
},
193+
},
194+
)
195+
196+
def check(label: str, result: rawgl.RunResultView, expected: list[float]) -> int:
197+
if not result.success:
198+
return fail(f"{label} prepared override workflow failed: {result.error_message}")
199+
image = result.captured_outputs.get("o_out0::0")
200+
if image is None:
201+
return fail(f"{label} prepared override workflow did not capture o_out0::0")
202+
values = rawgl.host_image_to_rgba32f(image)
203+
if len(values) != 4 or any(
204+
not math.isclose(values[i], expected[i], rel_tol=0.0, abs_tol=1e-6)
205+
for i in range(4)
206+
):
207+
return fail(f"{label} prepared override output mismatch: {values}")
208+
return 0
209+
210+
status = check("default", prepared.run(), [0.25, 0.25, 0.25, 1.0])
211+
if status != 0:
212+
return status
213+
214+
status = check(
215+
"vector",
216+
prepared.run(inputs={"bias": [0.0, 0.125, 0.25]}),
217+
[0.25, 0.375, 0.5, 1.0],
218+
)
219+
if status != 0:
220+
return status
221+
222+
status = check(
223+
"matrix",
224+
prepared.run(
225+
inputs={
226+
"transform": [
227+
1.0, 0.0, 0.0,
228+
0.0, 2.0, 0.0,
229+
0.0, 0.0, 3.0,
230+
],
231+
}
232+
),
233+
[0.25, 0.5, 0.75, 1.0],
234+
)
235+
if status != 0:
236+
return status
237+
238+
return 0
239+
240+
152241
def verify_system_uniform_mapping(session: rawgl.Session) -> int:
153242
result = rawgl.compute(
154243
"tests/shaders/system_uniforms.comp",
@@ -227,6 +316,10 @@ def main() -> int:
227316
if status != 0:
228317
return status
229318

319+
status = verify_prepared_numeric_overrides(session)
320+
if status != 0:
321+
return status
322+
230323
status = verify_system_uniform_mapping(session)
231324
if status != 0:
232325
return status

0 commit comments

Comments
 (0)