Optimize CPU verifier and fix biome shift sampling - #35
Open
sync0516 wants to merge 3 commits into
Open
Conversation
Refactor cubiomes.c to improve memory management and structure usage. Replace malloc with calloc for Cubiomes creation, implement FloodEntry struct for queue management, and update flood fill logic to use the new structure.
Added section for optional CPU architecture tuning in README.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sampleDoublePerlin(shift, z, x, 0).getBiomeAt()allocation with an exact staged mushroom-fields classifier: sample continentalness first, safely reject non-candidates, then run the remaining climate parameters andclimateToBiome().intstate grid and worst-case preallocated flood queue with a reusable visited bitmap, compact candidate list, and dynamically growing queue.CPU_ARCH=nativesetting for GCC/Clang CPU builds; the default remains portable.Motivation
The production large-biome verifier covers 51,200 blocks. At scale 4 this is a 12,800 x 12,800 grid (163,840,000 cells). The current implementation allocates approximately:
That is about 2.44 GiB per CPU worker before allocator overhead.
The existing Monte Carlo callback also swaps the arguments used for the shifted Z coordinate. In a 262,144-point scale-4 comparison, this changed 15 prefilter decisions, including 11 where the old expression rejected a point accepted by the correctly ordered expression.
Benchmarks
Ryzen 5 7600X, Windows 11, GCC 16.2, large biomes, seed
664124959764, center(1600, 16000), range 51,200, minimum area 1,000,000, scale 4:CPU_ARCH=nativeThe returned center and area were identical:
(2734, 6795), 72,710,512 blocks.Correctness checks
getBiomeAt(): 524,288 random points across normal/large biomes and scales 4/16, zero mismatches.CPU_ARCH=nativeCPU-only builds pass.-Wall -Wextra -Wpedanticproduces no diagnostics.git diff --checkpasses.A continentalness-only final classifier was tested and rejected: it produced 603 false-positive cells at scale 4 and 26 at scale 16 in the known region, which could inflate or connect islands.
Scope
This PR is intentionally CPU-only. It does not duplicate the GPU work already proposed in #28.