Commit 35aa264
Add type information for needed attributes. (#1650)
We can currently query which attribute names and scopes are requested in a shader. This PR extends that idea to also allow querying the attribute types. This now more closely matches the equivalent available queries for user data.
For example, this shader:
```
shader Shader
{
color c;
getattribute("user_color", c);
string s;
getattribute("user_string", s);
}
```
allows us to do this:
```
int nattr = 0;
if (shadingSys->getattribute(shaderRef.get(), "num_attributes_needed", nattr) && nattr)
{
// this already works
OIIO::ustring* names = nullptr;
shadingSys->getattribute(shaderRef.get(), "attributes_needed", OSL::TypeDesc::PTR, &names);
// this is the added feature
OIIO::TypeDesc* types = nullptr;
shadingSys->getattribute(shaderRef.get(), "attribute_types", OSL::TypeDesc::PTR, &types);
// nattr: 2
// names: ["user_color", "user_string"]
// types: [OIIO::TypeColor, OIIO::TypeString]
}
```
The motivation behind this feature is to perform additional type validation at material compile time when determining what primvars can be provided to the shader.
One side-effect of this change to be aware of is that, as mentioned in the code comments, if the same name is requested multiple times with different types, it will now be reported multiple times. Hopefully this is not too much of an issue as the same behaviour also occurs when an attribute is requested in multiple scopes, or when user data is requested with multiple types.
Signed-off-by: Curtis Black <[email protected]>1 parent 5c1617f commit 35aa264
File tree
5 files changed
+59
-16
lines changed- src
- include/OSL
- liboslexec
- testshade
5 files changed
+59
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
432 | 432 | | |
433 | 433 | | |
434 | 434 | | |
435 | | - | |
| 435 | + | |
| 436 | + | |
436 | 437 | | |
437 | | - | |
| 438 | + | |
438 | 439 | | |
439 | 440 | | |
440 | 441 | | |
| 442 | + | |
| 443 | + | |
441 | 444 | | |
442 | 445 | | |
443 | 446 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
| 214 | + | |
214 | 215 | | |
215 | | - | |
216 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
217 | 219 | | |
218 | 220 | | |
219 | 221 | | |
| |||
223 | 225 | | |
224 | 226 | | |
225 | 227 | | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
226 | 237 | | |
227 | 238 | | |
228 | 239 | | |
| |||
1919 | 1930 | | |
1920 | 1931 | | |
1921 | 1932 | | |
| 1933 | + | |
1922 | 1934 | | |
1923 | 1935 | | |
1924 | 1936 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3331 | 3331 | | |
3332 | 3332 | | |
3333 | 3333 | | |
| 3334 | + | |
3334 | 3335 | | |
3335 | 3336 | | |
3336 | | - | |
3337 | | - | |
3338 | | - | |
| 3337 | + | |
| 3338 | + | |
| 3339 | + | |
3339 | 3340 | | |
| 3341 | + | |
3340 | 3342 | | |
3341 | | - | |
3342 | | - | |
| 3343 | + | |
3343 | 3344 | | |
3344 | | - | |
3345 | | - | |
3346 | | - | |
| 3345 | + | |
| 3346 | + | |
| 3347 | + | |
3347 | 3348 | | |
3348 | 3349 | | |
3349 | 3350 | | |
3350 | 3351 | | |
3351 | 3352 | | |
3352 | 3353 | | |
3353 | | - | |
| 3354 | + | |
| 3355 | + | |
| 3356 | + | |
| 3357 | + | |
| 3358 | + | |
| 3359 | + | |
| 3360 | + | |
| 3361 | + | |
| 3362 | + | |
| 3363 | + | |
| 3364 | + | |
| 3365 | + | |
| 3366 | + | |
| 3367 | + | |
| 3368 | + | |
3354 | 3369 | | |
| 3370 | + | |
| 3371 | + | |
3355 | 3372 | | |
3356 | 3373 | | |
3357 | 3374 | | |
| |||
3403 | 3420 | | |
3404 | 3421 | | |
3405 | 3422 | | |
3406 | | - | |
| 3423 | + | |
| 3424 | + | |
3407 | 3425 | | |
3408 | 3426 | | |
3409 | 3427 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2102 | 2102 | | |
2103 | 2103 | | |
2104 | 2104 | | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
2105 | 2110 | | |
2106 | 2111 | | |
2107 | 2112 | | |
| |||
3560 | 3565 | | |
3561 | 3566 | | |
3562 | 3567 | | |
| 3568 | + | |
3563 | 3569 | | |
3564 | 3570 | | |
3565 | 3571 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1468 | 1468 | | |
1469 | 1469 | | |
1470 | 1470 | | |
| 1471 | + | |
1471 | 1472 | | |
1472 | 1473 | | |
1473 | 1474 | | |
1474 | 1475 | | |
1475 | | - | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
1476 | 1479 | | |
1477 | | - | |
| 1480 | + | |
| 1481 | + | |
1478 | 1482 | | |
1479 | 1483 | | |
1480 | 1484 | | |
| |||
0 commit comments