AcademySoftwareFoundation / AcademySoftwareFoundation/OpenShadingLanguage

Base closure pointer in layer is incorrect when using batched execute

Open
#1,801 1 comment 0 reactions 0 assignees View on GitHub
batch shading bug shading system
Dominant language
C++
Stars
2.3k
Forks
414
Avg merge
3d 1h
Merged PRs (30d)
10

Description

### Problem

Base closure pointer in osl layer points to its parent layer closure when using batched execute while it should actually point to a diffuse closure.

```
void process_bsdf_closure(const ClosureColor* closure) {
const ClosureComponent* comp = closure->as_comp();
const MxLayerParams* srcparams = comp->as();
assert(srcparams->base != closure);
```

[minimal_test_case.zip](https://github.com/AcademySoftwareFoundation/OpenShadingLanguage/files/15049651/minimal_test_case.zip)

### Steps to Reproduce

Download the attached minimal sample and issue the following commands:

g++ -DUSE_BATCHED -mavx2 -mfma -mtune=skylake -mf16c -g test2.cpp -loslcomp -loslexec -loslnoise -loslquery -lOpenImageIO -lOpenImageIO_Util
./a.out
parsing mx layer closure
parsing generalized schlick closure
Error: base closure in mx layer points back to currently parsed closure

g++ -mavx2 -mfma -mtune=skylake -mf16c -g test2.cpp -loslcomp -loslexec -loslnoise -loslquery -lOpenImageIO -lOpenImageIO_Util
./a.out
parsing mx layer closure
parsing generalized schlick closure
parsing diffuse closure

Here's .osl shader codes in the .zip:

```
shader layer_test(
color base_color = color(0.8, 0.8, 0.8),
color specular_tint = color(1.0),
float roughness = 0.5,
normal Tangent = normalize(dPdu),
output closure color BSDF = 0)
{
BSDF = base_color * diffuse(N);
color F0 = specular_tint;
color F90 = color(1.0);
BSDF = layer(generalized_schlick_bsdf(N, Tangent, color(1.0), color(0.0), roughness, roughness, F0, F90, 0.0, "ggx"),BSDF);
}
```

```
surface output_surface(closure color Surface = 0)
{
Ci = Surface;
}
```

### Versions

* OSL branch/version: v1.13.8.0
* OS: linux 64-bit 5.10.0-18-amd64
* C++ compiler: g++ 10.2.1
* LLVM version: 11.0.1-2
* OIIO version: v2.5.4.0

Contributor guide

Open the contributing guide

Research direction

Start with the attached minimal test case, especially test2.cpp, and reproduce the failure with USE_BATCHED enabled and without it. Trace process_bsdf_closure, MxLayerParams, and the osl layer closure handling; done means the batched run reports the diffuse closure as the base and the existing assertion no longer fails, while the non-batched output remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, linux
Domain
compilers, computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.