Skip to content

fix: use shader entrypoints in roundtrip tests instead of duplicated entrypoint bodies#104

Draft
schell wants to merge 1 commit into
mainfrom
fix/roundtrip-tests
Draft

fix: use shader entrypoints in roundtrip tests instead of duplicated entrypoint bodies#104
schell wants to merge 1 commit into
mainfrom
fix/roundtrip-tests

Conversation

@schell
Copy link
Copy Markdown
Owner

@schell schell commented Apr 22, 2026

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_code warnings.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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, compute main) 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.

Comment on lines 33 to 36
#[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;
}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

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}.

Copilot uses AI. Check for mistakes.
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());
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

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).

Suggested change
texture_sample_2d::__TEX_SAMPLER.set(SamplerState::default());
texture_sample_2d::TEX_SAMPLER.set(SamplerState::default());

Copilot uses AI. Check for mistakes.
Comment on lines +706 to +707
write_cpu_texture2d(&tex2d_variants::__TEX, &color0);
tex2d_variants::__S.set(SamplerState::default());
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

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;.

Suggested change
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());

Copilot uses AI. Check for mistakes.
Comment on lines +786 to +787
write_cpu_texture2d(&tex2d_gather_variants::__TEX, &color0);
tex2d_gather_variants::__S.set(SamplerState::default());
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

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}.

Suggested change
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());

Copilot uses AI. Check for mistakes.
Comment on lines +480 to +482
dispatch_workgroups((1, 1, 1), (N as u32, 1, 1), |builtins| {
select_f32_scalar::main(builtins.global_invocation_id);
});
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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);
},
);

Copilot uses AI. Check for mistakes.
Comment on lines 41 to 45
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;
}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
Comment on lines +36 to 37
pub static #inner_name: #sampler_type = #sampler_type::new(#group, #binding);
const #name: &'static #sampler_type = &#inner_name;
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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;

Copilot uses AI. Check for mistakes.
Comment on lines +399 to 400
write_cpu_texture(&texture_load_2d::__TEX, &pixels);
let gpu_load_pixels = render_texture_load_gpu(device, queue, &gpu_source_texture);
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
Comment on lines +869 to +870
write_cpu_texture2d_array(&tex2d_array_variants::__TEX, &color_layers);
tex2d_array_variants::__S.set(SamplerState::default());
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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());

Copilot uses AI. Check for mistakes.

all_vec2b::INPUT.set(inputs);
all_vec2b::OUTPUT.set([0u32; N]);
dispatch_workgroups((1, 1, 1), (N as u32, 1, 1), |builtins| {
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
dispatch_workgroups((1, 1, 1), (N as u32, 1, 1), |builtins| {
dispatch_workgroups((1, 1, 1), all_vec2b::linkage::main::WORKGROUP_SIZE, |builtins| {

Copilot uses AI. Check for mistakes.
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.

2 participants