Commit 70b812a
committed
BackendCpp: C++ source-generation backend for OSL shader groups
Add a BackendCpp execution path that generates human-readable, compilable
C++ from the post-optimized shader graph, as an alternative to the LLVM
JIT.
The direct benefit is for debugging and understanding post-optimized
shader by looking at its C++ equivalent rather than huge a pile of oso.
Possible secondary/future benefits (with a little more work):
- Speed, if DSO loading is faster than optimize/JIT.
- Pre-compiled shader networks for use in a renderer that needs a
fixed set of shaders and no runtime JIT.
- Distributing proprietary shaders as binaries.
But the REAL purpose is as a stepping stone to translating to other
languages like Metal or GLSL. I envision the mechanism to simply be to
subclass BackendCpp, inheriting all the parts that are common to all
C++-like languages, and using virtual methods as the customization
points for language-specific differences. (I don't claim that these
customization points are correct now; I expect significant refactoring
needs to be apparent when we add the next language.)
Anyway, so as for what's here:
Pipeline, controlled by the escalating `debug_output_cpp` ShadingSystem
attribute (and the `OSL_DEBUG_OUTPUT_CPP` env var):
1 - generate a self-contained `group-cpp-<name>.cpp`
2 - also shell out to compile it to a DSO
3 - also load the DSO, verify its ABI, and execute it instead of the JIT
(running BackendLLVM's layout pass only, skipping full JIT codegen)
Generated output: a typed `GroupData` struct mirroring the BackendLLVM
layout (layer-run flags, userdata, connected/output params), one
`void layer_N(ShaderGlobals*, GroupData*, ...)` function per active layer,
and a `RunLLVMGroupFunc`-compatible group entry. Every file includes the
new internal `osl_cpp_runtime.h` (ABI version + `extern "C"` osl_* decls)
and exports `osl_cpp_abi_version()`, checked at load. The `lang_*` virtual
interface keeps the language tokens overridable for future backends.
Op coverage is complete: arithmetic/comparison/math emit direct C++;
runtime-service ops (noise, texture, closures, transforms, pointcloud,
getattribute/getmatrix/gettextureinfo, splines, regex, messages, ...) call
osl_* functions. Control flow, arrays/components, structs (incl.
color2/4, vector2/4), and Dual2 derivatives (scalar and triple) are all
generated and verified against the JIT.
Testing is opt-out and automatic: the `OSL_TEST_CPP_BACKEND` CMake option
(ON in the linux-vfx2026 and macos26-arm CI variants) builds a per-group
DSO and runs every testshade/testrender test through the C++ path at both
opt levels. The full eligible suite passes, matching JIT output (with the
documented opt-outs: --entry/layers-entry, the backend-cpp fixture itself,
OptiX/GPU, and batched-regression harnesses).
Cross-platform notes:
- osl_* shadeops are exported from liboslexec for generated DSOs to
resolve. On Linux this required listing osl_* under `global:` in
hidesymbols.map (the version script otherwise localized them out of
the dynamic symbol table); they are marked INTERNAL/UNSTABLE.
- OSL_CPP_ABI_VERSION folds in the OSL major/minor version so minor
releases are link-incompatible automatically (the DSOs are ephemeral;
the check only guards against misuse).
- MSVC-clean (OSL::popcount instead of a GCC/Clang builtin).
- Array copy of mismatched lengths copies min(dst,src) elements,
matching BackendLLVM and avoiding an out-of-bounds source read.
Spec, plan, research, data-model, and tasks under
docs/dev/specs/002-backend-cpp/.
Assisted-by: Claude Code / claude-sonnet-4-6 and claude-opus-4.8
Signed-off-by: Larry Gritz <lg@larrygritz.com>1 parent ac508f9 commit 70b812a
41 files changed
Lines changed: 8181 additions & 35 deletions
File tree
- .github/workflows
- docs/dev/specs/002-backend-cpp
- checklists
- src
- build-scripts
- cmake
- include
- OSL
- liboslcomp
- liboslexec
- testsuite
- area
- ref
- backend-cpp
- ref
- layers-entry
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
210 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
211 | 213 | | |
212 | 214 | | |
213 | 215 | | |
| |||
484 | 486 | | |
485 | 487 | | |
486 | 488 | | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
487 | 492 | | |
488 | 493 | | |
489 | 494 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
121 | 122 | | |
122 | 123 | | |
123 | 124 | | |
| |||
Lines changed: 36 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
0 commit comments