Skip to content

Implement ClampToBorder (fixes #521)#581

Open
lisyarus wants to merge 4 commits intogfx-rs:trunkfrom
lisyarus:implement-clamp-to-border
Open

Implement ClampToBorder (fixes #521)#581
lisyarus wants to merge 4 commits intogfx-rs:trunkfrom
lisyarus:implement-clamp-to-border

Conversation

@lisyarus
Copy link
Copy Markdown
Contributor

@lisyarus lisyarus commented Apr 16, 2026

Checklist

  • cargo clippy reports no issues
  • cargo doc reports no issues
  • cargo deny issues have been fixed or added to deny.toml
  • Human-readable change descriptions added to CHANGELOG.md under the "Unreleased" heading.
    • If the change does not affect the user (or is a process change), preface the change with "Internal:"
    • Add credit to yourself for each change: Added new functionality. @githubname

Description

Uncommencted the ClampToBorder and ClampToZero features. Since these aren't present in webgpu.h, I had to add a few things to wgpu.h API:

  • Add WGPUNativeAddressMode enum with WGPUNativeAddressMode_ClampToBorder value, which is supposed to be used in places where WGPUAddressMode is expected
  • Add WGPUSamplerBorderColor enum that mimicks the corresponding wgpu enum
  • Add WGPUSamplerDescriptorExtras struct to be chained in WGPUSamplerDescriptor, which provides the WGPUSamplerBorderColor value.

I had to rewrite the map_address_mode function in conv.rs: preciously it was generated using the map_enum_with_undefined macro, but since now it mixes values from two native enums, I had to rewrite it by hand.

Currently, if WGPUNativeAddressMode_ClampToBorder is used but the WGPUSamplerDescriptorExtras isn't provided, it sets the borderColor in SamplerDescriptor to None, and the wgpu itself is supposed to handle this case. We could alternatively check that explicitly in wgpuDeviceCreateSampler, I'm not sure what the correct thing to do would be here.

Related Issues

This PR fixes #521

Copy link
Copy Markdown
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got a question, and this needs rebasing but looks good.

Comment thread src/conv.rs
Comment on lines -41 to -49
map_enum_with_undefined!(
map_address_mode,
WGPUAddressMode,
wgt::AddressMode,
"Unknown address mode",
ClampToEdge,
Repeat,
MirrorRepeat
);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: why did this need to be converted to an explicit function?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand it correctly, map_enum_with_undefined appends the native enum name (to get WGPUAddressMode_Repeat and the like), but now it has to mix enum values from two different enums (WGPUAddressMode and WGPUNativeAddressMode).

@lisyarus lisyarus force-pushed the implement-clamp-to-border branch from c8a1a4e to d5cee1c Compare April 30, 2026 11:45
@lisyarus
Copy link
Copy Markdown
Contributor Author

Rebased to fresh trunk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Why ClampToBorder and ClampToZero are disabled?

2 participants