fix: use shader entrypoints in roundtrip tests instead of duplicated entrypoint bodies#104
fix: use shader entrypoints in roundtrip tests instead of duplicated entrypoint bodies#104schell wants to merge 1 commit into
Conversation
…entrypoint bodies
There was a problem hiding this comment.
Pull request overview
This PR updates the roundtrip test suite to reuse the actual shader entry points (and their declared resources) for CPU-side execution, instead of duplicating entry point bodies in test code, reducing duplicated logic and dead_code warnings.
Changes:
- Updated CPU-side test execution to call shader entry points directly (e.g.
frag_main, computemain) rather than re-implementing logic inline. - Adjusted CPU-side setup in texture tests to initialize the same texture/sampler bindings the shaders use.
- Changed
texture!/sampler!macro expansions to make their backing__{NAME}statics public so tests can access them.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/wgsl-rs-macros/src/texture.rs | Makes macro-generated backing texture statics public. |
| crates/wgsl-rs-macros/src/sampler.rs | Makes macro-generated backing sampler statics public. |
| crates/roundtrip-tests/src/shaders/texture_operations.rs | CPU path now calls fragment entry points and initializes shader-declared bindings. |
| crates/roundtrip-tests/src/shaders/select_operations.rs | CPU path now dispatches the compute shader entry points rather than duplicating select logic. |
| crates/roundtrip-tests/src/shaders/logical_operations.rs | CPU path now dispatches the compute shader entry points rather than duplicating all/any logic. |
| crates/roundtrip-tests/src/shaders/derivative_operations.rs | CPU path now calls fragment entry points for derivative operations. |
| crates/roundtrip-tests/src/shaders/advanced_texture_operations.rs | CPU path now calls fragment entry points and initializes shader-declared bindings for advanced texture ops. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #[doc(hidden)] | ||
| static #inner_name: #rust_type<#sample_type> = #rust_type::new(#group, #binding); | ||
| pub static #inner_name: #rust_type<#sample_type> = #rust_type::new(#group, #binding); | ||
| const #name: &'static #rust_type<#sample_type> = &#inner_name; | ||
| } |
There was a problem hiding this comment.
texture! now emits pub static __{NAME} for the inner backing texture. That exposes the macro’s internal implementation detail as part of the module’s public API (and the comment above still describes it as a hidden inner static). Consider keeping the inner static private (or at most pub(crate)) and instead exposing a #[doc(hidden)] pub const {NAME}: &'static Texture* = &__{NAME}; so callers can initialize/mutate via {NAME} without depending on __{NAME}.
| let cpu_sampler: Sampler = Sampler::new(0, 0); | ||
| cpu_sampler.set(SamplerState::default()); | ||
| write_cpu_texture(&texture_sample_2d::__TEX, &pixels); | ||
| texture_sample_2d::__TEX_SAMPLER.set(SamplerState::default()); |
There was a problem hiding this comment.
Same issue for the sampler: referencing __TEX_SAMPLER relies on the macro’s internal backing symbol name. Prefer using the declared binding identifier (e.g. texture_sample_2d::TEX_SAMPLER) by having sampler! expose a #[doc(hidden)] pub const TEX_SAMPLER: &'static Sampler = &__TEX_SAMPLER; (and keep the backing static non-public).
| texture_sample_2d::__TEX_SAMPLER.set(SamplerState::default()); | |
| texture_sample_2d::TEX_SAMPLER.set(SamplerState::default()); |
| write_cpu_texture2d(&tex2d_variants::__TEX, &color0); | ||
| tex2d_variants::__S.set(SamplerState::default()); |
There was a problem hiding this comment.
This CPU setup uses __TEX/__S, which are macro-generated backing symbols (implementation detail). To avoid coupling tests to the __{NAME} convention and to keep those backing statics non-public, prefer initializing via the declared binding names (TEX, S) by having texture!/sampler! expose #[doc(hidden)] pub const TEX/S: &'static _ = &__TEX/__S;.
| write_cpu_texture2d(&tex2d_variants::__TEX, &color0); | |
| tex2d_variants::__S.set(SamplerState::default()); | |
| write_cpu_texture2d(tex2d_variants::TEX, &color0); | |
| tex2d_variants::S.set(SamplerState::default()); |
| write_cpu_texture2d(&tex2d_gather_variants::__TEX, &color0); | ||
| tex2d_gather_variants::__S.set(SamplerState::default()); |
There was a problem hiding this comment.
Same coupling here: __TEX/__S are macro backing symbols. Prefer setting up the CPU state via the declared binding names (TEX, S) with the macros exporting #[doc(hidden)] pub const references, rather than relying on __{NAME}.
| write_cpu_texture2d(&tex2d_gather_variants::__TEX, &color0); | |
| tex2d_gather_variants::__S.set(SamplerState::default()); | |
| write_cpu_texture2d(&tex2d_gather_variants::TEX, &color0); | |
| tex2d_gather_variants::S.set(SamplerState::default()); |
| dispatch_workgroups((1, 1, 1), (N as u32, 1, 1), |builtins| { | ||
| select_f32_scalar::main(builtins.global_invocation_id); | ||
| }); |
There was a problem hiding this comment.
The CPU path hardcodes the workgroup size as (N as u32, 1, 1). Since the shader’s #[workgroup_size(...)] is the source of truth (and linkage generation exposes it), consider using select_f32_scalar::linkage::main::WORKGROUP_SIZE (or an equivalent generated const) to avoid tests silently diverging if the workgroup size changes.
| dispatch_workgroups((1, 1, 1), (N as u32, 1, 1), |builtins| { | |
| select_f32_scalar::main(builtins.global_invocation_id); | |
| }); | |
| dispatch_workgroups( | |
| (1, 1, 1), | |
| select_f32_scalar::linkage::main::WORKGROUP_SIZE, | |
| |builtins| { | |
| select_f32_scalar::main(builtins.global_invocation_id); | |
| }, | |
| ); |
| quote! { | ||
| #[doc(hidden)] | ||
| static #inner_name: #rust_type = #rust_type::new(#group, #binding); | ||
| pub static #inner_name: #rust_type = #rust_type::new(#group, #binding); | ||
| const #name: &'static #rust_type = &#inner_name; | ||
| } |
There was a problem hiding this comment.
Same visibility concern as the sampled-texture branch: emitting pub static __{NAME} for the depth texture makes the internal backing symbol public. Prefer a private inner static plus a #[doc(hidden)] pub const {NAME}: &'static TextureDepth* = &__{NAME}; (or, at minimum, use pub(crate) instead of pub).
| pub static #inner_name: #sampler_type = #sampler_type::new(#group, #binding); | ||
| const #name: &'static #sampler_type = &#inner_name; |
There was a problem hiding this comment.
sampler! now emits pub static __{NAME} for the inner backing sampler, which makes an internal implementation detail part of the public API. Prefer keeping the inner static private (or pub(crate)) and exposing a #[doc(hidden)] pub const {NAME}: &'static Sampler* = &__{NAME}; so call sites can use {NAME} without depending on the __{NAME} symbol.
| pub static #inner_name: #sampler_type = #sampler_type::new(#group, #binding); | |
| const #name: &'static #sampler_type = &#inner_name; | |
| static #inner_name: #sampler_type = #sampler_type::new(#group, #binding); | |
| #[doc(hidden)] | |
| pub const #name: &'static #sampler_type = &#inner_name; |
| write_cpu_texture(&texture_load_2d::__TEX, &pixels); | ||
| let gpu_load_pixels = render_texture_load_gpu(device, queue, &gpu_source_texture); |
There was a problem hiding this comment.
This test now depends on the macro-generated internal symbol name __TEX. That couples the test to the texture! macro’s implementation detail and forces the macro to expose its backing static. Prefer initializing via the declared binding name (e.g. texture_load_2d::TEX) by making the macro expose a #[doc(hidden)] pub const TEX: &'static Texture2D<_> = &__TEX; (keeping __TEX private).
| write_cpu_texture2d_array(&tex2d_array_variants::__TEX, &color_layers); | ||
| tex2d_array_variants::__S.set(SamplerState::default()); |
There was a problem hiding this comment.
Same coupling here: __TEX/__S are macro backing symbols. Prefer initializing via the declared binding identifiers (TEX, S) by exporting #[doc(hidden)] pub const references from the macros, keeping the backing statics private.
| write_cpu_texture2d_array(&tex2d_array_variants::__TEX, &color_layers); | |
| tex2d_array_variants::__S.set(SamplerState::default()); | |
| write_cpu_texture2d_array(&tex2d_array_variants::TEX, &color_layers); | |
| tex2d_array_variants::S.set(SamplerState::default()); |
|
|
||
| all_vec2b::INPUT.set(inputs); | ||
| all_vec2b::OUTPUT.set([0u32; N]); | ||
| dispatch_workgroups((1, 1, 1), (N as u32, 1, 1), |builtins| { |
There was a problem hiding this comment.
The CPU dispatch hardcodes the workgroup size as (N as u32, 1, 1). To keep the test consistent with the shader declaration, prefer using the generated linkage workgroup-size constant (e.g. all_vec2b::linkage::main::WORKGROUP_SIZE) instead of duplicating the value here.
| dispatch_workgroups((1, 1, 1), (N as u32, 1, 1), |builtins| { | |
| dispatch_workgroups((1, 1, 1), all_vec2b::linkage::main::WORKGROUP_SIZE, |builtins| { |
A lot of the roundtrip tests duplicated the entrypoint function bodies instead of calling them directly. These changes fix that, eliminating a lot of
dead_codewarnings.