cuju-render 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cuju/render/__init__.py +759 -0
- cuju/render/__main__.py +1065 -0
- cuju/render/_export/__init__.py +3 -0
- cuju/render/_export/feed.py +542 -0
- cuju/render/_export/sizes.py +157 -0
- cuju/render/_export/video.py +1618 -0
- cuju/render/_export/video_jobs.py +408 -0
- cuju/render/_format/__init__.py +3 -0
- cuju/render/_format/annotations.py +235 -0
- cuju/render/_format/codec.py +307 -0
- cuju/render/_format/keep.py +121 -0
- cuju/render/_format/recording.py +860 -0
- cuju/render/_format/writer.py +54 -0
- cuju/render/_guide/__init__.py +3 -0
- cuju/render/_guide/doctor.py +523 -0
- cuju/render/_guide/help.py +62 -0
- cuju/render/_guide/tutorial.py +254 -0
- cuju/render/_http/__init__.py +3 -0
- cuju/render/_http/commands.py +57 -0
- cuju/render/_http/headers.py +103 -0
- cuju/render/_http/launch.py +500 -0
- cuju/render/_http/launchers.py +408 -0
- cuju/render/_http/pwa.py +128 -0
- cuju/render/_http/server.py +2105 -0
- cuju/render/_http/window.py +360 -0
- cuju/render/_moments/__init__.py +3 -0
- cuju/render/_moments/captions.py +284 -0
- cuju/render/_moments/events.py +1123 -0
- cuju/render/_moments/search.py +694 -0
- cuju/render/_packages/__init__.py +3 -0
- cuju/render/_packages/glsl.py +746 -0
- cuju/render/_packages/loudness.py +334 -0
- cuju/render/_packages/pack.py +1959 -0
- cuju/render/_packages/presentation.py +1376 -0
- cuju/render/_packages/vocabulary.py +609 -0
- cuju/render/_playing/__init__.py +3 -0
- cuju/render/_playing/achievements.py +463 -0
- cuju/render/_playing/bench.py +609 -0
- cuju/render/_playing/challenges.py +1813 -0
- cuju/render/_playing/demo.py +323 -0
- cuju/render/_playing/draw.py +211 -0
- cuju/render/_playing/errors.py +20 -0
- cuju/render/_playing/game.py +645 -0
- cuju/render/_playing/limits.py +339 -0
- cuju/render/_playing/play.py +926 -0
- cuju/render/_playing/policy_worker.py +250 -0
- cuju/render/_playing/strict.py +810 -0
- cuju/render/_registry/__init__.py +3 -0
- cuju/render/_registry/clips.py +394 -0
- cuju/render/_registry/joints.py +108 -0
- cuju/render/_registry/teams.py +2058 -0
- cuju/render/_store/__init__.py +3 -0
- cuju/render/_store/home.py +70 -0
- cuju/render/_store/library.py +604 -0
- cuju/render/_store/samples.py +163 -0
- cuju/render/_text/__init__.py +3 -0
- cuju/render/_text/languages.py +637 -0
- cuju/render/_text/messages.py +1396 -0
- cuju/render/_tournaments/__init__.py +3 -0
- cuju/render/_tournaments/results.py +547 -0
- cuju/render/_tournaments/tournament.py +2742 -0
- cuju/render/_tournaments/tournament_cli.py +587 -0
- cuju/render/_tournaments/tournament_runner.py +1975 -0
- cuju/render/_version.py +6 -0
- cuju/render/_watch/__init__.py +3 -0
- cuju/render/_watch/grid.py +265 -0
- cuju/render/_watch/live.py +664 -0
- cuju/render/_watch/notebook.py +79 -0
- cuju/render/_watch/show.py +171 -0
- cuju/render/samples/sample-11v11.cjr +0 -0
- cuju/render/samples/sample-5v5.cjr +0 -0
- cuju/render/samples/teams/starter/main.py +33 -0
- cuju/render/scenarios/benchmark_full_game_11_vs_11_easy.py +46 -0
- cuju/render/scenarios/benchmark_full_game_11_vs_11_hard.py +46 -0
- cuju/render/scenarios/benchmark_full_game_11_vs_11_medium.py +46 -0
- cuju/render/scenarios/benchmark_full_game_5_vs_5_easy.py +34 -0
- cuju/render/scenarios/benchmark_full_game_5_vs_5_hard.py +34 -0
- cuju/render/scenarios/benchmark_full_game_5_vs_5_medium.py +34 -0
- cuju/render/web/assets/adboard_polygon.webp +0 -0
- cuju/render/web/assets/adboard_your_ad_here.webp +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-combatmelee.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-general.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-movementadvanced.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-movementbasic.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-simulation.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-special.glb +0 -0
- cuju/render/web/assets/ball.glb +0 -0
- cuju/render/web/assets/challenges/3_vs_1_with_keeper.mp4 +0 -0
- cuju/render/web/assets/challenges/3_vs_1_with_keeper.webp +0 -0
- cuju/render/web/assets/challenges/corner.mp4 +0 -0
- cuju/render/web/assets/challenges/corner.webp +0 -0
- cuju/render/web/assets/challenges/counterattack_easy.mp4 +0 -0
- cuju/render/web/assets/challenges/counterattack_easy.webp +0 -0
- cuju/render/web/assets/challenges/counterattack_hard.mp4 +0 -0
- cuju/render/web/assets/challenges/counterattack_hard.webp +0 -0
- cuju/render/web/assets/challenges/empty_goal.mp4 +0 -0
- cuju/render/web/assets/challenges/empty_goal.webp +0 -0
- cuju/render/web/assets/challenges/empty_goal_close.mp4 +0 -0
- cuju/render/web/assets/challenges/empty_goal_close.webp +0 -0
- cuju/render/web/assets/challenges/manifest.json +375 -0
- cuju/render/web/assets/challenges/one_on_one.mp4 +0 -0
- cuju/render/web/assets/challenges/one_on_one.webp +0 -0
- cuju/render/web/assets/challenges/one_on_one_hard.mp4 +0 -0
- cuju/render/web/assets/challenges/one_on_one_hard.webp +0 -0
- cuju/render/web/assets/challenges/pass_and_shoot_with_keeper.mp4 +0 -0
- cuju/render/web/assets/challenges/pass_and_shoot_with_keeper.webp +0 -0
- cuju/render/web/assets/challenges/run_pass_and_shoot_with_keeper.mp4 +0 -0
- cuju/render/web/assets/challenges/run_pass_and_shoot_with_keeper.webp +0 -0
- cuju/render/web/assets/challenges/run_to_score.mp4 +0 -0
- cuju/render/web/assets/challenges/run_to_score.webp +0 -0
- cuju/render/web/assets/challenges/run_to_score_with_keeper.mp4 +0 -0
- cuju/render/web/assets/challenges/run_to_score_with_keeper.webp +0 -0
- cuju/render/web/assets/challenges/single_goal_versus_lazy.mp4 +0 -0
- cuju/render/web/assets/challenges/single_goal_versus_lazy.webp +0 -0
- cuju/render/web/assets/crowd.webp +0 -0
- cuju/render/web/assets/crowd_normal.webp +0 -0
- cuju/render/web/assets/cuju-logo-384.png +0 -0
- cuju/render/web/assets/cuju-logo.png +0 -0
- cuju/render/web/assets/cuju-logo.svg +46 -0
- cuju/render/web/assets/cuju-mark-light.svg +33 -0
- cuju/render/web/assets/cuju-mark.svg +33 -0
- cuju/render/web/assets/goal.glb +0 -0
- cuju/render/web/assets/grass.webp +0 -0
- cuju/render/web/assets/hair_black.png +0 -0
- cuju/render/web/assets/hair_blonde.png +0 -0
- cuju/render/web/assets/hair_brown.png +0 -0
- cuju/render/web/assets/hair_darkblonde.png +0 -0
- cuju/render/web/assets/hair_long01.glb +0 -0
- cuju/render/web/assets/hair_long02.glb +0 -0
- cuju/render/web/assets/hair_medium01.glb +0 -0
- cuju/render/web/assets/hair_red.png +0 -0
- cuju/render/web/assets/hair_short01.glb +0 -0
- cuju/render/web/assets/hair_short02.glb +0 -0
- cuju/render/web/assets/icons/cuju-192.png +0 -0
- cuju/render/web/assets/icons/cuju-512.png +0 -0
- cuju/render/web/assets/icons/cuju-maskable-512.png +0 -0
- cuju/render/web/assets/kit_goalkeeper.webp +0 -0
- cuju/render/web/assets/kit_mask.png +0 -0
- cuju/render/web/assets/kit_normal.webp +0 -0
- cuju/render/web/assets/manifest.json +601 -0
- cuju/render/web/assets/models/kaykit-barbarian.glb +0 -0
- cuju/render/web/assets/models/kaykit-barbarian.json +23 -0
- cuju/render/web/assets/models/kaykit-knight.glb +0 -0
- cuju/render/web/assets/models/kaykit-knight.json +23 -0
- cuju/render/web/assets/models/kaykit-mage.glb +0 -0
- cuju/render/web/assets/models/kaykit-mage.json +23 -0
- cuju/render/web/assets/models/kaykit-mannequin-medium.glb +0 -0
- cuju/render/web/assets/models/kaykit-mannequin-medium.json +23 -0
- cuju/render/web/assets/models/kaykit-ranger.glb +0 -0
- cuju/render/web/assets/models/kaykit-ranger.json +23 -0
- cuju/render/web/assets/models/kaykit-rogue-hooded.glb +0 -0
- cuju/render/web/assets/models/kaykit-rogue-hooded.json +23 -0
- cuju/render/web/assets/models/kaykit-rogue.glb +0 -0
- cuju/render/web/assets/models/kaykit-rogue.json +23 -0
- cuju/render/web/assets/models/kaykit-skeleton-mage.glb +0 -0
- cuju/render/web/assets/models/kaykit-skeleton-mage.json +23 -0
- cuju/render/web/assets/models/kaykit-skeleton-minion.glb +0 -0
- cuju/render/web/assets/models/kaykit-skeleton-minion.json +23 -0
- cuju/render/web/assets/models/kaykit-skeleton-rogue.glb +0 -0
- cuju/render/web/assets/models/kaykit-skeleton-rogue.json +23 -0
- cuju/render/web/assets/models/kaykit-skeleton-warrior.glb +0 -0
- cuju/render/web/assets/models/kaykit-skeleton-warrior.json +23 -0
- cuju/render/web/assets/pitch.webp +0 -0
- cuju/render/web/assets/pitch_normal.webp +0 -0
- cuju/render/web/assets/player.glb +0 -0
- cuju/render/web/assets/shoe.webp +0 -0
- cuju/render/web/assets/shoe_sole.png +0 -0
- cuju/render/web/assets/skin_01.png +0 -0
- cuju/render/web/assets/skin_02.png +0 -0
- cuju/render/web/assets/skin_03.png +0 -0
- cuju/render/web/assets/skin_04.png +0 -0
- cuju/render/web/assets/sounds/applause.ogg +0 -0
- cuju/render/web/assets/sounds/beach-wave-1.ogg +0 -0
- cuju/render/web/assets/sounds/beach-wave-2.ogg +0 -0
- cuju/render/web/assets/sounds/beach-wave-3.ogg +0 -0
- cuju/render/web/assets/sounds/beach-wave-4.ogg +0 -0
- cuju/render/web/assets/sounds/city-horn.ogg +0 -0
- cuju/render/web/assets/sounds/city-loop.ogg +0 -0
- cuju/render/web/assets/sounds/city-siren.ogg +0 -0
- cuju/render/web/assets/sounds/crowd-cheer.ogg +0 -0
- cuju/render/web/assets/sounds/crowd-loop.ogg +0 -0
- cuju/render/web/assets/sounds/crowd-ooh.ogg +0 -0
- cuju/render/web/assets/sounds/gulls.ogg +0 -0
- cuju/render/web/assets/sounds/neon-sting.ogg +0 -0
- cuju/render/web/assets/sounds/rain-loop.ogg +0 -0
- cuju/render/web/assets/sounds/sounds.json +46 -0
- cuju/render/web/assets/sounds/space-beep.ogg +0 -0
- cuju/render/web/assets/sounds/space-hum.ogg +0 -0
- cuju/render/web/assets/sounds/space-radio.ogg +0 -0
- cuju/render/web/assets/sounds/whistle-long.ogg +0 -0
- cuju/render/web/assets/sounds/whistle-short.ogg +0 -0
- cuju/render/web/assets/sounds/wind-loop.ogg +0 -0
- cuju/render/web/easy.css +357 -0
- cuju/render/web/export.html +23 -0
- cuju/render/web/feed.css +262 -0
- cuju/render/web/feed.html +28 -0
- cuju/render/web/flat.css +120 -0
- cuju/render/web/home.css +837 -0
- cuju/render/web/index.html +373 -0
- cuju/render/web/js/boot.js +50 -0
- cuju/render/web/js/broadcast/audio.js +2141 -0
- cuju/render/web/js/broadcast/celebrate.js +1238 -0
- cuju/render/web/js/broadcast/decisions.js +609 -0
- cuju/render/web/js/broadcast/hud.js +352 -0
- cuju/render/web/js/broadcast/show.js +3614 -0
- cuju/render/web/js/broadcast/transition.js +2231 -0
- cuju/render/web/js/broadcast/voices.js +153 -0
- cuju/render/web/js/capture.js +101 -0
- cuju/render/web/js/core/accessibility.js +90 -0
- cuju/render/web/js/core/api.js +429 -0
- cuju/render/web/js/core/comfort.js +135 -0
- cuju/render/web/js/core/i18n.js +705 -0
- cuju/render/web/js/core/icons.js +167 -0
- cuju/render/web/js/core/input-settings.js +156 -0
- cuju/render/web/js/core/keys.js +277 -0
- cuju/render/web/js/core/language-ui.js +125 -0
- cuju/render/web/js/core/menu.js +853 -0
- cuju/render/web/js/core/names.js +113 -0
- cuju/render/web/js/core/page-structure.js +110 -0
- cuju/render/web/js/core/scenarios.js +109 -0
- cuju/render/web/js/core/spoilers.js +236 -0
- cuju/render/web/js/core/typeahead.js +38 -0
- cuju/render/web/js/export/dom-picture.js +330 -0
- cuju/render/web/js/export/export-host.js +97 -0
- cuju/render/web/js/export/feed-dialog.js +191 -0
- cuju/render/web/js/export/feed-params.js +266 -0
- cuju/render/web/js/export/feed.js +363 -0
- cuju/render/web/js/export/mp4-mux.js +295 -0
- cuju/render/web/js/export/photo-core.js +313 -0
- cuju/render/web/js/export/photo.js +1314 -0
- cuju/render/web/js/export/safe-frame.js +59 -0
- cuju/render/web/js/export/size-fields.js +103 -0
- cuju/render/web/js/export/sizes.js +178 -0
- cuju/render/web/js/export/video-boot.js +55 -0
- cuju/render/web/js/export/video-browser.js +325 -0
- cuju/render/web/js/export/video-export.js +417 -0
- cuju/render/web/js/export/video-plan.js +207 -0
- cuju/render/web/js/export/video-range.js +185 -0
- cuju/render/web/js/export/webm-mux.js +198 -0
- cuju/render/web/js/feed-boot.js +151 -0
- cuju/render/web/js/feed-frame.js +101 -0
- cuju/render/web/js/help/doctor.js +488 -0
- cuju/render/web/js/help/firstrun.js +379 -0
- cuju/render/web/js/help/help-center.js +438 -0
- cuju/render/web/js/help/install-offer.js +164 -0
- cuju/render/web/js/help/install-state.js +104 -0
- cuju/render/web/js/help/lessons-core.js +207 -0
- cuju/render/web/js/help/lessons.js +463 -0
- cuju/render/web/js/help/palette.js +584 -0
- cuju/render/web/js/help/pwa.js +257 -0
- cuju/render/web/js/help/tour-core.js +241 -0
- cuju/render/web/js/help/tour.js +461 -0
- cuju/render/web/js/main.js +2513 -0
- cuju/render/web/js/pages/draw.js +188 -0
- cuju/render/web/js/pages/fieldpage.js +530 -0
- cuju/render/web/js/pages/home.js +521 -0
- cuju/render/web/js/pages/matches.js +779 -0
- cuju/render/web/js/pages/moments-ui.js +359 -0
- cuju/render/web/js/pages/queue-filters.js +63 -0
- cuju/render/web/js/pages/recording-groups.js +80 -0
- cuju/render/web/js/pages/recordings.js +1069 -0
- cuju/render/web/js/play/bench.js +347 -0
- cuju/render/web/js/play/challenges.js +1302 -0
- cuju/render/web/js/play/medals.js +127 -0
- cuju/render/web/js/play/play.js +1953 -0
- cuju/render/web/js/play/teasers.js +196 -0
- cuju/render/web/js/play/touch.js +350 -0
- cuju/render/web/js/play/tournament-layout.js +487 -0
- cuju/render/web/js/play/tournament-results.js +441 -0
- cuju/render/web/js/play/tournament-strict.js +560 -0
- cuju/render/web/js/play/tournament.js +2585 -0
- cuju/render/web/js/players/animate.js +972 -0
- cuju/render/web/js/players/clips.js +224 -0
- cuju/render/web/js/players/kaykit.js +162 -0
- cuju/render/web/js/players/kits.js +676 -0
- cuju/render/web/js/players/number-patch.js +82 -0
- cuju/render/web/js/players/players.js +2694 -0
- cuju/render/web/js/players/recolor.js +893 -0
- cuju/render/web/js/players/retarget.js +325 -0
- cuju/render/web/js/players/rig-numbers.js +174 -0
- cuju/render/web/js/presentation/animator.js +231 -0
- cuju/render/web/js/presentation/assign.js +85 -0
- cuju/render/web/js/presentation/behaviors.js +440 -0
- cuju/render/web/js/presentation/budget.js +209 -0
- cuju/render/web/js/presentation/catalog.js +1674 -0
- cuju/render/web/js/presentation/clocks.js +72 -0
- cuju/render/web/js/presentation/commands.js +301 -0
- cuju/render/web/js/presentation/contract.js +240 -0
- cuju/render/web/js/presentation/effects.js +904 -0
- cuju/render/web/js/presentation/flash.js +605 -0
- cuju/render/web/js/presentation/freeze-worklet.js +22 -0
- cuju/render/web/js/presentation/glsl.js +464 -0
- cuju/render/web/js/presentation/host.js +323 -0
- cuju/render/web/js/presentation/index.js +2066 -0
- cuju/render/web/js/presentation/loudness-worklet.js +235 -0
- cuju/render/web/js/presentation/loudness.js +740 -0
- cuju/render/web/js/presentation/moments.js +536 -0
- cuju/render/web/js/presentation/post.js +327 -0
- cuju/render/web/js/presentation/preview.js +180 -0
- cuju/render/web/js/presentation/protocol.js +174 -0
- cuju/render/web/js/presentation/reach.js +158 -0
- cuju/render/web/js/presentation/rigging.js +130 -0
- cuju/render/web/js/presentation/sandbox.js +157 -0
- cuju/render/web/js/presentation/shaders.js +235 -0
- cuju/render/web/js/presentation/stage.js +402 -0
- cuju/render/web/js/presentation/teamaudio.js +722 -0
- cuju/render/web/js/presentation/tracks.js +197 -0
- cuju/render/web/js/presentation/values.js +81 -0
- cuju/render/web/js/recording/annotation-data.js +203 -0
- cuju/render/web/js/recording/captions.js +491 -0
- cuju/render/web/js/recording/codec.js +185 -0
- cuju/render/web/js/recording/decode-worker.js +70 -0
- cuju/render/web/js/recording/decode.js +94 -0
- cuju/render/web/js/recording/episodes.js +46 -0
- cuju/render/web/js/recording/format.js +461 -0
- cuju/render/web/js/recording/live.js +348 -0
- cuju/render/web/js/recording/moments-query.js +59 -0
- cuju/render/web/js/recording/moments.js +149 -0
- cuju/render/web/js/recording/pose.js +86 -0
- cuju/render/web/js/recording/timeline.js +275 -0
- cuju/render/web/js/teams/art.js +50 -0
- cuju/render/web/js/teams/clip-editor.js +293 -0
- cuju/render/web/js/teams/editor.js +1979 -0
- cuju/render/web/js/teams/library.js +344 -0
- cuju/render/web/js/teams/painter.js +633 -0
- cuju/render/web/js/teams/surprise-ui.js +195 -0
- cuju/render/web/js/teams/surprise.js +497 -0
- cuju/render/web/js/teams/team-check.js +127 -0
- cuju/render/web/js/watch/annotations.js +270 -0
- cuju/render/web/js/watch/flat.js +366 -0
- cuju/render/web/js/watch/grid.js +436 -0
- cuju/render/web/js/watch/pitch2d.js +289 -0
- cuju/render/web/js/watch/player-tools.js +192 -0
- cuju/render/web/js/watch/presets.js +201 -0
- cuju/render/web/js/world/arenas.js +997 -0
- cuju/render/web/js/world/ball.js +204 -0
- cuju/render/web/js/world/cameras.js +982 -0
- cuju/render/web/js/world/crowd.js +376 -0
- cuju/render/web/js/world/field.js +227 -0
- cuju/render/web/js/world/framing.js +145 -0
- cuju/render/web/js/world/occlusion.js +48 -0
- cuju/render/web/js/world/pitch.js +703 -0
- cuju/render/web/js/world/scene.js +395 -0
- cuju/render/web/js/world/sky.js +325 -0
- cuju/render/web/js/world/stadium.js +1262 -0
- cuju/render/web/js/world/vendor-sky.js +367 -0
- cuju/render/web/js/world/weather.js +264 -0
- cuju/render/web/languages/en.json +4750 -0
- cuju/render/web/lessons.json +137 -0
- cuju/render/web/manifest.webmanifest +23 -0
- cuju/render/web/style.css +8399 -0
- cuju/render/web/sw.js +235 -0
- cuju/render/web/vendor/fabric/LICENSE +16 -0
- cuju/render/web/vendor/fabric/fabric.min.mjs +1 -0
- cuju/render/web/vendor/lucide/LICENSE +43 -0
- cuju/render/web/vendor/lucide/icons.js +141 -0
- cuju/render/web/vendor/three/LICENSE +21 -0
- cuju/render/web/vendor/three/build/three.core.js +60586 -0
- cuju/render/web/vendor/three/build/three.module.js +19719 -0
- cuju/render/web/vendor/three/examples/jsm/loaders/GLTFLoader.js +4925 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/EffectComposer.js +365 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/OutputPass.js +148 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/RenderPass.js +193 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/UnrealBloomPass.js +541 -0
- cuju/render/web/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
- cuju/render/web/vendor/three/examples/jsm/shaders/LuminosityHighPassShader.js +68 -0
- cuju/render/web/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
- cuju/render/web/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1501 -0
- cuju/render/web/vendor/three/examples/jsm/utils/SkeletonUtils.js +496 -0
- cuju_render-0.1.0.dist-info/METADATA +116 -0
- cuju_render-0.1.0.dist-info/RECORD +382 -0
- cuju_render-0.1.0.dist-info/WHEEL +4 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSE +202 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/CC-BY-4.0.txt +396 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/CC0-1.0.txt +127 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/ISC.txt +16 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/MIT.txt +24 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/Unlicense.txt +13 -0
- cuju_render-0.1.0.dist-info/licenses/NOTICE +35 -0
|
@@ -0,0 +1,746 @@
|
|
|
1
|
+
# Copyright 2026 The cuju Authors
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
"""The static checks of the shaders of team presentation packages.
|
|
5
|
+
|
|
6
|
+
A shader of a package is a `.glsl` file of UTF-8 text, at most 256 KB. The renderer writes the
|
|
7
|
+
`#version`, the precision and every uniform in front of it, so a file declares no uniform of its
|
|
8
|
+
own. In the mode `chunks`, the default, the file extends the renderer's standard material with
|
|
9
|
+
hook functions, `cujuVertex`, `cujuColor`, `cujuEmissive`, `cujuRoughness` and `cujuMetalness`,
|
|
10
|
+
and defines at least one of them. In the mode `material` the file is a whole shader material, a
|
|
11
|
+
vertex section after the line `#pragma cuju vertex` and a fragment section after the line
|
|
12
|
+
`#pragma cuju fragment`, each with its own `void main()`.
|
|
13
|
+
|
|
14
|
+
The checks keep a shader cheap and its cost known before it compiles. A loop is a `for` loop of a
|
|
15
|
+
fixed count, with integer literals or `const int` names of the file for its bounds and step, of
|
|
16
|
+
at most 256 iterations, and loops nested inside each other, through the helper functions they
|
|
17
|
+
call too, run their body at most 1024 times. A fragment fetches textures at most 16 times,
|
|
18
|
+
counted with the trip counts of the loops around each fetch and through the helper functions it
|
|
19
|
+
calls, and every hook of a chunks file counts as fragment. The code that a vertex or a fragment
|
|
20
|
+
runs holds at most 65536 words, names and numbers, each counted with the trip counts of the loops
|
|
21
|
+
around it, through the helper functions it calls and with the words of the macros it names, and
|
|
22
|
+
the whole file holds at most 262144 words once its macros expand. The only include is
|
|
23
|
+
`<cuju_noise>`. One rule of syntax catches the commonest slip, an operator with nothing after it,
|
|
24
|
+
and braces and parentheses must pair up.
|
|
25
|
+
Everything else of GLSL waits for the page, which compiles each shader before it draws and names
|
|
26
|
+
one that fails in a notice.
|
|
27
|
+
|
|
28
|
+
The server runs `check` on the shaders of a manifest, `cuju render pack check` runs it for an
|
|
29
|
+
author, and the page runs the same rules before it compiles. Each check reads the text with its
|
|
30
|
+
comments taken out, with plain regular expressions and no dependency, so it stays fast.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
from __future__ import annotations
|
|
34
|
+
|
|
35
|
+
import bisect
|
|
36
|
+
import re
|
|
37
|
+
from typing import Any
|
|
38
|
+
|
|
39
|
+
MODES = ('chunks', 'material')
|
|
40
|
+
MAXIMUM_BYTES = 256 * 1024
|
|
41
|
+
MAXIMUM_ITERATIONS = 256
|
|
42
|
+
# The most times the body of loops nested in each other runs, through helper calls too.
|
|
43
|
+
MAXIMUM_NESTED = 1024
|
|
44
|
+
MAXIMUM_FETCHES = 16
|
|
45
|
+
# The most words a vertex or a fragment runs, and the most words of the file with its macros.
|
|
46
|
+
MAXIMUM_WORK = 65536
|
|
47
|
+
MAXIMUM_EXPANDED = 262144
|
|
48
|
+
# The largest count the checks keep, far past every limit, so a count stays a small integer.
|
|
49
|
+
_CAP = 1 << 62
|
|
50
|
+
# The programs a team may compile at each quality, one for each distinct shader file and mode.
|
|
51
|
+
BUDGET = {'high': 16, 'medium': 16, 'low': 8}
|
|
52
|
+
INCLUDES = ('cuju_noise',)
|
|
53
|
+
# The hooks of a chunks file and the type each returns.
|
|
54
|
+
HOOKS = {
|
|
55
|
+
'cujuVertex': 'vec3',
|
|
56
|
+
'cujuColor': 'vec4',
|
|
57
|
+
'cujuEmissive': 'vec3',
|
|
58
|
+
'cujuRoughness': 'float',
|
|
59
|
+
'cujuMetalness': 'float',
|
|
60
|
+
}
|
|
61
|
+
# The built in functions of GLSL that fetch from a texture, those of GLSL ES 3.00 and the older
|
|
62
|
+
# names that WebGL still reads.
|
|
63
|
+
FETCHES = frozenset(
|
|
64
|
+
(
|
|
65
|
+
'texture',
|
|
66
|
+
'textureProj',
|
|
67
|
+
'textureLod',
|
|
68
|
+
'textureOffset',
|
|
69
|
+
'textureProjOffset',
|
|
70
|
+
'textureLodOffset',
|
|
71
|
+
'textureProjLod',
|
|
72
|
+
'textureProjLodOffset',
|
|
73
|
+
'textureGrad',
|
|
74
|
+
'textureGradOffset',
|
|
75
|
+
'textureProjGrad',
|
|
76
|
+
'textureProjGradOffset',
|
|
77
|
+
'texelFetch',
|
|
78
|
+
'texelFetchOffset',
|
|
79
|
+
'texture2D',
|
|
80
|
+
'texture2DProj',
|
|
81
|
+
'texture2DLod',
|
|
82
|
+
'texture2DProjLod',
|
|
83
|
+
'texture2DLodEXT',
|
|
84
|
+
'texture2DProjLodEXT',
|
|
85
|
+
'texture2DGradEXT',
|
|
86
|
+
'texture2DProjGradEXT',
|
|
87
|
+
'textureCube',
|
|
88
|
+
'textureCubeLod',
|
|
89
|
+
'textureCubeLodEXT',
|
|
90
|
+
'textureCubeGradEXT',
|
|
91
|
+
)
|
|
92
|
+
)
|
|
93
|
+
# Words of GLSL that a macro may neither name nor hide.
|
|
94
|
+
_KEYWORDS = frozenset(
|
|
95
|
+
(
|
|
96
|
+
'for',
|
|
97
|
+
'while',
|
|
98
|
+
'do',
|
|
99
|
+
'if',
|
|
100
|
+
'else',
|
|
101
|
+
'switch',
|
|
102
|
+
'case',
|
|
103
|
+
'default',
|
|
104
|
+
'break',
|
|
105
|
+
'continue',
|
|
106
|
+
'return',
|
|
107
|
+
'discard',
|
|
108
|
+
'uniform',
|
|
109
|
+
'const',
|
|
110
|
+
'int',
|
|
111
|
+
'float',
|
|
112
|
+
'void',
|
|
113
|
+
'in',
|
|
114
|
+
'out',
|
|
115
|
+
'inout',
|
|
116
|
+
'struct',
|
|
117
|
+
'layout',
|
|
118
|
+
'precision',
|
|
119
|
+
'highp',
|
|
120
|
+
'mediump',
|
|
121
|
+
'lowp',
|
|
122
|
+
'main',
|
|
123
|
+
)
|
|
124
|
+
)
|
|
125
|
+
_DIRECTIVES = frozenset(
|
|
126
|
+
('define', 'undef', 'if', 'ifdef', 'ifndef', 'elif', 'else', 'endif', 'error', 'line')
|
|
127
|
+
)
|
|
128
|
+
_VALUE = r'[-+]?\s*(?:0[xX][0-9a-fA-F]+|\d+)[uU]?|[A-Za-z_]\w*'
|
|
129
|
+
_INIT = re.compile(rf'(?:(?:lowp|mediump|highp)\s+)?int\s+([A-Za-z_]\w*)\s*=\s*({_VALUE})')
|
|
130
|
+
_CONDITION = re.compile(rf'([A-Za-z_]\w*)\s*(<=|>=|<|>)\s*({_VALUE})')
|
|
131
|
+
_STEP = re.compile(
|
|
132
|
+
rf'([A-Za-z_]\w*)\s*(\+\+|--)|(\+\+|--)\s*([A-Za-z_]\w*)|([A-Za-z_]\w*)\s*(\+=|-=)\s*({_VALUE})'
|
|
133
|
+
)
|
|
134
|
+
_CONSTANT = re.compile(r'\bconst\s+(?:(?:lowp|mediump|highp)\s+)?int\s+([^;]*);')
|
|
135
|
+
_LITERAL = re.compile(r'\s*([A-Za-z_]\w*)\s*=\s*([-+]?\s*(?:0[xX][0-9a-fA-F]+|\d+)[uU]?)\s*')
|
|
136
|
+
_CALL = re.compile(r'\b([A-Za-z_]\w*)\s*\(')
|
|
137
|
+
_HEAD = re.compile(
|
|
138
|
+
r'(?:(?:lowp|mediump|highp)\s+)?([A-Za-z_]\w*)\s+([A-Za-z_]\w*)\s*\(([^()]*)\)\s*$'
|
|
139
|
+
)
|
|
140
|
+
_RENDERER_NAME = re.compile(r'cuju\w*|u[A-Z]\w*')
|
|
141
|
+
_COMMENT = re.compile(r'//[^\n]*|/\*.*?(?:\*/|\Z)|\\\n', re.S)
|
|
142
|
+
_WORD = re.compile(r'[A-Za-z_]\w*')
|
|
143
|
+
# A word of the code that counts toward its work, a name or a number.
|
|
144
|
+
_TOKEN = re.compile(r'[A-Za-z_]\w*|\d+(?:\.\d*)?|\.\d+')
|
|
145
|
+
_BRACKETS = {'(': re.compile(r'[()]'), '{': re.compile(r'[{}]')}
|
|
146
|
+
_STATEMENT = re.compile(r'[(){};]')
|
|
147
|
+
# A name that an assignment, an increment or a decrement changes, the counter check of a loop.
|
|
148
|
+
_CHANGE = re.compile(
|
|
149
|
+
r'(?<![\w.])(?:([A-Za-z_]\w*)\s*(?:(?:[-+*/%&|^]|<<|>>)?=(?!=)|\+\+|--)'
|
|
150
|
+
r'|(?:\+\+|--)\s*([A-Za-z_]\w*))'
|
|
151
|
+
)
|
|
152
|
+
# An operator that a statement, an argument or a bracket ends right after, the commonest slip of a
|
|
153
|
+
# shader that then fails to compile, such as `return e + ;`.
|
|
154
|
+
_DANGLING = re.compile(r'([-+*/%=<>!&|^~]+)\s*[;),\]}]')
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _blank(match: re.Match[str]) -> str:
|
|
158
|
+
"""Returns a comment or a line continuation as spaces, its newlines kept in a comment."""
|
|
159
|
+
text = match.group(0)
|
|
160
|
+
if text == '\\\n':
|
|
161
|
+
return ' '
|
|
162
|
+
return re.sub(r'[^\n]', ' ', text)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _clean(text: str) -> str:
|
|
166
|
+
"""Returns the text with its comments and line continuations as spaces, of the same length.
|
|
167
|
+
|
|
168
|
+
Each character keeps its offset, so a problem names the line of the author's own file.
|
|
169
|
+
"""
|
|
170
|
+
return _COMMENT.sub(_blank, text)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def _integer(value: str, constants: dict[str, int]) -> int | None:
|
|
174
|
+
"""Returns the integer that a literal or a `const int` name gives, or `None` for another."""
|
|
175
|
+
value = value.replace(' ', '').rstrip('uU')
|
|
176
|
+
if value in constants:
|
|
177
|
+
return constants[value]
|
|
178
|
+
sign = -1 if value.startswith('-') else 1
|
|
179
|
+
digits = value.lstrip('+-')
|
|
180
|
+
if re.fullmatch(r'0[xX][0-9a-fA-F]+', digits):
|
|
181
|
+
return sign * int(digits, 16)
|
|
182
|
+
if digits.isdigit():
|
|
183
|
+
return sign * int(digits)
|
|
184
|
+
return None
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def _constants(code: str) -> dict[str, int]:
|
|
188
|
+
"""Returns the `const int` names of the code declared with an integer literal."""
|
|
189
|
+
found: dict[str, int] = {}
|
|
190
|
+
for match in _CONSTANT.finditer(code):
|
|
191
|
+
for part in match.group(1).split(','):
|
|
192
|
+
item = _LITERAL.fullmatch(part)
|
|
193
|
+
if item and item.group(1) not in found:
|
|
194
|
+
value = _integer(item.group(2), {})
|
|
195
|
+
if value is not None:
|
|
196
|
+
found[item.group(1)] = value
|
|
197
|
+
return found
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def _trips(start: int, op: str, bound: int, step: int) -> int | None:
|
|
201
|
+
"""Returns how many times a loop of the checked form runs, or `None` for one that never ends."""
|
|
202
|
+
if op in ('<', '<='):
|
|
203
|
+
last = bound if op == '<=' else bound - 1
|
|
204
|
+
if start > last:
|
|
205
|
+
return 0
|
|
206
|
+
return None if step <= 0 else (last - start) // step + 1
|
|
207
|
+
last = bound if op == '>=' else bound + 1
|
|
208
|
+
if start < last:
|
|
209
|
+
return 0
|
|
210
|
+
return None if step >= 0 else (start - last) // -step + 1
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def _match(code: str, start: int, opening: str, closing: str) -> int:
|
|
214
|
+
"""Returns the offset of the bracket that closes the one at `start`, or -1 when none does."""
|
|
215
|
+
depth = 0
|
|
216
|
+
for match in _BRACKETS[opening].finditer(code, start):
|
|
217
|
+
if match.group(0) == opening:
|
|
218
|
+
depth += 1
|
|
219
|
+
else:
|
|
220
|
+
depth -= 1
|
|
221
|
+
if depth == 0:
|
|
222
|
+
return match.start()
|
|
223
|
+
return -1
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _split(header: str) -> list[str]:
|
|
227
|
+
"""Splits the header of a `for` loop at its semicolons outside parentheses."""
|
|
228
|
+
parts, depth, last = [], 0, 0
|
|
229
|
+
for i, c in enumerate(header):
|
|
230
|
+
if c == '(':
|
|
231
|
+
depth += 1
|
|
232
|
+
elif c == ')':
|
|
233
|
+
depth -= 1
|
|
234
|
+
elif c == ';' and depth == 0:
|
|
235
|
+
parts.append(header[last:i])
|
|
236
|
+
last = i + 1
|
|
237
|
+
parts.append(header[last:])
|
|
238
|
+
return parts
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
class _Reader:
|
|
242
|
+
"""Reads the structure of one cleaned shader, its loops and functions, and notes problems."""
|
|
243
|
+
|
|
244
|
+
def __init__(self, text: str, code: str, problems: list[str]) -> None:
|
|
245
|
+
self.text = text
|
|
246
|
+
self.code = code
|
|
247
|
+
self.problems = problems
|
|
248
|
+
self.constants: dict[str, int] = {}
|
|
249
|
+
# Each loop as the span of its body and its trip count, and the offsets of those read.
|
|
250
|
+
self.loops: list[tuple[int, int, int]] = []
|
|
251
|
+
self.seen: set[int] = set()
|
|
252
|
+
self.starts: list[int] = []
|
|
253
|
+
|
|
254
|
+
def line(self, offset: int) -> int:
|
|
255
|
+
return self.text.count('\n', 0, offset) + 1
|
|
256
|
+
|
|
257
|
+
def note(self, offset: int, message: str) -> None:
|
|
258
|
+
problem = f'line {self.line(offset)} {message}'
|
|
259
|
+
if problem not in self.problems:
|
|
260
|
+
self.problems.append(problem)
|
|
261
|
+
|
|
262
|
+
def statement(self, start: int) -> int:
|
|
263
|
+
"""Returns the offset just past the statement that begins at `start`."""
|
|
264
|
+
code = self.code
|
|
265
|
+
i = start
|
|
266
|
+
while i < len(code) and code[i].isspace():
|
|
267
|
+
i += 1
|
|
268
|
+
if i < len(code) and code[i] == '{':
|
|
269
|
+
end = _match(code, i, '{', '}')
|
|
270
|
+
return len(code) if end < 0 else end + 1
|
|
271
|
+
word = _WORD.match(code, i)
|
|
272
|
+
if word and word.group(0) == 'for':
|
|
273
|
+
return self.loop(i)
|
|
274
|
+
if word and word.group(0) in ('if', 'else', 'switch'):
|
|
275
|
+
self.note(i, 'holds a loop whose body branches without braces, put the body in braces')
|
|
276
|
+
depth = 0
|
|
277
|
+
for match in _STATEMENT.finditer(code, i):
|
|
278
|
+
c = match.group(0)
|
|
279
|
+
if c in '({':
|
|
280
|
+
depth += 1
|
|
281
|
+
elif c in ')}':
|
|
282
|
+
depth -= 1
|
|
283
|
+
if depth < 0:
|
|
284
|
+
return match.start()
|
|
285
|
+
elif depth == 0:
|
|
286
|
+
return match.start() + 1
|
|
287
|
+
return len(code)
|
|
288
|
+
|
|
289
|
+
def loop(self, start: int) -> int:
|
|
290
|
+
"""Checks the `for` loop at `start`, notes its body and returns the offset past it."""
|
|
291
|
+
code = self.code
|
|
292
|
+
self.seen.add(start)
|
|
293
|
+
opening = code.find('(', start)
|
|
294
|
+
closing = _match(code, opening, '(', ')') if opening >= 0 else -1
|
|
295
|
+
if opening < 0 or code[start + 3 : opening].strip() or closing < 0:
|
|
296
|
+
self.note(start, 'holds a for loop without a header in parentheses')
|
|
297
|
+
return start + 3
|
|
298
|
+
parts = _split(code[opening + 1 : closing])
|
|
299
|
+
body_end = self.statement(closing + 1)
|
|
300
|
+
trips = self.header(start, parts)
|
|
301
|
+
if trips is None:
|
|
302
|
+
trips = MAXIMUM_ITERATIONS
|
|
303
|
+
else:
|
|
304
|
+
self.counter(start, parts, closing + 1, body_end)
|
|
305
|
+
self.loops.append((closing + 1, body_end, trips))
|
|
306
|
+
return body_end
|
|
307
|
+
|
|
308
|
+
def header(self, start: int, parts: list[str]) -> int | None:
|
|
309
|
+
"""Returns the trip count of a loop's header, or `None` after noting why it has none."""
|
|
310
|
+
form = 'holds a for loop outside the form for (int i = A; i < B; i++)'
|
|
311
|
+
if len(parts) != 3:
|
|
312
|
+
self.note(start, form)
|
|
313
|
+
return None
|
|
314
|
+
init = _INIT.fullmatch(parts[0].strip())
|
|
315
|
+
condition = _CONDITION.fullmatch(parts[1].strip())
|
|
316
|
+
step = _STEP.fullmatch(parts[2].strip())
|
|
317
|
+
if not (init and condition and step):
|
|
318
|
+
self.note(start, form)
|
|
319
|
+
return None
|
|
320
|
+
name = init.group(1)
|
|
321
|
+
if step.group(1):
|
|
322
|
+
counter, amount = step.group(1), 1 if step.group(2) == '++' else -1
|
|
323
|
+
elif step.group(3):
|
|
324
|
+
counter, amount = step.group(4), 1 if step.group(3) == '++' else -1
|
|
325
|
+
else:
|
|
326
|
+
counter, amount = step.group(5), 0
|
|
327
|
+
if condition.group(1) != name or counter != name:
|
|
328
|
+
self.note(start, f'holds a for loop whose condition or step leaves its counter {name}')
|
|
329
|
+
return None
|
|
330
|
+
values = {'start': init.group(2), 'bound': condition.group(3)}
|
|
331
|
+
if step.group(7):
|
|
332
|
+
values['step'] = step.group(7)
|
|
333
|
+
numbers = {}
|
|
334
|
+
for key, value in values.items():
|
|
335
|
+
number = _integer(value, self.constants)
|
|
336
|
+
if number is None:
|
|
337
|
+
self.note(
|
|
338
|
+
start,
|
|
339
|
+
f'bounds a loop by {value.strip()}, which is no integer literal or const int '
|
|
340
|
+
'of the file',
|
|
341
|
+
)
|
|
342
|
+
return None
|
|
343
|
+
numbers[key] = number
|
|
344
|
+
if step.group(7):
|
|
345
|
+
amount = numbers['step'] if step.group(6) == '+=' else -numbers['step']
|
|
346
|
+
trips = _trips(numbers['start'], condition.group(2), numbers['bound'], amount)
|
|
347
|
+
if trips is None:
|
|
348
|
+
self.note(start, 'holds a loop that never ends, its step moves away from its bound')
|
|
349
|
+
return None
|
|
350
|
+
if trips > MAXIMUM_ITERATIONS:
|
|
351
|
+
self.note(start, f'runs a loop {trips} times, at most {MAXIMUM_ITERATIONS}')
|
|
352
|
+
return trips
|
|
353
|
+
|
|
354
|
+
def counter(self, start: int, parts: list[str], body: int, end: int) -> None:
|
|
355
|
+
"""Notes a loop whose body changes its counter, which would void its trip count."""
|
|
356
|
+
name = _INIT.fullmatch(parts[0].strip()).group(1)
|
|
357
|
+
text = self.code[body:end]
|
|
358
|
+
for match in _CHANGE.finditer(text):
|
|
359
|
+
if (match.group(1) or match.group(2)) != name:
|
|
360
|
+
continue
|
|
361
|
+
if re.search(r'\bint\s*$', text[: match.start()]):
|
|
362
|
+
continue
|
|
363
|
+
self.note(body + match.start(), f'changes the counter {name} inside its loop')
|
|
364
|
+
|
|
365
|
+
def loops_of(self) -> None:
|
|
366
|
+
"""Checks every `for` loop of the code."""
|
|
367
|
+
for match in re.finditer(r'\bfor\b', self.code):
|
|
368
|
+
if match.start() not in self.seen:
|
|
369
|
+
self.loop(match.start())
|
|
370
|
+
self.loops.sort()
|
|
371
|
+
self.starts = [start for start, _, _ in self.loops]
|
|
372
|
+
|
|
373
|
+
def weights(self, offsets: list[int], low: int, high: int) -> tuple[list[int], int]:
|
|
374
|
+
"""Returns how many times the code at each offset runs, and the most a loop body runs.
|
|
375
|
+
|
|
376
|
+
Each count is the product of the trip counts of the loops around the offset, held at
|
|
377
|
+
`_CAP`. Only the loops of the function from `low` to `high` count, and the offsets come
|
|
378
|
+
in order, so one pass over them and the loops does.
|
|
379
|
+
"""
|
|
380
|
+
stack: list[tuple[int, int]] = []
|
|
381
|
+
out = []
|
|
382
|
+
deepest = 1
|
|
383
|
+
k = bisect.bisect_left(self.starts, low)
|
|
384
|
+
|
|
385
|
+
def enter(limit: int) -> None:
|
|
386
|
+
nonlocal k, deepest
|
|
387
|
+
while k < len(self.loops) and self.loops[k][0] <= limit and self.loops[k][0] < high:
|
|
388
|
+
start, end, trips = self.loops[k]
|
|
389
|
+
k += 1
|
|
390
|
+
while stack and stack[-1][0] <= start:
|
|
391
|
+
stack.pop()
|
|
392
|
+
product = min(_CAP, (stack[-1][1] if stack else 1) * trips)
|
|
393
|
+
stack.append((end, product))
|
|
394
|
+
deepest = max(deepest, product)
|
|
395
|
+
|
|
396
|
+
for offset in offsets:
|
|
397
|
+
enter(offset)
|
|
398
|
+
while stack and stack[-1][0] <= offset:
|
|
399
|
+
stack.pop()
|
|
400
|
+
out.append(stack[-1][1] if stack else 1)
|
|
401
|
+
enter(high)
|
|
402
|
+
return out, deepest
|
|
403
|
+
|
|
404
|
+
def functions(self) -> list[dict[str, Any]]:
|
|
405
|
+
"""Returns the functions the code defines, each with its name, type, offset and body."""
|
|
406
|
+
code = self.code
|
|
407
|
+
found = []
|
|
408
|
+
i = code.find('{')
|
|
409
|
+
while i >= 0:
|
|
410
|
+
low = max(0, i - 400)
|
|
411
|
+
head = _HEAD.search(code[low:i])
|
|
412
|
+
end = _match(code, i, '{', '}')
|
|
413
|
+
if head and head.group(1) not in ('struct', 'return', 'else'):
|
|
414
|
+
found.append(
|
|
415
|
+
{
|
|
416
|
+
'type': head.group(1),
|
|
417
|
+
'name': head.group(2),
|
|
418
|
+
'parameters': head.group(3).strip(),
|
|
419
|
+
'at': low + head.start(),
|
|
420
|
+
'body': (i, len(code) if end < 0 else end),
|
|
421
|
+
}
|
|
422
|
+
)
|
|
423
|
+
if end < 0:
|
|
424
|
+
break
|
|
425
|
+
i = code.find('{', end + 1)
|
|
426
|
+
return found
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
def _costs(
|
|
430
|
+
reader: _Reader,
|
|
431
|
+
functions: list[dict[str, Any]],
|
|
432
|
+
problems: list[str],
|
|
433
|
+
sizes: dict[str, int] | None = None,
|
|
434
|
+
) -> dict[str, tuple[int, int, int]]:
|
|
435
|
+
"""Returns the cost of each function, counted through loops and helper calls.
|
|
436
|
+
|
|
437
|
+
Each cost is the texture fetches, the words of code the function runs, a macro counting as
|
|
438
|
+
the words it expands to by `sizes`, and the most times a body of its nested loops runs.
|
|
439
|
+
"""
|
|
440
|
+
code = reader.code
|
|
441
|
+
sizes = sizes or {}
|
|
442
|
+
by_name: dict[str, list[dict[str, Any]]] = {}
|
|
443
|
+
for function in functions:
|
|
444
|
+
by_name.setdefault(function['name'], []).append(function)
|
|
445
|
+
costs: dict[str, tuple[int, int, int]] = {}
|
|
446
|
+
busy: set[str] = set()
|
|
447
|
+
|
|
448
|
+
def cost_of(name: str) -> tuple[int, int, int]:
|
|
449
|
+
if name in costs:
|
|
450
|
+
return costs[name]
|
|
451
|
+
if name in busy:
|
|
452
|
+
message = f'calls {name} back from itself, which GLSL refuses'
|
|
453
|
+
if message not in problems:
|
|
454
|
+
problems.append(message)
|
|
455
|
+
return (0, 0, 1)
|
|
456
|
+
busy.add(name)
|
|
457
|
+
# Overloads share a name, so a call counts the costliest of them.
|
|
458
|
+
fetches, work, nested = 0, 0, 1
|
|
459
|
+
for function in by_name[name]:
|
|
460
|
+
start, end = function['body']
|
|
461
|
+
tokens = list(_TOKEN.finditer(code, start, end))
|
|
462
|
+
counts, deepest = reader.weights([m.start() for m in tokens], start, end)
|
|
463
|
+
at = dict(zip((m.start() for m in tokens), counts, strict=True))
|
|
464
|
+
own = [0, 0, deepest]
|
|
465
|
+
for match, weight in zip(tokens, counts, strict=True):
|
|
466
|
+
own[1] = min(_CAP, own[1] + weight * sizes.get(match.group(0), 1))
|
|
467
|
+
for match in _CALL.finditer(code, start, end):
|
|
468
|
+
callee = match.group(1)
|
|
469
|
+
weight = at.get(match.start(), 1)
|
|
470
|
+
if callee in FETCHES:
|
|
471
|
+
own[0] = min(_CAP, own[0] + weight)
|
|
472
|
+
elif callee in by_name:
|
|
473
|
+
inner = cost_of(callee)
|
|
474
|
+
own[0] = min(_CAP, own[0] + weight * inner[0])
|
|
475
|
+
own[1] = min(_CAP, own[1] + weight * inner[1])
|
|
476
|
+
own[2] = max(own[2], min(_CAP, weight * inner[2]))
|
|
477
|
+
fetches, work, nested = max(fetches, own[0]), max(work, own[1]), max(nested, own[2])
|
|
478
|
+
busy.discard(name)
|
|
479
|
+
costs[name] = (fetches, work, nested)
|
|
480
|
+
return costs[name]
|
|
481
|
+
|
|
482
|
+
for name in by_name:
|
|
483
|
+
cost_of(name)
|
|
484
|
+
return costs
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
def _limits(where: str, cost: tuple[int, int, int], problems: list[str]) -> None:
|
|
488
|
+
"""Notes where the cost of a vertex or a fragment passes the limits of loops and work."""
|
|
489
|
+
_, work, nested = cost
|
|
490
|
+
if nested > MAXIMUM_NESTED:
|
|
491
|
+
problems.append(
|
|
492
|
+
f'holds nested loops in {where} that run their body {nested} times, at most '
|
|
493
|
+
f'{MAXIMUM_NESTED}'
|
|
494
|
+
)
|
|
495
|
+
if work > MAXIMUM_WORK:
|
|
496
|
+
problems.append(f'runs {work} words of code in {where}, at most {MAXIMUM_WORK}')
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
def _sizes(defines: list[tuple[int, str]]) -> dict[str, int]:
|
|
500
|
+
"""Returns the words each macro of the file expands to, through the macros it names."""
|
|
501
|
+
bodies: dict[str, list[str]] = {}
|
|
502
|
+
for _, rest in defines:
|
|
503
|
+
match = re.match(r'([A-Za-z_]\w*)(?:\(([^)]*)\))?(.*)', rest)
|
|
504
|
+
if match:
|
|
505
|
+
parameters = set(_WORD.findall(match.group(2) or ''))
|
|
506
|
+
words = [w for w in _TOKEN.findall(match.group(3)) if w not in parameters]
|
|
507
|
+
bodies[match.group(1)] = words
|
|
508
|
+
sizes: dict[str, int] = {}
|
|
509
|
+
busy: set[str] = set()
|
|
510
|
+
|
|
511
|
+
def size(name: str) -> int:
|
|
512
|
+
if name in sizes:
|
|
513
|
+
return sizes[name]
|
|
514
|
+
if name in busy:
|
|
515
|
+
# The preprocessor never expands a macro inside its own expansion.
|
|
516
|
+
return 1
|
|
517
|
+
busy.add(name)
|
|
518
|
+
total = sum(size(word) if word in bodies else 1 for word in bodies[name])
|
|
519
|
+
busy.discard(name)
|
|
520
|
+
sizes[name] = max(1, total)
|
|
521
|
+
return sizes[name]
|
|
522
|
+
|
|
523
|
+
for name in bodies:
|
|
524
|
+
size(name)
|
|
525
|
+
return sizes
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
def _directives(
|
|
529
|
+
reader: _Reader, mode: str, sections: list[tuple[str, int]], defines: list[tuple[int, str]]
|
|
530
|
+
) -> str:
|
|
531
|
+
"""Checks the directive lines of the code and returns the code with them as spaces."""
|
|
532
|
+
code = reader.code
|
|
533
|
+
out = list(code)
|
|
534
|
+
offset = 0
|
|
535
|
+
for line in code.split('\n'):
|
|
536
|
+
stripped = line.lstrip()
|
|
537
|
+
if stripped.startswith('#'):
|
|
538
|
+
at = offset + len(line) - len(stripped)
|
|
539
|
+
match = re.match(r'#\s*([A-Za-z_]\w*)?\s*(.*)', stripped)
|
|
540
|
+
word, rest = (match.group(1) or ''), match.group(2).strip()
|
|
541
|
+
if word == 'version':
|
|
542
|
+
reader.note(at, 'sets the version, which the renderer writes')
|
|
543
|
+
elif word == 'extension':
|
|
544
|
+
reader.note(at, 'enables an extension, which a package leaves to the renderer')
|
|
545
|
+
elif word == 'include':
|
|
546
|
+
name = re.fullmatch(r'<\s*([\w.]+)\s*>', rest)
|
|
547
|
+
if not name or name.group(1) not in INCLUDES:
|
|
548
|
+
reader.note(at, f'includes {rest}, of which only <cuju_noise> is available')
|
|
549
|
+
elif word == 'pragma' and re.match(r'cuju\b', rest):
|
|
550
|
+
section = re.fullmatch(r'cuju\s+(vertex|fragment)', rest)
|
|
551
|
+
if mode != 'material':
|
|
552
|
+
reader.note(at, 'starts a section, which only a file of mode material has')
|
|
553
|
+
elif not section:
|
|
554
|
+
reader.note(at, f'holds the unknown pragma {rest}')
|
|
555
|
+
else:
|
|
556
|
+
sections.append((section.group(1), offset + len(line)))
|
|
557
|
+
elif word in ('define', 'undef'):
|
|
558
|
+
defines.append((at, rest))
|
|
559
|
+
elif word and word not in _DIRECTIVES and word != 'pragma':
|
|
560
|
+
reader.note(at, f'holds the unknown directive #{word}')
|
|
561
|
+
out[offset : offset + len(line)] = ' ' * len(line)
|
|
562
|
+
offset += len(line) + 1
|
|
563
|
+
return ''.join(out)
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
def _macros(reader: _Reader, defines: list[tuple[int, str]], helpers: set[str]) -> None:
|
|
567
|
+
"""Checks the names and bodies of the macros, which may hide neither loops nor fetches."""
|
|
568
|
+
for at, rest in defines:
|
|
569
|
+
match = re.match(r'([A-Za-z_]\w*)(.*)', rest)
|
|
570
|
+
if not match:
|
|
571
|
+
reader.note(at, 'defines a macro without a name')
|
|
572
|
+
continue
|
|
573
|
+
name, body = match.group(1), match.group(2)
|
|
574
|
+
if _RENDERER_NAME.fullmatch(name) or name in HOOKS:
|
|
575
|
+
reader.note(at, f'defines {name}, a name the renderer owns')
|
|
576
|
+
elif name in _KEYWORDS or name in FETCHES:
|
|
577
|
+
reader.note(at, f'defines {name}, a word of GLSL')
|
|
578
|
+
if '##' in body:
|
|
579
|
+
reader.note(at, 'pastes tokens in a macro, which a package may not')
|
|
580
|
+
words = set(re.findall(r'[A-Za-z_]\w*', body))
|
|
581
|
+
hidden = sorted(words & ({'for', 'while', 'do', 'uniform'} | FETCHES | helpers))
|
|
582
|
+
if hidden:
|
|
583
|
+
reader.note(at, f'hides {hidden[0]} in a macro, write it out in the code')
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
def check(text: str, mode: str = 'chunks') -> list[str]:
|
|
587
|
+
"""Checks the text of a shader of a package and returns its problems.
|
|
588
|
+
|
|
589
|
+
Args:
|
|
590
|
+
text: The text of the `.glsl` file.
|
|
591
|
+
mode: `chunks`, hooks into the renderer's standard material, or `material`, a whole
|
|
592
|
+
shader material of a vertex and a fragment section.
|
|
593
|
+
|
|
594
|
+
Returns:
|
|
595
|
+
The problems as short sentences, each naming its line where it has one, empty when the
|
|
596
|
+
shader passes.
|
|
597
|
+
"""
|
|
598
|
+
if mode not in MODES:
|
|
599
|
+
return [f'expected the mode chunks or material, found {mode!r}']
|
|
600
|
+
try:
|
|
601
|
+
return _check(text, mode)
|
|
602
|
+
except RecursionError:
|
|
603
|
+
return ['nests its loops or its helper calls too deeply to count']
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
def _check(text: str, mode: str) -> list[str]:
|
|
607
|
+
"""Checks a shader of a known mode, as `check` describes."""
|
|
608
|
+
problems: list[str] = []
|
|
609
|
+
if len(text.encode('utf-8', 'surrogatepass')) > MAXIMUM_BYTES:
|
|
610
|
+
problems.append(f'holds more than {MAXIMUM_BYTES // 1024} KB')
|
|
611
|
+
reader = _Reader(text, _clean(text), problems)
|
|
612
|
+
sections: list[tuple[str, int]] = []
|
|
613
|
+
defines: list[tuple[int, str]] = []
|
|
614
|
+
reader.code = _directives(reader, mode, sections, defines)
|
|
615
|
+
code = reader.code
|
|
616
|
+
reader.constants = _constants(code)
|
|
617
|
+
closes = re.search(r'\bdo\b', code) is not None
|
|
618
|
+
for word, message in (
|
|
619
|
+
('uniform', 'declares a uniform, the renderer declares every uniform from the manifest'),
|
|
620
|
+
('while', 'holds a while loop, use a for loop of a fixed count'),
|
|
621
|
+
('do', 'holds a do loop, use a for loop of a fixed count'),
|
|
622
|
+
):
|
|
623
|
+
for match in re.finditer(rf'\b{word}\b', code):
|
|
624
|
+
# The while that closes a do loop belongs to the do loop's own problem.
|
|
625
|
+
if word == 'while' and closes and code[: match.start()].rstrip().endswith('}'):
|
|
626
|
+
continue
|
|
627
|
+
reader.note(match.start(), message)
|
|
628
|
+
if code.count('{') != code.count('}') or code.count('(') != code.count(')'):
|
|
629
|
+
problems.append('holds braces or parentheses that do not pair up')
|
|
630
|
+
for match in _DANGLING.finditer(code):
|
|
631
|
+
if match.group(1) not in ('++', '--'):
|
|
632
|
+
reader.note(match.start(), f'holds the operator {match.group(1)} with nothing after it')
|
|
633
|
+
reader.loops_of()
|
|
634
|
+
functions = reader.functions()
|
|
635
|
+
_macros(reader, defines, {f['name'] for f in functions})
|
|
636
|
+
sizes = _sizes(defines)
|
|
637
|
+
expanded = sum(sizes.get(word, 1) for word in _TOKEN.findall(code))
|
|
638
|
+
if expanded > MAXIMUM_EXPANDED:
|
|
639
|
+
problems.append(
|
|
640
|
+
f'holds {expanded} words once its macros expand, at most {MAXIMUM_EXPANDED}'
|
|
641
|
+
)
|
|
642
|
+
if mode == 'chunks':
|
|
643
|
+
costs = _costs(reader, functions, problems, sizes)
|
|
644
|
+
names = {f['name']: f for f in functions}
|
|
645
|
+
hooks = [name for name in HOOKS if name in names]
|
|
646
|
+
if not hooks:
|
|
647
|
+
problems.append(
|
|
648
|
+
'defines none of the hooks cujuVertex, cujuColor, cujuEmissive, cujuRoughness '
|
|
649
|
+
'and cujuMetalness'
|
|
650
|
+
)
|
|
651
|
+
for name in hooks:
|
|
652
|
+
if names[name]['type'] != HOOKS[name]:
|
|
653
|
+
reader.note(
|
|
654
|
+
names[name]['at'],
|
|
655
|
+
f'defines {name} returning {names[name]["type"]}, the hook returns '
|
|
656
|
+
f'{HOOKS[name]}',
|
|
657
|
+
)
|
|
658
|
+
if 'main' in names:
|
|
659
|
+
reader.note(names['main']['at'], 'defines main, which the standard material holds')
|
|
660
|
+
none = (0, 0, 1)
|
|
661
|
+
fetches = sum(costs.get(name, none)[0] for name in hooks)
|
|
662
|
+
_limits(
|
|
663
|
+
'the hooks',
|
|
664
|
+
(
|
|
665
|
+
fetches,
|
|
666
|
+
sum(costs.get(name, none)[1] for name in hooks),
|
|
667
|
+
max([costs.get(name, none)[2] for name in hooks] or [1]),
|
|
668
|
+
),
|
|
669
|
+
problems,
|
|
670
|
+
)
|
|
671
|
+
where = 'the hooks fetch'
|
|
672
|
+
else:
|
|
673
|
+
fetches = _material(reader, functions, sections, problems, sizes)
|
|
674
|
+
where = 'the fragment section fetches'
|
|
675
|
+
if fetches > MAXIMUM_FETCHES:
|
|
676
|
+
problems.append(f'{where} textures {fetches} times, at most {MAXIMUM_FETCHES}')
|
|
677
|
+
return problems
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
def _material(
|
|
681
|
+
reader: _Reader,
|
|
682
|
+
functions: list[dict[str, Any]],
|
|
683
|
+
sections: list[tuple[str, int]],
|
|
684
|
+
problems: list[str],
|
|
685
|
+
sizes: dict[str, int] | None = None,
|
|
686
|
+
) -> int:
|
|
687
|
+
"""Checks the two sections of a file of mode material and returns the fragment's fetches."""
|
|
688
|
+
kinds = [kind for kind, _ in sections]
|
|
689
|
+
for kind in ('vertex', 'fragment'):
|
|
690
|
+
if kinds.count(kind) != 1:
|
|
691
|
+
problems.append(f'expected one line #pragma cuju {kind}, found {kinds.count(kind)}')
|
|
692
|
+
if kinds.count('vertex') != 1 or kinds.count('fragment') != 1:
|
|
693
|
+
return 0
|
|
694
|
+
vertex = dict(sections)['vertex']
|
|
695
|
+
fragment = dict(sections)['fragment']
|
|
696
|
+
if vertex > fragment:
|
|
697
|
+
problems.append('expected #pragma cuju vertex before #pragma cuju fragment')
|
|
698
|
+
return 0
|
|
699
|
+
shared = [f for f in functions if f['at'] < vertex]
|
|
700
|
+
fetches = 0
|
|
701
|
+
for kind, low, high in (('vertex', vertex, fragment), ('fragment', fragment, len(reader.code))):
|
|
702
|
+
own = [f for f in functions if low <= f['at'] < high]
|
|
703
|
+
main = [f for f in own if f['name'] == 'main']
|
|
704
|
+
if not main or main[0]['type'] != 'void' or main[0]['parameters'] not in ('', 'void'):
|
|
705
|
+
problems.append(f'the {kind} section defines no void main()')
|
|
706
|
+
continue
|
|
707
|
+
names = {f['name'] for f in own}
|
|
708
|
+
visible = [f for f in shared if f['name'] not in names] + own
|
|
709
|
+
costs = _costs(reader, visible, problems, sizes)
|
|
710
|
+
_limits(f'the {kind} section', costs.get('main', (0, 0, 1)), problems)
|
|
711
|
+
if kind == 'fragment':
|
|
712
|
+
fetches = costs.get('main', (0, 0, 1))[0]
|
|
713
|
+
return fetches
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
def shaders(manifest: Any) -> list[tuple[str, str]]:
|
|
717
|
+
"""Returns the distinct shader files and modes that the materials, effects and post name.
|
|
718
|
+
|
|
719
|
+
A material's shader is of mode chunks unless it names material, and the shaders of effects
|
|
720
|
+
and post passes, which draw the package's own objects, are of mode material unless they name
|
|
721
|
+
chunks.
|
|
722
|
+
"""
|
|
723
|
+
found: set[tuple[str, str]] = set()
|
|
724
|
+
if not isinstance(manifest, dict):
|
|
725
|
+
return []
|
|
726
|
+
|
|
727
|
+
def add(entry: Any, default: str) -> None:
|
|
728
|
+
if isinstance(entry, dict) and isinstance(entry.get('shader'), str):
|
|
729
|
+
mode = entry.get('mode', default)
|
|
730
|
+
found.add((entry['shader'], mode if mode in MODES else default))
|
|
731
|
+
if isinstance(entry, dict) and isinstance(entry.get('rules'), list):
|
|
732
|
+
for rule in entry['rules']:
|
|
733
|
+
add(rule, default)
|
|
734
|
+
|
|
735
|
+
for key, default in (('materials', 'chunks'), ('effects', 'material'), ('post', 'material')):
|
|
736
|
+
section = manifest.get(key)
|
|
737
|
+
if isinstance(section, dict):
|
|
738
|
+
section = list(section.values())
|
|
739
|
+
for entry in section if isinstance(section, list) else []:
|
|
740
|
+
add(entry, default)
|
|
741
|
+
return sorted(found)
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
def programs(manifest: Any) -> int:
|
|
745
|
+
"""Returns the shader programs a manifest costs, one for each distinct shader file and mode."""
|
|
746
|
+
return len(shaders(manifest))
|