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

Shader fails to initialize uniform variable on linux #3737

Closed
tangytang opened this issue May 26, 2022 · 11 comments
Closed

Shader fails to initialize uniform variable on linux #3737

tangytang opened this issue May 26, 2022 · 11 comments
Assignees
Labels
bug Something isn't working display

Comments

@tangytang
Copy link

tangytang commented May 26, 2022

Description of Problem

Unable to get Viewer App started due to error in the console:
Screenshot from 2022-05-26 16-59-18

Error Code

​ Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of HeaderRow which is inside StrictMode. Instead, add a ref directly to the element you want to reference. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-find-node
at div
at t (http://localhost:3000/static/js/vendors~main.chunk.js:517983:89125)
at div
at t (http://localhost:3000/static/js/vendors~main.chunk.js:517983:83671)
at div
at t (http://localhost:3000/static/js/vendors~main.chunk.js:517983:76743)
at div
at div
at t (http://localhost:3000/static/js/vendors~main.chunk.js:517983:57330)
at ElementResizeObserver (http://localhost:3000/static/js/vendors~main.chunk.js:352917:34)
at div
at Table (http://localhost:3000/static/js/vendors~main.chunk.js:95475:9)
at div
at div
at ElementList (http://localhost:3000/static/js/vendors~main.chunk.js:422371:24)
at div
at div
at div
at MultiElementPropertyGrid (http://localhost:3000/static/js/vendors~main.chunk.js:422657:114)
at div
at ScrollableWidgetContent (http://localhost:3000/static/js/vendors~main.chunk.js:23773:72)
at WidgetContent (http://localhost:3000/static/js/vendors~main.chunk.js:69546:20)
at WidgetContentRenderer (http://localhost:3000/static/js/vendors~main.chunk.js:24132:82)
at WidgetContentRenderers (http://localhost:3000/static/js/vendors~main.chunk.js:24119:75)
at div
at WidgetPanelsComponent (http://localhost:3000/static/js/vendors~main.chunk.js:23558:69)
at WidgetPanels (http://localhost:3000/static/js/vendors~main.chunk.js:23552:109)
at WidgetInternals (http://localhost:3000/static/js/vendors~main.chunk.js:69678:133)
at WidgetPanelsFrontstageComponent
at WidgetContentManager (http://localhost:3000/static/js/vendors~main.chunk.js:24054:87)
at CursorTypeProvider (http://localhost:3000/static/js/vendors~main.chunk.js:11285:72)
at DraggedResizeHandleProvider (http://localhost:3000/static/js/vendors~main.chunk.js:10865:19)
at DraggedPanelSideProvider (http://localhost:3000/static/js/vendors~main.chunk.js:10861:27)
at DraggedWidgetIdProvider (http://localhost:3000/static/js/vendors~main.chunk.js:10857:21)
at DragProvider (http://localhost:3000/static/js/vendors~main.chunk.js:10832:69)
at NineZoneProvider (http://localhost:3000/static/js/vendors~main.chunk.js:11205:106)
at NineZone (http://localhost:3000/static/js/vendors~main.chunk.js:11192:13)
at div
at ActiveFrontstageDefProvider (http://localhost:3000/static/js/vendors~main.chunk.js:69816:40)
at WidgetPanelsFrontstage (http://localhost:3000/static/js/vendors~main.chunk.js:69798:112)
at main
at ConfigurableUiContent (http://localhost:3000/static/js/vendors~main.chunk.js:39810:108)
at FrameworkVersion (http://localhost:3000/static/js/vendors~main.chunk.js:48691:86)
at ThemeProvider (http://localhost:3000/static/js/vendors~main.chunk.js:393848:23)
at div
at ThemeManagerComponent (http://localhost:3000/static/js/vendors~main.chunk.js:64240:9)
at ConnectFunction (http://localhost:3000/static/js/vendors~main.chunk.js:552838:75)
at IModelViewer (http://localhost:3000/static/js/vendors~main.chunk.js:428932:25)
at Provider (http://localhost:3000/static/js/vendors~main.chunk.js:552543:20)
at div
at http://localhost:3000/static/js/vendors~main.chunk.js:428716:69
at IModelLoader (http://localhost:3000/static/js/vendors~main.chunk.js:428809:15)
at ErrorBoundary (http://localhost:3000/static/js/vendors~main.chunk.js:354037:9)
at BaseViewer (http://localhost:3000/static/js/vendors~main.chunk.js:428155:23)
at Viewer (http://localhost:3000/static/js/vendors~main.chunk.js:431180:80)
at div
at App (http://localhost:3000/static/js/main.chunk.js:182:89)

@aruniverse
Copy link
Member

So the warning you're seeing is something we will need to fix. But i don't think its actually what's throwing the error that you're seeing in the viewer.

Can you check your compatibility with iTwin.js here ?
Are you using a test model from Bentley or is this one of your own?
Have you added any additional code to display decorators or change the graphics?

@tangytang
Copy link
Author

Can you check your compatibility
Screenshot from 2022-05-27 07-23-01
atibility with iTwin.js here ?

Are you using a test model from Bentley or is this one of your own?
I'm using one of the Bentley samples (Stadium Project)

Have you added any additional code to display decorators or change the graphics?
No

Let me know what kind of debugging information you need. I'll be glad to help.

@aruniverse
Copy link
Member

aruniverse commented May 27, 2022

Please provide the iTwin.js Version you're using

@tangytang
Copy link
Author

tangytang commented May 27, 2022

Hi @aruniverse

See my package.json configuration:

{
"name": "***",
"version": "0.1.0",
"private": true,
"dependencies": {
"@bentley/icons-generic": "^1.0.34",
"@bentley/react-scripts": "^4.0.7",
"@itwin/appui-abstract": "^3.2.0",
"@itwin/appui-layout-react": "^3.2.0",
"@itwin/appui-react": "^3.2.0",
"@itwin/browser-authorization": "^0.5.1",
"@itwin/components-react": "^3.2.0",
"@itwin/core-bentley": "^3.2.0",
"@itwin/core-common": "^3.2.0",
"@itwin/core-frontend": "^3.2.0",
"@itwin/core-geometry": "^3.2.0",
"@itwin/core-i18n": "^3.2.0",
"@itwin/core-markup": "^3.2.0",
"@itwin/core-orbitgt": "^3.2.0",
"@itwin/core-quantity": "^3.2.0",
"@itwin/core-react": "^3.2.0",
"@itwin/core-telemetry": "^3.2.0",
"@itwin/imodel-components-react": "^3.2.0",
"@itwin/imodels-access-frontend": "^1.0.1",
"@itwin/imodels-client-management": "^1.0.1",
"@itwin/itwinui-react": "^1.38.1",
"@itwin/presentation-common": "^3.2.0",
"@itwin/presentation-frontend": "^3.2.0",
"@itwin/reality-data-client": "^0.7.2",
"@itwin/web-viewer-react": "^2.0.11",
"@itwin/webgl-compatibility": "^3.2.0",
"@types/history": "^4.7.11",
"@types/node": "^14.18.18",
"@types/react": "^17.0.45",
"@types/react-dom": "^17.0.17",
"history": "^4.10.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-redux": "^7.2.8",
"typescript": "~4.3.0"
},
"scripts": {
"start": "react-scripts --max_old_space_size=4096 start",
"build": "react-scripts --max_old_space_size=4096 build",
"test": "react-scripts --max_old_space_size=4096 test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": [
"last 4 chrome version",
"last 4 firefox version",
"last 4 safari version",
"last 4 ios version",
"last 4 ChromeAndroid version",
"last 4 edge version",
"not dead",
"not <0.2%"
]
}

@pmconne
Copy link
Member

pmconne commented Jun 2, 2022

Thanks for the info @tangytang. This error is most likely the result of your specific graphics card driver having optimized away one of the variables used by a shader program. We compile all of our shaders on Linux, Windows, and macOS without error, but some drivers are smarter about optimizations. We will investigate and fix the shader.

@pmconne pmconne self-assigned this Jun 2, 2022
@pmconne pmconne added the bug Something isn't working label Jun 2, 2022
@aruniverse aruniverse transferred this issue from iTwin/viewer Jun 2, 2022
@pmconne pmconne added the display label Jun 2, 2022
@pmconne pmconne changed the title Bug: findDOMNode is deprecated in StrictMode Shader fails to initialize uniform variable on linux Jun 2, 2022
@pmconne
Copy link
Member

pmconne commented Jun 3, 2022

I am able to reproduce this on my Ubuntu box with GPU enabled. The core-frontend shader compilation tests use software rendering, which does not produce this error.

@pmconne
Copy link
Member

pmconne commented Jun 3, 2022

Investigation results: the problematic shader's description is "Surface: Opaque-Instanced-Pick". The vertex shader uses u_patternFeatureId to compute g_featureIndex but never forwards the result to the fragment shader, so that all gets optimized away. The fragment shader outputs zero for FragColor1 and FragColor2, instead of outputting the pick data.
The reason that element locate works for instanced surfaces anyway is that we force edge testing while reading pixels, and the "Surface: Opaque-Instanced-EdgeTestNeeded-Pick" shader does correctly output the pick data.

@pmconne pmconne removed their assignment Jun 6, 2022
@pmconne
Copy link
Member

pmconne commented Jun 6, 2022

This appears to have been introduced 3 years ago. That PR made it so that for the combination of FeatureMode.Pick and IsEdgeTestNeeded.No (excluding classifiers), the shader computes the feature index but does nothing with it. Presumably we were relying on the compiler to optimize out those unnecessary computations, but the introduction of u_patternFeatureId appears to show that only Linux fully optimizes them, including removal of the uniform. Ideally we would not include those computations in the first place.

@DStradley
Copy link
Contributor

This appears to have been introduced 3 years ago. That PR made it so that for the combination of FeatureMode.Pick and IsEdgeTestNeeded.No (excluding classifiers), the shader computes the feature index but does nothing with it. Presumably we were relying on the compiler to optimize out those unnecessary computations, but the introduction of u_patternFeatureId appears to show that only Linux fully optimizes them, including removal of the uniform. Ideally we would not include those computations in the first place.

@pmconne @markschlosseratbentley - I looked at the output glsl, the hlsl, and the compiled assembly for Angle for this case and it is fully optimized. The way Angle and D3D work, it does leave the u_patternFeatureId in the uniform table, but marks it as unused (which is why we don't get a uniform error). All references, calculations, texture lookups for calculations, etc. have been removed. I suppose there is the very small CPU overhead of writing the value to this unused location, and ideally we should not generate unused code in glsl (for confusion if nothing else), but with #3754 done, to me fixing this becomes a low priority.

@markschlosseratbentley
Copy link
Contributor

Closing this because #3754 is merged and fixed the issue. Related issue #3740 has been also closed. I have created #3773 to track any remaining work based on the comments from @DStradley above.

@achrysaetos
Copy link
Contributor

We also fixed the findDOMNode warning in the console with iTwin/viewer-components-react#283.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working display
Projects
None yet
Development

No branches or pull requests

6 participants