feat(renderer): load block textures into a GPU array with mips and a sampler #26

Open
Serkyo wants to merge 21 commits from feat/block-texture-array into dev
Owner

What does this PR do?

I added the GPU side of block texturing. Nothing samples the array yet.

Renderer (crates/renderer/src/texture.rs):

  • BlockTextures walks assets/textures/blocks/ recursively in sorted order, decodes each PNG to RGBA8 with the png crate, refuses any image that is not 32 x 32, and builds a ContentId -> layer map. Layer 0 is a generated missing-texture pattern. A file foo/bar.png gets the id syn:blocks/foo/bar. The .png extension is matched in any letter case, and two files that map to the same id fail with TextureError::DuplicateId naming both.
  • BlockTextureArray::new creates one R8G8B8A8_SRGB 2D 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).
  • Before creating the image it queries vkGetPhysicalDeviceImageFormatProperties and refuses a layer count above maxArrayLayers with RendererError::TooManyBlockTextures. Every failure path inside BlockTextureArray::new releases what it created.
  • pipeline.rs puts the set layout in the pipeline layout, renderer.rs binds the set and tears the array down, and Renderer::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::Flat is what TryFrom, FromStr and serde still use and it still rejects /. IdKind::BlockTexture accepts syn:blocks/ plus /-separated [a-z0-9_-]+ segments.
  • ContentId::deserialize_block_texture reads a texture id into a field marked for it. RegistryBuilder::register and bind refuse a non-flat id with RegistryError::NotFlat, WorldMetadata::encode refuses a block table holding one, and DimensionId has a private field built by DimensionId::new, so a texture id cannot reach a registry, a saved world table or a dimension.

Client and assets:

  • crates/client/src/main.rs passes the textures directory to the renderer.
  • assets/textures/blocks/ holds placeholder stone, dirt, grass_top and grass_side PNGs, recorded in CREDITS.md as generated placeholders.

Docs: a "Block textures" section in docs/rendering.md, the charset note in DEVELOPMENT.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.png is syn: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 (the namespace:id format, the reserved syn: 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_SDK set to the SDK under C:/VulkanSDK:

  • cargo check -p shared -p renderer -p client passed.
  • cargo test -p shared -p renderer passed: 377 tests in shared, 48 in renderer.
  • cargo test -p server passed: 97 tests. The server change is one test updated for DimensionId::new.
  • cargo clippy --all-targets --all-features -- -D warnings passed.
  • cargo fmt --all -- --check passed.

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 check for the new png dependency.

Additional Context

  • Nothing samples the array. UVs, the per-face lookup and the fragment shader are the next change.
  • DimensionId's field is now private (DimensionId::new, id()). The only caller outside shared was a server test.
  • Not changed here: Renderer::new does not free a completed array if a later step fails, and create_gpu_buffer leaks partial buffers on its error paths. Both already exist on dev and this branch only calls them.

None.

Checklist

  • I have branched from dev (or a feature branch off dev) and my PR targets dev.
  • I have kept my changes focused to a single concept.
  • I have added or updated documentation (/// doc comments for Rust) where necessary.
  • I have tested my changes and described any relevant automated or manual testing above.
### What does this PR do? I added the GPU side of block texturing. Nothing samples the array yet. Renderer (`crates/renderer/src/texture.rs`): - `BlockTextures` walks `assets/textures/blocks/` recursively in sorted order, decodes each PNG to RGBA8 with the `png` crate, refuses any image that is not 32 x 32, and builds a `ContentId -> layer` map. Layer 0 is a generated missing-texture pattern. A file `foo/bar.png` gets the id `syn:blocks/foo/bar`. The `.png` extension is matched in any letter case, and two files that map to the same id fail with `TextureError::DuplicateId` naming both. - `BlockTextureArray::new` creates one `R8G8B8A8_SRGB` 2D 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). - Before creating the image it queries `vkGetPhysicalDeviceImageFormatProperties` and refuses a layer count above `maxArrayLayers` with `RendererError::TooManyBlockTextures`. Every failure path inside `BlockTextureArray::new` releases what it created. - `pipeline.rs` puts the set layout in the pipeline layout, `renderer.rs` binds the set and tears the array down, and `Renderer::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::Flat` is what `TryFrom`, `FromStr` and serde still use and it still rejects `/`. `IdKind::BlockTexture` accepts `syn:blocks/` plus `/`-separated `[a-z0-9_-]+` segments. - `ContentId::deserialize_block_texture` reads a texture id into a field marked for it. `RegistryBuilder::register` and `bind` refuse a non-flat id with `RegistryError::NotFlat`, `WorldMetadata::encode` refuses a block table holding one, and `DimensionId` has a private field built by `DimensionId::new`, so a texture id cannot reach a registry, a saved world table or a dimension. Client and assets: - `crates/client/src/main.rs` passes the textures directory to the renderer. - `assets/textures/blocks/` holds placeholder `stone`, `dirt`, `grass_top` and `grass_side` PNGs, recorded in `CREDITS.md` as generated placeholders. Docs: a "Block textures" section in `docs/rendering.md`, the charset note in `DEVELOPMENT.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.png` is `syn: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 (the `namespace:id` format, the reserved `syn:` 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_SDK` set to the SDK under `C:/VulkanSDK`: - `cargo check -p shared -p renderer -p client` passed. - `cargo test -p shared -p renderer` passed: 377 tests in `shared`, 48 in `renderer`. - `cargo test -p server` passed: 97 tests. The server change is one test updated for `DimensionId::new`. - `cargo clippy --all-targets --all-features -- -D warnings` passed. - `cargo fmt --all -- --check` passed. 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 check` for the new `png` dependency. ### Additional Context - Nothing samples the array. UVs, the per-face lookup and the fragment shader are the next change. - `DimensionId`'s field is now private (`DimensionId::new`, `id()`). The only caller outside `shared` was a server test. - Not changed here: `Renderer::new` does not free a completed array if a later step fails, and `create_gpu_buffer` leaks partial buffers on its error paths. Both already exist on `dev` and this branch only calls them. ### Related Issues None. ### Checklist - [x] I have branched from `dev` (or a feature branch off `dev`) and my PR targets `dev`. - [x] I have kept my changes focused to a single concept. - [x] I have added or updated documentation (`///` doc comments for Rust) where necessary. - [x] I have tested my changes and described any relevant automated or manual testing above.
fix(renderer): repeat the block texture sampler on U and V
Some checks failed
CLA Signed All authors have signed the CLA.
Auto Labeler / label-scope (pull_request_target) Successful in 2s
CI / Dependency Licenses & Advisories (pull_request) Successful in 30s
CLA Check / cla-check (pull_request_target) Successful in 2s
CI / Rust Check, Lint & Test (pull_request) Successful in 37m12s
CI / Lua Lint & Format (pull_request) Successful in 8s
CI / Commit Message Lint (pull_request) Failing after 2s
CI / LFS Pointer Guard (pull_request) Successful in 6s
1626708efb
Some checks failed
CLA Signed All authors have signed the CLA.
Required
Auto Labeler / label-scope (pull_request_target) Successful in 2s
CI / Dependency Licenses & Advisories (pull_request) Successful in 30s
CLA Check / cla-check (pull_request_target) Successful in 2s
CI / Rust Check, Lint & Test (pull_request) Successful in 37m12s
Required
Details
CI / Lua Lint & Format (pull_request) Successful in 8s
Required
Details
CI / Commit Message Lint (pull_request) Failing after 2s
CI / LFS Pointer Guard (pull_request) Successful in 6s
Required
Details
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/block-texture-array:feat/block-texture-array
git switch feat/block-texture-array
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Synvael/synvael!26
No description provided.