PixarAnimationStudios / OpenUSD

Universal Scene Description
http://www.openusd.org
Other
6.03k stars 1.19k forks source link

Hydra: primvar changes leave stale resources #906

Open danlea opened 5 years ago

danlea commented 5 years ago

Description of Issue

Scene changes may result in a removal or change of interpolation of primvars. Such a change should be correctly handled following dirtying of an Rprim's primvars, or at least with the additional dirtying of repr. However, draw items populate resources additively, meaning primvar BARs are left with stale buffers. Garbage collection has no effect. HdSt shader generation incoporates such buffers, resulting in stale shaders. Furthermore, if interpolation changes, the shader code will contain duplicate functions (one for each interpolation), and will hence fail to compile.

The only way to update correctly (as far as I can tell) is to remove and reinsert the Rprim. This is heavy-handed, and is particularly problematic in that it would make it especially awkward to defer validation of altered primvars to the multi-threaded data-gathering phase, as provision of an invalid value in Get() does not remove the buffer itself, an reinsertion would presumably need to wait until after the current execution.

The issue is perhaps broader than this description, but this bug is at least one concrete manifestation.

Steps to Reproduce

Compile a scene delegate that adds an Rprim with a primvar, e.g. color, with a given interpolation, e.g. constant, then alter the interpolation to, for example, uniform. The scene delegate can mark the Rprim as dirty as can be, mark all collections dirty (prior to 19.07), set garbage collection needed, and yet the old resource will not be removed. Using the HdSt render delegate, the Rprim will disappear following a shader compilation failure, with an error message of the following form:

pxr/imaging/lib/hdSt/glslProgram.cpp: CompileShader: 137: Failed to compile shader (GL_FRAGMENT_SHADER): 0(247) : error C1013: function "HdGet_color" is already defined at 0(187)
0(251) : error C1013: function "HdGet_color" is already defined at 0(191)

System Information (OS, Hardware)

Should be system/hardware independent.

Package Versions

Reproduced in USD 19.01 and 19.05

Build Flags

-

jtran56 commented 5 years ago

Filed as internal issue #USD-5450.