Skip to content

Merge redundant view-binding samplers to fix WebGPU sampler limit overflow - #25836

Open
issam3105 wants to merge 5 commits into
bevyengine:mainfrom
issam3105:Merge_redundant_samplers
Open

issam3105 wants to merge 5 commits into
bevyengine:mainfrom
issam3105:Merge_redundant_samplers

Conversation

@issam3105

@issam3105 issam3105 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Objective

Partially addresses #24711 — reduces the number of sampler bindings in @group(0) of the mesh view bind group.

WebGPU impose tight limits on the number of samplers per shader stage (often 16). Before this PR, every feature that needed texture sampling allocated its own dedicated Sampler object and binding slot, leaving little headroom for features such as additional glTF extensions (e.g. KHR_materials_transmission, KHR_materials_specular, KHR_materials_anisotropy...) that would each require their own sampler.

Solution

Audit every sampler in @group(0) and merge those that share the same descriptor:

  • Introduce a single LinearSampler resource (always bound at slot 25) that replaces all per-feature Linear samplers.
  • Merge the two Comparison shadow samplers (point + directional were identical) into one shadow_comparison_sampler.
  • Remove the redundant Sampler fields from ShadowSamplers, AtmosphereSampler, and ViewTransmissionTexture.

Testing

  • Tested an HTML5 app on WebGPU: before this PR, enabling pbr_transmission_textures triggered:
    Caught rendering error: The number of samplers (19) in the Fragment stage exceeds the maximum per-stage limit (16).
    
    After this PR, the same app runs without error and features such as pbr_specular_textures + pbr_transmission_textures can be enabled simultaneously.
  • Tested on Windows (Vulkan).

Showcase

Mapping from old to shared samplers

Binding Before After
3 point_shadow_textures_comparison_sampler shadow_textures_comparison_sampler
4 point_shadow_textures_linear_sampler (pcss) linear_sampler
6 directional_shadow_textures_comparison_sampler shadow_textures_comparison_sampler
7 directional_shadow_textures_linear_sampler (pcss) linear_sampler
19 dt_lut_sampler (tonemap) dt_lut_sampler (tonemap, unchanged)
25 view_transmission_sampler (conditional) linear_sampler
32 atmosphere_transmittance_sampler (conditional) linear_sampler
36 area_light_luts_sampler (conditional) linear_sampler
38 dfg_lut_sampler (conditional) linear_sampler

9 → 3 sampler bindings (with all features active).

GPU Sampler objects created at startup

Before After
point_light_comparison_sampler shadow_comparison_sampler
directional_light_comparison_sampler shadow_comparison_sampler
point_light_linear_sampler (pcss) LinearSampler
directional_light_linear_sampler (pcss) LinearSampler
AtmosphereSampler LinearSampler
ViewTransmissionTexture::sampler LinearSampler

6 → 2 GPU sampler objects.

@issam3105
issam3105 marked this pull request as ready for review September 18, 2026 15:05
@issam3105

Copy link
Copy Markdown
Contributor Author

Should i compact the binding indices to fill the gaps left by the removed sampler ?

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen O-WebGPU Specific to the WebGPU render API D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 20, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes O-WebGPU Specific to the WebGPU render API S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

2 participants