Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base closure pointer in layer is incorrect when using batched execute #1801

Open
johnfea opened this issue Apr 20, 2024 · 1 comment
Open
Labels
batch shading Specific to the SIMD batch shading back end bug Crash or wrong behavior of an existing feature. shading system Related to the runtime shader execution

Comments

@johnfea
Copy link
Contributor

johnfea commented Apr 20, 2024

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<MxLayerParams>();
assert(srcparams->base != closure);

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
<correct output, no problem!>

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
@lgritz lgritz added bug Crash or wrong behavior of an existing feature. shading system Related to the runtime shader execution batch shading Specific to the SIMD batch shading back end labels May 8, 2024
@johnfea
Copy link
Contributor Author

johnfea commented Jun 23, 2024

The problem occurs only when there's this type of usage of closure color:

BSDF = layer(generalized_schlick_bsdf(),BSDF)

So a workaround is to always do this instead:

BSDF = layer(generalized_schlick_bsdf(),BSDF2)

From this one can also speculate what might happen here: base closure pointer is at some point (too late) obtained from the BSDF closure and written into the layer closure, but the BSDF closure is now the layer closure itself instead of the base closure.

This issue results in infinite loop when parsing output closure tree so it definitely needs to be fixed at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
batch shading Specific to the SIMD batch shading back end bug Crash or wrong behavior of an existing feature. shading system Related to the runtime shader execution
Projects
None yet
Development

No branches or pull requests

2 participants