Commit Graph

131 Commits

Author SHA1 Message Date
Jozufozu
ef05f7d3fd Errors galore
- Make everything in the compiler chain's results not null
- Throw errors immediately when encountered
- Log error messages when falling back
- Do not eagerly grab utility programs in IndirectDrawManager so we can
  actually catch errors and fall back
- Remove CompilerStats
2024-09-28 16:00:23 -07:00
Jozufozu
11ce4ac185 Dynamic ubering
- Remove fog shader registry
- Remove Registry and RegistryImpl
- Make shader indices mutable
- Track fog uber component in a static field in PipelineCompiler
- When a new fog source is added, delete the pipeline compilation
  harness and recreate the fog uber component
- Inline SourceLoader
2024-09-28 15:30:10 -07:00
Jozufozu
bce657804a Source of all pain
- Strip out almost all source registries
- Fog will be dealt with in a follow-up commit
- Remove most static #init methods
- Remove old ubershader indices from shaders
2024-09-28 14:48:22 -07:00
Jozufozu
48fdcdb751 DeDelleetete
- Process instancer deletions in parallel
- Give DrawManagers a frame plan
2024-09-28 14:26:15 -07:00
Jozufozu
7bd59f7b14 Not pointing
- Fix occasional npe in PlayerUniforms
- Mark accessor method as Nullable
2024-09-23 11:16:45 -07:00
Jozufozu
36b0ad4cf9 To bug or not to bug
- Disable the debug stuff in the frag shader with compile flags
- Also disable discard and conservative depth with CutoutShaders.OFF
2024-09-22 15:51:37 -07:00
Jozufozu
897c350f41 Uberstate ready
- Fix material state sorting/equality functions
2024-09-22 13:13:38 -07:00
Jozufozu
ff73e78e21 Visions of visibility
- Add visible/skipDraw getter/setter to InstanceTree
- Minecart finally gets to resolve its TODO!
2024-09-22 13:04:51 -07:00
Jozufozu
ee0f799f60 More statefuler
- Hidden state now tracks the Instance object to keep the handle small
- Make the recreate supplier an explicit record to allow comparisons
- Add setVisible method to Instance
2024-09-22 12:56:49 -07:00
Jozufozu
c5d9abab5f Tasteful stateful handles
- Use state machine interface in InstanceHandleImpl
- 3 states: deleted, visible, hidden
- Visible is directly implemented by AbstractInstancer
- Hidden stores the instancer supplier to recreate an instancer
2024-09-22 12:28:35 -07:00
Jozufozu
6a6d98c0a7 Fewber
- Do not uberize material or cutout shaders
- Add debug log for shader compilations/program links
2024-09-21 15:10:27 -07:00
Jozufozu
27e5b609af Reject eagerness return to lazy
- Eagerly load ALL shaders in ShaderSources, resolving imports there
- Compile and cache programs on-demand
- Move gl state try blocks to EngineImpl
- EngineImpl catches shader exceptions and triggers a fallback
2024-09-21 13:41:55 -07:00
Jozufozu
cb58f6075e Crumbling grumbling
- Fix crumbling on indirect
- Directly use the baseInstance as instance index without indirection
- #define base instance and draw id variables to simplify usage
- Fix null pointer looking up culling group
- Add method to map an instancer's local instance index to a global
  index in the page file
2024-09-21 12:00:09 -07:00
Jozufozu
b7b7cca992 Happy as a clamp
- Fix instances vanishing close to the edge of your screen
2024-09-20 20:07:38 -07:00
Jozufozu
40cfc08025 Mul-ing things over
- Add missing multiply functions to TransformedInstance
2024-09-20 19:28:27 -07:00
Jozufozu
90e088aedc Creation is change
- Indirect instancers mark pages as changed when instances are added
2024-09-20 19:14:50 -07:00
PepperCode1
5b6463b8f1 Regularly scheduled maintenance
- Remove ModelHolder and ModelCache
- Remove lib/util.FlwUtil
- Remove lib/util.Pair and replace usages with com.mojang.datafixers.util.Pair
- Remove lib/util.Unit and replace usages with net.minecraft.util.Unit
- Make ResourceReloadHolder and ResourceReloadCache final and move to util
- Clean up code in backend/glsl
- Move LightSmoothnessArgument to impl
2024-09-19 20:24:58 -07:00
PepperCode1
62a0954381 Home alone
- Remove LoweringVisitor
- Move functionality of four main static methods in LoweringVisitor to new ModelTrees class
  - Return ModelTree directly
  - Accept Material instead of TextureAtlasSprite for efficiency, so visuals don't need to look up the sprite to get the ModelTree
- Use ResourceReloadCache for MeshTree.CACHE
2024-09-19 11:40:41 -07:00
Jozufozu
5a75fe972f First try
- Implement instance hiding by deleting/stealing
- Work around instancer persistence by storing a recreation supplier in
  the instance handle
- Rework instancer ctors to just take an InstancerKey
- Parameterize InstanceHandle by I extends Instance so the steal method
  and the supplier can be safely assigned
2024-09-18 23:43:23 -07:00
Jozufozu
e1b594ac47 Ctrl + Alt + N
- IndirectInstancer#uploadInstances: 46% of render thread to 26%
- Inline #enqueueCopy to avoid allocating LongConsumers
- Do not even bother to track individual changed indices, instead rely
  on just the changedPage set
2024-09-15 21:29:00 -07:00
Jozufozu
c658b2bfe3 Pop! Goes the storage
- Trigger an upload when an allocation is deleted
2024-09-15 16:50:02 -07:00
Jozufozu
9f938e0673 A slap on the wrist
- Add restrict qualifier to images in downsample shaders
- Early out when there are no changed pages in
  IndirectInstancer#uploadInstances
2024-09-15 16:37:12 -07:00
Jozufozu
d342ae740c Get shulked
- Convert ShulkerBoxVisual to use InstanceTree
- Add "pruning" helper visitors
- Remove ModelPartConverter
- Remove TextureMapper and related code from VertexWriter
2024-09-15 15:29:09 -07:00
Jozufozu
31b3507d62 One big happy family
- Add ModelTree
- Add LoweringVisitor to traverse a MeshTree and emit ModelTree nodes
  and Models
- Provide some default visitor creation methods
- Abstract ModelCache -> ResourceReloadCache
- Abstract ModelHolder -> ResourceReloadHolder
- Add ModelTreeCache to hide lookup cost if it gets extreme
2024-09-15 14:49:33 -07:00
PepperCode1
904933e22e Treeify bells and minecarts
- Use InstanceTrees in BellVisual and MinecartVisual
- Use JOML Matrix4fStack instead of PoseStack
- Directly transform Matrix4f instead of using PoseStack to compute initial pose
2024-09-15 13:27:08 -07:00
Jozufozu
ed727e7a1b Things are changing
- Track if the transforms for an InstanceTree have changed
- Pass a boolean down the tree and || it with our changed flag to force
  updates
- Expose the force flag to visuals so they can hint to us if their root
  transforms never change
- Add 2 wrapper methods to make the distinction more clear
2024-09-15 00:28:10 -07:00
Jozufozu
5299571540 A little encapsulation goes a long way
- Encapsulate instancerProvider and renderOrigin in AbstractVisual
- Saves 8 bytes per visual
2024-09-14 22:46:06 -07:00
PepperCode1
b24e87262b Stackless
- Store a pose matrix in each InstanceTree, equivalent to its instance's pose matrix if the instance exists
- Directly transform the current InstanceTree's pose matrix instead of transforming a PoseStack and copying its matrix to the instance, eliminating the need to push and pop stack entries
- Remove InstanceTree.rotation
- Add more InstanceTree methods to allow full inspection of children
2024-09-14 22:37:48 -07:00
Jozufozu
41e0aa6bba Strike a pose
- Rename TransformedInstance -> PosedInstance
- Add TransformedInstance, which does not have a normal matrix
- Use mat3(transpose(inverse(i.pose))) in the vertex shader, but for
  most cases that will be overkill
2024-09-14 21:46:49 -07:00
Jozufozu
6f2b8fd3fb Shiver me timbers
- Use arrrays in the trees
- MeshTree tracks parallel arrays of children and keys
- InstanceTree tracks which mesh tree it came from for lookup purposes
- Remove walker object
- Make RecyclingPoseStack use add/removeLast instead of push/pop
2024-09-14 19:38:55 -07:00
Jozufozu
5ffddeb221 Walk this way
- Update instances using a walker object created at the top level
2024-09-14 17:46:54 -07:00
Jozufozu
ed35c5a429 Reduce and reuse
- Create subclass to recycle PoseStack.Pose objects
- Add mixin/liblink to access a PoseStack's inner deque
2024-09-14 16:50:02 -07:00
PepperCode1
295ebc7573 Treefactors
- Add MeshTree and InstanceTree
- Deprecate ModelPartConverter for removal
- Refactor ChestVisual to use InstanceTree
- Combine double chest light in ChestVisual
2024-09-14 15:00:27 -07:00
Jozufozu
ddb0450105 Rapid descent
- Implement single (but actually 2) pass downsampling
2024-09-14 14:12:14 -07:00
Jozufozu
a527af513f Harvesting
- Cherry-pick misc cleanups from last-frame-visibility
- Smarter multibind logic
- Make offsets in IndirectBuffers dependent on BufferBindings
- Organize buffer bindings based on where they're used to allow each
  pass to bind exactly which buffers it needs
- Use DSA for the depth pyramid
- Pass the map of util programs to IndirectPrograms rather than
  unpacking them individually
- Actually delete all the indirect utils
2024-09-14 14:04:50 -07:00
Jozufozu
f009cb846c Near stability
- Fix near plane rejection logic
- Fix lod clamp
2024-09-14 12:55:05 -07:00
Jozufozu
6c1fbf610d The depths of the rabbit hole
- Fix mip levels being half the size they should be
- Use the next lowest po2 from the main render target size for mip 0
- Map from dst texel to src texel rather than naively multiply by 2
- Clamp the estimated mip level in the cull shader
- Use texel fetches in the cull shader (not sure if necessary?)
2024-09-14 12:55:04 -07:00
Jozufozu
01a7936a05 Joining the occult
- Implement hi-z occlusion culling
- Generate depth pyramid just before issuing cull dispatches
- Currently use raw texel fetches but this may be causing loss
- Add _flw_cullData to frame uniforms
2024-09-14 12:55:03 -07:00
Jozufozu
81cb2340e7 The hardest problem
- Rename most InstancePager terminology
- Rename MODEL_INDEX buffer stuffs
2024-09-14 12:55:03 -07:00
Jozufozu
b5680a0fd6 On-call paging
- Only update the page table when an allocation is resized
- Only upload the page table after it's uploaded
- Combine various setters for InstancePager.Allocation and
  IndirectInstancer
- Free pages when an allocation is deleted
2024-09-14 12:55:02 -07:00
Jozufozu
637f0538fc Growing pains
- Fix bit logic on the GPU
- Manually manage the size of the storage and pageTable buffers
- Make object2Page and page2Object static
- Fix instance writing loop
- Fix page table always having full pages
- Fix allocations not shrinking
2024-09-14 12:55:01 -07:00
Jozufozu
0af1127745 Paging Dr. Instancer
- Goal: avoid needing to re-upload everything when instance count for
  one instancer changes
- Solution: store instances in pages of 32
- Allocate pages in a GPU arena
- Store one uint per page to indicate which model the instances in the
  page belong to, and how many instances are actually stored in the page
- Instancers eagerly allocate and free pages as their instance count
  changes
- Instancers will not necessarily store instances contiguously anymore,
  but that's okay because any given cull workgroup will only reference a
  single page
- Culling threads *will* write instances contiguously however, and so we
  still need to keep track of a base instance per instancer, and the
  target buffer logic does not change
2024-09-14 12:55:01 -07:00
PepperCode1
14ca1d3286 Allow VertexViews to hold a memory owner
- Remove MemoryBlock parameter from SimpleQuadMesh constructors
2024-09-09 19:01:19 -07:00
Jozufozu
1a8ed8db28 Keeping our priorities straight
- Implement backend priority system
- Give indirect priority 1000 and instancing 500
- Generate the sorted list of backends on demand in case one changes
  priority at runtime
2024-08-15 21:45:14 -07:00
Jozufozu
a5f49c6738 Hol up
- Use way fewer memory barriers
- I didn't realize that GL_SHADER_STORAGE_BARRIER_BIT was global instead
  of operating only on the currently bound buffers. Oh, well
- Move apply program binding to IndirectDrawManager
- Fix embedded instances flickering when first loading a world. Need to
  actually bind the matrix buffer for the cull shader. Not sure how it
  worked at all before
- Minor styling/cleanup
2024-08-15 20:57:28 -07:00
Jozufozu
7a7d58adf2 Embeds your embeddings
- Optimize embeddings on indirect backend by uploading all matrices in
  an SSBO
- Allocate matrices in an arena
- Flatten IndirectCullingGroups to only be parameterized by
  InstanceType, so now all instances from all embeddings get culled in
  the same dispatch
- Sort indirect draws by whether they're embedded before anything else
- Include an "embedded" boolean in the MultiDraw record to decide which
  shader to use
- Include "matrixIndex" field in model descriptor and indirect draw
  structs
- Use matrixIndex == 0 to indicate that a matrix is the identity to
  avoid unnecessary work in the cull shader
- Add helper to write a mat3 as 3 vec4s
2024-08-15 11:41:33 -07:00
Jozufozu
b7d2b2ac7c Ubern't
- De-uberify the light shader
- Remove lightSources index
- Include LightShader in PipelineProgramKey and parameterize the
  pipeline fragment shader by it
- Profiling suggests that specializing the shaders uses significantly
  less GPU time, and we may want to do this for actual user-authored
  material shaders (and cutout?) as well
- Sort LightShader highest in the material comparator
- Implement a materialEquals method so IndirectCullingGroup can bucket
  draws on more that just material reference equality
- Do not store any particular draw program in IndirectCullingGroup
2024-08-12 17:35:31 -07:00
Jozufozu
2d37c3894d We (un)roll
- Manually unroll all loops in light_lut with the help of macros
  - Pretty significant perf gains on my 5600G
- I tried assembling a bitmask of the blocks we actually want to fetch
  and branching in each _FLW_LIGHT_FETCH in an attempt to reduce the
  bandwidth required but that turned out much slower. Perhaps there's
  still some middle-ground to be found for axis-aligned normals
- Re-order the 8-arrays in _flw_lightForDirection to be xzy to be
  consistent with everything else and improve the memory access pattern
2024-08-12 15:37:29 -07:00
Jozufozu
76a4b35ce6 Assimilate Backend Config
- Merge flywheel-backend config into an object within the base flywheel
  config
- On forge, push a path in the toml
- On fabric, serialize a nested json object
- Still expose the BackendConfig via FlwBackendXplat, but have the impl
  set a static field in the xplat impl
- Revert debug shulker box changes in previous commit
2024-08-10 12:54:15 -07:00
Jozufozu
744c40a56a Installing a light switch
- Guard 3 different flw_light impls via #define
- Guard the inner face correction behind another #define
- Add LightSmoothness enum to decide which flw_light impl to use
- Make LightSmoothness configurable via a new BackendConfig
- Add command to switch LightSmoothness on the fly
- Note: currently requires a resource reload so we don't need to compile
  4x as many shaders
2024-08-09 14:45:17 -07:00