feat(renderer): load block textures into a GPU array with mips and a sampler #26
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
scope/assets
scope/client
scope/networking
scope/renderer
scope/scripting
scope/server
scope/shared
scope/workspace
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Synvael/synvael!26
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/block-texture-array"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What does this PR do?
I added the GPU side of block texturing. Nothing samples the array yet.
Renderer (
crates/renderer/src/texture.rs):BlockTextureswalksassets/textures/blocks/recursively in sorted order, decodes each PNG to RGBA8 with thepngcrate, refuses any image that is not 32 x 32, and builds aContentId -> layermap. Layer 0 is a generated missing-texture pattern. A filefoo/bar.pnggets the idsyn:blocks/foo/bar. The.pngextension is matched in any letter case, and two files that map to the same id fail withTextureError::DuplicateIdnaming both.BlockTextureArray::newcreates oneR8G8B8A8_SRGB2D array image with a full mip chain, uploads it through a staging buffer, generates the mips with linear blits, and moves it to shader-read layout. The sampler uses nearest magnification, trilinear minification, repeat addressing, and anisotropy at the device limit where the device supports it. It also builds the descriptor set layout, pool and set (set 0, binding 0, fragment stage).vkGetPhysicalDeviceImageFormatPropertiesand refuses a layer count abovemaxArrayLayerswithRendererError::TooManyBlockTextures. Every failure path insideBlockTextureArray::newreleases what it created.pipeline.rsputs the set layout in the pipeline layout,renderer.rsbinds the set and tears the array down, andRenderer::block_texture_layer(&ContentId)returns the uploaded layer, or layer 0 for an unknown id. Texture errors display the file name and its size.Shared (
crates/shared/src/registry.rs):ContentId::parse(IdKind, &str)validates by kind.IdKind::Flatis whatTryFrom,FromStrand serde still use and it still rejects/.IdKind::BlockTextureacceptssyn:blocks/plus/-separated[a-z0-9_-]+segments.ContentId::deserialize_block_texturereads a texture id into a field marked for it.RegistryBuilder::registerandbindrefuse a non-flat id withRegistryError::NotFlat,WorldMetadata::encoderefuses a block table holding one, andDimensionIdhas a private field built byDimensionId::new, so a texture id cannot reach a registry, a saved world table or a dimension.Client and assets:
crates/client/src/main.rspasses the textures directory to the renderer.assets/textures/blocks/holds placeholderstone,dirt,grass_topandgrass_sidePNGs, recorded inCREDITS.mdas generated placeholders.Docs: a "Block textures" section in
docs/rendering.md, the charset note inDEVELOPMENT.md, and ADR-0020 (below).Why is this change necessary?
The renderer draws every face in one flat colour and has no image, sampler or descriptor plumbing. Texturing blocks needs the array, its mips, the sampler and the descriptor binding in place before UVs and the fragment shader can use them. I built that part on its own so the sampling change can stay small.
Textures are addressed by the path of their file, so
foo/bar.pngissyn:blocks/foo/bar. ADR-0005 rejects a slash in any content id, so the two could not both hold. I wrote ADR-0020, which supersedes the slash clause of the charset rule in ADR-0005: a name may hold/only for a kind the engine lists, and today that is block texture ids. The rest of ADR-0005 stands (thenamespace:idformat, the reservedsyn:namespace, the lowercase ASCII charset, interning). ADR-0005's status line now points to ADR-0020. The shared parser takes the kind as input so a slash stays invalid for blocks, items and dimensions.Scope of Changes
client, server, renderer, shared, workspace, assets
Testing
Automated, run from this worktree with
VULKAN_SDKset to the SDK underC:/VulkanSDK:cargo check -p shared -p renderer -p clientpassed.cargo test -p shared -p rendererpassed: 377 tests inshared, 48 inrenderer.cargo test -p serverpassed: 97 tests. The server change is one test updated forDimensionId::new.cargo clippy --all-targets --all-features -- -D warningspassed.cargo fmt --all -- --checkpassed.The new tests cover the id and layer map, the 32 x 32 check, the fallback layer, nested files, ordering, duplicate ids in both input orders, mixed-case extensions, the layer limit at and one over, the texture id in a flat registry, block table, dimension and
encode, and JSON and postcard round trips of a texture id.Manual: none. I did not start the client, and no validation layer run covers the Vulkan calls, because nothing samples the array yet. The failure path of the image-format query itself has no test. I did not run
cargo deny checkfor the newpngdependency.Additional Context
DimensionId's field is now private (DimensionId::new,id()). The only caller outsidesharedwas a server test.Renderer::newdoes not free a completed array if a later step fails, andcreate_gpu_bufferleaks partial buffers on its error paths. Both already exist ondevand this branch only calls them.Related Issues
None.
Checklist
dev(or a feature branch offdev) and my PR targetsdev.///doc comments for Rust) where necessary.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.